-
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 1765219 [wpt PR 33671] - [WPT] ordering/delay-the-load-event arou…
…nd scripts moved between Documents, a=testonly Automatic update from web-platform-tests [WPT] ordering/delay-the-load-event around scripts moved between Documents Bug: 1303648, 1317437, whatwg/html#5160 Change-Id: I83c8fc73804eb5c4de1508947fd1415cae3c3bcd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3508112 Reviewed-by: Domenic Denicola <domenic@chromium.org> Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Cr-Commit-Position: refs/heads/main@{#994917} -- wpt-commits: d533110f00fa6250e1ebbe46a23d2d2e3f70df1e wpt-pr: 33671
- Loading branch information
1 parent
c30f007
commit 4fe7a4b
Showing
8 changed files
with
143 additions
and
1 deletion.
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
6 changes: 6 additions & 0 deletions
6
...tics/scripting-1/the-script-element/moving-between-documents/ordering/README.md
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,6 @@ | ||
The tests in this directory checks side effects (other than script | ||
evaluation/event firing, which is covered by the tests in the parent directory) | ||
caused by scripts moved between Documents. | ||
|
||
The tests assume that script loading is not canceled when moved between | ||
documents (which is not explicitly specified as of Jan 2022). |
10 changes: 10 additions & 0 deletions
10
.../scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-1.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,10 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="helper.js"></script> | ||
<body> | ||
<script> | ||
runDelayEventTest('Script elements (parser-blocking)'); | ||
</script> | ||
<script id="to-be-moved" src="../../resources/throw.js?pipe=trickle(d3)"></script> |
14 changes: 14 additions & 0 deletions
14
.../scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-2.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,14 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="helper.js"></script> | ||
<body> | ||
<script> | ||
runDelayEventTest('Script elements (async)'); | ||
|
||
const script = document.createElement('script'); | ||
script.setAttribute('id', 'to-be-moved'); | ||
script.setAttribute('src', '../../resources/throw.js?pipe=trickle(d3)'); | ||
document.body.appendChild(script); | ||
</script> |
5 changes: 5 additions & 0 deletions
5
...pting-1/the-script-element/moving-between-documents/ordering/delay-load-event-iframe.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,5 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<body onload="parent.onloadIframe()"> | ||
<script src="../../resources/throw.js?pipe=trickle(d2)"></script> | ||
</body> |
31 changes: 31 additions & 0 deletions
31
...html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/helper.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,31 @@ | ||
function runDelayEventTest(description) { | ||
const t = async_test(description + | ||
' still delay the load event in the original Document after move'); | ||
const t_new = async_test(description + | ||
' does not delay the load event in the new Document after move'); | ||
const start_time = performance.now(); | ||
const iframe = document.createElement('iframe'); | ||
iframe.setAttribute('src', 'delay-load-event-iframe.html'); | ||
document.body.appendChild(iframe); | ||
|
||
window.onload = t.step_func_done(() => { | ||
// The `#to-be-moved` script should delay the load event until it is loaded | ||
// (i.e. 3 seconds), not just until it is moved out to another Document | ||
// (i.e. 1 second). Here we expect the delay should be at least 2 seconds, | ||
// as the latency can be slightly less than 3 seconds due to preloading. | ||
assert_greater_than(performance.now() - start_time, 2000, | ||
'Load event should be delayed until script is loaded'); | ||
}); | ||
|
||
window.onloadIframe = t_new.step_func_done(() => { | ||
// The iframe's load event is fired after 2 seconds of its subresource | ||
// loading, and shouldn't wait for the `#to-be-moved` script. | ||
assert_less_than(performance.now() - start_time, 2500, | ||
'Load event should not be delayed until moved script is loaded'); | ||
}); | ||
|
||
t.step_timeout(() => { | ||
const script = document.querySelector('#to-be-moved'); | ||
iframe.contentDocument.body.appendChild(script); | ||
}, 1000); | ||
} |
35 changes: 35 additions & 0 deletions
35
.../semantics/scripting-1/the-script-element/moving-between-documents/ordering/in-order.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,35 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<link rel="help" href="https://html.spec.whatwg.org/C/#list-of-scripts-that-will-execute-in-order-as-soon-as-possible"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="helper.js"></script> | ||
<body> | ||
<script> | ||
const t = async_test('Script elements (in-order) still block subsequent in-order scripts in the original Document after moved to another Document'); | ||
const start_time = performance.now(); | ||
const iframe = document.createElement('iframe'); | ||
document.body.appendChild(iframe); | ||
|
||
const onScript2Evaluated = t.step_func_done(() => { | ||
// `script1` should remain the | ||
// #list-of-scripts-that-will-execute-in-order-as-soon-as-possible of the | ||
// original Document and thus blocks `script2` evaluation until it is loaded. | ||
assert_greater_than(performance.now() - start_time, 2000, | ||
'In-order scripts should block subsequent in-order scripts'); | ||
}); | ||
|
||
const script1 = document.createElement('script'); | ||
script1.async = false; | ||
script1.setAttribute('src', '../../resources/throw.js?pipe=trickle(d2)'); | ||
document.body.appendChild(script1); | ||
|
||
const script2 = document.createElement('script'); | ||
script2.async = false; | ||
script2.setAttribute('src', 'data:text/javascript,onScript2Evaluated()'); | ||
document.body.appendChild(script2); | ||
|
||
t.step_timeout(() => { | ||
iframe.contentDocument.body.appendChild(script1); | ||
}, 1000); | ||
</script> |
41 changes: 41 additions & 0 deletions
41
...ics/scripting-1/the-script-element/moving-between-documents/ordering/parser-blocking.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,41 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<link rel="help" href="https://html.spec.whatwg.org/C/#pending-parsing-blocking-script"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="helper.js"></script> | ||
<body> | ||
<script> | ||
const t = async_test('Script elements (parser-blocking) still block the parser in the original Document after moved to another Document'); | ||
const start_time = performance.now(); | ||
const iframe = document.createElement('iframe'); | ||
document.body.appendChild(iframe); | ||
|
||
t.step_timeout(() => { | ||
const script = document.querySelector('#to-be-moved'); | ||
iframe.contentDocument.body.appendChild(script); | ||
}, 1000); | ||
|
||
let syncScriptEvaluated = false; | ||
|
||
const onSyncScript = t.step_func(() => { | ||
syncScriptEvaluated = true; | ||
|
||
// The `#to-be-moved` script should block the parser and thus the sync | ||
// script after `#to-be-moved` should be delayed until `#to-be-moved` is | ||
// loaded (i.e. 3 seconds). | ||
// Here we expect the delay should be at least 2 seconds, | ||
// as the latency can be slightly less than 3 seconds due to preloading. | ||
assert_greater_than(performance.now() - start_time, 2000, | ||
'Parser should be blocked until script is loaded'); | ||
}); | ||
|
||
document.addEventListener('DOMContentLoaded', t.step_func_done(() => { | ||
assert_true(syncScriptEvaluated, | ||
'sync script should be evaluated before DOMContentLoaded'); | ||
assert_greater_than(performance.now() - start_time, 2000, | ||
'DOMContentLoaded event should be delayed until script is loaded'); | ||
})); | ||
</script> | ||
<script id="to-be-moved" src="../../resources/throw.js?pipe=trickle(d3)"></script> | ||
<script src="data:text/javascript,onSyncScript()"></script> |