Skip to content

Commit

Permalink
HTML: document.open() and aborting documents
Browse files Browse the repository at this point in the history
For #10773.

Co-authored-by: Anne van Kesteren <[email protected]>
  • Loading branch information
TimothyGu and annevk committed Sep 6, 2018
1 parent e5b61fb commit fa75e02
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 3 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
var test5_load = event_test('no src, parser-inserted, has style sheets blocking scripts, script nesting level == 1', false, false);
</script>

<link rel="stylesheet" href="resources/slow.py"></link>
<link rel="stylesheet" href="/common/slow.py"></link>
<!-- This is testing the case where an inline classic script is inserted
by parser while there is an loading stylesheet. Therefore, it is critical to
place a <link rel="stylesheet"> just above the <script> to be tested. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
false, false);

document.write(
`<link rel="stylesheet" href="resources/slow.py"></link>
`<link rel="stylesheet" href="/common/slow.py"></link>
<script onload="onLoad(test6_load);"
onerror="onError(test6_load);">
"use strict";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// The following tests deal with the <meta http-equiv=refresh> pragma and the
// `Refresh` header. The spec is still hazy on the precise behavior in those
// cases but we use https://github.com/whatwg/html/issues/4003 as a guideline.

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;

const client = new frame.contentWindow.XMLHttpRequest();
client.open("GET", "/common/blank.html");
client.onabort = t.step_func_done();
client.send();

frame.contentDocument.open();
});
frame.src = "resources/meta-refresh.py?0";
}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (XMLHttpRequest)");

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;

frame.contentWindow.fetch("/common/blank.html").then(
t.unreached_func("Fetch should have been aborted"),
t.step_func_done());

frame.contentDocument.open();
});
frame.src = "resources/meta-refresh.py?0";
}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (fetch())");

// We cannot test for img element's error event for this test, as Firefox does
// not fire the event if the fetch is aborted while Chrome does.
async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;

let happened = false;
const img = frame.contentDocument.createElement("img");
img.src = new URL("resources/slow-png.py", document.URL);
img.onload = t.unreached_func("Image loading should not have succeeded");
// The image fetch starts in a microtask, so let's be sure to test after
// the fetch has started.
t.step_timeout(() => {
frame.contentDocument.open();
happened = true;
});
// If 3 seconds have passed and the image has still not loaded, we consider
// it aborted. slow-png.py only sleeps for 2 wallclock seconds.
t.step_timeout(t.step_func_done(() => {
assert_true(happened);
}), 3000);
});
frame.src = "resources/meta-refresh.py?0";
}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (image loading)");

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;

const client = new frame.contentWindow.XMLHttpRequest();
client.open("GET", "/common/blank.html");
client.onabort = t.step_func_done();
client.send();

frame.contentDocument.open();
});
frame.src = "resources/http-refresh.py?0";
}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (XMLHttpRequest)");

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;

frame.contentWindow.fetch("/common/blank.html").then(
t.unreached_func("Fetch should have been aborted"),
t.step_func_done());

frame.contentDocument.open();
});
frame.src = "resources/http-refresh.py?0";
}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (fetch())");

// We cannot test for img element's error event for this test, as Firefox does
// not fire the event if the fetch is aborted while Chrome does.
async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;

let happened = false;
const img = frame.contentDocument.createElement("img");
img.src = new URL("resources/slow-png.py", document.URL);
img.onload = t.unreached_func("Image loading should not have succeeded");
// The image fetch starts in a microtask, so let's be sure to test after
// the fetch has started.
t.step_timeout(() => {
frame.contentDocument.open();
happened = true;
});
// If 3 seconds have passed and the image has still not loaded, we consider
// it aborted. slow-png.py only sleeps for 2 wallclock seconds.
t.step_timeout(t.step_func_done(() => {
assert_true(happened);
}), 3000);
});
frame.src = "resources/http-refresh.py?0";
}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (image loading)");
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// The following tests deal with the <meta http-equiv=refresh> pragma and the
// `Refresh` header. The spec is still hazy on the precise behavior in those
// cases but we use https://github.com/whatwg/html/issues/4003 as a guideline.
//
// This is separate from abort-refresh-multisecond-meta.window.js to avoid
// browser interventions that limit the number of connections in a tab.

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;
let happened = false;

