|
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 const URI_EXTENSION_UPDATE_DIALOG = "chrome://mozapps/content/extensions/update.xul"; |
|
7 const PREF_EM_SHOW_MISMATCH_UI = "extensions.showMismatchUI"; |
|
8 |
|
9 // The test extension uses an insecure update url. |
|
10 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); |
|
11 |
|
12 const Cc = Components.classes; |
|
13 const Ci = Components.interfaces; |
|
14 const Cu = Components.utils; |
|
15 const Cr = Components.results; |
|
16 |
|
17 Cu.import("resource://testing-common/httpd.js"); |
|
18 var testserver; |
|
19 |
|
20 const profileDir = gProfD.clone(); |
|
21 profileDir.append("extensions"); |
|
22 |
|
23 var gInstallUpdate = false; |
|
24 var gCheckUpdates = false; |
|
25 |
|
26 // This will be called to show the compatibility update dialog. |
|
27 var WindowWatcher = { |
|
28 expected: false, |
|
29 arguments: null, |
|
30 |
|
31 openWindow: function(parent, url, name, features, arguments) { |
|
32 do_check_true(Services.startup.interrupted); |
|
33 do_check_eq(url, URI_EXTENSION_UPDATE_DIALOG); |
|
34 do_check_true(this.expected); |
|
35 this.expected = false; |
|
36 this.arguments = arguments.QueryInterface(AM_Ci.nsIVariant); |
|
37 |
|
38 var updated = !gCheckUpdates; |
|
39 if (gCheckUpdates) { |
|
40 AddonManager.getAddonByID("bug542391_6@tests.mozilla.org", function(a6) { |
|
41 a6.findUpdates({ |
|
42 onUpdateFinished: function() { |
|
43 AddonManagerPrivate.removeStartupChange("disabled", "bug542391_6@tests.mozilla.org"); |
|
44 updated = true; |
|
45 } |
|
46 }, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED); |
|
47 }); |
|
48 } |
|
49 |
|
50 var installed = !gInstallUpdate; |
|
51 if (gInstallUpdate) { |
|
52 // Simulate installing an update while in the dialog |
|
53 installAllFiles([do_get_addon("test_bug542391_3_2")], function() { |
|
54 AddonManagerPrivate.removeStartupChange("disabled", "bug542391_3@tests.mozilla.org"); |
|
55 AddonManagerPrivate.addStartupChange("updated", "bug542391_3@tests.mozilla.org"); |
|
56 installed = true; |
|
57 }); |
|
58 } |
|
59 |
|
60 // The dialog is meant to be opened modally and the install operation can be |
|
61 // asynchronous, so we must spin an event loop (like the modal window does) |
|
62 // until the install is complete |
|
63 let thr = AM_Cc["@mozilla.org/thread-manager;1"]. |
|
64 getService(AM_Ci.nsIThreadManager). |
|
65 mainThread; |
|
66 |
|
67 while (!installed || !updated) |
|
68 thr.processNextEvent(false); |
|
69 }, |
|
70 |
|
71 QueryInterface: function(iid) { |
|
72 if (iid.equals(Ci.nsIWindowWatcher) |
|
73 || iid.equals(Ci.nsISupports)) |
|
74 return this; |
|
75 |
|
76 throw Cr.NS_ERROR_NO_INTERFACE; |
|
77 } |
|
78 } |
|
79 |
|
80 var WindowWatcherFactory = { |
|
81 createInstance: function createInstance(outer, iid) { |
|
82 if (outer != null) |
|
83 throw Components.results.NS_ERROR_NO_AGGREGATION; |
|
84 return WindowWatcher.QueryInterface(iid); |
|
85 } |
|
86 }; |
|
87 |
|
88 var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); |
|
89 registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), |
|
90 "Fake Window Watcher", |
|
91 "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); |
|
92 |
|
93 function check_state_v1([a1, a2, a3, a4, a5, a6]) { |
|
94 do_check_neq(a1, null); |
|
95 do_check_false(a1.appDisabled); |
|
96 do_check_false(a1.userDisabled); |
|
97 do_check_true(a1.isActive); |
|
98 do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
|
99 |
|
100 do_check_neq(a2, null); |
|
101 do_check_false(a2.appDisabled); |
|
102 do_check_true(a2.userDisabled); |
|
103 do_check_false(a2.isActive); |
|
104 do_check_false(isExtensionInAddonsList(profileDir, a2.id)); |
|
105 |
|
106 do_check_neq(a3, null); |
|
107 do_check_false(a3.appDisabled); |
|
108 do_check_false(a3.userDisabled); |
|
109 do_check_true(a3.isActive); |
|
110 do_check_true(isExtensionInAddonsList(profileDir, a3.id)); |
|
111 do_check_eq(a3.version, "1.0"); |
|
112 |
|
113 do_check_neq(a4, null); |
|
114 do_check_false(a4.appDisabled); |
|
115 do_check_true(a4.userDisabled); |
|
116 do_check_false(a4.isActive); |
|
117 do_check_false(isExtensionInAddonsList(profileDir, a4.id)); |
|
118 |
|
119 do_check_neq(a5, null); |
|
120 do_check_false(a5.appDisabled); |
|
121 do_check_false(a5.userDisabled); |
|
122 do_check_true(a5.isActive); |
|
123 do_check_true(isExtensionInAddonsList(profileDir, a5.id)); |
|
124 |
|
125 do_check_neq(a6, null); |
|
126 do_check_false(a6.appDisabled); |
|
127 do_check_false(a6.userDisabled); |
|
128 do_check_true(a6.isActive); |
|
129 do_check_true(isExtensionInAddonsList(profileDir, a6.id)); |
|
130 } |
|
131 |
|
132 function check_state_v1_2([a1, a2, a3, a4, a5, a6]) { |
|
133 do_check_neq(a1, null); |
|
134 do_check_false(a1.appDisabled); |
|
135 do_check_false(a1.userDisabled); |
|
136 do_check_true(a1.isActive); |
|
137 do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
|
138 |
|
139 do_check_neq(a2, null); |
|
140 do_check_false(a2.appDisabled); |
|
141 do_check_true(a2.userDisabled); |
|
142 do_check_false(a2.isActive); |
|
143 do_check_false(isExtensionInAddonsList(profileDir, a2.id)); |
|
144 |
|
145 do_check_neq(a3, null); |
|
146 do_check_true(a3.appDisabled); |
|
147 do_check_false(a3.userDisabled); |
|
148 do_check_false(a3.isActive); |
|
149 do_check_false(isExtensionInAddonsList(profileDir, a3.id)); |
|
150 do_check_eq(a3.version, "2.0"); |
|
151 |
|
152 do_check_neq(a4, null); |
|
153 do_check_false(a4.appDisabled); |
|
154 do_check_true(a4.userDisabled); |
|
155 do_check_false(a4.isActive); |
|
156 do_check_false(isExtensionInAddonsList(profileDir, a4.id)); |
|
157 |
|
158 do_check_neq(a5, null); |
|
159 do_check_false(a5.appDisabled); |
|
160 do_check_false(a5.userDisabled); |
|
161 do_check_true(a5.isActive); |
|
162 do_check_true(isExtensionInAddonsList(profileDir, a5.id)); |
|
163 |
|
164 do_check_neq(a6, null); |
|
165 do_check_false(a6.appDisabled); |
|
166 do_check_false(a6.userDisabled); |
|
167 do_check_true(a6.isActive); |
|
168 do_check_true(isExtensionInAddonsList(profileDir, a6.id)); |
|
169 } |
|
170 |
|
171 function check_state_v2([a1, a2, a3, a4, a5, a6]) { |
|
172 do_check_neq(a1, null); |
|
173 do_check_true(a1.appDisabled); |
|
174 do_check_false(a1.userDisabled); |
|
175 do_check_false(a1.isActive); |
|
176 do_check_false(isExtensionInAddonsList(profileDir, a1.id)); |
|
177 |
|
178 do_check_neq(a2, null); |
|
179 do_check_false(a2.appDisabled); |
|
180 do_check_true(a2.userDisabled); |
|
181 do_check_false(a2.isActive); |
|
182 do_check_false(isExtensionInAddonsList(profileDir, a2.id)); |
|
183 |
|
184 do_check_neq(a3, null); |
|
185 do_check_false(a3.appDisabled); |
|
186 do_check_false(a3.userDisabled); |
|
187 do_check_true(a3.isActive); |
|
188 do_check_true(isExtensionInAddonsList(profileDir, a3.id)); |
|
189 do_check_eq(a3.version, "1.0"); |
|
190 |
|
191 do_check_neq(a4, null); |
|
192 do_check_false(a4.appDisabled); |
|
193 do_check_true(a4.userDisabled); |
|
194 do_check_false(a4.isActive); |
|
195 do_check_false(isExtensionInAddonsList(profileDir, a4.id)); |
|
196 |
|
197 do_check_neq(a5, null); |
|
198 do_check_false(a5.appDisabled); |
|
199 do_check_false(a5.userDisabled); |
|
200 do_check_true(a5.isActive); |
|
201 do_check_true(isExtensionInAddonsList(profileDir, a5.id)); |
|
202 |
|
203 do_check_neq(a6, null); |
|
204 do_check_false(a6.appDisabled); |
|
205 do_check_false(a6.userDisabled); |
|
206 do_check_true(a6.isActive); |
|
207 do_check_true(isExtensionInAddonsList(profileDir, a6.id)); |
|
208 } |
|
209 |
|
210 function check_state_v3([a1, a2, a3, a4, a5, a6]) { |
|
211 do_check_neq(a1, null); |
|
212 do_check_true(a1.appDisabled); |
|
213 do_check_false(a1.userDisabled); |
|
214 do_check_false(a1.isActive); |
|
215 do_check_false(isExtensionInAddonsList(profileDir, a1.id)); |
|
216 |
|
217 do_check_neq(a2, null); |
|
218 do_check_true(a2.appDisabled); |
|
219 do_check_true(a2.userDisabled); |
|
220 do_check_false(a2.isActive); |
|
221 do_check_false(isExtensionInAddonsList(profileDir, a2.id)); |
|
222 |
|
223 do_check_neq(a3, null); |
|
224 do_check_true(a3.appDisabled); |
|
225 do_check_false(a3.userDisabled); |
|
226 do_check_false(a3.isActive); |
|
227 do_check_false(isExtensionInAddonsList(profileDir, a3.id)); |
|
228 do_check_eq(a3.version, "1.0"); |
|
229 |
|
230 do_check_neq(a4, null); |
|
231 do_check_false(a4.appDisabled); |
|
232 do_check_true(a4.userDisabled); |
|
233 do_check_false(a4.isActive); |
|
234 do_check_false(isExtensionInAddonsList(profileDir, a4.id)); |
|
235 |
|
236 do_check_neq(a5, null); |
|
237 do_check_false(a5.appDisabled); |
|
238 do_check_false(a5.userDisabled); |
|
239 do_check_true(a5.isActive); |
|
240 do_check_true(isExtensionInAddonsList(profileDir, a5.id)); |
|
241 |
|
242 do_check_neq(a6, null); |
|
243 do_check_false(a6.appDisabled); |
|
244 do_check_false(a6.userDisabled); |
|
245 do_check_true(a6.isActive); |
|
246 do_check_true(isExtensionInAddonsList(profileDir, a6.id)); |
|
247 } |
|
248 |
|
249 function check_state_v3_2([a1, a2, a3, a4, a5, a6]) { |
|
250 do_check_neq(a1, null); |
|
251 do_check_true(a1.appDisabled); |
|
252 do_check_false(a1.userDisabled); |
|
253 do_check_false(a1.isActive); |
|
254 do_check_false(isExtensionInAddonsList(profileDir, a1.id)); |
|
255 |
|
256 do_check_neq(a2, null); |
|
257 do_check_true(a2.appDisabled); |
|
258 do_check_true(a2.userDisabled); |
|
259 do_check_false(a2.isActive); |
|
260 do_check_false(isExtensionInAddonsList(profileDir, a2.id)); |
|
261 |
|
262 do_check_neq(a3, null); |
|
263 do_check_false(a3.appDisabled); |
|
264 do_check_false(a3.userDisabled); |
|
265 do_check_true(a3.isActive); |
|
266 do_check_true(isExtensionInAddonsList(profileDir, a3.id)); |
|
267 do_check_eq(a3.version, "2.0"); |
|
268 |
|
269 do_check_neq(a4, null); |
|
270 do_check_false(a4.appDisabled); |
|
271 do_check_true(a4.userDisabled); |
|
272 do_check_false(a4.isActive); |
|
273 do_check_false(isExtensionInAddonsList(profileDir, a4.id)); |
|
274 |
|
275 do_check_neq(a5, null); |
|
276 do_check_false(a5.appDisabled); |
|
277 do_check_false(a5.userDisabled); |
|
278 do_check_true(a5.isActive); |
|
279 do_check_true(isExtensionInAddonsList(profileDir, a5.id)); |
|
280 |
|
281 do_check_neq(a6, null); |
|
282 do_check_false(a6.appDisabled); |
|
283 do_check_false(a6.userDisabled); |
|
284 do_check_true(a6.isActive); |
|
285 do_check_true(isExtensionInAddonsList(profileDir, a6.id)); |
|
286 } |
|
287 |
|
288 // Install all the test add-ons, disable two of them and "upgrade" the app to |
|
289 // version 2 which will appDisable one. |
|
290 function run_test() { |
|
291 do_test_pending(); |
|
292 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); |
|
293 |
|
294 Services.prefs.setBoolPref(PREF_EM_SHOW_MISMATCH_UI, true); |
|
295 |
|
296 // Add an extension to the profile to make sure the dialog doesn't show up |
|
297 // on new profiles |
|
298 var dest = writeInstallRDFForExtension({ |
|
299 id: "addon1@tests.mozilla.org", |
|
300 version: "1.0", |
|
301 targetApplications: [{ |
|
302 id: "xpcshell@tests.mozilla.org", |
|
303 minVersion: "1", |
|
304 maxVersion: "1" |
|
305 }], |
|
306 name: "Test Addon 1", |
|
307 }, profileDir); |
|
308 |
|
309 // Create and configure the HTTP server. |
|
310 testserver = new HttpServer(); |
|
311 testserver.registerDirectory("/data/", do_get_file("data")); |
|
312 testserver.registerDirectory("/addons/", do_get_file("addons")); |
|
313 testserver.start(4444); |
|
314 |
|
315 startupManager(); |
|
316 |
|
317 dest.remove(true); |
|
318 |
|
319 installAllFiles([do_get_addon("test_bug542391_1"), |
|
320 do_get_addon("test_bug542391_2"), |
|
321 do_get_addon("test_bug542391_3_1"), |
|
322 do_get_addon("test_bug542391_4"), |
|
323 do_get_addon("test_bug542391_5"), |
|
324 do_get_addon("test_bug542391_6")], function install_and_restart() { |
|
325 |
|
326 restartManager(); |
|
327 check_startup_changes("installed", []); |
|
328 check_startup_changes("updated", []); |
|
329 check_startup_changes("uninstalled", ["addon1@tests.mozilla.org"]); |
|
330 check_startup_changes("disabled", []); |
|
331 check_startup_changes("enabled", []); |
|
332 |
|
333 AddonManager.getAddonsByIDs(["bug542391_2@tests.mozilla.org", |
|
334 "bug542391_4@tests.mozilla.org"], |
|
335 callback_soon(function disable_and_restart([a2, a4]) { |
|
336 do_check_true(a2 != null && a4 != null); |
|
337 a2.userDisabled = true; |
|
338 a4.userDisabled = true; |
|
339 restartManager(); |
|
340 check_startup_changes("installed", []); |
|
341 check_startup_changes("updated", []); |
|
342 check_startup_changes("uninstalled", []); |
|
343 check_startup_changes("disabled", []); |
|
344 check_startup_changes("enabled", []); |
|
345 |
|
346 AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", |
|
347 "bug542391_2@tests.mozilla.org", |
|
348 "bug542391_3@tests.mozilla.org", |
|
349 "bug542391_4@tests.mozilla.org", |
|
350 "bug542391_5@tests.mozilla.org", |
|
351 "bug542391_6@tests.mozilla.org"], |
|
352 callback_soon(function(addons) { |
|
353 check_state_v1(addons); |
|
354 |
|
355 WindowWatcher.expected = true; |
|
356 restartManager("2"); |
|
357 check_startup_changes("installed", []); |
|
358 check_startup_changes("updated", []); |
|
359 check_startup_changes("uninstalled", []); |
|
360 check_startup_changes("disabled", ["bug542391_1@tests.mozilla.org"]); |
|
361 check_startup_changes("enabled", []); |
|
362 do_check_false(WindowWatcher.expected); |
|
363 |
|
364 AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", |
|
365 "bug542391_2@tests.mozilla.org", |
|
366 "bug542391_3@tests.mozilla.org", |
|
367 "bug542391_4@tests.mozilla.org", |
|
368 "bug542391_5@tests.mozilla.org", |
|
369 "bug542391_6@tests.mozilla.org"], |
|
370 function(addons) { |
|
371 check_state_v2(addons); |
|
372 |
|
373 do_execute_soon(run_test_1); |
|
374 }); |
|
375 })); |
|
376 })); |
|
377 }); |
|
378 } |
|
379 |
|
380 function end_test() { |
|
381 testserver.stop(do_test_finished); |
|
382 } |
|
383 |
|
384 // Upgrade to version 3 which will appDisable two more add-ons. Check that the |
|
385 // 3 already disabled add-ons were passed to the mismatch dialog. |
|
386 function run_test_1() { |
|
387 gCheckUpdates = true; |
|
388 WindowWatcher.expected = true; |
|
389 restartManager("3"); |
|
390 check_startup_changes("installed", []); |
|
391 check_startup_changes("updated", []); |
|
392 check_startup_changes("uninstalled", []); |
|
393 check_startup_changes("disabled", ["bug542391_3@tests.mozilla.org"]); |
|
394 check_startup_changes("enabled", []); |
|
395 do_check_false(WindowWatcher.expected); |
|
396 gCheckUpdates = false; |
|
397 |
|
398 AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", |
|
399 "bug542391_2@tests.mozilla.org", |
|
400 "bug542391_3@tests.mozilla.org", |
|
401 "bug542391_4@tests.mozilla.org", |
|
402 "bug542391_5@tests.mozilla.org", |
|
403 "bug542391_6@tests.mozilla.org"], |
|
404 function(addons) { |
|
405 check_state_v3(addons); |
|
406 |
|
407 do_check_eq(WindowWatcher.arguments.length, 3); |
|
408 do_check_true(WindowWatcher.arguments.indexOf("bug542391_1@tests.mozilla.org") >= 0); |
|
409 do_check_true(WindowWatcher.arguments.indexOf("bug542391_2@tests.mozilla.org") >= 0); |
|
410 do_check_true(WindowWatcher.arguments.indexOf("bug542391_4@tests.mozilla.org") >= 0); |
|
411 |
|
412 do_execute_soon(run_test_2); |
|
413 }); |
|
414 } |
|
415 |
|
416 // Downgrade to version 2 which will remove appDisable from two add-ons and |
|
417 // should pass all 4 previously disabled add-ons. |
|
418 function run_test_2() { |
|
419 WindowWatcher.expected = true; |
|
420 restartManager("2"); |
|
421 check_startup_changes("installed", []); |
|
422 check_startup_changes("updated", []); |
|
423 check_startup_changes("uninstalled", []); |
|
424 check_startup_changes("disabled", []); |
|
425 check_startup_changes("enabled", ["bug542391_3@tests.mozilla.org"]); |
|
426 do_check_false(WindowWatcher.expected); |
|
427 |
|
428 AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", |
|
429 "bug542391_2@tests.mozilla.org", |
|
430 "bug542391_3@tests.mozilla.org", |
|
431 "bug542391_4@tests.mozilla.org", |
|
432 "bug542391_5@tests.mozilla.org", |
|
433 "bug542391_6@tests.mozilla.org"], |
|
434 function(addons) { |
|
435 check_state_v2(addons); |
|
436 |
|
437 do_check_eq(WindowWatcher.arguments.length, 4); |
|
438 do_check_true(WindowWatcher.arguments.indexOf("bug542391_1@tests.mozilla.org") >= 0); |
|
439 do_check_true(WindowWatcher.arguments.indexOf("bug542391_2@tests.mozilla.org") >= 0); |
|
440 do_check_true(WindowWatcher.arguments.indexOf("bug542391_3@tests.mozilla.org") >= 0); |
|
441 do_check_true(WindowWatcher.arguments.indexOf("bug542391_4@tests.mozilla.org") >= 0); |
|
442 |
|
443 do_execute_soon(run_test_5); |
|
444 }); |
|
445 } |
|
446 |
|
447 // Upgrade to version 3 which will appDisable two more add-ons. Check that when |
|
448 // the upgrade dialog updates an add-on no restart is necessary |
|
449 function run_test_5() { |
|
450 Services.prefs.setBoolPref(PREF_EM_SHOW_MISMATCH_UI, true); |
|
451 gInstallUpdate = true; |
|
452 |
|
453 WindowWatcher.expected = true; |
|
454 restartManager("3"); |
|
455 check_startup_changes("installed", []); |
|
456 check_startup_changes("updated", ["bug542391_3@tests.mozilla.org"]); |
|
457 check_startup_changes("uninstalled", []); |
|
458 check_startup_changes("disabled", []); |
|
459 check_startup_changes("enabled", []); |
|
460 do_check_false(WindowWatcher.expected); |
|
461 gInstallUpdate = false; |
|
462 |
|
463 AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", |
|
464 "bug542391_2@tests.mozilla.org", |
|
465 "bug542391_3@tests.mozilla.org", |
|
466 "bug542391_4@tests.mozilla.org", |
|
467 "bug542391_5@tests.mozilla.org", |
|
468 "bug542391_6@tests.mozilla.org"], |
|
469 function(addons) { |
|
470 check_state_v3_2(addons); |
|
471 |
|
472 do_check_eq(WindowWatcher.arguments.length, 3); |
|
473 do_check_true(WindowWatcher.arguments.indexOf("bug542391_1@tests.mozilla.org") >= 0); |
|
474 do_check_true(WindowWatcher.arguments.indexOf("bug542391_2@tests.mozilla.org") >= 0); |
|
475 do_check_true(WindowWatcher.arguments.indexOf("bug542391_4@tests.mozilla.org") >= 0); |
|
476 |
|
477 do_execute_soon(run_test_6); |
|
478 }); |
|
479 } |
|
480 |
|
481 // Downgrade to version 1 which will appEnable all the add-ons |
|
482 function run_test_6() { |
|
483 WindowWatcher.expected = true; |
|
484 restartManager("1"); |
|
485 check_startup_changes("installed", []); |
|
486 check_startup_changes("updated", []); |
|
487 check_startup_changes("uninstalled", []); |
|
488 check_startup_changes("disabled", ["bug542391_3@tests.mozilla.org"]); |
|
489 check_startup_changes("enabled", ["bug542391_1@tests.mozilla.org"]); |
|
490 do_check_false(WindowWatcher.expected); |
|
491 |
|
492 AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", |
|
493 "bug542391_2@tests.mozilla.org", |
|
494 "bug542391_3@tests.mozilla.org", |
|
495 "bug542391_4@tests.mozilla.org", |
|
496 "bug542391_5@tests.mozilla.org", |
|
497 "bug542391_6@tests.mozilla.org"], |
|
498 function(addons) { |
|
499 check_state_v1_2(addons); |
|
500 |
|
501 end_test(); |
|
502 }); |
|
503 } |