Skip to content

Commit

Permalink
[WebDriverBiDi] Add test for originalOpener to `browsingContext.cre…
Browse files Browse the repository at this point in the history
…ated` (#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 <[email protected]>

---------

Co-authored-by: Alex Rudenko <[email protected]>
Co-authored-by: Henrik Skupin <[email protected]>
  • Loading branch information
3 people authored and sadym-chromium committed Jul 18, 2024
1 parent 495533c commit 3ed35e6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions webdriver/tests/bidi/browsing_context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]
)

0 comments on commit 3ed35e6

Please sign in to comment.