From e1c766bade79d1d411e122b86a4717e0de5bcbe2 Mon Sep 17 00:00:00 2001 From: Henrik Skupin Date: Tue, 28 Feb 2023 21:00:53 +0000 Subject: [PATCH] [wdspec] Enhance tests for execute (async) script for primitive values. Tests originally written by jugglinmike: https://github.com/web-platform-tests/wpt/pull/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 --- .../execute_async_script/execute_async.py | 21 +++++++++++++++++++ webdriver/tests/execute_script/execute.py | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/webdriver/tests/execute_async_script/execute_async.py b/webdriver/tests/execute_async_script/execute_async.py index d0b9daee4155ca..42cf4aacee8342 100644 --- a/webdriver/tests/execute_async_script/execute_async.py +++ b/webdriver/tests/execute_async_script/execute_async.py @@ -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( diff --git a/webdriver/tests/execute_script/execute.py b/webdriver/tests/execute_script/execute.py index adfd2836f32a4d..fbccc98633867b 100644 --- a/webdriver/tests/execute_script/execute.py +++ b/webdriver/tests/execute_script/execute.py @@ -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