summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/navigation-api/commit-behavior/multiple-intercept.html
blob: 848af6a65d8954accaa0c9882224ba07d76f7958 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div style="height: 1000px; width: 1000px;"></div>
<div id="frag"></div>
<script>
let i = 0;
async function urlDidChangeImmediately(listener, expected) {
  navigation.addEventListener("navigate", listener, { once: true });
  let expected_hash = "#" + ++i;
  assert_not_equals(location.hash, expected_hash);
  let finished = navigation.navigate(expected_hash).finished;
  assert_equals(location.hash === expected_hash, expected);
  await finished;
  assert_equals(location.hash, expected_hash);
}

async function testUrlDidChangeImmediately(listener) {
  await urlDidChangeImmediately(listener, true);
}

async function testUrlDidNotChangeImmediately(listener) {
  await urlDidChangeImmediately(listener, false);
}

promise_test(async t => {
  await testUrlDidNotChangeImmediately(e => {
    e.intercept({ commit: "after-transition" });
    e.intercept({ commit: "after-transition" });
  });
}, "after-transition + after-transition");

promise_test(async t => {
  await testUrlDidNotChangeImmediately(e => {
    e.intercept({ commit: "after-transition" });
    e.intercept();
  });
}, "after-transition + (not provided)");

promise_test(async t => {
  await testUrlDidChangeImmediately(e => {
    e.intercept({ commit: "after-transition" });
    e.intercept({ commit: "immediate" });
  });
}, "after-transition + immediate");

promise_test(async t => {
  await testUrlDidNotChangeImmediately(e => {
    e.intercept({ commit: "immediate" });
    e.intercept({ commit: "after-transition" });
  });
}, "immediate + after-transition");

promise_test(async t => {
  await testUrlDidChangeImmediately(e => {
    e.intercept({ commit: "immediate" });
    e.intercept();
  });
}, "immediate + (not provided)");

promise_test(async t => {
  await testUrlDidChangeImmediately(e => {
    e.intercept({ commit: "immediate" });
    e.intercept({ commit: "immediate" });
  });
}, "immediate + immediate");

promise_test(async t => {
  await testUrlDidNotChangeImmediately(e => {
    e.intercept();
    e.intercept({ commit: "after-transition" });
  });
}, "(not provided) + after-transition");

promise_test(async t => {
  await testUrlDidChangeImmediately(e => {
    e.intercept();
    e.intercept({ commit: "immediate" });
  });
}, "(not provided) + immediate");
</script>
</body>