From a5f4f5fc14f80bf13ef5843c9ef6f46325a0c46f Mon Sep 17 00:00:00 2001 From: Nate Chapin Date: Mon, 1 Nov 2021 16:49:11 -0700 Subject: [PATCH] Update AppHistory navigate event behavior for traversals Follows https://github.com/WICG/app-history/issues/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 --- ...vigate-appHistory-back-cross-document.html | 2 +- ...avigate-appHistory-back-same-document.html | 2 +- .../navigate-history-back-after-fragment.html | 2 +- ...navigate-history-back-after-pushState.html | 2 +- .../navigate-history-back-cross-document.html | 31 +++++++++++++++++++ .../goTo-cross-document-preventDefault.html | 6 ++-- 6 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 app-history/navigate-event/navigate-history-back-cross-document.html diff --git a/app-history/navigate-event/navigate-appHistory-back-cross-document.html b/app-history/navigate-event/navigate-appHistory-back-cross-document.html index da68ea4765ed69..2be9cb9b889ace 100644 --- a/app-history/navigate-event/navigate-appHistory-back-cross-document.html +++ b/app-history/navigate-event/navigate-appHistory-back-cross-document.html @@ -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); diff --git a/app-history/navigate-event/navigate-appHistory-back-same-document.html b/app-history/navigate-event/navigate-appHistory-back-same-document.html index b4bbd3718964a8..acc71ad3fe2cda 100644 --- a/app-history/navigate-event/navigate-appHistory-back-same-document.html +++ b/app-history/navigate-event/navigate-appHistory-back-same-document.html @@ -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); diff --git a/app-history/navigate-event/navigate-history-back-after-fragment.html b/app-history/navigate-event/navigate-history-back-after-fragment.html index 54791d898642bf..f0a423a47b43b5 100644 --- a/app-history/navigate-event/navigate-history-back-after-fragment.html +++ b/app-history/navigate-event/navigate-history-back-after-fragment.html @@ -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); diff --git a/app-history/navigate-event/navigate-history-back-after-pushState.html b/app-history/navigate-event/navigate-history-back-after-pushState.html index 3d94855e799d31..40c41ee3b7098c 100644 --- a/app-history/navigate-event/navigate-history-back-after-pushState.html +++ b/app-history/navigate-event/navigate-history-back-after-pushState.html @@ -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); diff --git a/app-history/navigate-event/navigate-history-back-cross-document.html b/app-history/navigate-event/navigate-history-back-cross-document.html new file mode 100644 index 00000000000000..c6c8322a35ace2 --- /dev/null +++ b/app-history/navigate-event/navigate-history-back-cross-document.html @@ -0,0 +1,31 @@ + + + + + diff --git a/app-history/navigate/return-value/goTo-cross-document-preventDefault.html b/app-history/navigate/return-value/goTo-cross-document-preventDefault.html index a7571a7caf7116..9c2301728deef4 100644 --- a/app-history/navigate/return-value/goTo-cross-document-preventDefault.html +++ b/app-history/navigate/return-value/goTo-cross-document-preventDefault.html @@ -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)");