Skip to content

Commit

Permalink
Bug 1738739 [wpt PR 31459] - Update AppHistory navigate event behavio…
Browse files Browse the repository at this point in the history
…r for traversals, a=testonly

Automatic update from web-platform-tests
Update AppHistory navigate event behavior for traversals

Follows WICG/navigation-api#178

* Always fire navigate event for traversals (currently, we fire it for
  all same-document traversals and for cross-document appHistory.goTo(),
  but not cross-document traversals from the legacy history API, or
  from the UI).
* The AppHistory navigate event should never be cancelable for
  traversals. Previously, it was cancelable for renderer-initiated
  traversals, but this has the potential to cause problems in the case
  where multiple frames are navigating and one frame (but not all)
  cancels. That frame would be out of sync with the authoritative
  history state in the browser process.

Change-Id: I92a3ee0f908acc04c31dc9b8ec57569bd66b4bc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3255177
Reviewed-by: Domenic Denicola <[email protected]>
Commit-Queue: Nate Chapin <[email protected]>
Cr-Commit-Position: refs/heads/main@{#937981}

--

wpt-commits: e637041005202690b5cf3be09bd4056f80fce2be
wpt-pr: 31459
  • Loading branch information
natechapin authored and moz-wptsync-bot committed Nov 9, 2021
1 parent a2df653 commit 1062507
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
i.onload = t.step_func(() => {
i.contentWindow.appHistory.onnavigate = t.step_func_done(e => {
assert_equals(e.navigationType, "traverse");
assert_true(e.cancelable);
assert_false(e.cancelable);
assert_false(e.canTransition);
assert_false(e.userInitiated);
assert_false(e.hashChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
appHistory.navigate("#foo").committed.then(t.step_func(() => {
appHistory.onnavigate = t.step_func_done(e => {
assert_equals(e.navigationType, "traverse");
assert_true(e.cancelable);
assert_false(e.cancelable);
assert_true(e.canTransition);
assert_false(e.userInitiated);
assert_true(e.hashChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

appHistory.onnavigate = t.step_func_done(e => {
assert_equals(e.navigationType, "traverse");
assert_true(e.cancelable);
assert_false(e.cancelable);
assert_true(e.canTransition);
assert_false(e.userInitiated);
assert_true(e.hashChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

appHistory.onnavigate = t.step_func_done(e => {
assert_equals(e.navigationType, "traverse");
assert_true(e.cancelable);
assert_false(e.cancelable);
assert_true(e.canTransition);
assert_false(e.userInitiated);
assert_false(e.hashChange);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe id="i" src="/common/blank.html"></iframe>
<script>
async_test(t => {
window.onload = t.step_func(() => {
let target_key = i.contentWindow.appHistory.current.key;
let target_id = i.contentWindow.appHistory.current.id;
i.contentWindow.appHistory.navigate("?foo");
i.onload = t.step_func(() => {
i.contentWindow.appHistory.onnavigate = t.step_func_done(e => {
assert_equals(e.navigationType, "traverse");
assert_false(e.cancelable);
assert_false(e.canTransition);
assert_false(e.userInitiated);
assert_false(e.hashChange);
assert_equals(new URL(e.destination.url).pathname, "/common/blank.html");
assert_false(e.destination.sameDocument);
assert_equals(e.destination.key, target_key);
assert_equals(e.destination.id, target_id);
assert_equals(e.destination.index, 0);
assert_equals(e.formData, null);
assert_equals(e.info, undefined);
});
assert_true(i.contentWindow.appHistory.canGoBack);
i.contentWindow.history.back();
})
});
}, "navigate event for history.back() - cross-document");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
assert_equals(i.contentWindow.appHistory.entries().length, 2);
assert_equals(i.contentWindow.appHistory.current, i.contentWindow.appHistory.entries()[1]);

// This will be a noop, because navigate events are uncancelable for traversals.
i.contentWindow.appHistory.onnavigate = e => e.preventDefault();

await assertBothRejectDOM(t, i.contentWindow.appHistory.goTo(key), "AbortError", i.contentWindow);
}, "goTo() promise rejection when preventDefault()ing the navigate event (cross-document)");
assertNeverSettles(t, i.contentWindow.appHistory.goTo(key), i.contentWindow);
await new Promise(resolve => i.onload = () => t.step_timeout(resolve, 0));
}, "goTo() promise never settle when preventDefault()ing the navigate event (cross-document)");
</script>

0 comments on commit 1062507

Please sign in to comment.