Skip to content

Commit 41d4d41

Browse files
Ensure initial about:blank Doc's initialness is not carried over (#55785)
This CL adds a test to ensure that the initial about:blank Document's initial-ness is not carried over to another about:blank Document, when navigating from the initial about:blank Document to about:blank. This CL also fixes or cleans up some documentation in related tests. R=rakina Bug: N/A Change-Id: If5788ecb534b61b541551e57cdd2e37a8df26ea5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7101623 Reviewed-by: Rakina Zata Amni <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1538831} Co-authored-by: Dominic Farolino <[email protected]>
1 parent 7869fb6 commit 41d4d41

File tree

3 files changed

+82
-30
lines changed

3 files changed

+82
-30
lines changed

html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/iframe-nosrc.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,39 @@
175175
assert_equals(history.length, startingHistoryLength + 1,
176176
"history.length increases after normal navigation from non-initial empty document");
177177
}, "form submission");
178+
179+
// This test is very similar to the `location.href` test a few cases above, but
180+
// the difference is that instead of navigating from:
181+
// initial about:blank Document => HTTP => HTTP
182+
// ... we navigate from:
183+
// initial about:blank Document => (non-initial) about:blank Document => HTTP
184+
//
185+
// We do this to ensure/assert that an explicit navigation to about:blank
186+
// *after* the iframe has finished initializing, is counted as a normal
187+
// navigation away from the initial about:blank Document, and the "initial-ness"
188+
// of the initial about:blank Document is not carried over to the next
189+
// about:blank Document.
190+
promise_test(async t => {
191+
const startingHistoryLength = history.length;
192+
// Create an iframe with src not set, which will stay on the initial empty
193+
// document.
194+
const iframe = insertIframe(t);
195+
assert_equals(history.length, startingHistoryLength,
196+
"Inserting iframe with no src must not change history.length");
197+
198+
// Navigate away from the initial empty document through setting location.href
199+
// to `about:blank`. This should do a replacement TO ANOTHER about:blank
200+
// Document, which is not the initial about:blank Document.
201+
iframe.contentWindow.location.href = 'about:blank';
202+
await waitForLoad(t, iframe, 'about:blank');
203+
assert_equals(history.length, startingHistoryLength,
204+
"history.length must not change after normal navigation on document loaded by iframe with no src");
205+
206+
// Navigate again using the same method, but this time it shouldn't do a
207+
// replacement since it's no longer on the initial empty document.
208+
iframe.contentWindow.location.href = url2;
209+
await waitForLoad(t, iframe, url2);
210+
assert_equals(history.length, startingHistoryLength + 1,
211+
"history.length increases after normal navigation from non-initial empty document");
212+
}, "initial about:blank => non-initial about:blank (via location.href) => normal HTTP navigation");
178213
</script>

html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/iframe-src-aboutblank-navigate-immediately.html

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,42 @@
1616

1717
promise_test(async t => {
1818
const startingHistoryLength = history.length;
19-
// Create an iframe with src set to about:blank. This would trigger a
20-
// navigation to a non-initial about:blank document.
19+
// Create an iframe with src set to about:blank. Per the HTML Standard, this
20+
// stays on the "initial about:blank Document" [1], because the "process the
21+
// iframe attributes" algorithm [2] catches the "about:blank" navigation and
22+
// fires a special synchronous `load` event at the initial about:blank
23+
// Document, instead of replacing it with a non-initial, second about:blank
24+
// Document. This is documented in the note at the end of [3].
25+
//
26+
// [1]: https://html.spec.whatwg.org/#is-initial-about:blank.
27+
// [2]: https://html.spec.whatwg.org/#process-the-iframe-attributes
28+
// [3]: https://html.spec.whatwg.org/#completely-finish-loading
2129
const iframe = insertIframeWithAboutBlankSrc(t);
2230
assert_equals(history.length, startingHistoryLength,
2331
"Inserting iframe with src='about:blank' must not change history.length");
2432

25-
// Trigger a navigation to url1 through the iframe's src attribute.
26-
// The iframe should still be on the initial empty document, and the
27-
// navigation should do replacement.
33+
// Trigger a navigation from the initial about:blank Document, to url1 through
34+
// the iframe's src attribute. Because we're navigating from the initial
35+
// about:blank Document, the navigation should be a replacement.
2836
iframe.src = url1;
37+
2938
// Wait for the latest navigation to finish.
3039
await waitForLoad(t, iframe, url1);
3140
assert_equals(history.length, startingHistoryLength,
32-
"history.length must not change after normal navigation on initial empty document");
33-
}, "Navigating to a different document with src");
41+
"history.length must not change after normal navigation from initial " +
42+
"about:blank Document");
43+
}, "Navigating away from the initial about:blank Document to a different " +
44+
"one, with src");
3445

