forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create dedicated tests for script.evaluate exceptionDetails
- Loading branch information
1 parent
0c81808
commit 8815898
Showing
2 changed files
with
123 additions
and
45 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
122 changes: 122 additions & 0 deletions
122
webdriver/tests/bidi/script/evaluate/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,122 @@ | ||
import pytest | ||
|
||
from webdriver.bidi.modules.script import ContextTarget, ScriptEvaluateResultException | ||
|
||
from ... import any_int, any_string, recursive_compare | ||
from .. import any_stack_trace | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_invalid_script(bidi_session, top_context): | ||
with pytest.raises(ScriptEvaluateResultException) as exception: | ||
await bidi_session.script.evaluate( | ||
expression='))) !!@@## some invalid JS script (((', | ||
target=ContextTarget(top_context["context"]), | ||
await_promise=True) | ||
recursive_compare({ | ||
'realm': any_string, | ||
'exceptionDetails': { | ||
'columnNumber': any_int, | ||
'exception': { | ||
'handle': any_string, | ||
'type': 'error'}, | ||
'lineNumber': any_int, | ||
'stackTrace': any_stack_trace, | ||
'text': any_string}}, | ||
exception.value.result) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_reject_complex_value(bidi_session, top_context): | ||
with pytest.raises(ScriptEvaluateResultException) as exception: | ||
await bidi_session.script.evaluate( | ||
expression="Promise.reject(new Set(['SOME_REJECTED_RESULT']))", | ||
target=ContextTarget(top_context["context"]), | ||
await_promise=True, | ||
) | ||
|
||
recursive_compare( | ||
{ | ||
"realm": any_string, | ||
"exceptionDetails": { | ||
"columnNumber": any_int, | ||
"exception": { | ||
"type": "set", "value": [ | ||
{"type": "string", "value": "SOME_REJECTED_RESULT"} | ||
] | ||
}, | ||
"lineNumber": any_int, | ||
"stackTrace": any_stack_trace, | ||
"text": any_string, | ||
}, | ||
}, | ||
exception.value.result, | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_reject_error(bidi_session, top_context): | ||
with pytest.raises(ScriptEvaluateResultException) as exception: | ||
await bidi_session.script.evaluate( | ||
expression="Promise.reject(new Error('SOME_ERROR_MESSAGE'))", | ||
target=ContextTarget(top_context["context"]), | ||
await_promise=True, | ||
) | ||
|
||
recursive_compare( | ||
{ | ||
"realm": any_string, | ||
"exceptionDetails": { | ||
"columnNumber": any_int, | ||
"exception": { | ||
"handle": any_string, | ||
"type": "error"}, | ||
"lineNumber": any_int, | ||
"stackTrace": any_stack_trace, | ||
"text": any_string, | ||
}, | ||
}, | ||
exception.value.result, | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_throw_error(bidi_session, top_context): | ||
with pytest.raises(ScriptEvaluateResultException) as exception: | ||
await bidi_session.script.evaluate( | ||
expression="throw Error('SOME_ERROR_MESSAGE')", | ||
target=ContextTarget(top_context["context"]), | ||
await_promise=True) | ||
|
||
recursive_compare({ | ||
'realm': any_string, | ||
'exceptionDetails': { | ||
'columnNumber': any_int, | ||
'exception': { | ||
'handle': any_string, | ||
'type': 'error'}, | ||
'lineNumber': any_int, | ||
'stackTrace': any_stack_trace, | ||
'text': any_string}}, | ||
exception.value.result) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_throw_string(bidi_session, top_context): | ||
with pytest.raises(ScriptEvaluateResultException) as exception: | ||
await bidi_session.script.evaluate( | ||
expression="throw 'SOME_STRING_ERROR'", | ||
target=ContextTarget(top_context["context"]), | ||
await_promise=True) | ||
|
||
recursive_compare({ | ||
'realm': any_string, | ||
'exceptionDetails': { | ||
'columnNumber': any_int, | ||
'exception': { | ||
'value': 'SOME_STRING_ERROR', | ||
'type': 'string'}, | ||
'lineNumber': any_int, | ||
'stackTrace': any_stack_trace, | ||
'text': any_string}}, | ||
exception.value.result) |