Skip to content

Commit

Permalink
[wdspec] Updating tests for serializing the full context tree for "br…
Browse files Browse the repository at this point in the history
…owsingContext.contextDestroyed" events.

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

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1860955
gecko-commit: ceff112065fd0b77f756c897a2d9f0e2d55d0749
gecko-reviewers: whimboo, webdriver-reviewers
  • Loading branch information
liamdebeasi authored and moz-wptsync-bot committed Jan 23, 2025
1 parent 0abe43d commit 9763308
Showing 1 changed file with 56 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def test_new_context(bidi_session, wait_for_event, wait_for_future_safe, s
assert_browsing_context(
context_info,
new_context["context"],
children=None,
children=0,
url="about:blank",
parent=None,
user_context="default"
Expand Down Expand Up @@ -105,31 +105,29 @@ async def test_navigate_iframe(
assert_browsing_context(
context_info,
frame["context"],
children=None,
children=0,
url=frame_url,
parent=new_tab["context"],
)


async def test_delete_iframe(
bidi_session, wait_for_event, wait_for_future_safe, subscribe_events, new_tab, inline
bidi_session, wait_for_event, wait_for_future_safe, subscribe_events, new_tab, inline, test_page_multiple_frames
):
await subscribe_events([CONTEXT_DESTROYED_EVENT])

on_entry = wait_for_event(CONTEXT_DESTROYED_EVENT)

frame_url = inline("<div>foo</div>")
url = inline(f"<iframe src='{frame_url}'></iframe>")
await bidi_session.browsing_context.navigate(
url=url, context=new_tab["context"], wait="complete"
url=test_page_multiple_frames, context=new_tab["context"], wait="complete"
)

contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"])
iframe = contexts[0]["children"][0]

# Delete the iframe
# Delete the first iframe
await bidi_session.script.evaluate(
expression="""document.querySelector('iframe').remove()""",
expression="""document.querySelector('iframe:nth-of-type(1)').remove()""",
target=ContextTarget(new_tab["context"]),
await_promise=False,
)
Expand All @@ -139,13 +137,13 @@ async def test_delete_iframe(
assert_browsing_context(
context_info,
iframe["context"],
children=None,
url=frame_url,
children=0,
url=iframe["url"],
parent=new_tab["context"],
)


async def test_delete_nested_iframes(
async def test_nested_iframes_delete_top_iframe(
bidi_session,
subscribe_events,
new_tab,
Expand Down Expand Up @@ -179,14 +177,58 @@ async def on_event(_, data):
assert_browsing_context(
events[0],
top_iframe["context"],
children=None,
children=1,
url=test_page_same_origin_frame,
parent=new_tab["context"],
)

remove_listener()


async def test_nested_iframes_delete_deepest_iframe(
bidi_session,
subscribe_events,
new_tab,
test_page_nested_frames,
test_page_same_origin_frame,
):
await subscribe_events([CONTEXT_DESTROYED_EVENT])
# Track all received browsingContext.contextDestroyed events in the events array
events = []

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

remove_listener = bidi_session.add_event_listener(CONTEXT_DESTROYED_EVENT, on_event)

await bidi_session.browsing_context.navigate(
url=test_page_nested_frames, context=new_tab["context"], wait="complete"
)

contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"])

top_iframe = contexts[0]["children"][0]
deepest_iframe = contexts[0]["children"][0]["children"][0]

# Delete deepest iframe
await bidi_session.script.evaluate(
expression="""document.querySelector('iframe').remove()""",
target=ContextTarget(top_iframe["context"]),
await_promise=False,
)

assert len(events) == 1
assert_browsing_context(
events[0],
deepest_iframe["context"],
children=0,
url=deepest_iframe["url"],
parent=top_iframe["context"],
)

remove_listener()


async def test_iframe_destroy_parent(
bidi_session, subscribe_events, new_tab, test_page_nested_frames
):
Expand All @@ -210,7 +252,7 @@ async def on_event(_, data):
assert_browsing_context(
events[0],
new_tab["context"],
children=None,
children=1,
url=test_page_nested_frames,
parent=None,
)
Expand Down Expand Up @@ -283,7 +325,7 @@ async def on_event(method, data):
assert_browsing_context(
context_info,
context["context"],
children=None,
children=0,
url="about:blank",
parent=None,
user_context=user_context,
Expand Down

0 comments on commit 9763308

Please sign in to comment.