From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- .../mochitest/general/workerStoragePrevented.js | 114 +++++++++++++++------ 1 file changed, 85 insertions(+), 29 deletions(-) (limited to 'dom/tests/mochitest/general/workerStoragePrevented.js') diff --git a/dom/tests/mochitest/general/workerStoragePrevented.js b/dom/tests/mochitest/general/workerStoragePrevented.js index 467cc09113..7d232d65df 100644 --- a/dom/tests/mochitest/general/workerStoragePrevented.js +++ b/dom/tests/mochitest/general/workerStoragePrevented.js @@ -21,40 +21,94 @@ ok( "sessionStorage should be undefined" ); -// Make sure that we can't access indexedDB +// Make sure that we can access indexedDB handle try { indexedDB; - ok(false, "WORKER getting indexedDB should have thrown"); + ok(true, "WORKER getting indexedDB didn't throw"); } catch (e) { - ok(true, "WORKER getting indexedDB threw"); + ok(false, "WORKER getting indexedDB threw"); +} + +// Make sure that we cannot access indexedDB methods +idbOpenTest(); + +// Make sure that we can't access indexedDB deleteDatabase +function idbDeleteTest() { + try { + indexedDB.deleteDatabase("door"); + ok(false, "WORKER deleting indexedDB database succeeded"); + } catch (e) { + ok(true, "WORKER deleting indexedDB database failed"); + ok( + e.name == "SecurityError", + "WORKER deleting indexedDB database threw a security error" + ); + } finally { + cacheTest(); + } +} + +// Make sure that we can't access indexedDB databases +function idbDatabasesTest() { + indexedDB + .databases() + .then(() => { + ok(false, "WORKER querying indexedDB databases succeeded"); + }) + .catch(e => { + ok(true, "WORKER querying indexedDB databases failed"); + ok( + e.name == "SecurityError", + "WORKER querying indexedDB databases threw a security error" + ); + }) + .finally(idbDeleteTest); +} + +// Make sure that we can't access indexedDB open +function idbOpenTest() { + try { + indexedDB.open("door"); + ok(false, "WORKER opening indexedDB database succeeded"); + } catch (e) { + ok(true, "WORKER opening indexedDB database failed"); + ok( + e.name == "SecurityError", + "WORKER opening indexedDB database threw a security error" + ); + } finally { + idbDatabasesTest(); + } } // Make sure that we can't access caches -try { - var promise = caches.keys(); - ok(true, "WORKER getting caches didn't throw"); +function cacheTest() { + try { + var promise = caches.keys(); + ok(true, "WORKER getting caches didn't throw"); - promise.then( - function () { - ok(false, "WORKER The promise should have rejected"); - workerTest(); - }, - function () { - ok(true, "WORKER The promise was rejected"); - workerTest(); - } - ); -} catch (e) { - ok( - location.protocol !== "https:", - "WORKER getting caches should not have thrown" - ); - workerTest(); + promise.then( + function () { + ok(false, "WORKER The promise should have rejected"); + workerTest(); + }, + function () { + ok(true, "WORKER The promise was rejected"); + workerTest(); + } + ); + } catch (e) { + ok( + location.protocol !== "https:", + "WORKER getting caches should not have thrown" + ); + workerTest(); + } } // Try to spawn an inner worker, and make sure that it also can't access storage function workerTest() { - if (location.hash == "#inner") { + if (location.hash != "#outer") { // Don't recurse infinitely, if we are the inner worker, don't spawn another finishTest(); return; @@ -62,14 +116,16 @@ function workerTest() { // Create the inner worker, and listen for test messages from it var worker = new Worker("workerStoragePrevented.js#inner"); worker.addEventListener("message", function (e) { - if (e.data == "done") { + const isFail = e.data.match(/^FAILURE/); + ok(!isFail, e.data + " (WORKER = workerStoragePrevented.js#inner)"); + + if (e.data == "done" || isFail) { finishTest(); - return; } + }); + worker.addEventListener("error", function (e) { + ok(false, e.data + " (WORKER = workerStoragePrevented.js#inner)"); - ok( - !e.data.match(/^FAILURE/), - e.data + " (WORKER = workerStoragePrevented.js#inner)" - ); + finishTest(); }); } -- cgit v1.2.3