1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/unit/test_bogus_files.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,42 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function test_BrokenFile(path, shouldThrow, expectedName) { 1.9 + var didThrow = false; 1.10 + try { 1.11 + Components.utils.import(path); 1.12 + } catch (ex) { 1.13 + var exceptionName = ex.name; 1.14 + print("ex: " + ex + "; name = " + ex.name); 1.15 + didThrow = true; 1.16 + } 1.17 + 1.18 + do_check_eq(didThrow, shouldThrow); 1.19 + if (didThrow) 1.20 + do_check_eq(exceptionName, expectedName); 1.21 +} 1.22 + 1.23 +function run_test() { 1.24 + test_BrokenFile("resource://test/bogus_exports_type.jsm", true, "Error"); 1.25 + 1.26 + test_BrokenFile("resource://test/bogus_element_type.jsm", true, "Error"); 1.27 + 1.28 + test_BrokenFile("resource://test/non_existing.jsm", 1.29 + true, 1.30 + "NS_ERROR_FILE_NOT_FOUND"); 1.31 + 1.32 + test_BrokenFile("chrome://test/content/test.jsm", 1.33 + true, 1.34 + "NS_ERROR_ILLEGAL_VALUE"); 1.35 + 1.36 + // check that we can access modules' global objects even if 1.37 + // EXPORTED_SYMBOLS is missing or ill-formed: 1.38 + do_check_eq(typeof(Components.utils.import("resource://test/bogus_exports_type.jsm", 1.39 + null)), 1.40 + "object"); 1.41 + 1.42 + do_check_eq(typeof(Components.utils.import("resource://test/bogus_element_type.jsm", 1.43 + null)), 1.44 + "object"); 1.45 +}