summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'js/xpconnect/tests/unit')
-rw-r--r--js/xpconnect/tests/unit/ReturnCodeChild.jsm51
-rw-r--r--js/xpconnect/tests/unit/es6module_devtoolsLoader.sys.mjs91
-rw-r--r--js/xpconnect/tests/unit/import_shared_in_worker.js10
-rw-r--r--js/xpconnect/tests/unit/lazy_shared_in_worker.js14
-rw-r--r--js/xpconnect/tests/unit/test_defineESModuleGetters_options.js18
-rw-r--r--js/xpconnect/tests/unit/test_defineESModuleGetters_options_worker.js1
-rw-r--r--js/xpconnect/tests/unit/test_import_devtools_loader.js28
-rw-r--r--js/xpconnect/tests/unit/test_import_global.js8
-rw-r--r--js/xpconnect/tests/unit/test_import_global_worker.js1
-rw-r--r--js/xpconnect/tests/unit/test_returncode.js4
-rw-r--r--js/xpconnect/tests/unit/xpcshell.toml1
11 files changed, 106 insertions, 121 deletions
diff --git a/js/xpconnect/tests/unit/ReturnCodeChild.jsm b/js/xpconnect/tests/unit/ReturnCodeChild.jsm
deleted file mode 100644
index bf74453969..0000000000
--- a/js/xpconnect/tests/unit/ReturnCodeChild.jsm
+++ /dev/null
@@ -1,51 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-var EXPORTED_SYMBOLS = ["ReturnCodeChild"];
-
-function xpcWrap(obj, iface) {
- let ifacePointer = Cc[
- "@mozilla.org/supports-interface-pointer;1"
- ].createInstance(Ci.nsISupportsInterfacePointer);
-
- ifacePointer.data = obj;
- return ifacePointer.data.QueryInterface(iface);
-}
-
-var ReturnCodeChild = {
- QueryInterface: ChromeUtils.generateQI(["nsIXPCTestReturnCodeChild"]),
-
- doIt(behaviour) {
- switch (behaviour) {
- case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_THROW:
- throw(new Error("a requested error"));
- case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_SUCCESS:
- return;
- case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_RESULTCODE:
- Components.returnCode = Cr.NS_ERROR_FAILURE;
- return;
- case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_NEST_RESULTCODES:
- // Use xpconnect to create another instance of *this* component and
- // call that. This way we have crossed the xpconnect bridge twice.
-
- // We set *our* return code early - this should be what is returned
- // to our caller, even though our "inner" component will set it to
- // a different value that we will see (but our caller should not)
- Components.returnCode = Cr.NS_ERROR_UNEXPECTED;
- // call the child asking it to do the .returnCode set.
- let sub = xpcWrap(ReturnCodeChild, Ci.nsIXPCTestReturnCodeChild);
- let childResult = Cr.NS_OK;
- try {
- sub.doIt(Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_RESULTCODE);
- } catch (ex) {
- childResult = ex.result;
- }
- // write it to the console so the test can check it.
- let consoleService = Cc["@mozilla.org/consoleservice;1"]
- .getService(Ci.nsIConsoleService);
- consoleService.logStringMessage("nested child returned " + childResult);
- return;
- }
- }
-};
diff --git a/js/xpconnect/tests/unit/es6module_devtoolsLoader.sys.mjs b/js/xpconnect/tests/unit/es6module_devtoolsLoader.sys.mjs
index c7de54c82f..c8262f5f5c 100644
--- a/js/xpconnect/tests/unit/es6module_devtoolsLoader.sys.mjs
+++ b/js/xpconnect/tests/unit/es6module_devtoolsLoader.sys.mjs
@@ -7,23 +7,88 @@ export function increment() {
import { object } from "resource://test/es6module_devtoolsLoader.js";
export const importedObject = object;
-const importTrue = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { loadInDevToolsLoader : true });
-export const importESModuleTrue = importTrue.object;
+const importDevTools = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { global: "devtools" });
+export const importESModuleDevTools = importDevTools.object;
-const importFalse = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { loadInDevToolsLoader : false });
-export const importESModuleFalse = importFalse.object;
+const importShared = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { global: "shared" });
+export const importESModuleShared = importShared.object;
-const importNull = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", {});
-export const importESModuleNull = importNull.object;
+const importCurrent = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { global: "current" });
+export const importESModuleCurrent = importCurrent.object;
-const importNull2 = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js");
-export const importESModuleNull2 = importNull2.object;
+const importContextual = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { global: "contextual" });
+export const importESModuleContextual = importContextual.object;
-const lazy = {};
-ChromeUtils.defineESModuleGetters(lazy, {
+let caught = false;
+try {
+ ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js");
+} catch (e) {
+ caught = true;
+}
+export const importESModuleNoOptionFailed1 = caught;
+
+caught = false;
+try {
+ ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", {});
+} catch (e) {
+ caught = true;
+}
+export const importESModuleNoOptionFailed2 = caught;
+
+const lazyDevTools = {};
+ChromeUtils.defineESModuleGetters(lazyDevTools, {
+ object: "resource://test/es6module_devtoolsLoader.js",
+}, { global: "devtools" });
+
+export function importLazyDevTools() {
+ return lazyDevTools.object;
+}
+
+const lazyShared = {};
+ChromeUtils.defineESModuleGetters(lazyShared, {
+ object: "resource://test/es6module_devtoolsLoader.js",
+}, { global: "shared" });
+
+export function importLazyShared() {
+ return lazyShared.object;
+}
+
+const lazyCurrent = {};
+ChromeUtils.defineESModuleGetters(lazyCurrent, {
+ object: "resource://test/es6module_devtoolsLoader.js",
+}, { global: "current" });
+
+export function importLazyCurrent() {
+ return lazyCurrent.object;
+}
+
+const lazyContextual = {};
+ChromeUtils.defineESModuleGetters(lazyContextual, {
object: "resource://test/es6module_devtoolsLoader.js",
-});
+}, { global: "contextual" });
+
+export function importLazyContextual() {
+ return lazyContextual.object;
+}
+
+caught = false;
+try {
+ let lazy = {};
+ ChromeUtils.defineESModuleGetters({}, {
+ object: "resource://test/es6module_devtoolsLoader.js",
+ });
+} catch (e) {
+ caught = true;
+}
+export const importLazyNoOptionFailed1 = caught;
-export function importLazy() {
- return lazy.object;
+caught = false;
+try {
+ let lazy = {};
+ ChromeUtils.defineESModuleGetters({}, {
+ object: "resource://test/es6module_devtoolsLoader.js",
+ }, {});
+} catch (e) {
+ caught = true;
}
+export const importLazyNoOptionFailed2 = caught;
diff --git a/js/xpconnect/tests/unit/import_shared_in_worker.js b/js/xpconnect/tests/unit/import_shared_in_worker.js
index bc92fe26a6..170254fb21 100644
--- a/js/xpconnect/tests/unit/import_shared_in_worker.js
+++ b/js/xpconnect/tests/unit/import_shared_in_worker.js
@@ -24,13 +24,5 @@ onmessage = event => {
caught3 = true;
}
- let caught4 = false;
- try {
- ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
- loadInDevToolsLoader: true,
- });
- } catch (e) {
- caught4 = true;
- }
- postMessage({ caught1, caught2, caught3, caught4 });
+ postMessage({ caught1, caught2, caught3 });
};
diff --git a/js/xpconnect/tests/unit/lazy_shared_in_worker.js b/js/xpconnect/tests/unit/lazy_shared_in_worker.js
index 148cdefb3e..91114e61c4 100644
--- a/js/xpconnect/tests/unit/lazy_shared_in_worker.js
+++ b/js/xpconnect/tests/unit/lazy_shared_in_worker.js
@@ -36,17 +36,5 @@ onmessage = event => {
caught3 = true;
}
- let caught4 = false;
- try {
- const lazy = {};
- ChromeUtils.defineESModuleGetters(lazy, {
- obj: "resource://test/esmified-1.sys.mjs"
- }, {
- loadInDevToolsLoader: true,
- });
- lazy.obj;
- } catch (e) {
- caught4 = true;
- }
- postMessage({ caught1, caught2, caught3, caught4 });
+ postMessage({ caught1, caught2, caught3 });
};
diff --git a/js/xpconnect/tests/unit/test_defineESModuleGetters_options.js b/js/xpconnect/tests/unit/test_defineESModuleGetters_options.js
index 11d282e511..b01580dfa1 100644
--- a/js/xpconnect/tests/unit/test_defineESModuleGetters_options.js
+++ b/js/xpconnect/tests/unit/test_defineESModuleGetters_options.js
@@ -25,29 +25,21 @@ add_task(async function testShared() {
});
add_task(async function testDevTools() {
- const lazy1 = {};
- const lazy2 = {};
-
- ChromeUtils.defineESModuleGetters(lazy1, {
- GetX: "resource://test/esm_lazy-1.sys.mjs",
- }, {
- loadInDevToolsLoader: true,
- });
+ const lazy = {};
- ChromeUtils.defineESModuleGetters(lazy2, {
+ ChromeUtils.defineESModuleGetters(lazy, {
GetX: "resource://test/esm_lazy-1.sys.mjs",
}, {
global: "devtools",
});
- Assert.equal(lazy1.GetX, lazy2.GetX);
+ lazy.GetX; // delazify before import.
const ns = ChromeUtils.importESModule("resource://test/esm_lazy-1.sys.mjs", {
- loadInDevToolsLoader: true,
+ global: "devtools",
});
- Assert.equal(ns.GetX, lazy1.GetX);
- Assert.equal(ns.GetX, lazy2.GetX);
+ Assert.equal(ns.GetX, lazy.GetX);
});
add_task(async function testSandbox() {
diff --git a/js/xpconnect/tests/unit/test_defineESModuleGetters_options_worker.js b/js/xpconnect/tests/unit/test_defineESModuleGetters_options_worker.js
index f1eab22d2b..a21030ac6a 100644
--- a/js/xpconnect/tests/unit/test_defineESModuleGetters_options_worker.js
+++ b/js/xpconnect/tests/unit/test_defineESModuleGetters_options_worker.js
@@ -29,5 +29,4 @@ add_task(async function testSharedInWorker() {
Assert.equal(result.caught1, true);
Assert.equal(result.caught2, true);
Assert.equal(result.caught3, true);
- Assert.equal(result.caught4, true);
});
diff --git a/js/xpconnect/tests/unit/test_import_devtools_loader.js b/js/xpconnect/tests/unit/test_import_devtools_loader.js
index d7e6fe42f6..f3518ca301 100644
--- a/js/xpconnect/tests/unit/test_import_devtools_loader.js
+++ b/js/xpconnect/tests/unit/test_import_devtools_loader.js
@@ -39,19 +39,27 @@ add_task(async function testDevToolsModuleLoader() {
dbg.addDebuggee(nsGlobal);
Assert.ok(true, "The global is accepted by the Debugger API");
- const ns1 = ChromeUtils.importESModule(ESM_URL, { loadInDevToolsLoader : false });
- Assert.equal(ns1, ns, "Passing loadInDevToolsLoader=false from the shared JSM global is equivalent to regular importESModule");
+ const ns1 = ChromeUtils.importESModule(ESM_URL, { global: "shared" });
+ Assert.equal(ns1, ns, "Passing global: 'shared' from the shared JSM global is equivalent to regular importESModule");
info("Test importing in the devtools loader");
- const ns2 = ChromeUtils.importESModule(ESM_URL, { loadInDevToolsLoader: true });
+ const ns2 = ChromeUtils.importESModule(ESM_URL, { global: "devtools" });
Assert.equal(ns2.x, 0, "We get a new module instance with a new incremented number");
Assert.notEqual(ns2, ns, "We imported a new instance of the module");
Assert.notEqual(ns2.importedObject, ns.importedObject, "The two module instances expose distinct objects");
- Assert.equal(ns2.importESModuleTrue, ns2.importedObject, "When using loadInDevToolsLoader:true from a devtools global, we keep loading in the same loader");
- Assert.equal(ns2.importESModuleNull, ns2.importedObject, "When having an undefined loadInDevToolsLoader from a devtools global, we keep loading in the same loader");
- Assert.equal(ns2.importESModuleNull2, ns2.importedObject, "When having no optional argument at all, we keep loading in the same loader");
- Assert.equal(ns2.importESModuleFalse, ns.importedObject, "When passing an explicit loadInDevToolsLoader:false, we load in the shared global, even from a devtools global");
- Assert.equal(ns2.importLazy(), ns2.importedObject, "ChromeUtils.defineESModuleGetters imports will follow the contextual loader");
+ Assert.equal(ns2.importESModuleDevTools, ns2.importedObject, "When using global: 'devtools' from a devtools global, we keep loading in the same loader");
+ Assert.equal(ns2.importESModuleCurrent, ns2.importedObject, "When using global: 'current' from a devtools global, we keep loading in the same loader");
+ Assert.equal(ns2.importESModuleContextual, ns2.importedObject, "When using global: 'contextual' from a devtools global, we keep loading in the same loader");
+ Assert.ok(ns2.importESModuleNoOptionFailed1, "global option is required in DevTools global");
+ Assert.ok(ns2.importESModuleNoOptionFailed2, "global option is required in DevTools global");
+ Assert.equal(ns2.importESModuleShared, ns.importedObject, "When passing global: 'shared', we load in the shared global, even from a devtools global");
+
+ Assert.equal(ns2.importLazyDevTools(), ns2.importedObject, "When using global: 'devtools' from a devtools global, we keep loading in the same loader");
+ Assert.equal(ns2.importLazyCurrent(), ns2.importedObject, "When using global: 'current' from a devtools global, we keep loading in the same loader");
+ Assert.equal(ns2.importLazyContextual(), ns2.importedObject, "When using global: 'contextual' from a devtools global, we keep loading in the same loader");
+ Assert.ok(ns2.importLazyNoOptionFailed1, "global option is required in DevTools global");
+ Assert.ok(ns2.importLazyNoOptionFailed2, "global option is required in DevTools global");
+ Assert.equal(ns2.importLazyShared(), ns.importedObject, "When passing global: 'shared', we load in the shared global, even from a devtools global");
info("When using the devtools loader, we load in a distinct global, but the same compartment");
const ns2Global = Cu.getGlobalForObject(ns2);
@@ -63,12 +71,12 @@ add_task(async function testDevToolsModuleLoader() {
"Global os ESM loaded in the devtools loader can't be inspected by the Debugee");
info("Re-import the same module in the devtools loader");
- const ns3 = ChromeUtils.importESModule(ESM_URL, { loadInDevToolsLoader: true });
+ const ns3 = ChromeUtils.importESModule(ESM_URL, { global: "devtools" });
Assert.equal(ns3, ns2, "We import the exact same module");
Assert.equal(ns3.importedObject, ns2.importedObject, "The two module expose the same objects");
info("Import a module only from the devtools loader");
- const ns4 = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader_only.js", { loadInDevToolsLoader: true });
+ const ns4 = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader_only.js", { global: "devtools" });
const ns4Global = Cu.getGlobalForObject(ns4);
Assert.equal(ns4Global, ns2Global, "The module is loaded in the same devtools global");
diff --git a/js/xpconnect/tests/unit/test_import_global.js b/js/xpconnect/tests/unit/test_import_global.js
index 9ad4522854..97dbaac90d 100644
--- a/js/xpconnect/tests/unit/test_import_global.js
+++ b/js/xpconnect/tests/unit/test_import_global.js
@@ -14,16 +14,14 @@ add_task(async function testShared() {
});
add_task(async function testDevTools() {
- const ns1 = ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
- loadInDevToolsLoader: true,
- });
+ const ns1 = ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs");
const ns2 = ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
global: "devtools",
});
- Assert.equal(ns1, ns2);
- Assert.equal(ns1.obj, ns2.obj);
+ Assert.notEqual(ns1, ns2);
+ Assert.notEqual(ns1.obj, ns2.obj);
});
add_task(async function testInvalidOptions() {
diff --git a/js/xpconnect/tests/unit/test_import_global_worker.js b/js/xpconnect/tests/unit/test_import_global_worker.js
index 16359a4da4..9000358b67 100644
--- a/js/xpconnect/tests/unit/test_import_global_worker.js
+++ b/js/xpconnect/tests/unit/test_import_global_worker.js
@@ -17,5 +17,4 @@ add_task(async function testSharedInWorker() {
Assert.equal(result.caught1, true);
Assert.equal(result.caught2, true);
Assert.equal(result.caught3, true);
- Assert.equal(result.caught4, true);
});
diff --git a/js/xpconnect/tests/unit/test_returncode.js b/js/xpconnect/tests/unit/test_returncode.js
index de4289c013..31997eb4ad 100644
--- a/js/xpconnect/tests/unit/test_returncode.js
+++ b/js/xpconnect/tests/unit/test_returncode.js
@@ -14,10 +14,6 @@ function run_test() {
// Load the component manifests.
registerXPCTestComponents();
- // and the tests.
- test_simple("@mozilla.org/js/xpc/test/native/ReturnCodeParent;1");
- test_nested("@mozilla.org/js/xpc/test/native/ReturnCodeParent;1");
-
test_simple("@mozilla.org/js/xpc/test/native/ESMReturnCodeParent;1");
test_nested("@mozilla.org/js/xpc/test/native/ESMReturnCodeParent;1");
}
diff --git a/js/xpconnect/tests/unit/xpcshell.toml b/js/xpconnect/tests/unit/xpcshell.toml
index 97b2dbe559..37274eba96 100644
--- a/js/xpconnect/tests/unit/xpcshell.toml
+++ b/js/xpconnect/tests/unit/xpcshell.toml
@@ -15,7 +15,6 @@ support-files = [
"importer.jsm",
"recursive_importA.jsm",
"recursive_importB.jsm",
- "ReturnCodeChild.jsm",
"ReturnCodeChild.sys.mjs",
"syntax_error.jsm",
"uninitialized_lexical.jsm",