summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/iframe-src-204.html
blob: f7bade68fbd00c005b7f1f3e6a59a94113ca5933 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Navigations on iframe with src set to URL that doesn't load a new document</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<body></body>
<script>
/*
  When an iframe is created it will contain the initial empty document. If the
  src is set to a URL that doesn't load a new document (e.g. it results in a
  HTTP 204 response), it will stay on the initial empty document.
  These tests verify the behavior of navigations that happen on the initial
  empty document in that situation. They should all be converted to do a
  replacement.
*/
"use strict";
const url1 = "/common/blank.html?1";
const url2 = "/common/blank.html?2";

promise_test(async t => {
  const startingHistoryLength = history.length;
  // Create an iframe with src set to URL that doesn't load a new document, so
  // it will stay on the initial empty document.
  const iframe = insertIframeWith204Src(t);
  assert_equals(history.length, startingHistoryLength,
    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");

  // Navigate away from the initial empty document through iframe.src. This
  // should do a replacement.
  iframe.src = url1;
  await waitForLoad(t, iframe, url1);
  assert_equals(history.length, startingHistoryLength,
    "history.length must not change after normal navigation on document loaded by iframe with no src");

  // Navigate again using the same method, but this time it shouldn't do a
  // replacement since it's no longer on the initial empty document.
  iframe.src = url2;
  await waitForLoad(t, iframe, url2);
  assert_equals(history.length, startingHistoryLength + 1,
    "history.length increases after normal navigation from  non-initial empty document");
}, "Navigating to a different document with src");

promise_test(async t => {
  const startingHistoryLength = history.length;
  // Create an iframe with src set to URL that doesn't load a new document, so
  // it will stay on the initial empty document.
  const iframe = insertIframeWith204Src(t);
  assert_equals(history.length, startingHistoryLength,
    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");

  // Navigate away from the initial empty document through setting
  // location.href. This should do a replacement.
  iframe.contentWindow.location.href = url1;
  await waitForLoad(t, iframe, url1);
  assert_equals(history.length, startingHistoryLength,
    "history.length must not change after normal navigation on document loaded by iframe with no src");

  // Navigate again using the same method, but this time it shouldn't do a
  // replacement since it's no longer on the initial empty document.
  iframe.contentWindow.location.href = url2;
  await waitForLoad(t, iframe, url2);
  assert_equals(history.length, startingHistoryLength + 1,
    "history.length increases after normal navigation from  non-initial empty document");
}, "Navigating to a different document with location.href");

promise_test(async t => {
  const startingHistoryLength = history.length;
  // Create an iframe with src set to URL that doesn't load a new document, so
  // it will stay on the initial empty document.
  const iframe = insertIframeWith204Src(t);
  assert_equals(history.length, startingHistoryLength,
    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");

  // Navigate away from the initial empty document through location.assign().
  // This should do a replacement.
  iframe.contentWindow.location.assign(url1);
  await waitForLoad(t, iframe, url1);
  assert_equals(history.length, startingHistoryLength,
    "history.length must not change after normal navigation on document loaded by iframe with no src");

  // Navigate again using the same method, but this time it shouldn't do a
  // replacement since it's no longer on the initial empty document.
  iframe.contentWindow.location.assign(url2);
  await waitForLoad(t, iframe, url2);
  assert_equals(history.length, startingHistoryLength + 1,
    "history.length increases after normal navigation from  non-initial empty document");
}, "Navigating to a different document with location.assign");

promise_test(async t => {
  const startingHistoryLength = history.length;
  // Create an iframe with src set to URL that doesn't load a new document, so
  // it will stay on the initial empty document.
  const iframe = insertIframeWith204Src(t);
  assert_equals(history.length, startingHistoryLength,
    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");

  // Navigate away from the initial empty document through window.open().
  // This should do a replacement.
  iframe.contentWindow.open(url1, "_self");
  await waitForLoad(t, iframe, url1);
  assert_equals(history.length, startingHistoryLength,
    "history.length must not change after normal navigation on document loaded by iframe with no src");

  // Navigate again using the same method, but this time it shouldn't do a
  // replacement since it's no longer on the initial empty document.
  iframe.contentWindow.open(url2, "_self");
  await waitForLoad(t, iframe, url2);
  assert_equals(history.length, startingHistoryLength + 1,
    "history.length increases after normal navigation from  non-initial empty document");
}, "Navigating to a different document with window.open");

promise_test(async t => {
  const startingHistoryLength = history.length;
  // Create an iframe with src set to URL that doesn't load a new document, so
  // it will stay on the initial empty document.
  const iframe = insertIframeWith204Src(t);
  assert_equals(history.length, startingHistoryLength,
    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");

  // Navigate away from the initial empty document through clicking an <a>
  // element. This should do a replacement.
  const a1 = iframe.contentDocument.createElement("a");
  a1.href = url1;
  iframe.contentDocument.body.appendChild(a1);
  a1.click();
  await waitForLoad(t, iframe, url1);
  assert_equals(history.length, startingHistoryLength,
    "history.length must not change after normal navigation on document loaded by iframe with no src");

  // Navigate again using the same method, but this time it shouldn't do a
  // replacement since it's no longer on the initial empty document.
  const a2 = iframe.contentDocument.createElement("a");
  a2.href = url2;
  iframe.contentDocument.body.appendChild(a2);
  a2.click();
  await waitForLoad(t, iframe, url2);
  assert_equals(history.length, startingHistoryLength + 1,
    "history.length increases after normal navigation from  non-initial empty document");
}, "Navigating to a different document with link click");

promise_test(async t => {
  const startingHistoryLength = history.length;
  // Create an iframe with src set to URL that doesn't load a new document, so
  // it will stay on the initial empty document.
  const iframe = insertIframeWith204Src(t);
  assert_equals(history.length, startingHistoryLength,
    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");

  // Navigate away from the initial empty document through form submission.
  // This should do a replacement.
  const form1 = iframe.contentDocument.createElement("form");
  form1.action = "/common/blank.html";
  iframe.contentDocument.body.appendChild(form1);
  const input1 = iframe.contentDocument.createElement("input");
  input1.type = "hidden";
  input1.name = "1";
  form1.append(input1);
  form1.submit();
  await waitForLoad(t, iframe, url1 + "=");
  assert_equals(history.length, startingHistoryLength,
    "history.length must not change after normal navigation on document loaded by iframe with no src");

  // Navigate again using the same method, but this time it shouldn't do a
  // replacement since it's no longer on the initial empty document.
  const form2 = iframe.contentDocument.createElement("form");
  form2.action = "/common/blank.html";
  iframe.contentDocument.body.appendChild(form2);
  const input2 = iframe.contentDocument.createElement("input");
  input2.type = "hidden";
  input2.name = "2";
  form2.append(input2);
  form2.submit();
  await waitForLoad(t, iframe, url2 + "=");
  assert_equals(history.length, startingHistoryLength + 1,
    "history.length increases after normal navigation from  non-initial empty document");
}, "Navigating to a different document with form submission");
</script>