|
| 1 | +<!DOCTYPE html> |
| 2 | +<script src="/resources/testharness.js"></script> |
| 3 | +<script src="/resources/testharnessreport.js"></script> |
| 4 | + |
| 5 | +<script> |
| 6 | +async_test(t => { |
| 7 | + // Wait for after the load event so that the navigation doesn't get converted |
| 8 | + // into a replace navigation. |
| 9 | + window.onload = () => t.step_timeout(() => { |
| 10 | + assert_equals(appHistory.transition, null); |
| 11 | + const from = appHistory.current; |
| 12 | + let from2; |
| 13 | + |
| 14 | + appHistory.addEventListener("navigate", t.step_func(e => { |
| 15 | + e.transitionWhile(new Promise(r => t.step_timeout(r, 1))); |
| 16 | + assert_equals(appHistory.transition, null); |
| 17 | + })); |
| 18 | + |
| 19 | + let navigateerrorFired = false; |
| 20 | + appHistory.addEventListener("navigateerror", t.step_func(() => { |
| 21 | + // (3) handle the interruption of the navigation to ?1. |
| 22 | + navigateerrorFired = true; |
| 23 | + |
| 24 | + assert_equals(appHistory.transition.navigationType, "push"); |
| 25 | + assert_equals(appHistory.transition.from, from); |
| 26 | + })); |
| 27 | + |
| 28 | + let navigatesuccessFired = false; |
| 29 | + appHistory.addEventListener("navigatesuccess", t.step_func(() => { |
| 30 | + // (5) The navigation to ?2 succeeds. |
| 31 | + navigatesuccessFired = true; |
| 32 | + assert_true(navigateerrorFired, "navigateerror must fire before navigatesuccess"); |
| 33 | + |
| 34 | + assert_equals(appHistory.transition.navigationType, "replace"); |
| 35 | + assert_equals(appHistory.transition.from, from2); |
| 36 | + })); |
| 37 | + |
| 38 | + // (1) Navigate to ?1. This will take 1 ms to settle. |
| 39 | + let secondNavigateFulfilled = false; |
| 40 | + promise_rejects_dom(t, "AbortError", appHistory.navigate("?1")).then(t.step_func(() => { |
| 41 | + // (4) After navigateerror for the navigation to ?1 comes the promise rejection. |
| 42 | + firstNavigateRejected = true; |
| 43 | + |
| 44 | + assert_equals(appHistory.transition.navigationType, "replace"); |
| 45 | + assert_equals(appHistory.transition.from, from2); |
| 46 | + assert_true(navigateerrorFired, "navigateerror must fire before the first navigate() rejects"); |
| 47 | + })); |
| 48 | + |
| 49 | + assert_equals(appHistory.transition.navigationType, "push"); |
| 50 | + assert_equals(appHistory.transition.from, from); |
| 51 | + |
| 52 | + from2 = appHistory.current; |
| 53 | + assert_not_equals(from, from2); |
| 54 | + |
| 55 | + // (2) Navigate to ?2. This will interrupt the navigation to ?1 and take us to (3). |
| 56 | + appHistory.navigate("?2", { replace: true }).then(t.step_func_done(() => { |
| 57 | + // (6) After navigatesuccess for the navigation to ?2 comes the promise fulfillment. |
| 58 | + assert_true(navigatesuccessFired, "navigatesuccess must be fired"); |
| 59 | + |
| 60 | + assert_equals(appHistory.transition, null); |
| 61 | + })); |
| 62 | + |
| 63 | + assert_equals(appHistory.transition.navigationType, "replace"); |
| 64 | + assert_equals(appHistory.transition.from, from2); |
| 65 | + }, 0); |
| 66 | +}, "transitionWhile()ed one navigate() interrupting the other"); |
| 67 | +</script> |
0 commit comments