|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Test the compatibility dialog that displays during startup when the browser |
|
6 // version changes. |
|
7 |
|
8 const URI_EXTENSION_UPDATE_DIALOG = "chrome://mozapps/content/extensions/update.xul"; |
|
9 |
|
10 const PREF_GETADDONS_BYIDS = "extensions.getAddons.get.url"; |
|
11 const PREF_MIN_PLATFORM_COMPAT = "extensions.minCompatiblePlatformVersion"; |
|
12 |
|
13 Services.prefs.setBoolPref(PREF_STRICT_COMPAT, true); |
|
14 // avoid the 'leaked window property' check |
|
15 let scope = {}; |
|
16 Components.utils.import("resource://gre/modules/TelemetryPing.jsm", scope); |
|
17 let TelemetryPing = scope.TelemetryPing; |
|
18 |
|
19 /** |
|
20 * Test add-ons: |
|
21 * |
|
22 * Addon minVersion maxVersion Notes |
|
23 * addon1 0 * |
|
24 * addon2 0 0 |
|
25 * addon3 0 0 |
|
26 * addon4 1 * |
|
27 * addon5 0 0 Made compatible by update check |
|
28 * addon6 0 0 Made compatible by update check |
|
29 * addon7 0 0 Has a broken update available |
|
30 * addon8 0 0 Has an update available |
|
31 * addon9 0 0 Has an update available |
|
32 */ |
|
33 |
|
34 function test() { |
|
35 requestLongerTimeout(2); |
|
36 waitForExplicitFinish(); |
|
37 |
|
38 run_next_test(); |
|
39 } |
|
40 |
|
41 function end_test() { |
|
42 // Test generates a lot of available installs so just cancel them all |
|
43 AddonManager.getAllInstalls(function(aInstalls) { |
|
44 for (let install of aInstalls) |
|
45 install.cancel(); |
|
46 |
|
47 finish(); |
|
48 }); |
|
49 } |
|
50 |
|
51 function install_test_addons(aCallback) { |
|
52 var installs = []; |
|
53 |
|
54 // Use a blank update URL |
|
55 Services.prefs.setCharPref(PREF_UPDATEURL, TESTROOT + "missing.rdf"); |
|
56 |
|
57 let names = ["browser_bug557956_1", |
|
58 "browser_bug557956_2", |
|
59 "browser_bug557956_3", |
|
60 "browser_bug557956_4", |
|
61 "browser_bug557956_5", |
|
62 "browser_bug557956_6", |
|
63 "browser_bug557956_7", |
|
64 "browser_bug557956_8_1", |
|
65 "browser_bug557956_9_1", |
|
66 "browser_bug557956_10"]; |
|
67 for (let name of names) { |
|
68 AddonManager.getInstallForURL(TESTROOT + "addons/" + name + ".xpi", function(aInstall) { |
|
69 installs.push(aInstall); |
|
70 }, "application/x-xpinstall"); |
|
71 } |
|
72 |
|
73 var listener = { |
|
74 installCount: 0, |
|
75 |
|
76 onInstallEnded: function() { |
|
77 this.installCount++; |
|
78 if (this.installCount == installs.length) { |
|
79 // Switch to the test update URL |
|
80 Services.prefs.setCharPref(PREF_UPDATEURL, TESTROOT + "browser_bug557956.rdf"); |
|
81 |
|
82 aCallback(); |
|
83 } |
|
84 } |
|
85 }; |
|
86 |
|
87 for (let install of installs) { |
|
88 install.addListener(listener); |
|
89 install.install(); |
|
90 } |
|
91 } |
|
92 |
|
93 function uninstall_test_addons(aCallback) { |
|
94 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
95 "addon2@tests.mozilla.org", |
|
96 "addon3@tests.mozilla.org", |
|
97 "addon4@tests.mozilla.org", |
|
98 "addon5@tests.mozilla.org", |
|
99 "addon6@tests.mozilla.org", |
|
100 "addon7@tests.mozilla.org", |
|
101 "addon8@tests.mozilla.org", |
|
102 "addon9@tests.mozilla.org", |
|
103 "addon10@tests.mozilla.org"], |
|
104 function(aAddons) { |
|
105 for (let addon of aAddons) { |
|
106 if (addon) |
|
107 addon.uninstall(); |
|
108 } |
|
109 aCallback(); |
|
110 }); |
|
111 } |
|
112 |
|
113 function open_compatibility_window(aInactiveAddonIds, aCallback) { |
|
114 // This will reset the longer timeout multiplier to 2 which will give each |
|
115 // test that calls open_compatibility_window a minimum of 60 seconds to |
|
116 // complete. |
|
117 requestLongerTimeout(2); |
|
118 |
|
119 var variant = Cc["@mozilla.org/variant;1"]. |
|
120 createInstance(Ci.nsIWritableVariant); |
|
121 variant.setFromVariant(aInactiveAddonIds); |
|
122 |
|
123 // Cannot be modal as we want to interract with it, shouldn't cause problems |
|
124 // with testing though. |
|
125 var features = "chrome,centerscreen,dialog,titlebar"; |
|
126 var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]. |
|
127 getService(Ci.nsIWindowWatcher); |
|
128 var win = ww.openWindow(null, URI_EXTENSION_UPDATE_DIALOG, "", features, variant); |
|
129 |
|
130 win.addEventListener("load", function() { |
|
131 win.removeEventListener("load", arguments.callee, false); |
|
132 |
|
133 info("Compatibility dialog opened"); |
|
134 |
|
135 function page_shown(aEvent) { |
|
136 if (aEvent.target.pageid) |
|
137 info("Page " + aEvent.target.pageid + " shown"); |
|
138 } |
|
139 |
|
140 win.addEventListener("pageshow", page_shown, false); |
|
141 win.addEventListener("unload", function() { |
|
142 win.removeEventListener("unload", arguments.callee, false); |
|
143 win.removeEventListener("pageshow", page_shown, false); |
|
144 info("Compatibility dialog closed"); |
|
145 }, false); |
|
146 |
|
147 aCallback(win); |
|
148 }, false); |
|
149 } |
|
150 |
|
151 function wait_for_window_close(aWindow, aCallback) { |
|
152 aWindow.addEventListener("unload", function() { |
|
153 aWindow.removeEventListener("unload", arguments.callee, false); |
|
154 aCallback(); |
|
155 }, false); |
|
156 } |
|
157 |
|
158 function wait_for_page(aWindow, aPageId, aCallback) { |
|
159 var page = aWindow.document.getElementById(aPageId); |
|
160 page.addEventListener("pageshow", function() { |
|
161 page.removeEventListener("pageshow", arguments.callee, false); |
|
162 executeSoon(function() { |
|
163 aCallback(aWindow); |
|
164 }); |
|
165 }, false); |
|
166 } |
|
167 |
|
168 function get_list_names(aList) { |
|
169 var items = []; |
|
170 for (let listItem of aList.childNodes) |
|
171 items.push(listItem.label); |
|
172 items.sort(); |
|
173 return items; |
|
174 } |
|
175 |
|
176 function check_telemetry({disabled, metaenabled, metadisabled, upgraded, failed, declined}) { |
|
177 let ping = TelemetryPing.getPayload(); |
|
178 // info(JSON.stringify(ping)); |
|
179 let am = ping.simpleMeasurements.addonManager; |
|
180 if (disabled !== undefined) |
|
181 is(am.appUpdate_disabled, disabled, disabled + " add-ons disabled by version change"); |
|
182 if (metaenabled !== undefined) |
|
183 is(am.appUpdate_metadata_enabled, metaenabled, metaenabled + " add-ons enabled by metadata"); |
|
184 if (metadisabled !== undefined) |
|
185 is(am.appUpdate_metadata_disabled, metadisabled, metadisabled + " add-ons disabled by metadata"); |
|
186 if (upgraded !== undefined) |
|
187 is(am.appUpdate_upgraded, upgraded, upgraded + " add-ons upgraded"); |
|
188 if (failed !== undefined) |
|
189 is(am.appUpdate_upgradeFailed, failed, failed + " upgrades failed"); |
|
190 if (declined !== undefined) |
|
191 is(am.appUpdate_upgradeDeclined, declined, declined + " upgrades declined"); |
|
192 } |
|
193 |
|
194 // Tests that the right add-ons show up in the mismatch dialog and updates can |
|
195 // be installed |
|
196 add_test(function() { |
|
197 install_test_addons(function() { |
|
198 // These add-ons were inactive in the old application |
|
199 var inactiveAddonIds = [ |
|
200 "addon2@tests.mozilla.org", |
|
201 "addon4@tests.mozilla.org", |
|
202 "addon5@tests.mozilla.org", |
|
203 "addon10@tests.mozilla.org" |
|
204 ]; |
|
205 |
|
206 AddonManager.getAddonsByIDs(["addon5@tests.mozilla.org", |
|
207 "addon6@tests.mozilla.org"], |
|
208 function([a5, a6]) { |
|
209 // Check starting (pre-update) conditions |
|
210 ok(!a5.isCompatible, "addon5 should not be compatible"); |
|
211 ok(!a6.isCompatible, "addon6 should not be compatible"); |
|
212 |
|
213 open_compatibility_window(inactiveAddonIds, function(aWindow) { |
|
214 var doc = aWindow.document; |
|
215 wait_for_page(aWindow, "mismatch", function(aWindow) { |
|
216 var items = get_list_names(doc.getElementById("mismatch.incompatible")); |
|
217 // Check that compatibility updates from individual add-on update checks were applied. |
|
218 is(items.length, 4, "Should have seen 4 still incompatible items"); |
|
219 is(items[0], "Addon3 1.0", "Should have seen addon3 still incompatible"); |
|
220 is(items[1], "Addon7 1.0", "Should have seen addon7 still incompatible"); |
|
221 is(items[2], "Addon8 1.0", "Should have seen addon8 still incompatible"); |
|
222 is(items[3], "Addon9 1.0", "Should have seen addon9 still incompatible"); |
|
223 |
|
224 ok(a5.isCompatible, "addon5 should be compatible"); |
|
225 ok(a6.isCompatible, "addon6 should be compatible"); |
|
226 |
|
227 var button = doc.documentElement.getButton("next"); |
|
228 EventUtils.synthesizeMouse(button, 2, 2, { }, aWindow); |
|
229 |
|
230 wait_for_page(aWindow, "found", function(aWindow) { |
|
231 ok(doc.getElementById("xpinstallDisabledAlert").hidden, |
|
232 "Install should be allowed"); |
|
233 |
|
234 var list = doc.getElementById("found.updates"); |
|
235 var items = get_list_names(list); |
|
236 is(items.length, 3, "Should have seen 3 updates available"); |
|
237 is(items[0], "Addon7 2.0", "Should have seen update for addon7"); |
|
238 is(items[1], "Addon8 2.0", "Should have seen update for addon8"); |
|
239 is(items[2], "Addon9 2.0", "Should have seen update for addon9"); |
|
240 |
|
241 ok(!doc.documentElement.getButton("next").disabled, |
|
242 "Next button should be enabled"); |
|
243 |
|
244 // Uncheck all |
|
245 for (let listItem of list.childNodes) |
|
246 EventUtils.synthesizeMouse(listItem, 2, 2, { }, aWindow); |
|
247 |
|
248 ok(doc.documentElement.getButton("next").disabled, |
|
249 "Next button should not be enabled"); |
|
250 |
|
251 // Check the ones we want to install |
|
252 for (let listItem of list.childNodes) { |
|
253 if (listItem.label != "Addon7 2.0") |
|
254 EventUtils.synthesizeMouse(listItem, 2, 2, { }, aWindow); |
|
255 } |
|
256 |
|
257 var button = doc.documentElement.getButton("next"); |
|
258 EventUtils.synthesizeMouse(button, 2, 2, { }, aWindow); |
|
259 |
|
260 wait_for_page(aWindow, "finished", function(aWindow) { |
|
261 var button = doc.documentElement.getButton("finish"); |
|
262 ok(!button.hidden, "Finish button should not be hidden"); |
|
263 ok(!button.disabled, "Finish button should not be disabled"); |
|
264 EventUtils.synthesizeMouse(button, 2, 2, { }, aWindow); |
|
265 |
|
266 wait_for_window_close(aWindow, function() { |
|
267 AddonManager.getAddonsByIDs(["addon8@tests.mozilla.org", |
|
268 "addon9@tests.mozilla.org"], |
|
269 function([a8, a9]) { |
|
270 is(a8.version, "2.0", "addon8 should have updated"); |
|
271 is(a9.version, "2.0", "addon9 should have updated"); |
|
272 |
|
273 check_telemetry({disabled: 4, metaenabled: 2, metadisabled: 0, |
|
274 upgraded: 2, failed: 0, declined: 1}); |
|
275 |
|
276 uninstall_test_addons(run_next_test); |
|
277 }); |
|
278 }); |
|
279 }); |
|
280 }); |
|
281 }); |
|
282 }); |
|
283 }); |
|
284 }); |
|
285 }); |
|
286 |
|
287 // Tests that the install failures show the install failed page and disabling |
|
288 // xpinstall shows the right UI. |
|
289 add_test(function() { |
|
290 install_test_addons(function() { |
|
291 // These add-ons were inactive in the old application |
|
292 var inactiveAddonIds = [ |
|
293 "addon2@tests.mozilla.org", |
|
294 "addon4@tests.mozilla.org", |
|
295 "addon5@tests.mozilla.org", |
|
296 "addon10@tests.mozilla.org" |
|
297 ]; |
|
298 |
|
299 Services.prefs.setBoolPref("xpinstall.enabled", false); |
|
300 |
|
301 open_compatibility_window(inactiveAddonIds, function(aWindow) { |
|
302 var doc = aWindow.document; |
|
303 wait_for_page(aWindow, "mismatch", function(aWindow) { |
|
304 var items = get_list_names(doc.getElementById("mismatch.incompatible")); |
|
305 is(items.length, 4, "Should have seen 4 still incompatible items"); |
|
306 is(items[0], "Addon3 1.0", "Should have seen addon3 still incompatible"); |
|
307 is(items[1], "Addon7 1.0", "Should have seen addon7 still incompatible"); |
|
308 is(items[2], "Addon8 1.0", "Should have seen addon8 still incompatible"); |
|
309 is(items[3], "Addon9 1.0", "Should have seen addon9 still incompatible"); |
|
310 |
|
311 // Check that compatibility updates were applied. |
|
312 AddonManager.getAddonsByIDs(["addon5@tests.mozilla.org", |
|
313 "addon6@tests.mozilla.org"], |
|
314 function([a5, a6]) { |
|
315 ok(a5.isCompatible, "addon5 should be compatible"); |
|
316 ok(a6.isCompatible, "addon6 should be compatible"); |
|
317 |
|
318 var button = doc.documentElement.getButton("next"); |
|
319 EventUtils.synthesizeMouse(button, 2, 2, { }, aWindow); |
|
320 |
|
321 wait_for_page(aWindow, "found", function(aWindow) { |
|
322 ok(!doc.getElementById("xpinstallDisabledAlert").hidden, |
|
323 "Install should not be allowed"); |
|
324 |
|
325 ok(doc.documentElement.getButton("next").disabled, |
|
326 "Next button should be disabled"); |
|
327 |
|
328 var checkbox = doc.getElementById("enableXPInstall"); |
|
329 EventUtils.synthesizeMouse(checkbox, 2, 2, { }, aWindow); |
|
330 |
|
331 ok(!doc.documentElement.getButton("next").disabled, |
|
332 "Next button should be enabled"); |
|
333 |
|
334 var list = doc.getElementById("found.updates"); |
|
335 var items = get_list_names(list); |
|
336 is(items.length, 3, "Should have seen 3 updates available"); |
|
337 is(items[0], "Addon7 2.0", "Should have seen update for addon7"); |
|
338 is(items[1], "Addon8 2.0", "Should have seen update for addon8"); |
|
339 is(items[2], "Addon9 2.0", "Should have seen update for addon9"); |
|
340 |
|
341 // Unheck the ones we don't want to install |
|
342 for (let listItem of list.childNodes) { |
|
343 if (listItem.label != "Addon7 2.0") |
|
344 EventUtils.synthesizeMouse(listItem, 2, 2, { }, aWindow); |
|
345 } |
|
346 |
|
347 var button = doc.documentElement.getButton("next"); |
|
348 EventUtils.synthesizeMouse(button, 2, 2, { }, aWindow); |
|
349 |
|
350 wait_for_page(aWindow, "installerrors", function(aWindow) { |
|
351 var button = doc.documentElement.getButton("finish"); |
|
352 ok(!button.hidden, "Finish button should not be hidden"); |
|
353 ok(!button.disabled, "Finish button should not be disabled"); |
|
354 |
|
355 wait_for_window_close(aWindow, function() { |
|
356 uninstall_test_addons(run_next_test); |
|
357 }); |
|
358 |
|
359 check_telemetry({disabled: 4, metaenabled: 2, metadisabled: 0, |
|
360 upgraded: 0, failed: 1, declined: 2}); |
|
361 |
|
362 EventUtils.synthesizeMouse(button, 2, 2, { }, aWindow); |
|
363 }); |
|
364 }); |
|
365 }); |
|
366 }); |
|
367 }); |
|
368 }); |
|
369 }); |
|
370 |
|
371 // Tests that no add-ons show up in the mismatch dialog when they are all disabled |
|
372 add_test(function() { |
|
373 install_test_addons(function() { |
|
374 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
375 "addon2@tests.mozilla.org", |
|
376 "addon3@tests.mozilla.org", |
|
377 "addon4@tests.mozilla.org", |
|
378 "addon5@tests.mozilla.org", |
|
379 "addon6@tests.mozilla.org", |
|
380 "addon7@tests.mozilla.org", |
|
381 "addon8@tests.mozilla.org", |
|
382 "addon9@tests.mozilla.org", |
|
383 "addon10@tests.mozilla.org"], |
|
384 function(aAddons) { |
|
385 for (let addon of aAddons) |
|
386 addon.userDisabled = true; |
|
387 |
|
388 // These add-ons were inactive in the old application |
|
389 var inactiveAddonIds = [ |
|
390 "addon1@tests.mozilla.org", |
|
391 "addon2@tests.mozilla.org", |
|
392 "addon3@tests.mozilla.org", |
|
393 "addon4@tests.mozilla.org", |
|
394 "addon5@tests.mozilla.org", |
|
395 "addon6@tests.mozilla.org", |
|
396 "addon7@tests.mozilla.org", |
|
397 "addon8@tests.mozilla.org", |
|
398 "addon9@tests.mozilla.org", |
|
399 "addon10@tests.mozilla.org" |
|
400 ]; |
|
401 |
|
402 open_compatibility_window(inactiveAddonIds, function(aWindow) { |
|
403 // Should close immediately on its own |
|
404 wait_for_window_close(aWindow, function() { |
|
405 uninstall_test_addons(run_next_test); |
|
406 }); |
|
407 }); |
|
408 }); |
|
409 }); |
|
410 }); |
|
411 |
|
412 // Tests that the right UI shows for when no updates are available |
|
413 add_test(function() { |
|
414 install_test_addons(function() { |
|
415 AddonManager.getAddonsByIDs(["addon7@tests.mozilla.org", |
|
416 "addon8@tests.mozilla.org", |
|
417 "addon9@tests.mozilla.org", |
|
418 "addon10@tests.mozilla.org"], |
|
419 function(aAddons) { |
|
420 for (let addon of aAddons) |
|
421 addon.uninstall(); |
|
422 |
|
423 // These add-ons were inactive in the old application |
|
424 var inactiveAddonIds = [ |
|
425 "addon2@tests.mozilla.org", |
|
426 "addon4@tests.mozilla.org", |
|
427 "addon5@tests.mozilla.org" |
|
428 ]; |
|
429 |
|
430 open_compatibility_window(inactiveAddonIds, function(aWindow) { |
|
431 var doc = aWindow.document; |
|
432 wait_for_page(aWindow, "mismatch", function(aWindow) { |
|
433 var items = get_list_names(doc.getElementById("mismatch.incompatible")); |
|
434 is(items.length, 1, "Should have seen 1 still incompatible items"); |
|
435 is(items[0], "Addon3 1.0", "Should have seen addon3 still incompatible"); |
|
436 |
|
437 var button = doc.documentElement.getButton("next"); |
|
438 EventUtils.synthesizeMouse(button, 2, 2, { }, aWindow); |
|
439 |
|
440 wait_for_page(aWindow, "noupdates", function(aWindow) { |
|
441 var button = doc.documentElement.getButton("finish"); |
|
442 ok(!button.hidden, "Finish button should not be hidden"); |
|
443 ok(!button.disabled, "Finish button should not be disabled"); |
|
444 |
|
445 wait_for_window_close(aWindow, function() { |
|
446 uninstall_test_addons(run_next_test); |
|
447 }); |
|
448 |
|
449 EventUtils.synthesizeMouse(button, 2, 2, { }, aWindow); |
|
450 }); |
|
451 }); |
|
452 }); |
|
453 }); |
|
454 }); |
|
455 }); |
|
456 |
|
457 // Tests that compatibility overrides are retrieved and affect addon |
|
458 // compatibility. |
|
459 add_test(function() { |
|
460 Services.prefs.setBoolPref(PREF_STRICT_COMPAT, false); |
|
461 Services.prefs.setCharPref(PREF_MIN_PLATFORM_COMPAT, "0"); |
|
462 is(AddonManager.strictCompatibility, false, "Strict compatibility should be disabled"); |
|
463 |
|
464 // Use a blank update URL |
|
465 Services.prefs.setCharPref(PREF_UPDATEURL, TESTROOT + "missing.rdf"); |
|
466 |
|
467 install_test_addons(function() { |
|
468 |
|
469 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
470 "addon2@tests.mozilla.org", |
|
471 "addon3@tests.mozilla.org", |
|
472 "addon4@tests.mozilla.org", |
|
473 "addon5@tests.mozilla.org", |
|
474 "addon6@tests.mozilla.org", |
|
475 "addon7@tests.mozilla.org", |
|
476 "addon8@tests.mozilla.org", |
|
477 "addon9@tests.mozilla.org", |
|
478 "addon10@tests.mozilla.org"], |
|
479 function(aAddons) { |
|
480 |
|
481 for (let addon of aAddons) { |
|
482 if (addon.id == "addon10@tests.mozilla.org") |
|
483 is(addon.isCompatible, true, "Addon10 should be compatible before compat overrides are refreshed"); |
|
484 else |
|
485 addon.uninstall(); |
|
486 } |
|
487 |
|
488 Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, TESTROOT + "browser_bug557956.xml"); |
|
489 Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); |
|
490 |
|
491 open_compatibility_window([], function(aWindow) { |
|
492 var doc = aWindow.document; |
|
493 wait_for_page(aWindow, "mismatch", function(aWindow) { |
|
494 var items = get_list_names(doc.getElementById("mismatch.incompatible")); |
|
495 is(items.length, 1, "Should have seen 1 incompatible item"); |
|
496 is(items[0], "Addon10 1.0", "Should have seen addon10 as incompatible"); |
|
497 |
|
498 var button = doc.documentElement.getButton("next"); |
|
499 EventUtils.synthesizeMouse(button, 2, 2, { }, aWindow); |
|
500 |
|
501 wait_for_page(aWindow, "noupdates", function(aWindow) { |
|
502 var button = doc.documentElement.getButton("finish"); |
|
503 ok(!button.hidden, "Finish button should not be hidden"); |
|
504 ok(!button.disabled, "Finish button should not be disabled"); |
|
505 |
|
506 wait_for_window_close(aWindow, function() { |
|
507 uninstall_test_addons(run_next_test); |
|
508 }); |
|
509 |
|
510 check_telemetry({disabled: 0, metaenabled: 0, metadisabled: 1, |
|
511 upgraded: 0, failed: 0, declined: 0}); |
|
512 |
|
513 EventUtils.synthesizeMouse(button, 2, 2, { }, aWindow); |
|
514 }); |
|
515 }); |
|
516 }); |
|
517 }); |
|
518 }); |
|
519 }); |