From 9763308e2757d20bdc2b51ac099e7a5a27b3e165 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Wed, 22 Jan 2025 16:38:09 +0000 Subject: [PATCH] [wdspec] Updating tests for serializing the full context tree for "browsingContext.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 --- .../context_destroyed/context_destroyed.py | 70 +++++++++++++++---- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py b/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py index 17f7acf2f9b689..ac964b67687805 100644 --- a/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py +++ b/webdriver/tests/bidi/browsing_context/context_destroyed/context_destroyed.py @@ -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" @@ -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("
foo
") - url = inline(f"") 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, ) @@ -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, @@ -179,7 +177,7 @@ 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"], ) @@ -187,6 +185,50 @@ async def on_event(_, data): 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 ): @@ -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, ) @@ -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,