summaryrefslogtreecommitdiffstats
path: root/dom/quota/test/modules/content/worker
diff options
context:
space:
mode:
Diffstat (limited to 'dom/quota/test/modules/content/worker')
-rw-r--r--dom/quota/test/modules/content/worker/.eslintrc.js21
-rw-r--r--dom/quota/test/modules/content/worker/Assert.js22
-rw-r--r--dom/quota/test/modules/content/worker/ModuleLoader.js52
-rw-r--r--dom/quota/test/modules/content/worker/Utils.js27
-rw-r--r--dom/quota/test/modules/content/worker/UtilsChild.mjs22
-rw-r--r--dom/quota/test/modules/content/worker/head.js55
6 files changed, 199 insertions, 0 deletions
diff --git a/dom/quota/test/modules/content/worker/.eslintrc.js b/dom/quota/test/modules/content/worker/.eslintrc.js
new file mode 100644
index 0000000000..a62b649451
--- /dev/null
+++ b/dom/quota/test/modules/content/worker/.eslintrc.js
@@ -0,0 +1,21 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+"use strict";
+
+module.exports = {
+ env: {
+ worker: true,
+ },
+
+ overrides: [
+ {
+ files: ["Assert.js", "ModuleLoader.js", "Utils.js"],
+ parserOptions: {
+ sourceType: "script",
+ },
+ },
+ ],
+};
diff --git a/dom/quota/test/modules/content/worker/Assert.js b/dom/quota/test/modules/content/worker/Assert.js
new file mode 100644
index 0000000000..7c7e2683ea
--- /dev/null
+++ b/dom/quota/test/modules/content/worker/Assert.js
@@ -0,0 +1,22 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const Assert = {
+ ok(value, message) {
+ postMessage({
+ op: "ok",
+ value: !!value,
+ message,
+ });
+ },
+ equal(a, b, message) {
+ postMessage({
+ op: "is",
+ a,
+ b,
+ message,
+ });
+ },
+};
diff --git a/dom/quota/test/modules/content/worker/ModuleLoader.js b/dom/quota/test/modules/content/worker/ModuleLoader.js
new file mode 100644
index 0000000000..5354c26e34
--- /dev/null
+++ b/dom/quota/test/modules/content/worker/ModuleLoader.js
@@ -0,0 +1,52 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+function ModuleLoader(base, depth) {
+ const modules = {};
+
+ const require = async function (id) {
+ if (modules[id]) {
+ return modules[id].exported_symbols;
+ }
+
+ const url = new URL(depth + id, base);
+
+ const module = Object.create(null, {
+ exported_symbols: {
+ configurable: false,
+ enumerable: true,
+ value: Object.create(null),
+ writable: true,
+ },
+ });
+
+ modules[id] = module;
+
+ const xhr = new XMLHttpRequest();
+ xhr.open("GET", url.href, false);
+ xhr.responseType = "text";
+ xhr.send();
+
+ let source = xhr.responseText;
+
+ let code = new Function(
+ "require_module",
+ "exported_symbols",
+ `eval(arguments[2] + "\\n//# sourceURL=" + arguments[3] + "\\n")`
+ );
+ code(require, module.exported_symbols, source, url.href);
+
+ return module.exported_symbols;
+ };
+
+ const returnObj = {
+ require: {
+ enumerable: true,
+ value: require,
+ },
+ };
+
+ return Object.create(null, returnObj);
+}
diff --git a/dom/quota/test/modules/content/worker/Utils.js b/dom/quota/test/modules/content/worker/Utils.js
new file mode 100644
index 0000000000..0f8888fc00
--- /dev/null
+++ b/dom/quota/test/modules/content/worker/Utils.js
@@ -0,0 +1,27 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+let UtilsChild;
+
+async function ensureUtilsChild() {
+ if (UtilsChild) {
+ return;
+ }
+
+ const { UtilsChild: importedUtilsChild } = await import(
+ "/tests/dom/quota/test/modules/worker/UtilsChild.mjs"
+ );
+
+ UtilsChild = importedUtilsChild;
+}
+
+const Utils = {
+ async getCachedOriginUsage() {
+ await ensureUtilsChild();
+
+ const result = await UtilsChild.getCachedOriginUsage();
+ return result;
+ },
+};
diff --git a/dom/quota/test/modules/content/worker/UtilsChild.mjs b/dom/quota/test/modules/content/worker/UtilsChild.mjs
new file mode 100644
index 0000000000..db5757bff0
--- /dev/null
+++ b/dom/quota/test/modules/content/worker/UtilsChild.mjs
@@ -0,0 +1,22 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+export const UtilsChild = {
+ async getCachedOriginUsage() {
+ postMessage({
+ moduleName: "UtilsParent",
+ objectName: "UtilsParent",
+ op: "getCachedOriginUsage",
+ });
+
+ return new Promise(function (resolve) {
+ addEventListener("message", async function onMessage(event) {
+ removeEventListener("message", onMessage);
+ const data = event.data;
+ resolve(data);
+ });
+ });
+ },
+};
diff --git a/dom/quota/test/modules/content/worker/head.js b/dom/quota/test/modules/content/worker/head.js
new file mode 100644
index 0000000000..ab7a916d22
--- /dev/null
+++ b/dom/quota/test/modules/content/worker/head.js
@@ -0,0 +1,55 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const Cr = {
+ NS_ERROR_NOT_IMPLEMENTED: 2147500033,
+};
+
+function add_task(func) {
+ if (!add_task.tasks) {
+ add_task.tasks = [];
+ add_task.index = 0;
+ }
+
+ add_task.tasks.push(func);
+}
+
+addEventListener("message", async function onMessage(event) {
+ function info(message) {
+ postMessage({ op: "info", message });
+ }
+
+ function executeSoon(callback) {
+ const channel = new MessageChannel();
+ channel.port1.postMessage("");
+ channel.port2.onmessage = function () {
+ callback();
+ };
+ }
+
+ function runNextTest() {
+ if (add_task.index < add_task.tasks.length) {
+ const task = add_task.tasks[add_task.index++];
+ info("add_task | Entering test " + task.name);
+ task()
+ .then(function () {
+ executeSoon(runNextTest);
+ info("add_task | Leaving test " + task.name);
+ })
+ .catch(function (ex) {
+ postMessage({ op: "failure", message: "" + ex });
+ });
+ } else {
+ postMessage({ op: "finish" });
+ }
+ }
+
+ removeEventListener("message", onMessage);
+
+ const data = event.data;
+ importScripts(...data);
+
+ executeSoon(runNextTest);
+});