diff options
Diffstat (limited to 'testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering')
7 files changed, 144 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/README.md b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/README.md new file mode 100644 index 0000000000..dcf5597e2d --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/README.md @@ -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). diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-1.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-1.html new file mode 100644 index 0000000000..c5812765eb --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-1.html @@ -0,0 +1,12 @@ +<!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> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-2.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-2.html new file mode 100644 index 0000000000..916673894d --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-2.html @@ -0,0 +1,15 @@ +<!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> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-iframe.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-iframe.html new file mode 100644 index 0000000000..efec7657c3 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/delay-load-event-iframe.html @@ -0,0 +1,4 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<body onload="parent.onloadIframe()"> +<script src="../../resources/throw.js?pipe=trickle(d2)"></script> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/helper.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/helper.js new file mode 100644 index 0000000000..cb5f45eb0d --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/helper.js @@ -0,0 +1,31 @@ +function runDelayEventTest(description) { + const t_original = 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 iframe = document.createElement('iframe'); + iframe.setAttribute('src', 'delay-load-event-iframe.html'); + const start_time = performance.now(); + document.body.appendChild(iframe); + + window.onload = t_original.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, 3000, + 'Load event should not be delayed until moved script is loaded'); + }); + + t_original.step_timeout(() => { + const script = document.querySelector('#to-be-moved'); + iframe.contentDocument.body.appendChild(script); + }, 1000); +} diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/in-order.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/in-order.html new file mode 100644 index 0000000000..6a3e2b54a7 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/in-order.html @@ -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> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/parser-blocking.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/parser-blocking.html new file mode 100644 index 0000000000..9edde13736 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/parser-blocking.html @@ -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> |