Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App history API to navigation API rename (1/n) #33132

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app-history/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Navigation API tests

This directory contains tests for the
[navigation API](https://wicg.github.io/navigation-api/),
[formerly known as](https://github.com/WICG/navigation-api/issues/83) the app
history API.

The tests are currently being updated for the rename, and so are likely to have
filenames, descriptions, etc. which don't match the spec, or mismatch the
contents of the test. The rename is being done in stages and tracked at
<https://crbug.com/1300246>.
28 changes: 14 additions & 14 deletions app-history/app-history-entry/after-detach.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
// into a replace navigation.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));

let i_appHistory = i.contentWindow.appHistory;
let i_navigation = i.contentWindow.navigation;

await i_appHistory.navigate("#1").finished;
await i_appHistory.navigate("#2").finished;
await i_appHistory.back().finished;
await i_navigation.navigate("#1").finished;
await i_navigation.navigate("#2").finished;
await i_navigation.back().finished;

assert_not_equals(i_appHistory, null);
assert_not_equals(i_appHistory.current, null);
assert_equals(i_appHistory.entries().length, 3);
assert_true(i_appHistory.canGoBack, "canGoBack");
assert_true(i_appHistory.canGoForward, "canGoForward");
assert_not_equals(i_navigation, null);
assert_not_equals(i_navigation.currentEntry, null);
assert_equals(i_navigation.entries().length, 3);
assert_true(i_navigation.canGoBack, "canGoBack");
assert_true(i_navigation.canGoForward, "canGoForward");

i.remove();

assert_equals(i_appHistory.current, null);
assert_equals(i_appHistory.entries().length, 0);
assert_false(i_appHistory.canGoBack);
assert_false(i_appHistory.canGoForward);
}, "appHistory.current/entries()/canGoBack/canGoForward after iframe removal");
assert_equals(i_navigation.currentEntry, null);
assert_equals(i_navigation.entries().length, 0);
assert_false(i_navigation.canGoBack);
assert_false(i_navigation.canGoForward);
}, "navigation.currentEntry/entries()/canGoBack/canGoForward after iframe removal");
</script>
52 changes: 26 additions & 26 deletions app-history/app-history-entry/current-basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,104 @@
<script src="resources/is_uuid.js"></script>
<script>
test(() => {
let first_entry = appHistory.current;
let first_entry = navigation.currentEntry;
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(appHistory.entries().length, 1);
assert_equals(first_entry, appHistory.entries()[0]);
assert_equals(navigation.entries().length, 1);
assert_equals(first_entry, navigation.entries()[0]);

history.replaceState(2, "", "#2");
let second_entry = appHistory.current;
let second_entry = navigation.currentEntry;
assert_not_equals(second_entry, first_entry);
assert_equals(second_entry.key, first_entry.key);
assert_true(isUUID(second_entry.key));
assert_not_equals(second_entry.id, first_entry.id);
assert_true(isUUID(second_entry.id));
assert_equals(second_entry.url, location.href);
assert_true(second_entry.sameDocument);
assert_equals(appHistory.entries().length, 1);
assert_equals(second_entry, appHistory.entries()[0]);
assert_equals(navigation.entries().length, 1);
assert_equals(second_entry, navigation.entries()[0]);

history.pushState(3, "", "#3");
let third_entry = appHistory.current;
let third_entry = navigation.currentEntry;
assert_not_equals(third_entry, second_entry);
assert_not_equals(third_entry.key, second_entry.key);
assert_true(isUUID(third_entry.key));
assert_not_equals(third_entry.id, second_entry.id);
assert_true(isUUID(third_entry.id));
assert_equals(third_entry.url, location.href);
assert_true(third_entry.sameDocument);
assert_equals(appHistory.entries().length, 2);
assert_equals(third_entry, appHistory.entries()[1]);
assert_equals(navigation.entries().length, 2);
assert_equals(third_entry, navigation.entries()[1]);

history.pushState(4, "");
let fourth_entry = appHistory.current;
let fourth_entry = navigation.currentEntry;
assert_not_equals(fourth_entry, third_entry);
assert_not_equals(fourth_entry.key, third_entry.key);
assert_true(isUUID(fourth_entry.key));
assert_not_equals(fourth_entry.id, third_entry.id);
assert_true(isUUID(fourth_entry.id));
assert_equals(fourth_entry.url, third_entry.url);
assert_true(fourth_entry.sameDocument);
assert_equals(appHistory.entries().length, 3);
assert_equals(fourth_entry, appHistory.entries()[2]);
assert_equals(navigation.entries().length, 3);
assert_equals(fourth_entry, navigation.entries()[2]);

history.replaceState(5, "");
let fifth_entry = appHistory.current;
let fifth_entry = navigation.currentEntry;
assert_not_equals(fifth_entry, fourth_entry);
assert_equals(fifth_entry.key, fourth_entry.key);
assert_true(isUUID(fifth_entry.key));
assert_not_equals(fifth_entry.id, fourth_entry.id);
assert_true(isUUID(fifth_entry.id));
assert_equals(fifth_entry.url, fourth_entry.url);
assert_true(fifth_entry.sameDocument);
assert_equals(appHistory.entries().length, 3);
assert_equals(fifth_entry, appHistory.entries()[2]);
assert_equals(navigation.entries().length, 3);
assert_equals(fifth_entry, navigation.entries()[2]);

history.pushState(5, "");
let fifth_entry_after_push = appHistory.current;
let fifth_entry_after_push = navigation.currentEntry;
assert_not_equals(fifth_entry_after_push, fifth_entry);
assert_not_equals(fifth_entry_after_push.key, fifth_entry.key);
assert_true(isUUID(fifth_entry_after_push.key));
assert_not_equals(fifth_entry_after_push.id, fifth_entry.id);
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(appHistory.entries().length, 4);
assert_equals(fifth_entry_after_push, appHistory.entries()[3]);
assert_equals(navigation.entries().length, 4);
assert_equals(fifth_entry_after_push, navigation.entries()[3]);

history.replaceState(5, "");
let fifth_entry_after_replace = appHistory.current;
let fifth_entry_after_replace = navigation.currentEntry;
assert_not_equals(fifth_entry_after_replace, fifth_entry_after_push);
assert_equals(fifth_entry_after_replace.key, fifth_entry_after_push.key);
assert_true(isUUID(fifth_entry_after_replace.key));
assert_not_equals(fifth_entry_after_replace.id, fifth_entry_after_push.id);
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(appHistory.entries().length, 4);
assert_equals(fifth_entry_after_replace, appHistory.entries()[3]);
assert_equals(navigation.entries().length, 4);
assert_equals(fifth_entry_after_replace, navigation.entries()[3]);

location.hash = "6";
let sixth_entry = appHistory.current;
let sixth_entry = navigation.currentEntry;
assert_not_equals(sixth_entry, fifth_entry_after_replace);
assert_equals(sixth_entry.key, fifth_entry_after_replace.key);
assert_true(isUUID(sixth_entry.key));
assert_not_equals(sixth_entry.id, fifth_entry_after_replace.id);
assert_true(isUUID(sixth_entry.id));
assert_not_equals(sixth_entry.url, fifth_entry_after_replace.url);
assert_true(sixth_entry.sameDocument);
assert_equals(appHistory.entries().length, 4);
assert_equals(sixth_entry, appHistory.entries()[3]);
assert_equals(navigation.entries().length, 4);
assert_equals(sixth_entry, navigation.entries()[3]);

appHistory.entries().forEach(entry => {
navigation.entries().forEach(entry => {
assert_true(isUUID(entry.id));
assert_true(isUUID(entry.key));
});
}, "Basic tests for appHistory.current");
}, "Basic tests for navigation.currentEntry");
</script>
8 changes: 4 additions & 4 deletions app-history/app-history-entry/entries-across-origins.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<script>
async_test(t => {
window.onload = t.step_func(() => {
let start_key = i.contentWindow.appHistory.current.key;
let start_id = i.contentWindow.appHistory.current.id;
let start_key = i.contentWindow.navigation.currentEntry.key;
let start_id = i.contentWindow.navigation.currentEntry.id;

let cross_origin_url = new URL("resources/post-entries-length-to-top.html", location.href);
cross_origin_url.hostname = get_host_info().REMOTE_HOST;
Expand All @@ -19,7 +19,7 @@

i.src = "/common/blank.html?2";
i.onload = t.step_func_done(() => {
let entries = i.contentWindow.appHistory.entries();
let entries = i.contentWindow.navigation.entries();
assert_equals(entries.length, 1);
assert_equals(new URL(entries[0].url).search, "?2");
assert_not_equals(entries[0].key, start_key);
Expand All @@ -29,5 +29,5 @@
});
});
});
}, "appHistory.entries() should only contain entries that are both same-origin and contiguous");
}, "navigation.entries() should only contain entries that are both same-origin and contiguous");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<script src="resources/is_uuid.js"></script>