const client = new frame.contentWindow.XMLHttpRequest();
client.open("GET", "/common/blank.html");
client.onload = t.step_func_done(() => {
assert_true(happened);
});
client.onerror = t.unreached_func("XMLHttpRequest should have succeeded");
client.onabort = t.unreached_func("XMLHttpRequest should have succeeded");
client.ontimeout = t.unreached_func("XMLHttpRequest should have succeeded");
client.send();

frame.contentDocument.open();
happened = true;
});
frame.src = "resources/http-refresh.py?1";
}, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 1-sec timeout (XMLHttpRequest)");

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;
let happened = false;
frame.contentWindow.fetch("/common/blank.html").then(
t.step_func_done(() => {
assert_true(happened);
}),
t.unreached_func("Fetch should have succeeded")
);
frame.contentDocument.open();
happened = true;
});
frame.src = "resources/http-refresh.py?1";
}, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 1-sec timeout (fetch())");

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;
let happened = false;
const img = frame.contentDocument.createElement("img");
img.src = new URL("resources/slow-png.py", document.URL);
img.onload = t.step_func_done(() => {
assert_true(happened);
});
img.onerror = t.unreached_func("Image loading should not have errored");
// The image fetch starts in a microtask, so let's be sure to test after
// the fetch has started.
t.step_timeout(() => {
frame.contentDocument.open();
happened = true;
});
});
frame.src = "resources/http-refresh.py?4";
}, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 4-sec timeout (image loading)");
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// The following tests deal with the <meta http-equiv=refresh> pragma and the
// `Refresh` header. The spec is still hazy on the precise behavior in those
// cases but we use https://github.com/whatwg/html/issues/4003 as a guideline.
//
// This is separate from abort-refresh-multisecond-header.window.js to avoid
// browser interventions that limit the number of connections in a tab.

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;
let happened = false;

const client = new frame.contentWindow.XMLHttpRequest();
client.open("GET", "/common/blank.html");
client.onload = t.step_func_done(() => {
assert_true(happened);
});
client.onerror = t.unreached_func("XMLHttpRequest should have succeeded");
client.onabort = t.unreached_func("XMLHttpRequest should have succeeded");
client.ontimeout = t.unreached_func("XMLHttpRequest should have succeeded");
client.send();

frame.contentDocument.open();
happened = true;
});
frame.src = "resources/meta-refresh.py?1";
}, "document.open() does NOT abort documents that are queued for navigation through <meta> refresh with 1-sec timeout (XMLHttpRequest)");

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;
let happened = false;
frame.contentWindow.fetch("/common/blank.html").then(
t.step_func_done(() => {
assert_true(happened);
}),
t.unreached_func("Fetch should have succeeded")
);
frame.contentDocument.open();
happened = true;
});
frame.src = "resources/meta-refresh.py?1";
}, "document.open() does NOT abort documents that are queued for navigation through <meta> refresh with 1-sec timeout (fetch())");

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func(() => {
frame.onload = null;
let happened = false;
const img = frame.contentDocument.createElement("img");
img.src = new URL("resources/slow-png.py", document.URL);
img.onload = t.step_func_done(() => {
assert_true(happened);
});
img.onerror = t.unreached_func("Image loading should not have errored");
// The image fetch starts in a microtask, so let's be sure to test after
// the fetch has started.
t.step_timeout(() => {
frame.contentDocument.open();
happened = true;
});
});
frame.src = "resources/meta-refresh.py?4";
}, "document.open() does NOT abort documents that are queued for navigation through <meta> refresh with 4-sec timeout (image loading)");
Loading

0 comments on commit fa75e02

Please sign in to comment.