diff options
Diffstat (limited to '')
-rw-r--r-- | dom/quota/test/mochitest/helpers.js | 312 | ||||
-rw-r--r-- | dom/quota/test/mochitest/mochitest.toml | 18 | ||||
-rw-r--r-- | dom/quota/test/mochitest/test_simpledb.html | 21 | ||||
-rw-r--r-- | dom/quota/test/mochitest/test_storage_manager_persist_allow.html | 21 | ||||
-rw-r--r-- | dom/quota/test/mochitest/test_storage_manager_persist_deny.html | 21 | ||||
-rw-r--r-- | dom/quota/test/mochitest/test_storage_manager_persisted.html | 24 |
6 files changed, 417 insertions, 0 deletions
diff --git a/dom/quota/test/mochitest/helpers.js b/dom/quota/test/mochitest/helpers.js new file mode 100644 index 0000000000..a6f4ad56f7 --- /dev/null +++ b/dom/quota/test/mochitest/helpers.js @@ -0,0 +1,312 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// The path to the top level directory. +const depth = "../../../../"; + +var testGenerator; +var testHarnessGenerator; +var workerScriptPaths = []; + +loadScript("dom/quota/test/common/mochitest.js"); + +function loadScript(path) { + const url = new URL(depth + path, window.location.href); + SpecialPowers.Services.scriptloader.loadSubScript(url.href, this); +} + +function loadWorkerScript(path) { + const url = new URL(depth + path, window.location.href); + workerScriptPaths.push(url.href); +} + +function* testHarnessSteps() { + function nextTestHarnessStep(val) { + testHarnessGenerator.next(val); + } + + info("Enabling storage testing"); + + enableStorageTesting().then(nextTestHarnessStep); + yield undefined; + + info("Pushing preferences"); + + SpecialPowers.pushPrefEnv( + { + set: [["dom.storageManager.prompt.testing", true]], + }, + nextTestHarnessStep + ); + yield undefined; + + info("Clearing old databases"); + + clearAllDatabases(nextTestHarnessStep); + yield undefined; + + info("Running test in given scopes"); + + if (workerScriptPaths.length) { + info("Running test in a worker"); + + let workerScriptBlob = new Blob(["(" + workerScript.toString() + ")();"], { + type: "text/javascript", + }); + let workerScriptURL = URL.createObjectURL(workerScriptBlob); + + let worker = new Worker(workerScriptURL); + + worker.onerror = function (event) { + ok(false, "Worker had an error: " + event.message); + worker.terminate(); + nextTestHarnessStep(); + }; + + worker.onmessage = function (event) { + let message = event.data; + switch (message.op) { + case "ok": + ok(message.condition, message.name + " - " + message.diag); + break; + + case "todo": + todo(message.condition, message.name, message.diag); + break; + + case "info": + info(message.msg); + break; + + case "ready": + worker.postMessage({ op: "load", files: workerScriptPaths }); + break; + + case "loaded": + worker.postMessage({ op: "start" }); + break; + + case "done": + ok(true, "Worker finished"); + nextTestHarnessStep(); + break; + + case "clearAllDatabases": + clearAllDatabases(function () { + worker.postMessage({ op: "clearAllDatabasesDone" }); + }); + break; + + default: + ok( + false, + "Received a bad message from worker: " + JSON.stringify(message) + ); + nextTestHarnessStep(); + } + }; + + URL.revokeObjectURL(workerScriptURL); + + yield undefined; + + worker.terminate(); + worker = null; + + clearAllDatabases(nextTestHarnessStep); + yield undefined; + } + + info("Running test in main thread"); + + // Now run the test script in the main thread. + if (testSteps.constructor.name === "AsyncFunction") { + SimpleTest.registerCleanupFunction(async function () { + await requestFinished(clearAllDatabases()); + }); + + add_task(testSteps); + } else { + testGenerator = testSteps(); + testGenerator.next(); + + yield undefined; + } +} + +if (!window.runTest) { + window.runTest = function () { + SimpleTest.waitForExplicitFinish(); + testHarnessGenerator = testHarnessSteps(); + testHarnessGenerator.next(); + }; +} + +function finishTest() { + SimpleTest.executeSoon(function () { + clearAllDatabases(function () { + SimpleTest.finish(); + }); + }); +} + +function grabArgAndContinueHandler(arg) { + testGenerator.next(arg); +} + +function continueToNextStep() { + SimpleTest.executeSoon(function () { + testGenerator.next(); + }); +} + +function continueToNextStepSync() { + testGenerator.next(); +} + +function workerScript() { + "use strict"; + + self.testGenerator = null; + + self.repr = function (_thing_) { + if (typeof _thing_ == "undefined") { + return "undefined"; + } + + let str; + + try { + str = _thing_ + ""; + } catch (e) { + return "[" + typeof _thing_ + "]"; + } + + if (typeof _thing_ == "function") { + str = str.replace(/^\s+/, ""); + let idx = str.indexOf("{"); + if (idx != -1) { + str = str.substr(0, idx) + "{...}"; + } + } + + return str; + }; + + self.ok = function (_condition_, _name_, _diag_) { + self.postMessage({ + op: "ok", + condition: !!_condition_, + name: _name_, + diag: _diag_, + }); + }; + + self.is = function (_a_, _b_, _name_) { + let pass = _a_ == _b_; + let diag = pass ? "" : "got " + repr(_a_) + ", expected " + repr(_b_); + ok(pass, _name_, diag); + }; + + self.isnot = function (_a_, _b_, _name_) { + let pass = _a_ != _b_; + let diag = pass ? "" : "didn't expect " + repr(_a_) + ", but got it"; + ok(pass, _name_, diag); + }; + + self.todo = function (_condition_, _name_, _diag_) { + self.postMessage({ + op: "todo", + condition: !!_condition_, + name: _name_, + diag: _diag_, + }); + }; + + self.info = function (_msg_) { + self.postMessage({ op: "info", msg: _msg_ }); + }; + + self.executeSoon = function (_fun_) { + var channel = new MessageChannel(); + channel.port1.postMessage(""); + channel.port2.onmessage = function (event) { + _fun_(); + }; + }; + + self.finishTest = function () { + self.postMessage({ op: "done" }); + }; + + self.grabArgAndContinueHandler = function (_arg_) { + testGenerator.next(_arg_); + }; + + self.continueToNextStep = function () { + executeSoon(function () { + testGenerator.next(); + }); + }; + + self.continueToNextStepSync = function () { + testGenerator.next(); + }; + + self._clearAllDatabasesCallback = undefined; + self.clearAllDatabases = function (_callback_) { + self._clearAllDatabasesCallback = _callback_; + self.postMessage({ op: "clearAllDatabases" }); + }; + + self.onerror = function (_message_, _file_, _line_) { + ok( + false, + "Worker: uncaught exception [" + + _file_ + + ":" + + _line_ + + "]: '" + + _message_ + + "'" + ); + self.finishTest(); + self.close(); + return true; + }; + + self.onmessage = function (_event_) { + let message = _event_.data; + switch (message.op) { + case "load": + info("Worker: loading " + JSON.stringify(message.files)); + self.importScripts(message.files); + self.postMessage({ op: "loaded" }); + break; + + case "start": + executeSoon(function () { + info("Worker: starting tests"); + testGenerator = testSteps(); + testGenerator.next(); + }); + break; + + case "clearAllDatabasesDone": + info("Worker: all databases are cleared"); + if (self._clearAllDatabasesCallback) { + self._clearAllDatabasesCallback(); + } + break; + + default: + throw new Error( + "Received a bad message from parent: " + JSON.stringify(message) + ); + } + }; + + self.postMessage({ op: "ready" }); +} diff --git a/dom/quota/test/mochitest/mochitest.toml b/dom/quota/test/mochitest/mochitest.toml new file mode 100644 index 0000000000..ddc3204b37 --- /dev/null +++ b/dom/quota/test/mochitest/mochitest.toml @@ -0,0 +1,18 @@ +[DEFAULT] +support-files = ["helpers.js"] + +["test_simpledb.html"] +skip-if = [ + "http3", + "http2", +] + +["test_storage_manager_persist_allow.html"] +fail-if = ["xorigin"] +scheme = "https" + +["test_storage_manager_persist_deny.html"] +scheme = "https" + +["test_storage_manager_persisted.html"] +scheme = "https" diff --git a/dom/quota/test/mochitest/test_simpledb.html b/dom/quota/test/mochitest/test_simpledb.html new file mode 100644 index 0000000000..29ca8be65e --- /dev/null +++ b/dom/quota/test/mochitest/test_simpledb.html @@ -0,0 +1,21 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<html> +<head> + <title>SimpleDB Test</title> + + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + + <script type="text/javascript" src="helpers.js"></script> + <script type="text/javascript"> + loadScript("dom/quota/test/common/test_simpledb.js"); + </script> + +</head> + +<body onload="runTest();"></body> + +</html> diff --git a/dom/quota/test/mochitest/test_storage_manager_persist_allow.html b/dom/quota/test/mochitest/test_storage_manager_persist_allow.html new file mode 100644 index 0000000000..8477630f21 --- /dev/null +++ b/dom/quota/test/mochitest/test_storage_manager_persist_allow.html @@ -0,0 +1,21 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<html> +<head> + <title>Allow Persist Prompt for StorageManager</title> + + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + + <script type="text/javascript" src="helpers.js"></script> + <script type="text/javascript"> + loadScript("dom/quota/test/common/test_storage_manager_persist_allow.js"); + </script> + +</head> + +<body onload="runTest();"></body> + +</html> diff --git a/dom/quota/test/mochitest/test_storage_manager_persist_deny.html b/dom/quota/test/mochitest/test_storage_manager_persist_deny.html new file mode 100644 index 0000000000..2b0fab4423 --- /dev/null +++ b/dom/quota/test/mochitest/test_storage_manager_persist_deny.html @@ -0,0 +1,21 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<html> +<head> + <title>Deny Persist Prompt for StorageManager</title> + + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + + <script type="text/javascript" src="helpers.js"></script> + <script type="text/javascript"> + loadScript("dom/quota/test/common/test_storage_manager_persist_deny.js"); + </script> + +</head> + +<body onload="runTest();"></body> + +</html> diff --git a/dom/quota/test/mochitest/test_storage_manager_persisted.html b/dom/quota/test/mochitest/test_storage_manager_persisted.html new file mode 100644 index 0000000000..6e03f33e2d --- /dev/null +++ b/dom/quota/test/mochitest/test_storage_manager_persisted.html @@ -0,0 +1,24 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<html> +<head> + <title>Storage Manager Persisted Test</title> + + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + + <script type="text/javascript" src="helpers.js"></script> + <script type="text/javascript"> + const path = "dom/quota/test/common/test_storage_manager_persisted.js"; + + loadScript(path); + loadWorkerScript(path); + </script> + +</head> + +<body onload="runTest();"></body> + +</html> |