<script>
// This test ensures that appHistory.entries() in an iframe is properly updated
// This test ensures that navigation.entries() in an iframe is properly updated
// when a page is restored from bfcache.
// First, create an iframe and do a fragment navigation in it, so that its
// appHistory.entries().length == 2. Then go back, so that entries()[0] is
// navigation.entries().length == 2. Then go back, so that entries()[0] is
// current. Finally, navigate the main window (which should clobber the
// the iframe's entries()[1]), and come back via bfcache. If the iframe's
// entries() were updated, then its entries().length should have been reduced
Expand All @@ -23,13 +23,13 @@
i.src = "/common/blank.html";
document.body.appendChild(i);
await new Promise(resolve => i.onload = () => setTimeout(resolve, 0));
await i.contentWindow.appHistory.navigate("#foo");
await i.contentWindow.appHistory.back();
window.frames[0].appHistory.entries()[1].ondispose = () => events.push("dispose");
await i.contentWindow.navigation.navigate("#foo");
await i.contentWindow.navigation.back();
window.frames[0].navigation.entries()[1].ondispose = () => events.push("dispose");
window.frames[0].onpageshow = () => events.push("pageshow");
},
async funcAfterAssertion(pageA, pageB) {
assert_equals(await pageA.execute_script(() => window.frames[0].appHistory.entries().length), 1);
assert_equals(await pageA.execute_script(() => window.frames[0].navigation.entries().length), 1);
assert_array_equals(await pageA.execute_script(() => window.events), ["pageshow", "dispose"]);
}
}, "entries() in an iframe must be updated after navigating back to a bfcached page");
Expand Down
10 changes: 5 additions & 5 deletions app-history/app-history-entry/entries-after-bfcache.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script src="resources/is_uuid.js"></script>

