Bug 1580381. Fix document.open tests to align with HTML spec changes. r=hsivonen
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 16 Oct 2019 15:59:28 +0000
changeset 559234 4a4bed5bc1cb91fcc5d717bf66feade5442b23fe
parent 559233 383e2052153e8f58da4f4e1b80005cee58ca4761
child 559235 520d76b5e3bcfc8ae2256acd4ae4ec0b75ac75a2
push id12175
push userccoroiu@mozilla.com
push dateThu, 17 Oct 2019 19:29:09 +0000
treeherdermozilla-beta@d333b6ef1fd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs1580381
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1580381. Fix document.open tests to align with HTML spec changes. r=hsivonen See https://github.com/whatwg/html/issues/4723 Differential Revision: https://phabricator.services.mozilla.com/D45478
dom/base/Document.cpp
testing/web-platform/meta/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/aborted-parser.window.js.ini
testing/web-platform/tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/aborted-parser.window.js
testing/web-platform/tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/location-set-and-document-open.html
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -8758,19 +8758,16 @@ Document* Document::Open(const Optional<
   // the entry document.
   if (!callerDoc->NodePrincipal()->Equals(NodePrincipal())) {
     aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return nullptr;
   }
 
   // Step 5 -- if we have an active parser with a nonzero script nesting level,
   // just no-op.
-  //
-  // The mParserAborted check here is probably wrong.  Removing it is
-  // tracked in https://bugzilla.mozilla.org/show_bug.cgi?id=1475000
   if ((mParser && mParser->HasNonzeroScriptNestingLevel()) || mParserAborted) {
     return this;
   }
 
   // Step 6 -- check for open() during unload.  Per spec, this is just a check
   // of the ignore-opens-during-unload counter, but our unload event code
   // doesn't affect that counter yet (unlike pagehide and beforeunload, which
   // do), so we check for unload directly.
deleted file mode 100644
--- a/testing/web-platform/meta/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/aborted-parser.window.js.ini
+++ /dev/null
@@ -1,8 +0,0 @@
-[aborted-parser.window.html]
-  [document.open() after parser is aborted]
-    expected: FAIL
-    bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1475000
-
-  [async document.open() after parser is aborted]
-    expected: FAIL
-    bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1475000
--- a/testing/web-platform/tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/aborted-parser.window.js
+++ b/testing/web-platform/tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/aborted-parser.window.js
@@ -1,28 +1,31 @@
-// document.open() bails out early if there is an **active parser** with
-// non-zero script nesting level. window.stop() aborts the current parser and
-// makes it no longer active, and should allow document.open() to work.
-// For more details, see https://bugzilla.mozilla.org/show_bug.cgi?id=1475000.
+// document.open() bails out early if there is an active parser with non-zero
+// script nesting level or if a load was aborted while there was an active
+// parser. window.stop() aborts the current parser, so once it has been called
+// while a parser is active, document.open() will no longer do anything to that
+// document,
 
 window.handlers = {};
 
 async_test(t => {
   const frame = document.body.appendChild(document.createElement("iframe"));
+  t.add_cleanup(() => frame.remove());
   frame.src = "resources/aborted-parser-frame.html";
   window.handlers.afterOpen = t.step_func_done(() => {
     const openCalled = frame.contentDocument.childNodes.length === 0;
-    frame.remove();
-    assert_true(openCalled, "child document should be empty");
+    assert_false(openCalled, "child document should not be empty");
+    assert_equals(frame.contentDocument.querySelector("p").textContent,
+                  "Text", "Should still have our paragraph");
   });
 }, "document.open() after parser is aborted");
 
-// Note: This test should pass even if window.close() is not there, as
-// document.open() is not executed synchronously in an inline script.
 async_test(t => {
   const frame = document.body.appendChild(document.createElement("iframe"));
+  t.add_cleanup(() => frame.remove());
   frame.src = "resources/aborted-parser-async-frame.html";
   window.handlers.afterOpenAsync = t.step_func_done(() => {
     const openCalled = frame.contentDocument.childNodes.length === 0;
-    frame.remove();
-    assert_true(openCalled, "child document should be empty");
+    assert_false(openCalled, "child document should not be empty");
+    assert_equals(frame.contentDocument.querySelector("p").textContent,
+                  "Text", "Should still have our paragraph");
   });
 }, "async document.open() after parser is aborted");
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/location-set-and-document-open.html
@@ -0,0 +1,31 @@
+<!doctype html>
+<meta charset=utf-8>
+<title></title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<body>
+  <script>
+    var t = async_test("Location sets should cancel current navigation and prevent later document.open() from doing anything");
+
+    var finishTest = t.step_func_done(function() {
+        assert_equals(frames[0].document.body.textContent, "PASS",
+                      "Should not have FAIL in our textContent");
+    });
+
+    t.step(function() {
+        var i = document.createElement("iframe");
+        i.srcdoc = `
+          <script>
+            var blob = new Blob(["PASS"], { type: "text/html" });
+            var url = URL.createObjectURL(blob);
+            location.href = url;
+            frameElement.onload = parent.finishTest;
+            document.open();
+            document.write("FAIL");
+            document.close();
+          <\/script>`;
+        document.body.appendChild(i);
+    });
+
+  </script>
+</body>