forked from web-platform-tests/wpt
/
navigate-same-document-transitionWhile-reject.html
57 lines (49 loc) · 1.92 KB
/
navigate-same-document-transitionWhile-reject.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name="variant" content="?">
<meta name="variant" content="?currentchange">
<script>
const variants = new Set((new URLSearchParams(location.search)).keys());
promise_test(async t => {
// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
const events = [];
appHistory.addEventListener("navigatesuccess", () => events.push(`navigatesuccess ${location.hash}`));
appHistory.addEventListener("navigateerror", () => events.push(`navigateerror ${location.hash}`));
if (variants.has("currentchange")) {
appHistory.addEventListener("currentchange", () => events.push(`currentchange ${location.hash}`));
}
appHistory.addEventListener("navigate", e => {
e.transitionWhile(Promise.reject());
});
const { committed, finished } = appHistory.navigate("#1");
committed.then(
() => events.push(`committed fulfilled ${location.hash}`),
() => events.push(`committed rejected ${location.hash}`)
);
finished.then(
() => events.push(`finished fulfilled ${location.hash}`),
() => events.push(`finished rejected ${location.hash}`)
);
Promise.resolve().then(() => events.push(`promise microtask ${location.hash}`));
await finished.catch(() => {});
if (variants.has("currentchange")) {
assert_array_equals(events, [
"currentchange #1",
"committed fulfilled #1",
"promise microtask #1",
"navigateerror #1",
"finished rejected #1"
]);
} else {
assert_array_equals(events, [
"committed fulfilled #1",
"promise microtask #1",
"navigateerror #1",
"finished rejected #1"
]);
}
}, "event and promise ordering for appHistory.navigate() with a rejected promise passed to transitionWhile()");
</script>