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
|
<!DOCTYPE html>
<title>SharedWorker: WorkerOptions 'type'</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(() => {
const worker = new SharedWorker('resources/post-message-on-load-worker.js',
'default');
return new Promise(resolve => worker.port.onmessage = resolve)
.then(msg_event => assert_equals(msg_event.data, 'LOADED'));
}, 'Test worker construction with the default worker type.');
promise_test(() => {
const worker = new SharedWorker('resources/post-message-on-load-worker.js',
{ name: 'classic', type: 'classic' });
return new Promise(resolve => worker.port.onmessage = resolve)
.then(msg_event => assert_equals(msg_event.data, 'LOADED'));
}, 'Test worker construction with the "classic" worker type.');
promise_test(() => {
const worker = new SharedWorker('resources/post-message-on-load-worker.js',
{ name: 'module', type: 'module' });
return new Promise(resolve => worker.port.onmessage = resolve)
.then(msg_event => assert_equals(msg_event.data, 'LOADED'));
}, 'Test worker construction with the "module" worker type.');
test(() => {
assert_throws_js(
TypeError,
() => {
new SharedWorker('resources/post-message-on-load-worker.js',
{ name: 'blank', type : '' });
},
'Worker construction with an empty type should throw an exception');
}, 'Test worker construction with an empty worker type.');
test(() => {
assert_throws_js(
TypeError,
() => {
new SharedWorker('resources/post-message-on-load-worker.js',
{ name: 'unknown', type : 'unknown' });
},
'Worker construction with an unknown type should throw an exception');
}, 'Test worker construction with an unknown worker type.');
</script>
|