summaryrefslogtreecommitdiffstats
path: root/dom/security/test/general/file_loads_nonscript.html
blob: f7692b806622cbf7265c4afc071535cafbedf83e (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
<!DOCTYPE HTML>
<html>
<head>
  <title>File that loads a non-script file-extension as script</title>
</head>
<body>
  <script>
    /* global equal */

    const files = ["file_nonscript",
                   "file_nonscript.xyz",
                   "file_nonscript.html",
                   "file_nonscript.txt",
                   "file_nonscript.json"];

    async function run() {
      window.counter = 0;

      for (let file of files) {
        let script = document.createElement("script");
        let promise = new Promise((resolve, reject) => {
          script.addEventListener("error", resolve, {once: true});
          script.addEventListener("load", reject, {once: true});
        });
        script.src = file;
        document.body.append(script);

        let event = await promise;
        equal(event.type, "error");
        equal(window.counter, 0);
      }

      let script = document.createElement("script");
      let promise = new Promise((resolve, reject) => {
        script.addEventListener("load", resolve, {once: true});
        script.addEventListener("error", reject, {once: true});
      });
      script.src = "file_script.js";
      document.body.append(script);

      let event = await promise;
      equal(event.type, "load");
      equal(window.counter, 1);

      window.postMessage("done", "*");
    }
    window.addEventListener("message", run, {once: true})
  </script>
</html>