blob: d1314c8430337f34f3d4b9e7a6b8397b77608d8b (
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
|
function doXHR(uri) {
try {
var xhr = new XMLHttpRequest();
xhr.open("GET", uri);
xhr.send();
} catch(ex) {}
}
var sameBase = "http://mochi.test:8888/tests/dom/security/test/csp/file_CSP.sjs?testid=";
var crossBase = "http://example.com/tests/dom/security/test/csp/file_CSP.sjs?testid=";
onmessage = (e) => {
// Tests of nested worker
if (e.data.nested) {
if (e.data.inherited != "none") {
// Worker inherits CSP
new Worker(e.data.nested).postMessage({inherited : e.data.inherited});
}
else {
// Worker does not inherit CSP
new Worker("file_child_worker.js").postMessage({inherited : e.data.inherited});
}
return;
}
//Tests of top level worker
for (base of [sameBase, crossBase]) {
var prefix;
var suffix;
if (e.data.inherited != "none") {
// Top worker inherits CSP from owner document
prefix = base + "worker_inherited_";
suffix = base == sameBase ? "_good" : "_bad";
}
else {
// Top worker delivers CSP from HTTP header
prefix = base + "worker_";
suffix = base == sameBase ? "_same_bad" : "_cross_good";
}
doXHR(prefix + "xhr" + suffix);
fetch(prefix + "fetch" + suffix);
try {
if (e.data.inherited == "none") suffix = base == sameBase ? "_same_good" : "_cross_bad";
importScripts(prefix + "script" + suffix);
} catch(ex) {}
}
}
|