summaryrefslogtreecommitdiffstats
path: root/testing/xpcshell/example/unit/import_module.jsm
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/xpcshell/example/unit/import_module.jsm
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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 'testing/xpcshell/example/unit/import_module.jsm')
-rw-r--r--testing/xpcshell/example/unit/import_module.jsm34
1 files changed, 34 insertions, 0 deletions
diff --git a/testing/xpcshell/example/unit/import_module.jsm b/testing/xpcshell/example/unit/import_module.jsm
new file mode 100644
index 000000000..3b1ddaf9f
--- /dev/null
+++ b/testing/xpcshell/example/unit/import_module.jsm
@@ -0,0 +1,34 @@
+/* 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/. */
+
+// Module used by test_import_module.js
+
+const EXPORTED_SYMBOLS = [ "MODULE_IMPORTED", "MODULE_URI", "SUBMODULE_IMPORTED", "same_scope", "SUBMODULE_IMPORTED_TO_SCOPE" ];
+
+const MODULE_IMPORTED = true;
+const MODULE_URI = __URI__;
+
+// Will import SUBMODULE_IMPORTED into scope.
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.importRelative(this, "import_sub_module.jsm");
+
+// Prepare two scopes that we can import the submodule into.
+var scope1 = { __URI__: __URI__ };
+var scope2 = { __URI__: __URI__ };
+// First one is the regular path.
+XPCOMUtils.importRelative(scope1, "import_sub_module.jsm");
+scope1.test_obj.i++;
+// Second one is with a different path (leads to the same file).
+XPCOMUtils.importRelative(scope2, "duh/../import_sub_module.jsm");
+// test_obj belongs to import_sub_module.jsm and has a mutable field name i, if
+// the two modules are actually the same, then they'll share the same value.
+// We'll leave it up to test_import_module.js to check that this variable is
+// true.
+var same_scope = (scope1.test_obj.i == scope2.test_obj.i);
+
+// Check that importRelative can also import into a given scope
+var testScope = {};
+XPCOMUtils.importRelative(this, "import_sub_module.jsm", testScope);
+var SUBMODULE_IMPORTED_TO_SCOPE = testScope.SUBMODULE_IMPORTED;
+