Skip to content

Commit

Permalink
fail aborted navigation commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed Nov 27, 2024
1 parent 6699abc commit 2907b01
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
14 changes: 5 additions & 9 deletions src/bidiMapper/modules/context/BrowsingContextImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {Deferred} from '../../../utils/Deferred.js';
import {EventEmitter} from '../../../utils/EventEmitter.js';
import {type LoggerFn, LogType} from '../../../utils/log.js';
import {inchesFromCm} from '../../../utils/unitConversions.js';
import {urlMatchesAboutBlank} from '../../../utils/UrlHelpers';
import {urlMatchesAboutBlank} from '../../../utils/UrlHelpers.js';
import {uuidv4} from '../../../utils/uuid.js';
import type {CdpTarget} from '../cdp/CdpTarget.js';
import type {Realm} from '../script/Realm.js';
Expand Down Expand Up @@ -99,12 +99,6 @@ class NavigationState extends EventEmitter<NavigationEventType> {
}
}

isStarted() {
return this.#states[
ChromiumBidi.BrowsingContext.EventNames.NavigationStarted
];
}

markStarted() {
this.#completeAndNotify(
ChromiumBidi.BrowsingContext.EventNames.NavigationStarted,
Expand Down Expand Up @@ -324,8 +318,6 @@ class NavigationTracker {
}

frameScheduledNavigation(url: string): void {
// If `Page.frameScheduledNavigation` is not guaranteed to be emitted, but if it
// does, it never goes before `Page.frameScheduledNavigation`.
// Signals that it's a new navigation:
// 1. The `Page.frameStartedLoading` was already emitted.
// 2. The `Page.frameScheduledNavigation` was already emitted.
Expand Down Expand Up @@ -1152,6 +1144,9 @@ export class BrowsingContextImpl {
if (navigationResult === NavigationWaitResult.FAILED) {
throw new UnknownErrorException('Navigation failed');
}
if (navigationResult === NavigationWaitResult.ABORTED) {
throw new UnknownErrorException('Navigation aborted');
}

return {
navigation: navigation.navigationId,
Expand Down Expand Up @@ -1503,6 +1498,7 @@ export class BrowsingContextImpl {
`No history entry at delta ${delta}`,
);
}
this.#navigationTracker.createNavigation(entry.url);
await this.#cdpTarget.cdpClient.sendCommand('Page.navigateToHistoryEntry', {
entryId: entry.id,
});
Expand Down
3 changes: 1 addition & 2 deletions tests/browsing_context/test_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ async def test_browsingContext_navigate_prompt(websocket, context_id, html,
assert resp == AnyExtending({
'error': 'unknown error',
'id': navigate_command_id,
'message': 'net::ERR_ABORTED',
'stacktrace': ANY_STR,
'message': 'Navigation aborted',
'type': 'error',
})
# Handle prompt command expected to succeed.
Expand Down
37 changes: 13 additions & 24 deletions tests/browsing_context/test_navigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ async def test_browsingContext_navigateWaitInteractive_redirect(
navigation_aborted_event] = await read_sorted_messages(2)
assert navigation_result == AnyExtending({
'id': command_id,
'type': 'success'
'type': 'error',
'message': 'Navigation aborted'
})
initial_navigation_id = navigation_result['result']['navigation']

assert navigation_aborted_event == AnyExtending({
'method': 'browsingContext.navigationAborted',
'type': 'event',
'params': {
'context': context_id,
'navigation': initial_navigation_id,
'navigation': ANY_UUID,
'timestamp': ANY_TIMESTAMP,
'url': initial_url
}
Expand Down Expand Up @@ -565,11 +565,10 @@ async def test_browsingContext_navigationStarted_browsingContextClosedBeforeNavi
assert messages == [
{
'id': navigate_command_id,
'result': {
'navigation': ANY_UUID,
'url': url_hang_forever,
},
'type': 'success',
'error': 'unknown error',
'message': 'Navigation aborted',
'stacktrace': ANY_STR,
'type': 'error',
},
{
'id': close_command_id,
Expand Down Expand Up @@ -613,10 +612,9 @@ async def test_browsingContext_navigationStarted_browsingContextClosedBeforeNavi


@pytest.mark.asyncio
async def test_browsingContext_navigationStarted_navigateBeforeNavigationEnded_navigationSucceeded(
async def test_browsingContext_navigationStarted_navigateBeforeNavigationEnded_navigationFailed(
websocket, context_id, read_sorted_messages, url_hang_forever,
url_example):
pytest.xfail("Not implemented yet")
await subscribe(websocket, ["browsingContext.navigationAborted"])

first_navigation_command_id = await send_JSON_command(
Expand All @@ -643,11 +641,10 @@ async def test_browsingContext_navigationStarted_navigateBeforeNavigationEnded_n
assert messages == [
{
'id': first_navigation_command_id,
'result': {
'navigation': ANY_UUID,
'url': url_hang_forever,
},
'type': 'success',
'type': 'error',
'error': 'unknown error',
'message': 'Navigation aborted',
'stacktrace': ANY_STR
},
{
'id': second_navigation_command_id,
Expand All @@ -669,10 +666,6 @@ async def test_browsingContext_navigationStarted_navigateBeforeNavigationEnded_n
},
]

# Assert the first navigation aborted.
assert messages[0]['result']['navigation'] == messages[2]['params'][
'navigation']


@pytest.mark.asyncio
async def test_browsingContext_navigationStarted_sameDocumentNavigation(
Expand Down Expand Up @@ -780,11 +773,7 @@ async def navigate():
if capabilities.get('acceptInsecureCerts'):
await navigate()
else:
with pytest.raises(Exception,
match=str({
'error': 'unknown error',
'message': 'net::ERR_CERT_AUTHORITY_INVALID'
})):
with pytest.raises(Exception):
await navigate()


Expand Down

0 comments on commit 2907b01

Please sign in to comment.