diff --git a/src/bidiMapper/modules/context/NavigationTracker.spec.ts b/src/bidiMapper/modules/context/NavigationTracker.spec.ts index ea1452987..0868abf8c 100644 --- a/src/bidiMapper/modules/context/NavigationTracker.spec.ts +++ b/src/bidiMapper/modules/context/NavigationTracker.spec.ts @@ -40,13 +40,13 @@ describe('NavigationTracker', () => { let eventManager: SinonStubbedInstance<EventManager>; let initialNavigationId: string; - async function assertNoNavigationEvents() { + function assertNoNavigationEvents() { // `eventManager.registerEvent` is safe do be used unbound. // eslint-disable-next-line @typescript-eslint/unbound-method sinon.assert.notCalled(eventManager.registerEvent); } - async function assertNavigationEvent( + function assertNavigationEvent( this: void, eventName: string, navigationId: string | sinon.SinonMatcher, @@ -89,14 +89,14 @@ describe('NavigationTracker', () => { navigationTracker.navigationCommandFinished(navigation, undefined); // Assert navigation is not finished. - await assertNoNavigationEvents(); + assertNoNavigationEvents(); // Fragment navigation should not update the current navigation. assert.equal(navigationTracker.currentNavigationId, initialNavigationId); navigationTracker.navigatedWithinDocument(SOME_URL, 'fragment'); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.FragmentNavigated, navigation.navigationId, SOME_URL, @@ -114,7 +114,7 @@ describe('NavigationTracker', () => { it('started', async () => { const navigation = navigationTracker.createPendingNavigation(SOME_URL); - await assertNoNavigationEvents(); + assertNoNavigationEvents(); assert.equal(navigation.url, SOME_URL); assert.equal(navigationTracker.url, INITIAL_URL); assert.equal( @@ -124,7 +124,7 @@ describe('NavigationTracker', () => { navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationStarted, navigation.navigationId, ANOTHER_URL, @@ -138,7 +138,7 @@ describe('NavigationTracker', () => { navigationTracker.navigationCommandFinished(navigation, LOADER_ID); - await assertNoNavigationEvents(); + assertNoNavigationEvents(); assert.equal(navigation.url, ANOTHER_URL); assert.equal(navigationTracker.url, ANOTHER_URL); assert.equal( @@ -148,11 +148,11 @@ describe('NavigationTracker', () => { navigationTracker.loadPageEvent(ANOTHER_LOADER_ID); - await assertNoNavigationEvents(); + assertNoNavigationEvents(); navigationTracker.loadPageEvent(LOADER_ID); - await assertNoNavigationEvents(); + assertNoNavigationEvents(); assert.equal( (await navigation.finished).eventName, NavigationEventName.Load, @@ -164,7 +164,7 @@ describe('NavigationTracker', () => { const navigation = navigationTracker.createPendingNavigation(SOME_URL); navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationStarted, navigation.navigationId, ANOTHER_URL, @@ -172,7 +172,7 @@ describe('NavigationTracker', () => { navigationTracker.frameRequestedNavigation(YET_ANOTHER_URL); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationAborted, navigation.navigationId, ANOTHER_URL, @@ -190,7 +190,7 @@ describe('NavigationTracker', () => { const navigation = navigationTracker.createPendingNavigation(SOME_URL); navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationStarted, navigation.navigationId, ANOTHER_URL, @@ -198,7 +198,7 @@ describe('NavigationTracker', () => { navigationTracker.failNavigation(navigation, ERROR_MESSAGE); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationFailed, navigation.navigationId, ANOTHER_URL, @@ -220,7 +220,7 @@ describe('NavigationTracker', () => { const navigation = navigationTracker.createPendingNavigation(SOME_URL); navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationStarted, navigation.navigationId, ANOTHER_URL, @@ -228,7 +228,7 @@ describe('NavigationTracker', () => { navigationTracker.networkLoadingFailed(LOADER_ID, ERROR_MESSAGE); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationFailed, navigation.navigationId, ANOTHER_URL, @@ -248,10 +248,10 @@ describe('NavigationTracker', () => { }); describe('Renderer initiated navigation', () => { - it('should process fragment navigation', async () => { + it('should process fragment navigation', () => { navigationTracker.navigatedWithinDocument(SOME_URL, 'fragment'); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.FragmentNavigated, sinon.match.any, SOME_URL, @@ -262,10 +262,10 @@ describe('NavigationTracker', () => { }); describe('cross-document navigation', () => { - it('started', async () => { + it('started', () => { navigationTracker.frameRequestedNavigation(SOME_URL); - await assertNoNavigationEvents(); + assertNoNavigationEvents(); assert.equal( navigationTracker.currentNavigationId, initialNavigationId, @@ -274,7 +274,7 @@ describe('NavigationTracker', () => { navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationStarted, sinon.match.any, ANOTHER_URL, @@ -288,18 +288,18 @@ describe('NavigationTracker', () => { navigationTracker.frameNavigated(YET_ANOTHER_URL, LOADER_ID); - await assertNoNavigationEvents(); + assertNoNavigationEvents(); assert.equal(navigationTracker.url, YET_ANOTHER_URL); navigationTracker.loadPageEvent(LOADER_ID); - await assertNoNavigationEvents(); + assertNoNavigationEvents(); }); - it('aborted by script-initiated navigation', async () => { + it('aborted by script-initiated navigation', () => { navigationTracker.frameRequestedNavigation(SOME_URL); - await assertNoNavigationEvents(); + assertNoNavigationEvents(); assert.equal( navigationTracker.currentNavigationId, initialNavigationId, @@ -308,7 +308,7 @@ describe('NavigationTracker', () => { navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationStarted, sinon.match.any, ANOTHER_URL, @@ -316,7 +316,7 @@ describe('NavigationTracker', () => { navigationTracker.frameRequestedNavigation(YET_ANOTHER_URL); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationAborted, sinon.match.any, ANOTHER_URL, @@ -328,11 +328,11 @@ describe('NavigationTracker', () => { assert.equal(navigationTracker.url, INITIAL_URL); }); - it('aborted by command navigation', async () => { + it('aborted by command navigation', () => { navigationTracker.frameRequestedNavigation(SOME_URL); navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationStarted, sinon.match.any, ANOTHER_URL, @@ -340,7 +340,7 @@ describe('NavigationTracker', () => { navigationTracker.createPendingNavigation(YET_ANOTHER_URL); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationAborted, sinon.match.any, ANOTHER_URL, @@ -352,11 +352,11 @@ describe('NavigationTracker', () => { assert.equal(navigationTracker.url, INITIAL_URL); }); - it('failed network', async () => { + it('failed network', () => { navigationTracker.frameRequestedNavigation(SOME_URL); navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationStarted, sinon.match.any, ANOTHER_URL, @@ -364,7 +364,7 @@ describe('NavigationTracker', () => { navigationTracker.networkLoadingFailed(LOADER_ID, ERROR_MESSAGE); - await assertNavigationEvent( + assertNavigationEvent( ChromiumBidi.BrowsingContext.EventNames.NavigationFailed, sinon.match.any, ANOTHER_URL, diff --git a/tests/browsing_context/__snapshots__/test_navigate_events.ambr b/tests/browsing_context/__snapshots__/test_navigate_events.ambr index 1ca01036c..04b842d93 100644 --- a/tests/browsing_context/__snapshots__/test_navigate_events.ambr +++ b/tests/browsing_context/__snapshots__/test_navigate_events.ambr @@ -614,20 +614,6 @@ # --- # name: test_scriptNavigate_checkEvents list([ - dict({ - 'method': 'script.message', - 'params': dict({ - 'channel': 'beforeunload_channel', - 'data': dict({ - 'type': 'string', - 'value': 'beforeunload', - }), - 'source': dict({ - 'context': 'stable_0', - }), - }), - 'type': 'event', - }), dict({ 'method': 'browsingContext.navigationStarted', 'params': dict({ @@ -637,34 +623,12 @@ }), 'type': 'event', }), - dict({ - 'method': 'network.beforeRequestSent', - 'params': dict({ - 'context': 'stable_0', - 'isBlocked': False, - 'navigation': 'stable_1', - 'redirectCount': 0, - 'request': 'stable_4', - }), - 'type': 'event', - }), dict({ 'method': 'browsingContext.navigationStarted', 'params': dict({ 'context': 'stable_0', - 'navigation': 'stable_5', - 'url': 'stable_6', - }), - 'type': 'event', - }), - dict({ - 'method': 'network.beforeRequestSent', - 'params': dict({ - 'context': 'stable_0', - 'isBlocked': False, - 'navigation': 'stable_5', - 'redirectCount': 0, - 'request': 'stable_8', + 'navigation': 'stable_3', + 'url': 'stable_4', }), 'type': 'event', }), @@ -677,17 +641,12 @@ }), 'type': 'event', }), - dict({ - 'error': 'unknown error', - 'id': 'stable_9', - 'type': 'error', - }), dict({ 'method': 'browsingContext.domContentLoaded', 'params': dict({ 'context': 'stable_0', - 'navigation': 'stable_5', - 'url': 'stable_6', + 'navigation': 'stable_3', + 'url': 'stable_4', }), 'type': 'event', }), @@ -695,8 +654,8 @@ 'method': 'browsingContext.load', 'params': dict({ 'context': 'stable_0', - 'navigation': 'stable_5', - 'url': 'stable_6', + 'navigation': 'stable_3', + 'url': 'stable_4', }), 'type': 'event', }), diff --git a/tests/browsing_context/test_navigate_events.py b/tests/browsing_context/test_navigate_events.py index f487d90dd..675b957aa 100644 --- a/tests/browsing_context/test_navigate_events.py +++ b/tests/browsing_context/test_navigate_events.py @@ -192,14 +192,9 @@ async def test_navigate_dataUrl_checkEvents(websocket, context_id, url_base, @pytest.mark.asyncio -async def test_scriptNavigate_checkEvents(websocket, context_id, url_base, - url_example, html, read_messages, - snapshot): - await goto_url(websocket, context_id, url_base) - await set_beforeunload_handler(websocket, context_id) - await subscribe( - websocket, - ["browsingContext", "script.message", "network.beforeRequestSent"]) +async def test_scriptNavigate_checkEvents(websocket, context_id, url_example, + html, read_messages, snapshot): + await subscribe(websocket, ["browsingContext"]) initial_url = html(f"<script>window.location='{url_example}';</script>") @@ -213,10 +208,14 @@ async def test_scriptNavigate_checkEvents(websocket, context_id, url_base, } }) - messages = await read_messages(9, - keys_to_stabilize=KEYS_TO_STABILIZE, - check_no_other_messages=True, - sort=False) + messages = await read_messages( + 5, + # Filter out command result, as it can be + # racy with other events. + filter_lambda=lambda x: 'id' not in x, + keys_to_stabilize=KEYS_TO_STABILIZE, + check_no_other_messages=True, + sort=False) assert messages == snapshot(exclude=SNAPSHOT_EXCLUDE)