summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/script/test_bug1053321.html
blob: bad2b4b4c4129a6a429c98c62807ff4bfcea3bae (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
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<!--
This test confirms we don't block body referred sub-resources by head-referenced defer and async scripts.
If this test times out, the two image requests, that unblock the two script requests, never happen, hence
are unexpectedly blocked.
-->

<head>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />

  <script>
    // The two scripts below are expected to load and call scriptLoaded().
    SimpleTest.waitForExplicitFinish();

    window.expected_scripts = {
      "defer": true,
      "async": true,
    };

    function scriptLoaded(script)
    {
      ok(true, 'Script ' + script + ' executed');
      delete window.expected_scripts[script];

      let expecting = Object.keys(window.expected_scripts).length;
      info("Expecting " + expecting + " more script(s) to execute");

      if (expecting == 0) {
        SimpleTest.finish();
      }
    }
  </script>

  <!-- this script is not loaded until file_blocked_script.sjs?unblock&defer request is made,
       when this script is executed, it calls SimpleTest.finish().
   -->
  <script defer src="file_blocked_script.sjs?blocked&defer"></script>

  <!-- this script is not loaded until file_blocked_script.sjs?unblock&async request is made,
       when this script is executed, it calls SimpleTest.finish().
   -->
  <script async src="file_blocked_script.sjs?blocked&async"></script>
</head>

<body>
  <img src="file_blocked_script.sjs?unblock&defer"/>
  <img src="file_blocked_script.sjs?unblock&async"/>
</body>