From 3ed35e6dc64966569012f537f09230c91750fec1 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:49:09 +0200 Subject: [PATCH] [WebDriverBiDi] Add test for `originalOpener` to `browsingContext.created` (#46754) * [WebDriverBiDi] Add test for `originalOpener` to `browsingContext.created` * chore: fix comments * chore: update comment * Update webdriver/tests/bidi/browsing_context/context_created/original_opener.py Co-authored-by: Henrik Skupin --------- Co-authored-by: Alex Rudenko Co-authored-by: Henrik Skupin --- .../tests/bidi/browsing_context/__init__.py | 2 + .../context_created/original_opener.py | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 webdriver/tests/bidi/browsing_context/context_created/original_opener.py diff --git a/webdriver/tests/bidi/browsing_context/__init__.py b/webdriver/tests/bidi/browsing_context/__init__.py index 91899eb50df49b1..a60940d370fdd7f 100644 --- a/webdriver/tests/bidi/browsing_context/__init__.py +++ b/webdriver/tests/bidi/browsing_context/__init__.py @@ -18,6 +18,7 @@ def assert_browsing_context( parent=None, url=None, user_context="default", + original_opener=None ): assert "children" in info if children is not None: @@ -51,6 +52,7 @@ def assert_browsing_context( assert isinstance(info["url"], str) assert info["url"] == url assert info["userContext"] == user_context + assert info["originalOpener"] == original_opener async def assert_document_status(bidi_session, context, visible, focused): diff --git a/webdriver/tests/bidi/browsing_context/context_created/original_opener.py b/webdriver/tests/bidi/browsing_context/context_created/original_opener.py new file mode 100644 index 000000000000000..4d984e6f5150cd3 --- /dev/null +++ b/webdriver/tests/bidi/browsing_context/context_created/original_opener.py @@ -0,0 +1,63 @@ +import pytest +from webdriver.bidi.modules.script import ContextTarget + +from .. import assert_browsing_context + +pytestmark = pytest.mark.asyncio + +CONTEXT_CREATED_EVENT = "browsingContext.contextCreated" + + +@pytest.mark.parametrize("type_hint", ["tab", "window"]) +async def test_original_opener_context_create(bidi_session, wait_for_event, wait_for_future_safe, subscribe_events, type_hint): + + await subscribe_events([CONTEXT_CREATED_EVENT]) + on_entry = wait_for_event(CONTEXT_CREATED_EVENT) + + top_level_context = await bidi_session.browsing_context.create(type_hint=type_hint) + + context_info = await wait_for_future_safe(on_entry) + + assert_browsing_context( + context_info, + context=top_level_context["context"], + original_opener=None + ) + + +@pytest.mark.parametrize("type_hint", ["tab", "window"]) +@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"]) +@pytest.mark.parametrize("features, returns_window", [ + ("", True), + ("popup", True), + ("noopener", False), + ("noreferrer", False) +] +) +async def test_original_opener_window_open(bidi_session, wait_for_event, wait_for_future_safe, subscribe_events, inline, + type_hint, domain, features, returns_window): + + top_level_context = await bidi_session.browsing_context.create(type_hint=type_hint) + + await subscribe_events([CONTEXT_CREATED_EVENT]) + on_entry = wait_for_event(CONTEXT_CREATED_EVENT) + + url = inline("", domain=domain) + + result = await bidi_session.script.evaluate( + expression=f"""window.open("{url}", "_blank", "{features}");""", + target=ContextTarget(top_level_context["context"]), + await_promise=False) + + context_info = await wait_for_future_safe(on_entry) + + # We use None here as evaluate not always returns value. + context = None + if returns_window: + context = result["value"]["context"] + + assert_browsing_context( + context_info, + context=context, + original_opener=top_level_context["context"] + )