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/. */
8 var exports = ChromeUtils.import("resource://test/TestFile.jsm", scope);
9 Assert.equal(typeof(scope.TestFile), "object");
10 Assert.equal(typeof(scope.TestFile.doTest), "function");
12 equal(scope.TestFile, exports.TestFile);
13 deepEqual(Object.keys(scope), ["TestFile"]);
14 deepEqual(Object.keys(exports), ["TestFile"]);
16 exports = ChromeUtils.import("resource://test/TestFile.jsm");
17 equal(scope.TestFile, exports.TestFile);
18 deepEqual(Object.keys(exports), ["TestFile"]);
20 // access module's global object directly without importing any
23 () => ChromeUtils.import("resource://test/TestFile.jsm", null),
27 // import symbols to our global object
28 Assert.equal(typeof(Cu.import), "function");
29 ({TestFile} = ChromeUtils.import("resource://test/TestFile.jsm"));
30 Assert.equal(typeof(TestFile), "object");
31 Assert.equal(typeof(TestFile.doTest), "function");
33 // try on a new object
35 ChromeUtils.import("resource://test/TestFile.jsm", scope2);
36 Assert.equal(typeof(scope2.TestFile), "object");
37 Assert.equal(typeof(scope2.TestFile.doTest), "function");
39 Assert.ok(scope2.TestFile == scope.TestFile);
41 // try on a new object using the resolved URL
42 var res = Cc["@mozilla.org/network/protocol;1?name=resource"]
43 .getService(Ci.nsIResProtocolHandler);
44 var resURI = Cc["@mozilla.org/network/io-service;1"]
45 .getService(Ci.nsIIOService)
46 .newURI("resource://test/TestFile.jsm");
47 dump("resURI: " + resURI + "\n");
48 var filePath = res.resolveURI(resURI);
51 () => ChromeUtils.import(filePath, scope3),
52 /SecurityError/, "Expecting file URI not to be imported"
55 // make sure we throw when the second arg is bogus
58 ChromeUtils.import("resource://test/TestFile.jsm", "wrong");
60 print("exception (expected): " + ex);
65 // make sure we throw when the URL scheme is not known
67 const wrongScheme = "data:text/javascript,var a = {a:1}";
69 () => ChromeUtils.import(wrongScheme, scope4),
70 /SecurityError/, "Expecting data URI not to be imported"