Skip to content

Commit

Permalink
[wdspec] Add test for browser.removeUserContext to check browsing con…
Browse files Browse the repository at this point in the history
…texts are closed

Depends on D200023

Differential Revision: https://phabricator.services.mozilla.com/D200339

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1874918
gecko-commit: 4be6b1980ac25cdf37cea10a1b246151b6646811
gecko-reviewers: webdriver-reviewers, whimboo
  • Loading branch information
juliandescottes authored and mbrodesser-Igalia committed Feb 19, 2024
1 parent 7f84fce commit b09034c
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions webdriver/tests/bidi/browser/remove_user_context/user_context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from tests.support.sync import AsyncPoll
import webdriver.bidi.error as error

from .. import get_user_context_ids
Expand All @@ -13,3 +14,62 @@ async def test_remove_context(bidi_session, create_user_context):
await bidi_session.browser.remove_user_context(user_context=user_context)
assert user_context not in await get_user_context_ids(bidi_session)
assert "default" in await get_user_context_ids(bidi_session)


@pytest.mark.parametrize("type_hint", ["tab", "window"])
@pytest.mark.asyncio
async def test_remove_context_closes_contexts(
bidi_session, subscribe_events, wait_for_event, create_user_context, type_hint
):
# Subscribe to all browsing context events
await subscribe_events(events=["browsingContext.contextDestroyed"])

user_context_1 = await create_user_context()
user_context_2 = await create_user_context()

# context 1 and 2 are owned by user context 1
context_1 = await bidi_session.browsing_context.create(
user_context=user_context_1, type_hint=type_hint
)
context_2 = await bidi_session.browsing_context.create(
user_context=user_context_1, type_hint=type_hint
)
# context 3 and 4 are owned by user context 2
context_3 = await bidi_session.browsing_context.create(
user_context=user_context_2, type_hint=type_hint
)
context_4 = await bidi_session.browsing_context.create(
user_context=user_context_2, type_hint=type_hint
)

# Track all received browsingContext.contextDestroyed events in the events array
events = []

async def on_event(method, data):
events.append(data)

remove_listener = bidi_session.add_event_listener("browsingContext.contextDestroyed", on_event)

# destroy user context 1 and wait for context 1 and 2 to be destroyed
await bidi_session.browser.remove_user_context(user_context=user_context_1)

wait = AsyncPoll(bidi_session, timeout=2)
await wait.until(lambda _: len(events) >= 2)

assert len(events) == 2
destroyed_contexts = [event["context"] for event in events]
assert context_1["context"] in destroyed_contexts
assert context_2["context"] in destroyed_contexts

# destroy user context 1 and wait for context 3 and 4 to be destroyed
await bidi_session.browser.remove_user_context(user_context=user_context_2)

wait = AsyncPoll(bidi_session, timeout=2)
await wait.until(lambda _: len(events) >= 4)

assert len(events) == 4
destroyed_contexts = [event["context"] for event in events]
assert context_3["context"] in destroyed_contexts
assert context_4["context"] in destroyed_contexts

remove_listener()

0 comments on commit b09034c

Please sign in to comment.