Skip to content

Commit 0a04996

Browse files
TimothyGuannevk
andcommittedSep 6, 2018
HTML: document.open() and aborting documents
For #10773. Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
1 parent f2ea2ba commit 0a04996

12 files changed

+559
-3
lines changed
 
File renamed without changes.

‎html/semantics/scripting-1/the-script-element/load-error-events-2.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
var test5_load = event_test('no src, parser-inserted, has style sheets blocking scripts, script nesting level == 1', false, false);
1212
</script>
1313

14-
<link rel="stylesheet" href="resources/slow.py"></link>
14+
<link rel="stylesheet" href="/common/slow.py"></link>
1515
<!-- This is testing the case where an inline classic script is inserted
1616
by parser while there is an loading stylesheet. Therefore, it is critical to
1717
place a <link rel="stylesheet"> just above the <script> to be tested. -->

‎html/semantics/scripting-1/the-script-element/load-error-events-3.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
false, false);
1414

1515
document.write(
16-
`<link rel="stylesheet" href="resources/slow.py"></link>
16+
`<link rel="stylesheet" href="/common/slow.py"></link>
1717
<script onload="onLoad(test6_load);"
1818
onerror="onError(test6_load);">
1919
"use strict";

‎html/semantics/scripting-1/the-script-element/script-text-modifications.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</script>
1313

1414
<!-- This is "a style sheet that is blocking scripts" and thus ... -->
15-
<link rel="stylesheet" href="resources/slow.py"></link>
15+
<link rel="stylesheet" href="/common/slow.py"></link>
1616

1717
<script src="resources/script-text-modifications.py" async></script>
1818

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// The following tests deal with the <meta http-equiv=refresh> pragma and the
2+
// `Refresh` header. The spec is still hazy on the precise behavior in those
3+
// cases but we use https://github.com/whatwg/html/issues/4003 as a guideline.
4+
5+
async_test(t => {
6+
const frame = document.body.appendChild(document.createElement("iframe"));
7+
t.add_cleanup(() => frame.remove());
8+
frame.onload = t.step_func(() => {
9+
frame.onload = null;
10+
11+
const client = new frame.contentWindow.XMLHttpRequest();
12+
client.open("GET", "/common/blank.html");
13+
client.onabort = t.step_func_done();
14+
client.send();
15+
16+
frame.contentDocument.open();
17+
});
18+
frame.src = "resources/meta-refresh.py?0";
19+
}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (XMLHttpRequest)");
20+
21+
async_test(t => {
22+
const frame = document.body.appendChild(document.createElement("iframe"));
23+
t.add_cleanup(() => frame.remove());
24+
frame.onload = t.step_func(() => {
25+
frame.onload = null;
26+
27+
frame.contentWindow.fetch("/common/blank.html").then(
28+
t.unreached_func("Fetch should have been aborted"),
29+
t.step_func_done());
30+
31+
frame.contentDocument.open();
32+
});
33+
frame.src = "resources/meta-refresh.py?0";
34+
}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (fetch())");
35+
36+
// We cannot test for img element's error event for this test, as Firefox does
37+
// not fire the event if the fetch is aborted while Chrome does.
38+
async_test(t => {
39+
const frame = document.body.appendChild(document.createElement("iframe"));
40+
t.add_cleanup(() => frame.remove());
41+
frame.onload = t.step_func(() => {
42+
frame.onload = null;
43+
44+
let happened = false;
45+
const img = frame.contentDocument.createElement("img");
46+
img.src = new URL("resources/slow-png.py", document.URL);
47+
img.onload = t.unreached_func("Image loading should not have succeeded");
48+
// The image fetch starts in a microtask, so let's be sure to test after
49+
// the fetch has started.
50+
t.step_timeout(() => {
51+
frame.contentDocument.open();
52+
happened = true;
53+
});
54+
// If 3 seconds have passed and the image has still not loaded, we consider
55+
// it aborted. slow-png.py only sleeps for 2 wallclock seconds.
56+
t.step_timeout(t.step_func_done(() => {
57+
assert_true(happened);
58+
}), 3000);
59+
});
60+
frame.src = "resources/meta-refresh.py?0";
61+
}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (image loading)");
62+
63+
async_test(t => {
64+
const frame = document.body.appendChild(document.createElement("iframe"));
65+
t.add_cleanup(() => frame.remove());
66+
frame.onload = t.step_func(() => {
67+
frame.onload = null;
68+
69+
const client = new frame.contentWindow.XMLHttpRequest();
70+
client.open("GET", "/common/blank.html");
71+
client.onabort = t.step_func_done();
72+
client.send();
73+
74+
frame.contentDocument.open();
75+
});
76+
frame.src = "resources/http-refresh.py?0";
77+
}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (XMLHttpRequest)");
78+
79+
async_test(t => {
80+
const frame = document.body.appendChild(document.createElement("iframe"));
81+
t.add_cleanup(() => frame.remove());
82+
frame.onload = t.step_func(() => {
83+
frame.onload = null;
84+
85+
frame.contentWindow.fetch("/common/blank.html").then(
86+
t.unreached_func("Fetch should have been aborted"),
87+
t.step_func_done());
88+
89+
frame.contentDocument.open();
90+
});
91+
frame.src = "resources/http-refresh.py?0";
92+
}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (fetch())");
93+
94+
// We cannot test for img element's error event for this test, as Firefox does
95+
// not fire the event if the fetch is aborted while Chrome does.
96+
async_test(t => {
97+
const frame = document.body.appendChild(document.createElement("iframe"));
98+
t.add_cleanup(() => frame.remove());
99+
frame.onload = t.step_func(() => {
100+
frame.onload = null;
101+
102+
let happened = false;
103+
const img = frame.contentDocument.createElement("img");
104+
img.src = new URL("resources/slow-png.py", document.URL);
105+
img.onload = t.unreached_func("Image loading should not have succeeded");
106+
// The image fetch starts in a microtask, so let's be sure to test after
107+
// the fetch has started.
108+
t.step_timeout(() => {
109+
frame.contentDocument.open();
110+
happened = true;
111+
});
112+
// If 3 seconds have passed and the image has still not loaded, we consider
113+
// it aborted. slow-png.py only sleeps for 2 wallclock seconds.
114+
t.step_timeout(t.step_func_done(() => {
115+
assert_true(happened);
116+
}), 3000);
117+
});
118+
frame.src = "resources/http-refresh.py?0";
119+
}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (image loading)");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// The following tests deal with the <meta http-equiv=refresh> pragma and the
2+
// `Refresh` header. The spec is still hazy on the precise behavior in those
3+
// cases but we use https://github.com/whatwg/html/issues/4003 as a guideline.
4+
//
5+
// This is separate from abort-refresh-multisecond-meta.window.js to avoid
6+
// browser interventions that limit the number of connections in a tab.
7+
8+
async_test(t => {
9+
const frame = document.body.appendChild(document.createElement("iframe"));
10+
t.add_cleanup(() => frame.remove());
11+
frame.onload = t.step_func(() => {
12+
frame.onload = null;
13+
let happened = false;
14+
15+
const client = new frame.contentWindow.XMLHttpRequest();
16+
client.open("GET", "/common/blank.html");
17+
client.onload = t.step_func_done(() => {
18+
assert_true(happened);
19+
});
20+
client.onerror = t.unreached_func("XMLHttpRequest should have succeeded");
21+
client.onabort = t.unreached_func("XMLHttpRequest should have succeeded");
22+
client.ontimeout = t.unreached_func("XMLHttpRequest should have succeeded");
23+
client.send();
24+
25+
frame.contentDocument.open();
26+
happened = true;
27+
});
28+
frame.src = "resources/http-refresh.py?1";
29+
}, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 1-sec timeout (XMLHttpRequest)");
30+
31+
async_test(t => {
32+
const frame = document.body.appendChild(document.createElement("iframe"));
33+
t.add_cleanup(() => frame.remove());
34+
frame.onload = t.step_func(() => {
35+
frame.onload = null;
36+
let happened = false;
37+
frame.contentWindow.fetch("/common/blank.html").then(
38+
t.step_func_done(() => {
39+
assert_true(happened);
40+
}),
41+
t.unreached_func("Fetch should have succeeded")
42+
);
43+
frame.contentDocument.open();
44+
happened = true;
45+
});
46+
frame.src = "resources/http-refresh.py?1";
47+
}, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 1-sec timeout (fetch())");
48+
49+
async_test(t => {
50+
const frame = document.body.appendChild(document.createElement("iframe"));
51+
t.add_cleanup(() => frame.remove());
52+
frame.onload = t.step_func(() => {
53+
frame.onload = null;
54+
let happened = false;
55+
const img = frame.contentDocument.createElement("img");
56+
img.src = new URL("resources/slow-png.py", document.URL);
57+
img.onload = t.step_func_done(() => {
58+
assert_true(happened);
59+
});
60+
img.onerror = t.unreached_func("Image loading should not have errored");
61+
// The image fetch starts in a microtask, so let's be sure to test after
62+
// the fetch has started.
63+
t.step_timeout(() => {
64+
frame.contentDocument.open();
65+
happened = true;
66+
});
67+
});
68+
frame.src = "resources/http-refresh.py?4";
69+
}, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 4-sec timeout (image loading)");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// The following tests deal with the <meta http-equiv=refresh> pragma and the
2+
// `Refresh` header. The spec is still hazy on the precise behavior in those
3+
// cases but we use https://github.com/whatwg/html/issues/4003 as a guideline.
4+
//
5+
// This is separate from abort-refresh-multisecond-header.window.js to avoid
6+
// browser interventions that limit the number of connections in a tab.
7+
8+
async_test(t => {
9+
const frame = document.body.appendChild(document.createElement("iframe"));
10+
t.add_cleanup(() => frame.remove());
11+
frame.onload = t.step_func(() => {
12+
frame.onload = null;
13+
let happened = false;
14+
15+
const client = new frame.contentWindow.XMLHttpRequest();
16+
client.open("GET", "/common/blank.html");
17+
client.onload = t.step_func_done(() => {
18+
assert_true(happened);
19+
});
20+
client.onerror = t.unreached_func("XMLHttpRequest should have succeeded");
21+
client.onabort = t.unreached_func("XMLHttpRequest should have succeeded");
22+
client.ontimeout = t.unreached_func("XMLHttpRequest should have succeeded");
23+
client.send();
24+
25+
frame.contentDocument.open();
26+
happened = true;
27+
});
28+
frame.src = "resources/meta-refresh.py?1";
29+
}, "document.open() does NOT abort documents that are queued for navigation through <meta> refresh with 1-sec timeout (XMLHttpRequest)");
30+
31+
async_test(t => {
32+
const frame = document.body.appendChild(document.createElement("iframe"));
33+
t.add_cleanup(() => frame.remove());
34+
frame.onload = t.step_func(() => {
35+
frame.onload = null;
36+
let happened = false;
37+
frame.contentWindow.fetch("/common/blank.html").then(
38+
t.step_func_done(() => {
39+
assert_true(happened);
40+
}),
41+
t.unreached_func("Fetch should have succeeded")
42+
);
43+
frame.contentDocument.open();
44+
happened = true;
45+
});
46+
frame.src = "resources/meta-refresh.py?1";
47+
}, "document.open() does NOT abort documents that are queued for navigation through <meta> refresh with 1-sec timeout (fetch())");
48+
49+
async_test(t => {
50+
const frame = document.body.appendChild(document.createElement("iframe"));
51+
t.add_cleanup(() => frame.remove());
52+
frame.onload = t.step_func(() => {
53+
frame.onload = null;
54+
let happened = false;
55+
const img = frame.contentDocument.createElement("img");
56+
img.src = new URL("resources/slow-png.py", document.URL);
57+
img.onload = t.step_func_done(() => {
58+
assert_true(happened);
59+
});
60+
img.onerror = t.unreached_func("Image loading should not have errored");
61+
// The image fetch starts in a microtask, so let's be sure to test after
62+
// the fetch has started.
63+
t.step_timeout(() => {
64+
frame.contentDocument.open();
65+
happened = true;
66+
});
67+
});
68+
frame.src = "resources/meta-refresh.py?4";
69+
}, "document.open() does NOT abort documents that are queued for navigation through <meta> refresh with 4-sec timeout (image loading)");

0 commit comments

Comments
 (0)