diff options
Diffstat (limited to 'testing/web-platform/tests/webdriver/tests/bidi/integration/navigation.py')
-rw-r--r-- | testing/web-platform/tests/webdriver/tests/bidi/integration/navigation.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/integration/navigation.py b/testing/web-platform/tests/webdriver/tests/bidi/integration/navigation.py new file mode 100644 index 0000000000..23615040c7 --- /dev/null +++ b/testing/web-platform/tests/webdriver/tests/bidi/integration/navigation.py @@ -0,0 +1,67 @@ +import pytest + +from webdriver.error import TimeoutException +from webdriver.bidi.error import UnknownErrorException +from webdriver.bidi.modules.script import ContextTarget + + +pytestmark = pytest.mark.asyncio + +NAVIGATION_STARTED_EVENT = "browsingContext.navigationStarted" +FRAGMENT_NAVIGATED_EVENT = "browsingContext.fragmentNavigated" +BEFORE_REQUEST_SENT_EVENT = "network.beforeRequestSent" + +async def test_navigate_history_replacestate_beforeunload( + bidi_session, inline, new_tab, subscribe_events +): + url = inline(""" + <script> + window.addEventListener( + 'beforeunload', + () => { + return history.replaceState(null, 'initial', window.location.href); + }, + false + ); + </script>""") + + result = await bidi_session.browsing_context.navigate( + context=new_tab["context"], url=url, wait="complete" + ) + + events = [] + + async def on_event(method, data): + events.append(method) + + remove_navigation_started_listener = bidi_session.add_event_listener( + NAVIGATION_STARTED_EVENT, on_event + ) + + remove_fragment_navigated_listener = bidi_session.add_event_listener( + FRAGMENT_NAVIGATED_EVENT, on_event + ) + + remove_before_request_sent_listener = bidi_session.add_event_listener( + BEFORE_REQUEST_SENT_EVENT, on_event + ) + + await subscribe_events([NAVIGATION_STARTED_EVENT, FRAGMENT_NAVIGATED_EVENT, BEFORE_REQUEST_SENT_EVENT]) + + result = await bidi_session.browsing_context.navigate( + context=new_tab["context"], url=url, wait="interactive" + ) + + # Navigation caused by browsing_context.navigate call should happen first: + # https://html.spec.whatwg.org/#beginning-navigation + # network.beforeRequestSent should arrive before the page becomes + # interactive. + assert events == [ + NAVIGATION_STARTED_EVENT, + FRAGMENT_NAVIGATED_EVENT, + BEFORE_REQUEST_SENT_EVENT + ] + + remove_navigation_started_listener() + remove_fragment_navigated_listener() + remove_before_request_sent_listener() |