From 7dd36728d26cf2dcf48eba9dd871b5437443a7e2 Mon Sep 17 00:00:00 2001 From: Nate Chapin Date: Tue, 3 Oct 2023 13:07:27 -0700 Subject: [PATCH] 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 --- .../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/navigation-api/navigation-methods/back-forward-multiple-frames.html b/navigation-api/navigation-methods/back-forward-multiple-frames.html index 738bfd37dcc720a..6c30987f7598de0 100644 --- a/navigation-api/navigation-methods/back-forward-multiple-frames.html +++ b/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/navigation-api/navigation-methods/disambigaute-back.html b/navigation-api/navigation-methods/disambigaute-back.html index d44d435896dd872..a42000ca5fc9c10 100644 --- a/navigation-api/navigation-methods/disambigaute-back.html +++ b/navigation-api/navigation-methods/disambigaute-back.html @@ -4,18 +4,20 @@ diff --git a/navigation-api/navigation-methods/forward-to-pruned-entry.html b/navigation-api/navigation-methods/forward-to-pruned-entry.html index 05f70c5c2dccb65..18b30c620d59c8a 100644 --- a/navigation-api/navigation-methods/forward-to-pruned-entry.html +++ b/navigation-api/navigation-methods/forward-to-pruned-entry.html @@ -3,13 +3,15 @@ diff --git a/navigation-api/navigation-methods/navigate-history-push-not-loaded.html b/navigation-api/navigation-methods/navigate-history-push-not-loaded.html index c1ecdaeeafdfbee..f919417332559cd 100644 --- a/navigation-api/navigation-methods/navigate-history-push-not-loaded.html +++ b/navigation-api/navigation-methods/navigate-history-push-not-loaded.html @@ -5,8 +5,9 @@ diff --git a/navigation-api/navigation-methods/navigate-history-push-same-url.html b/navigation-api/navigation-methods/navigate-history-push-same-url.html index 339e8c3056bb2e6..a81215f7d46a323 100644 --- a/navigation-api/navigation-methods/navigate-history-push-same-url.html +++ b/navigation-api/navigation-methods/navigate-history-push-same-url.html @@ -5,10 +5,12 @@ diff --git a/navigation-api/navigation-methods/navigate-replace-cross-document.html b/navigation-api/navigation-methods/navigate-replace-cross-document.html index 7f016babe6bc767..ded321e55825c7b 100644 --- a/navigation-api/navigation-methods/navigate-replace-cross-document.html +++ b/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_navigation_entries_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_navigation_entries_length); assert_equals(navigation.currentEntry, start_entry_top); assert_equals(i.contentWindow.navigation.entries().length, 1); diff --git a/navigation-api/navigation-methods/navigate-replace-same-document.html b/navigation-api/navigation-methods/navigate-replace-same-document.html index 0d8493b7882407e..9ae59f465c2cfec 100644 --- a/navigation-api/navigation-methods/navigate-replace-same-document.html +++ b/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_navigation_entries_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_navigation_entries_length + 1); assert_equals(history.length, start_history_length + 1); }), 0); }, "navigate() with history: 'replace' option"); diff --git a/navigation-api/navigation-methods/return-value/back-forward-out-of-bounds.html b/navigation-api/navigation-methods/return-value/back-forward-out-of-bounds.html index 015c090bf97e567..ac6d901ba52a972 100644 --- a/navigation-api/navigation-methods/return-value/back-forward-out-of-bounds.html +++ b/navigation-api/navigation-methods/return-value/back-forward-out-of-bounds.html @@ -2,15 +2,16 @@ - + diff --git a/navigation-api/navigation-methods/return-value/back-intercept-rejected.html b/navigation-api/navigation-methods/return-value/back-intercept-rejected.html index 9d4238087ff501b..013ebf1e1e3df14 100644 --- a/navigation-api/navigation-methods/return-value/back-intercept-rejected.html +++ b/navigation-api/navigation-methods/return-value/back-intercept-rejected.html @@ -5,14 +5,16 @@ diff --git a/navigation-api/navigation-methods/return-value/navigate-interrupted-within-onnavigate.html b/navigation-api/navigation-methods/return-value/navigate-interrupted-within-onnavigate.html index 3db02c6931e41da..249a7df69c2fff1 100644 --- a/navigation-api/navigation-methods/return-value/navigate-interrupted-within-onnavigate.html +++ b/navigation-api/navigation-methods/return-value/navigate-interrupted-within-onnavigate.html @@ -5,6 +5,8 @@ diff --git a/navigation-api/navigation-methods/return-value/traverseTo-current.html b/navigation-api/navigation-methods/return-value/traverseTo-current.html index 212fe992cf774cd..3942faf77fb3b0f 100644 --- a/navigation-api/navigation-methods/return-value/traverseTo-current.html +++ b/navigation-api/navigation-methods/return-value/traverseTo-current.html @@ -5,13 +5,13 @@ diff --git a/navigation-api/navigation-methods/return-value/traverseTo-intercept-rejected.html b/navigation-api/navigation-methods/return-value/traverseTo-intercept-rejected.html index f934eae5d4c1a39..f39913e05b23915 100644 --- a/navigation-api/navigation-methods/return-value/traverseTo-intercept-rejected.html +++ b/navigation-api/navigation-methods/return-value/traverseTo-intercept-rejected.html @@ -5,6 +5,8 @@ diff --git a/navigation-api/navigation-methods/traverseTo-navigates-multiple-iframes.html b/navigation-api/navigation-methods/traverseTo-navigates-multiple-iframes.html index 3d6adb53413e3e8..1892ae065e2e372 100644 --- a/navigation-api/navigation-methods/traverseTo-navigates-multiple-iframes.html +++ b/navigation-api/navigation-methods/traverseTo-navigates-multiple-iframes.html @@ -6,6 +6,7 @@