1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/unit/component_import.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 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 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.9 + 1.10 +function FooComponent() { 1.11 + this.wrappedJSObject = this; 1.12 +} 1.13 +FooComponent.prototype = 1.14 +{ 1.15 + // nsIClassInfo + information for XPCOM registration code in XPCOMUtils.jsm 1.16 + classDescription: "Foo Component", 1.17 + classID: Components.ID("{6b933fe6-6eba-4622-ac86-e4f654f1b474}"), 1.18 + contractID: "@mozilla.org/tests/module-importer;1", 1.19 + 1.20 + // nsIClassInfo 1.21 + implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT, 1.22 + flags: 0, 1.23 + 1.24 + getInterfaces: function getInterfaces(aCount) { 1.25 + var interfaces = [Components.interfaces.nsIClassInfo]; 1.26 + aCount.value = interfaces.length; 1.27 + 1.28 + // Guerilla test for line numbers hiding in this method 1.29 + var threw = true; 1.30 + try { 1.31 + thereIsNoSuchIdentifier; 1.32 + threw = false; 1.33 + } catch (ex) { 1.34 + do_check_true(ex.lineNumber == 28); 1.35 + } 1.36 + do_check_true(threw); 1.37 + 1.38 + return interfaces; 1.39 + }, 1.40 + 1.41 + getHelperForLanguage: function getHelperForLanguage(aLanguage) { 1.42 + return null; 1.43 + }, 1.44 + 1.45 + // nsISupports 1.46 + QueryInterface: function QueryInterface(aIID) { 1.47 + if (aIID.equals(Components.interfaces.nsIClassInfo) || 1.48 + aIID.equals(Components.interfaces.nsISupports)) 1.49 + return this; 1.50 + 1.51 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.52 + } 1.53 +}; 1.54 + 1.55 +function BarComponent() { 1.56 +} 1.57 +BarComponent.prototype = 1.58 +{ 1.59 + // nsIClassInfo + information for XPCOM registration code in XPCOMUtils.jsm 1.60 + classDescription: "Module importer test 2", 1.61 + classID: Components.ID("{708a896a-b48d-4bff-906e-fc2fd134b296}"), 1.62 + contractID: "@mozilla.org/tests/module-importer;2", 1.63 + 1.64 + // nsIClassInfo 1.65 + implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT, 1.66 + flags: 0, 1.67 + 1.68 + getInterfaces: function getInterfaces(aCount) { 1.69 + var interfaces = [Components.interfaces.nsIClassInfo]; 1.70 + aCount.value = interfaces.length; 1.71 + return interfaces; 1.72 + }, 1.73 + 1.74 + getHelperForLanguage: function getHelperForLanguage(aLanguage) { 1.75 + return null; 1.76 + }, 1.77 + 1.78 + // nsISupports 1.79 + QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIClassInfo]) 1.80 +}; 1.81 + 1.82 +function do_check_true(cond, text) { 1.83 + // we don't have the test harness' utilities in this scope, so we need this 1.84 + // little helper. In the failure case, the exception is propagated to the 1.85 + // caller in the main run_test() function, and the test fails. 1.86 + if (!cond) 1.87 + throw "Failed check: " + text; 1.88 +} 1.89 + 1.90 +var gComponentsArray = [FooComponent, BarComponent]; 1.91 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory(gComponentsArray);