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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-10-16 15:59:28 +00:00
Родитель b57c9b9834
Коммит 664c53333a
4 изменённых файлов: 44 добавлений и 21 удалений

Просмотреть файл

@ -8763,9 +8763,6 @@ Document* Document::Open(const Optional<nsAString>& /* unused */,
// 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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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");

Просмотреть файл

@ -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>