|
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 |
|
6 // This just verifies that FUEL integrates to the add-ons manager |
|
7 |
|
8 var testdata = { |
|
9 dummyid: "fuel-dummy-extension@mozilla.org", |
|
10 dummyname: "Dummy Extension", |
|
11 inspectorid: "addon1@tests.mozilla.org", |
|
12 inspectorname: "Test Addon", |
|
13 missing: "fuel.fuel-test-missing", |
|
14 dummy: "fuel.fuel-test" |
|
15 }; |
|
16 |
|
17 var Application = null |
|
18 |
|
19 function run_test() { |
|
20 var cm = AM_Cc["@mozilla.org/categorymanager;1"]. |
|
21 getService(AM_Ci.nsICategoryManager); |
|
22 |
|
23 try { |
|
24 var contract = cm.getCategoryEntry("JavaScript-global-privileged-property", |
|
25 "Application"); |
|
26 Application = AM_Cc[contract].getService(AM_Ci.extIApplication); |
|
27 } |
|
28 catch (e) { |
|
29 // This application does not include a FUEL variant. |
|
30 return; |
|
31 } |
|
32 |
|
33 do_test_pending(); |
|
34 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
35 |
|
36 const profileDir = gProfD.clone(); |
|
37 profileDir.append("extensions"); |
|
38 |
|
39 writeInstallRDFForExtension({ |
|
40 id: "addon1@tests.mozilla.org", |
|
41 version: "1.0", |
|
42 name: "Test Addon", |
|
43 targetApplications: [{ |
|
44 id: "xpcshell@tests.mozilla.org", |
|
45 minVersion: "1", |
|
46 maxVersion: "1" |
|
47 }], |
|
48 }, profileDir); |
|
49 |
|
50 startupManager(); |
|
51 |
|
52 Application.getExtensions(function(extensions) { |
|
53 // test to see if the extensions object is available |
|
54 do_check_neq(extensions, null); |
|
55 |
|
56 // test to see if a non-existant extension exists |
|
57 do_check_true(!extensions.has(testdata.dummyid)); |
|
58 |
|
59 // test to see if an extension exists |
|
60 do_check_true(extensions.has(testdata.inspectorid)); |
|
61 |
|
62 var inspector = extensions.get(testdata.inspectorid); |
|
63 do_check_eq(inspector.id, testdata.inspectorid); |
|
64 do_check_eq(inspector.name, testdata.inspectorname); |
|
65 do_check_eq(inspector.version, "1.0"); |
|
66 do_check_true(inspector.firstRun, true); |
|
67 do_check_true(inspector.enabled); |
|
68 |
|
69 // test to see if extension find works |
|
70 do_check_eq(extensions.all.length, 1); |
|
71 // STORAGE TESTING |
|
72 // Make sure the we are given the same extension (cached) so things like .storage work right |
|
73 inspector.storage.set("test", "simple check"); |
|
74 do_check_true(inspector.storage.has("test")); |
|
75 |
|
76 var inspector2 = extensions.get(testdata.inspectorid); |
|
77 do_check_eq(inspector2.id, testdata.inspectorid); |
|
78 do_check_true(inspector.storage.has("test")); |
|
79 do_check_eq(inspector2.storage.get("test", "cache"), inspector.storage.get("test", "original")); |
|
80 |
|
81 inspector.events.addListener("disable", onGenericEvent); |
|
82 inspector.events.addListener("enable", onGenericEvent); |
|
83 inspector.events.addListener("uninstall", onGenericEvent); |
|
84 inspector.events.addListener("cancel", onGenericEvent); |
|
85 |
|
86 AddonManager.getAddonByID(testdata.inspectorid, function(a) { |
|
87 a.userDisabled = true; |
|
88 |
|
89 do_check_eq(gLastEvent, "disable"); |
|
90 |
|
91 // enabling after a disable will only fire a 'cancel' event |
|
92 // see - http://mxr.mozilla.org/seamonkey/source/toolkit/mozapps/extensions/src/nsExtensionManager.js.in#5216 |
|
93 a.userDisabled = false; |
|
94 do_check_eq(gLastEvent, "cancel"); |
|
95 |
|
96 a.uninstall(); |
|
97 do_check_eq(gLastEvent, "uninstall"); |
|
98 |
|
99 a.cancelUninstall(); |
|
100 do_check_eq(gLastEvent, "cancel"); |
|
101 |
|
102 // PREF TESTING |
|
103 // Reset the install event preference, so that we can test it again later |
|
104 //inspector.prefs.get("install-event-fired").reset(); |
|
105 |
|
106 // test the value of the preference root |
|
107 do_check_eq(extensions.all[0].prefs.root, "extensions.addon1@tests.mozilla.org."); |
|
108 |
|
109 // test getting nonexistent values |
|
110 var itemValue = inspector.prefs.getValue(testdata.missing, "default"); |
|
111 do_check_eq(itemValue, "default"); |
|
112 |
|
113 do_check_eq(inspector.prefs.get(testdata.missing), null); |
|
114 |
|
115 // test setting and getting a value |
|
116 inspector.prefs.setValue(testdata.dummy, "dummy"); |
|
117 itemValue = inspector.prefs.getValue(testdata.dummy, "default"); |
|
118 do_check_eq(itemValue, "dummy"); |
|
119 |
|
120 // test for overwriting an existing value |
|
121 inspector.prefs.setValue(testdata.dummy, "smarty"); |
|
122 itemValue = inspector.prefs.getValue(testdata.dummy, "default"); |
|
123 do_check_eq(itemValue, "smarty"); |
|
124 |
|
125 // test setting and getting a value |
|
126 inspector.prefs.get(testdata.dummy).value = "dummy2"; |
|
127 itemValue = inspector.prefs.get(testdata.dummy).value; |
|
128 do_check_eq(itemValue, "dummy2"); |
|
129 |
|
130 // test resetting a pref [since there is no default value, the pref should disappear] |
|
131 inspector.prefs.get(testdata.dummy).reset(); |
|
132 var itemValue = inspector.prefs.getValue(testdata.dummy, "default"); |
|
133 do_check_eq(itemValue, "default"); |
|
134 |
|
135 // test to see if a non-existant property exists |
|
136 do_check_true(!inspector.prefs.has(testdata.dummy)); |
|
137 |
|
138 inspector.prefs.events.addListener("change", onPrefChange); |
|
139 inspector.prefs.setValue("fuel.fuel-test", "change event"); |
|
140 }); |
|
141 }); |
|
142 } |
|
143 |
|
144 function onGenericEvent(event) { |
|
145 gLastEvent = event.type; |
|
146 } |
|
147 |
|
148 function onPrefChange(evt) { |
|
149 Application.getExtensions(function(extensions) { |
|
150 var inspector3 = extensions.get(testdata.inspectorid); |
|
151 |
|
152 do_check_eq(evt.data, testdata.dummy); |
|
153 inspector3.prefs.events.removeListener("change", onPrefChange); |
|
154 |
|
155 inspector3.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2); |
|
156 inspector3.prefs.setValue("fuel.fuel-test", "change event2"); |
|
157 }); |
|
158 } |
|
159 |
|
160 function onPrefChange2(evt) { |
|
161 do_check_eq(evt.data, testdata.dummy); |
|
162 |
|
163 do_execute_soon(do_test_finished); |
|
164 } |