testing/xpcshell/example/unit/import_module.jsm

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:c629d524d4f1
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 // Module used by test_import_module.js
6
7 const EXPORTED_SYMBOLS = [ "MODULE_IMPORTED", "MODULE_URI", "SUBMODULE_IMPORTED", "same_scope", "SUBMODULE_IMPORTED_TO_SCOPE" ];
8
9 const MODULE_IMPORTED = true;
10 const MODULE_URI = __URI__;
11
12 // Will import SUBMODULE_IMPORTED into scope.
13 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
14 XPCOMUtils.importRelative(this, "import_sub_module.jsm");
15
16 // Prepare two scopes that we can import the submodule into.
17 var scope1 = { __URI__: __URI__ };
18 var scope2 = { __URI__: __URI__ };
19 // First one is the regular path.
20 XPCOMUtils.importRelative(scope1, "import_sub_module.jsm");
21 scope1.test_obj.i++;
22 // Second one is with a different path (leads to the same file).
23 XPCOMUtils.importRelative(scope2, "duh/../import_sub_module.jsm");
24 // test_obj belongs to import_sub_module.jsm and has a mutable field name i, if
25 // the two modules are actually the same, then they'll share the same value.
26 // We'll leave it up to test_import_module.js to check that this variable is
27 // true.
28 var same_scope = (scope1.test_obj.i == scope2.test_obj.i);
29
30 // Check that importRelative can also import into a given scope
31 var testScope = {};
32 XPCOMUtils.importRelative(this, "import_sub_module.jsm", testScope);
33 var SUBMODULE_IMPORTED_TO_SCOPE = testScope.SUBMODULE_IMPORTED;
34

mercurial