-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1484354 [wpt PR 12555] - HTML: document.open() and reload, a=test…
…only Automatic update from web-platform-testsHTML: document.open() and reload (#12555) For whatwg/html#3946. -- wpt-commits: 8b0c29bfa35d03c3db9027af796abcdb08b7c6dc wpt-pr: 12555
- Loading branch information
1 parent
f271a26
commit f3893fc
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
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
71 changes: 71 additions & 0 deletions
71
.../tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/reload.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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// This test tests for the nonexistence of a reload override buffer, which is | ||
// used in a previous version of the HTML Standard to make reloads of a | ||
// document.open()'d document load the written-to document rather than doing an | ||
// actual reload of the document's URL. | ||
// | ||
// This test has a somewhat interesting structure compared to the other tests | ||
// in this directory. It eschews the <iframe> structure used by other tests, | ||
// since when the child frame is reloaded it would adopt the URL of the test | ||
// page (the responsible document of the entry settings object), and the spec | ||
// forbids navigation in nested browsing contexts to the same URL as their | ||
// parent. To work around that, we use window.open() which does not suffer from | ||
// that restriction. | ||
// | ||
// In any case, this test as the caller of `document.open()` would be used both | ||
// as the test file and as part of the test file. The `if (!opener)` condition | ||
// controls what role this file plays. | ||
|
||
if (!opener) { | ||
async_test(t => { | ||
const testURL = document.URL; | ||
const dummyURL = new URL("resources/dummy.html", document.URL).href; | ||
|
||
// 1. Open an auxiliary window. | ||
const win = window.open("resources/dummy.html"); | ||
t.add_cleanup(() => { win.close(); }); | ||
|
||
win.addEventListener("load", t.step_func(() => { | ||
// The timeout seems to be necessary for Firefox, which when `load` is | ||
// called may still have an active parser. | ||
t.step_timeout(() => { | ||
const doc = win.document; | ||
assert_true(doc.body.textContent.includes("Dummy"), "precondition"); | ||
assert_equals(doc.URL, dummyURL, "precondition"); | ||
|
||
window.onChildLoad = t.step_func(message => { | ||
// 3. The dynamically overwritten content will trigger this function, | ||
// which puts in place the actual test. | ||
|
||
assert_equals(message, "Written", "script on written page is executed"); | ||
assert_true(win.document.body.textContent.includes("Content"), "page is written to"); | ||
assert_equals(win.document.URL, testURL, "postcondition: after document.write()"); | ||
assert_equals(win.document, doc, "document.open should not change the document object"); | ||
window.onChildLoad = t.step_func_done(message => { | ||
// 6. This function should be called from the if (opener) branch of | ||
// this file. It would throw an assertion error if the overwritten | ||
// content was executed instead. | ||
assert_equals(message, "Done!", "actual test"); | ||
assert_true(win.document.body.textContent.includes("Back to the test"), "test is reloaded"); | ||
assert_equals(win.document.URL, testURL, "postcondition: after reload"); | ||
assert_not_equals(win.document, doc, "reload should change the document object"); | ||
}); | ||
|
||
// 4. Reload the pop-up window. Because of the doc.open() call, this | ||
// pop-up window will reload to the same URL as this test itself. | ||
win.location.reload(); | ||
}); | ||
|
||
// 2. When it is loaded, dynamically overwrite its content. | ||
assert_equals(doc.open(), doc); | ||
assert_equals(doc.URL, testURL, "postcondition: after document.open()"); | ||
doc.write("<p>Content</p><script>opener.onChildLoad('Written');</script>"); | ||
doc.close(); | ||
}, 100); | ||
}), { once: true }); | ||
}, "Reloading a document.open()'d page should reload the URL of the entry realm's responsible document"); | ||
} else { | ||
document.write("<p>Back to the test</p>"); | ||
// 5. Since this window is window.open()'d, opener refers to the test window. | ||
// Inform the opener that reload succeeded. | ||
opener.onChildLoad("Done!"); | ||
} |
2 changes: 2 additions & 0 deletions
2
...ts/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/resources/dummy.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,2 @@ | ||
<!-- Like /common/blank.html, but with some content in it. --> | ||
<p>Dummy</p> |