summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/browsing-the-web/overlapping-navigations-and-traversals/same-document-traversal-same-document-traversal-hashchange.html
blob: df5ea5caab0bf37ba7b17e3d4ab82d529e2076df (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<meta charset="utf-8">
<title>Same-document traversals during same-document traversals (using fragment navigations)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<!--
  Compare this to cross-document-traversal-cross-document-traversal.html. Since
  there are no network loads or document unloads to cancel tasks, both
  traversals should observably go through. Target step calculation for the
  second traversal should take place after the first traversal is finished. So
  we end up with both traversals observable in sequence.
-->

<body>
<script type="module">
import { createIframe, delay, waitForHashchange } from "./resources/helpers.mjs";

promise_test(async t => {
  const iframe = await createIframe(t);
  const baseURL = iframe.contentWindow.location.href;

  // Setup
  iframe.contentWindow.location.hash = "#1";
  await waitForHashchange(iframe.contentWindow);
  iframe.contentWindow.location.hash = "#2";
  await waitForHashchange(iframe.contentWindow);
  iframe.contentWindow.location.hash = "#3";
  await waitForHashchange(iframe.contentWindow);
  iframe.contentWindow.history.back();
  await waitForHashchange(iframe.contentWindow);
  assert_equals(iframe.contentWindow.location.hash, "#2", "we made our way to #2 for setup");

  iframe.contentWindow.history.back();
  assert_equals(iframe.contentWindow.location.hash, "#2", "must not go back synchronously");

  iframe.contentWindow.history.forward();
  assert_equals(iframe.contentWindow.location.hash, "#2", "must not go forward synchronously");

  const event1 = await waitForHashchange(iframe.contentWindow);
  assert_equals(event1.oldURL, baseURL + "#2", "oldURL 1");
  assert_equals(event1.newURL, baseURL + "#1", "newURL 1");
  // Cannot test iframe.contentWindow.location.hash since the second history
  // traversal task is racing with the fire an event task, so we don't know
  // which will happen first.

  const event2 = await waitForHashchange(iframe.contentWindow);
  assert_equals(event2.oldURL, baseURL + "#1", "oldURL 2");
  assert_equals(event2.newURL, baseURL + "#2", "newURL 2");
  assert_equals(iframe.contentWindow.location.hash, "#2");
}, "same-document traversals in opposite directions: queued up");

promise_test(async t => {
  const iframe = await createIframe(t);
  const baseURL = iframe.contentWindow.location.href;

  // Setup
  iframe.contentWindow.location.hash = "#1";
  await waitForHashchange(iframe.contentWindow);
  iframe.contentWindow.location.hash = "#2";
  await waitForHashchange(iframe.contentWindow);

  iframe.contentWindow.history.back();
  assert_equals(iframe.contentWindow.location.hash, "#2", "must not go back synchronously");

  iframe.contentWindow.history.forward();
  assert_equals(iframe.contentWindow.location.hash, "#2", "must not go forward synchronously");

  const event1 = await waitForHashchange(iframe.contentWindow);
  assert_equals(event1.oldURL, baseURL + "#2", "oldURL 1");
  assert_equals(event1.newURL, baseURL + "#1", "newURL 1");
  // Cannot test iframe.contentWindow.location.hash since the second history
  // traversal task is racing with the fire an event task, so we don't know
  // which will happen first.

  const event2 = await waitForHashchange(iframe.contentWindow);
  assert_equals(event2.oldURL, baseURL + "#1", "oldURL 2");
  assert_equals(event2.newURL, baseURL + "#2", "newURL 2");
  assert_equals(iframe.contentWindow.location.hash, "#2");
}, "same-document traversals in opposite directions, second traversal invalid at queuing time: queued up");

promise_test(async t => {
  const iframe = await createIframe(t);
  const baseURL = iframe.contentWindow.location.href;

  // Setup
  iframe.contentWindow.location.hash = "#1";
  await waitForHashchange(iframe.contentWindow);
  iframe.contentWindow.location.hash = "#2";
  await waitForHashchange(iframe.contentWindow);
  iframe.contentWindow.location.hash = "#3";
  await waitForHashchange(iframe.contentWindow);

  iframe.contentWindow.history.back();
  assert_equals(iframe.contentWindow.location.hash, "#3", "must not go back synchronously (1)");

  iframe.contentWindow.history.back();
  assert_equals(iframe.contentWindow.location.hash, "#3", "must not go back synchronously (2)");

  const event1 = await waitForHashchange(iframe.contentWindow);
  assert_equals(event1.oldURL, baseURL + "#3", "oldURL 1");
  assert_equals(event1.newURL, baseURL + "#2", "newURL 1");
  // Cannot test iframe.contentWindow.location.hash since the second history
  // traversal task is racing with the fire an event task, so we don't know
  // which will happen first.

  const event2 = await waitForHashchange(iframe.contentWindow);
  assert_equals(event2.oldURL, baseURL + "#2", "oldURL 2");
  assert_equals(event2.newURL, baseURL + "#1", "newURL 2");
  assert_equals(iframe.contentWindow.location.hash, "#1");
}, "same-document traversals in the same (back) direction: queue up");

promise_test(async t => {
  const iframe = await createIframe(t);
  const baseURL = iframe.contentWindow.location.href;

  // Setup
  iframe.contentWindow.location.hash = "#1";
  await waitForHashchange(iframe.contentWindow);
  iframe.contentWindow.location.hash = "#2";
  await waitForHashchange(iframe.contentWindow);
  iframe.contentWindow.location.hash = "#3";
  await waitForHashchange(iframe.contentWindow);
  iframe.contentWindow.history.back();
  await waitForHashchange(iframe.contentWindow);
  iframe.contentWindow.history.back();
  await waitForHashchange(iframe.contentWindow);
  assert_equals(iframe.contentWindow.location.hash, "#1", "we made our way to #1 for setup");

  iframe.contentWindow.history.forward();
  assert_equals(iframe.contentWindow.location.hash, "#1", "must not go forward synchronously (1)");

  iframe.contentWindow.history.forward();
  assert_equals(iframe.contentWindow.location.hash, "#1", "must not go forward synchronously (2)");

  const event1 = await waitForHashchange(iframe.contentWindow);
  assert_equals(event1.oldURL, baseURL + "#1", "oldURL 1");
  assert_equals(event1.newURL, baseURL + "#2", "newURL 1");
  // Cannot test iframe.contentWindow.location.hash since the second history
  // traversal task is racing with the fire an event task, so we don't know
  // which will happen first.

  const event2 = await waitForHashchange(iframe.contentWindow);
  assert_equals(event2.oldURL, baseURL + "#2", "oldURL 2");
  assert_equals(event2.newURL, baseURL + "#3", "newURL 2");
  assert_equals(iframe.contentWindow.location.hash, "#3");
}, "same-document traversals in the same (forward) direction: queue up");
</script>