From 7e66d427e9d739051cf915c3adb463ccc4de22bb Mon Sep 17 00:00:00 2001 From: Nate Chapin Date: Wed, 18 Oct 2023 08:33:19 +0000 Subject: [PATCH] Bug 1856741 [wpt PR 42228] - Make navigation-api/navigation-methods/ resilient to starting with extra NavigationHistoryEntries, a=testonly Automatic update from web-platform-tests Make navigation-api/navigation-methods/ resilient to starting with extra NavigationHistoryEntries 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 is a workaround for https://github.com/web-platform-tests/wpt/issues/33590. Change-Id: I406474b33d9c17b682d5d54fc88f5c677bc3d3ea Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4904062 Reviewed-by: Domenic Denicola Commit-Queue: Nate Chapin Auto-Submit: Nate Chapin Cr-Commit-Position: refs/heads/main@{#1204876} -- wpt-commits: e1f2e7c0dd66323b85a8cb90182066ed3e6cef9f wpt-pr: 42228 --- .../back-forward-multiple-frames.html | 22 ++++++++++--------- .../navigation-methods/disambigaute-back.html | 12 +++++----- .../disambigaute-forward.html | 16 ++++++++------ ...disambigaute-traverseTo-back-multiple.html | 12 +++++----- ...ambigaute-traverseTo-forward-multiple.html | 16 ++++++++------ .../forward-to-pruned-entry.html | 12 +++++----- .../navigate-history-push-not-loaded.html | 7 +++--- .../navigate-history-push-same-url.html | 8 ++++--- .../navigate-replace-cross-document.html | 3 ++- .../navigate-replace-same-document.html | 3 ++- .../back-forward-out-of-bounds.html | 15 +++++++------ .../return-value/back-intercept-rejected.html | 6 +++-- .../return-value/back-intercept.html | 6 +++-- .../navigation-methods/return-value/back.html | 6 +++-- .../forward-intercept-rejected.html | 6 +++-- .../return-value/forward-intercept.html | 6 +++-- .../return-value/forward.html | 6 +++-- .../navigate-intercept-interrupted.html | 8 ++++--- ...avigate-interrupted-within-onnavigate.html | 6 +++-- .../return-value/navigate-interrupted.html | 8 ++++--- .../return-value/traverseTo-current.html | 4 ++-- .../traverseTo-intercept-rejected.html | 6 +++-- .../return-value/traverseTo-intercept.html | 6 +++-- .../return-value/traverseTo.html | 6 +++-- .../traverseTo-after-adding-iframe.html | 4 ++-- .../traverseTo-multiple-steps.html | 14 +++++++----- ...traverseTo-navigates-multiple-iframes.html | 3 ++- .../traverseTo-same-document.html | 20 +++++++++-------- 28 files changed, 147 insertions(+), 100 deletions(-) diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/back-forward-multiple-frames.html b/testing/web-platform/tests/navigation-api/navigation-methods/back-forward-multiple-frames.html index 738bfd37dcc72..6c30987f7598d 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/back-forward-multiple-frames.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/back-forward-multiple-frames.html @@ -6,20 +6,22 @@ promise_test(async t => { // Wait for after the load event so that the navigation doesn't get converted // into a replace navigation. + let start_length = navigation.entries().length; + let start_index = navigation.currentEntry.index; await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); // Step 1 - assert_equals(navigation.entries().length, 1, "step 1 outer entries() length"); + assert_equals(navigation.entries().length, start_length, "step 1 outer entries() length"); assert_equals(i.contentWindow.navigation.entries().length, 1, "step 1 iframe entries() length"); await navigation.navigate("#top").committed; // Step 2: iframe at initial entry, top on second entry - assert_equals(navigation.entries().length, 2, "step 2 outer entries() length"); + assert_equals(navigation.entries().length, start_length+1, "step 2 outer entries() length"); assert_equals(i.contentWindow.navigation.entries().length, 1, "step 2 iframe entries() length"); await i.contentWindow.navigation.navigate("#iframe").committed; // Step 3: Both windows on second entry. - assert_equals(navigation.entries().length, 2, "step 3 outer entries() length"); + assert_equals(navigation.entries().length, start_length+1, "step 3 outer entries() length"); assert_equals(i.contentWindow.navigation.entries().length, 2, "step 3 iframe entries() length"); - assert_equals(navigation.currentEntry.index, 1, "step 3 outer index"); + assert_equals(navigation.currentEntry.index, start_index+1, "step 3 outer index"); assert_equals(i.contentWindow.navigation.currentEntry.index, 1, "step 1 iframe index"); // NOTE: the order of navigation in the two windows is not guaranteed; we need to wait for both. @@ -29,7 +31,7 @@ i.contentWindow.navigation.back().committed, new Promise(resolve => i.contentWindow.onpopstate = resolve) ]); - assert_equals(navigation.currentEntry.index, 1, "after iframe back() outer index"); + assert_equals(navigation.currentEntry.index, start_index+1, "after iframe back() outer index"); assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after iframe back() iframe index"); // Going forward in iframe should go 2->3 @@ -37,7 +39,7 @@ i.contentWindow.navigation.forward().commited, new Promise(resolve => i.contentWindow.onpopstate = resolve) ]); - assert_equals(navigation.currentEntry.index, 1, "after iframe forward() outer index"); + assert_equals(navigation.currentEntry.index, start_index+1, "after iframe forward() outer index"); assert_equals(i.contentWindow.navigation.currentEntry.index, 1, "after iframe forward() iframe index"); // Going back in top should go 3->1 (navigating both windows). @@ -45,7 +47,7 @@ navigation.back().commited, new Promise(resolve => i.contentWindow.onpopstate = resolve) ]); - assert_equals(navigation.currentEntry.index, 0, "after outer back() outer index"); + assert_equals(navigation.currentEntry.index, start_index, "after outer back() outer index"); assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after outer back() iframe index"); // Next two should not navigate the iframe @@ -54,13 +56,13 @@ // Going forward in top should go 1->2 (navigating top only) await navigation.forward().committed; await new Promise(resolve => t.step_timeout(resolve, 0)); - assert_equals(navigation.currentEntry.index, 1, "after outer forward() outer index"); + assert_equals(navigation.currentEntry.index, start_index+1, "after outer forward() outer index"); assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after outer forward() iframe index"); // Going back in top should go 2->1 await navigation.back().committed; await new Promise(resolve => t.step_timeout(resolve, 0)); - assert_equals(navigation.currentEntry.index, 0, "after outer second back() outer index"); + assert_equals(navigation.currentEntry.index, start_index, "after outer second back() outer index"); assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after outer second back() iframe index"); // Going forward in iframe should go 1->3 (navigating both windows) @@ -68,7 +70,7 @@ i.contentWindow.navigation.forward().commited, new Promise(resolve => i.contentWindow.onpopstate = resolve) ]); - assert_equals(navigation.currentEntry.index, 1, "after iframe second forward() outer index"); + assert_equals(navigation.currentEntry.index, start_index+1, "after iframe second forward() outer index"); assert_equals(i.contentWindow.navigation.currentEntry.index, 1, "after iframe second forward() iframe index"); }, "navigation.back() and navigation.forward() can navigate multiple frames"); diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/disambigaute-back.html b/testing/web-platform/tests/navigation-api/navigation-methods/disambigaute-back.html index d44d435896dd8..a42000ca5fc9c 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/disambigaute-back.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/disambigaute-back.html @@ -4,18 +4,20 @@ diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/forward-to-pruned-entry.html b/testing/web-platform/tests/navigation-api/navigation-methods/forward-to-pruned-entry.html index 05f70c5c2dccb..18b30c620d59c 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/forward-to-pruned-entry.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/forward-to-pruned-entry.html @@ -3,13 +3,15 @@ diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/navigate-history-push-not-loaded.html b/testing/web-platform/tests/navigation-api/navigation-methods/navigate-history-push-not-loaded.html index c1ecdaeeafdfb..f919417332559 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/navigate-history-push-not-loaded.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/navigate-history-push-not-loaded.html @@ -5,8 +5,9 @@ diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/navigate-history-push-same-url.html b/testing/web-platform/tests/navigation-api/navigation-methods/navigate-history-push-same-url.html index 339e8c3056bb2..a81215f7d46a3 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/navigate-history-push-same-url.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/navigate-history-push-same-url.html @@ -5,10 +5,12 @@ diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/navigate-replace-cross-document.html b/testing/web-platform/tests/navigation-api/navigation-methods/navigate-replace-cross-document.html index 7f016babe6bc7..0a36e25970fd1 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/navigate-replace-cross-document.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/navigate-replace-cross-document.html @@ -7,6 +7,7 @@ // Wait for after the load event so that the navigation doesn't get converted // into a replace navigation (which would defeat the point of the test). window.onload = () => t.step_timeout(() => { + let start_length = navigation.entries().length; let start_history_length = history.length; let start_entry_top = navigation.currentEntry; let start_entry_iframe_id = i.contentWindow.navigation.currentEntry.id; @@ -16,7 +17,7 @@ i.onload = t.step_func_done(() => { assert_equals(history.length, start_history_length); - assert_equals(navigation.entries().length, 1); + assert_equals(navigation.entries().length, start_length); assert_equals(navigation.currentEntry, start_entry_top); assert_equals(i.contentWindow.navigation.entries().length, 1); diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/navigate-replace-same-document.html b/testing/web-platform/tests/navigation-api/navigation-methods/navigate-replace-same-document.html index 0d8493b788240..943ab377654b1 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/navigate-replace-same-document.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/navigate-replace-same-document.html @@ -6,6 +6,7 @@ // Wait for after the load event so that the navigation doesn't get converted // into a replace navigation. window.onload = () => t.step_timeout(t.step_func_done(async () => { + let start_length = navigation.entries().length; let start_history_length = history.length; let key1 = navigation.currentEntry.key; await navigation.navigate("#1").committed; @@ -14,7 +15,7 @@ await navigation.navigate("#2", { history: "replace" }).committed; let key3 = navigation.currentEntry.key; assert_equals(key2, key3); - assert_equals(navigation.entries().length, 2); + assert_equals(navigation.entries().length, start_length + 1); assert_equals(history.length, start_history_length + 1); }), 0); }, "navigate() with history: 'replace' option"); diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-forward-out-of-bounds.html b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-forward-out-of-bounds.html index 015c090bf97e5..ac6d901ba52a9 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-forward-out-of-bounds.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-forward-out-of-bounds.html @@ -2,15 +2,16 @@ - + diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-intercept-rejected.html b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-intercept-rejected.html index 9d4238087ff50..013ebf1e1e3df 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-intercept-rejected.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-intercept-rejected.html @@ -5,14 +5,16 @@ diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/navigate-interrupted-within-onnavigate.html b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/navigate-interrupted-within-onnavigate.html index 3db02c6931e41..249a7df69c2ff 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/navigate-interrupted-within-onnavigate.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/navigate-interrupted-within-onnavigate.html @@ -5,6 +5,8 @@ diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/traverseTo-current.html b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/traverseTo-current.html index 212fe992cf774..3942faf77fb3b 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/traverseTo-current.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/traverseTo-current.html @@ -5,13 +5,13 @@ diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/traverseTo-intercept-rejected.html b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/traverseTo-intercept-rejected.html index f934eae5d4c1a..f39913e05b239 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/traverseTo-intercept-rejected.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/traverseTo-intercept-rejected.html @@ -5,6 +5,8 @@ diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/traverseTo-navigates-multiple-iframes.html b/testing/web-platform/tests/navigation-api/navigation-methods/traverseTo-navigates-multiple-iframes.html index 3d6adb53413e3..1892ae065e2e3 100644 --- a/testing/web-platform/tests/navigation-api/navigation-methods/traverseTo-navigates-multiple-iframes.html +++ b/testing/web-platform/tests/navigation-api/navigation-methods/traverseTo-navigates-multiple-iframes.html @@ -6,6 +6,7 @@