From b51e507f0f773b6c88c1419614aa3729de721528 Mon Sep 17 00:00:00 2001 From: Blink WPT Bot Date: Thu, 5 Oct 2023 14:19:04 -0700 Subject: [PATCH] Make navigation-api/ tests resilient to starting with extra NavigationHistoryEntries (#42232) When WPT are run in-browser or via wptrunner, there may be additional session history entries when the test starts, so the tests shouldn't assume that they start with navigation.entries().length == 1 or navigation.currentEntry.index == 0. This fixes all directories except navigate-event/ and navigation-methods/, which had enough tests to deserve separate treatment. This is a workaround for https://github.com/web-platform-tests/wpt/issues/33590. Change-Id: Ic60de8ffe247b374ef3a0e0939fc4c1a3427c7e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4903245 Auto-Submit: Nate Chapin Commit-Queue: Nate Chapin Reviewed-by: Domenic Denicola Reviewed-by: Weizhong Xia Cr-Commit-Position: refs/heads/main@{#1204873} Co-authored-by: Nate Chapin --- .../after-transition-traverse.html | 10 +++--- .../anchor-click.html | 8 +++-- .../history-back-same-doc.html | 9 +++-- .../history-pushState.html | 6 ++-- .../history-replaceState.html | 4 ++- .../location-api.html | 4 ++- .../navigation-back-forward-same-doc.html | 13 ++++--- .../navigation-navigate-replace-same-doc.html | 4 ++- .../navigation-navigate-same-doc.html | 6 ++-- .../current-basic.html | 34 ++++++++++--------- ...after-navigations-in-multiple-windows.html | 3 +- .../entries-when-inactive.html | 9 ++--- .../index-not-in-entries.html | 4 ++- .../key-id-back-cross-document.html | 3 +- .../key-id-back-same-document.html | 11 +++--- .../key-id-location-reload.html | 3 +- .../key-id-location-replace.html | 3 +- .../sameDocument-after-fragment-navigate.html | 11 +++--- ...entrychange-before-popstate-intercept.html | 3 +- .../currententrychange-dispose-ordering.html | 3 +- ...se-for-full-session-history.tentative.html | 3 +- .../dispose-for-navigation-in-child.html | 16 +++++---- .../dispose-same-document-intercept.html | 14 ++++---- ...dispose-same-document-navigate-during.html | 10 +++--- ...-same-document-replace-with-intercept.html | 5 ++- .../dispose-same-document-replaceState.html | 5 +-- .../dispose-same-document.html | 14 ++++---- .../dispose-skip-current-on-truncate.html | 15 ++++---- ...e-document-away-and-back-location-api.html | 14 ++++---- ...document-away-and-back-navigation-api.html | 14 ++++---- ...e-document-away-and-back-location-api.html | 10 +++--- 31 files changed, 161 insertions(+), 110 deletions(-) diff --git a/navigation-api/commit-behavior/after-transition-traverse.html b/navigation-api/commit-behavior/after-transition-traverse.html index 7dd1226e54c10c7..d348a218ac4a4b7 100644 --- a/navigation-api/commit-behavior/after-transition-traverse.html +++ b/navigation-api/commit-behavior/after-transition-traverse.html @@ -5,11 +5,13 @@ diff --git a/navigation-api/navigation-history-entry/index-not-in-entries.html b/navigation-api/navigation-history-entry/index-not-in-entries.html index a16d130ba16b39b..021848f1a3e09ae 100644 --- a/navigation-api/navigation-history-entry/index-not-in-entries.html +++ b/navigation-api/navigation-history-entry/index-not-in-entries.html @@ -4,12 +4,14 @@ diff --git a/navigation-api/navigation-history-entry/key-id-back-same-document.html b/navigation-api/navigation-history-entry/key-id-back-same-document.html index 858b5fd2c896347..d3c0252fdbbd9c1 100644 --- a/navigation-api/navigation-history-entry/key-id-back-same-document.html +++ b/navigation-api/navigation-history-entry/key-id-back-same-document.html @@ -3,21 +3,22 @@ diff --git a/navigation-api/ordering-and-transition/currententrychange-before-popstate-intercept.html b/navigation-api/ordering-and-transition/currententrychange-before-popstate-intercept.html index c51c7c444cb9a57..10627c5875433a4 100644 --- a/navigation-api/ordering-and-transition/currententrychange-before-popstate-intercept.html +++ b/navigation-api/ordering-and-transition/currententrychange-before-popstate-intercept.html @@ -3,11 +3,12 @@ diff --git a/navigation-api/per-entry-events/dispose-same-document-intercept.html b/navigation-api/per-entry-events/dispose-same-document-intercept.html index 44aa096aafec78d..862e01127bed042 100644 --- a/navigation-api/per-entry-events/dispose-same-document-intercept.html +++ b/navigation-api/per-entry-events/dispose-same-document-intercept.html @@ -6,13 +6,15 @@ // Wait for after the load event so that the navigation doesn't get converted // into a replace navigation. await new Promise(r => window.onload = () => t.step_timeout(r, 0)); + let start_length = navigation.entries().length; + let start_index = navigation.currentEntry.index; location.hash = "#1"; location.hash = "#2"; location.hash = "#3"; - assert_equals(navigation.entries().length, 4); - const [entry0, entry1, entry2, entry3] = navigation.entries(); + assert_equals(navigation.entries().length, start_length + 3); + const [entry0, entry1, entry2, entry3] = navigation.entries().slice(start_index); assert_equals((new URL(entry2.url)).hash, "#2"); assert_equals((new URL(entry3.url)).hash, "#3"); @@ -26,7 +28,7 @@ assert_equals(e.composed, false); assert_array_equals( - navigation.entries(), + navigation.entries().slice(start_index), [entry0, entry1, navigation.currentEntry], "entries() is updated during dispose for entry 2"); assert_not_equals(navigation.currentEntry, entry1, "current entry must be updated during dispose for entry 3"); @@ -41,7 +43,7 @@ assert_true(dispose2Called, "dispose for entry 2 must have happened before entry 3"); assert_array_equals( - navigation.entries(), + navigation.entries().slice(start_index), [entry0, entry1, navigation.currentEntry], "entries() is updated during dispose for entry 3"); assert_not_equals(navigation.currentEntry, entry1, "current entry must be updated during dispose for entry 3"); @@ -60,8 +62,8 @@ navigation.navigate("#fork"); - assert_equals(navigation.entries().length, 3); - const [finalEntry0, finalEntry1, finalEntry2] = navigation.entries(); + assert_equals(navigation.entries().length, start_length + 2); + const [finalEntry0, finalEntry1, finalEntry2] = navigation.entries().slice(start_index); assert_equals(finalEntry0, entry0); assert_equals(finalEntry1, entry1); assert_not_equals(finalEntry2, entry2); diff --git a/navigation-api/per-entry-events/dispose-same-document-navigate-during.html b/navigation-api/per-entry-events/dispose-same-document-navigate-during.html index 59d9b3cce3977ae..88eb35c225fa7cb 100644 --- a/navigation-api/per-entry-events/dispose-same-document-navigate-during.html +++ b/navigation-api/per-entry-events/dispose-same-document-navigate-during.html @@ -6,13 +6,15 @@ // Wait for after the load event so that the navigation doesn't get converted // into a replace navigation. await new Promise(r => window.onload = () => t.step_timeout(r, 0)); + let start_length = navigation.entries().length; + let start_index = navigation.currentEntry.index; location.hash = "#1"; location.hash = "#2"; location.hash = "#3"; - assert_equals(navigation.entries().length, 4); - const [entry0, entry1, entry2, entry3] = navigation.entries(); + assert_equals(navigation.entries().length, start_length + 3); + const [entry0, entry1, entry2, entry3] = navigation.entries().slice(start_index); assert_equals((new URL(entry2.url)).hash, "#2"); assert_equals((new URL(entry3.url)).hash, "#3"); @@ -37,8 +39,8 @@ assert_equals(dispose3Called, 1, "dispose for entry 3 must happen exactly once (final check)"); - assert_equals(navigation.entries().length, 4); - const [finalEntry0, finalEntry1, finalEntry2, finalEntry3] = navigation.entries(); + assert_equals(navigation.entries().length, start_length + 3); + const [finalEntry0, finalEntry1, finalEntry2, finalEntry3] = navigation.entries().slice(start_index); assert_equals(finalEntry0, entry0); assert_equals(finalEntry1, entry1); assert_not_equals(finalEntry2, entry2); diff --git a/navigation-api/per-entry-events/dispose-same-document-replace-with-intercept.html b/navigation-api/per-entry-events/dispose-same-document-replace-with-intercept.html index 4e492e30aedeb69..7814543e7142229 100644 --- a/navigation-api/per-entry-events/dispose-same-document-replace-with-intercept.html +++ b/navigation-api/per-entry-events/dispose-same-document-replace-with-intercept.html @@ -8,7 +8,6 @@ // automatically before the load event completes. await new Promise(r => window.onload = () => t.step_timeout(r, 0)); - const entriesBefore = navigation.entries(); const currentBefore = navigation.currentEntry; let disposeCalled = false; @@ -21,10 +20,10 @@ assert_equals(e.composed, false); assert_not_equals(navigation.currentEntry, currentBefore); - assert_array_equals(navigation.entries(), [navigation.currentEntry]); + assert_array_equals(navigation.entries().slice(navigation.currentEntry.index), [navigation.currentEntry]); assert_equals((new URL(navigation.currentEntry.url)).search, "?replacement"); assert_equals(navigation.transition.navigationType, "replace"); - assert_equals(navigation.transition.from, entriesBefore[0]); + assert_equals(navigation.transition.from, currentBefore); assert_equals(location.search, "?replacement"); }); diff --git a/navigation-api/per-entry-events/dispose-same-document-replaceState.html b/navigation-api/per-entry-events/dispose-same-document-replaceState.html index a6197260a28b813..78df25774c33d88 100644 --- a/navigation-api/per-entry-events/dispose-same-document-replaceState.html +++ b/navigation-api/per-entry-events/dispose-same-document-replaceState.html @@ -3,7 +3,8 @@ diff --git a/navigation-api/state/same-document-away-and-back-location-api.html b/navigation-api/state/same-document-away-and-back-location-api.html index d161df8b5295f1b..ddc90eef8c57027 100644 --- a/navigation-api/state/same-document-away-and-back-location-api.html +++ b/navigation-api/state/same-document-away-and-back-location-api.html @@ -6,7 +6,9 @@ // Wait for after the load event so that the navigation doesn't get converted // into a replace navigation. window.onload = () => t.step_timeout(async () => { + let start_length = navigation.entries().length; let entry0 = navigation.currentEntry; + let start_index = entry0.index; let navState = { statevar: "state" }; await navigation.navigate("#1", { state: navState }); @@ -15,10 +17,10 @@ location.href = "#2"; let entry2 = navigation.currentEntry; - assert_equals(navigation.entries().length, 3); - assert_equals(entry0, navigation.entries()[0]); - assert_equals(entry1, navigation.entries()[1]); - assert_equals(entry2, navigation.entries()[2]); + assert_equals(navigation.entries().length, start_length + 2); + assert_equals(entry0, navigation.entries()[start_index]); + assert_equals(entry1, navigation.entries()[start_index + 1]); + assert_equals(entry2, navigation.entries()[start_index + 2]); assert_equals(entry0.getState(), undefined); @@ -34,9 +36,9 @@ history.back(); window.onpopstate = t.step_func_done(() => { - assert_equals(navigation.entries().length, 3); + assert_equals(navigation.entries().length, start_length + 2); let back_entry = navigation.currentEntry; - assert_equals(back_entry, navigation.entries()[1]); + assert_equals(back_entry, navigation.entries()[start_index + 1]); let back_state = back_entry.getState(); assert_not_equals(back_state, state1); assert_not_equals(back_state, state2); diff --git a/navigation-api/state/same-document-away-and-back-navigation-api.html b/navigation-api/state/same-document-away-and-back-navigation-api.html index 220908e4c46cb91..cfb7765b0d5dc49 100644 --- a/navigation-api/state/same-document-away-and-back-navigation-api.html +++ b/navigation-api/state/same-document-away-and-back-navigation-api.html @@ -6,7 +6,9 @@ // Wait for after the load event so that the navigation doesn't get converted // into a replace navigation. window.onload = () => t.step_timeout(async () => { + let start_length = navigation.entries().length; let entry0 = navigation.currentEntry; + let start_index = entry0.index; let navState = { statevar: "state" }; await navigation.navigate("#1", { state: navState }).committed; @@ -17,10 +19,10 @@ let entry2 = navigation.currentEntry; t.step_func(() => { - assert_equals(navigation.entries().length, 3); - assert_equals(entry0, navigation.entries()[0]); - assert_equals(entry1, navigation.entries()[1]); - assert_equals(entry2, navigation.entries()[2]); + assert_equals(navigation.entries().length, start_length + 2); + assert_equals(entry0, navigation.entries()[start_index]); + assert_equals(entry1, navigation.entries()[start_index + 1]); + assert_equals(entry2, navigation.entries()[start_index + 2]); assert_equals(entry0.getState(), undefined); @@ -38,9 +40,9 @@ navigation.back(); window.onpopstate = t.step_func_done(() => { - assert_equals(navigation.entries().length, 3); + assert_equals(navigation.entries().length, start_length + 2); let back_entry = navigation.currentEntry; - assert_equals(back_entry, navigation.entries()[1]); + assert_equals(back_entry, navigation.entries()[start_index + 1]); let back_state = back_entry.getState(); assert_not_equals(back_state, state1); assert_not_equals(back_state, state2); diff --git a/navigation-api/updateCurrentEntry-method/same-document-away-and-back-location-api.html b/navigation-api/updateCurrentEntry-method/same-document-away-and-back-location-api.html index 47b1904f4f46f6c..04b615cf831ed20 100644 --- a/navigation-api/updateCurrentEntry-method/same-document-away-and-back-location-api.html +++ b/navigation-api/updateCurrentEntry-method/same-document-away-and-back-location-api.html @@ -6,7 +6,9 @@ // Wait for after the load event so that the navigation doesn't get converted // into a replace navigation. window.onload = () => t.step_timeout(async () => { + let start_length = navigation.entries().length; let entry0 = navigation.currentEntry; + let start_index = entry0.index; let navState = { statevar: "state" }; navigation.updateCurrentEntry({ state: navState }); @@ -15,9 +17,9 @@ location.href = "#2"; let entry1 = navigation.currentEntry; - assert_equals(navigation.entries().length, 2); - assert_equals(entry0, navigation.entries()[0]); - assert_equals(entry1, navigation.entries()[1]); + assert_equals(navigation.entries().length, start_length + 1); + assert_equals(entry0, navigation.entries()[start_index]); + assert_equals(entry1, navigation.entries()[start_index + 1]); assert_equals(entry0.getState().statevar, "state"); assert_not_equals(entry0.getState(), navState); @@ -28,7 +30,7 @@ history.back(); window.onpopstate = t.step_func_done(() => { - assert_equals(navigation.entries().length, 2); + assert_equals(navigation.entries().length, start_length + 1); let back_entry = navigation.currentEntry; assert_equals(back_entry, entry0); let back_state = back_entry.getState();