js/xpconnect/tests/unit/test_bogus_files.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 function test_BrokenFile(path, shouldThrow, expectedName) {
michael@0 6 var didThrow = false;
michael@0 7 try {
michael@0 8 Components.utils.import(path);
michael@0 9 } catch (ex) {
michael@0 10 var exceptionName = ex.name;
michael@0 11 print("ex: " + ex + "; name = " + ex.name);
michael@0 12 didThrow = true;
michael@0 13 }
michael@0 14
michael@0 15 do_check_eq(didThrow, shouldThrow);
michael@0 16 if (didThrow)
michael@0 17 do_check_eq(exceptionName, expectedName);
michael@0 18 }
michael@0 19
michael@0 20 function run_test() {
michael@0 21 test_BrokenFile("resource://test/bogus_exports_type.jsm", true, "Error");
michael@0 22
michael@0 23 test_BrokenFile("resource://test/bogus_element_type.jsm", true, "Error");
michael@0 24
michael@0 25 test_BrokenFile("resource://test/non_existing.jsm",
michael@0 26 true,
michael@0 27 "NS_ERROR_FILE_NOT_FOUND");
michael@0 28
michael@0 29 test_BrokenFile("chrome://test/content/test.jsm",
michael@0 30 true,
michael@0 31 "NS_ERROR_ILLEGAL_VALUE");
michael@0 32
michael@0 33 // check that we can access modules' global objects even if
michael@0 34 // EXPORTED_SYMBOLS is missing or ill-formed:
michael@0 35 do_check_eq(typeof(Components.utils.import("resource://test/bogus_exports_type.jsm",
michael@0 36 null)),
michael@0 37 "object");
michael@0 38
michael@0 39 do_check_eq(typeof(Components.utils.import("resource://test/bogus_element_type.jsm",
michael@0 40 null)),
michael@0 41 "object");
michael@0 42 }

mercurial