blob: b2a9d81a27ad9e7dd8c979a5b22a2f1249d5881b (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_shared_array_buffer_worker() {
const extension_description = {
isPrivileged: null,
async background() {
browser.test.onMessage.addListener(async isPrivileged => {
const worker = new Worker("worker.js");
worker.isPrivileged = isPrivileged;
worker.onmessage = function (e) {
const msg = `${
this.isPrivileged
? "privileged addon can"
: "non-privileged addon can't"
} instantiate a SharedArrayBuffer
in a worker`;
if (e.data === this.isPrivileged) {
browser.test.succeed(msg);
} else {
browser.test.fail(msg);
}
browser.test.sendMessage("test-sab-worker:done");
};
});
},
files: {
"worker.js": function () {
try {
new SharedArrayBuffer(1);
this.postMessage(true);
} catch (e) {
this.postMessage(false);
}
},
},
};
// This test attempts to verify that a worker inside a privileged addon
// is allowed to instantiate a SharedArrayBuffer
extension_description.isPrivileged = true;
let extension = ExtensionTestUtils.loadExtension(extension_description);
await extension.startup();
extension.sendMessage(extension_description.isPrivileged);
await extension.awaitMessage("test-sab-worker:done");
await extension.unload();
// This test attempts to verify that a worker inside a non privileged addon
// is not allowed to instantiate a SharedArrayBuffer
extension_description.isPrivileged = false;
extension = ExtensionTestUtils.loadExtension(extension_description);
await extension.startup();
extension.sendMessage(extension_description.isPrivileged);
await extension.awaitMessage("test-sab-worker:done");
await extension.unload();
});
add_task(async function test_shared_array_buffer_content() {
let extension_description = {
isPrivileged: null,
async background() {
browser.test.onMessage.addListener(async isPrivileged => {
let succeed = null;
try {
new SharedArrayBuffer(1);
succeed = true;
} catch (e) {
succeed = false;
} finally {
const msg = `${
isPrivileged ? "privileged addon can" : "non-privileged addon can't"
} instantiate a SharedArrayBuffer
in the main thread`;
if (succeed === isPrivileged) {
browser.test.succeed(msg);
} else {
browser.test.fail(msg);
}
browser.test.sendMessage("test-sab-content:done");
}
});
},
};
// This test attempts to verify that a non privileged addon
// is allowed to instantiate a sharedarraybuffer
extension_description.isPrivileged = true;
let extension = ExtensionTestUtils.loadExtension(extension_description);
await extension.startup();
extension.sendMessage(extension_description.isPrivileged);
await extension.awaitMessage("test-sab-content:done");
await extension.unload();
// This test attempts to verify that a non privileged addon
// is not allowed to instantiate a sharedarraybuffer
extension_description.isPrivileged = false;
extension = ExtensionTestUtils.loadExtension(extension_description);
await extension.startup();
extension.sendMessage(extension_description.isPrivileged);
await extension.awaitMessage("test-sab-content:done");
await extension.unload();
});
|