Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit f8ae07a

Browse files
committed
Bug 1580381. Fix document.open tests to align with HTML spec changes. r=hsivonen
See whatwg/html#4723 Differential Revision: https://phabricator.services.mozilla.com/D45478 --HG-- extra : moz-landing-system : lando
1 parent 481c8f9 commit f8ae07a

4 files changed

Lines changed: 44 additions & 21 deletions

File tree

‎dom/base/Document.cpp‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8763,9 +8763,6 @@ Document* Document::Open(const Optional<nsAString>& /* unused */,
87638763

87648764
// Step 5 -- if we have an active parser with a nonzero script nesting level,
87658765
// just no-op.
8766-
//
8767-
// The mParserAborted check here is probably wrong. Removing it is
8768-
// tracked in https://bugzilla.mozilla.org/show_bug.cgi?id=1475000
87698766
if ((mParser && mParser->HasNonzeroScriptNestingLevel()) || mParserAborted) {
87708767
return this;
87718768
}

‎testing/web-platform/meta/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/aborted-parser.window.js.ini‎

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
// document.open() bails out early if there is an **active parser** with
2-
// non-zero script nesting level. window.stop() aborts the current parser and
3-
// makes it no longer active, and should allow document.open() to work.
4-
// For more details, see https://bugzilla.mozilla.org/show_bug.cgi?id=1475000.
1+
// document.open() bails out early if there is an active parser with non-zero
2+
// script nesting level or if a load was aborted while there was an active
3+
// parser. window.stop() aborts the current parser, so once it has been called
4+
// while a parser is active, document.open() will no longer do anything to that
5+
// document,
56

67
window.handlers = {};
78

89
async_test(t => {
910
const frame = document.body.appendChild(document.createElement("iframe"));
11+
t.add_cleanup(() => frame.remove());
1012
frame.src = "resources/aborted-parser-frame.html";
1113
window.handlers.afterOpen = t.step_func_done(() => {
1214
const openCalled = frame.contentDocument.childNodes.length === 0;
13-
frame.remove();
14-
assert_true(openCalled, "child document should be empty");
15+
assert_false(openCalled, "child document should not be empty");
16+
assert_equals(frame.contentDocument.querySelector("p").textContent,
17+
"Text", "Should still have our paragraph");
1518
});
1619
}, "document.open() after parser is aborted");
1720

18-
// Note: This test should pass even if window.close() is not there, as
19-
// document.open() is not executed synchronously in an inline script.
2021
async_test(t => {
2122
const frame = document.body.appendChild(document.createElement("iframe"));
23+
t.add_cleanup(() => frame.remove());
2224
frame.src = "resources/aborted-parser-async-frame.html";
2325
window.handlers.afterOpenAsync = t.step_func_done(() => {
2426
const openCalled = frame.contentDocument.childNodes.length === 0;
25-
frame.remove();
26-
assert_true(openCalled, "child document should be empty");
27+
assert_false(openCalled, "child document should not be empty");
28+
assert_equals(frame.contentDocument.querySelector("p").textContent,
29+
"Text", "Should still have our paragraph");
2730
});
2831
}, "async document.open() after parser is aborted");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title></title>
4+
<script src=/resources/testharness.js></script>
5+
<script src=/resources/testharnessreport.js></script>
6+
<body>
7+
<script>
8+
var t = async_test("Location sets should cancel current navigation and prevent later document.open() from doing anything");
9+
10+
var finishTest = t.step_func_done(function() {
11+
assert_equals(frames[0].document.body.textContent, "PASS",
12+
"Should not have FAIL in our textContent");
13+
});
14+
15+
t.step(function() {
16+
var i = document.createElement("iframe");
17+
i.srcdoc = `
18+
<script>
19+
var blob = new Blob(["PASS"], { type: "text/html" });
20+
var url = URL.createObjectURL(blob);
21+
location.href = url;
22+
frameElement.onload = parent.finishTest;
23+
document.open();
24+
document.write("FAIL");
25+
document.close();
26+
<\/script>`;
27+
document.body.appendChild(i);
28+
});
29+
30+
</script>
31+
</body>

0 commit comments

Comments
 (0)