js/xpconnect/tests/unit/test_bogus_files.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:7b7f5a759669
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 function test_BrokenFile(path, shouldThrow, expectedName) {
6 var didThrow = false;
7 try {
8 Components.utils.import(path);
9 } catch (ex) {
10 var exceptionName = ex.name;
11 print("ex: " + ex + "; name = " + ex.name);
12 didThrow = true;
13 }
14
15 do_check_eq(didThrow, shouldThrow);
16 if (didThrow)
17 do_check_eq(exceptionName, expectedName);
18 }
19
20 function run_test() {
21 test_BrokenFile("resource://test/bogus_exports_type.jsm", true, "Error");
22
23 test_BrokenFile("resource://test/bogus_element_type.jsm", true, "Error");
24
25 test_BrokenFile("resource://test/non_existing.jsm",
26 true,
27 "NS_ERROR_FILE_NOT_FOUND");
28
29 test_BrokenFile("chrome://test/content/test.jsm",
30 true,
31 "NS_ERROR_ILLEGAL_VALUE");
32
33 // check that we can access modules' global objects even if
34 // EXPORTED_SYMBOLS is missing or ill-formed:
35 do_check_eq(typeof(Components.utils.import("resource://test/bogus_exports_type.jsm",
36 null)),
37 "object");
38
39 do_check_eq(typeof(Components.utils.import("resource://test/bogus_element_type.jsm",
40 null)),
41 "object");
42 }

mercurial