|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // This verifies that bootstrappable add-ons can be used without restarts. |
|
6 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
7 |
|
8 // Enable loading extensions from the user scopes |
|
9 Services.prefs.setIntPref("extensions.enabledScopes", |
|
10 AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER); |
|
11 |
|
12 // The test extension uses an insecure update url. |
|
13 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); |
|
14 |
|
15 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
16 |
|
17 const profileDir = gProfD.clone(); |
|
18 profileDir.append("extensions"); |
|
19 const userExtDir = gProfD.clone(); |
|
20 userExtDir.append("extensions2"); |
|
21 userExtDir.append(gAppInfo.ID); |
|
22 registerDirectory("XREUSysExt", userExtDir.parent); |
|
23 |
|
24 Components.utils.import("resource://testing-common/httpd.js"); |
|
25 // Create and configure the HTTP server. |
|
26 var testserver = new HttpServer(); |
|
27 testserver.start(-1); |
|
28 gPort = testserver.identity.primaryPort; |
|
29 |
|
30 // register files with server |
|
31 testserver.registerDirectory("/addons/", do_get_file("addons")); |
|
32 mapFile("/data/test_dictionary.rdf", testserver); |
|
33 |
|
34 /** |
|
35 * This object is both a factory and an mozISpellCheckingEngine implementation (so, it |
|
36 * is de-facto a service). It's also an interface requestor that gives out |
|
37 * itself when asked for mozISpellCheckingEngine. |
|
38 */ |
|
39 var HunspellEngine = { |
|
40 dictionaryDirs: [], |
|
41 listener: null, |
|
42 |
|
43 QueryInterface: function hunspell_qi(iid) { |
|
44 if (iid.equals(Components.interfaces.nsISupports) || |
|
45 iid.equals(Components.interfaces.nsIFactory) || |
|
46 iid.equals(Components.interfaces.mozISpellCheckingEngine)) |
|
47 return this; |
|
48 throw Components.results.NS_ERROR_NO_INTERFACE; |
|
49 }, |
|
50 createInstance: function hunspell_ci(outer, iid) { |
|
51 if (outer) |
|
52 throw Components.results.NS_ERROR_NO_AGGREGATION; |
|
53 return this.QueryInterface(iid); |
|
54 }, |
|
55 lockFactory: function hunspell_lockf(lock) { |
|
56 throw Components.results.NS_ERROR_NOT_IMPLEMENTED; |
|
57 }, |
|
58 |
|
59 addDirectory: function hunspell_addDirectory(dir) { |
|
60 this.dictionaryDirs.push(dir); |
|
61 if (this.listener) |
|
62 this.listener("addDirectory"); |
|
63 }, |
|
64 |
|
65 removeDirectory: function hunspell_addDirectory(dir) { |
|
66 this.dictionaryDirs.splice(this.dictionaryDirs.indexOf(dir), 1); |
|
67 if (this.listener) |
|
68 this.listener("removeDirectory"); |
|
69 }, |
|
70 |
|
71 getInterface: function hunspell_gi(iid) { |
|
72 if (iid.equals(Components.interfaces.mozISpellCheckingEngine)) |
|
73 return this; |
|
74 throw Components.results.NS_ERROR_NO_INTERFACE; |
|
75 }, |
|
76 |
|
77 contractID: "@mozilla.org/spellchecker/engine;1", |
|
78 classID: Components.ID("{6f3c63bc-a4fd-449b-9a58-a2d9bd972cce}"), |
|
79 |
|
80 activate: function hunspell_activate() { |
|
81 this.origClassID = Components.manager.nsIComponentRegistrar |
|
82 .contractIDToCID(this.contractID); |
|
83 this.origFactory = Components.manager |
|
84 .getClassObject(Components.classes[this.contractID], |
|
85 Components.interfaces.nsIFactory); |
|
86 |
|
87 Components.manager.nsIComponentRegistrar |
|
88 .unregisterFactory(this.origClassID, this.origFactory); |
|
89 Components.manager.nsIComponentRegistrar.registerFactory(this.classID, |
|
90 "Test hunspell", this.contractID, this); |
|
91 }, |
|
92 |
|
93 deactivate: function hunspell_deactivate() { |
|
94 Components.manager.nsIComponentRegistrar.unregisterFactory(this.classID, this); |
|
95 Components.manager.nsIComponentRegistrar.registerFactory(this.origClassID, |
|
96 "Hunspell", this.contractID, this.origFactory); |
|
97 }, |
|
98 |
|
99 isDictionaryEnabled: function hunspell_isDictionaryEnabled(name) { |
|
100 return this.dictionaryDirs.some(function(dir) { |
|
101 var dic = dir.clone(); |
|
102 dic.append(name); |
|
103 return dic.exists(); |
|
104 }); |
|
105 } |
|
106 }; |
|
107 |
|
108 function run_test() { |
|
109 do_test_pending(); |
|
110 |
|
111 startupManager(); |
|
112 |
|
113 run_test_1(); |
|
114 } |
|
115 |
|
116 // Tests that installing doesn't require a restart |
|
117 function run_test_1() { |
|
118 prepare_test({ }, [ |
|
119 "onNewInstall" |
|
120 ]); |
|
121 |
|
122 HunspellEngine.activate(); |
|
123 |
|
124 AddonManager.getInstallForFile(do_get_addon("test_dictionary"), function(install) { |
|
125 ensure_test_completed(); |
|
126 |
|
127 do_check_neq(install, null); |
|
128 do_check_eq(install.type, "dictionary"); |
|
129 do_check_eq(install.version, "1.0"); |
|
130 do_check_eq(install.name, "Test Dictionary"); |
|
131 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
132 do_check_true(install.addon.hasResource("install.rdf")); |
|
133 do_check_false(install.addon.hasResource("bootstrap.js")); |
|
134 do_check_eq(install.addon.operationsRequiringRestart & |
|
135 AddonManager.OP_NEEDS_RESTART_INSTALL, 0); |
|
136 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
137 |
|
138 let addon = install.addon; |
|
139 prepare_test({ |
|
140 "ab-CD@dictionaries.addons.mozilla.org": [ |
|
141 ["onInstalling", false], |
|
142 "onInstalled" |
|
143 ] |
|
144 }, [ |
|
145 "onInstallStarted", |
|
146 "onInstallEnded", |
|
147 ], function() { |
|
148 do_check_true(addon.hasResource("install.rdf")); |
|
149 HunspellEngine.listener = function(aEvent) { |
|
150 HunspellEngine.listener = null; |
|
151 do_check_eq(aEvent, "addDirectory"); |
|
152 do_execute_soon(check_test_1); |
|
153 }; |
|
154 }); |
|
155 install.install(); |
|
156 }); |
|
157 } |
|
158 |
|
159 function check_test_1() { |
|
160 AddonManager.getAllInstalls(function(installs) { |
|
161 // There should be no active installs now since the install completed and |
|
162 // doesn't require a restart. |
|
163 do_check_eq(installs.length, 0); |
|
164 |
|
165 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
166 do_check_neq(b1, null); |
|
167 do_check_eq(b1.version, "1.0"); |
|
168 do_check_false(b1.appDisabled); |
|
169 do_check_false(b1.userDisabled); |
|
170 do_check_true(b1.isActive); |
|
171 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
172 do_check_true(b1.hasResource("install.rdf")); |
|
173 do_check_false(b1.hasResource("bootstrap.js")); |
|
174 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
175 |
|
176 let dir = do_get_addon_root_uri(profileDir, "ab-CD@dictionaries.addons.mozilla.org"); |
|
177 |
|
178 AddonManager.getAddonsWithOperationsByTypes(null, function(list) { |
|
179 do_check_eq(list.length, 0); |
|
180 |
|
181 run_test_2(); |
|
182 }); |
|
183 }); |
|
184 }); |
|
185 } |
|
186 |
|
187 // Tests that disabling doesn't require a restart |
|
188 function run_test_2() { |
|
189 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
190 prepare_test({ |
|
191 "ab-CD@dictionaries.addons.mozilla.org": [ |
|
192 ["onDisabling", false], |
|
193 "onDisabled" |
|
194 ] |
|
195 }); |
|
196 |
|
197 do_check_eq(b1.operationsRequiringRestart & |
|
198 AddonManager.OP_NEEDS_RESTART_DISABLE, 0); |
|
199 b1.userDisabled = true; |
|
200 ensure_test_completed(); |
|
201 |
|
202 do_check_neq(b1, null); |
|
203 do_check_eq(b1.version, "1.0"); |
|
204 do_check_false(b1.appDisabled); |
|
205 do_check_true(b1.userDisabled); |
|
206 do_check_false(b1.isActive); |
|
207 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
208 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
209 |
|
210 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) { |
|
211 do_check_neq(newb1, null); |
|
212 do_check_eq(newb1.version, "1.0"); |
|
213 do_check_false(newb1.appDisabled); |
|
214 do_check_true(newb1.userDisabled); |
|
215 do_check_false(newb1.isActive); |
|
216 |
|
217 do_execute_soon(run_test_3); |
|
218 }); |
|
219 }); |
|
220 } |
|
221 |
|
222 // Test that restarting doesn't accidentally re-enable |
|
223 function run_test_3() { |
|
224 shutdownManager(); |
|
225 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
226 startupManager(false); |
|
227 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
228 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
229 |
|
230 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
231 do_check_neq(b1, null); |
|
232 do_check_eq(b1.version, "1.0"); |
|
233 do_check_false(b1.appDisabled); |
|
234 do_check_true(b1.userDisabled); |
|
235 do_check_false(b1.isActive); |
|
236 |
|
237 run_test_4(); |
|
238 }); |
|
239 } |
|
240 |
|
241 // Tests that enabling doesn't require a restart |
|
242 function run_test_4() { |
|
243 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
244 prepare_test({ |
|
245 "ab-CD@dictionaries.addons.mozilla.org": [ |
|
246 ["onEnabling", false], |
|
247 "onEnabled" |
|
248 ] |
|
249 }); |
|
250 |
|
251 do_check_eq(b1.operationsRequiringRestart & |
|
252 AddonManager.OP_NEEDS_RESTART_ENABLE, 0); |
|
253 b1.userDisabled = false; |
|
254 ensure_test_completed(); |
|
255 |
|
256 do_check_neq(b1, null); |
|
257 do_check_eq(b1.version, "1.0"); |
|
258 do_check_false(b1.appDisabled); |
|
259 do_check_false(b1.userDisabled); |
|
260 do_check_true(b1.isActive); |
|
261 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
262 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
263 |
|
264 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) { |
|
265 do_check_neq(newb1, null); |
|
266 do_check_eq(newb1.version, "1.0"); |
|
267 do_check_false(newb1.appDisabled); |
|
268 do_check_false(newb1.userDisabled); |
|
269 do_check_true(newb1.isActive); |
|
270 |
|
271 do_execute_soon(run_test_5); |
|
272 }); |
|
273 }); |
|
274 } |
|
275 |
|
276 // Tests that a restart shuts down and restarts the add-on |
|
277 function run_test_5() { |
|
278 shutdownManager(); |
|
279 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
280 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
281 startupManager(false); |
|
282 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
283 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
284 |
|
285 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
286 do_check_neq(b1, null); |
|
287 do_check_eq(b1.version, "1.0"); |
|
288 do_check_false(b1.appDisabled); |
|
289 do_check_false(b1.userDisabled); |
|
290 do_check_true(b1.isActive); |
|
291 do_check_false(isExtensionInAddonsList(profileDir, b1.id)); |
|
292 |
|
293 run_test_7(); |
|
294 }); |
|
295 } |
|
296 |
|
297 // Tests that uninstalling doesn't require a restart |
|
298 function run_test_7() { |
|
299 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
300 prepare_test({ |
|
301 "ab-CD@dictionaries.addons.mozilla.org": [ |
|
302 ["onUninstalling", false], |
|
303 "onUninstalled" |
|
304 ] |
|
305 }); |
|
306 |
|
307 do_check_eq(b1.operationsRequiringRestart & |
|
308 AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0); |
|
309 b1.uninstall(); |
|
310 |
|
311 check_test_7(); |
|
312 }); |
|
313 } |
|
314 |
|
315 function check_test_7() { |
|
316 ensure_test_completed(); |
|
317 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
318 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
319 |
|
320 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", |
|
321 callback_soon(function(b1) { |
|
322 do_check_eq(b1, null); |
|
323 |
|
324 restartManager(); |
|
325 |
|
326 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) { |
|
327 do_check_eq(newb1, null); |
|
328 |
|
329 do_execute_soon(run_test_8); |
|
330 }); |
|
331 })); |
|
332 } |
|
333 |
|
334 // Test that a bootstrapped extension dropped into the profile loads properly |
|
335 // on startup and doesn't cause an EM restart |
|
336 function run_test_8() { |
|
337 shutdownManager(); |
|
338 |
|
339 let dir = profileDir.clone(); |
|
340 dir.append("ab-CD@dictionaries.addons.mozilla.org"); |
|
341 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); |
|
342 let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"]. |
|
343 createInstance(AM_Ci.nsIZipReader); |
|
344 zip.open(do_get_addon("test_dictionary")); |
|
345 dir.append("install.rdf"); |
|
346 zip.extract("install.rdf", dir); |
|
347 dir = dir.parent; |
|
348 dir.append("dictionaries"); |
|
349 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); |
|
350 dir.append("ab-CD.dic"); |
|
351 zip.extract("dictionaries/ab-CD.dic", dir); |
|
352 zip.close(); |
|
353 |
|
354 startupManager(false); |
|
355 |
|
356 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
357 do_check_neq(b1, null); |
|
358 do_check_eq(b1.version, "1.0"); |
|
359 do_check_false(b1.appDisabled); |
|
360 do_check_false(b1.userDisabled); |
|
361 do_check_true(b1.isActive); |
|
362 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
363 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
364 |
|
365 do_execute_soon(run_test_9); |
|
366 }); |
|
367 } |
|
368 |
|
369 // Test that items detected as removed during startup get removed properly |
|
370 function run_test_9() { |
|
371 shutdownManager(); |
|
372 |
|
373 let dir = profileDir.clone(); |
|
374 dir.append("ab-CD@dictionaries.addons.mozilla.org"); |
|
375 dir.remove(true); |
|
376 startupManager(false); |
|
377 |
|
378 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
379 do_check_eq(b1, null); |
|
380 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
381 |
|
382 do_execute_soon(run_test_12); |
|
383 }); |
|
384 } |
|
385 |
|
386 |
|
387 // Tests that bootstrapped extensions are correctly loaded even if the app is |
|
388 // upgraded at the same time |
|
389 function run_test_12() { |
|
390 shutdownManager(); |
|
391 |
|
392 let dir = profileDir.clone(); |
|
393 dir.append("ab-CD@dictionaries.addons.mozilla.org"); |
|
394 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); |
|
395 let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"]. |
|
396 createInstance(AM_Ci.nsIZipReader); |
|
397 zip.open(do_get_addon("test_dictionary")); |
|
398 dir.append("install.rdf"); |
|
399 zip.extract("install.rdf", dir); |
|
400 dir = dir.parent; |
|
401 dir.append("dictionaries"); |
|
402 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); |
|
403 dir.append("ab-CD.dic"); |
|
404 zip.extract("dictionaries/ab-CD.dic", dir); |
|
405 zip.close(); |
|
406 |
|
407 startupManager(true); |
|
408 |
|
409 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
410 do_check_neq(b1, null); |
|
411 do_check_eq(b1.version, "1.0"); |
|
412 do_check_false(b1.appDisabled); |
|
413 do_check_false(b1.userDisabled); |
|
414 do_check_true(b1.isActive); |
|
415 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
416 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
417 |
|
418 b1.uninstall(); |
|
419 do_execute_soon(run_test_16); |
|
420 }); |
|
421 } |
|
422 |
|
423 |
|
424 // Tests that bootstrapped extensions don't get loaded when in safe mode |
|
425 function run_test_16() { |
|
426 restartManager(); |
|
427 |
|
428 installAllFiles([do_get_addon("test_dictionary")], function() { |
|
429 // spin the event loop to let the addon finish starting |
|
430 do_execute_soon(function check_installed_dictionary() { |
|
431 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", |
|
432 callback_soon(function(b1) { |
|
433 // Should have installed and started |
|
434 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
435 |
|
436 shutdownManager(); |
|
437 |
|
438 // Should have stopped |
|
439 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
440 |
|
441 gAppInfo.inSafeMode = true; |
|
442 startupManager(false); |
|
443 |
|
444 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", |
|
445 callback_soon(function(b1) { |
|
446 // Should still be stopped |
|
447 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
448 do_check_false(b1.isActive); |
|
449 |
|
450 shutdownManager(); |
|
451 gAppInfo.inSafeMode = false; |
|
452 startupManager(false); |
|
453 |
|
454 // Should have started |
|
455 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
456 |
|
457 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
458 b1.uninstall(); |
|
459 |
|
460 do_execute_soon(run_test_17); |
|
461 }); |
|
462 })); |
|
463 })); |
|
464 }); |
|
465 }); |
|
466 } |
|
467 |
|
468 // Check that a bootstrapped extension in a non-profile location is loaded |
|
469 function run_test_17() { |
|
470 shutdownManager(); |
|
471 |
|
472 let dir = userExtDir.clone(); |
|
473 dir.append("ab-CD@dictionaries.addons.mozilla.org"); |
|
474 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); |
|
475 let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"]. |
|
476 createInstance(AM_Ci.nsIZipReader); |
|
477 zip.open(do_get_addon("test_dictionary")); |
|
478 dir.append("install.rdf"); |
|
479 zip.extract("install.rdf", dir); |
|
480 dir = dir.parent; |
|
481 dir.append("dictionaries"); |
|
482 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); |
|
483 dir.append("ab-CD.dic"); |
|
484 zip.extract("dictionaries/ab-CD.dic", dir); |
|
485 zip.close(); |
|
486 |
|
487 startupManager(); |
|
488 |
|
489 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", |
|
490 callback_soon(function(b1) { |
|
491 // Should have installed and started |
|
492 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
493 do_check_neq(b1, null); |
|
494 do_check_eq(b1.version, "1.0"); |
|
495 do_check_true(b1.isActive); |
|
496 |
|
497 // From run_test_21 |
|
498 dir = userExtDir.clone(); |
|
499 dir.append("ab-CD@dictionaries.addons.mozilla.org"); |
|
500 dir.remove(true); |
|
501 |
|
502 restartManager(); |
|
503 |
|
504 run_test_23(); |
|
505 })); |
|
506 } |
|
507 |
|
508 // Tests that installing from a URL doesn't require a restart |
|
509 function run_test_23() { |
|
510 prepare_test({ }, [ |
|
511 "onNewInstall" |
|
512 ]); |
|
513 |
|
514 let url = "http://localhost:" + gPort + "/addons/test_dictionary.xpi"; |
|
515 AddonManager.getInstallForURL(url, function(install) { |
|
516 ensure_test_completed(); |
|
517 |
|
518 do_check_neq(install, null); |
|
519 |
|
520 prepare_test({ }, [ |
|
521 "onDownloadStarted", |
|
522 "onDownloadEnded" |
|
523 ], function() { |
|
524 do_check_eq(install.type, "dictionary"); |
|
525 do_check_eq(install.version, "1.0"); |
|
526 do_check_eq(install.name, "Test Dictionary"); |
|
527 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
528 do_check_true(install.addon.hasResource("install.rdf")); |
|
529 do_check_false(install.addon.hasResource("bootstrap.js")); |
|
530 do_check_eq(install.addon.operationsRequiringRestart & |
|
531 AddonManager.OP_NEEDS_RESTART_INSTALL, 0); |
|
532 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
533 |
|
534 let addon = install.addon; |
|
535 prepare_test({ |
|
536 "ab-CD@dictionaries.addons.mozilla.org": [ |
|
537 ["onInstalling", false], |
|
538 "onInstalled" |
|
539 ] |
|
540 }, [ |
|
541 "onInstallStarted", |
|
542 "onInstallEnded", |
|
543 ], function() { |
|
544 do_check_true(addon.hasResource("install.rdf")); |
|
545 // spin to let the addon startup finish |
|
546 do_execute_soon(check_test_23); |
|
547 }); |
|
548 }); |
|
549 install.install(); |
|
550 }, "application/x-xpinstall"); |
|
551 } |
|
552 |
|
553 function check_test_23() { |
|
554 AddonManager.getAllInstalls(function(installs) { |
|
555 // There should be no active installs now since the install completed and |
|
556 // doesn't require a restart. |
|
557 do_check_eq(installs.length, 0); |
|
558 |
|
559 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
560 do_check_neq(b1, null); |
|
561 do_check_eq(b1.version, "1.0"); |
|
562 do_check_false(b1.appDisabled); |
|
563 do_check_false(b1.userDisabled); |
|
564 do_check_true(b1.isActive); |
|
565 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
566 do_check_true(b1.hasResource("install.rdf")); |
|
567 do_check_false(b1.hasResource("bootstrap.js")); |
|
568 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); |
|
569 |
|
570 let dir = do_get_addon_root_uri(profileDir, "ab-CD@dictionaries.addons.mozilla.org"); |
|
571 |
|
572 AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(list) { |
|
573 do_check_eq(list.length, 0); |
|
574 |
|
575 restartManager(); |
|
576 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
577 b1.uninstall(); |
|
578 do_execute_soon(run_test_25); |
|
579 }); |
|
580 })); |
|
581 }); |
|
582 }); |
|
583 } |
|
584 |
|
585 // Tests that updating from a bootstrappable add-on to a normal add-on calls |
|
586 // the uninstall method |
|
587 function run_test_25() { |
|
588 restartManager(); |
|
589 |
|
590 HunspellEngine.listener = function(aEvent) { |
|
591 HunspellEngine.listener = null; |
|
592 do_check_eq(aEvent, "addDirectory"); |
|
593 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
594 |
|
595 installAllFiles([do_get_addon("test_dictionary_2")], function test_25_installed2() { |
|
596 // Needs a restart to complete this so the old version stays running |
|
597 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
598 |
|
599 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", |
|
600 callback_soon(function(b1) { |
|
601 do_check_neq(b1, null); |
|
602 do_check_eq(b1.version, "1.0"); |
|
603 do_check_true(b1.isActive); |
|
604 do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE)); |
|
605 |
|
606 restartManager(); |
|
607 |
|
608 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
609 |
|
610 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
611 do_check_neq(b1, null); |
|
612 do_check_eq(b1.version, "2.0"); |
|
613 do_check_true(b1.isActive); |
|
614 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); |
|
615 |
|
616 do_execute_soon(run_test_26); |
|
617 }); |
|
618 })); |
|
619 }); |
|
620 }; |
|
621 |
|
622 installAllFiles([do_get_addon("test_dictionary")], function test_25_installed() { }); |
|
623 } |
|
624 |
|
625 // Tests that updating from a normal add-on to a bootstrappable add-on calls |
|
626 // the install method |
|
627 function run_test_26() { |
|
628 installAllFiles([do_get_addon("test_dictionary")], function test_26_install() { |
|
629 // Needs a restart to complete this |
|
630 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
631 |
|
632 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", |
|
633 callback_soon(function(b1) { |
|
634 do_check_neq(b1, null); |
|
635 do_check_eq(b1.version, "2.0"); |
|
636 do_check_true(b1.isActive); |
|
637 do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE)); |
|
638 |
|
639 restartManager(); |
|
640 |
|
641 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); |
|
642 |
|
643 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
644 do_check_neq(b1, null); |
|
645 do_check_eq(b1.version, "1.0"); |
|
646 do_check_true(b1.isActive); |
|
647 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); |
|
648 |
|
649 HunspellEngine.deactivate(); |
|
650 b1.uninstall(); |
|
651 do_execute_soon(run_test_27); |
|
652 }); |
|
653 })); |
|
654 }); |
|
655 } |
|
656 |
|
657 // Tests that an update check from a normal add-on to a bootstrappable add-on works |
|
658 function run_test_27() { |
|
659 restartManager(); |
|
660 writeInstallRDFForExtension({ |
|
661 id: "ab-CD@dictionaries.addons.mozilla.org", |
|
662 version: "1.0", |
|
663 updateURL: "http://localhost:" + gPort + "/data/test_dictionary.rdf", |
|
664 targetApplications: [{ |
|
665 id: "xpcshell@tests.mozilla.org", |
|
666 minVersion: "1", |
|
667 maxVersion: "1" |
|
668 }], |
|
669 name: "Test Dictionary", |
|
670 }, profileDir); |
|
671 restartManager(); |
|
672 |
|
673 prepare_test({ |
|
674 "ab-CD@dictionaries.addons.mozilla.org": [ |
|
675 "onInstalling" |
|
676 ] |
|
677 }, [ |
|
678 "onNewInstall", |
|
679 "onDownloadStarted", |
|
680 "onDownloadEnded", |
|
681 "onInstallStarted", |
|
682 "onInstallEnded" |
|
683 ], callback_soon(check_test_27)); |
|
684 |
|
685 AddonManagerPrivate.backgroundUpdateCheck(); |
|
686 } |
|
687 |
|
688 function check_test_27(install) { |
|
689 do_check_eq(install.existingAddon.pendingUpgrade.install, install); |
|
690 |
|
691 restartManager(); |
|
692 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { |
|
693 do_check_neq(b1, null); |
|
694 do_check_eq(b1.version, "2.0"); |
|
695 do_check_eq(b1.type, "dictionary"); |
|
696 b1.uninstall(); |
|
697 do_execute_soon(run_test_28); |
|
698 }); |
|
699 } |
|
700 |
|
701 // Tests that an update check from a bootstrappable add-on to a normal add-on works |
|
702 function run_test_28() { |
|
703 restartManager(); |
|
704 |
|
705 writeInstallRDFForExtension({ |
|
706 id: "ef@dictionaries.addons.mozilla.org", |
|
707 version: "1.0", |
|
708 type: "64", |
|
709 updateURL: "http://localhost:" + gPort + "/data/test_dictionary.rdf", |
|
710 targetApplications: [{ |
|
711 id: "xpcshell@tests.mozilla.org", |
|
712 minVersion: "1", |
|
713 maxVersion: "1" |
|
714 }], |
|
715 name: "Test Dictionary ef", |
|
716 }, profileDir); |
|
717 restartManager(); |
|
718 |
|
719 prepare_test({ |
|
720 "ef@dictionaries.addons.mozilla.org": [ |
|
721 "onInstalling" |
|
722 ] |
|
723 }, [ |
|
724 "onNewInstall", |
|
725 "onDownloadStarted", |
|
726 "onDownloadEnded", |
|
727 "onInstallStarted", |
|
728 "onInstallEnded" |
|
729 ], callback_soon(check_test_28)); |
|
730 |
|
731 AddonManagerPrivate.backgroundUpdateCheck(); |
|
732 } |
|
733 |
|
734 function check_test_28(install) { |
|
735 do_check_eq(install.existingAddon.pendingUpgrade.install, install); |
|
736 |
|
737 restartManager(); |
|
738 AddonManager.getAddonByID("ef@dictionaries.addons.mozilla.org", function(b2) { |
|
739 do_check_neq(b2, null); |
|
740 do_check_eq(b2.version, "2.0"); |
|
741 do_check_eq(b2.type, "extension"); |
|
742 b2.uninstall(); |
|
743 do_execute_soon(run_test_29); |
|
744 }); |
|
745 } |
|
746 |
|
747 // Tests that an update check from a bootstrappable add-on to a bootstrappable add-on works |
|
748 function run_test_29() { |
|
749 restartManager(); |
|
750 |
|
751 writeInstallRDFForExtension({ |
|
752 id: "gh@dictionaries.addons.mozilla.org", |
|
753 version: "1.0", |
|
754 type: "64", |
|
755 updateURL: "http://localhost:" + gPort + "/data/test_dictionary.rdf", |
|
756 targetApplications: [{ |
|
757 id: "xpcshell@tests.mozilla.org", |
|
758 minVersion: "1", |
|
759 maxVersion: "1" |
|
760 }], |
|
761 name: "Test Dictionary gh", |
|
762 }, profileDir); |
|
763 restartManager(); |
|
764 |
|
765 prepare_test({ |
|
766 "gh@dictionaries.addons.mozilla.org": [ |
|
767 ["onInstalling", false /* = no restart */], |
|
768 ["onInstalled", false] |
|
769 ] |
|
770 }, [ |
|
771 "onNewInstall", |
|
772 "onDownloadStarted", |
|
773 "onDownloadEnded", |
|
774 "onInstallStarted", |
|
775 "onInstallEnded" |
|
776 ], check_test_29); |
|
777 |
|
778 AddonManagerPrivate.backgroundUpdateCheck(); |
|
779 } |
|
780 |
|
781 function check_test_29(install) { |
|
782 AddonManager.getAddonByID("gh@dictionaries.addons.mozilla.org", function(b2) { |
|
783 do_check_neq(b2, null); |
|
784 do_check_eq(b2.version, "2.0"); |
|
785 do_check_eq(b2.type, "dictionary"); |
|
786 |
|
787 prepare_test({ |
|
788 "gh@dictionaries.addons.mozilla.org": [ |
|
789 ["onUninstalling", false], |
|
790 ["onUninstalled", false], |
|
791 ] |
|
792 }, [ |
|
793 ], callback_soon(finish_test_29)); |
|
794 |
|
795 b2.uninstall(); |
|
796 }); |
|
797 } |
|
798 |
|
799 function finish_test_29() { |
|
800 testserver.stop(do_test_finished); |
|
801 } |