|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 const APP_STARTUP = 1; |
|
6 const APP_SHUTDOWN = 2; |
|
7 const ADDON_ENABLE = 3; |
|
8 const ADDON_DISABLE = 4; |
|
9 const ADDON_INSTALL = 5; |
|
10 const ADDON_UNINSTALL = 6; |
|
11 const ADDON_UPGRADE = 7; |
|
12 const ADDON_DOWNGRADE = 8; |
|
13 |
|
14 // This verifies that bootstrappable add-ons can be used without restarts. |
|
15 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
16 Components.utils.import("resource://gre/modules/Promise.jsm"); |
|
17 |
|
18 // Enable loading extensions from the user scopes |
|
19 Services.prefs.setIntPref("extensions.enabledScopes", |
|
20 AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER); |
|
21 |
|
22 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
23 |
|
24 const profileDir = gProfD.clone(); |
|
25 profileDir.append("extensions"); |
|
26 const userExtDir = gProfD.clone(); |
|
27 userExtDir.append("extensions2"); |
|
28 userExtDir.append(gAppInfo.ID); |
|
29 registerDirectory("XREUSysExt", userExtDir.parent); |
|
30 |
|
31 Components.utils.import("resource://testing-common/httpd.js"); |
|
32 var testserver = new HttpServer(); |
|
33 testserver.start(-1); |
|
34 gPort = testserver.identity.primaryPort; |
|
35 |
|
36 testserver.registerDirectory("/addons/", do_get_file("addons")); |
|
37 |
|
38 function resetPrefs() { |
|
39 Services.prefs.setIntPref("bootstraptest.active_version", -1); |
|
40 Services.prefs.setIntPref("bootstraptest.installed_version", -1); |
|
41 Services.prefs.setIntPref("bootstraptest2.active_version", -1); |
|
42 Services.prefs.setIntPref("bootstraptest2.installed_version", -1); |
|
43 Services.prefs.setIntPref("bootstraptest.startup_reason", -1); |
|
44 Services.prefs.setIntPref("bootstraptest.shutdown_reason", -1); |
|
45 Services.prefs.setIntPref("bootstraptest.install_reason", -1); |
|
46 Services.prefs.setIntPref("bootstraptest.uninstall_reason", -1); |
|
47 Services.prefs.setIntPref("bootstraptest.startup_oldversion", -1); |
|
48 Services.prefs.setIntPref("bootstraptest.shutdown_newversion", -1); |
|
49 Services.prefs.setIntPref("bootstraptest.install_oldversion", -1); |
|
50 Services.prefs.setIntPref("bootstraptest.uninstall_newversion", -1); |
|
51 } |
|
52 |
|
53 function waitForPref(aPref, aCallback) { |
|
54 function prefChanged() { |
|
55 Services.prefs.removeObserver(aPref, prefChanged); |
|
56 // Always let whoever set the preference keep running |
|
57 do_execute_soon(aCallback); |
|
58 } |
|
59 Services.prefs.addObserver(aPref, prefChanged, false); |
|
60 } |
|
61 |
|
62 function promisePref(aPref) { |
|
63 let deferred = Promise.defer(); |
|
64 |
|
65 waitForPref(aPref, deferred.resolve.bind(deferred)); |
|
66 |
|
67 return deferred.promise; |
|
68 } |
|
69 |
|
70 function promiseInstall(aFiles) { |
|
71 let deferred = Promise.defer(); |
|
72 |
|
73 installAllFiles(aFiles, function() { |
|
74 deferred.resolve(); |
|
75 }); |
|
76 |
|
77 return deferred.promise; |
|
78 } |
|
79 |
|
80 function getActiveVersion() { |
|
81 return Services.prefs.getIntPref("bootstraptest.active_version"); |
|
82 } |
|
83 |
|
84 function getInstalledVersion() { |
|
85 return Services.prefs.getIntPref("bootstraptest.installed_version"); |
|
86 } |
|
87 |
|
88 function getActiveVersion2() { |
|
89 return Services.prefs.getIntPref("bootstraptest2.active_version"); |
|
90 } |
|
91 |
|
92 function getInstalledVersion2() { |
|
93 return Services.prefs.getIntPref("bootstraptest2.installed_version"); |
|
94 } |
|
95 |
|
96 function getStartupReason() { |
|
97 return Services.prefs.getIntPref("bootstraptest.startup_reason"); |
|
98 } |
|
99 |
|
100 function getShutdownReason() { |
|
101 return Services.prefs.getIntPref("bootstraptest.shutdown_reason"); |
|
102 } |
|
103 |
|
104 function getInstallReason() { |
|
105 return Services.prefs.getIntPref("bootstraptest.install_reason"); |
|
106 } |
|
107 |
|
108 function getUninstallReason() { |
|
109 return Services.prefs.getIntPref("bootstraptest.uninstall_reason"); |
|
110 } |
|
111 |
|
112 function getStartupOldVersion() { |
|
113 return Services.prefs.getIntPref("bootstraptest.startup_oldversion"); |
|
114 } |
|
115 |
|
116 function getShutdownNewVersion() { |
|
117 return Services.prefs.getIntPref("bootstraptest.shutdown_newversion"); |
|
118 } |
|
119 |
|
120 function getInstallOldVersion() { |
|
121 return Services.prefs.getIntPref("bootstraptest.install_oldversion"); |
|
122 } |
|
123 |
|
124 function getUninstallNewVersion() { |
|
125 return Services.prefs.getIntPref("bootstraptest.uninstall_newversion"); |
|
126 } |
|
127 |
|
128 function do_check_bootstrappedPref(aCallback) { |
|
129 let data = "{}"; |
|
130 try { |
|
131 // This is ok to fail, as the pref won't exist on a fresh profile. |
|
132 data = Services.prefs.getCharPref("extensions.bootstrappedAddons"); |
|
133 } catch (e) {} |
|
134 data = JSON.parse(data); |
|
135 |
|
136 AddonManager.getAddonsByTypes(["extension"], function(aAddons) { |
|
137 for (let addon of aAddons) { |
|
138 if (!addon.id.endsWith("@tests.mozilla.org")) |
|
139 continue; |
|
140 if (!addon.isActive) |
|
141 continue; |
|
142 if (addon.operationsRequiringRestart != AddonManager.OP_NEEDS_RESTART_NONE) |
|
143 continue; |
|
144 |
|
145 do_check_true(addon.id in data); |
|
146 let addonData = data[addon.id]; |
|
147 delete data[addon.id]; |
|
148 |
|
149 do_check_eq(addonData.version, addon.version); |
|
150 do_check_eq(addonData.type, addon.type); |
|
151 let file = addon.getResourceURI().QueryInterface(Components.interfaces.nsIFileURL).file; |
|
152 do_check_eq(addonData.descriptor, file.persistentDescriptor); |
|
153 } |
|
154 do_check_eq(Object.keys(data).length, 0); |
|
155 |
|
156 aCallback(); |
|
157 }); |
|
158 } |
|
159 |
|
160 |
|
161 function run_test() { |
|
162 do_test_pending(); |
|
163 |
|
164 resetPrefs(); |
|
165 |
|
166 startupManager(); |
|
167 |
|
168 do_check_false(gExtensionsJSON.exists()); |
|
169 |
|
170 do_check_false(gExtensionsINI.exists()); |
|
171 |
|
172 do_check_bootstrappedPref(run_test_1); |
|
173 } |
|
174 |
|
175 // Tests that installing doesn't require a restart |
|
176 function run_test_1() { |
|
177 prepare_test({ }, [ |
|
178 "onNewInstall" |
|
179 ]); |
|
180 |
|
181 AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_1"), function(install) { |
|
182 ensure_test_completed(); |
|
183 |
|
184 do_check_neq(install, null); |
|
185 do_check_eq(install.type, "extension"); |
|
186 do_check_eq(install.version, "1.0"); |
|
187 do_check_eq(install.name, "Test Bootstrap 1"); |
|
188 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
189 do_check_neq(install.addon.syncGUID, null); |
|
190 do_check_true(install.addon.hasResource("install.rdf")); |
|
191 do_check_true(install.addon.hasResource("bootstrap.js")); |
|
192 do_check_false(install.addon.hasResource("foo.bar")); |
|
193 do_check_eq(install.addon.operationsRequiringRestart & |
|
194 AddonManager.OP_NEEDS_RESTART_INSTALL, 0); |
|
195 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
196 |
|
197 let addon = install.addon; |
|
198 |
|
199 waitForPref("bootstraptest.startup_reason", function() { |
|
200 do_check_bootstrappedPref(function() { |
|
201 check_test_1(addon.syncGUID); |
|
202 }); |
|
203 }); |
|
204 |
|
205 prepare_test({ |
|
206 "bootstrap1@tests.mozilla.org": [ |
|
207 ["onInstalling", false], |
|
208 "onInstalled" |
|
209 ] |
|
210 }, [ |
|
211 "onInstallStarted", |
|
212 "onInstallEnded", |
|
213 ], function() { |
|
214 do_check_true(addon.hasResource("install.rdf")); |
|
215 |
|
216 // startup should not have been called yet. |
|
217 do_check_eq(getActiveVersion(), -1); |
|
218 }); |
|
219 install.install(); |
|
220 }); |
|
221 } |
|
222 |
|
223 function check_test_1(installSyncGUID) { |
|
224 do_check_false(gExtensionsINI.exists()); |
|
225 |
|
226 AddonManager.getAllInstalls(function(installs) { |
|
227 // There should be no active installs now since the install completed and |
|
228 // doesn't require a restart. |
|
229 do_check_eq(installs.length, 0); |
|
230 |
|
231 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
232 do_check_neq(b1, null); |
|
233 do_check_eq(b1.version, "1.0"); |
|
234 do_check_neq(b1.syncGUID, null); |
|
235 do_check_eq(b1.syncGUID, installSyncGUID); |
|
236 do_check_false(b1.appDisabled); |
|
237 do_check_false(b1.userDisabled); |
|
238 do_check_true(b1.isActive); |
|
239 do_check_eq(getInstalledVersion(), 1); |
|
240 do_check_eq(getActiveVersion(), 1); |
|
241 do_check_eq(getStartupReason(), ADDON_INSTALL); |
|
242 do_check_eq(getStartupOldVersion(), 0); |
|
243 do_check_true(b1.hasResource("install.rdf")); |
|
244 do_check_true(b1.hasResource("bootstrap.js")); |
|
245 do_check_false(b1.hasResource("foo.bar")); |
|
246 do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
247 |
|
248 let dir = do_get_addon_root_uri(profileDir, "bootstrap1@tests.mozilla.org"); |
|
249 do_check_eq(b1.getResourceURI("bootstrap.js").spec, dir + "bootstrap.js"); |
|
250 |
|
251 AddonManager.getAddonsWithOperationsByTypes(null, function(list) { |
|
252 do_check_eq(list.length, 0); |
|
253 |
|
254 do_execute_soon(run_test_2); |
|
255 }); |
|
256 }); |
|
257 }); |
|
258 } |
|
259 |
|
260 // Tests that disabling doesn't require a restart |
|
261 function run_test_2() { |
|
262 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
263 prepare_test({ |
|
264 "bootstrap1@tests.mozilla.org": [ |
|
265 ["onDisabling", false], |
|
266 "onDisabled" |
|
267 ] |
|
268 }); |
|
269 |
|
270 do_check_eq(b1.operationsRequiringRestart & |
|
271 AddonManager.OP_NEEDS_RESTART_DISABLE, 0); |
|
272 b1.userDisabled = true; |
|
273 ensure_test_completed(); |
|
274 |
|
275 do_check_neq(b1, null); |
|
276 do_check_eq(b1.version, "1.0"); |
|
277 do_check_false(b1.appDisabled); |
|
278 do_check_true(b1.userDisabled); |
|
279 do_check_false(b1.isActive); |
|
280 do_check_eq(getInstalledVersion(), 1); |
|
281 do_check_eq(getActiveVersion(), 0); |
|
282 do_check_eq(getShutdownReason(), ADDON_DISABLE); |
|
283 do_check_eq(getShutdownNewVersion(), 0); |
|
284 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
285 |
|
286 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(newb1) { |
|
287 do_check_neq(newb1, null); |
|
288 do_check_eq(newb1.version, "1.0"); |
|
289 do_check_false(newb1.appDisabled); |
|
290 do_check_true(newb1.userDisabled); |
|
291 do_check_false(newb1.isActive); |
|
292 |
|
293 do_check_bootstrappedPref(run_test_3); |
|
294 }); |
|
295 }); |
|
296 } |
|
297 |
|
298 // Test that restarting doesn't accidentally re-enable |
|
299 function run_test_3() { |
|
300 shutdownManager(); |
|
301 do_check_eq(getInstalledVersion(), 1); |
|
302 do_check_eq(getActiveVersion(), 0); |
|
303 do_check_eq(getShutdownReason(), ADDON_DISABLE); |
|
304 do_check_eq(getShutdownNewVersion(), 0); |
|
305 startupManager(false); |
|
306 do_check_eq(getInstalledVersion(), 1); |
|
307 do_check_eq(getActiveVersion(), 0); |
|
308 do_check_eq(getShutdownReason(), ADDON_DISABLE); |
|
309 do_check_eq(getShutdownNewVersion(), 0); |
|
310 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
311 |
|
312 do_check_false(gExtensionsINI.exists()); |
|
313 |
|
314 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
315 do_check_neq(b1, null); |
|
316 do_check_eq(b1.version, "1.0"); |
|
317 do_check_false(b1.appDisabled); |
|
318 do_check_true(b1.userDisabled); |
|
319 do_check_false(b1.isActive); |
|
320 |
|
321 do_check_bootstrappedPref(run_test_4); |
|
322 }); |
|
323 } |
|
324 |
|
325 // Tests that enabling doesn't require a restart |
|
326 function run_test_4() { |
|
327 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
328 prepare_test({ |
|
329 "bootstrap1@tests.mozilla.org": [ |
|
330 ["onEnabling", false], |
|
331 "onEnabled" |
|
332 ] |
|
333 }); |
|
334 |
|
335 do_check_eq(b1.operationsRequiringRestart & |
|
336 AddonManager.OP_NEEDS_RESTART_ENABLE, 0); |
|
337 b1.userDisabled = false; |
|
338 ensure_test_completed(); |
|
339 |
|
340 do_check_neq(b1, null); |
|
341 do_check_eq(b1.version, "1.0"); |
|
342 do_check_false(b1.appDisabled); |
|
343 do_check_false(b1.userDisabled); |
|
344 do_check_true(b1.isActive); |
|
345 do_check_eq(getInstalledVersion(), 1); |
|
346 do_check_eq(getActiveVersion(), 1); |
|
347 do_check_eq(getStartupReason(), ADDON_ENABLE); |
|
348 do_check_eq(getStartupOldVersion(), 0); |
|
349 do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
350 |
|
351 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(newb1) { |
|
352 do_check_neq(newb1, null); |
|
353 do_check_eq(newb1.version, "1.0"); |
|
354 do_check_false(newb1.appDisabled); |
|
355 do_check_false(newb1.userDisabled); |
|
356 do_check_true(newb1.isActive); |
|
357 |
|
358 do_check_bootstrappedPref(run_test_5); |
|
359 }); |
|
360 }); |
|
361 } |
|
362 |
|
363 // Tests that a restart shuts down and restarts the add-on |
|
364 function run_test_5() { |
|
365 shutdownManager(); |
|
366 // By the time we've shut down, the database must have been written |
|
367 do_check_true(gExtensionsJSON.exists()); |
|
368 |
|
369 do_check_eq(getInstalledVersion(), 1); |
|
370 do_check_eq(getActiveVersion(), 0); |
|
371 do_check_eq(getShutdownReason(), APP_SHUTDOWN); |
|
372 do_check_eq(getShutdownNewVersion(), 0); |
|
373 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
374 startupManager(false); |
|
375 do_check_eq(getInstalledVersion(), 1); |
|
376 do_check_eq(getActiveVersion(), 1); |
|
377 do_check_eq(getStartupReason(), APP_STARTUP); |
|
378 do_check_eq(getStartupOldVersion(), 0); |
|
379 do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
380 |
|
381 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
382 do_check_neq(b1, null); |
|
383 do_check_eq(b1.version, "1.0"); |
|
384 do_check_false(b1.appDisabled); |
|
385 do_check_false(b1.userDisabled); |
|
386 do_check_true(b1.isActive); |
|
387 do_check_false(isExtensionInAddonsList(profileDir, b1.id)); |
|
388 |
|
389 do_check_bootstrappedPref(run_test_6); |
|
390 }); |
|
391 } |
|
392 |
|
393 // Tests that installing an upgrade doesn't require a restart |
|
394 function run_test_6() { |
|
395 prepare_test({ }, [ |
|
396 "onNewInstall" |
|
397 ]); |
|
398 |
|
399 AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_2"), function(install) { |
|
400 ensure_test_completed(); |
|
401 |
|
402 do_check_neq(install, null); |
|
403 do_check_eq(install.type, "extension"); |
|
404 do_check_eq(install.version, "2.0"); |
|
405 do_check_eq(install.name, "Test Bootstrap 1"); |
|
406 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
407 |
|
408 waitForPref("bootstraptest.startup_reason", check_test_6); |
|
409 prepare_test({ |
|
410 "bootstrap1@tests.mozilla.org": [ |
|
411 ["onInstalling", false], |
|
412 "onInstalled" |
|
413 ] |
|
414 }, [ |
|
415 "onInstallStarted", |
|
416 "onInstallEnded", |
|
417 ], function() { |
|
418 }); |
|
419 install.install(); |
|
420 }); |
|
421 } |
|
422 |
|
423 function check_test_6() { |
|
424 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
425 do_check_neq(b1, null); |
|
426 do_check_eq(b1.version, "2.0"); |
|
427 do_check_false(b1.appDisabled); |
|
428 do_check_false(b1.userDisabled); |
|
429 do_check_true(b1.isActive); |
|
430 do_check_eq(getInstalledVersion(), 2); |
|
431 do_check_eq(getActiveVersion(), 2); |
|
432 do_check_eq(getStartupReason(), ADDON_UPGRADE); |
|
433 do_check_eq(getInstallOldVersion(), 1); |
|
434 do_check_eq(getStartupOldVersion(), 1); |
|
435 do_check_eq(getShutdownReason(), ADDON_UPGRADE); |
|
436 do_check_eq(getShutdownNewVersion(), 2); |
|
437 do_check_eq(getUninstallNewVersion(), 2); |
|
438 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
439 do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "2.0"); |
|
440 |
|
441 do_check_bootstrappedPref(run_test_7); |
|
442 }); |
|
443 } |
|
444 |
|
445 // Tests that uninstalling doesn't require a restart |
|
446 function run_test_7() { |
|
447 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
448 prepare_test({ |
|
449 "bootstrap1@tests.mozilla.org": [ |
|
450 ["onUninstalling", false], |
|
451 "onUninstalled" |
|
452 ] |
|
453 }); |
|
454 |
|
455 do_check_eq(b1.operationsRequiringRestart & |
|
456 AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0); |
|
457 b1.uninstall(); |
|
458 |
|
459 do_check_bootstrappedPref(check_test_7); |
|
460 }); |
|
461 } |
|
462 |
|
463 function check_test_7() { |
|
464 ensure_test_completed(); |
|
465 do_check_eq(getInstalledVersion(), 0); |
|
466 do_check_eq(getActiveVersion(), 0); |
|
467 do_check_eq(getShutdownReason(), ADDON_UNINSTALL); |
|
468 do_check_eq(getShutdownNewVersion(), 0); |
|
469 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "2.0"); |
|
470 |
|
471 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", callback_soon(function(b1) { |
|
472 do_check_eq(b1, null); |
|
473 |
|
474 restartManager(); |
|
475 |
|
476 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(newb1) { |
|
477 do_check_eq(newb1, null); |
|
478 |
|
479 do_check_bootstrappedPref(run_test_8); |
|
480 }); |
|
481 })); |
|
482 } |
|
483 |
|
484 // Test that a bootstrapped extension dropped into the profile loads properly |
|
485 // on startup and doesn't cause an EM restart |
|
486 function run_test_8() { |
|
487 shutdownManager(); |
|
488 |
|
489 manuallyInstall(do_get_addon("test_bootstrap1_1"), profileDir, |
|
490 "bootstrap1@tests.mozilla.org"); |
|
491 |
|
492 startupManager(false); |
|
493 |
|
494 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
495 do_check_neq(b1, null); |
|
496 do_check_eq(b1.version, "1.0"); |
|
497 do_check_false(b1.appDisabled); |
|
498 do_check_false(b1.userDisabled); |
|
499 do_check_true(b1.isActive); |
|
500 do_check_eq(getInstalledVersion(), 1); |
|
501 do_check_eq(getActiveVersion(), 1); |
|
502 do_check_eq(getStartupReason(), ADDON_INSTALL); |
|
503 do_check_eq(getStartupOldVersion(), 0); |
|
504 do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
505 |
|
506 do_check_bootstrappedPref(run_test_9); |
|
507 }); |
|
508 } |
|
509 |
|
510 // Test that items detected as removed during startup get removed properly |
|
511 function run_test_9() { |
|
512 shutdownManager(); |
|
513 |
|
514 manuallyUninstall(profileDir, "bootstrap1@tests.mozilla.org"); |
|
515 |
|
516 startupManager(false); |
|
517 |
|
518 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
519 do_check_eq(b1, null); |
|
520 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
521 |
|
522 do_check_bootstrappedPref(run_test_10); |
|
523 }); |
|
524 } |
|
525 |
|
526 |
|
527 // Tests that installing a downgrade sends the right reason |
|
528 function run_test_10() { |
|
529 resetPrefs(); |
|
530 prepare_test({ }, [ |
|
531 "onNewInstall" |
|
532 ]); |
|
533 |
|
534 AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_2"), function(install) { |
|
535 ensure_test_completed(); |
|
536 |
|
537 do_check_neq(install, null); |
|
538 do_check_eq(install.type, "extension"); |
|
539 do_check_eq(install.version, "2.0"); |
|
540 do_check_eq(install.name, "Test Bootstrap 1"); |
|
541 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
542 do_check_true(install.addon.hasResource("install.rdf")); |
|
543 do_check_true(install.addon.hasResource("bootstrap.js")); |
|
544 do_check_false(install.addon.hasResource("foo.bar")); |
|
545 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "2.0"); |
|
546 |
|
547 waitForPref("bootstraptest.startup_reason", check_test_10_pt1); |
|
548 prepare_test({ |
|
549 "bootstrap1@tests.mozilla.org": [ |
|
550 ["onInstalling", false], |
|
551 "onInstalled" |
|
552 ] |
|
553 }, [ |
|
554 "onInstallStarted", |
|
555 "onInstallEnded", |
|
556 ], function() { |
|
557 do_print("Waiting for startup of bootstrap1_2"); |
|
558 }); |
|
559 install.install(); |
|
560 }); |
|
561 } |
|
562 |
|
563 function check_test_10_pt1() { |
|
564 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
565 do_check_neq(b1, null); |
|
566 do_check_eq(b1.version, "2.0"); |
|
567 do_check_false(b1.appDisabled); |
|
568 do_check_false(b1.userDisabled); |
|
569 do_check_true(b1.isActive); |
|
570 do_check_eq(getInstalledVersion(), 2); |
|
571 do_check_eq(getActiveVersion(), 2); |
|
572 do_check_eq(getStartupReason(), ADDON_INSTALL); |
|
573 do_check_eq(getStartupOldVersion(), 0); |
|
574 do_check_true(b1.hasResource("install.rdf")); |
|
575 do_check_true(b1.hasResource("bootstrap.js")); |
|
576 do_check_false(b1.hasResource("foo.bar")); |
|
577 do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "2.0"); |
|
578 |
|
579 prepare_test({ }, [ |
|
580 "onNewInstall" |
|
581 ]); |
|
582 |
|
583 AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_1"), function(install) { |
|
584 ensure_test_completed(); |
|
585 |
|
586 do_check_neq(install, null); |
|
587 do_check_eq(install.type, "extension"); |
|
588 do_check_eq(install.version, "1.0"); |
|
589 do_check_eq(install.name, "Test Bootstrap 1"); |
|
590 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
591 |
|
592 waitForPref("bootstraptest.startup_reason", check_test_10_pt2); |
|
593 prepare_test({ |
|
594 "bootstrap1@tests.mozilla.org": [ |
|
595 ["onInstalling", false], |
|
596 "onInstalled" |
|
597 ] |
|
598 }, [ |
|
599 "onInstallStarted", |
|
600 "onInstallEnded", |
|
601 ], function() { }); |
|
602 install.install(); |
|
603 }); |
|
604 }); |
|
605 } |
|
606 |
|
607 function check_test_10_pt2() { |
|
608 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
609 do_check_neq(b1, null); |
|
610 do_check_eq(b1.version, "1.0"); |
|
611 do_check_false(b1.appDisabled); |
|
612 do_check_false(b1.userDisabled); |
|
613 do_check_true(b1.isActive); |
|
614 do_check_eq(getInstalledVersion(), 1); |
|
615 do_check_eq(getActiveVersion(), 1); |
|
616 do_check_eq(getStartupReason(), ADDON_DOWNGRADE); |
|
617 do_check_eq(getInstallOldVersion(), 2); |
|
618 do_check_eq(getStartupOldVersion(), 2); |
|
619 do_check_eq(getShutdownReason(), ADDON_DOWNGRADE); |
|
620 do_check_eq(getShutdownNewVersion(), 1); |
|
621 do_check_eq(getUninstallNewVersion(), 1); |
|
622 do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
623 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "2.0"); |
|
624 |
|
625 do_check_bootstrappedPref(run_test_11); |
|
626 }); |
|
627 } |
|
628 |
|
629 // Tests that uninstalling a disabled add-on still calls the uninstall method |
|
630 function run_test_11() { |
|
631 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
632 prepare_test({ |
|
633 "bootstrap1@tests.mozilla.org": [ |
|
634 ["onDisabling", false], |
|
635 "onDisabled", |
|
636 ["onUninstalling", false], |
|
637 "onUninstalled" |
|
638 ] |
|
639 }); |
|
640 |
|
641 b1.userDisabled = true; |
|
642 |
|
643 do_check_eq(getInstalledVersion(), 1); |
|
644 do_check_eq(getActiveVersion(), 0); |
|
645 do_check_eq(getShutdownReason(), ADDON_DISABLE); |
|
646 do_check_eq(getShutdownNewVersion(), 0); |
|
647 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
648 |
|
649 b1.uninstall(); |
|
650 |
|
651 check_test_11(); |
|
652 }); |
|
653 } |
|
654 |
|
655 function check_test_11() { |
|
656 ensure_test_completed(); |
|
657 do_check_eq(getInstalledVersion(), 0); |
|
658 do_check_eq(getActiveVersion(), 0); |
|
659 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
660 |
|
661 do_check_bootstrappedPref(run_test_12); |
|
662 } |
|
663 |
|
664 // Tests that bootstrapped extensions are correctly loaded even if the app is |
|
665 // upgraded at the same time |
|
666 function run_test_12() { |
|
667 shutdownManager(); |
|
668 |
|
669 manuallyInstall(do_get_addon("test_bootstrap1_1"), profileDir, |
|
670 "bootstrap1@tests.mozilla.org"); |
|
671 |
|
672 startupManager(true); |
|
673 |
|
674 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
675 do_check_neq(b1, null); |
|
676 do_check_eq(b1.version, "1.0"); |
|
677 do_check_false(b1.appDisabled); |
|
678 do_check_false(b1.userDisabled); |
|
679 do_check_true(b1.isActive); |
|
680 do_check_eq(getInstalledVersion(), 1); |
|
681 do_check_eq(getActiveVersion(), 1); |
|
682 do_check_eq(getStartupReason(), ADDON_INSTALL); |
|
683 do_check_eq(getStartupOldVersion(), 0); |
|
684 do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
685 |
|
686 b1.uninstall(); |
|
687 do_execute_soon(test_12_restart); |
|
688 }); |
|
689 } |
|
690 |
|
691 function test_12_restart() { |
|
692 restartManager(); |
|
693 do_check_bootstrappedPref(run_test_13); |
|
694 } |
|
695 |
|
696 |
|
697 // Tests that installing a bootstrapped extension with an invalid application |
|
698 // entry doesn't call it's startup method |
|
699 function run_test_13() { |
|
700 prepare_test({ }, [ |
|
701 "onNewInstall" |
|
702 ]); |
|
703 |
|
704 AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_3"), function(install) { |
|
705 ensure_test_completed(); |
|
706 |
|
707 do_check_neq(install, null); |
|
708 do_check_eq(install.type, "extension"); |
|
709 do_check_eq(install.version, "3.0"); |
|
710 do_check_eq(install.name, "Test Bootstrap 1"); |
|
711 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
712 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0"); |
|
713 |
|
714 prepare_test({ |
|
715 "bootstrap1@tests.mozilla.org": [ |
|
716 ["onInstalling", false], |
|
717 "onInstalled" |
|
718 ] |
|
719 }, [ |
|
720 "onInstallStarted", |
|
721 "onInstallEnded", |
|
722 ], callback_soon(check_test_13)); |
|
723 install.install(); |
|
724 }); |
|
725 } |
|
726 |
|
727 function check_test_13() { |
|
728 AddonManager.getAllInstalls(function(installs) { |
|
729 // There should be no active installs now since the install completed and |
|
730 // doesn't require a restart. |
|
731 do_check_eq(installs.length, 0); |
|
732 |
|
733 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
734 do_check_neq(b1, null); |
|
735 do_check_eq(b1.version, "3.0"); |
|
736 do_check_true(b1.appDisabled); |
|
737 do_check_false(b1.userDisabled); |
|
738 do_check_false(b1.isActive); |
|
739 do_check_eq(getInstalledVersion(), 3); // We call install even for disabled add-ons |
|
740 do_check_eq(getActiveVersion(), 0); // Should not have called startup though |
|
741 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0"); |
|
742 |
|
743 do_execute_soon(test_13_restart); |
|
744 }); |
|
745 }); |
|
746 } |
|
747 |
|
748 function test_13_restart() { |
|
749 restartManager(); |
|
750 |
|
751 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
752 do_check_neq(b1, null); |
|
753 do_check_eq(b1.version, "3.0"); |
|
754 do_check_true(b1.appDisabled); |
|
755 do_check_false(b1.userDisabled); |
|
756 do_check_false(b1.isActive); |
|
757 do_check_eq(getInstalledVersion(), 3); // We call install even for disabled add-ons |
|
758 do_check_eq(getActiveVersion(), 0); // Should not have called startup though |
|
759 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0"); |
|
760 |
|
761 do_check_bootstrappedPref(function() { |
|
762 b1.uninstall(); |
|
763 do_execute_soon(run_test_14); |
|
764 }); |
|
765 }); |
|
766 } |
|
767 |
|
768 // Tests that a bootstrapped extension with an invalid target application entry |
|
769 // does not get loaded when detected during startup |
|
770 function run_test_14() { |
|
771 restartManager(); |
|
772 |
|
773 shutdownManager(); |
|
774 |
|
775 manuallyInstall(do_get_addon("test_bootstrap1_3"), profileDir, |
|
776 "bootstrap1@tests.mozilla.org"); |
|
777 |
|
778 startupManager(false); |
|
779 |
|
780 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
781 do_check_neq(b1, null); |
|
782 do_check_eq(b1.version, "3.0"); |
|
783 do_check_true(b1.appDisabled); |
|
784 do_check_false(b1.userDisabled); |
|
785 do_check_false(b1.isActive); |
|
786 do_check_eq(getInstalledVersion(), 3); // We call install even for disabled add-ons |
|
787 do_check_eq(getActiveVersion(), 0); // Should not have called startup though |
|
788 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0"); |
|
789 |
|
790 do_check_bootstrappedPref(function() { |
|
791 b1.uninstall(); |
|
792 |
|
793 run_test_15(); |
|
794 }); |
|
795 }); |
|
796 } |
|
797 |
|
798 // Tests that upgrading a disabled bootstrapped extension still calls uninstall |
|
799 // and install but doesn't startup the new version |
|
800 function run_test_15() { |
|
801 resetPrefs(); |
|
802 waitForPref("bootstraptest.startup_reason", function test_15_after_startup() { |
|
803 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
804 do_check_neq(b1, null); |
|
805 do_check_eq(b1.version, "1.0"); |
|
806 do_check_false(b1.appDisabled); |
|
807 do_check_false(b1.userDisabled); |
|
808 do_check_true(b1.isActive); |
|
809 do_check_eq(getInstalledVersion(), 1); |
|
810 do_check_eq(getActiveVersion(), 1); |
|
811 |
|
812 b1.userDisabled = true; |
|
813 do_check_false(b1.isActive); |
|
814 do_check_eq(getInstalledVersion(), 1); |
|
815 do_check_eq(getActiveVersion(), 0); |
|
816 |
|
817 prepare_test({ }, [ |
|
818 "onNewInstall" |
|
819 ]); |
|
820 |
|
821 AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_2"), function(install) { |
|
822 ensure_test_completed(); |
|
823 |
|
824 do_check_neq(install, null); |
|
825 do_check_true(install.addon.userDisabled); |
|
826 |
|
827 prepare_test({ |
|
828 "bootstrap1@tests.mozilla.org": [ |
|
829 ["onInstalling", false], |
|
830 "onInstalled" |
|
831 ] |
|
832 }, [ |
|
833 "onInstallStarted", |
|
834 "onInstallEnded", |
|
835 ], callback_soon(check_test_15)); |
|
836 install.install(); |
|
837 }); |
|
838 }); |
|
839 }); |
|
840 installAllFiles([do_get_addon("test_bootstrap1_1")], function test_15_addon_installed() { }); |
|
841 } |
|
842 |
|
843 function check_test_15() { |
|
844 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
845 do_check_neq(b1, null); |
|
846 do_check_eq(b1.version, "2.0"); |
|
847 do_check_false(b1.appDisabled); |
|
848 do_check_true(b1.userDisabled); |
|
849 do_check_false(b1.isActive); |
|
850 do_check_eq(getInstalledVersion(), 2); |
|
851 do_check_eq(getActiveVersion(), 0); |
|
852 |
|
853 do_check_bootstrappedPref(function() { |
|
854 restartManager(); |
|
855 |
|
856 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
857 do_check_neq(b1, null); |
|
858 do_check_eq(b1.version, "2.0"); |
|
859 do_check_false(b1.appDisabled); |
|
860 do_check_true(b1.userDisabled); |
|
861 do_check_false(b1.isActive); |
|
862 do_check_eq(getInstalledVersion(), 2); |
|
863 do_check_eq(getActiveVersion(), 0); |
|
864 |
|
865 b1.uninstall(); |
|
866 |
|
867 run_test_16(); |
|
868 }); |
|
869 }); |
|
870 }); |
|
871 } |
|
872 |
|
873 // Tests that bootstrapped extensions don't get loaded when in safe mode |
|
874 function run_test_16() { |
|
875 resetPrefs(); |
|
876 waitForPref("bootstraptest.startup_reason", function test_16_after_startup() { |
|
877 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", callback_soon(function(b1) { |
|
878 // Should have installed and started |
|
879 do_check_eq(getInstalledVersion(), 1); |
|
880 do_check_eq(getActiveVersion(), 1); |
|
881 do_check_true(b1.isActive); |
|
882 do_check_eq(b1.iconURL, "chrome://foo/skin/icon.png"); |
|
883 do_check_eq(b1.aboutURL, "chrome://foo/content/about.xul"); |
|
884 do_check_eq(b1.optionsURL, "chrome://foo/content/options.xul"); |
|
885 |
|
886 shutdownManager(); |
|
887 |
|
888 // Should have stopped |
|
889 do_check_eq(getInstalledVersion(), 1); |
|
890 do_check_eq(getActiveVersion(), 0); |
|
891 |
|
892 gAppInfo.inSafeMode = true; |
|
893 startupManager(false); |
|
894 |
|
895 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", callback_soon(function(b1) { |
|
896 // Should still be stopped |
|
897 do_check_eq(getInstalledVersion(), 1); |
|
898 do_check_eq(getActiveVersion(), 0); |
|
899 do_check_false(b1.isActive); |
|
900 do_check_eq(b1.iconURL, null); |
|
901 do_check_eq(b1.aboutURL, null); |
|
902 do_check_eq(b1.optionsURL, null); |
|
903 |
|
904 shutdownManager(); |
|
905 gAppInfo.inSafeMode = false; |
|
906 startupManager(false); |
|
907 |
|
908 // Should have started |
|
909 do_check_eq(getInstalledVersion(), 1); |
|
910 do_check_eq(getActiveVersion(), 1); |
|
911 |
|
912 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
913 b1.uninstall(); |
|
914 |
|
915 do_execute_soon(run_test_17); |
|
916 }); |
|
917 })); |
|
918 })); |
|
919 }); |
|
920 installAllFiles([do_get_addon("test_bootstrap1_1")], function() { }); |
|
921 } |
|
922 |
|
923 // Check that a bootstrapped extension in a non-profile location is loaded |
|
924 function run_test_17() { |
|
925 shutdownManager(); |
|
926 |
|
927 manuallyInstall(do_get_addon("test_bootstrap1_1"), userExtDir, |
|
928 "bootstrap1@tests.mozilla.org"); |
|
929 |
|
930 resetPrefs(); |
|
931 startupManager(); |
|
932 |
|
933 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
934 // Should have installed and started |
|
935 do_check_eq(getInstalledVersion(), 1); |
|
936 do_check_eq(getActiveVersion(), 1); |
|
937 do_check_neq(b1, null); |
|
938 do_check_eq(b1.version, "1.0"); |
|
939 do_check_true(b1.isActive); |
|
940 |
|
941 do_check_bootstrappedPref(run_test_18); |
|
942 }); |
|
943 } |
|
944 |
|
945 // Check that installing a new bootstrapped extension in the profile replaces |
|
946 // the existing one |
|
947 function run_test_18() { |
|
948 resetPrefs(); |
|
949 waitForPref("bootstraptest.startup_reason", function test_16_after_startup() { |
|
950 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
951 // Should have installed and started |
|
952 do_check_eq(getInstalledVersion(), 2); |
|
953 do_check_eq(getActiveVersion(), 2); |
|
954 do_check_neq(b1, null); |
|
955 do_check_eq(b1.version, "2.0"); |
|
956 do_check_true(b1.isActive); |
|
957 |
|
958 do_check_eq(getShutdownReason(), ADDON_UPGRADE); |
|
959 do_check_eq(getUninstallReason(), ADDON_UPGRADE); |
|
960 do_check_eq(getInstallReason(), ADDON_UPGRADE); |
|
961 do_check_eq(getStartupReason(), ADDON_UPGRADE); |
|
962 |
|
963 do_check_eq(getShutdownNewVersion(), 2); |
|
964 do_check_eq(getUninstallNewVersion(), 2); |
|
965 do_check_eq(getInstallOldVersion(), 1); |
|
966 do_check_eq(getStartupOldVersion(), 1); |
|
967 |
|
968 do_check_bootstrappedPref(run_test_19); |
|
969 }); |
|
970 }); |
|
971 installAllFiles([do_get_addon("test_bootstrap1_2")], function() { }); |
|
972 } |
|
973 |
|
974 // Check that uninstalling the profile version reveals the non-profile one |
|
975 function run_test_19() { |
|
976 resetPrefs(); |
|
977 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
978 // The revealed add-on gets activated asynchronously |
|
979 prepare_test({ |
|
980 "bootstrap1@tests.mozilla.org": [ |
|
981 ["onUninstalling", false], |
|
982 "onUninstalled", |
|
983 ["onInstalling", false], |
|
984 "onInstalled" |
|
985 ] |
|
986 }, [], check_test_19); |
|
987 |
|
988 b1.uninstall(); |
|
989 }); |
|
990 } |
|
991 |
|
992 function check_test_19() { |
|
993 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
994 // Should have reverted to the older version |
|
995 do_check_eq(getInstalledVersion(), 1); |
|
996 do_check_eq(getActiveVersion(), 1); |
|
997 do_check_neq(b1, null); |
|
998 do_check_eq(b1.version, "1.0"); |
|
999 do_check_true(b1.isActive); |
|
1000 |
|
1001 // TODO these reasons really should be ADDON_DOWNGRADE (bug 607818) |
|
1002 do_check_eq(getShutdownReason(), ADDON_UNINSTALL); |
|
1003 do_check_eq(getUninstallReason(), ADDON_UNINSTALL); |
|
1004 do_check_eq(getInstallReason(), ADDON_INSTALL); |
|
1005 do_check_eq(getStartupReason(), ADDON_INSTALL); |
|
1006 |
|
1007 do_check_eq(getShutdownNewVersion(), 0); |
|
1008 do_check_eq(getUninstallNewVersion(), 0); |
|
1009 do_check_eq(getInstallOldVersion(), 0); |
|
1010 do_check_eq(getStartupOldVersion(), 0); |
|
1011 |
|
1012 do_check_bootstrappedPref(run_test_20); |
|
1013 }); |
|
1014 } |
|
1015 |
|
1016 // Check that a new profile extension detected at startup replaces the non-profile |
|
1017 // one |
|
1018 function run_test_20() { |
|
1019 resetPrefs(); |
|
1020 shutdownManager(); |
|
1021 |
|
1022 manuallyInstall(do_get_addon("test_bootstrap1_2"), profileDir, |
|
1023 "bootstrap1@tests.mozilla.org"); |
|
1024 |
|
1025 startupManager(); |
|
1026 |
|
1027 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
1028 // Should have installed and started |
|
1029 do_check_eq(getInstalledVersion(), 2); |
|
1030 do_check_eq(getActiveVersion(), 2); |
|
1031 do_check_neq(b1, null); |
|
1032 do_check_eq(b1.version, "2.0"); |
|
1033 do_check_true(b1.isActive); |
|
1034 |
|
1035 do_check_eq(getShutdownReason(), APP_SHUTDOWN); |
|
1036 do_check_eq(getUninstallReason(), ADDON_UPGRADE); |
|
1037 do_check_eq(getInstallReason(), ADDON_UPGRADE); |
|
1038 do_check_eq(getStartupReason(), APP_STARTUP); |
|
1039 |
|
1040 do_check_eq(getShutdownNewVersion(), 0); |
|
1041 do_check_eq(getUninstallNewVersion(), 2); |
|
1042 do_check_eq(getInstallOldVersion(), 1); |
|
1043 do_check_eq(getStartupOldVersion(), 0); |
|
1044 |
|
1045 do_execute_soon(run_test_21); |
|
1046 }); |
|
1047 } |
|
1048 |
|
1049 // Check that a detected removal reveals the non-profile one |
|
1050 function run_test_21() { |
|
1051 resetPrefs(); |
|
1052 shutdownManager(); |
|
1053 |
|
1054 manuallyUninstall(profileDir, "bootstrap1@tests.mozilla.org"); |
|
1055 |
|
1056 startupManager(); |
|
1057 |
|
1058 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
1059 // Should have installed and started |
|
1060 do_check_eq(getInstalledVersion(), 1); |
|
1061 do_check_eq(getActiveVersion(), 1); |
|
1062 do_check_neq(b1, null); |
|
1063 do_check_eq(b1.version, "1.0"); |
|
1064 do_check_true(b1.isActive); |
|
1065 |
|
1066 do_check_eq(getShutdownReason(), APP_SHUTDOWN); |
|
1067 do_check_eq(getShutdownNewVersion(), 0); |
|
1068 |
|
1069 // This won't be set as the bootstrap script was gone so we couldn't |
|
1070 // uninstall it properly |
|
1071 do_check_eq(getUninstallReason(), -1); |
|
1072 do_check_eq(getUninstallNewVersion(), -1); |
|
1073 |
|
1074 // TODO this reason should probably be ADDON_DOWNGRADE (bug 607818) |
|
1075 do_check_eq(getInstallReason(), ADDON_INSTALL); |
|
1076 do_check_eq(getInstallOldVersion(), 0); |
|
1077 |
|
1078 do_check_eq(getStartupReason(), APP_STARTUP); |
|
1079 do_check_eq(getStartupOldVersion(), 0); |
|
1080 |
|
1081 do_check_bootstrappedPref(function() { |
|
1082 manuallyUninstall(userExtDir, "bootstrap1@tests.mozilla.org"); |
|
1083 |
|
1084 restartManager(); |
|
1085 run_test_22(); |
|
1086 }); |
|
1087 }); |
|
1088 } |
|
1089 |
|
1090 // Check that an upgrade from the filesystem is detected and applied correctly |
|
1091 function run_test_22() { |
|
1092 shutdownManager(); |
|
1093 |
|
1094 let file = manuallyInstall(do_get_addon("test_bootstrap1_1"), profileDir, |
|
1095 "bootstrap1@tests.mozilla.org"); |
|
1096 |
|
1097 // Make it look old so changes are detected |
|
1098 setExtensionModifiedTime(file, file.lastModifiedTime - 5000); |
|
1099 |
|
1100 startupManager(); |
|
1101 |
|
1102 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", callback_soon(function(b1) { |
|
1103 // Should have installed and started |
|
1104 do_check_eq(getInstalledVersion(), 1); |
|
1105 do_check_eq(getActiveVersion(), 1); |
|
1106 do_check_neq(b1, null); |
|
1107 do_check_eq(b1.version, "1.0"); |
|
1108 do_check_true(b1.isActive); |
|
1109 |
|
1110 resetPrefs(); |
|
1111 shutdownManager(); |
|
1112 |
|
1113 manuallyUninstall(profileDir, "bootstrap1@tests.mozilla.org"); |
|
1114 manuallyInstall(do_get_addon("test_bootstrap1_2"), profileDir, |
|
1115 "bootstrap1@tests.mozilla.org"); |
|
1116 |
|
1117 startupManager(); |
|
1118 |
|
1119 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
1120 // Should have installed and started |
|
1121 do_check_eq(getInstalledVersion(), 2); |
|
1122 do_check_eq(getActiveVersion(), 2); |
|
1123 do_check_neq(b1, null); |
|
1124 do_check_eq(b1.version, "2.0"); |
|
1125 do_check_true(b1.isActive); |
|
1126 |
|
1127 do_check_eq(getShutdownReason(), APP_SHUTDOWN); |
|
1128 do_check_eq(getShutdownNewVersion(), 0); |
|
1129 |
|
1130 // This won't be set as the bootstrap script was gone so we couldn't |
|
1131 // uninstall it properly |
|
1132 do_check_eq(getUninstallReason(), -1); |
|
1133 do_check_eq(getUninstallNewVersion(), -1); |
|
1134 |
|
1135 do_check_eq(getInstallReason(), ADDON_UPGRADE); |
|
1136 do_check_eq(getInstallOldVersion(), 1); |
|
1137 do_check_eq(getStartupReason(), APP_STARTUP); |
|
1138 do_check_eq(getStartupOldVersion(), 0); |
|
1139 |
|
1140 do_check_bootstrappedPref(function() { |
|
1141 b1.uninstall(); |
|
1142 |
|
1143 run_test_23(); |
|
1144 }); |
|
1145 }); |
|
1146 })); |
|
1147 } |
|
1148 |
|
1149 |
|
1150 // Tests that installing from a URL doesn't require a restart |
|
1151 function run_test_23() { |
|
1152 prepare_test({ }, [ |
|
1153 "onNewInstall" |
|
1154 ]); |
|
1155 |
|
1156 let url = "http://localhost:" + gPort + "/addons/test_bootstrap1_1.xpi"; |
|
1157 AddonManager.getInstallForURL(url, function(install) { |
|
1158 ensure_test_completed(); |
|
1159 |
|
1160 do_check_neq(install, null); |
|
1161 |
|
1162 prepare_test({ }, [ |
|
1163 "onDownloadStarted", |
|
1164 "onDownloadEnded" |
|
1165 ], function() { |
|
1166 do_check_eq(install.type, "extension"); |
|
1167 do_check_eq(install.version, "1.0"); |
|
1168 do_check_eq(install.name, "Test Bootstrap 1"); |
|
1169 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
1170 do_check_true(install.addon.hasResource("install.rdf")); |
|
1171 do_check_true(install.addon.hasResource("bootstrap.js")); |
|
1172 do_check_false(install.addon.hasResource("foo.bar")); |
|
1173 do_check_eq(install.addon.operationsRequiringRestart & |
|
1174 AddonManager.OP_NEEDS_RESTART_INSTALL, 0); |
|
1175 do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
1176 |
|
1177 let addon = install.addon; |
|
1178 prepare_test({ |
|
1179 "bootstrap1@tests.mozilla.org": [ |
|
1180 ["onInstalling", false], |
|
1181 "onInstalled" |
|
1182 ] |
|
1183 }, [ |
|
1184 "onInstallStarted", |
|
1185 "onInstallEnded", |
|
1186 ], function() { |
|
1187 do_check_true(addon.hasResource("install.rdf")); |
|
1188 do_check_bootstrappedPref(check_test_23); |
|
1189 }); |
|
1190 }); |
|
1191 install.install(); |
|
1192 }, "application/x-xpinstall"); |
|
1193 } |
|
1194 |
|
1195 function check_test_23() { |
|
1196 AddonManager.getAllInstalls(function(installs) { |
|
1197 // There should be no active installs now since the install completed and |
|
1198 // doesn't require a restart. |
|
1199 do_check_eq(installs.length, 0); |
|
1200 |
|
1201 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
1202 do_execute_soon(function test_23_after_startup() { |
|
1203 do_check_neq(b1, null); |
|
1204 do_check_eq(b1.version, "1.0"); |
|
1205 do_check_false(b1.appDisabled); |
|
1206 do_check_false(b1.userDisabled); |
|
1207 do_check_true(b1.isActive); |
|
1208 do_check_eq(getInstalledVersion(), 1); |
|
1209 do_check_eq(getActiveVersion(), 1); |
|
1210 do_check_eq(getStartupReason(), ADDON_INSTALL); |
|
1211 do_check_eq(getStartupOldVersion(), 0); |
|
1212 do_check_true(b1.hasResource("install.rdf")); |
|
1213 do_check_true(b1.hasResource("bootstrap.js")); |
|
1214 do_check_false(b1.hasResource("foo.bar")); |
|
1215 do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); |
|
1216 |
|
1217 let dir = do_get_addon_root_uri(profileDir, "bootstrap1@tests.mozilla.org"); |
|
1218 do_check_eq(b1.getResourceURI("bootstrap.js").spec, dir + "bootstrap.js"); |
|
1219 |
|
1220 AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(list) { |
|
1221 do_check_eq(list.length, 0); |
|
1222 |
|
1223 restartManager(); |
|
1224 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", callback_soon(function(b1) { |
|
1225 b1.uninstall(); |
|
1226 restartManager(); |
|
1227 |
|
1228 testserver.stop(run_test_24); |
|
1229 })); |
|
1230 })); |
|
1231 }); |
|
1232 }); |
|
1233 }); |
|
1234 } |
|
1235 |
|
1236 // Tests that we recover from a broken preference |
|
1237 function run_test_24() { |
|
1238 resetPrefs(); |
|
1239 do_print("starting 24"); |
|
1240 |
|
1241 Promise.all([promisePref("bootstraptest2.active_version"), |
|
1242 promiseInstall([do_get_addon("test_bootstrap1_1"), do_get_addon("test_bootstrap2_1")])]) |
|
1243 .then(function test_24_pref() { |
|
1244 do_print("test 24 got prefs"); |
|
1245 do_check_eq(getInstalledVersion(), 1); |
|
1246 do_check_eq(getActiveVersion(), 1); |
|
1247 do_check_eq(getInstalledVersion2(), 1); |
|
1248 do_check_eq(getActiveVersion2(), 1); |
|
1249 |
|
1250 resetPrefs(); |
|
1251 |
|
1252 restartManager(); |
|
1253 |
|
1254 do_check_eq(getInstalledVersion(), -1); |
|
1255 do_check_eq(getActiveVersion(), 1); |
|
1256 do_check_eq(getInstalledVersion2(), -1); |
|
1257 do_check_eq(getActiveVersion2(), 1); |
|
1258 |
|
1259 shutdownManager(); |
|
1260 |
|
1261 do_check_eq(getInstalledVersion(), -1); |
|
1262 do_check_eq(getActiveVersion(), 0); |
|
1263 do_check_eq(getInstalledVersion2(), -1); |
|
1264 do_check_eq(getActiveVersion2(), 0); |
|
1265 |
|
1266 // Break the preferece |
|
1267 let bootstrappedAddons = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons")); |
|
1268 bootstrappedAddons["bootstrap1@tests.mozilla.org"].descriptor += "foo"; |
|
1269 Services.prefs.setCharPref("extensions.bootstrappedAddons", JSON.stringify(bootstrappedAddons)); |
|
1270 |
|
1271 startupManager(false); |
|
1272 |
|
1273 do_check_eq(getInstalledVersion(), -1); |
|
1274 do_check_eq(getActiveVersion(), 1); |
|
1275 do_check_eq(getInstalledVersion2(), -1); |
|
1276 do_check_eq(getActiveVersion2(), 1); |
|
1277 |
|
1278 run_test_25(); |
|
1279 }); |
|
1280 } |
|
1281 |
|
1282 // Tests that updating from a bootstrappable add-on to a normal add-on calls |
|
1283 // the uninstall method |
|
1284 function run_test_25() { |
|
1285 waitForPref("bootstraptest.startup_reason", function test_25_after_pref() { |
|
1286 do_print("test 25 pref change detected"); |
|
1287 do_check_eq(getInstalledVersion(), 1); |
|
1288 do_check_eq(getActiveVersion(), 1); |
|
1289 |
|
1290 installAllFiles([do_get_addon("test_bootstrap1_4")], function() { |
|
1291 // Needs a restart to complete this so the old version stays running |
|
1292 do_check_eq(getInstalledVersion(), 1); |
|
1293 do_check_eq(getActiveVersion(), 1); |
|
1294 |
|
1295 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", callback_soon(function(b1) { |
|
1296 do_check_neq(b1, null); |
|
1297 do_check_eq(b1.version, "1.0"); |
|
1298 do_check_true(b1.isActive); |
|
1299 do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE)); |
|
1300 |
|
1301 restartManager(); |
|
1302 |
|
1303 do_check_eq(getInstalledVersion(), 0); |
|
1304 do_check_eq(getUninstallReason(), ADDON_UPGRADE); |
|
1305 do_check_eq(getUninstallNewVersion(), 4); |
|
1306 do_check_eq(getActiveVersion(), 0); |
|
1307 |
|
1308 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
1309 do_check_neq(b1, null); |
|
1310 do_check_eq(b1.version, "4.0"); |
|
1311 do_check_true(b1.isActive); |
|
1312 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); |
|
1313 |
|
1314 do_check_bootstrappedPref(run_test_26); |
|
1315 }); |
|
1316 })); |
|
1317 }); |
|
1318 }); |
|
1319 installAllFiles([do_get_addon("test_bootstrap1_1")], function test_25_installed() { |
|
1320 do_print("test 25 install done"); |
|
1321 }); |
|
1322 } |
|
1323 |
|
1324 // Tests that updating from a normal add-on to a bootstrappable add-on calls |
|
1325 // the install method |
|
1326 function run_test_26() { |
|
1327 installAllFiles([do_get_addon("test_bootstrap1_1")], function() { |
|
1328 // Needs a restart to complete this |
|
1329 do_check_eq(getInstalledVersion(), 0); |
|
1330 do_check_eq(getActiveVersion(), 0); |
|
1331 |
|
1332 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", callback_soon(function(b1) { |
|
1333 do_check_neq(b1, null); |
|
1334 do_check_eq(b1.version, "4.0"); |
|
1335 do_check_true(b1.isActive); |
|
1336 do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE)); |
|
1337 |
|
1338 restartManager(); |
|
1339 |
|
1340 do_check_eq(getInstalledVersion(), 1); |
|
1341 do_check_eq(getInstallReason(), ADDON_DOWNGRADE); |
|
1342 do_check_eq(getInstallOldVersion(), 4); |
|
1343 do_check_eq(getActiveVersion(), 1); |
|
1344 |
|
1345 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
1346 do_check_neq(b1, null); |
|
1347 do_check_eq(b1.version, "1.0"); |
|
1348 do_check_true(b1.isActive); |
|
1349 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); |
|
1350 |
|
1351 do_check_bootstrappedPref(run_test_27); |
|
1352 }); |
|
1353 })); |
|
1354 }); |
|
1355 } |
|
1356 |
|
1357 // Tests that updating from a bootstrappable add-on to a normal add-on while |
|
1358 // disabled calls the uninstall method |
|
1359 function run_test_27() { |
|
1360 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
1361 do_check_neq(b1, null); |
|
1362 b1.userDisabled = true; |
|
1363 do_check_eq(b1.version, "1.0"); |
|
1364 do_check_false(b1.isActive); |
|
1365 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); |
|
1366 do_check_eq(getInstalledVersion(), 1); |
|
1367 do_check_eq(getActiveVersion(), 0); |
|
1368 |
|
1369 installAllFiles([do_get_addon("test_bootstrap1_4")], function() { |
|
1370 // Updating disabled things happens immediately |
|
1371 do_check_eq(getInstalledVersion(), 0); |
|
1372 do_check_eq(getUninstallReason(), ADDON_UPGRADE); |
|
1373 do_check_eq(getUninstallNewVersion(), 4); |
|
1374 do_check_eq(getActiveVersion(), 0); |
|
1375 |
|
1376 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", callback_soon(function(b1) { |
|
1377 do_check_neq(b1, null); |
|
1378 do_check_eq(b1.version, "4.0"); |
|
1379 do_check_false(b1.isActive); |
|
1380 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); |
|
1381 |
|
1382 restartManager(); |
|
1383 |
|
1384 do_check_eq(getInstalledVersion(), 0); |
|
1385 do_check_eq(getActiveVersion(), 0); |
|
1386 |
|
1387 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
1388 do_check_neq(b1, null); |
|
1389 do_check_eq(b1.version, "4.0"); |
|
1390 do_check_false(b1.isActive); |
|
1391 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); |
|
1392 |
|
1393 do_check_bootstrappedPref(run_test_28); |
|
1394 }); |
|
1395 })); |
|
1396 }); |
|
1397 }); |
|
1398 } |
|
1399 |
|
1400 // Tests that updating from a normal add-on to a bootstrappable add-on when |
|
1401 // disabled calls the install method but not the startup method |
|
1402 function run_test_28() { |
|
1403 installAllFiles([do_get_addon("test_bootstrap1_1")], function() { |
|
1404 do_execute_soon(function bootstrap_disabled_downgrade_check() { |
|
1405 // Doesn't need a restart to complete this |
|
1406 do_check_eq(getInstalledVersion(), 1); |
|
1407 do_check_eq(getInstallReason(), ADDON_DOWNGRADE); |
|
1408 do_check_eq(getInstallOldVersion(), 4); |
|
1409 do_check_eq(getActiveVersion(), 0); |
|
1410 |
|
1411 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", callback_soon(function(b1) { |
|
1412 do_check_neq(b1, null); |
|
1413 do_check_eq(b1.version, "1.0"); |
|
1414 do_check_false(b1.isActive); |
|
1415 do_check_true(b1.userDisabled); |
|
1416 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); |
|
1417 |
|
1418 restartManager(); |
|
1419 |
|
1420 do_check_eq(getInstalledVersion(), 1); |
|
1421 do_check_eq(getActiveVersion(), 0); |
|
1422 |
|
1423 AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { |
|
1424 do_check_neq(b1, null); |
|
1425 do_check_true(b1.userDisabled); |
|
1426 b1.userDisabled = false; |
|
1427 do_check_eq(b1.version, "1.0"); |
|
1428 do_check_true(b1.isActive); |
|
1429 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); |
|
1430 do_check_eq(getInstalledVersion(), 1); |
|
1431 do_check_eq(getActiveVersion(), 1); |
|
1432 |
|
1433 do_check_bootstrappedPref(do_test_finished); |
|
1434 }); |
|
1435 })); |
|
1436 }); |
|
1437 }); |
|
1438 } |