Skip to content

Commit

Permalink
Fix document.open tests to align with HTML spec changes.
Browse files Browse the repository at this point in the history
See whatwg/html#4723

Differential Revision: https://phabricator.services.mozilla.com/D45478

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1580381
gecko-commit: 4a4bed5bc1cb91fcc5d717bf66feade5442b23fe
gecko-integration-branch: autoland
gecko-reviewers: hsivonen
  • Loading branch information
bzbarsky authored and moz-wptsync-bot committed Oct 17, 2019
1 parent 796ebc4 commit d874037
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit d874037

Please sign in to comment.