From 06ed3db3fc5f4b0044e636e20566be9bbc762ae3 Mon Sep 17 00:00:00 2001 From: Henrik Skupin Date: Tue, 28 Feb 2023 20:55:55 +0000 Subject: [PATCH] Bug 1819029 - [wdspec] Enhance tests for execute (async) script for primitive values. r=webdriver-reviewers,jdescottes Tests originally written by jugglinmike: https://github.com/web-platform-tests/wpt/pull/13880 Differential Revision: https://phabricator.services.mozilla.com/D171234 --- .../execute_async_script/execute_async.py | 21 +++++++++++++++++++ .../webdriver/tests/execute_script/execute.py | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/testing/web-platform/tests/webdriver/tests/execute_async_script/execute_async.py b/testing/web-platform/tests/webdriver/tests/execute_async_script/execute_async.py index d0b9daee4155c..42cf4aacee834 100644 --- a/testing/web-platform/tests/webdriver/tests/execute_async_script/execute_async.py +++ b/testing/web-platform/tests/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/testing/web-platform/tests/webdriver/tests/execute_script/execute.py b/testing/web-platform/tests/webdriver/tests/execute_script/execute.py index adfd2836f32a4..fbccc98633867 100644 --- a/testing/web-platform/tests/webdriver/tests/execute_script/execute.py +++ b/testing/web-platform/tests/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