forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test moving <script>s between documents
This follows the changes in whatwg/html#2673, but also tests the issue at whatwg/html#2137 in favor of the current spec.
- Loading branch information
1 parent
db7735a
commit d64d5b6
Showing
3 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
html/semantics/scripting-1/the-script-element/moving-between-documents.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,138 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Moving script elements between documents</title> | ||
<link rel="author" href="mailto:d@domenic.me" title="Domenic Denicola"> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/#execute-the-script-block"> | ||
|
||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<!-- Background: | ||
- https://www.w3.org/Bugs/Public/show_bug.cgi?id=11323 | ||
- https://github.com/whatwg/html/issues/2137 | ||
- https://github.com/whatwg/html/issues/2469 | ||
- https://github.com/whatwg/html/pull/2673 | ||
--> | ||
|
||
<body> | ||
<script> | ||
"use strict"; | ||
window.didExecute = false; | ||
|
||
async_test(t => { | ||
t.add_cleanup(() => { | ||
window.didExecute = false; | ||
}); | ||
|
||
const iframe = document.createElement("iframe"); | ||
iframe.onload = t.step_func_done(() => { | ||
iframe.contentWindow.didExecute = false; | ||
iframe.contentDocument.write("<streaming-element>"); | ||
document.body.appendChild(iframe.contentDocument.querySelector("streaming-element")); | ||
iframe.contentDocument.write(`<script id="s1">window.didExecute = true;<` + "/script>"); | ||
iframe.contentDocument.write("</streaming-element>"); | ||
|
||
const s = document.querySelector("#s1"); | ||
s.onload = t.unreached_func("onload"); | ||
s.onerror = t.unreached_func("onerror"); | ||
|
||
iframe.contentDocument.close(); | ||
|
||
assert_false(window.didExecute, "The script must not have executed in this window"); | ||
assert_equals(iframe.contentWindow.didExecute, undefined, | ||
"The script must not have executed in the iframe window"); | ||
}); | ||
|
||
document.body.appendChild(iframe); | ||
}, "Moving to another document during parsing, inline script"); | ||
|
||
async_test(t => { | ||
t.add_cleanup(() => { | ||
window.didExecute = false; | ||
}); | ||
|
||
const iframe = document.createElement("iframe"); | ||
iframe.onload = t.step_func(() => { | ||
iframe.contentWindow.didExecute = false; | ||
iframe.contentDocument.write("<streaming-element>"); | ||
document.body.appendChild(iframe.contentDocument.querySelector("streaming-element")); | ||
iframe.contentDocument.write(`<script id="s2" src="resources/flag-setter.js"><` + "/script>"); | ||
iframe.contentDocument.write("</streaming-element>"); | ||
|
||
const s = document.querySelector("#s2"); | ||
s.onload = t.unreached_func("onload"); | ||
s.onerror = t.unreached_func("onerror"); | ||
|
||
iframe.contentDocument.close(); | ||
|
||
t.step_timeout(() => { | ||
assert_false(window.didExecute, "The script must not have executed in this window"); | ||
assert_equals(iframe.contentWindow.didExecute, undefined, | ||
"The script must not have executed in the iframe window"); | ||
t.done(); | ||
}, 3000); | ||
}); | ||
|
||
document.body.appendChild(iframe); | ||
}, "Moving to another document during parsing, external script"); | ||
|
||
async_test(t => { | ||
t.add_cleanup(() => { | ||
window.didExecute = false; | ||
}); | ||
|
||
const iframe = document.createElement("iframe"); | ||
iframe.onload = t.step_func(() => { | ||
const s = document.createElement("script"); | ||
s.src = "resources/slow-flag-setter.py"; | ||
s.onload = t.unreached_func("onload"); | ||
s.onerror = t.unreached_func("onerror"); | ||
|
||
// Start the fetch | ||
document.body.appendChild(s); | ||
|
||
// Need to delay since the "prepare a script" algorithm also contains related checks; we want to | ||
// test the "execute a script block" algorithm for when the fetch comes back. | ||
t.step_timeout(() => { | ||
iframe.contentDocument.body.appendChild(s); | ||
}, 0); | ||
|
||
t.step_timeout(() => { | ||
assert_false(window.didExecute, "The script must not have executed in this window"); | ||
assert_equals(iframe.contentWindow.didExecute, undefined, | ||
"The script must not have executed in the iframe window"); | ||
t.done(); | ||
}, 3000); | ||
}); | ||
|
||
document.body.appendChild(iframe); | ||
}, "Moving to another Window's document during fetching"); | ||
|
||
async_test(t => { | ||
t.add_cleanup(() => { | ||
window.didExecute = false; | ||
}); | ||
|
||
const s = document.createElement("script"); | ||
s.src = "resources/slow-flag-setter.py"; | ||
s.onload = t.unreached_func("onload"); | ||
s.onerror = t.unreached_func("onerror"); | ||
|
||
// Start the fetch | ||
document.body.appendChild(s); | ||
|
||
// Need to delay since the "prepare a script" algorithm also contains related checks; we want to | ||
// test the "execute a script block" algorithm for when the fetch comes back. | ||
t.step_timeout(() => { | ||
const doc2 = document.implementation.createHTMLDocument("title"); | ||
doc2.body.appendChild(s); | ||
}, 0); | ||
|
||
t.step_timeout(() => { | ||
assert_false(window.didExecute, "The script must not have executed in this window"); | ||
t.done(); | ||
}, 3000); | ||
}, "Moving to a document where scripting is disabled during fetching"); | ||
</script> |
3 changes: 3 additions & 0 deletions
3
html/semantics/scripting-1/the-script-element/resources/flag-setter.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,3 @@ | ||
"use strict"; | ||
|
||
window.didExecute = true; |
10 changes: 10 additions & 0 deletions
10
html/semantics/scripting-1/the-script-element/resources/slow-flag-setter.py
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,10 @@ | ||
|
||
import time | ||
|
||
def main(request, response): | ||
time.sleep(1) | ||
|
||
headers = [("Content-Type", "text/javascript")] | ||
body = "window.didExecute = true;" | ||
|
||
return headers, body |