michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test_BrokenFile(path, shouldThrow, expectedName) { michael@0: var didThrow = false; michael@0: try { michael@0: Components.utils.import(path); michael@0: } catch (ex) { michael@0: var exceptionName = ex.name; michael@0: print("ex: " + ex + "; name = " + ex.name); michael@0: didThrow = true; michael@0: } michael@0: michael@0: do_check_eq(didThrow, shouldThrow); michael@0: if (didThrow) michael@0: do_check_eq(exceptionName, expectedName); michael@0: } michael@0: michael@0: function run_test() { michael@0: test_BrokenFile("resource://test/bogus_exports_type.jsm", true, "Error"); michael@0: michael@0: test_BrokenFile("resource://test/bogus_element_type.jsm", true, "Error"); michael@0: michael@0: test_BrokenFile("resource://test/non_existing.jsm", michael@0: true, michael@0: "NS_ERROR_FILE_NOT_FOUND"); michael@0: michael@0: test_BrokenFile("chrome://test/content/test.jsm", michael@0: true, michael@0: "NS_ERROR_ILLEGAL_VALUE"); michael@0: michael@0: // check that we can access modules' global objects even if michael@0: // EXPORTED_SYMBOLS is missing or ill-formed: michael@0: do_check_eq(typeof(Components.utils.import("resource://test/bogus_exports_type.jsm", michael@0: null)), michael@0: "object"); michael@0: michael@0: do_check_eq(typeof(Components.utils.import("resource://test/bogus_element_type.jsm", michael@0: null)), michael@0: "object"); michael@0: }