commit 5a83a161a49512e0b29ee83d178b015b77da334f
parent 26756143306596419f04518a7d622061fff035a9
Author: Henrik Skupin <mail@hskupin.info>
Date: Tue, 9 Dec 2025 14:06:20 +0000
Bug 1944568 - [wdspec] Add "new_window" fixture and improve browsing context assertions. r=jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D275231
Diffstat:
3 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/__init__.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/__init__.py
@@ -14,12 +14,12 @@ def assert_browsing_context(
info,
context,
children=None,
+ client_window=None,
original_opener=None,
parent_expected=True,
parent=None,
url=None,
user_context="default",
- client_window=None
):
assert "children" in info
if children is not None:
@@ -28,6 +28,14 @@ def assert_browsing_context(
else:
assert info["children"] is None
+ assert "clientWindow" in info
+ assert isinstance(info["clientWindow"], str)
+ # Note: Only the tests for browsingContext.getTree should be allowed to
+ # pass None here because it's not possible to assert the exact client
+ # window id for other browser windows.
+ if client_window is not None:
+ assert info["clientWindow"] == client_window
+
assert "context" in info
assert isinstance(info["context"], str)
# Note: Only the tests for browsingContext.getTree should be allowed to
@@ -54,7 +62,6 @@ def assert_browsing_context(
assert info["url"] == url
assert info["userContext"] == user_context
assert info["originalOpener"] == original_opener
- assert info["clientWindow"] == client_window
async def assert_document_status(bidi_session, context, visible, focused):
diff --git a/testing/web-platform/tests/webdriver/tests/support/fixtures.py b/testing/web-platform/tests/webdriver/tests/support/fixtures.py
@@ -510,9 +510,3 @@ async function getText() {
""" % encoded_pdf_data)
return test_page_with_pdf_js
-
-
-@pytest_asyncio.fixture
-async def top_context(bidi_session):
- contexts = await bidi_session.browsing_context.get_tree()
- return contexts[0]
diff --git a/testing/web-platform/tests/webdriver/tests/support/fixtures_bidi.py b/testing/web-platform/tests/webdriver/tests/support/fixtures_bidi.py
@@ -115,16 +115,45 @@ async def set_cookie(bidi_session):
@pytest_asyncio.fixture
+async def top_context(bidi_session):
+ contexts = await bidi_session.browsing_context.get_tree()
+ return contexts[0]
+
+
+@pytest_asyncio.fixture
async def new_tab(bidi_session):
"""Open and focus a new tab to run the test in a foreground tab."""
- new_tab = await bidi_session.browsing_context.create(type_hint='tab')
+ result = await bidi_session.browsing_context.create(type_hint="tab")
+ contexts_info = await bidi_session.browsing_context.get_tree(
+ root=result["context"], max_depth=0
+ )
+
+ yield contexts_info[0]
+
+ try:
+ await bidi_session.browsing_context.close(context=contexts_info[0]["context"])
+ except NoSuchFrameException:
+ print(
+ f"Tab with context id {contexts_info[0]['context']} has already been closed"
+ )
+
- yield new_tab
+@pytest_asyncio.fixture
+async def new_window(bidi_session):
+ """Open a new window and focus the first tab to run the test in a foreground tab."""
+ result = await bidi_session.browsing_context.create(type_hint="window")
+ contexts_info = await bidi_session.browsing_context.get_tree(
+ root=result["context"], max_depth=0
+ )
+
+ yield contexts_info[0]
try:
- await bidi_session.browsing_context.close(context=new_tab["context"])
+ await bidi_session.browsing_context.close(context=contexts_info[0]["context"])
except NoSuchFrameException:
- print(f"Tab with id {new_tab['context']} has already been closed")
+ print(
+ f"Window with context id {contexts_info[0]['context']} has already been closed"
+ )
@pytest.fixture