|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Bug 591465 - Context menu of add-ons miss context related state change entries |
|
6 |
|
7 |
|
8 let tempScope = {}; |
|
9 Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", tempScope); |
|
10 let LightweightThemeManager = tempScope.LightweightThemeManager; |
|
11 |
|
12 |
|
13 const PREF_GETADDONS_MAXRESULTS = "extensions.getAddons.maxResults"; |
|
14 const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; |
|
15 const SEARCH_URL = TESTROOT + "browser_bug591465.xml"; |
|
16 const SEARCH_QUERY = "SEARCH"; |
|
17 |
|
18 var gManagerWindow; |
|
19 var gProvider; |
|
20 var gContextMenu; |
|
21 var gLWTheme = { |
|
22 id: "4", |
|
23 version: "1", |
|
24 name: "Bling", |
|
25 description: "SO MUCH BLING!", |
|
26 author: "Pixel Pusher", |
|
27 homepageURL: "http://mochi.test:8888/data/index.html", |
|
28 headerURL: "http://mochi.test:8888/data/header.png", |
|
29 footerURL: "http://mochi.test:8888/data/footer.png", |
|
30 previewURL: "http://mochi.test:8888/data/preview.png", |
|
31 iconURL: "http://mochi.test:8888/data/icon.png" |
|
32 }; |
|
33 |
|
34 |
|
35 function test() { |
|
36 waitForExplicitFinish(); |
|
37 |
|
38 gProvider = new MockProvider(); |
|
39 |
|
40 gProvider.createAddons([{ |
|
41 id: "addon1@tests.mozilla.org", |
|
42 name: "addon 1", |
|
43 version: "1.0" |
|
44 }, { |
|
45 id: "addon2@tests.mozilla.org", |
|
46 name: "addon 2", |
|
47 version: "1.0", |
|
48 _userDisabled: true |
|
49 }, { |
|
50 id: "theme1@tests.mozilla.org", |
|
51 name: "theme 1", |
|
52 version: "1.0", |
|
53 type: "theme" |
|
54 }, { |
|
55 id: "theme2@tests.mozilla.org", |
|
56 name: "theme 2", |
|
57 version: "1.0", |
|
58 type: "theme", |
|
59 _userDisabled: true |
|
60 }, { |
|
61 id: "theme3@tests.mozilla.org", |
|
62 name: "theme 3", |
|
63 version: "1.0", |
|
64 type: "theme", |
|
65 permissions: 0 |
|
66 }]); |
|
67 |
|
68 |
|
69 open_manager("addons://list/extension", function(aWindow) { |
|
70 gManagerWindow = aWindow; |
|
71 gContextMenu = aWindow.document.getElementById("addonitem-popup"); |
|
72 run_next_test(); |
|
73 }); |
|
74 } |
|
75 |
|
76 |
|
77 function end_test() { |
|
78 close_manager(gManagerWindow, finish); |
|
79 } |
|
80 |
|
81 |
|
82 function check_contextmenu(aIsTheme, aIsEnabled, aIsRemote, aIsDetails, aIsSingleItemCase) { |
|
83 if (aIsTheme || aIsEnabled || aIsRemote) |
|
84 is_element_hidden(gManagerWindow.document.getElementById("menuitem_enableItem"), |
|
85 "'Enable' should be hidden"); |
|
86 else |
|
87 is_element_visible(gManagerWindow.document.getElementById("menuitem_enableItem"), |
|
88 "'Enable' should be visible"); |
|
89 |
|
90 if (aIsTheme || !aIsEnabled || aIsRemote) |
|
91 is_element_hidden(gManagerWindow.document.getElementById("menuitem_disableItem"), |
|
92 "'Disable' should be hidden"); |
|
93 else |
|
94 is_element_visible(gManagerWindow.document.getElementById("menuitem_disableItem"), |
|
95 "'Disable' should be visible"); |
|
96 |
|
97 if (!aIsTheme || aIsEnabled || aIsRemote || aIsSingleItemCase) |
|
98 is_element_hidden(gManagerWindow.document.getElementById("menuitem_enableTheme"), |
|
99 "'Wear Theme' should be hidden"); |
|
100 else |
|
101 is_element_visible(gManagerWindow.document.getElementById("menuitem_enableTheme"), |
|
102 "'Wear Theme' should be visible"); |
|
103 |
|
104 if (!aIsTheme || !aIsEnabled || aIsRemote || aIsSingleItemCase) |
|
105 is_element_hidden(gManagerWindow.document.getElementById("menuitem_disableTheme"), |
|
106 "'Stop Wearing Theme' should be hidden"); |
|
107 else |
|
108 is_element_visible(gManagerWindow.document.getElementById("menuitem_disableTheme"), |
|
109 "'Stop Wearing Theme' should be visible"); |
|
110 |
|
111 if (aIsRemote) |
|
112 is_element_visible(gManagerWindow.document.getElementById("menuitem_installItem"), |
|
113 "'Install' should be visible"); |
|
114 else |
|
115 is_element_hidden(gManagerWindow.document.getElementById("menuitem_installItem"), |
|
116 "'Install' should be hidden"); |
|
117 |
|
118 if (aIsDetails) |
|
119 is_element_hidden(gManagerWindow.document.getElementById("menuitem_showDetails"), |
|
120 "'Show More Information' should be hidden in details view"); |
|
121 else |
|
122 is_element_visible(gManagerWindow.document.getElementById("menuitem_showDetails"), |
|
123 "'Show More Information' should be visible in list view"); |
|
124 |
|
125 if (aIsSingleItemCase) |
|
126 is_element_hidden(gManagerWindow.document.getElementById("addonitem-menuseparator"), |
|
127 "Menu separator should be hidden with only one menu item"); |
|
128 else |
|
129 is_element_visible(gManagerWindow.document.getElementById("addonitem-menuseparator"), |
|
130 "Menu separator should be visible with multiple menu items"); |
|
131 |
|
132 } |
|
133 |
|
134 |
|
135 add_test(function() { |
|
136 var el = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
|
137 isnot(el, null, "Should have found addon element"); |
|
138 |
|
139 gContextMenu.addEventListener("popupshown", function() { |
|
140 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
141 |
|
142 check_contextmenu(false, true, false, false, false); |
|
143 |
|
144 gContextMenu.hidePopup(); |
|
145 run_next_test(); |
|
146 }, false); |
|
147 |
|
148 info("Opening context menu on enabled extension item"); |
|
149 el.parentNode.ensureElementIsVisible(el); |
|
150 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
151 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
152 }); |
|
153 |
|
154 add_test(function() { |
|
155 var el = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
|
156 isnot(el, null, "Should have found addon element"); |
|
157 el.mAddon.userDisabled = true; |
|
158 |
|
159 gContextMenu.addEventListener("popupshown", function() { |
|
160 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
161 |
|
162 check_contextmenu(false, false, false, false, false); |
|
163 |
|
164 gContextMenu.hidePopup(); |
|
165 run_next_test(); |
|
166 }, false); |
|
167 |
|
168 info("Opening context menu on newly disabled extension item"); |
|
169 el.parentNode.ensureElementIsVisible(el); |
|
170 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
171 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
172 }); |
|
173 |
|
174 add_test(function() { |
|
175 var el = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
|
176 isnot(el, null, "Should have found addon element"); |
|
177 el.mAddon.userDisabled = false; |
|
178 |
|
179 gContextMenu.addEventListener("popupshown", function() { |
|
180 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
181 |
|
182 check_contextmenu(false, true, false, false, false); |
|
183 |
|
184 gContextMenu.hidePopup(); |
|
185 run_next_test(); |
|
186 }, false); |
|
187 |
|
188 info("Opening context menu on newly enabled extension item"); |
|
189 el.parentNode.ensureElementIsVisible(el); |
|
190 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
191 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
192 }); |
|
193 |
|
194 add_test(function() { |
|
195 var el = get_addon_element(gManagerWindow, "addon2@tests.mozilla.org"); |
|
196 |
|
197 gContextMenu.addEventListener("popupshown", function() { |
|
198 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
199 |
|
200 check_contextmenu(false, false, false, false, false); |
|
201 |
|
202 gContextMenu.hidePopup(); |
|
203 run_next_test(); |
|
204 }, false); |
|
205 |
|
206 info("Opening context menu on disabled extension item"); |
|
207 el.parentNode.ensureElementIsVisible(el); |
|
208 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
209 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
210 }); |
|
211 |
|
212 |
|
213 add_test(function() { |
|
214 gManagerWindow.loadView("addons://list/theme"); |
|
215 wait_for_view_load(gManagerWindow, function() { |
|
216 var el = get_addon_element(gManagerWindow, "theme1@tests.mozilla.org"); |
|
217 |
|
218 gContextMenu.addEventListener("popupshown", function() { |
|
219 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
220 |
|
221 check_contextmenu(true, true, false, false, false); |
|
222 |
|
223 gContextMenu.hidePopup(); |
|
224 run_next_test(); |
|
225 }, false); |
|
226 |
|
227 info("Opening context menu on enabled theme item"); |
|
228 el.parentNode.ensureElementIsVisible(el); |
|
229 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
230 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
231 }); |
|
232 }); |
|
233 |
|
234 |
|
235 add_test(function() { |
|
236 var el = get_addon_element(gManagerWindow, "theme2@tests.mozilla.org"); |
|
237 |
|
238 gContextMenu.addEventListener("popupshown", function() { |
|
239 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
240 |
|
241 check_contextmenu(true, false, false, false, false); |
|
242 |
|
243 gContextMenu.hidePopup(); |
|
244 run_next_test(); |
|
245 }, false); |
|
246 |
|
247 info("Opening context menu on disabled theme item"); |
|
248 el.parentNode.ensureElementIsVisible(el); |
|
249 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
250 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
251 }); |
|
252 |
|
253 |
|
254 add_test(function() { |
|
255 LightweightThemeManager.currentTheme = gLWTheme; |
|
256 |
|
257 var el = get_addon_element(gManagerWindow, "4@personas.mozilla.org"); |
|
258 |
|
259 gContextMenu.addEventListener("popupshown", function() { |
|
260 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
261 |
|
262 check_contextmenu(true, true, false, false, false); |
|
263 |
|
264 gContextMenu.hidePopup(); |
|
265 run_next_test(); |
|
266 }, false); |
|
267 |
|
268 info("Opening context menu on enabled LW theme item"); |
|
269 el.parentNode.ensureElementIsVisible(el); |
|
270 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
271 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
272 }); |
|
273 |
|
274 |
|
275 add_test(function() { |
|
276 LightweightThemeManager.currentTheme = null; |
|
277 |
|
278 var el = get_addon_element(gManagerWindow, "4@personas.mozilla.org"); |
|
279 |
|
280 gContextMenu.addEventListener("popupshown", function() { |
|
281 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
282 |
|
283 check_contextmenu(true, false, false, false, false); |
|
284 |
|
285 gContextMenu.hidePopup(); |
|
286 run_next_test(); |
|
287 }, false); |
|
288 |
|
289 info("Opening context menu on disabled LW theme item"); |
|
290 el.parentNode.ensureElementIsVisible(el); |
|
291 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
292 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
293 }); |
|
294 |
|
295 |
|
296 add_test(function() { |
|
297 LightweightThemeManager.currentTheme = gLWTheme; |
|
298 |
|
299 gManagerWindow.loadView("addons://detail/4@personas.mozilla.org"); |
|
300 wait_for_view_load(gManagerWindow, function() { |
|
301 |
|
302 gContextMenu.addEventListener("popupshown", function() { |
|
303 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
304 |
|
305 check_contextmenu(true, true, false, true, false); |
|
306 |
|
307 gContextMenu.hidePopup(); |
|
308 run_next_test(); |
|
309 }, false); |
|
310 |
|
311 info("Opening context menu on enabled LW theme, in detail view"); |
|
312 var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); |
|
313 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
314 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
315 }); |
|
316 }); |
|
317 |
|
318 |
|
319 add_test(function() { |
|
320 LightweightThemeManager.currentTheme = null; |
|
321 |
|
322 gManagerWindow.loadView("addons://detail/4@personas.mozilla.org"); |
|
323 wait_for_view_load(gManagerWindow, function() { |
|
324 |
|
325 gContextMenu.addEventListener("popupshown", function() { |
|
326 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
327 |
|
328 check_contextmenu(true, false, false, true, false); |
|
329 |
|
330 gContextMenu.hidePopup(); |
|
331 |
|
332 AddonManager.getAddonByID("4@personas.mozilla.org", function(aAddon) { |
|
333 aAddon.uninstall(); |
|
334 run_next_test(); |
|
335 }); |
|
336 }, false); |
|
337 |
|
338 info("Opening context menu on disabled LW theme, in detail view"); |
|
339 var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); |
|
340 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
341 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
342 }); |
|
343 }); |
|
344 |
|
345 |
|
346 add_test(function() { |
|
347 gManagerWindow.loadView("addons://detail/addon1@tests.mozilla.org"); |
|
348 wait_for_view_load(gManagerWindow, function() { |
|
349 |
|
350 gContextMenu.addEventListener("popupshown", function() { |
|
351 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
352 |
|
353 check_contextmenu(false, true, false, true, false); |
|
354 |
|
355 gContextMenu.hidePopup(); |
|
356 run_next_test(); |
|
357 }, false); |
|
358 |
|
359 info("Opening context menu on enabled extension, in detail view"); |
|
360 var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); |
|
361 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
362 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
363 }); |
|
364 }); |
|
365 |
|
366 |
|
367 add_test(function() { |
|
368 gManagerWindow.loadView("addons://detail/addon2@tests.mozilla.org"); |
|
369 wait_for_view_load(gManagerWindow, function() { |
|
370 |
|
371 gContextMenu.addEventListener("popupshown", function() { |
|
372 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
373 |
|
374 check_contextmenu(false, false, false, true, false); |
|
375 |
|
376 gContextMenu.hidePopup(); |
|
377 run_next_test(); |
|
378 }, false); |
|
379 |
|
380 info("Opening context menu on disabled extension, in detail view"); |
|
381 var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); |
|
382 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
383 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
384 }); |
|
385 }); |
|
386 |
|
387 |
|
388 add_test(function() { |
|
389 gManagerWindow.loadView("addons://detail/theme1@tests.mozilla.org"); |
|
390 wait_for_view_load(gManagerWindow, function() { |
|
391 |
|
392 gContextMenu.addEventListener("popupshown", function() { |
|
393 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
394 |
|
395 check_contextmenu(true, true, false, true, false); |
|
396 |
|
397 gContextMenu.hidePopup(); |
|
398 run_next_test(); |
|
399 }, false); |
|
400 |
|
401 info("Opening context menu on enabled theme, in detail view"); |
|
402 var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); |
|
403 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
404 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
405 }); |
|
406 }); |
|
407 |
|
408 |
|
409 add_test(function() { |
|
410 gManagerWindow.loadView("addons://detail/theme2@tests.mozilla.org"); |
|
411 wait_for_view_load(gManagerWindow, function() { |
|
412 |
|
413 gContextMenu.addEventListener("popupshown", function() { |
|
414 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
415 |
|
416 check_contextmenu(true, false, false, true, false); |
|
417 |
|
418 gContextMenu.hidePopup(); |
|
419 run_next_test(); |
|
420 }, false); |
|
421 |
|
422 info("Opening context menu on disabled theme, in detail view"); |
|
423 var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); |
|
424 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
425 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
426 }); |
|
427 }); |
|
428 |
|
429 add_test(function() { |
|
430 gManagerWindow.loadView("addons://detail/theme3@tests.mozilla.org"); |
|
431 wait_for_view_load(gManagerWindow, function() { |
|
432 |
|
433 gContextMenu.addEventListener("popupshown", function() { |
|
434 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
435 |
|
436 check_contextmenu(true, true, false, true, true); |
|
437 |
|
438 gContextMenu.hidePopup(); |
|
439 run_next_test(); |
|
440 }, false); |
|
441 |
|
442 info("Opening context menu with single menu item on enabled theme, in detail view"); |
|
443 var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); |
|
444 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
445 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
446 }); |
|
447 }); |
|
448 |
|
449 add_test(function() { |
|
450 info("Searching for remote addons"); |
|
451 |
|
452 Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL); |
|
453 Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); |
|
454 |
|
455 var searchBox = gManagerWindow.document.getElementById("header-search"); |
|
456 searchBox.value = SEARCH_QUERY; |
|
457 |
|
458 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); |
|
459 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); |
|
460 |
|
461 wait_for_view_load(gManagerWindow, function() { |
|
462 var filter = gManagerWindow.document.getElementById("search-filter-remote"); |
|
463 EventUtils.synthesizeMouseAtCenter(filter, { }, gManagerWindow); |
|
464 executeSoon(function() { |
|
465 |
|
466 var el = get_addon_element(gManagerWindow, "remote1@tests.mozilla.org"); |
|
467 |
|
468 gContextMenu.addEventListener("popupshown", function() { |
|
469 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
470 |
|
471 check_contextmenu(false, false, true, false, false); |
|
472 |
|
473 gContextMenu.hidePopup(); |
|
474 run_next_test(); |
|
475 }, false); |
|
476 |
|
477 info("Opening context menu on remote extension item"); |
|
478 el.parentNode.ensureElementIsVisible(el); |
|
479 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
480 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
481 |
|
482 }); |
|
483 }); |
|
484 }); |
|
485 |
|
486 |
|
487 add_test(function() { |
|
488 gManagerWindow.loadView("addons://detail/remote1@tests.mozilla.org"); |
|
489 wait_for_view_load(gManagerWindow, function() { |
|
490 |
|
491 gContextMenu.addEventListener("popupshown", function() { |
|
492 gContextMenu.removeEventListener("popupshown", arguments.callee, false); |
|
493 |
|
494 check_contextmenu(false, false, true, true, false); |
|
495 |
|
496 gContextMenu.hidePopup(); |
|
497 |
|
498 // Delete the created install |
|
499 AddonManager.getAllInstalls(function(aInstalls) { |
|
500 is(aInstalls.length, 1, "Should be one available install"); |
|
501 aInstalls[0].cancel(); |
|
502 |
|
503 run_next_test(); |
|
504 }); |
|
505 }, false); |
|
506 |
|
507 info("Opening context menu on remote extension, in detail view"); |
|
508 var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); |
|
509 EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); |
|
510 EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); |
|
511 }); |
|
512 }); |