diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/tests/mochitest/general/workerStorageAllowed.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/tests/mochitest/general/workerStorageAllowed.js')
-rw-r--r-- | dom/tests/mochitest/general/workerStorageAllowed.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/dom/tests/mochitest/general/workerStorageAllowed.js b/dom/tests/mochitest/general/workerStorageAllowed.js new file mode 100644 index 0000000000..89e0a4b9ce --- /dev/null +++ b/dom/tests/mochitest/general/workerStorageAllowed.js @@ -0,0 +1,78 @@ +// Unfortunately, workers can't share the code from storagePermissionsUtils. +// These are basic mechanisms for communicating to the test runner. + +function ok(condition, text) { + if (!condition) { + self.postMessage("FAILURE: " + text); + } else { + self.postMessage(text); + } +} + +function finishTest() { + self.postMessage("done"); + self.close(); +} + +// Workers don't have access to localstorage or sessionstorage +ok(typeof self.localStorage == "undefined", "localStorage should be undefined"); +ok( + typeof self.sessionStorage == "undefined", + "sessionStorage should be undefined" +); + +// Make sure that we can access indexedDB +try { + indexedDB; + ok(true, "WORKER getting indexedDB didn't throw"); +} catch (e) { + ok(false, "WORKER getting indexedDB should not throw"); +} + +// Make sure that we can access caches +try { + var promise = caches.keys(); + ok(true, "WORKER getting caches didn't throw"); + + promise.then( + function () { + ok(location.protocol == "https:", "WORKER The promise was not rejected"); + workerTest(); + }, + function () { + ok( + location.protocol !== "https:", + "WORKER The promise should not have been 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 can also access storage +function workerTest() { + if (location.hash == "#inner") { + // Don't recurse infinitely, if we are the inner worker, don't spawn another + finishTest(); + return; + } + // Create the inner worker, and listen for test messages from it + var worker = new Worker("workerStorageAllowed.js#inner"); + worker.addEventListener("message", function (e) { + if (e.data == "done") { + finishTest(); + return; + } + + ok( + !e.data.match(/^FAILURE/), + e.data + " (WORKER = workerStorageAllowed.js#inner)" + ); + }); +} |