commit 3aba5f11a2edf9d1f1ad6a42d374ddd55995c5e7
parent a143d95449674d6f4ed1b100a015bdb25a7cf9c9
Author: elkal98 <khalid.alhaddad98@gmail.com>
Date: Mon, 1 Dec 2025 20:53:09 +0000
Bug 1983822 - [wdspec] Add tests for WebDriver classic's "Get All Cookies" command. r=whimboo
Differential Revision: https://phabricator.services.mozilla.com/D271920
Diffstat:
3 files changed, 241 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/webdriver/tests/classic/get_all_cookies/__init__.py b/testing/web-platform/tests/webdriver/tests/classic/get_all_cookies/__init__.py
@@ -0,0 +1,4 @@
+def get_all_cookies(session):
+ return session.transport.send(
+ "GET", "/session/{session_id}/cookie".format(**vars(session))
+ )
diff --git a/testing/web-platform/tests/webdriver/tests/classic/get_all_cookies/get.py b/testing/web-platform/tests/webdriver/tests/classic/get_all_cookies/get.py
@@ -0,0 +1,89 @@
+import pytest
+
+from tests.support.asserts import assert_error, assert_success
+from . import get_all_cookies
+
+
+@pytest.fixture(autouse=True)
+def clean_up_cookies(session):
+ # Ensure that any test in the file does not navigate away once done with checking the cookies.
+ session.transport.send("DELETE", "session/%s/cookie" % session.session_id)
+
+
+def test_no_top_browsing_context(session, closed_window):
+ response = get_all_cookies(session)
+ assert_error(response, "no such window")
+
+
+def test_no_browsing_context(session, closed_frame):
+ response = get_all_cookies(session)
+ assert_error(response, "no such window")
+
+
+def test_get_multiple_cookies(session, url):
+ session.url = url("/common/blank.html")
+ session.execute_script("document.cookie = 'foo=bar'")
+ session.execute_script("document.cookie = 'hello=world'")
+
+ result = get_all_cookies(session)
+ cookies = assert_success(result)
+ assert isinstance(cookies, list)
+
+ expected_cookies = [
+ {
+ "name": "foo",
+ "value": "bar",
+ "path": "/common",
+ "domain": "web-platform" + ".test",
+ "secure": False,
+ "httpOnly": False,
+ "sameSite": "None",
+ },
+ {
+ "name": "hello",
+ "value": "world",
+ "path": "/common",
+ "domain": "web-platform" + ".test",
+ "secure": False,
+ "httpOnly": False,
+ "sameSite": "None",
+ },
+ ]
+
+ assert len(cookies) == len(expected_cookies)
+
+
+def test_get_cookies_only_from_active_document(session, url, create_cookie):
+ # Set cookies for two different pages.
+ create_cookie("foo", value="bar", path="/common/blank.html")
+ create_cookie("hello", value="world", path="/common/blank.html")
+ create_cookie("abc", value="xyz", path="/example/index.html")
+ create_cookie("mock", value="dummy", path="/example/index.html")
+
+ session.url = url("/common/blank.html")
+ result = get_all_cookies(session)
+ cookies = assert_success(result)
+ assert isinstance(cookies, list)
+
+ expected_cookies = [
+ {
+ "name": "foo",
+ "value": "bar",
+ "path": "/common/blank.html",
+ "domain": "web-platform" + ".test",
+ "secure": False,
+ "httpOnly": False,
+ "sameSite": "None",
+ },
+ {
+ "name": "hello",
+ "value": "world",
+ "path": "/common/blank.html",
+ "domain": "web-platform" + ".test",
+ "secure": False,
+ "httpOnly": False,
+ "sameSite": "None",
+ },
+ ]
+
+ assert cookies == expected_cookies
diff --git a/testing/web-platform/tests/webdriver/tests/classic/get_all_cookies/user_prompts.py b/testing/web-platform/tests/webdriver/tests/classic/get_all_cookies/user_prompts.py
@@ -0,0 +1,148 @@
+# META: timeout=long
+
+import pytest
+
+from tests.support.asserts import assert_dialog_handled, assert_error, assert_success
+from . import get_all_cookies
+
+
+@pytest.fixture
+def check_user_prompt_closed_without_exception(session, create_dialog, create_cookie):
+ def check_user_prompt_closed_without_exception(dialog_type, retval):
+ create_cookie("foo", value="bar", path="/common/blank.html")
+
+ create_dialog(dialog_type, text="cheese")
+
+ response = get_all_cookies(session)
+ assert_success(response)
+
+ assert_dialog_handled(
+ session, expected_text=dialog_type, expected_retval=retval
+ )
+
+ expected = [
+ {
+ "name": "foo",
+ "value": "bar",
+ "path": "/common/blank.html",
+ "domain": "web-platform" + ".test",
+ "secure": False,
+ "httpOnly": False,
+ "sameSite": "None",
+ }
+ ]
+
+ assert_success(response, expected)
+
+ return check_user_prompt_closed_without_exception
+
+
+@pytest.fixture
+def check_user_prompt_closed_with_exception(session, create_dialog, create_cookie):
+ def check_user_prompt_closed_with_exception(dialog_type, retval):
+ create_cookie("foo", value="bar", path="/common/blank.html")
+
+ create_dialog(dialog_type, text="cheese")
+
+ response = get_all_cookies(session)
+ assert_error(response, "unexpected alert open", data={"text": "cheese"})
+
+ assert_dialog_handled(
+ session, expected_text=dialog_type, expected_retval=retval
+ )
+
+ assert session.cookies() != []
+
+ return check_user_prompt_closed_with_exception
+
+
+@pytest.fixture
+def check_user_prompt_not_closed_but_exception(session, create_dialog, create_cookie):
+ def check_user_prompt_not_closed_but_exception(dialog_type):
+ create_cookie("foo", value="bar", path="/common/blank.html")
+
+ create_dialog(dialog_type, text="cheese")
+
+ response = get_all_cookies(session)
+ assert_error(response, "unexpected alert open", data={"text": "cheese"})
+
+ assert session.alert.text == "cheese"
+ session.alert.dismiss()
+
+ assert session.cookies() != []
+
+ return check_user_prompt_not_closed_but_exception
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
+@pytest.mark.parametrize(
+ "dialog_type, retval",
+ [
+ ("alert", None),
+ ("confirm", True),
+ ("prompt", ""),
+ ],
+)
+def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
+ check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
+@pytest.mark.parametrize(
+ "dialog_type, retval",
+ [
+ ("alert", None),
+ ("confirm", True),
+ ("prompt", ""),
+ ],
+)
+def test_accept_and_notify(
+ check_user_prompt_closed_with_exception, dialog_type, retval
+):
+ check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
+@pytest.mark.parametrize(
+ "dialog_type, retval",
+ [
+ ("alert", None),
+ ("confirm", False),
+ ("prompt", None),
+ ],
+)
+def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
+ check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
+@pytest.mark.parametrize(
+ "dialog_type, retval",
+ [
+ ("alert", None),
+ ("confirm", False),
+ ("prompt", None),
+ ],
+)
+def test_dismiss_and_notify(
+ check_user_prompt_closed_with_exception, dialog_type, retval
+):
+ check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
+ check_user_prompt_not_closed_but_exception(dialog_type)
+
+
+@pytest.mark.parametrize(
+ "dialog_type, retval",
+ [
+ ("alert", None),
+ ("confirm", False),
+ ("prompt", None),
+ ],
+)
+def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
+ check_user_prompt_closed_with_exception(dialog_type, retval)