3546
promise_test(async t => {
3647
const startingHistoryLength = history.length;
37-
// Create an iframe with src set to about:blank but navigate away from it immediately below.
3848
const iframe = insertIframeWithAboutBlankSrc(t);
3949
assert_equals(history.length, startingHistoryLength,
4050
"Inserting iframe with src='about:blank' must not change history.length");
4151

42-
// Navigate away from the initial empty document through setting
43-
// location.href. The iframe should still be on the initial empty document,
44-
// and the navigation should do replacement.
52+
// Trigger a navigation from the initial about:blank Document, to url1 through
53+
// location.href. Because we're navigating from the initial about:blank
54+
// Document, the navigation should be a replacement.
4555
iframe.contentWindow.location.href = url1;
4656
await waitForLoad(t, iframe, url1);
4757
assert_equals(history.length, startingHistoryLength,
@@ -50,14 +60,13 @@
5060

5161
promise_test(async t => {
5262
const startingHistoryLength = history.length;
53-
// Create an iframe with src set to about:blank but navigate away from it immediately below.
5463
const iframe = insertIframeWithAboutBlankSrc(t);
5564
assert_equals(history.length, startingHistoryLength,
5665
"Inserting iframe with src='about:blank' must not change history.length");
5766

58-
// Navigate away from the initial empty document through location.assign().
59-
// The iframe should still be on the initial empty document, and the
60-
// navigation should do replacement.
67+
// Trigger a navigation from the initial about:blank Document, to url1 through
68+
// location.assign(). Because we're navigating from the initial about:blank
69+
// Document, the navigation should be a replacement.
6170
iframe.contentWindow.location.assign(url1);
6271
await waitForLoad(t, iframe, url1);
6372
assert_equals(history.length, startingHistoryLength,
@@ -66,14 +75,13 @@
6675

6776
promise_test(async t => {
6877
const startingHistoryLength = history.length;
69-
// Create an iframe with src set to about:blank but navigate away from it immediately below.
7078
const iframe = insertIframeWithAboutBlankSrc(t);
7179
assert_equals(history.length, startingHistoryLength,
7280
"Inserting iframe with src='about:blank' must not change history.length");
7381

74-
// Navigate away from the initial empty document through window.open().
75-
// The iframe should still be on the initial empty document, and the
76-
// navigation should do replacement.
82+
// Trigger a navigation from the initial about:blank Document, to url1 through
83+
// window.open(). Because we're navigating from the initial about:blank
84+
// Document, the navigation should be a replacement.
7785
iframe.contentWindow.open(url1, "_self");
7886
await waitForLoad(t, iframe, url1);
7987
assert_equals(history.length, startingHistoryLength,
@@ -82,14 +90,13 @@
8290

8391
promise_test(async t => {
8492
const startingHistoryLength = history.length;
85-
// Create an iframe with src set to about:blank but navigate away from it immediately below.
8693
const iframe = insertIframeWithAboutBlankSrc(t);
8794
assert_equals(history.length, startingHistoryLength,
8895
"Inserting iframe with src='about:blank' must not change history.length");
8996

90-
// Navigate away from the initial empty document through clicking an <a>
91-
// element. The iframe should still be on the initial empty document, and the
92-
// navigation should do replacement.
97+
// Trigger a navigation from the initial about:blank Document, to url1 through
98+
// clicking an `<a>` element. Because we're navigating from the initial
99+
// about:blank Document, the navigation should be a replacement.
93100
const a = iframe.contentDocument.createElement("a");
94101
a.href = url1;
95102
iframe.contentDocument.body.appendChild(a);
@@ -101,14 +108,13 @@
101108

102109
promise_test(async t => {
103110
const startingHistoryLength = history.length;
104-
// Create an iframe with src set to about:blank but navigate away from it immediately below.
105111
const iframe = insertIframeWithAboutBlankSrc(t);
106112
assert_equals(history.length, startingHistoryLength,
107113
"Inserting iframe with src='about:blank' must not change history.length");
108114

109-
// Navigate away from the initial empty document through form submission.
110-
// The iframe should still be on the initial empty document, and the
111-
// navigation should do replacement.
115+
// Trigger a navigation from the initial about:blank Document, to url1 through
116+
// a form submission. Because we're navigating from the initial about:blank
117+
// Document, the navigation should be a replacement.
112118
const form = iframe.contentDocument.createElement("form");
113119
form.action = "/common/blank.html";
114120
iframe.contentDocument.body.appendChild(form);

html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/resources/helpers.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ window.insertIframeWith204Src = (t) => {
3737
return iframe;
3838
};
3939

40-
// Creates an iframe with src="about:blank" and appends it to the document.
40+
// Creates an iframe with src="about:blank" and appends it to the document. The
41+
// resulting document in the iframe is the initial about:blank Document [1],
42+
// because during the "process the iframe attributes" algorithm [2], `src`
43+
// navigations to `about:blank` are caught and result in a synchronous load
44+
// event; not a SEPARATE navigation to a non-initial `about:blank` Document. See
45+
// the documentation in [3] as well.
46+
//
47+
// [1]: https://html.spec.whatwg.org/#is-initial-about:blank
48+
// [2]: https://html.spec.whatwg.org/#process-the-iframe-attributes
49+
// [3]: https://html.spec.whatwg.org/#completely-finish-loading
4150
window.insertIframeWithAboutBlankSrc = (t) => {
4251
const iframe = document.createElement("iframe");
4352
t.add_cleanup(() => iframe.remove());
@@ -47,12 +56,14 @@ window.insertIframeWithAboutBlankSrc = (t) => {
4756
};
4857

4958
// Creates an iframe with src="about:blank", appends it to the document, and
50-
// waits for the non-initial about:blank document finished loading.
59+
// waits for initial about:blank Document to finish loading.
5160
window.insertIframeWithAboutBlankSrcWaitForLoad = async (t) => {
5261
const iframe = insertIframeWithAboutBlankSrc(t);
5362
const aboutBlankLoad = new Promise(resolve => {
54-
// In some browsers, the non-initial about:blank navigation commits
63+
// In some browsers, when the initial about:blank Document is influenced by
64+
// a `src=about:blank` attribute, the about:blank navigation commits
5565
// asynchronously, while in other browsers, it would commit synchronously.
66+
//
5667
// This means we can't wait for the "load" event as it might have already
5768
// ran. Instead, just wait for 100ms before resolving, as the non-initial
5869
// about:blank navigation will most likely take less than 100 ms to commit.

0 commit comments

Comments
 (0)