<!
DOCTYPE HTML>
<
html>
<
head>
<
title>Test for document.blockParsing</
title>
<
script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></
script>
<
link rel=
"stylesheet" href=
"chrome://mochikit/content/tests/SimpleTest/test.css">
</
head>
<
body>
<
script>
const {TestUtils} = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
async function runTest(url, initialHTML, finalHTML) {
let
iframe = document.createElement(
"iframe");
iframe.src = url;
let blockerPromise;
let promise = TestUtils.topicObserved(
"document-element-inserted", document => {
if (document !==
iframe.contentDocument) {
return false;
}
blockerPromise = new Promise(resolve => {
setTimeout(resolve, 0);
}).then(() => {
return new Promise(resolve => setTimeout(resolve, 0));
}).then(() => {
return new Promise(resolve => setTimeout(resolve, 0));
});
is(document.documentElement.outerHTML, initialHTML,
"Should have initial HTML during document-element-inserted");
is(document.defaultView.wrappedJSObject.scriptRan, undefined,
"Script node should not have run");
document.blockParsing(blockerPromise);
return true;
}).then(([document]) => {
return document;
});
document.
body.appendChild(
iframe);
// Wait for document-element-inserted to fire.
let doc = await promise;
let win = doc.defaultView.wrappedJSObject;
let root = doc.documentElement;
// At this point, if the parser was successfully blocked, we should still
// have the initial skeleton
HTML for the page.
is(root.outerHTML, initialHTML,
"Should have initial HTML after document-element-inserted returns");
is(win.scriptRan, undefined,
"Script node should still not have run");
await blockerPromise;
// Just after the promise that
's blocking the parser fires, we shouldn't have
// returned to the main event loop, so we should still have the initial
HTML.
is(root.outerHTML, initialHTML,
"Should still have initial HTML");
is(win.scriptRan, undefined,
"Script node should still not have run");
await new Promise(resolve => win.addEventListener(
"DOMContentLoaded", resolve, {once: tr
ue}));
// Parsing should have resumed, and we should have finished loading the document.
is(root.outerHTML, finalHTML, "Should have final HTML");
is(win.scriptRan, true, "Script node should have run");
iframe.remove();
}
add_task(async function() {
await runTest("http://mochi.test:8888/chrome/dom/base/test/file_inline_script.html",
'',
'\n