|
5 | 5 | <script src="/resources/testharnessreport.js"></script>
|
6 | 6 | <div></div>
|
7 | 7 | <script>
|
8 |
| - var noop = function() {}; |
| 8 | + const noop = () => {}; |
| 9 | + const expect_error = (e) => { |
| 10 | + assert_equals(e.constructor, Event); |
| 11 | + }; |
9 | 12 |
|
10 | 13 | ["non-empty", "empty"].forEach(function(content) {
|
11 | 14 | ["text/csv",
|
|
18 | 21 | "image/jpeg",
|
19 | 22 | "image/gif",
|
20 | 23 | "image/whatever"].forEach(function(test_case) {
|
| 24 | + const url = "../resources/script-with-header.py?content=" + content + |
| 25 | + "&mime=" + test_case; |
| 26 | + |
| 27 | + async_test(function(t) { |
| 28 | + var script = document.createElement("script"); |
| 29 | + script.onerror = t.step_func_done(expect_error); |
| 30 | + script.onload = t.unreached_func("Unexpected load event"); |
| 31 | + script.src = url; |
| 32 | + document.body.appendChild(script); |
| 33 | + }, "Should fail loading " + content + " script with " + test_case + |
| 34 | + " MIME type (script)"); |
| 35 | + |
21 | 36 | async_test(function(t) {
|
22 | 37 | var script = document.createElement("script");
|
23 |
| - script.onerror = t.step_func_done(noop); |
| 38 | + script.setAttribute("type", "module"); |
| 39 | + script.onerror = t.step_func_done(expect_error); |
24 | 40 | script.onload = t.unreached_func("Unexpected load event");
|
25 |
| - script.src = "../resources/script-with-header.py?content=" + content + |
26 |
| - "&mime=" + test_case; |
| 41 | + script.src = url; |
27 | 42 | document.body.appendChild(script);
|
28 | 43 | }, "Should fail loading " + content + " script with " + test_case +
|
29 |
| - " MIME type"); |
| 44 | + " MIME type (module script)"); |
| 45 | + |
| 46 | + async_test(function(t) { |
| 47 | + const worker = new Worker(url); |
| 48 | + worker.onerror = t.step_func_done(expect_error); |
| 49 | + worker.onload = t.unreached_func("Unexpected load event"); |
| 50 | + }, "Should fail loading " + content + " script with " + test_case + |
| 51 | + " MIME type (dedicated worker)"); |
| 52 | + |
| 53 | + async_test(function(t) { |
| 54 | + const worker = new Worker(url, {type: "module"}); |
| 55 | + worker.onerror = t.step_func_done(expect_error); |
| 56 | + worker.onload = t.unreached_func("Unexpected load event"); |
| 57 | + }, "Should fail loading " + content + " script with " + test_case + |
| 58 | + " MIME type (module dedicated worker)"); |
30 | 59 | });
|
31 | 60 | });
|
32 | 61 |
|
|
37 | 66 | script.onload = t.step_func_done(noop);
|
38 | 67 | script.src = "../resources/script-with-header.py?mime=text/" + test_case;
|
39 | 68 | document.body.appendChild(script);
|
40 |
| - }, "Should load script with text/" + test_case + " MIME type"); |
| 69 | + }, "Should load script with text/" + test_case + " MIME type (script)"); |
41 | 70 | });
|
42 | 71 |
|
43 | 72 | </script>
|
0 commit comments