summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/ordering/parser-blocking.html
blob: 9edde1373676716b94fdb99aeeffe4cf50f2aa5d (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
32
33
34
35
36
37
38
39
40
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>