tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

exception_details.py (970B)


      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_evaluate_without_to_string_interface(
     18    bidi_session, top_context, await_promise, expression
     19 ):
     20    if await_promise:
     21        expression = f"Promise.reject({expression})"
     22    else:
     23        expression = f"throw {expression}"
     24 
     25    with pytest.raises(ScriptEvaluateResultException) as exception:
     26        await bidi_session.script.evaluate(
     27            expression=expression,
     28            await_promise=await_promise,
     29            target=ContextTarget(top_context["context"]),
     30        )
     31 
     32    assert isinstance(exception.value.text, str)