Debian Codegraph @

testing/web-platform/mozilla/tests/webdriver/bidi/script/exception_details.py

raw
1 import pytest
2 from webdriver.bidi.modules.script import ContextTarget, ScriptEvaluateResultException
3
4
5 @pytest.mark.asyncio
6 @pytest.mark.parametrize("await_promise", [True, False])
7 @pytest.mark.parametrize(
8 "expression",
9 [
10 "null",
11 "{ toString: 'not a function' }",
12 "{ toString: () => {{ throw 'toString not allowed'; }} }",
13 "{ toString: () => true }",
14 ],
15 )
16 @pytest.mark.asyncio
17 async def test_call_function_without_to_string_interface(
18 bidi_session, top_context, await_promise, expression
19 ):
20 function_declaration = "()=>{throw { toString: 'not a function' } }"
21 if await_promise:
22 function_declaration = "async" + function_declaration
23
24 with pytest.raises(ScriptEvaluateResultException) as exception:
25 await bidi_session.script.call_function(
26 function_declaration=function_declaration,
27 await_promise=await_promise,
28 target=ContextTarget(top_context["context"]),
29 )
30
31 assert isinstance(exception.value.text, str)
32
33
34 @pytest.mark.asyncio
35 @pytest.mark.parametrize("await_promise", [True, False])
36 @pytest.mark.parametrize(
37 "expression",
38 [
39 "null",
40 "{ toString: 'not a function' }",
41 "{ toString: () => {{ throw 'toString not allowed'; }} }",
42 "{ toString: () => true }",
43 ],
44 )
45 @pytest.mark.asyncio
46 async def test_evaluate_without_to_string_interface(
47 bidi_session, top_context, await_promise, expression
48 ):
49 if await_promise:
50 expression = f"Promise.reject({expression})"
51 else:
52 expression = f"throw {expression}"
53
54 with pytest.raises(ScriptEvaluateResultException) as exception:
55 await bidi_session.script.evaluate(
56 expression=expression,
57 await_promise=await_promise,
58 target=ContextTarget(top_context["context"]),
59 )
60
61 assert isinstance(exception.value.text, str)