|
5 | 5 | from webdriver.bidi.modules.script import ContextTarget |
6 | 6 |
|
7 | 7 | from . import navigate_and_assert |
| 8 | +from .. import assert_navigation_info |
8 | 9 | from ... import any_string |
9 | 10 |
|
10 | 11 | pytestmark = pytest.mark.asyncio |
11 | 12 |
|
12 | | -USER_PROMPT_OPENED_EVENT = "browsingContext.userPromptOpened" |
| 13 | +CONTEXT_LOAD_EVENT = "browsingContext.load" |
13 | 14 |
|
14 | 15 |
|
15 | 16 | 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, |
108 | 109 |
|
109 | 110 | url_after = url_before.replace("empty.html", "other.html") |
110 | 111 | 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