summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/workers/Worker_script_mimetype.htm
blob: d2278d3717c2f0c57673c220da49a07d8251d0d5 (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
<!DOCTYPE html>
<title>Worker constructor with wrong MIME type scripts</title>
<meta charset="utf-8">
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
async_test(t => {
  const worker = new Worker('./support/WorkerText.txt');
  worker.onmessage = t.unreached_func("Worker should not receive messages");
  worker.onerror = () => t.done();
}, "HTTP(S) URLs which respond with text/plain MIME type must not work");

async_test(t => {
  const worker = new SharedWorker('./support/WorkerText.txt');
  worker.onmessage = t.unreached_func("Worker should not receive messages");
  worker.onerror = () => t.done();
}, "HTTP(S) URLs which respond with text/plain MIME type must not work on SharedWorkers");

async_test(t => {
  const url = URL.createObjectURL(new Blob(['postMessage("PASS")'])); // no MIME type parameter
  const worker = new Worker(url);
  worker.onmessage = () => t.done();
  worker.onerror = t.unreached_func("Worker should not error");
}, "blob: URLs should load, despite no MIME type for the backing Blob");

async_test(t => {
  const url = URL.createObjectURL(new Blob(['postMessage("PASS")'], { type: 'text/plain' }));
  const worker = new Worker(url);
  worker.onmessage = () => t.done();
  worker.onerror = t.unreached_func("Worker should not error");
}, "blob: URLs should load, despite the wrong MIME type for the backing Blob");

async_test(t => {
  const url = `data:text/plain,postMessage("PASS");`
  const worker = new Worker(url);
  worker.onmessage = () => t.done();
  worker.onerror = t.unreached_func("Worker should not error");
}, "data: URLs should load, despite the wrong MIME type");

</script>