Skip to content

Commit efb92ea

Browse files
wdspec: add test for interrupted navigation
1 parent 0949ad1 commit efb92ea

File tree

1 file changed

+44
-1
lines changed
  • webdriver/tests/bidi/browsing_context/navigate

1 file changed

+44
-1
lines changed

webdriver/tests/bidi/browsing_context/navigate/navigate.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from webdriver.bidi.modules.script import ContextTarget
66

77
from . import navigate_and_assert
8+
from .. import assert_navigation_info
89
from ... import any_string
910

1011
pytestmark = pytest.mark.asyncio
1112

12-
USER_PROMPT_OPENED_EVENT = "browsingContext.userPromptOpened"
13+
CONTEXT_LOAD_EVENT = "browsingContext.load"
1314

1415

1516
async def test_payload(bidi_session, inline, new_tab):
@@ -108,3 +109,45 @@ async def test_same_document_navigation_in_before_unload(bidi_session, new_tab,
108109

109110
url_after = url_before.replace("empty.html", "other.html")
110111
await navigate_and_assert(bidi_session, new_tab, url_after, "complete")
112+
113+
114+
@pytest.mark.parametrize(
115+
"script",
116+
[
117+
"<script>window.location='{url}'</script>",
118+
"""<script>window.addEventListener('DOMContentLoaded', () => {{
119+
window.location = '{url}';
120+
}});</script>""",
121+
"""<script>window.addEventListener('load', () => {{
122+
window.location = '{url}';
123+
}});</script>""",
124+
],
125+
ids=[
126+
"Interrupted immediately",
127+
"Interrupted on DOMContentLoaded",
128+
"Interrupted on load",
129+
],
130+
)
131+
@pytest.mark.parametrize("wait", ["none", "interactive", "complete"])
132+
async def test_interrupted_navigation(
133+
bidi_session,
134+
subscribe_events,
135+
new_tab,
136+
url,
137+
inline,
138+
wait_for_events,
139+
script,
140+
wait,
141+
):
142+
url_after = url("/webdriver/tests/bidi/browsing_context/support/empty.html")
143+
url_before = inline(script.format(url=url_after))
144+
145+
await subscribe_events([CONTEXT_LOAD_EVENT], contexts=[new_tab["context"]])
146+
with wait_for_events([CONTEXT_LOAD_EVENT]) as waiter:
147+
result = await bidi_session.browsing_context.navigate(
148+
context=new_tab["context"], url=url_before, wait=wait
149+
)
150+
# Wait until we received the load event for the final URL.
151+
load_events = await waiter.get_events(
152+
lambda events: any(event["url"] == url_after for [name, event] in events)
153+
)

0 commit comments

Comments
 (0)