|
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 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
6 |
|
7 function FooComponent() { |
|
8 this.wrappedJSObject = this; |
|
9 } |
|
10 FooComponent.prototype = |
|
11 { |
|
12 // nsIClassInfo + information for XPCOM registration code in XPCOMUtils.jsm |
|
13 classDescription: "Foo Component", |
|
14 classID: Components.ID("{6b933fe6-6eba-4622-ac86-e4f654f1b474}"), |
|
15 contractID: "@mozilla.org/tests/module-importer;1", |
|
16 |
|
17 // nsIClassInfo |
|
18 implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT, |
|
19 flags: 0, |
|
20 |
|
21 getInterfaces: function getInterfaces(aCount) { |
|
22 var interfaces = [Components.interfaces.nsIClassInfo]; |
|
23 aCount.value = interfaces.length; |
|
24 |
|
25 // Guerilla test for line numbers hiding in this method |
|
26 var threw = true; |
|
27 try { |
|
28 thereIsNoSuchIdentifier; |
|
29 threw = false; |
|
30 } catch (ex) { |
|
31 do_check_true(ex.lineNumber == 28); |
|
32 } |
|
33 do_check_true(threw); |
|
34 |
|
35 return interfaces; |
|
36 }, |
|
37 |
|
38 getHelperForLanguage: function getHelperForLanguage(aLanguage) { |
|
39 return null; |
|
40 }, |
|
41 |
|
42 // nsISupports |
|
43 QueryInterface: function QueryInterface(aIID) { |
|
44 if (aIID.equals(Components.interfaces.nsIClassInfo) || |
|
45 aIID.equals(Components.interfaces.nsISupports)) |
|
46 return this; |
|
47 |
|
48 throw Components.results.NS_ERROR_NO_INTERFACE; |
|
49 } |
|
50 }; |
|
51 |
|
52 function BarComponent() { |
|
53 } |
|
54 BarComponent.prototype = |
|
55 { |
|
56 // nsIClassInfo + information for XPCOM registration code in XPCOMUtils.jsm |
|
57 classDescription: "Module importer test 2", |
|
58 classID: Components.ID("{708a896a-b48d-4bff-906e-fc2fd134b296}"), |
|
59 contractID: "@mozilla.org/tests/module-importer;2", |
|
60 |
|
61 // nsIClassInfo |
|
62 implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT, |
|
63 flags: 0, |
|
64 |
|
65 getInterfaces: function getInterfaces(aCount) { |
|
66 var interfaces = [Components.interfaces.nsIClassInfo]; |
|
67 aCount.value = interfaces.length; |
|
68 return interfaces; |
|
69 }, |
|
70 |
|
71 getHelperForLanguage: function getHelperForLanguage(aLanguage) { |
|
72 return null; |
|
73 }, |
|
74 |
|
75 // nsISupports |
|
76 QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIClassInfo]) |
|
77 }; |
|
78 |
|
79 function do_check_true(cond, text) { |
|
80 // we don't have the test harness' utilities in this scope, so we need this |
|
81 // little helper. In the failure case, the exception is propagated to the |
|
82 // caller in the main run_test() function, and the test fails. |
|
83 if (!cond) |
|
84 throw "Failed check: " + text; |
|
85 } |
|
86 |
|
87 var gComponentsArray = [FooComponent, BarComponent]; |
|
88 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(gComponentsArray); |