diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/tests/mochitest/general/workerStoragePrevented.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/tests/mochitest/general/workerStoragePrevented.js')
-rw-r--r-- | dom/tests/mochitest/general/workerStoragePrevented.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/dom/tests/mochitest/general/workerStoragePrevented.js b/dom/tests/mochitest/general/workerStoragePrevented.js new file mode 100644 index 000000000..93a81eb75 --- /dev/null +++ b/dom/tests/mochitest/general/workerStoragePrevented.js @@ -0,0 +1,61 @@ +// 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't access indexedDB +try { + indexedDB; + ok(false, "WORKER getting indexedDB should have thrown"); +} catch (e) { + ok(true, "WORKER getting indexedDB threw"); +} + +// Make sure that we can't access caches +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(false, "WORKER getting caches should not have thrown"); +} + +// Try to spawn an inner worker, and make sure that it also can't 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("workerStoragePrevented.js#inner"); + worker.addEventListener('message', function(e) { + if (e.data == "done") { + finishTest(); + return; + } + + ok(!e.data.match(/^FAILURE/), e.data + " (WORKER = workerStoragePrevented.js#inner)"); + }); +} |