зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1718698 [wpt PR 29538] - Move app history tests to public WPT, a=testonly
Automatic update from web-platform-tests Move app history tests to public WPT (#29538) Bug: 1183545 Change-Id: Ie06b392f1982227946a118d16982dff8dd9a4051 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2991902 Auto-Submit: Domenic Denicola <domenic@chromium.org> Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/master@{#897133} Co-authored-by: Domenic Denicola <domenic@chromium.org> -- wpt-commits: 86c19366cdacbeca332982dbd6fd3c7c496f92f2 wpt-pr: 29538
This commit is contained in:
Родитель
bfa08b8fd2
Коммит
ebdfc5ad46
|
@ -0,0 +1,4 @@
|
|||
spec: https://wicg.github.io/app-history/
|
||||
suggested_reviewers:
|
||||
- domenic
|
||||
- natechapin
|
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func_done(() => {
|
||||
let i_entry = i.contentWindow.appHistory.current;
|
||||
assert_true(i_entry.sameDocument);
|
||||
assert_not_equals(i_entry.url, "");
|
||||
assert_not_equals(i_entry.key, "");
|
||||
assert_not_equals(i_entry.id, "");
|
||||
i.remove();
|
||||
assert_false(i_entry.sameDocument);
|
||||
assert_equals(i_entry.url, "");
|
||||
assert_equals(i_entry.key, "");
|
||||
assert_equals(i_entry.id, "");
|
||||
});
|
||||
}, "AppHistoryEntry attributes after detach");
|
||||
</script>
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func_done(() => {
|
||||
let i_appHistory = i.contentWindow.appHistory;
|
||||
assert_not_equals(i_appHistory, null);
|
||||
assert_not_equals(i_appHistory.current, null);
|
||||
assert_equals(i_appHistory.entries().length, 1);
|
||||
i.remove();
|
||||
assert_equals(i_appHistory.current, null);
|
||||
assert_equals(i_appHistory.entries().length, 0);
|
||||
});
|
||||
}, "appHistory.current should be null after iframe removal");
|
||||
</script>
|
|
@ -0,0 +1,107 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/is_uuid.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let first_entry = appHistory.current;
|
||||
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]);
|
||||
|
||||
history.replaceState(2, "", "#2");
|
||||
let second_entry = appHistory.current;
|
||||
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]);
|
||||
|
||||
history.pushState(3, "", "#3");
|
||||
let third_entry = appHistory.current;
|
||||
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]);
|
||||
|
||||
history.pushState(4, "");
|
||||
let fourth_entry = appHistory.current;
|
||||
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]);
|
||||
|
||||
history.replaceState(5, "");
|
||||
let fifth_entry = appHistory.current;
|
||||
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]);
|
||||
|
||||
history.pushState(5, "");
|
||||
let fifth_entry_after_push = appHistory.current;
|
||||
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]);
|
||||
|
||||
history.replaceState(5, "");
|
||||
let fifth_entry_after_replace = appHistory.current;
|
||||
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]);
|
||||
|
||||
location.hash = "6";
|
||||
let sixth_entry = appHistory.current;
|
||||
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]);
|
||||
|
||||
appHistory.entries().forEach(entry => {
|
||||
assert_true(isUUID(entry.id));
|
||||
assert_true(isUUID(entry.key));
|
||||
});
|
||||
}, "Basic tests for appHistory.current");
|
||||
</script>
|
|
@ -0,0 +1,33 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script src="resources/is_uuid.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<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 cross_origin_url = new URL("resources/post-entries-length-to-top.html", location.href);
|
||||
cross_origin_url.hostname = get_host_info().REMOTE_HOST;
|
||||
i.contentWindow.location.assign(cross_origin_url.href);
|
||||
|
||||
window.onmessage = t.step_func(e => {
|
||||
assert_equals(e.data, 1);
|
||||
|
||||
i.src = "/common/blank.html?2";
|
||||
i.onload = t.step_func_done(() => {
|
||||
let entries = i.contentWindow.appHistory.entries();
|
||||
assert_equals(entries.length, 1);
|
||||
assert_equals(new URL(entries[0].url).search, "?2");
|
||||
assert_not_equals(entries[0].key, start_key);
|
||||
assert_not_equals(entries[0].id, start_id);
|
||||
assert_true(isUUID(entries[0].key));
|
||||
assert_true(isUUID(entries[0].id));
|
||||
});
|
||||
});
|
||||
});
|
||||
}, "appHistory.entries() should only contain entries that are both same-origin and contiguous");
|
||||
</script>
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/is_uuid.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
i.onload = t.step_func_done(() => {
|
||||
let entries = i.contentWindow.appHistory.entries();
|
||||
assert_equals(entries.length, 2);
|
||||
assert_not_equals(entries[1].key, entries[0].key);
|
||||
assert_not_equals(entries[1].url, entries[0].url);
|
||||
assert_equals(entries[1].url, "about:blank");
|
||||
assert_not_equals(entries[1].id, entries[0].id);
|
||||
|
||||
assert_true(isUUID(entries[0].key));
|
||||
assert_true(isUUID(entries[0].id));
|
||||
assert_true(isUUID(entries[1].key));
|
||||
assert_true(isUUID(entries[1].id));
|
||||
});
|
||||
i.src = "about:blank";
|
||||
});
|
||||
}, "AppHistory behavior after navigation to about:blank");
|
||||
</script>
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/is_uuid.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
i.onload = t.step_func_done(() => {
|
||||
let entries = i.contentWindow.appHistory.entries();
|
||||
assert_equals(entries.length, 2);
|
||||
assert_not_equals(entries[1].key, entries[0].key);
|
||||
assert_not_equals(entries[1].url, entries[0].url);
|
||||
assert_equals(new URL(entries[1].url).protocol, "blob:");
|
||||
assert_not_equals(entries[1].id, entries[0].id);
|
||||
|
||||
assert_true(isUUID(entries[0].key));
|
||||
assert_true(isUUID(entries[0].id));
|
||||
assert_true(isUUID(entries[1].key));
|
||||
assert_true(isUUID(entries[1].id));
|
||||
});
|
||||
i.src = URL.createObjectURL(new Blob(["<body></body>"]));
|
||||
});
|
||||
}, "AppHistory behavior after navigation to a blob: url");
|
||||
</script>
|
|
@ -0,0 +1,23 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<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;
|
||||
window.onmessage = t.step_func_done(e => {
|
||||
assert_equals(e.data.length, 1);
|
||||
assert_not_equals(e.data.key, start_key);
|
||||
assert_equals(e.data.protocol, "data:");
|
||||
assert_not_equals(e.data.id, start_id);
|
||||
});
|
||||
i.src = "data:text/html,<script>top.postMessage({ length: appHistory.entries().length, " +
|
||||
"key: appHistory.current.key, protocol: new URL(appHistory.current.url).protocol," +
|
||||
"id: appHistory.current.id}, '*')</sc" +
|
||||
"ript>";
|
||||
});
|
||||
}, "AppHistory behavior after navigation to a data: url");
|
||||
</script>
|
|
@ -0,0 +1,38 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<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 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;
|
||||
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(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.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");
|
||||
});
|
||||
}, "AppHistory behavior after navigation to a javascript: url");
|
||||
</script>
|
|
@ -0,0 +1,34 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/is_uuid.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// The navigations in each window should have only added an appHistory to
|
||||
// their own window.
|
||||
function assertExpectedEntries(entries, expected_url) {
|
||||
assert_equals(entries.length, 2);
|
||||
assert_not_equals(entries[1].key, entries[0].key);
|
||||
assert_not_equals(entries[1].url, entries[0].url);
|
||||
assert_not_equals(entries[1].id, entries[0].id);
|
||||
assert_true(isUUID(entries[0].key));
|
||||
assert_true(isUUID(entries[0].id));
|
||||
assert_true(isUUID(entries[1].key));
|
||||
assert_true(isUUID(entries[1].id));
|
||||
|
||||
assert_equals(entries[1].url, expected_url);
|
||||
}
|
||||
|
||||
// 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(() => {
|
||||
location.hash = "#1";
|
||||
i.onload = t.step_func_done(() => {
|
||||
assertExpectedEntries(appHistory.entries(), location.href);
|
||||
assertExpectedEntries(i.contentWindow.appHistory.entries(), i.contentWindow.location.href);
|
||||
});
|
||||
i.contentWindow.location = "/common/blank.html?2";
|
||||
}), 0);
|
||||
}, "appHistory.entries() behavior when multiple windows navigate.");
|
||||
</script>
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/is_uuid.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
i.onload = t.step_func_done(() => {
|
||||
let entries = i.contentWindow.appHistory.entries();
|
||||
assert_equals(entries.length, 2);
|
||||
assert_not_equals(entries[1].key, entries[0].key);
|
||||
assert_not_equals(entries[1].url, entries[0].url);
|
||||
assert_equals(entries[1].url, "about:srcdoc");
|
||||
assert_not_equals(entries[1].id, entries[0].id);
|
||||
|
||||
assert_true(isUUID(entries[0].key));
|
||||
assert_true(isUUID(entries[0].id));
|
||||
assert_true(isUUID(entries[1].key));
|
||||
assert_true(isUUID(entries[1].id));
|
||||
});
|
||||
i.srcdoc = "new";
|
||||
});
|
||||
}, "AppHistory behavior after setting a srcdoc attribute");
|
||||
</script>
|
|
@ -0,0 +1,8 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<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");
|
||||
</script>
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
const first_entry = appHistory.entries()[0];
|
||||
history.pushState(1, "", "#1");
|
||||
assert_equals(appHistory.entries()[0], first_entry);
|
||||
history.back();
|
||||
window.onpopstate = t.step_func_done(() => {
|
||||
const second_entry = appHistory.entries()[1];
|
||||
history.replaceState(0, "", "#0");
|
||||
assert_equals(appHistory.entries()[1], second_entry);
|
||||
});
|
||||
}, "A non-active entry in appHistory.entries() should not be modified when a different entry is modified");
|
||||
</script>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// 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 = appHistory.current;
|
||||
assert_equals(replaced_entry.index, 0);
|
||||
appHistory.navigate("#0", { replace: true });
|
||||
assert_equals(replaced_entry.index, -1);
|
||||
|
||||
// Remove the entry by detaching its window.
|
||||
let iframe_entry = i.contentWindow.appHistory.current;
|
||||
assert_equals(iframe_entry.index, 0);
|
||||
i.remove();
|
||||
assert_equals(iframe_entry.index, -1);
|
||||
t.done();
|
||||
}), 0);
|
||||
}, "AppHistoryEntry.index should return -1 when not in AppHistory.entries");
|
||||
</script>
|
|
@ -0,0 +1,15 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="resources/key-navigate-back-cross-document-helper.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.finish = t.step_func_done((end_key, end_id) => {
|
||||
assert_equals(window.start_key, end_key);
|
||||
assert_equals(window.start_id, end_id);
|
||||
// The new history entry in the iframe should not add any entries to
|
||||
// this window's appHistory.
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
});
|
||||
}, "AppHistoryEntry.key behavior on cross-document back navigation");
|
||||
</script>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let key = appHistory.current.key;
|
||||
let id = appHistory.current.id;
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
|
||||
history.pushState("hash", "", "#hash");
|
||||
assert_not_equals(key, appHistory.current.key);
|
||||
assert_not_equals(id, appHistory.current.id);
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current.index, 1);
|
||||
|
||||
window.onpopstate = t.step_func_done(() => {
|
||||
assert_equals(key, appHistory.current.key);
|
||||
assert_equals(id, appHistory.current.id);
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current.index, 0);
|
||||
});
|
||||
history.back();
|
||||
}, "AppHistoryEntry.key behavior on same-document back navigation");
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
let key = i.contentWindow.appHistory.current.key;
|
||||
let id = i.contentWindow.appHistory.current.id;
|
||||
i.contentWindow.location.reload();
|
||||
i.onload = t.step_func_done(() => {
|
||||
assert_equals(key, i.contentWindow.appHistory.current.key);
|
||||
assert_not_equals(id, i.contentWindow.appHistory.current.id);
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
});
|
||||
});
|
||||
}, "AppHistoryEntry.key behavior after location.reload()");
|
||||
</script>
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
let key_before_replace = i.contentWindow.appHistory.current.key;
|
||||
window.onmessage = t.step_func_done(e => assert_not_equals(key_before_replace, e.data));
|
||||
|
||||
let cross_origin_url = new URL("resources/post-key-to-top.html", location.href);
|
||||
cross_origin_url.hostname = get_host_info().REMOTE_HOST;
|
||||
i.contentWindow.location.replace(cross_origin_url.href);
|
||||
});
|
||||
}, "AppHistoryEntry.key behavior after location.replace()");
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
let key = i.contentWindow.appHistory.current.key;
|
||||
let id = i.contentWindow.appHistory.current.id;
|
||||
i.contentWindow.location.replace("/common/blank.html?query");
|
||||
i.onload = t.step_func_done(() => {
|
||||
assert_equals(key, i.contentWindow.appHistory.current.key);
|
||||
assert_not_equals(id, i.contentWindow.appHistory.current.id);
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
});
|
||||
});
|
||||
}, "AppHistoryEntry.key behavior after location.replace()");
|
||||
</script>
|
|
@ -0,0 +1,3 @@
|
|||
function isUUID(key) {
|
||||
return /[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/.test(key);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script>
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => step_timeout(() => {
|
||||
if (location.search == "?go-back") {
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current.index, 1);
|
||||
// Step 2: Navigate back.
|
||||
history.back();
|
||||
return;
|
||||
}
|
||||
if (top.start_key) {
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current.index, 0);
|
||||
// Step 3: Notify parent, which will ensure the same key is used after back navigation.
|
||||
top.finish(appHistory.current.key, appHistory.current.id);
|
||||
return;
|
||||
}
|
||||
// Step 1: Record initial key and navigate.
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
top.start_key = appHistory.current.key;
|
||||
top.start_id = appHistory.current.id;
|
||||
location.search = "go-back";
|
||||
}, 0);
|
||||
</script>
|
|
@ -0,0 +1,7 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script>
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => step_timeout(() => top.postMessage(appHistory.entries().length, "*"), 0);
|
||||
</script>
|
|
@ -0,0 +1,3 @@
|
|||
<script>
|
||||
top.postMessage(appHistory.current.key, "*");
|
||||
</script>
|
|
@ -0,0 +1,30 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// 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(() => {
|
||||
let entry1 = appHistory.current;
|
||||
assert_true(entry1.sameDocument);
|
||||
|
||||
location = "#hash";
|
||||
let entry2 = appHistory.current;
|
||||
assert_not_equals(entry1, entry2);
|
||||
assert_true(entry1.sameDocument);
|
||||
|
||||
history.pushState("push", "", "#push");
|
||||
let entry3 = appHistory.current;
|
||||
assert_not_equals(entry1, entry3);
|
||||
assert_not_equals(entry2, entry3);
|
||||
assert_true(entry1.sameDocument);
|
||||
assert_true(entry2.sameDocument);
|
||||
|
||||
assert_equals(appHistory.entries().length, 3);
|
||||
assert_equals(appHistory.entries()[0], entry1);
|
||||
assert_equals(appHistory.entries()[1], entry2);
|
||||
assert_equals(appHistory.entries()[2], entry3);
|
||||
}), 0);
|
||||
}, "AppHistoryEntry.sameDocument after same-document navigations");
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
let i_entry = i.contentWindow.appHistory.current;
|
||||
assert_true(i_entry.sameDocument);
|
||||
i.onload = t.step_func_done(() => assert_false(i_entry.sameDocument));
|
||||
i.contentWindow.location = "about:blank";
|
||||
});
|
||||
}, "AppHistoryEntry.sameDocument after cross-document navigation");
|
||||
</script>
|
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<a id="a" href="https://does-not-exist/foo.html"></a>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_false(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(e.formData, null);
|
||||
assert_equals(e.destination.url, "https://does-not-exist/foo.html");
|
||||
assert_false(e.destination.sameDocument);
|
||||
e.preventDefault();
|
||||
});
|
||||
a.click();
|
||||
}, "<a> cross-origin navigate event");
|
||||
</script>
|
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<a id="a" href="#1"></a>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_true(e.hashChange);
|
||||
assert_equals(e.formData, null);
|
||||
assert_equals(new URL(e.destination.url).hash, "#1");
|
||||
assert_true(e.destination.sameDocument);
|
||||
e.preventDefault();
|
||||
t.step_timeout(t.step_func_done(() => assert_equals(location.hash, "")), 0);
|
||||
});
|
||||
a.click();
|
||||
}, "Fragment <a> click fires navigate event");
|
||||
</script>
|
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<a id="a" href="foo.html"></a>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(e.formData, null);
|
||||
assert_equals(new URL(e.destination.url).pathname,
|
||||
"/app-history/navigate-event/foo.html");
|
||||
assert_false(e.destination.sameDocument);
|
||||
e.preventDefault();
|
||||
});
|
||||
a.click();
|
||||
}, "<a> cross-document (but same-origin) navigate event");
|
||||
</script>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/resources/testdriver.js"></script>
|
||||
<script src="/resources/testdriver-vendor.js"></script>
|
||||
<script src="/resources/testdriver-actions.js"></script>
|
||||
<a id="a" href="#1">Click me</a>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_true(e.userInitiated);
|
||||
assert_true(e.hashChange);
|
||||
assert_equals(e.formData, null);
|
||||
assert_equals(new URL(e.destination.url).hash, "#1");
|
||||
assert_true(e.destination.sameDocument);
|
||||
e.preventDefault();
|
||||
t.step_timeout(t.step_func_done(() => assert_equals(location.hash, "")), 0);
|
||||
});
|
||||
|
||||
test_driver.click(a);
|
||||
}, "Fragment <a> click fires navigate event");
|
||||
</script>
|
|
@ -0,0 +1,26 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="iframe" name="i" src="/common/blank.html"></iframe>
|
||||
<a id="a" href="foo.html" target="i"></a>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
appHistory.onnavigate = t.step_func_done(() => {
|
||||
assert_unreached("onnavigate should not have fired in source window");
|
||||
});
|
||||
iframe.contentWindow.appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(e.formData, null);
|
||||
assert_equals(new URL(e.destination.url).pathname,
|
||||
"/app-history/navigate-event/foo.html");
|
||||
assert_false(e.destination.sameDocument);
|
||||
e.preventDefault();
|
||||
});
|
||||
a.click();
|
||||
});
|
||||
}, "<a> with a target fires navigate event in target window but not source");
|
||||
</script>
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
i.contentWindow.appHistory.navigate("?foo");
|
||||
i.onload = t.step_func(() => {
|
||||
i.contentWindow.appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_false(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).pathname, "/common/blank.html");
|
||||
assert_false(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
assert_equals(e.info, "hi");
|
||||
});
|
||||
assert_true(i.contentWindow.appHistory.canGoBack);
|
||||
i.contentWindow.appHistory.back({ navigateInfo: "hi" });
|
||||
})
|
||||
});
|
||||
}, "navigate event for appHistory.back() - cross-document");
|
||||
</script>
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
appHistory.navigate("#foo").then(() => {
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_true(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).hash, "");
|
||||
assert_true(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
assert_equals(e.info, "hi");
|
||||
});
|
||||
assert_true(appHistory.canGoBack);
|
||||
appHistory.back({ navigateInfo: "hi" });
|
||||
});
|
||||
}, 0);
|
||||
}, "navigate event for appHistory.back() - same-document");
|
||||
</script>
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_true(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).hash, "#foo");
|
||||
assert_true(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
});
|
||||
appHistory.navigate("#foo");
|
||||
}, "navigate event for appHistory.navigate()");
|
||||
</script>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let iframe_url = new URL("resources/cross-origin-iframe-helper.html", location.href);
|
||||
iframe_url.hostname = get_host_info().REMOTE_HOST;
|
||||
let iframe = document.createElement("iframe")
|
||||
iframe.src = iframe_url;
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
window.onmessage = t.step_func_done(e => {
|
||||
assert_equals(e.data, "cancelable,canRespond,hashChange,");
|
||||
});
|
||||
|
||||
appHistory.onnavigate = t.step_func_done(() => {
|
||||
assert_unreached("onnavigate should not have fired in source window");
|
||||
});
|
||||
window.onload = t.step_func(() => iframe.contentWindow.location = iframe_url + "#");
|
||||
}, "location API on another window fires navigate event even if the target window is cross-origin");
|
||||
</script>
|
||||
<body>
|
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// 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(() => {
|
||||
let navState = { statevar: "state" };
|
||||
appHistory.navigate("#foo", { replace: true, state: navState });
|
||||
appHistory.navigate("#bar");
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_not_equals(e.destination, null);
|
||||
assert_not_equals(e.destination.getState(), undefined);
|
||||
assert_not_equals(e.destination.getState(), e.destination.getState());
|
||||
});
|
||||
appHistory.back();
|
||||
}), 0);
|
||||
}, "navigate event destination.getState() on back/forward navigation");
|
||||
</script>
|
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
let navState = { statevar: "state" };
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_not_equals(e.destination, null);
|
||||
assert_not_equals(e.destination.getState(), undefined);
|
||||
assert_equals(e.destination.getState().statevar, "state");
|
||||
assert_not_equals(e.destination.getState(), e.destination.getState());
|
||||
});
|
||||
appHistory.navigate("#foo", { state: navState });
|
||||
}, 0);
|
||||
}, "navigate event destination.getState() should be the state given to navigate()");
|
||||
</script>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/resources/testdriver.js"></script>
|
||||
<script src="/resources/testdriver-vendor.js"></script>
|
||||
<script src="/resources/testdriver-actions.js"></script>
|
||||
<form id="form" action="">
|
||||
<input id="submit" type="submit" value="Submit">
|
||||
</form>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_true(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(e.destination.url, location.href + "?");
|
||||
assert_false(e.destination.sameDocument);
|
||||
assert_not_equals(e.formData, null);
|
||||
e.preventDefault();
|
||||
});
|
||||
window.onload = t.step_func(() => test_driver.click(submit));
|
||||
}, "<form> submission fires navigate event");
|
||||
</script>
|
|
@ -0,0 +1,27 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="iframe" name="i" src="/common/blank.html"></iframe>
|
||||
<form id="form" action="foo.html" target="i"></form>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
appHistory.onnavigate = t.step_func_done(() => {
|
||||
assert_unreached("onnavigate should not have fired in source window");
|
||||
});
|
||||
iframe.contentWindow.appHistory.onnavigate = t.step_func_done(e => {
|
||||
e.preventDefault();
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).pathname,
|
||||
"/app-history/navigate-event/foo.html");
|
||||
assert_false(e.destination.sameDocument);
|
||||
assert_not_equals(e.formData, null);
|
||||
e.preventDefault();
|
||||
});
|
||||
form.submit();
|
||||
});
|
||||
}, "<form> submission with a target fires navigate event in target window but not source");
|
||||
</script>
|
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<form id="form" action=""></form>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(e.destination.url, location.href + "?");
|
||||
assert_false(e.destination.sameDocument);
|
||||
assert_not_equals(e.formData, null);
|
||||
e.preventDefault();
|
||||
});
|
||||
window.onload = t.step_func(() => form.submit());
|
||||
}, "<form> submission fires navigate event");
|
||||
</script>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_timeout(() => {
|
||||
let start_length = history.length;
|
||||
location.hash = "#1";
|
||||
assert_equals(history.length, start_length + 1);
|
||||
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_true(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).hash, "");
|
||||
assert_true(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
});
|
||||
|
||||
history.back();
|
||||
}, 0);
|
||||
}, "history.back() fires the navigate event and sets hashChange when reversing a fragment navigation");
|
||||
</script>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_timeout(() => {
|
||||
let start_length = history.length;
|
||||
history.pushState(1, "", "pushState.html");
|
||||
assert_equals(history.length, start_length + 1);
|
||||
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).hash, "");
|
||||
assert_true(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
});
|
||||
|
||||
history.back();
|
||||
}, 0);
|
||||
}, "history.back() fires the navigate event when reversing a pushState()");
|
||||
</script>
|
|
@ -0,0 +1,22 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
i.contentWindow.appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).pathname, "/common/blank.html");
|
||||
assert_false(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
i.contentWindow.history.go(0);
|
||||
});
|
||||
}, "history.go(0) fires the navigate event");
|
||||
</script>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let start_length = history.length;
|
||||
appHistory.onnavigate = t.step_func(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).hash, "#1");
|
||||
assert_true(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
e.preventDefault();
|
||||
t.step_timeout(t.step_func_done(() => {
|
||||
assert_equals(location.hash, "");
|
||||
assert_equals(history.state, null);
|
||||
assert_equals(history.length, start_length);
|
||||
}), 0);
|
||||
});
|
||||
history.pushState(1, null, "#1");
|
||||
}, "history.pushState() fires the navigate event");
|
||||
</script>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let start_length = history.length;
|
||||
appHistory.onnavigate = t.step_func(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).hash, "#1");
|
||||
assert_true(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
e.preventDefault();
|
||||
t.step_timeout(t.step_func_done(() => {
|
||||
assert_equals(location.hash, "");
|
||||
assert_equals(history.state, null);
|
||||
assert_equals(history.length, start_length);
|
||||
}), 0);
|
||||
});
|
||||
history.replaceState(1, null, "#1");
|
||||
}, "history.replaceState() fires the navigate event");
|
||||
</script>
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="iframe" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
appHistory.onnavigate = t.step_func_done(() => {
|
||||
assert_unreached("onnavigate should not have fired in source window");
|
||||
});
|
||||
iframe.contentWindow.appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_true(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).hash, "#1");
|
||||
assert_true(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
e.preventDefault();
|
||||
t.step_timeout(t.step_func_done(() => assert_equals(location.hash, "")), 0);
|
||||
});
|
||||
iframe.contentWindow.location.hash = "#1";
|
||||
});
|
||||
}, "location API on another window fires navigate event in the target window only");
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<form id="form" action=""></form>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_true(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).hash, "#1");
|
||||
assert_true(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
});
|
||||
location.href = "#1";
|
||||
}, "location API fires navigate event");
|
||||
</script>
|
|
@ -0,0 +1,22 @@
|
|||
<!doctype html>
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="resources/meta-refresh.html"></iframe>
|
||||
</head>
|
||||
<script>
|
||||
async_test(t => {
|
||||
i.onload = t.step_func(() => {
|
||||
i.contentWindow.appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_equals(e.destination.url, i.contentWindow.location.href);
|
||||
assert_false(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
e.preventDefault();
|
||||
});
|
||||
});
|
||||
}, "<meta> refresh fires navigate event");
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_true(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).hash, "#1");
|
||||
assert_true(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
e.preventDefault();
|
||||
});
|
||||
window.onload = t.step_func(() => window.open("#1", "_self"));
|
||||
}, "window.open() fires navigate event when targeting self");
|
||||
</script>
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="iframe" name="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
appHistory.onnavigate = t.step_func_done(() => {
|
||||
assert_unreached("onnavigate should not have fired in source window");
|
||||
});
|
||||
iframe.contentWindow.appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_true(e.hashChange);
|
||||
assert_equals(new URL(e.destination.url).hash, "#1");
|
||||
assert_true(e.destination.sameDocument);
|
||||
assert_equals(e.formData, null);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
window.open("/common/blank.html#1", "i");
|
||||
});
|
||||
}, "window.open() fires navigate event in target window but not source");
|
||||
</script>
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<form id="form" action=""></form>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
appHistory.onnavigate = t.step_func(e => {
|
||||
if (e.info == 1) {
|
||||
appHistory.navigate("#2", { navigateInfo: 2 });
|
||||
assert_true(e.defaultPrevented);
|
||||
}
|
||||
});
|
||||
await promise_rejects_dom(t, 'AbortError', appHistory.navigate("#1", { navigateInfo: 1 }));
|
||||
assert_equals(location.hash, "#2");
|
||||
}, "if navigate() is called inside onnavigate, the previous navigation and navigate event are cancelled");
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="resources/navigatesuccess-cross-document-helper.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// The iframe will post a message if it receives a navigatesuccess.
|
||||
window.onmessage = t.unreached_func("navigatesuccess received");
|
||||
window.onload = t.step_func(() => {
|
||||
i.contentWindow.location.search = "?1";
|
||||
i.onload = t.step_func_done(() => assert_equals(i.contentWindow.location.search, "?1"));
|
||||
});
|
||||
}, "navigatesucess does not fire for a cross-document navigation");
|
||||
</script>
|
|
@ -0,0 +1,10 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<a id="a" href="#1"></a>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigatesuccess = t.step_func_done(() => assert_equals(location.hash, "#1"));
|
||||
a.click();
|
||||
}, "navigatesucess fires for a same-document navigation");
|
||||
</script>
|
|
@ -0,0 +1,17 @@
|
|||
<script>
|
||||
appHistory.onnavigate = e => {
|
||||
let message = "";
|
||||
if (e.cancelable)
|
||||
message += "cancelable,";
|
||||
if (e.canRespond)
|
||||
message += "canRespond,";
|
||||
if (e.userInitiated)
|
||||
message += "userInitiated,";
|
||||
if (e.hashChange)
|
||||
message += "hashChange,";
|
||||
if (e.formData != null)
|
||||
message += "formData,";
|
||||
e.preventDefault();
|
||||
top.postMessage(message, "*");
|
||||
};
|
||||
</script>
|
|
@ -0,0 +1,4 @@
|
|||
<head>
|
||||
<meta http-equiv="refresh" content="0"></meta>
|
||||
</head>
|
||||
<body></body>
|
|
@ -0,0 +1,6 @@
|
|||
<!doctype html>
|
||||
<head>
|
||||
<script>
|
||||
appHistory.onnavigatesuccess = () => top.postMessage("navigatesucess received");
|
||||
</script>
|
||||
</head>
|
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
appHistory.navigate("#foo").then(() => {
|
||||
assert_true(appHistory.canGoBack);
|
||||
appHistory.onnavigate = t.step_func(e => e.respondWith(Promise.resolve()));
|
||||
appHistory.back().then(t.step_func_done(() => {
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current, appHistory.entries()[0]);
|
||||
}));
|
||||
});
|
||||
}, 0);
|
||||
}, "AppHistoryNavigateEvent.respondWith can intercept appHistory.back()");
|
||||
</script>
|
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let target_url = location.href + "?1";
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_true(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
e.respondWith(Promise.resolve().then(
|
||||
t.step_func_done(() => assert_equals(location.href, target_url))));
|
||||
});
|
||||
|
||||
window.onload = t.step_func(() => location.href = target_url);
|
||||
}, "AppHistoryNavigateEvent.respondWith intercepts a same-origin cross-document navigation");
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
assert_true(e.cancelable);
|
||||
assert_false(e.canRespond);
|
||||
assert_false(e.userInitiated);
|
||||
assert_false(e.hashChange);
|
||||
assert_throws_dom("SecurityError", () => e.respondWith(Promise.resolve()));
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
window.onload = t.step_func(() => location.href = get_host_info().HTTPS_REMOTE_ORIGIN);
|
||||
}, "AppHistoryNavigateEvent.respondWith should throw if called for a cross origin navigation");
|
||||
</script>
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
i.contentWindow.appHistory.onnavigate = t.step_func_done(e => {
|
||||
let iframe_constructor = i.contentWindow.DOMException;
|
||||
i.remove();
|
||||
assert_throws_dom("InvalidStateError", iframe_constructor, () => e.respondWith(Promise.resolve()));
|
||||
});
|
||||
|
||||
i.contentWindow.location.href = "#1";
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,23 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let start_length = history.length;
|
||||
appHistory.onnavigate = t.step_func(e => {
|
||||
e.respondWith(new Promise(resolve => t.step_timeout(() => {
|
||||
resolve();
|
||||
t.step_timeout(t.step_func_done(() => {
|
||||
assert_equals(location.hash, "#1");
|
||||
assert_equals(history.state, "update");
|
||||
assert_equals(history.length, start_length + 1);
|
||||
}, 0));
|
||||
}, 0)));
|
||||
});
|
||||
|
||||
history.pushState("update", "", "#1");
|
||||
assert_equals(location.hash, "#1");
|
||||
assert_equals(history.state, "update");
|
||||
assert_equals(history.length, start_length + 1);
|
||||
}, "AppHistoryNavigateEvent.respondWith should proceed if the given promise resolves");
|
||||
</script>
|
|
@ -0,0 +1,23 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let start_length = history.length;
|
||||
appHistory.onnavigate = t.step_func(e => {
|
||||
e.respondWith(new Promise(resolve => t.step_timeout(() => {
|
||||
resolve();
|
||||
t.step_timeout(t.step_func_done(() => {
|
||||
assert_equals(location.hash, "#1");
|
||||
assert_equals(history.state, "update");
|
||||
assert_equals(history.length, start_length);
|
||||
}, 0));
|
||||
}, 0)));
|
||||
});
|
||||
|
||||
history.replaceState("update", "", "#1");
|
||||
assert_equals(location.hash, "#1");
|
||||
assert_equals(history.state, "update");
|
||||
assert_equals(history.length, start_length);
|
||||
}, "AppHistoryNavigateEvent.respondWith should proceed if the given promise resolves");
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigate = t.step_func_done(e => {
|
||||
e.respondWith(Promise.resolve());
|
||||
assert_throws_dom("InvalidStateError", () => e.respondWith(Promise.resolve()));
|
||||
});
|
||||
|
||||
location.href = "#1";
|
||||
assert_equals(location.hash, "");
|
||||
}, "AppHistoryNavigateEvent.respondWith throws if invoked more than once");
|
||||
</script>
|
|
@ -0,0 +1,8 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
assert_throws_dom("SecurityError", () => new AppHistoryNavigateEvent("navigate").respondWith(Promise.resolve()));
|
||||
}, "AppHistoryNavigateEvent.respondWith throws if invoked on a synthetic event");
|
||||
</script>
|
|
@ -0,0 +1,26 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
const err = new TypeError("a message");
|
||||
let start_href = location.href;
|
||||
|
||||
appHistory.onnavigatesuccess = t.step_func_done(assert_unreached);
|
||||
appHistory.onnavigateerror = t.step_func_done(e => {
|
||||
assert_equals(location.hash, "#1");
|
||||
assert_equals(e.constructor, ErrorEvent);
|
||||
assert_true(e.error === err);
|
||||
assert_equals(e.message, "Uncaught TypeError: a message");
|
||||
assert_equals(e.filename, start_href);
|
||||
assert_greater_than(e.colno, 0);
|
||||
assert_greater_than(e.lineno, 0);
|
||||
});
|
||||
appHistory.onnavigate = e => {
|
||||
e.respondWith(new Promise((resolve, reject) => t.step_timeout(() => reject(err), 0)));
|
||||
};
|
||||
|
||||
location.href = "#1";
|
||||
assert_equals(location.hash, "#1");
|
||||
}, "AppHistoryNavigateEvent.respondWith should abort if the given promise rejects");
|
||||
</script>
|
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
appHistory.onnavigatesuccess = t.step_func_done(e => {
|
||||
assert_equals(location.hash, "#1");
|
||||
assert_equals(e.constructor, Event);
|
||||
assert_false(e.bubbles);
|
||||
assert_false(e.cancelable);
|
||||
});
|
||||
appHistory.onnavigateerror = t.step_func_done(assert_unreached);
|
||||
appHistory.onnavigate = e => {
|
||||
e.respondWith(new Promise(resolve => t.step_timeout(resolve, 0)));
|
||||
};
|
||||
|
||||
location.href = "#1";
|
||||
assert_equals(location.hash, "#1");
|
||||
}, "AppHistoryNavigateEvent.respondWith should proceed if the given promise resolves");
|
||||
</script>
|
|
@ -0,0 +1,40 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
let onnavigate_calls = 0;
|
||||
let onnavigatesuccess_calls = 0;
|
||||
appHistory.onnavigate = e => {
|
||||
onnavigate_calls++;
|
||||
e.respondWith(Promise.resolve());
|
||||
}
|
||||
appHistory.onnavigatesuccess = t.step_func(e => {
|
||||
onnavigatesuccess_calls++;
|
||||
if (onnavigatesuccess_calls == 3) {
|
||||
assert_equals(appHistory.entries().length, 3);
|
||||
assert_equals(appHistory.current.index, 1);
|
||||
assert_equals(onnavigate_calls, 3);
|
||||
history.back();
|
||||
} else if (onnavigatesuccess_calls == 4) {
|
||||
assert_equals(appHistory.entries().length, 3);
|
||||
assert_equals(appHistory.current.index, 0);
|
||||
assert_equals(onnavigate_calls, 4);
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
|
||||
appHistory.navigate("?foo")
|
||||
.then(t.step_func(() => appHistory.navigate("?bar")))
|
||||
.then(t.step_func(() => {
|
||||
assert_equals(appHistory.entries().length, 3);
|
||||
assert_equals(appHistory.current.index, 2);
|
||||
assert_equals(onnavigate_calls, 2);
|
||||
history.back();
|
||||
}));
|
||||
}, 0);
|
||||
}, "AppHistoryNavigateEvent.respondWith can intercept same-document history.back()");
|
||||
</script>
|
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
assert_equals(appHistory.entries()[0], appHistory.current);
|
||||
assert_false(appHistory.canGoBack);
|
||||
assert_false(appHistory.canGoForward);
|
||||
await promise_rejects_dom(t, 'InvalidStateError', appHistory.back());
|
||||
await promise_rejects_dom(t, 'InvalidStateError', appHistory.forward());
|
||||
}, "back() and forward() out of bounds");
|
||||
</script>
|
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
appHistory.navigate("#top");
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
i.contentWindow.appHistory.navigate("#1");
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current.index, 1);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 1);
|
||||
assert_true(appHistory.canGoBack);
|
||||
assert_true(i.contentWindow.appHistory.canGoBack);
|
||||
|
||||
// There are 2 joint session history entries containing the iframe's
|
||||
// previous key. Navigate to the nearest one (which navigates the iframe
|
||||
// but not the top window).
|
||||
i.contentWindow.appHistory.back().then(t.step_func_done(() => {
|
||||
assert_equals(appHistory.current.index, 1);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
}));
|
||||
}, 0);
|
||||
}, "appHistory.back() goes to the nearest back entry");
|
||||
</script>
|
|
@ -0,0 +1,40 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
appHistory.navigate("#top");
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
i.contentWindow.appHistory.navigate("#1");
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current.index, 1);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 1);
|
||||
assert_true(appHistory.canGoBack);
|
||||
assert_true(i.contentWindow.appHistory.canGoBack);
|
||||
|
||||
i.contentWindow.appHistory.back().then(t.step_func(() => {
|
||||
assert_equals(appHistory.current.index, 1);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
appHistory.back().then(t.step_func(() => {
|
||||
assert_equals(appHistory.current.index, 0);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
// There are 2 joint session history entries containing the top window's
|
||||
// final key. Navigate to the nearest one (which navigates only the
|
||||
// top window).
|
||||
appHistory.forward().then(t.step_func_done(() => {
|
||||
assert_equals(appHistory.current.index, 1);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
}, 0);
|
||||
}, "appHistory.forward() goes to the nearest forward entry");
|
||||
</script>
|
|
@ -0,0 +1,35 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
appHistory.navigate("#top");
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
|
||||
let iframe_initial_key = i.contentWindow.appHistory.current.key;
|
||||
i.contentWindow.appHistory.navigate("#1");
|
||||
i.contentWindow.appHistory.navigate("#2");
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 3);
|
||||
assert_equals(appHistory.current.index, 1);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 2);
|
||||
assert_true(appHistory.canGoBack);
|
||||
assert_true(i.contentWindow.appHistory.canGoBack);
|
||||
|
||||
// There are 2 joint session history entries containing the iframe's
|
||||
// initial key. Navigate to the nearest one (which navigates the iframe
|
||||
// but not the top window).
|
||||
i.contentWindow.appHistory.goTo(iframe_initial_key).then(t.step_func_done(() => {
|
||||
assert_equals(appHistory.current.index, 1);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
}));
|
||||
}, 0);
|
||||
}, "appHistory.goTo() goes to the nearest entry when going back");
|
||||
</script>
|
|
@ -0,0 +1,43 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
let initial_key = appHistory.current.key;
|
||||
appHistory.navigate("#top1");
|
||||
appHistory.navigate("#top2");
|
||||
assert_equals(appHistory.entries().length, 3);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
i.contentWindow.appHistory.navigate("#1");
|
||||
assert_equals(appHistory.entries().length, 3);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current.index, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 1);
|
||||
assert_true(appHistory.canGoBack);
|
||||
assert_true(i.contentWindow.appHistory.canGoBack);
|
||||
let final_key = appHistory.current.key;
|
||||
|
||||
i.contentWindow.appHistory.back().then(t.step_func(() => {
|
||||
assert_equals(appHistory.current.index, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
appHistory.goTo(initial_key).then(t.step_func(() => {
|
||||
assert_equals(appHistory.current.index, 0);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
// There are 2 joint session history entries containing the top window's
|
||||
// final key. Navigate to the nearest one (which navigates only the
|
||||
// top window).
|
||||
appHistory.goTo(final_key).then(t.step_func_done(() => {
|
||||
assert_equals(appHistory.current.index, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
}, 0);
|
||||
}, "appHistory.goTo() goes to the nearest entry when going forward");
|
||||
</script>
|
|
@ -0,0 +1,34 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let start_length = history.length;
|
||||
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
appHistory.navigate("#top");
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
|
||||
let i = document.createElement("iframe");
|
||||
i.src = "/common/blank.html";
|
||||
document.body.appendChild(i);
|
||||
i.onload = () => t.step_timeout(() => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
i.contentWindow.appHistory.navigate("#fragment");
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
i.contentWindow.appHistory.back().then(t.step_func(() => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
return i.contentWindow.appHistory.forward();
|
||||
})).then(t.step_func_done(() => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 1);
|
||||
}));
|
||||
}, 0);
|
||||
}, 0);
|
||||
}, "appHistory.goTo() should work in an iframe that is not present in all history entries");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,33 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let i = document.createElement("iframe");
|
||||
i.src = "data:text/html,";
|
||||
document.body.appendChild(i);
|
||||
let start_length = history.length;
|
||||
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
i.contentWindow.location = "/common/blank.html";
|
||||
i.onload = () => t.step_timeout(() => {
|
||||
assert_equals(history.length, start_length + 1);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
i.contentWindow.appHistory.navigate("#fragment");
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
i.contentWindow.appHistory.back().then(t.step_func(() => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
return i.contentWindow.appHistory.forward();
|
||||
})).then(t.step_func_done(() => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 1);
|
||||
}));
|
||||
}, 0);
|
||||
}, 0);
|
||||
}, "appHistory.goTo() should work in an iframe that started at a data: url");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,22 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
let key = i.contentWindow.appHistory.current.key;
|
||||
i.contentWindow.appHistory.navigate("?1");
|
||||
i.onload = t.step_func(async () => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current, i.contentWindow.appHistory.entries()[1]);
|
||||
i.contentWindow.appHistory.onnavigate = () => i.remove();
|
||||
await promise_rejects_dom(t, 'AbortError', i.contentWindow.DOMException, i.contentWindow.appHistory.goTo(key));
|
||||
t.done();
|
||||
});
|
||||
}, 0);
|
||||
}, "detach iframe inside onnavigate during cross-document appHistory.goTo()");
|
||||
</script>
|
|
@ -0,0 +1,22 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
let key = i.contentWindow.appHistory.current.key;
|
||||
i.contentWindow.appHistory.navigate("?1");
|
||||
i.onload = t.step_func(async () => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current, i.contentWindow.appHistory.entries()[1]);
|
||||
i.contentWindow.appHistory.onnavigate = e => e.preventDefault();
|
||||
await promise_rejects_dom(t, 'AbortError', i.contentWindow.DOMException, i.contentWindow.appHistory.goTo(key));
|
||||
t.done();
|
||||
});
|
||||
}, 0);
|
||||
}, "preventDefault on cross-document appHistory.goTo()");
|
||||
</script>
|
|
@ -0,0 +1,41 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
let next_step = "goto";
|
||||
let key = i.contentWindow.appHistory.current.key;
|
||||
i.contentWindow.appHistory.navigate("?1");
|
||||
i.onload = t.step_func(() => {
|
||||
if (next_step == "goto") {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current, i.contentWindow.appHistory.entries()[1]);
|
||||
i.contentWindow.appHistory.goTo(key);
|
||||
next_step = "forward";
|
||||
} else if (next_step == "forward") {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(key, i.contentWindow.appHistory.current.key);
|
||||
assert_equals(i.contentWindow.appHistory.current, i.contentWindow.appHistory.entries()[0]);
|
||||
assert_true(i.contentWindow.appHistory.canGoForward);
|
||||
i.contentWindow.appHistory.forward();
|
||||
next_step = "back";
|
||||
} else if (next_step == "back") {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current, i.contentWindow.appHistory.entries()[1]);
|
||||
assert_true(i.contentWindow.appHistory.canGoBack);
|
||||
i.contentWindow.appHistory.back();
|
||||
next_step = "finish";
|
||||
} else if (next_step == "finish") {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current, i.contentWindow.appHistory.entries()[0]);
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
}, 0);
|
||||
}, "cross-document navigate.goTo(), back(), and forward()");
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
let current_url = location.href;
|
||||
let current_history_state = history.state;
|
||||
let current_id = appHistory.current.id;
|
||||
let current_state = appHistory.current.getState();
|
||||
await appHistory.goTo(appHistory.current.key);
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
assert_equals(current_url, location.href);
|
||||
assert_equals(current_history_state, history.state);
|
||||
assert_equals(current_id, appHistory.current.id);
|
||||
assert_equals(current_state, appHistory.current.getState());
|
||||
}, "goTo() with current key");
|
||||
</script>
|
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(async () => {
|
||||
let iframe_constructor = i.contentWindow.DOMException;
|
||||
let i_win = i.contentWindow;
|
||||
i.contentWindow.history.pushState(1, "", "#1");
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
let key = i.contentWindow.appHistory.entries()[0].key;
|
||||
|
||||
i.contentWindow.appHistory.onnavigate = () => i.remove();
|
||||
await promise_rejects_dom(t, 'AbortError', iframe_constructor, i.contentWindow.appHistory.goTo(key));
|
||||
t.done();
|
||||
});
|
||||
}, "goTo() in a detached window");
|
||||
</script>
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(async () => {
|
||||
let iframe_constructor = i.contentWindow.DOMException;
|
||||
let i_win = i.contentWindow;
|
||||
let key = i_win.appHistory.current.key;
|
||||
i.remove();
|
||||
await promise_rejects_dom(t, 'InvalidStateError', iframe_constructor, i_win.appHistory.goTo(key));
|
||||
t.done();
|
||||
});
|
||||
}, "goTo() in a detached window");
|
||||
</script>
|
|
@ -0,0 +1,8 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
await promise_rejects_dom(t, 'InvalidStateError', appHistory.goTo("not-a-real-key"));
|
||||
}, "goTo() with invalid key");
|
||||
</script>
|
|
@ -0,0 +1,30 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
let key0 = appHistory.current.key;
|
||||
appHistory.navigate("#1");
|
||||
appHistory.navigate("#2");
|
||||
let key2 = appHistory.current.key;
|
||||
assert_equals(appHistory.entries().length, 3);
|
||||
|
||||
appHistory.goTo(key0)
|
||||
.then(t.step_func(() => {
|
||||
assert_equals(appHistory.entries().length, 3);
|
||||
assert_equals(appHistory.current, appHistory.entries()[0]);
|
||||
assert_equals(key0, appHistory.current.key);
|
||||
return appHistory.goTo(key2);
|
||||
}))
|
||||
.then(t.step_func_done(() => {
|
||||
assert_equals(appHistory.entries().length, 3);
|
||||
assert_equals(appHistory.current, appHistory.entries()[2]);
|
||||
assert_equals(key2, appHistory.current.key);
|
||||
}));
|
||||
}, 0);
|
||||
}, "goto() can precisely traverse multiple steps in the joint session history");
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// 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 key = appHistory.current.key;
|
||||
await appHistory.navigate("#1");
|
||||
|
||||
let first_promise = appHistory.goTo(key);
|
||||
appHistory.goTo(key);
|
||||
await promise_rejects_dom(t, 'AbortError', first_promise);
|
||||
t.done();
|
||||
}, 0);
|
||||
}, "Repeated navigate.goTo()");
|
||||
</script>
|
|
@ -0,0 +1,43 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
|
||||
let onnavigate_count = 0;
|
||||
appHistory.onnavigate = () => onnavigate_count++;
|
||||
|
||||
let key = appHistory.current.key;
|
||||
appHistory.navigate("#")
|
||||
.then(t.step_func(() => {
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current, appHistory.entries()[1]);
|
||||
assert_not_equals(key, appHistory.current.key);
|
||||
return appHistory.goTo(key);
|
||||
}))
|
||||
.then(t.step_func(() => {
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current, appHistory.entries()[0]);
|
||||
assert_equals(key, appHistory.current.key);
|
||||
assert_true(appHistory.canGoForward);
|
||||
return appHistory.forward();
|
||||
}))
|
||||
.then(t.step_func(() => {
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current, appHistory.entries()[1]);
|
||||
assert_true(appHistory.canGoBack);
|
||||
return appHistory.back();
|
||||
}))
|
||||
.then(t.step_func_done(() => {
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(appHistory.current, appHistory.entries()[0]);
|
||||
assert_equals(key, appHistory.current.key);
|
||||
assert_equals(onnavigate_count, 4);
|
||||
}));
|
||||
}, 0);
|
||||
}, "same-document navigate.goTo(), back(), and forward()");
|
||||
</script>
|
|
@ -0,0 +1,37 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let cross_origin_url = new URL(get_host_info().HTTPS_REMOTE_ORIGIN);
|
||||
cross_origin_url.pathname = "/common/blank.html";
|
||||
let i = document.createElement("iframe");
|
||||
i.src = cross_origin_url;
|
||||
document.body.appendChild(i);
|
||||
|
||||
let start_length = history.length;
|
||||
|
||||
// Wait for after the load event so that the navigation doesn't get converted
|
||||
// into a replace navigation.
|
||||
window.onload = () => t.step_timeout(() => {
|
||||
i.contentWindow.location = "/common/blank.html";
|
||||
i.onload = () => t.step_timeout(() => {
|
||||
assert_equals(history.length, start_length + 1);
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
i.contentWindow.appHistory.navigate("#fragment");
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
i.contentWindow.appHistory.back().then(t.step_func(() => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 0);
|
||||
return i.contentWindow.appHistory.forward();
|
||||
})).then(t.step_func_done(() => {
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 2);
|
||||
assert_equals(i.contentWindow.appHistory.current.index, 1);
|
||||
}));
|
||||
}, 0);
|
||||
}, 0);
|
||||
}, "appHistory.goTo() should work in an iframe that has navigated across origins");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="resources/notify-top-early.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let events = [];
|
||||
function finish() {
|
||||
assert_array_equals(events, ["onnavigate", "readystateinteractive", "domcontentloaded", "readystatecomplete", "onload", "onpageshow"]);
|
||||
t.done();
|
||||
};
|
||||
|
||||
window.onload = t.step_func(() => {
|
||||
window.childStarted = () => {
|
||||
i.contentWindow.appHistory.onnavigatesuccess = () => events.push("onnavigatesuccess");
|
||||
i.contentWindow.appHistory.onnavigateerror = () => events.push("onnavigateerror");
|
||||
i.contentWindow.onpageshow = () => events.push("onpageshow");
|
||||
i.contentWindow.onhashchange = () => events.push("onhashchange");
|
||||
i.contentWindow.onpopstate = () => events.push("onpopstate");
|
||||
i.onload = t.step_func(() => {
|
||||
events.push("onload");
|
||||
t.step_timeout(finish, 0);
|
||||
});
|
||||
i.contentDocument.addEventListener("DOMContentLoaded", () => events.push("domcontentloaded"));
|
||||
i.contentDocument.onreadystatechange = () => events.push("readystate" + i.contentDocument.readyState);
|
||||
};
|
||||
i.contentWindow.appHistory.onnavigate = () => events.push("onnavigate");
|
||||
i.contentWindow.appHistory.navigate("?1").then(
|
||||
() => events.push("promisefulfilled"), () => events.push("promiserejected"));
|
||||
});
|
||||
}, "navigate() event ordering for cross-document navigation");
|
||||
</script>
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
let onnavigate_called = false;
|
||||
i.contentWindow.appHistory.onnavigate = () => onnavigate_called = true;
|
||||
// The promise returned by appHistory.navigate() will not resolve on a
|
||||
// cross-document navigation.
|
||||
i.contentWindow.appHistory.navigate("?1")
|
||||
.then(t.unreached_func("fulfilled"), t.unreached_func("rejected"));
|
||||
i.onload = t.step_func(() => t.step_timeout(() => t.done(), 0));
|
||||
});
|
||||
}, "navigate() navigates cross-document and fires onnavigate");
|
||||
</script>
|
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
await new Promise(resolve => window.onload = resolve);
|
||||
let iframe_exception = i.contentWindow.DOMException;
|
||||
i.contentWindow.appHistory.onnavigate = () => i.remove();
|
||||
await promise_rejects_dom(t, 'AbortError', iframe_exception, i.contentWindow.appHistory.navigate("#"));
|
||||
}, "Detach inside onnavigate");
|
||||
</script>
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async () => {
|
||||
history.replaceState("state1", "", "#1");
|
||||
assert_equals(history.state, "state1");
|
||||
|
||||
let onnavigate_called = false;
|
||||
appHistory.onnavigate = () => onnavigate_called = true;
|
||||
await appHistory.navigate("#2", { replace: true });
|
||||
assert_equals(location.hash, "#2");
|
||||
assert_true(onnavigate_called);
|
||||
assert_equals(history.state, null);
|
||||
}, "history.state should be nulled by navigate()");
|
||||
</script>
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async () => {
|
||||
history.replaceState("state1", "", "#1");
|
||||
assert_equals(history.state, "state1");
|
||||
|
||||
let onnavigate_called = false;
|
||||
appHistory.onnavigate = () => onnavigate_called = true;
|
||||
await appHistory.navigate("#2");
|
||||
assert_equals(location.hash, "#2");
|
||||
assert_true(onnavigate_called);
|
||||
assert_equals(history.state, null);
|
||||
}, "history.state should be nulled by navigate()");
|
||||
</script>
|
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i"></iframe>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
let iframe_constructor = i.contentWindow.DOMException;
|
||||
let i_win = i.contentWindow;
|
||||
i.remove();
|
||||
await promise_rejects_dom(t, 'InvalidStateError', iframe_constructor, i_win.appHistory.navigate("#"));
|
||||
}, "navigate() in a detached window");
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
let navInfo = { nav : "info" };
|
||||
let navState = { statevar: "state" };
|
||||
let onnavigated_called = false;
|
||||
appHistory.onnavigate = t.step_func(e => {
|
||||
onnavigated_called = true;
|
||||
assert_equals(e.info, navInfo)
|
||||
});
|
||||
await appHistory.navigate("#1", { navigateInfo: navInfo, state: navState });
|
||||
assert_true(onnavigated_called);
|
||||
assert_not_equals(appHistory.current.getState(), navState);
|
||||
assert_equals(appHistory.current.getState().statevar, navState.statevar);
|
||||
}, "navigate() with info and state");
|
||||
</script>
|
|
@ -0,0 +1,10 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
let navInfo = { nav : "info" };
|
||||
appHistory.onnavigate = t.unreached_func("onnavigate");
|
||||
await promise_rejects_dom(t, "SyntaxError", appHistory.navigate("https://example.com\u0000mozilla.org"));
|
||||
}, "navigate() with invalid url");
|
||||
</script>
|
|
@ -0,0 +1,10 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
await promise_rejects_js(t, TypeError, appHistory.navigate());
|
||||
await promise_rejects_js(t, TypeError, appHistory.navigate({}));
|
||||
await promise_rejects_js(t, TypeError, appHistory.navigate({ replace : true }));
|
||||
}, "navigate() with no args or empty options");
|
||||
</script>
|
|
@ -0,0 +1,9 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
appHistory.onnavigate = e => e.preventDefault();
|
||||
await promise_rejects_dom(t, 'AbortError', appHistory.navigate("#"));
|
||||
}, "navigate() promise rejects when the navigation is aborted");
|
||||
</script>
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
i.contentWindow.appHistory.navigate("?1");
|
||||
i.onload = t.step_func_done(() => {
|
||||
let iframe_url = new URL(i.contentWindow.appHistory.current.url);
|
||||
assert_equals(iframe_url.search, "?1");
|
||||
assert_equals(iframe_url.pathname, "/common/blank.html");
|
||||
});
|
||||
});
|
||||
}, "navigate() should resolve urls relative to appHistory object, not the caller");
|
||||
</script>
|
|
@ -0,0 +1,29 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="/common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// 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_history_length = history.length;
|
||||
let start_entry_top = appHistory.current;
|
||||
let start_entry_iframe_id = i.contentWindow.appHistory.current.id;
|
||||
let start_entry_iframe_key = i.contentWindow.appHistory.current.key;
|
||||
|
||||
i.contentWindow.appHistory.navigate("?1", { replace: true });
|
||||
i.onload = t.step_func_done(() => {
|
||||
assert_equals(history.length, start_history_length);
|
||||
|
||||
assert_equals(appHistory.entries().length, 1);
|
||||
assert_equals(appHistory.current, start_entry_top);
|
||||
|
||||
assert_equals(i.contentWindow.appHistory.entries().length, 1);
|
||||
let iframe_entry = i.contentWindow.appHistory.current;
|
||||
assert_not_equals(start_entry_iframe_id, iframe_entry.id);
|
||||
assert_equals(start_entry_iframe_key, iframe_entry.key);
|
||||
});
|
||||
}, 0);
|
||||
}, "navigate() with replace option");
|
||||
</script>
|
|
@ -0,0 +1,21 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
// 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_history_length = history.length;
|
||||
let key1 = appHistory.current.key;
|
||||
await appHistory.navigate("#1");
|
||||
let key2 = appHistory.current.key;
|
||||
assert_not_equals(key1, key2);
|
||||
await appHistory.navigate("#2", { replace: true });
|
||||
let key3 = appHistory.current.key;
|
||||
assert_equals(key2, key3);
|
||||
assert_equals(appHistory.entries().length, 2);
|
||||
assert_equals(history.length, start_history_length + 1);
|
||||
}), 0);
|
||||
}, "navigate() with replace option");
|
||||
</script>
|
|
@ -0,0 +1,15 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async () => {
|
||||
history.replaceState("state1", "", "#1");
|
||||
assert_equals(history.state, "state1");
|
||||
|
||||
appHistory.onnavigate = e => e.respondWith(Promise.resolve("r"));
|
||||
let result = await appHistory.navigate("#2");
|
||||
assert_equals(result, "r");
|
||||
assert_equals(location.hash, "#2");
|
||||
assert_equals(history.state, null);
|
||||
}, "history.story should be nulled by navigate() handled by respondWith()");
|
||||
</script>
|
|
@ -0,0 +1,27 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(t => {
|
||||
let events = [];
|
||||
function finish() {
|
||||
assert_array_equals(events, ["onnavigate", "onnavigateerror", "promiserejected"]);
|
||||
t.done();
|
||||
}
|
||||
|
||||
appHistory.onnavigate = e => {
|
||||
events.push("onnavigate");
|
||||
e.respondWith(Promise.reject());
|
||||
};
|
||||
appHistory.onnavigatesuccess = () => events.push("onnavigatesuccess");
|
||||
appHistory.onnavigateerror = () => events.push("onnavigateerror");
|
||||
window.onhashchange = () => events.push("onhashchange");
|
||||
window.onpopstate = () => events.push("onpopstate");
|
||||
appHistory.navigate("#1").then(
|
||||
() => events.push("promisefulfilled"),
|
||||
() => {
|
||||
events.push("promiserejected");
|
||||
t.step_timeout(finish, 0);
|
||||
});
|
||||
}, "navigate() event ordering for same-document navigation");
|
||||
</script>
|
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
let promise_value = { abc: 'def' };
|
||||
let promise = Promise.reject(promise_value);
|
||||
appHistory.onnavigate = e => e.respondWith(promise);
|
||||
let returned_promise = appHistory.navigate("#1");
|
||||
assert_not_equals(promise, returned_promise);
|
||||
return promise_rejects_exactly(t, promise_value, returned_promise);
|
||||
}, "navigate() and respondWith with a reject promise");
|
||||
</script>
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче