blob: 6e3d82169973167ddb2b693ceaf674208d150082 [file] [log] [blame]
<!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.transition, null);
const from = appHistory.current;
let from2;
appHistory.addEventListener("navigate", t.step_func(e => {
e.transitionWhile(new Promise(r => t.step_timeout(r, 1)));
assert_equals(appHistory.transition, null);
}));
let navigateerrorFired = false;
appHistory.addEventListener("navigateerror", t.step_func(() => {
// (3) handle the interruption of the navigation to ?1.
navigateerrorFired = true;
assert_equals(appHistory.transition.navigationType, "push");
assert_equals(appHistory.transition.from, from);
}));
let navigatesuccessFired = false;
appHistory.addEventListener("navigatesuccess", t.step_func(() => {
// (5) The navigation to ?2 succeeds.
navigatesuccessFired = true;
assert_true(navigateerrorFired, "navigateerror must fire before navigatesuccess");
assert_equals(appHistory.transition.navigationType, "replace");
assert_equals(appHistory.transition.from, from2);
}));
// (1) Navigate to ?1. This will take 1 ms to settle.
let secondNavigateFulfilled = false;
promise_rejects_dom(t, "AbortError", appHistory.navigate("?1").finished).then(t.step_func(() => {
// (4) After navigateerror for the navigation to ?1 comes the promise rejection.
firstNavigateRejected = true;
assert_equals(appHistory.transition.navigationType, "replace");
assert_equals(appHistory.transition.from, from2);
assert_true(navigateerrorFired, "navigateerror must fire before the first navigate() rejects");
}));
assert_equals(appHistory.transition.navigationType, "push");
assert_equals(appHistory.transition.from, from);
from2 = appHistory.current;
assert_not_equals(from, from2);
// (2) Navigate to ?2. This will interrupt the navigation to ?1 and take us to (3).
appHistory.navigate("?2", { replace: true }).finished.then(t.step_func_done(() => {
// (6) After navigatesuccess for the navigation to ?2 comes the promise fulfillment.
assert_true(navigatesuccessFired, "navigatesuccess must be fired");
assert_equals(appHistory.transition, null);
}));
assert_equals(appHistory.transition.navigationType, "replace");
assert_equals(appHistory.transition.from, from2);
}, 0);
}, "transitionWhile()ed one navigate() interrupting the other");
</script>