diff --git a/webdriver/tests/execute_async_script/execute_async.py b/webdriver/tests/execute_async_script/execute_async.py index 7c454eaf4ac4f8..03f82ad8ccd5eb 100644 --- a/webdriver/tests/execute_async_script/execute_async.py +++ b/webdriver/tests/execute_async_script/execute_async.py @@ -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]" + ) + ]) +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( diff --git a/webdriver/tests/execute_script/execute.py b/webdriver/tests/execute_script/execute.py index 2af16c1e5e8a3b..d8aa481b25730d 100644 --- a/webdriver/tests/execute_script/execute.py +++ b/webdriver/tests/execute_script/execute.py @@ -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(