commit 80f703ee9209fedf674af875ebc07810a440c3f0
parent dba09acbc4fd06e4056655630e45f2c08570f078
Author: Julian Descottes <jdescottes@mozilla.com>
Date: Thu, 11 Dec 2025 07:24:33 +0000
Bug 2003857 - [wdspec] Add test for parallel calls to browsingContext.create r=Sasha
Differential Revision: https://phabricator.services.mozilla.com/D275235
Diffstat:
1 file changed, 40 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/create/background.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/create/background.py
@@ -1,3 +1,4 @@
+import asyncio
import pytest
pytestmark = pytest.mark.asyncio
@@ -30,3 +31,41 @@ async def test_background(bidi_session, top_context, type_hint, background):
assert await get_document_focus(bidi_session, new_context) != background
finally:
await bidi_session.browsing_context.close(context=new_context["context"])
+
+
+@pytest.mark.parametrize("type_hint", ["tab", "window"])
+@pytest.mark.parametrize("background", [True, False])
+async def test_create_in_parallel(
+ bidi_session, top_context, wait_for_future_safe, type_hint, background
+):
+ # Create 2 browsing contexts in quick succession, without waiting for
+ # the individual commands to resolve.
+ context_task_1 = asyncio.create_task(
+ bidi_session.browsing_context.create(type_hint="tab", background=background)
+ )
+ context_task_2 = asyncio.create_task(
+ bidi_session.browsing_context.create(type_hint="tab", background=background)
+ )
+
+ # Wait for both contexts to be created successfully
+ context_1 = await wait_for_future_safe(context_task_1)
+ context_2 = await wait_for_future_safe(context_task_2)
+
+ try:
+ if background:
+ # if background was true, the initial tab should still be selected
+ assert await get_visibility_state(bidi_session, top_context) == "visible"
+ assert await get_document_focus(bidi_session, top_context)
+ else:
+ # otherwise either context 1 or 2 might end up with the visibility and focus.
+ context_1_focus = await get_document_focus(bidi_session, context_1)
+ context_2_focus = await get_document_focus(bidi_session, context_2)
+ assert context_1_focus or context_2_focus
+
+ context_1_visible = await get_visibility_state(bidi_session, context_1) == "visible"
+ context_2_visible = await get_visibility_state(bidi_session, context_2) == "visible"
+ assert context_1_visible or context_2_visible
+
+ finally:
+ await bidi_session.browsing_context.close(context=context_1["context"])
+ await bidi_session.browsing_context.close(context=context_2["context"])
+\ No newline at end of file