Skip to content

Commit 918ca86

Browse files
[WPT] Fire Worker error events using ErrorEvent
Change-Id: I6c497324efd38fad1e017dcd6684da186d574b79
1 parent 7af5cc6 commit 918ca86

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

fetch/api/basic/block-mime-as-script.html

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
<script src="/resources/testharnessreport.js"></script>
66
<div></div>
77
<script>
8-
var noop = function() {};
8+
const noop = () => {};
9+
const expect_error = (e) => {
10+
assert_equals(e.constructor, Event);
11+
};
912

1013
["non-empty", "empty"].forEach(function(content) {
1114
["text/csv",
@@ -18,15 +21,41 @@
1821
"image/jpeg",
1922
"image/gif",
2023
"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+
2136
async_test(function(t) {
2237
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);
2440
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;
2742
document.body.appendChild(script);
2843
}, "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)");
3059
});
3160
});
3261

@@ -37,7 +66,7 @@
3766
script.onload = t.step_func_done(noop);
3867
script.src = "../resources/script-with-header.py?mime=text/" + test_case;
3968
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)");
4170
});
4271

4372
</script>

workers/Worker_script_mimetype.htm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
async_test(t => {
99
const worker = new Worker('./support/WorkerText.txt');
1010
worker.onmessage = t.unreached_func("Worker should not receive messages");
11-
worker.onerror = () => t.done();
11+
worker.onerror = t.step_func_done((e) => {
12+
assert_equals(e.constructor, ErrorEvent);
13+
});
1214
}, "HTTP(S) URLs which respond with text/plain MIME type must not work");
1315

1416
async_test(t => {
1517
const worker = new SharedWorker('./support/WorkerText.txt');
1618
worker.onmessage = t.unreached_func("Worker should not receive messages");
17-
worker.onerror = () => t.done();
19+
worker.onerror = t.step_func_done((e) => {
20+
assert_equals(e.constructor, ErrorEvent);
21+
});
1822
}, "HTTP(S) URLs which respond with text/plain MIME type must not work on SharedWorkers");
1923

2024
async_test(t => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
window.checkErrorArguments = args => {
22
assert_equals(args.length, 1);
3-
assert_equals(args[0].constructor, Event);
3+
assert_equals(args[0].constructor, ErrorEvent);
44
};

0 commit comments

Comments
 (0)