Bug 1333990: Part 2e - Test that document.blockParsing blocks the parser at its current state during document-element-inserted. r?hsivonen
MozReview-Commit-ID: 1ERtCpAqeTg
--- a/dom/base/test/chrome.ini
+++ b/dom/base/test/chrome.ini
@@ -1,18 +1,24 @@
[DEFAULT]
skip-if = os == 'android'
support-files =
file_empty.html
file_bug945152.jar
file_bug945152_worker.js
file_bug1008126_worker.js
+ file_inline_script.html
+ file_inline_script.xhtml
+ file_external_script.html
+ file_external_script.xhtml
+ file_script.js
mozbrowser_api_utils.js
[test_anonymousContent_xul_window.xul]
+[test_blockParsing.html]
[test_bug715041.xul]
[test_bug715041_removal.xul]
[test_bug945152.html]
[test_bug1008126.html]
[test_bug1016960.html]
[test_copypaste.xul]
subsuite = clipboard
[test_domrequesthelper.xul]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_external_script.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <script src="file_script.js"></script>
+ <meta charset="utf-8">
+ <title></title>
+</head>
+<body>
+ <p>Hello Mochitest</p>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_external_script.xhtml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html>
+<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <script src="file_script.js"/>
+ <title/>
+</head>
+<body>
+ <p>Hello Mochitest</p>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_inline_script.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <script>window.scriptRan = true;</script>
+ <meta charset="utf-8">
+ <title></title>
+</head>
+<body>
+ <p>Hello Mochitest</p>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_inline_script.xhtml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html>
+<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <script>window.scriptRan = true;</script>
+ <title/>
+</head>
+<body>
+ <p>Hello Mochitest</p>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_script.js
@@ -0,0 +1,1 @@
+window.scriptRan = true;
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_blockParsing.html
@@ -0,0 +1,92 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for document.blockParsing</title>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+ <link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+</head>
+<body>
+<script>
+Components.utils.import("resource://testing-common/TestUtils.jsm");
+
+function* runTest(url, initialHTML, finalHTML) {
+ let iframe = document.createElement("iframe");
+ iframe.src = url;
+
+ let blockerPromise;
+ let promise = TestUtils.topicObserved("document-element-inserted", document => {
+ 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 = yield 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");
+
+ yield 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");
+
+ // Three trips to the event loop should be more than is necessary, but to be safe...
+ yield new Promise(resolve => setTimeout(resolve, 0));
+ yield new Promise(resolve => setTimeout(resolve, 0));
+ yield new Promise(resolve => setTimeout(resolve, 0));
+
+ // After a few trips to the event loop, parsing should have resumed, and
+ // 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(function* () {
+ yield runTest("http://mochi.test:8888/chrome/dom/base/test/file_inline_script.html",
+ '<html lang="en"></html>',
+ '<html lang="en"><head>\n <script>window.scriptRan = true;<\/script>\n <meta charset="utf-8">\n <title></title>\n</head>\n<body>\n <p>Hello Mochitest</p>\n\n\n</body></html>');
+
+ yield runTest("http://mochi.test:8888/chrome/dom/base/test/file_inline_script.xhtml",
+ '<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"></html>',
+ '<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">\n<head>\n <script>window.scriptRan = true;<\/script>\n <title></title>\n</head>\n<body>\n <p>Hello Mochitest</p>\n</body>\n</html>');
+
+ yield runTest("http://mochi.test:8888/chrome/dom/base/test/file_external_script.html",
+ '<html lang="en"></html>',
+ '<html lang="en"><head>\n <script src="file_script.js"><\/script>\n <meta charset="utf-8">\n <title></title>\n</head>\n<body>\n <p>Hello Mochitest</p>\n\n\n</body></html>');
+
+ yield runTest("http://mochi.test:8888/chrome/dom/base/test/file_external_script.xhtml",
+ '<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"></html>',
+ '<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">\n<head>\n <script src="file_script.js"><\/script>\n <title></title>\n</head>\n<body>\n <p>Hello Mochitest</p>\n</body>\n</html>');
+});
+</script>
+</body>
+</html>
+
+