Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion webdriver/tests/bidi/browsing_context/navigate/navigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
from webdriver.bidi.modules.script import ContextTarget

from . import navigate_and_assert
from .. import assert_navigation_info
from ... import any_string

pytestmark = pytest.mark.asyncio

USER_PROMPT_OPENED_EVENT = "browsingContext.userPromptOpened"
CONTEXT_LOAD_EVENT = "browsingContext.load"


async def test_payload(bidi_session, inline, new_tab):
Expand Down Expand Up @@ -108,3 +109,45 @@ async def test_same_document_navigation_in_before_unload(bidi_session, new_tab,

url_after = url_before.replace("empty.html", "other.html")
await navigate_and_assert(bidi_session, new_tab, url_after, "complete")


@pytest.mark.parametrize(
"script",
[
"<script>window.location='{url}'</script>",
"""<script>window.addEventListener('DOMContentLoaded', () => {{
window.location = '{url}';
}});</script>""",
"""<script>window.addEventListener('load', () => {{
window.location = '{url}';
}});</script>""",
],
ids=[
"Interrupted immediately",
"Interrupted on DOMContentLoaded",
"Interrupted on load",
],
)
@pytest.mark.parametrize("wait", ["none", "interactive", "complete"])
async def test_interrupted_navigation(
bidi_session,
subscribe_events,
new_tab,
url,
inline,
wait_for_events,
script,
wait,
):
url_after = url("/webdriver/tests/bidi/browsing_context/support/empty.html")
url_before = inline(script.format(url=url_after))

await subscribe_events([CONTEXT_LOAD_EVENT], contexts=[new_tab["context"]])
with wait_for_events([CONTEXT_LOAD_EVENT]) as waiter:
result = await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=url_before, wait=wait
)
# Wait until we received the load event for the final URL.
load_events = await waiter.get_events(
lambda events: any(event["url"] == url_after for [name, event] in events)
)