mirror of
https://github.com/servo/servo.git
synced 2025-07-21 22:33:41 +01:00
Workers created from Blobs inherit their CSP. Now we inherit the CSP and set the correct base API url. The base API url should be used when determining the report-uri endpoint. Otherwise, the blob URL would be used as a base, which is invalid and the report wouldn't be sent. Also create a helper method to concatenate two optionals of CSPList, which was used in several places. Part of #4577 Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
71 lines
2.4 KiB
JavaScript
Vendored
71 lines
2.4 KiB
JavaScript
Vendored
function message_from_port(port) {
|
|
return new Promise(resolve => {
|
|
port.onmessage = e => resolve(e.data);
|
|
});
|
|
}
|
|
|
|
promise_test(async t => {
|
|
const run_result = 'worker_OK_';
|
|
const blob_contents =
|
|
'self.counter = 0; self.onconnect = e => {++self.counter;' +
|
|
'e.source.postMessage("' + run_result + '" + self.counter); };';
|
|
const blob = new Blob([blob_contents]);
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
const worker1 = new SharedWorker(url);
|
|
const reply1 = await message_from_port(worker1.port);
|
|
assert_equals(reply1, run_result + '1');
|
|
const worker2 = new SharedWorker(url);
|
|
const reply2 = await message_from_port(worker2.port);
|
|
assert_equals(reply2, run_result + '2');
|
|
}, 'Creating a shared worker from a blob URL works.');
|
|
|
|
promise_test(async t => {
|
|
const run_result = 'worker_OK';
|
|
const blob_contents =
|
|
'self.onconnect = e => { e.source.postMessage("' + run_result + '"); };';
|
|
const blob = new Blob([blob_contents]);
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
const worker = new SharedWorker(url);
|
|
URL.revokeObjectURL(url);
|
|
|
|
const reply = await message_from_port(worker.port);
|
|
assert_equals(reply, run_result);
|
|
}, 'Creating a shared worker from a blob URL works immediately before revoking.');
|
|
|
|
promise_test(async t => {
|
|
const run_result = 'worker_OK_';
|
|
const blob_contents =
|
|
'self.counter = 0; self.onconnect = e => {++self.counter;' +
|
|
'e.source.postMessage("' + run_result + '" + self.counter); };';
|
|
const blob = new Blob([blob_contents]);
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
const worker1 = new SharedWorker(url);
|
|
URL.revokeObjectURL(url);
|
|
|
|
const reply1 = await message_from_port(worker1.port);
|
|
assert_equals(reply1, run_result + '1');
|
|
const worker2 = new SharedWorker(url);
|
|
const reply2 = await message_from_port(worker2.port);
|
|
assert_equals(reply2, run_result + '2');
|
|
}, 'Connecting to a shared worker on a revoked blob URL works.');
|
|
|
|
promise_test(async t => {
|
|
const run_result = false;
|
|
const blob_contents = `
|
|
let constructedRequest = false;
|
|
try {
|
|
new Request("./file.js");
|
|
constructedRequest = true;
|
|
} catch (e) {}
|
|
self.postMessage(constructedRequest);
|
|
`;
|
|
const blob = new Blob([blob_contents]);
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
const worker = new SharedWorker(url);
|
|
const reply = await message_from_port(worker);
|
|
assert_equals(reply, run_result, "Should not be able to resolve request with relative file path in blob");
|
|
}, 'Blob URLs should not resolve relative to document base URL.');
|