Skip to content

Commit

Permalink
navigation.navigate(url, { history: "push" }); should actually force …
Browse files Browse the repository at this point in the history
…push

Currently, { history: "push" } is actually push-or-fail: if the
navigation would've been a push, it pushes. If it would've been a
replace, the navigation fails immediately.

This CL makes { history: "push" } actually override some cases where
we would implicitly convert a push navigation to a replace:
navigations before onload completes, and navigation to the current url.

Change-Id: I0b985a4c9563c6000f7ee44153394466cc4bcb50
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4175895
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1099590}
  • Loading branch information
natechapin authored and chromium-wpt-export-bot committed Feb 1, 2023
1 parent d80a211 commit 3a5a9af
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
Expand Up @@ -6,14 +6,15 @@
<script>
promise_test(async t => {
// Purposefully do not wait until after the load event (unlike some sibling tests).

navigation.onnavigate = t.unreached_func("onnavigate should not be called");
navigation.onnavigatesuccess = t.unreached_func("onnavigatesuccess should not be called");
navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called");

assert_equals(navigation.entries().length, 1);
assert_equals(document.readyState, "loading", "Document must not have loaded yet");

const result = navigation.navigate("#1", { history: "push" });
await assertBothRejectDOM(t, result, "NotSupportedError");
let navigateEventType;
navigation.onnavigate = e => navigateEventType = e.navigationType;

await navigation.navigate("#1", { history: "push" }).finished;
assert_equals(navigateEventType, "push");
assert_equals(navigation.entries().length, 2);
assert_equals(navigation.currentEntry.index, 1);
}, "navigate() with history: 'push' in a document that has not yet had its load event");
</script>
@@ -0,0 +1,25 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<iframe id="i" src="/common/blank.html"></iframe>
<script>
promise_test(async t => {
// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation due to onload not having completed.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
assert_equals(i.contentWindow.navigation.entries().length, 1);

i.contentWindow.navigation.onnavigatesuccess = t.unreached_func("onnavigatesuccess should not be called");
i.contentWindow.navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called");

let navigateEventType;
i.contentWindow.navigation.onnavigate = e => navigateEventType = e.navigationType;

i.contentWindow.navigation.navigate(i.contentWindow.location, { history: "push" });
await new Promise(resolve => i.onload = resolve);
assert_equals(navigateEventType, "push");
assert_equals(i.contentWindow.navigation.entries().length, 2);
assert_equals(i.contentWindow.navigation.currentEntry.index, 1);
}, "navigate() to the current URL with history: 'push' and allow it to go cross document");
</script>
@@ -0,0 +1,26 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<script>
promise_test(async t => {
// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation due to onload not having completed.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
assert_equals(navigation.entries().length, 1);


let navigateEventType;
navigation.onnavigate = e => {
navigateEventType = e.navigationType;
e.intercept();
}
navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called");

await navigation.navigate(location.href, { history: "push" }).finished;
assert_equals(navigateEventType, "push");
assert_equals(navigation.entries().length, 2);
assert_equals(navigation.currentEntry.index, 1);
}, "navigate() to the current URL with history: 'push' and intercept so it remains same-document");
</script>

This file was deleted.

0 comments on commit 3a5a9af

Please sign in to comment.