<script>
// This test ensures that appHistory.entries() is properly updated when a page
// This test ensures that navigation.entries() is properly updated when a page
// is restored from bfcache. Before navigating away and back, entries() contains
// a single entry representing this document. When restored from bfcache,
// entries() should now have two entries: [0] should still be this document, but
Expand All @@ -16,11 +16,11 @@
runBfcacheTest({
targetOrigin: originSameOrigin,
funcBeforeNavigation: () => {
window.originalEntry0 = appHistory.entries()[0];
window.originalEntry0 = navigation.entries()[0];
},
async funcAfterAssertion(pageA, pageB) {
const entryData = await pageA.execute_script(() => {
return appHistory.entries().map(e => ({
return navigation.entries().map(e => ({
url: e.url,
key: e.key,
id: e.id,
Expand Down Expand Up @@ -50,10 +50,10 @@
assert_true(entryData[0].sameDocument);
assert_false(entryData[1].sameDocument);

const currentIsZero = await pageA.execute_script(() => appHistory.current === appHistory.entries()[0]);
const currentIsZero = await pageA.execute_script(() => navigation.currentEntry === navigation.entries()[0]);
assert_true(currentIsZero);

const zeroIsSameAsOriginal = await pageA.execute_script(() => appHistory.current === window.originalEntry0);
const zeroIsSameAsOriginal = await pageA.execute_script(() => navigation.currentEntry === window.originalEntry0);
assert_true(zeroIsSameAsOriginal);
}
}, "entries() must contain the forward-history page after navigating back to a bfcached page");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
async_test(t => {
window.onload = t.step_func(() => {
i.onload = t.step_func_done(() => {
let entries = i.contentWindow.appHistory.entries();
let entries = i.contentWindow.navigation.entries();
assert_equals(entries.length, 2);
assert_not_equals(entries[1].key, entries[0].key);
assert_not_equals(entries[1].url, entries[0].url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
async_test(t => {
window.onload = t.step_func(() => {
i.onload = t.step_func_done(() => {
let entries = i.contentWindow.appHistory.entries();
let entries = i.contentWindow.navigation.entries();
assert_equals(entries.length, 2);
assert_not_equals(entries[1].key, entries[0].key);
assert_not_equals(entries[1].url, entries[0].url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
i.contentWindow.location.search = "?fork";
await new Promise(r => i.onload = () => t.step_timeout(r, 0));

const entries = i.contentWindow.appHistory.entries();
const entries = i.contentWindow.navigation.entries();
const searches = entries.map(e => (new URL(e.url)).search);
assert_array_equals(searches, ["", "?fork"]);

assert_equals(i.contentWindow.appHistory.entries().at(-1), i.contentWindow.appHistory.current);
}, "appHistory.entries() behavior after forward-pruning due to cross-document navs");
assert_equals(i.contentWindow.navigation.entries().at(-1), i.contentWindow.navigation.currentEntry);
}, "navigation.entries() behavior after forward-pruning due to cross-document navs");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
<script>
async_test(t => {
window.onload = t.step_func(() => {
let start_key = i.contentWindow.appHistory.current.key;
let start_url = i.contentWindow.appHistory.current.url;
let start_id = i.contentWindow.appHistory.current.id;
let start_key = i.contentWindow.navigation.currentEntry.key;
let start_url = i.contentWindow.navigation.currentEntry.url;
let start_id = i.contentWindow.navigation.currentEntry.id;
let did_js_url_nav = false;
i.onload = t.step_func(() => {
if (!did_js_url_nav) {
assert_equals(i.contentWindow.appHistory.entries().length, 2);
before_js_nav_key = i.contentWindow.appHistory.current.key;
before_js_nav_url = i.contentWindow.appHistory.current.url;
before_js_nav_id = i.contentWindow.appHistory.current.id;
assert_equals(i.contentWindow.navigation.entries().length, 2);
before_js_nav_key = i.contentWindow.navigation.currentEntry.key;
before_js_nav_url = i.contentWindow.navigation.currentEntry.url;
before_js_nav_id = i.contentWindow.navigation.currentEntry.id;
i.src = "javascript:'new content'";
did_js_url_nav = true;
} else {
assert_equals(i.contentWindow.appHistory.entries().length, 2);
let first_entry = i.contentWindow.appHistory.entries()[0];
let js_url_entry = i.contentWindow.appHistory.entries()[1];
assert_equals(i.contentWindow.navigation.entries().length, 2);
let first_entry = i.contentWindow.navigation.entries()[0];
let js_url_entry = i.contentWindow.navigation.entries()[1];
assert_equals(first_entry.key, start_key);
assert_equals(first_entry.url, start_url);
assert_equals(first_entry.id, start_id);

assert_equals(js_url_entry, i.contentWindow.appHistory.current);
assert_equals(js_url_entry, i.contentWindow.navigation.currentEntry);
assert_equals(js_url_entry.key, before_js_nav_key);
assert_equals(js_url_entry.url, before_js_nav_url);
assert_not_equals(js_url_entry.id, before_js_nav_id);
t.done();
}
});
i.contentWindow.appHistory.navigate("?1");
i.contentWindow.navigation.navigate("?1");
});
}, "AppHistory behavior after navigation to a javascript: url");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<iframe id="i" src="/common/blank.html"></iframe>
<script>
async_test(t => {
// The navigations in each window should have only added an appHistory to
// The navigations in each window should have only added an navigation to
// their own window.
function assertExpectedEntries(entries, expected_url) {
assert_equals(entries.length, 2);
Expand All @@ -25,10 +25,10 @@
window.onload = () => t.step_timeout(t.step_func(() => {
location.hash = "#1";
i.onload = t.step_func_done(() => {
assertExpectedEntries(appHistory.entries(), location.href);
assertExpectedEntries(i.contentWindow.appHistory.entries(), i.contentWindow.location.href);
assertExpectedEntries(navigation.entries(), location.href);
assertExpectedEntries(i.contentWindow.navigation.entries(), i.contentWindow.location.href);
});
i.contentWindow.location = "/common/blank.html?2";
}), 0);
}, "appHistory.entries() behavior when multiple windows navigate.");
}, "navigation.entries() behavior when multiple windows navigate.");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
async_test(t => {
window.onload = t.step_func(() => {
i.onload = t.step_func_done(() => {
let entries = i.contentWindow.appHistory.entries();
let entries = i.contentWindow.navigation.entries();
assert_equals(entries.length, 2);
assert_not_equals(entries[1].key, entries[0].key);
assert_not_equals(entries[1].url, entries[0].url);
Expand Down
4 changes: 2 additions & 2 deletions app-history/app-history-entry/entries-array-equality.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<script src="/resources/testharnessreport.js"></script>
<script>
test(() => {
assert_not_equals(appHistory.entries(), appHistory.entries());
}, "appHistory.entries() should not return an identical object on repeated invocations");
assert_not_equals(navigation.entries(), navigation.entries());
}, "navigation.entries() should not return an identical object on repeated invocations");
</script>
Loading