Skip to content

Commit

Permalink
Make navigation-api/ tests resilient to starting with extra Navigatio…
Browse files Browse the repository at this point in the history
…nHistoryEntries

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 web-platform-tests/wpt#33590.

Change-Id: Ic60de8ffe247b374ef3a0e0939fc4c1a3427c7e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4903245
Auto-Submit: Nate Chapin <japhet@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Weizhong Xia <weizhong@google.com>
Cr-Commit-Position: refs/heads/main@{#1204873}
  • Loading branch information
natechapin authored and Chromium LUCI CQ committed Oct 3, 2023
1 parent 65419a5 commit dc26878
Show file tree
Hide file tree
Showing 60 changed files with 161 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
<script src="resources/after-transition-commit-helpers.js"></script>
<body>
<script>
let start_index = navigation.currentEntry.index;

let tests = [
{ mode: "rejectBeforeCommit", destinationIndex: 0, description: "{ commit: 'after-transition' } for a traverse navigation, reject before commit" },
{ mode: "rejectAfterCommit", destinationIndex: 1, description: "{ commit: 'after-transition' } for a traverse navigation, reject after commit" },
{ mode: "successExplicitCommit", destinationIndex: 2, description: "{ commit: 'after-transition' } for a traverse navigation, explicit commit()" },
{ mode: "successNoExplicitCommit", destinationIndex: 3, description: "{ commit: 'after-transition' } for a traverse navigation, commit when handler resolves" }
{ mode: "rejectBeforeCommit", destinationIndex: start_index, description: "{ commit: 'after-transition' } for a traverse navigation, reject before commit" },
{ mode: "rejectAfterCommit", destinationIndex: start_index + 1, description: "{ commit: 'after-transition' } for a traverse navigation, reject after commit" },
{ mode: "successExplicitCommit", destinationIndex: start_index + 2, description: "{ commit: 'after-transition' } for a traverse navigation, explicit commit()" },
{ mode: "successNoExplicitCommit", destinationIndex: start_index + 3, description: "{ commit: 'after-transition' } for a traverse navigation, commit when handler resolves" }
];

// Push a bunch of history entries so each test case can target a unique entry.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
<a id="a" href="#foo"></a>
<script>
test(t => {
let start_index = navigation.currentEntry.index;

let oncurrententrychange_called = false;
navigation.oncurrententrychange = t.step_func(e => {
oncurrententrychange_called = true;
assert_equals(e.from, navigation.entries()[0]);
assert_equals(e.from.index, 0);
assert_equals(e.from, navigation.entries()[start_index]);
assert_equals(e.from.index, start_index);
assert_equals(e.navigationType, "push");
assert_equals(navigation.currentEntry.index, 1);
assert_equals(navigation.currentEntry.index, start_index + 1);
});
a.click();
assert_true(oncurrententrychange_called);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async t => {
let start_length = navigation.entries().length;
let start_index = navigation.currentEntry.index;

// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
await navigation.navigate("#foo");
assert_equals(navigation.entries().length, 2);
assert_equals(navigation.entries().length, start_length + 1);

let oncurrententrychange_called = false;
navigation.oncurrententrychange = t.step_func(e => {
oncurrententrychange_called = true;
assert_equals(e.from, navigation.entries()[1]);
assert_equals(e.from, navigation.entries()[start_index + 1]);
assert_equals(e.navigationType, "traverse");
assert_equals(navigation.currentEntry.index, 0);
assert_equals(navigation.currentEntry.index, start_index);
});
history.back();
assert_false(oncurrententrychange_called);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
<script src="/resources/testharnessreport.js"></script>
<script>
test(t => {
let start_index = navigation.currentEntry.index;

let oncurrententrychange_called = false;
navigation.oncurrententrychange = t.step_func(e => {
oncurrententrychange_called = true;
assert_equals(e.from, navigation.entries()[0]);
assert_equals(e.from, navigation.entries()[start_index]);
assert_equals(e.navigationType, "push");
assert_equals(navigation.currentEntry.index, 1);
assert_equals(navigation.currentEntry.index, start_index + 1);
});
history.pushState(1, "", "#1");
assert_true(oncurrententrychange_called);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
<script src="/resources/testharnessreport.js"></script>
<script>
test(t => {
let start_index = navigation.currentEntry.index;

let oncurrententrychange_called = false;
let original_currentEntry = navigation.currentEntry;
navigation.oncurrententrychange = t.step_func(e => {
oncurrententrychange_called = true;
assert_equals(e.from, original_currentEntry);
assert_equals(e.from.index, -1);
assert_equals(e.navigationType, "replace");
assert_equals(navigation.currentEntry.index, 0);
assert_equals(navigation.currentEntry.index, start_index);
});
history.replaceState(1, "", "#1");
assert_true(oncurrententrychange_called);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
<script src="/resources/testharnessreport.js"></script>
<script>
test(t => {
let start_index = navigation.currentEntry.index;

let oncurrententrychange_called = false;
let original_entry = navigation.currentEntry;
navigation.oncurrententrychange = t.step_func(e => {
oncurrententrychange_called = true;
assert_equals(e.from, original_entry);
assert_equals(e.from.index, -1);
assert_equals(e.navigationType, "replace");
assert_equals(navigation.currentEntry.index, 0);
assert_equals(navigation.currentEntry.index, start_index);
});
location.hash = "#foo";
assert_true(oncurrententrychange_called);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async t => {
let start_length = navigation.entries().length;
let start_index = navigation.currentEntry.index;

// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
await navigation.navigate("#foo").committed;
assert_equals(navigation.entries().length, 2);
assert_equals(navigation.entries().length, start_length + 1);

let oncurrententrychange_back_called = false;
let back_committed = false;
navigation.oncurrententrychange = t.step_func(e => {
oncurrententrychange_back_called = true;
assert_equals(e.from, navigation.entries()[1]);
assert_equals(e.from, navigation.entries()[start_index + 1]);
assert_equals(e.navigationType, "traverse");
assert_equals(navigation.currentEntry.index, 0);
assert_equals(navigation.currentEntry.index, start_index);
assert_false(back_committed);
});
let back_result = navigation.back();
Expand All @@ -27,9 +30,9 @@
let forward_committed = false;
navigation.oncurrententrychange = t.step_func(e => {
oncurrententrychange_forward_called = true;
assert_equals(e.from, navigation.entries()[0]);
assert_equals(e.from, navigation.entries()[start_index]);
assert_equals(e.navigationType, "traverse");
assert_equals(navigation.currentEntry.index, 1);
assert_equals(navigation.currentEntry.index, start_index + 1);
assert_false(forward_committed);
});
let forward_result = navigation.forward();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async t => {
let start_index = navigation.currentEntry.index;

// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
Expand All @@ -14,7 +16,7 @@
assert_equals(e.from, original_entry);
assert_equals(e.from.index, -1);
assert_equals(e.navigationType, "replace");
assert_equals(navigation.currentEntry.index, 0);
assert_equals(navigation.currentEntry.index, start_index);
});
let result = navigation.navigate("#foo", { history: "replace" });
assert_true(oncurrententrychange_called);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async t => {
let start_index = navigation.currentEntry.index;

// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));

let oncurrententrychange_called = false;
navigation.oncurrententrychange = t.step_func(e => {
oncurrententrychange_called = true;
assert_equals(e.from, navigation.entries()[0]);
assert_equals(e.from, navigation.entries()[start_index]);
assert_equals(e.navigationType, "push");
assert_equals(navigation.currentEntry.index, 1);
assert_equals(navigation.currentEntry.index, start_index + 1);
});
let result = navigation.navigate("#foo");
assert_true(oncurrententrychange_called);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
<script src="resources/is_uuid.js"></script>
<script>
test(() => {
let start_length = navigation.entries().length;
let first_entry = navigation.currentEntry;
let start_index = first_entry.index;
assert_not_equals(first_entry, null);
assert_not_equals(first_entry.key, null);
assert_true(isUUID(first_entry.key));
assert_not_equals(first_entry.id, null);
assert_true(isUUID(first_entry.id));
assert_equals(first_entry.url, location.href);
assert_true(first_entry.sameDocument);
assert_equals(navigation.entries().length, 1);
assert_equals(first_entry, navigation.entries()[0]);
assert_equals(navigation.entries().length, start_length);
assert_equals(first_entry, navigation.entries()[start_index]);

history.replaceState(2, "", "#2");
let second_entry = navigation.currentEntry;
Expand All @@ -24,8 +26,8 @@
assert_true(isUUID(second_entry.id));
assert_equals(second_entry.url, location.href);
assert_true(second_entry.sameDocument);
assert_equals(navigation.entries().length, 1);
assert_equals(second_entry, navigation.entries()[0]);
assert_equals(navigation.entries().length, start_length);
assert_equals(second_entry, navigation.entries()[start_index]);

history.pushState(3, "", "#3");
let third_entry = navigation.currentEntry;
Expand All @@ -36,8 +38,8 @@
assert_true(isUUID(third_entry.id));
assert_equals(third_entry.url, location.href);
assert_true(third_entry.sameDocument);
assert_equals(navigation.entries().length, 2);
assert_equals(third_entry, navigation.entries()[1]);
assert_equals(navigation.entries().length, start_length + 1);
assert_equals(third_entry, navigation.entries()[start_index + 1]);

history.pushState(4, "");
let fourth_entry = navigation.currentEntry;
Expand All @@ -48,8 +50,8 @@
assert_true(isUUID(fourth_entry.id));
assert_equals(fourth_entry.url, third_entry.url);
assert_true(fourth_entry.sameDocument);
assert_equals(navigation.entries().length, 3);
assert_equals(fourth_entry, navigation.entries()[2]);
assert_equals(navigation.entries().length, start_length + 2);
assert_equals(fourth_entry, navigation.entries()[start_index + 2]);

history.replaceState(5, "");
let fifth_entry = navigation.currentEntry;
Expand All @@ -60,8 +62,8 @@
assert_true(isUUID(fifth_entry.id));
assert_equals(fifth_entry.url, fourth_entry.url);
assert_true(fifth_entry.sameDocument);
assert_equals(navigation.entries().length, 3);
assert_equals(fifth_entry, navigation.entries()[2]);
assert_equals(navigation.entries().length, start_length + 2);
assert_equals(fifth_entry, navigation.entries()[start_index + 2]);

history.pushState(5, "");
let fifth_entry_after_push = navigation.currentEntry;
Expand All @@ -72,8 +74,8 @@
assert_true(isUUID(fifth_entry_after_push.id));
assert_equals(fifth_entry_after_push.url, fifth_entry.url);
assert_true(fifth_entry_after_push.sameDocument);
assert_equals(navigation.entries().length, 4);
assert_equals(fifth_entry_after_push, navigation.entries()[3]);
assert_equals(navigation.entries().length, start_length + 3);
assert_equals(fifth_entry_after_push, navigation.entries()[start_index + 3]);

history.replaceState(5, "");
let fifth_entry_after_replace = navigation.currentEntry;
Expand All @@ -84,8 +86,8 @@
assert_true(isUUID(fifth_entry_after_replace.id));
assert_equals(fifth_entry_after_replace.url, fifth_entry_after_push.url);
assert_true(fifth_entry_after_replace.sameDocument);
assert_equals(navigation.entries().length, 4);
assert_equals(fifth_entry_after_replace, navigation.entries()[3]);
assert_equals(navigation.entries().length, start_length + 3);
assert_equals(fifth_entry_after_replace, navigation.entries()[start_index + 3]);

location.hash = "6";
let sixth_entry = navigation.currentEntry;
Expand All @@ -96,8 +98,8 @@
assert_true(isUUID(sixth_entry.id));
assert_not_equals(sixth_entry.url, fifth_entry_after_replace.url);
assert_true(sixth_entry.sameDocument);
assert_equals(navigation.entries().length, 4);
assert_equals(sixth_entry, navigation.entries()[3]);
assert_equals(navigation.entries().length, start_length + 3);
assert_equals(sixth_entry, navigation.entries()[start_index + 3]);

navigation.entries().forEach(entry => {
assert_true(isUUID(entry.id));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<iframe id="i" src="/common/blank.html"></iframe>
<script>
async_test(t => {
let start_index = navigation.currentEntry.index;
// The navigations in each window should have only added an navigation to
// their own window.
function assertExpectedEntries(entries, expected_url) {
Expand All @@ -25,7 +26,7 @@
window.onload = () => t.step_timeout(t.step_func(() => {
location.hash = "#1";
i.onload = t.step_func_done(() => {
assertExpectedEntries(navigation.entries(), location.href);
assertExpectedEntries(navigation.entries().slice(start_index), location.href);
assertExpectedEntries(i.contentWindow.navigation.entries(), i.contentWindow.location.href);
});
i.contentWindow.location = "/common/blank.html?2";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(t => {
const first_entry = navigation.entries()[0];
let start_index = navigation.currentEntry.index;
const first_entry = navigation.entries()[start_index];
history.pushState(1, "", "#1");
assert_equals(navigation.entries()[0], first_entry);
assert_equals(navigation.entries()[start_index], first_entry);
history.back();
window.onpopstate = t.step_func_done(() => {
const second_entry = navigation.entries()[1];
const second_entry = navigation.entries()[start_index + 1];
history.replaceState(0, "", "#0");
assert_equals(navigation.entries()[1], second_entry);
assert_equals(navigation.entries()[start_index + 1], second_entry);
});
}, "A non-active entry in navigation.entries() should not be modified when a different entry is modified");
</script>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
<iframe id="i" src="/common/blank.html"></iframe>
<script>
async_test(t => {
let start_index = navigation.currentEntry.index;

// 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(() => {
// Remove the entry by replacing it.
let replaced_entry = navigation.currentEntry;
assert_equals(replaced_entry.index, 0);
assert_equals(replaced_entry.index, start_index);
navigation.navigate("#0", { history: "replace" });
assert_equals(replaced_entry.index, -1);

Expand Down

This file was deleted.

Loading

0 comments on commit dc26878

Please sign in to comment.