summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/helper.js
blob: cb5f45eb0d656a09c8f12aa37c1127f2752f1c09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
}