Skip to content

Commit

Permalink
update e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed Dec 12, 2024
1 parent a291c5f commit b506b68
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
14 changes: 9 additions & 5 deletions src/bidiMapper/modules/context/NavigationTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ export class NavigationTracker {
*/
createPendingNavigation(url: string): NavigationState {
this.#logger?.(LogType.debug, 'createCommandNavigation');
if (!urlMatchesAboutBlank(url)) {
this.#isInitialNavigation = false;
}

this.#pendingNavigation?.finished.resolve(
new NavigationResult(
Expand Down Expand Up @@ -258,9 +261,13 @@ export class NavigationTracker {
}

if (!this.#loaderIdToNavigationsMap.has(loaderId)) {
// Unexpected situation, but no need in throwing exception.
this.#logger?.(LogType.debug, `Unknown loader ${loaderId} navigated`);

if (this.isInitialNavigation && urlMatchesAboutBlank(url)) {
// Initial navigation should be ignored.
return;
}

if (
this.#pendingNavigation !== undefined &&
this.#pendingNavigation?.loaderId === undefined
Expand Down Expand Up @@ -338,9 +345,6 @@ export class NavigationTracker {

frameRequestedNavigation(url: string) {
this.#logger?.(LogType.debug, `Page.frameRequestedNavigation ${url}`);
if (!urlMatchesAboutBlank(url)) {
this.#isInitialNavigation = false;
}
// The page is about to navigate to the url.
this.createPendingNavigation(url);
}
Expand All @@ -352,6 +356,7 @@ export class NavigationTracker {
*/
loadPageEvent(loaderId: string) {
this.#logger?.(LogType.debug, 'loadPageEvent');
// Even if it was an initial navigation, it is finished.
this.#isInitialNavigation = false;

this.#loaderIdToNavigationsMap
Expand Down Expand Up @@ -398,7 +403,6 @@ export class NavigationTracker {
);

navigation.started.resolve();
this.#isInitialNavigation = false;
this.#currentNavigation = navigation;

if (this.#pendingNavigation === navigation) {
Expand Down
2 changes: 1 addition & 1 deletion tests/browsing_context/test_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ async def test_browsingContext_navigate_prompt(websocket, context_id, html,
assert resp == AnyExtending({
'error': 'unknown error',
'id': navigate_command_id,
'message': 'navigation failed',
'message': 'net::ERR_ABORTED',
'stacktrace': ANY_STR,
'type': 'error',
})
Expand Down
38 changes: 34 additions & 4 deletions tests/browsing_context/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
from anys import ANY_STR, Not
from anys import ANY_STR
from test_helpers import (ANY_TIMESTAMP, AnyExtending, execute_command,
get_tree, goto_url, read_JSON_message,
send_JSON_command, subscribe)
Expand Down Expand Up @@ -272,7 +272,7 @@ async def test_browsingContext_create_withUserGesture_eventsEmitted(

await goto_url(websocket, context_id, LINK_WITH_BLANK_TARGET)

await subscribe(websocket, 'browsingContext.contextCreated')
await subscribe(websocket, 'browsingContext')

command_id = await send_JSON_command(
websocket, {
Expand All @@ -287,7 +287,10 @@ async def test_browsingContext_create_withUserGesture_eventsEmitted(
}
})

messages = await read_sorted_messages(2, check_no_other_messages=True)
messages = await read_sorted_messages(
5,
check_no_other_messages=True,
keys_to_stabilize=['context', 'navigation'])

assert messages == [
AnyExtending({
Expand All @@ -297,14 +300,41 @@ async def test_browsingContext_create_withUserGesture_eventsEmitted(
'type': 'event',
'method': 'browsingContext.contextCreated',
'params': {
'context': ANY_STR & Not(context_id),
'context': 'stable_0',
'url': 'about:blank',
'clientWindow': ANY_STR,
'children': None,
'parent': None,
'userContext': 'default',
'originalOpener': ANY_STR,
}
}, {
'type': 'event',
'method': 'browsingContext.domContentLoaded',
'params': {
'context': 'stable_0',
'navigation': 'stable_1',
'timestamp': ANY_TIMESTAMP,
'url': url_example,
},
}, {
'type': 'event',
'method': 'browsingContext.load',
'params': {
'context': 'stable_0',
'navigation': 'stable_1',
'timestamp': ANY_TIMESTAMP,
'url': url_example,
},
}, {
'method': 'browsingContext.navigationStarted',
'params': {
'context': 'stable_0',
'navigation': 'stable_1',
'timestamp': ANY_TIMESTAMP,
'url': url_example,
},
'type': 'event',
}
]

Expand Down
12 changes: 5 additions & 7 deletions tests/browsing_context/test_navigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def test_browsingContext_navigateWaitInteractive_redirect(
AnyExtending({
'id': command_id,
'error': 'unknown error',
'message': 'navigation aborted',
'message': 'navigation canceled by concurrent navigation',
'type': 'error',
}),
{
Expand Down Expand Up @@ -399,16 +399,14 @@ async def test_browsingContext_navigationStartedEvent_viaScript(
AnyExtending({
'id': command_id,
'type': 'success',
}),
{
}), {
'type': 'event',
"method": "browsingContext.navigationStarted",
"params": {
"context": context_id,
"navigation": ANY_UUID,
"timestamp": ANY_TIMESTAMP,
# TODO: Should report correct string
"url": ANY_STR,
"url": url_base,
}
}
]
Expand Down Expand Up @@ -591,7 +589,7 @@ async def test_browsingContext_navigationStarted_browsingContextClosedBeforeNavi
'id': navigate_command_id,
'type': 'error',
'error': 'unknown error',
'message': 'navigation aborted',
'message': 'net::ERR_ABORTED',
})

assert close_command_result == AnyExtending({
Expand Down Expand Up @@ -717,7 +715,7 @@ async def test_browsingContext_acceptInsecureCertsCapability_respected(
assert resp == AnyExtending({
'error': 'unknown error',
'id': command_id,
'message': 'navigation failed',
'message': 'net::ERR_CERT_AUTHORITY_INVALID',
'type': 'error',
})

Expand Down

0 comments on commit b506b68

Please sign in to comment.