summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/helper.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/helper.js')
-rw-r--r--testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/helper.js31
1 files changed, 31 insertions, 0 deletions
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);
+}