forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1780752 - [bidi] Handle exception objects which don't support toS…
…tring r=webdriver-reviewers,jgraham Differential Revision: https://phabricator.services.mozilla.com/D152506
- Loading branch information
1 parent
0b5a7f0
commit 81897c2
Showing
6 changed files
with
143 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
testing/web-platform/mozilla/tests/webdriver/bidi/script/exception_details.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import pytest | ||
|
||
from webdriver.bidi.modules.script import ContextTarget, ScriptEvaluateResultException | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize("await_promise", [True, False]) | ||
@pytest.mark.parametrize( | ||
"expression", | ||
[ | ||
"null", | ||
"{ toString: 'not a function' }", | ||
"{ toString: () => {{ throw 'toString not allowed'; }} }", | ||
"{ toString: () => true }", | ||
], | ||
) | ||
@pytest.mark.asyncio | ||
async def test_call_function_without_to_string_interface( | ||
bidi_session, top_context, await_promise, expression | ||
): | ||
function_declaration = "()=>{throw { toString: 'not a function' } }" | ||
if await_promise: | ||
function_declaration = "async" + function_declaration | ||
|
||
with pytest.raises(ScriptEvaluateResultException) as exception: | ||
await bidi_session.script.call_function( | ||
function_declaration=function_declaration, | ||
await_promise=await_promise, | ||
target=ContextTarget(top_context["context"]), | ||
) | ||
|
||
assert "exceptionDetails" in exception.value.result | ||
exceptionDetails = exception.value.result["exceptionDetails"] | ||
|
||
assert "text" in exceptionDetails | ||
assert isinstance(exceptionDetails["text"], str) | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize("await_promise", [True, False]) | ||
@pytest.mark.parametrize( | ||
"expression", | ||
[ | ||
"null", | ||
"{ toString: 'not a function' }", | ||
"{ toString: () => {{ throw 'toString not allowed'; }} }", | ||
"{ toString: () => true }", | ||
], | ||
) | ||
@pytest.mark.asyncio | ||
async def test_evaluate_without_to_string_interface( | ||
bidi_session, top_context, await_promise, expression | ||
): | ||
if await_promise: | ||
expression = f"Promise.reject({expression})" | ||
else: | ||
expression = f"throw {expression}" | ||
|
||
with pytest.raises(ScriptEvaluateResultException) as exception: | ||
await bidi_session.script.evaluate( | ||
expression=expression, | ||
await_promise=await_promise, | ||
target=ContextTarget(top_context["context"]), | ||
) | ||
|
||
assert "exceptionDetails" in exception.value.result | ||
exceptionDetails = exception.value.result["exceptionDetails"] | ||
|
||
assert "text" in exceptionDetails | ||
assert isinstance(exceptionDetails["text"], str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters