toolkit/mozapps/extensions/test/xpcshell/test_hotfix.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:bb61593944a7
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
4
5 // This verifies that hotfix installation works
6
7 // The test extension uses an insecure update url.
8 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
9 // Ignore any certificate requirements the app has set
10 Services.prefs.setBoolPref("extensions.hotfix.cert.checkAttributes", false);
11
12 Components.utils.import("resource://testing-common/httpd.js");
13 var testserver = new HttpServer();
14 testserver.start(-1);
15 gPort = testserver.identity.primaryPort;
16 testserver.registerDirectory("/addons/", do_get_file("addons"));
17 mapFile("/data/test_hotfix_1.rdf", testserver);
18 mapFile("/data/test_hotfix_2.rdf", testserver);
19 mapFile("/data/test_hotfix_3.rdf", testserver);
20
21 const profileDir = gProfD.clone();
22 profileDir.append("extensions");
23
24 function run_test() {
25 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
26
27 startupManager();
28
29 do_test_pending();
30 run_test_1();
31 }
32
33 function end_test() {
34 testserver.stop(do_test_finished);
35 }
36
37 // Test that background updates find and install any available hotfix
38 function run_test_1() {
39 Services.prefs.setCharPref("extensions.hotfix.id", "hotfix@tests.mozilla.org");
40 Services.prefs.setCharPref("extensions.update.background.url", "http://localhost:" +
41 gPort + "/data/test_hotfix_1.rdf");
42
43 prepare_test({
44 "hotfix@tests.mozilla.org": [
45 "onInstalling"
46 ]
47 }, [
48 "onNewInstall",
49 "onDownloadStarted",
50 "onDownloadEnded",
51 "onInstallStarted",
52 "onInstallEnded",
53 ], callback_soon(check_test_1));
54
55 // Fake a timer event
56 gInternalManager.notify(null);
57 }
58
59 function check_test_1() {
60 restartManager();
61
62 AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
63 do_check_neq(aAddon, null);
64 do_check_eq(aAddon.version, "1.0");
65
66 aAddon.uninstall();
67 do_execute_soon(run_test_2);
68 });
69 }
70
71 // Don't install an already used hotfix
72 function run_test_2() {
73 restartManager();
74
75 AddonManager.addInstallListener({
76 onNewInstall: function() {
77 do_throw("Should not have seen a new install created");
78 }
79 });
80
81 function observer() {
82 Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
83 do_execute_soon(run_test_3);
84 }
85
86 Services.obs.addObserver(observer, "addons-background-update-complete", false);
87
88 // Fake a timer event
89 gInternalManager.notify(null);
90 }
91
92 // Install a newer hotfix
93 function run_test_3() {
94 restartManager();
95 Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
96 gPort + "/data/test_hotfix_2.rdf");
97
98 prepare_test({
99 "hotfix@tests.mozilla.org": [
100 "onInstalling"
101 ]
102 }, [
103 "onNewInstall",
104 "onDownloadStarted",
105 "onDownloadEnded",
106 "onInstallStarted",
107 "onInstallEnded",
108 ], callback_soon(check_test_3));
109
110 // Fake a timer event
111 gInternalManager.notify(null);
112 }
113
114 function check_test_3() {
115 restartManager();
116
117 AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
118 do_check_neq(aAddon, null);
119 do_check_eq(aAddon.version, "2.0");
120
121 aAddon.uninstall();
122 do_execute_soon(run_test_4);
123 });
124 }
125
126 // Don't install an incompatible hotfix
127 function run_test_4() {
128 restartManager();
129
130 Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
131 gPort + "/data/test_hotfix_3.rdf");
132
133 AddonManager.addInstallListener({
134 onNewInstall: function() {
135 do_throw("Should not have seen a new install created");
136 }
137 });
138
139 function observer() {
140 Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
141 do_execute_soon(run_test_5);
142 }
143
144 Services.obs.addObserver(observer, "addons-background-update-complete", false);
145
146 // Fake a timer event
147 gInternalManager.notify(null);
148 }
149
150 // Don't install an older hotfix
151 function run_test_5() {
152 restartManager();
153
154 Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
155 gPort + "/data/test_hotfix_1.rdf");
156
157 AddonManager.addInstallListener({
158 onNewInstall: function() {
159 do_throw("Should not have seen a new install created");
160 }
161 });
162
163 function observer() {
164 Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
165 do_execute_soon(run_test_6);
166 }
167
168 Services.obs.addObserver(observer, "addons-background-update-complete", false);
169
170 // Fake a timer event
171 gInternalManager.notify(null);
172 }
173
174 // Don't re-download an already pending install
175 function run_test_6() {
176 restartManager();
177
178 Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0");
179 Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
180 gPort + "/data/test_hotfix_1.rdf");
181
182 prepare_test({
183 "hotfix@tests.mozilla.org": [
184 "onInstalling"
185 ]
186 }, [
187 "onNewInstall",
188 "onDownloadStarted",
189 "onDownloadEnded",
190 "onInstallStarted",
191 "onInstallEnded",
192 ], callback_soon(check_test_6));
193
194 // Fake a timer event
195 gInternalManager.notify(null);
196 }
197
198 function check_test_6() {
199 AddonManager.addInstallListener({
200 onNewInstall: function() {
201 do_throw("Should not have seen a new install created");
202 }
203 });
204
205 function observer() {
206 Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
207 restartManager();
208
209 AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
210 aAddon.uninstall();
211 do_execute_soon(run_test_7);
212 });
213 }
214
215 Services.obs.addObserver(observer, "addons-background-update-complete", false);
216
217 // Fake a timer event
218 gInternalManager.notify(null);
219 }
220
221 // Start downloading again if something cancels the install
222 function run_test_7() {
223 restartManager();
224
225 Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0");
226
227 prepare_test({
228 "hotfix@tests.mozilla.org": [
229 "onInstalling"
230 ]
231 }, [
232 "onNewInstall",
233 "onDownloadStarted",
234 "onDownloadEnded",
235 "onInstallStarted",
236 "onInstallEnded",
237 ], check_test_7);
238
239 // Fake a timer event
240 gInternalManager.notify(null);
241 }
242
243 function check_test_7(aInstall) {
244 prepare_test({
245 "hotfix@tests.mozilla.org": [
246 "onOperationCancelled"
247 ]
248 }, [
249 "onInstallCancelled",
250 ]);
251
252 aInstall.cancel();
253
254 prepare_test({
255 "hotfix@tests.mozilla.org": [
256 "onInstalling"
257 ]
258 }, [
259 "onNewInstall",
260 "onDownloadStarted",
261 "onDownloadEnded",
262 "onInstallStarted",
263 "onInstallEnded",
264 ], callback_soon(finish_test_7));
265
266 // Fake a timer event
267 gInternalManager.notify(null);
268 }
269
270 function finish_test_7() {
271 restartManager();
272
273 AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
274 do_check_neq(aAddon, null);
275 do_check_eq(aAddon.version, "1.0");
276
277 aAddon.uninstall();
278 do_execute_soon(run_test_8);
279 });
280 }
281
282 // Cancel a pending install when a newer version is already available
283 function run_test_8() {
284 restartManager();
285
286 Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0");
287 Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
288 gPort + "/data/test_hotfix_1.rdf");
289
290 prepare_test({
291 "hotfix@tests.mozilla.org": [
292 "onInstalling"
293 ]
294 }, [
295 "onNewInstall",
296 "onDownloadStarted",
297 "onDownloadEnded",
298 "onInstallStarted",
299 "onInstallEnded",
300 ], check_test_8);
301
302 // Fake a timer event
303 gInternalManager.notify(null);
304 }
305
306 function check_test_8() {
307 Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
308 gPort + "/data/test_hotfix_2.rdf");
309
310 prepare_test({
311 "hotfix@tests.mozilla.org": [
312 "onOperationCancelled",
313 "onInstalling"
314 ]
315 }, [
316 "onNewInstall",
317 "onDownloadStarted",
318 "onDownloadEnded",
319 "onInstallStarted",
320 "onInstallCancelled",
321 "onInstallEnded",
322 ], finish_test_8);
323
324 // Fake a timer event
325 gInternalManager.notify(null);
326 }
327
328 function finish_test_8() {
329 AddonManager.getAllInstalls(callback_soon(function(aInstalls) {
330 do_check_eq(aInstalls.length, 1);
331 do_check_eq(aInstalls[0].version, "2.0");
332
333 restartManager();
334
335 AddonManager.getAddonByID("hotfix@tests.mozilla.org", callback_soon(function(aAddon) {
336 do_check_neq(aAddon, null);
337 do_check_eq(aAddon.version, "2.0");
338
339 aAddon.uninstall();
340 restartManager();
341
342 end_test();
343 }));
344 }));
345 }

mercurial