Skip to content

Commit

Permalink
[wdspec] Fix call_function/arguments.py | test_primitive_value for Nu…
Browse files Browse the repository at this point in the history
…mber.NaN.

Differential Revision: https://phabricator.services.mozilla.com/D185158

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1846744
gecko-commit: fe331e7b17f97ad284e93d013f9dcf6d587e0aa3
gecko-reviewers: webdriver-reviewers, jdescottes
  • Loading branch information
whimboo authored and moz-wptsync-bot committed Aug 3, 2023
1 parent ecd28aa commit 2bdb8f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
2 changes: 1 addition & 1 deletion webdriver/tests/bidi/script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def any_stack_frame(actual: Any) -> None:
("null", {"type": "null"}),
("'foobar'", {"type": "string", "value": "foobar"}),
("'2'", {"type": "string", "value": "2"}),
("Number.NaN", {"type": "number", "value": "NaN"}),
("NaN", {"type": "number", "value": "NaN"}),
("-0", {"type": "number", "value": "-0"}),
("Infinity", {"type": "number", "value": "Infinity"}),
("-Infinity", {"type": "number", "value": "-Infinity"}),
Expand Down
24 changes: 5 additions & 19 deletions webdriver/tests/bidi/script/call_function/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ async def test_default_arguments(bidi_session, top_context):
async def test_primitive_value(bidi_session, top_context, argument, expected):
result = await bidi_session.script.call_function(
function_declaration=f"""(arg) => {{
if (arg !== {expected}) {{
if (typeof {expected} === "number" && isNaN({expected})) {{
if (!isNaN(arg)) {{
throw new Error(`Argument should be {expected}, but was ` + arg);
}}
}} else if (arg !== {expected}) {{
throw new Error(`Argument should be {expected}, but was ` + arg);
}}
return arg;
Expand All @@ -36,24 +40,6 @@ async def test_primitive_value(bidi_session, top_context, argument, expected):
recursive_compare(argument, result)


@pytest.mark.asyncio
async def test_primitive_value_NaN(bidi_session, top_context):
nan_remote_value = {"type": "number", "value": "NaN"}
result = await bidi_session.script.call_function(
function_declaration="""(arg) => {
if (!isNaN(arg)) {
throw new Error("Argument should be 'NaN', but was " + arg);
}
return arg;
}""",
arguments=[nan_remote_value],
await_promise=False,
target=ContextTarget(top_context["context"]),
)

recursive_compare(nan_remote_value, result)


@pytest.mark.asyncio
@pytest.mark.parametrize(
"argument, expected_type",
Expand Down

0 comments on commit 2bdb8f3

Please sign in to comment.