summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/webdriver/bidi
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/mozilla/tests/webdriver/bidi')
-rw-r--r--testing/web-platform/mozilla/tests/webdriver/bidi/browsing_context/navigate/error.py14
-rw-r--r--testing/web-platform/mozilla/tests/webdriver/bidi/storage/delete_cookies/__init__.py0
-rw-r--r--testing/web-platform/mozilla/tests/webdriver/bidi/storage/delete_cookies/partition.py114
-rw-r--r--testing/web-platform/mozilla/tests/webdriver/bidi/storage/get_cookies/partition.py53
-rw-r--r--testing/web-platform/mozilla/tests/webdriver/bidi/storage/set_cookie/partition.py25
5 files changed, 166 insertions, 40 deletions
diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/browsing_context/navigate/error.py b/testing/web-platform/mozilla/tests/webdriver/bidi/browsing_context/navigate/error.py
index 374359d1ae..ea76b13727 100644
--- a/testing/web-platform/mozilla/tests/webdriver/bidi/browsing_context/navigate/error.py
+++ b/testing/web-platform/mozilla/tests/webdriver/bidi/browsing_context/navigate/error.py
@@ -1,4 +1,3 @@
-import os
from copy import deepcopy
import pytest
@@ -7,13 +6,12 @@ from tests.bidi.browsing_context.navigate import navigate_and_assert
pytestmark = pytest.mark.asyncio
-async def test_insecure_certificate(configuration, url, custom_profile, geckodriver):
- try:
- # Create a new profile and remove the certificate storage so that
- # loading a HTTPS page will cause an insecure certificate error
- os.remove(os.path.join(custom_profile.profile, "cert9.db"))
- except Exception:
- pass
+async def test_insecure_certificate(
+ configuration, url, create_custom_profile, geckodriver
+):
+ # Create a fresh profile without any item in the certificate storage so that
+ # loading a HTTPS page will cause an insecure certificate error
+ custom_profile = create_custom_profile(clone=False)
config = deepcopy(configuration)
config["capabilities"]["moz:firefoxOptions"]["args"] = [
diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/storage/delete_cookies/__init__.py b/testing/web-platform/mozilla/tests/webdriver/bidi/storage/delete_cookies/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/webdriver/bidi/storage/delete_cookies/__init__.py
diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/storage/delete_cookies/partition.py b/testing/web-platform/mozilla/tests/webdriver/bidi/storage/delete_cookies/partition.py
new file mode 100644
index 0000000000..d8e2729fe2
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/webdriver/bidi/storage/delete_cookies/partition.py
@@ -0,0 +1,114 @@
+import pytest
+from tests.bidi import recursive_compare
+from tests.support.helpers import get_origin_from_url
+from webdriver.bidi.modules.network import NetworkStringValue
+from webdriver.bidi.modules.storage import (
+ BrowsingContextPartitionDescriptor,
+ PartialCookie,
+)
+
+pytestmark = pytest.mark.asyncio
+
+
+@pytest.mark.parametrize(
+ "with_document_cookie",
+ [True, False],
+ ids=["with document cookie", "with set cookie"],
+)
+async def test_partition_context(
+ bidi_session,
+ new_tab,
+ test_page,
+ domain_value,
+ add_cookie,
+ set_cookie,
+ with_document_cookie,
+):
+ await bidi_session.browsing_context.navigate(
+ context=new_tab["context"], url=test_page, wait="complete"
+ )
+
+ cookie_name = "foo"
+ cookie_value = "bar"
+ source_origin = get_origin_from_url(test_page)
+ partition = BrowsingContextPartitionDescriptor(new_tab["context"])
+ if with_document_cookie:
+ await add_cookie(new_tab["context"], cookie_name, cookie_value)
+ else:
+ await set_cookie(
+ cookie=PartialCookie(
+ domain=domain_value(),
+ name=cookie_name,
+ value=NetworkStringValue(cookie_value),
+ ),
+ partition=partition,
+ )
+
+ result = await bidi_session.storage.delete_cookies(partition=partition)
+ recursive_compare({"partitionKey": {"sourceOrigin": source_origin}}, result)
+
+ result = await bidi_session.storage.get_cookies(partition=partition)
+ assert result["cookies"] == []
+
+
+@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"])
+async def test_partition_context_iframe_with_set_cookie(
+ bidi_session, new_tab, inline, domain_value, domain, set_cookie
+):
+ iframe_url = inline("<div id='in-iframe'>foo</div>", domain=domain)
+ page_url = inline(f"<iframe src='{iframe_url}'></iframe>")
+ await bidi_session.browsing_context.navigate(
+ context=new_tab["context"], url=page_url, wait="complete"
+ )
+ source_origin = get_origin_from_url(iframe_url)
+
+ contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"])
+ iframe_context = contexts[0]["children"][0]
+
+ cookie_name = "foo"
+ cookie_value = "bar"
+ frame_partition = BrowsingContextPartitionDescriptor(iframe_context["context"])
+ await set_cookie(
+ cookie=PartialCookie(
+ domain=domain_value(domain),
+ name=cookie_name,
+ value=NetworkStringValue(cookie_value),
+ ),
+ partition=frame_partition,
+ )
+
+ result = await bidi_session.storage.delete_cookies(partition=frame_partition)
+ recursive_compare({"partitionKey": {"sourceOrigin": source_origin}}, result)
+
+ result = await bidi_session.storage.get_cookies(partition=frame_partition)
+ assert result["cookies"] == []
+
+
+# Because of Dynamic First-Party Isolation, adding the cookie with `document.cookie`
+# works only with same-origin iframes.
+async def test_partition_context_same_origin_iframe_with_document_cookie(
+ bidi_session,
+ new_tab,
+ inline,
+ add_cookie,
+):
+ iframe_url = inline("<div id='in-iframe'>foo</div>")
+ page_url = inline(f"<iframe src='{iframe_url}'></iframe>")
+ await bidi_session.browsing_context.navigate(
+ context=new_tab["context"], url=page_url, wait="complete"
+ )
+ source_origin = get_origin_from_url(iframe_url)
+
+ contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"])
+ iframe_context = contexts[0]["children"][0]
+
+ cookie_name = "foo"
+ cookie_value = "bar"
+ frame_partition = BrowsingContextPartitionDescriptor(iframe_context["context"])
+ await add_cookie(iframe_context["context"], cookie_name, cookie_value)
+
+ result = await bidi_session.storage.delete_cookies(partition=frame_partition)
+ recursive_compare({"partitionKey": {"sourceOrigin": source_origin}}, result)
+
+ result = await bidi_session.storage.get_cookies(partition=frame_partition)
+ assert result["cookies"] == []
diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/storage/get_cookies/partition.py b/testing/web-platform/mozilla/tests/webdriver/bidi/storage/get_cookies/partition.py
index b037c30038..5503f13224 100644
--- a/testing/web-platform/mozilla/tests/webdriver/bidi/storage/get_cookies/partition.py
+++ b/testing/web-platform/mozilla/tests/webdriver/bidi/storage/get_cookies/partition.py
@@ -59,18 +59,22 @@ async def test_partition_context(
)
recursive_compare(
- {"cookies": [], "partitionKey": {"sourceOrigin": source_origin_2}}, cookies
+ {
+ "cookies": [],
+ "partitionKey": {"sourceOrigin": source_origin_2, "userContext": "default"},
+ },
+ cookies,
)
-@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"])
-async def test_partition_context_iframe(
- bidi_session, new_tab, inline, domain_value, domain, add_cookie
+# Because of Dynamic First-Party Isolation, adding the cookie with `document.cookie`
+# works only with same-origin iframes.
+async def test_partition_context_same_origin_iframe(
+ bidi_session, new_tab, inline, domain_value, add_cookie
):
- iframe_url = inline("<div id='in-iframe'>foo</div>", domain=domain)
- source_origin_for_iframe = get_origin_from_url(iframe_url)
+ iframe_url = inline("<div id='in-iframe'>foo</div>")
+ source_origin = get_origin_from_url(iframe_url)
page_url = inline(f"<iframe src='{iframe_url}'></iframe>")
- source_origin_for_page = get_origin_from_url(page_url)
await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=page_url, wait="complete"
)
@@ -89,7 +93,7 @@ async def test_partition_context_iframe(
expected_cookies = [
{
- "domain": domain_value(domain=domain),
+ "domain": domain_value(),
"httpOnly": False,
"name": cookie_name,
"path": "/webdriver/tests/support",
@@ -99,10 +103,11 @@ async def test_partition_context_iframe(
"value": {"type": "string", "value": cookie_value},
}
]
+
recursive_compare(
{
"cookies": expected_cookies,
- "partitionKey": {"sourceOrigin": source_origin_for_iframe},
+ "partitionKey": {"sourceOrigin": source_origin},
},
cookies,
)
@@ -110,22 +115,16 @@ async def test_partition_context_iframe(
cookies = await bidi_session.storage.get_cookies(
partition=BrowsingContextPartitionDescriptor(new_tab["context"])
)
- # When the iframe is on the different domain we can verify that top context has no iframe cookie.
- if domain == "alt":
- recursive_compare(
- {
- "cookies": [],
- "partitionKey": {"sourceOrigin": source_origin_for_page},
- },
- cookies,
- )
- else:
- # When the iframe is on the same domain, since the browsing context partition is defined by user context and origin,
- # which will be the same for the page, we get the same cookies as for the iframe
- recursive_compare(
- {
- "cookies": expected_cookies,
- "partitionKey": {"sourceOrigin": source_origin_for_page},
+
+ # When the iframe is on the same domain, since the browsing context partition is defined by user context and origin,
+ # which will be the same for the page, we get the same cookies as for the iframe.
+ recursive_compare(
+ {
+ "cookies": expected_cookies,
+ "partitionKey": {
+ "sourceOrigin": source_origin,
+ "userContext": "default",
},
- cookies,
- )
+ },
+ cookies,
+ )
diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/storage/set_cookie/partition.py b/testing/web-platform/mozilla/tests/webdriver/bidi/storage/set_cookie/partition.py
index f8e2823dbc..a9b5d3a43a 100644
--- a/testing/web-platform/mozilla/tests/webdriver/bidi/storage/set_cookie/partition.py
+++ b/testing/web-platform/mozilla/tests/webdriver/bidi/storage/set_cookie/partition.py
@@ -42,7 +42,9 @@ async def test_partition_context(
partition=new_tab_partition,
)
- assert set_cookie_result == {"partitionKey": {"sourceOrigin": source_origin_1}}
+ assert set_cookie_result == {
+ "partitionKey": {"sourceOrigin": source_origin_1, "userContext": "default"}
+ }
# Check that added cookies are present on the right context.
cookies = await bidi_session.storage.get_cookies(partition=new_tab_partition)
@@ -72,7 +74,11 @@ async def test_partition_context(
)
recursive_compare(
- {"cookies": [], "partitionKey": {"sourceOrigin": source_origin_2}}, cookies
+ {
+ "cookies": [],
+ "partitionKey": {"sourceOrigin": source_origin_2, "userContext": "default"},
+ },
+ cookies,
)
@@ -121,7 +127,10 @@ async def test_partition_context_iframe(
recursive_compare(
{
"cookies": expected_cookies,
- "partitionKey": {"sourceOrigin": source_origin_for_iframe},
+ "partitionKey": {
+ "sourceOrigin": source_origin_for_iframe,
+ "userContext": "default",
+ },
},
cookies,
)
@@ -134,7 +143,10 @@ async def test_partition_context_iframe(
recursive_compare(
{
"cookies": [],
- "partitionKey": {"sourceOrigin": source_origin_for_page},
+ "partitionKey": {
+ "sourceOrigin": source_origin_for_page,
+ "userContext": "default",
+ },
},
cookies,
)
@@ -144,7 +156,10 @@ async def test_partition_context_iframe(
recursive_compare(
{
"cookies": expected_cookies,
- "partitionKey": {"sourceOrigin": source_origin_for_page},
+ "partitionKey": {
+ "sourceOrigin": source_origin_for_page,
+ "userContext": "default",
+ },
},
cookies,
)