Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webdriver] Test serialization of script values #13880

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions webdriver/tests/execute_async_script/execute_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ def test_no_browsing_context(session, closed_window):
assert_error(response, "no such window")


@pytest.mark.parametrize("expression,expected", [
("null", None),
("undefined", None),
("true", True),
("false", False),
("23", 23),
("'a string'", "a string"),
(
# Compute value in the runtime to reduce the potential for
# interference from encoding literal bytes or escape sequences in
# Python and HTTP.
"'a string with a null byte: [' + String.fromCharCode(0) + ']'",
"a string with a null byte: [\x00]"
)
])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Instead of parametrizing on a dictionary with primitive and expected keys, I feel it would read better if you just exposed both values as arguments:

@pytest.mark.parametrize("primitive,expected", [("null", None), ("undefined", None), ("true", True), …])
def test_primitive_serialization(session, primitive, expected):
    …

def test_primitive_serialization(session, expression, expected):
response = execute_async_script(
session, "arguments[0](%s);" % (expression,)
)
assert_success(response)
assert response.body["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 @@ -32,6 +32,27 @@ def test_ending_comment(session):
assert_success(response, 1)


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


@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_abort_by_user_prompt(session, dialog_type):
response = execute_script(
Expand Down