Skip to content

Commit

Permalink
feat: implement browsingContext.historyUpdated (#2656)
Browse files Browse the repository at this point in the history
Spec: w3c/webdriver-bidi#740
WPT: web-platform-tests/wpt#48347

---------

Co-authored-by: browser-automation-bot <133232582+browser-automation-bot@users.noreply.github.com>
  • Loading branch information
OrKoN and browser-automation-bot authored Oct 22, 2024
1 parent 06ad2d0 commit 48d496a
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/bidiMapper/modules/context/BrowsingContextImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,24 +427,41 @@ export class BrowsingContextImpl {
if (this.id !== params.frameId) {
return;
}
if (params.navigationType === 'historyApi') {
this.#url = params.url;
this.#eventManager.registerEvent(
{
type: 'event',
method: 'browsingContext.historyUpdated',
params: {
context: this.id,
url: this.#url,
},
},
this.id,
);
return;
}
this.#pendingNavigationUrl = undefined;
const timestamp = BrowsingContextImpl.getTimestamp();
this.#url = params.url;
this.#navigation.withinDocument.resolve();

this.#eventManager.registerEvent(
{
type: 'event',
method: ChromiumBidi.BrowsingContext.EventNames.FragmentNavigated,
params: {
context: this.id,
navigation: this.#navigationId,
timestamp,
url: this.#url,
if (params.navigationType === 'fragment') {
this.#eventManager.registerEvent(
{
type: 'event',
method: ChromiumBidi.BrowsingContext.EventNames.FragmentNavigated,
params: {
context: this.id,
navigation: this.#navigationId,
timestamp,
url: this.#url,
},
},
},
this.id,
);
this.id,
);
}
});

this.#cdpTarget.cdpClient.on('Page.frameStartedLoading', (params) => {
Expand Down
47 changes: 47 additions & 0 deletions tests/browsing_context/test_history_updated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2024 Google LLC.
# Copyright (c) Microsoft Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
from test_helpers import (goto_url, read_JSON_message, send_JSON_command,
subscribe)


@pytest.mark.asyncio
async def test_browsingContext_historyUpdated_event(websocket, context_id,
url_base):
await subscribe(websocket, ["browsingContext.historyUpdated"])

await goto_url(websocket, context_id, url_base)

await send_JSON_command(
websocket, {
"method": "script.evaluate",
"params": {
"expression": "history.replaceState(null, '', '#test');",
"target": {
"context": context_id,
},
"awaitPromise": False
}
})

response = await read_JSON_message(websocket)
assert response == {
'type': 'event',
"method": "browsingContext.historyUpdated",
"params": {
"context": context_id,
"url": url_base + "#test",
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[history_api.py]
[test_history_push_state[-#foo\]]
expected: FAIL

[test_history_push_state[#foo-#bar\]]
expected: FAIL

[test_history_push_state[#foo-#foo\]]
expected: FAIL

[test_history_push_state[#bar-\]]
expected: FAIL
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[history_api.py]
[test_history_push_state[-#foo\]]
expected: FAIL

[test_history_push_state[#foo-#bar\]]
expected: FAIL

[test_history_push_state[#foo-#foo\]]
expected: FAIL

[test_history_push_state[#bar-\]]
expected: FAIL
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[history_api.py]
[test_history_push_state[-#foo\]]
expected: FAIL

[test_history_push_state[#foo-#bar\]]
expected: FAIL

[test_history_push_state[#foo-#foo\]]
expected: FAIL

[test_history_push_state[#bar-\]]
expected: FAIL

0 comments on commit 48d496a

Please sign in to comment.