Skip to content

Commit

Permalink
Bug 1765219 [wpt PR 33671] - [WPT] ordering/delay-the-load-event arou…
Browse files Browse the repository at this point in the history
…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
hiroshige-g authored and moz-wptsync-bot committed May 15, 2022
1 parent c30f007 commit 4fe7a4b
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Use
$ tools/generate.py
```

to generate test HTML files.
to generate test HTML files (except for tests in subdirectories).

Background:

Expand Down
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).
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>
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>
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>
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);
}
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>
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>

0 comments on commit 4fe7a4b

Please sign in to comment.