Skip to content

Commit

Permalink
[wdspec] Enhance tests for execute (async) script for primitive values.
Browse files Browse the repository at this point in the history
Tests originally written by jugglinmike:
 #13880

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

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1819029
gecko-commit: f4cffe8e9381701473709db6054097d43396ce6e
gecko-reviewers: webdriver-reviewers, jdescottes
  • Loading branch information
whimboo authored and moz-wptsync-bot committed Mar 1, 2023
1 parent 377930f commit e1c766b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions webdriver/tests/execute_async_script/execute_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ def test_no_browsing_context(session, closed_frame):
assert_error(response, "no such window")


@pytest.mark.parametrize("expression, expected", [
("null", None),
("undefined", None),
("true", True),
("false", False),
("23", 23),
("'foo'", "foo"),
(
# Compute value in the runtime to reduce the potential for
# interference from encoding literal bytes or escape sequences in
# Python and HTTP.
"String.fromCharCode(0)",
"\x00"
)
])
def test_primitive_serialization(session, expression, expected):
response = execute_async_script(session, "arguments[0]({});".format(expression))
value = assert_success(response)
assert value == expected


@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_abort_by_user_prompt(session, dialog_type):
response = execute_async_script(
Expand Down
21 changes: 21 additions & 0 deletions webdriver/tests/execute_script/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ def test_no_browsing_context(session, closed_frame):
assert_error(response, "no such window")


@pytest.mark.parametrize("expression, expected", [
("null", None),
("undefined", None),
("true", True),
("false", False),
("23", 23),
("'foo'", "foo"),
(
# Compute value in the runtime to reduce the potential for
# interference from encoding literal bytes or escape sequences in
# Python and HTTP.
"String.fromCharCode(0)",
"\x00"
)
])
def test_primitive_serialization(session, expression, expected):
response = execute_script(session, "return {};".format(expression))
value = assert_success(response)
assert value == expected


def test_opening_new_window_keeps_current_window_handle(session, inline):
original_handle = session.window_handle
original_handles = session.handles
Expand Down

0 comments on commit e1c766b

Please sign in to comment.