-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix document.open tests to align with HTML spec changes.
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
1 parent
796ebc4
commit d874037
Showing
2 changed files
with
44 additions
and
10 deletions.
There are no files selected for viewing
23 changes: 13 additions & 10 deletions
23
html/webappapis/dynamic-markup-insertion/opening-the-input-stream/aborted-parser.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
31 changes: 31 additions & 0 deletions
31
...pis/dynamic-markup-insertion/opening-the-input-stream/location-set-and-document-open.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |