Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 // Tests that searching for add-ons works correctly
7 var gManagerWindow;
8 var gDocument;
9 var gCategoryUtilities;
10 var gProvider;
12 function test() {
13 requestLongerTimeout(2);
14 waitForExplicitFinish();
16 gProvider = new MockProvider();
18 gProvider.createAddons([{
19 id: "addon1@tests.mozilla.org",
20 name: "Uninstall needs restart",
21 type: "extension",
22 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_UNINSTALL
23 }, {
24 id: "addon2@tests.mozilla.org",
25 name: "Uninstall doesn't need restart 1",
26 type: "extension",
27 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
28 }, {
29 id: "addon3@tests.mozilla.org",
30 name: "Uninstall doesn't need restart 2",
31 type: "extension",
32 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
33 }, {
34 id: "addon4@tests.mozilla.org",
35 name: "Uninstall doesn't need restart 3",
36 type: "extension",
37 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
38 }, {
39 id: "addon5@tests.mozilla.org",
40 name: "Uninstall doesn't need restart 4",
41 type: "extension",
42 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
43 }, {
44 id: "addon6@tests.mozilla.org",
45 name: "Uninstall doesn't need restart 5",
46 type: "extension",
47 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
48 }, {
49 id: "addon7@tests.mozilla.org",
50 name: "Uninstall doesn't need restart 6",
51 type: "extension",
52 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
53 }, {
54 id: "addon8@tests.mozilla.org",
55 name: "Uninstall doesn't need restart 7",
56 type: "extension",
57 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
58 }, {
59 id: "addon9@tests.mozilla.org",
60 name: "Uninstall doesn't need restart 8",
61 type: "extension",
62 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
63 }]);
65 open_manager(null, function(aWindow) {
66 gManagerWindow = aWindow;
67 gDocument = gManagerWindow.document;
68 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
69 run_next_test();
70 });
71 }
73 function end_test() {
74 close_manager(gManagerWindow, function() {
75 finish();
76 });
77 }
79 function get_item_in_list(aId, aList) {
80 var item = aList.firstChild;
81 while (item) {
82 if ("mAddon" in item && item.mAddon.id == aId) {
83 aList.ensureElementIsVisible(item);
84 return item;
85 }
86 item = item.nextSibling;
87 }
88 return null;
89 }
91 // Tests that uninstalling a normal add-on from the list view can be undone
92 add_test(function() {
93 var ID = "addon1@tests.mozilla.org";
94 var list = gDocument.getElementById("addon-list");
96 // Select the extensions category
97 gCategoryUtilities.openType("extension", function() {
98 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
100 AddonManager.getAddonByID(ID, function(aAddon) {
101 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
102 ok(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL, "Add-on should require a restart to uninstall");
104 var item = get_item_in_list(ID, list);
105 isnot(item, null, "Should have found the add-on in the list");
107 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
108 isnot(button, null, "Should have a remove button");
109 ok(!button.disabled, "Button should not be disabled");
111 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
113 // Force XBL to apply
114 item.clientTop;
116 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
118 ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
120 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
121 isnot(button, null, "Should have a restart button");
122 ok(!button.hidden, "Restart button should not be hidden");
123 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
124 isnot(button, null, "Should have an undo button");
126 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
128 // Force XBL to apply
129 item.clientTop;
131 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
132 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
133 isnot(button, null, "Should have a remove button");
134 ok(!button.disabled, "Button should not be disabled");
136 run_next_test();
137 });
138 });
139 });
141 // Tests that uninstalling a restartless add-on from the list view can be undone
142 add_test(function() {
143 var ID = "addon2@tests.mozilla.org";
144 var list = gDocument.getElementById("addon-list");
146 // Select the extensions category
147 gCategoryUtilities.openType("extension", function() {
148 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
150 AddonManager.getAddonByID(ID, function(aAddon) {
151 ok(aAddon.isActive, "Add-on should be active");
152 ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
153 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
155 var item = get_item_in_list(ID, list);
156 isnot(item, null, "Should have found the add-on in the list");
158 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
159 isnot(button, null, "Should have a remove button");
160 ok(!button.disabled, "Button should not be disabled");
162 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
164 // Force XBL to apply
165 item.clientTop;
167 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
169 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
170 ok(!aAddon.isActive, "Add-on should be inactive");
172 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
173 isnot(button, null, "Should have a restart button");
174 ok(button.hidden, "Restart button should be hidden");
175 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
176 isnot(button, null, "Should have an undo button");
178 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
180 // Force XBL to apply
181 item.clientTop;
183 ok(aAddon.isActive, "Add-on should be active");
184 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
185 isnot(button, null, "Should have a remove button");
186 ok(!button.disabled, "Button should not be disabled");
188 run_next_test();
189 });
190 });
191 });
193 // Tests that uninstalling a disabled restartless add-on from the list view can
194 // be undone and doesn't re-enable
195 add_test(function() {
196 var ID = "addon2@tests.mozilla.org";
197 var list = gDocument.getElementById("addon-list");
199 // Select the extensions category
200 gCategoryUtilities.openType("extension", function() {
201 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
203 AddonManager.getAddonByID(ID, function(aAddon) {
204 aAddon.userDisabled = true;
206 ok(!aAddon.isActive, "Add-on should be inactive");
207 ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
208 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
210 var item = get_item_in_list(ID, list);
211 isnot(item, null, "Should have found the add-on in the list");
213 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
214 isnot(button, null, "Should have a remove button");
215 ok(!button.disabled, "Button should not be disabled");
217 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
219 // Force XBL to apply
220 item.clientTop;
222 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
224 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
225 ok(!aAddon.isActive, "Add-on should be inactive");
227 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
228 isnot(button, null, "Should have a restart button");
229 ok(button.hidden, "Restart button should be hidden");
230 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
231 isnot(button, null, "Should have an undo button");
233 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
235 // Force XBL to apply
236 item.clientTop;
238 ok(!aAddon.isActive, "Add-on should be inactive");
239 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
240 isnot(button, null, "Should have a remove button");
241 ok(!button.disabled, "Button should not be disabled");
243 aAddon.userDisabled = false;
244 ok(aAddon.isActive, "Add-on should be active");
246 run_next_test();
247 });
248 });
249 });
251 // Tests that uninstalling a normal add-on from the search view can be undone
252 add_test(function() {
253 var ID = "addon1@tests.mozilla.org";
254 var list = gDocument.getElementById("search-list");
256 var searchBox = gManagerWindow.document.getElementById("header-search");
257 searchBox.value = "Uninstall";
259 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
260 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
262 wait_for_view_load(gManagerWindow, function() {
263 is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
265 // Make sure to show local add-ons
266 EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
268 AddonManager.getAddonByID(ID, function(aAddon) {
269 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
270 ok(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL, "Add-on should require a restart to uninstall");
272 var item = get_item_in_list(ID, list);
273 isnot(item, null, "Should have found the add-on in the list");
275 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
276 isnot(button, null, "Should have a remove button");
277 ok(!button.disabled, "Button should not be disabled");
279 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
281 // Force XBL to apply
282 item.clientTop;
284 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
286 ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
288 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
289 isnot(button, null, "Should have a restart button");
290 ok(!button.hidden, "Restart button should not be hidden");
291 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
292 isnot(button, null, "Should have an undo button");
294 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
296 // Force XBL to apply
297 item.clientTop;
299 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
300 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
301 isnot(button, null, "Should have a remove button");
302 ok(!button.disabled, "Button should not be disabled");
304 run_next_test();
305 });
306 });
307 });
309 // Tests that uninstalling a restartless add-on from the search view can be undone
310 add_test(function() {
311 var ID = "addon2@tests.mozilla.org";
312 var list = gDocument.getElementById("search-list");
314 var searchBox = gManagerWindow.document.getElementById("header-search");
315 searchBox.value = "Uninstall";
317 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
318 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
320 wait_for_view_load(gManagerWindow, function() {
321 is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
323 // Make sure to show local add-ons
324 EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
326 AddonManager.getAddonByID(ID, function(aAddon) {
327 ok(aAddon.isActive, "Add-on should be active");
328 ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
329 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
331 var item = get_item_in_list(ID, list);
332 isnot(item, null, "Should have found the add-on in the list");
334 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
335 isnot(button, null, "Should have a remove button");
336 ok(!button.disabled, "Button should not be disabled");
338 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
340 // Force XBL to apply
341 item.clientTop;
343 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
345 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
346 ok(!aAddon.isActive, "Add-on should be inactive");
348 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
349 isnot(button, null, "Should have a restart button");
350 ok(button.hidden, "Restart button should be hidden");
351 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
352 isnot(button, null, "Should have an undo button");
354 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
356 // Force XBL to apply
357 item.clientTop;
359 ok(aAddon.isActive, "Add-on should be active");
360 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
361 isnot(button, null, "Should have a remove button");
362 ok(!button.disabled, "Button should not be disabled");
364 run_next_test();
365 });
366 });
367 });
369 // Tests that uninstalling a disabled restartless add-on from the search view can
370 // be undone and doesn't re-enable
371 add_test(function() {
372 var ID = "addon2@tests.mozilla.org";
373 var list = gDocument.getElementById("search-list");
375 var searchBox = gManagerWindow.document.getElementById("header-search");
376 searchBox.value = "Uninstall";
378 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
379 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
381 wait_for_view_load(gManagerWindow, function() {
382 is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
384 // Make sure to show local add-ons
385 EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
387 AddonManager.getAddonByID(ID, function(aAddon) {
388 aAddon.userDisabled = true;
390 ok(!aAddon.isActive, "Add-on should be inactive");
391 ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
392 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
394 var item = get_item_in_list(ID, list);
395 isnot(item, null, "Should have found the add-on in the list");
397 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
398 isnot(button, null, "Should have a remove button");
399 ok(!button.disabled, "Button should not be disabled");
401 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
403 // Force XBL to apply
404 item.clientTop;
406 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
408 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
409 ok(!aAddon.isActive, "Add-on should be inactive");
411 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
412 isnot(button, null, "Should have a restart button");
413 ok(button.hidden, "Restart button should be hidden");
414 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
415 isnot(button, null, "Should have an undo button");
417 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
419 // Force XBL to apply
420 item.clientTop;
422 ok(!aAddon.isActive, "Add-on should be inactive");
423 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
424 isnot(button, null, "Should have a remove button");
425 ok(!button.disabled, "Button should not be disabled");
427 aAddon.userDisabled = false;
428 ok(aAddon.isActive, "Add-on should be active");
430 run_next_test();
431 });
432 });
433 });
435 // Tests that uninstalling a normal add-on from the details view switches back
436 // to the list view and can be undone
437 add_test(function() {
438 var ID = "addon1@tests.mozilla.org";
439 var list = gDocument.getElementById("addon-list");
441 // Select the extensions category
442 gCategoryUtilities.openType("extension", function() {
443 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
445 AddonManager.getAddonByID(ID, function(aAddon) {
446 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
447 ok(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL, "Add-on should require a restart to uninstall");
449 var item = get_item_in_list(ID, list);
450 isnot(item, null, "Should have found the add-on in the list");
452 EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
453 EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
454 wait_for_view_load(gManagerWindow, function() {
455 is(gDocument.getElementById("view-port").selectedPanel.id, "detail-view", "Should be in the detail view");
457 var button = gDocument.getElementById("detail-uninstall-btn");
458 isnot(button, null, "Should have a remove button");
459 ok(!button.disabled, "Button should not be disabled");
461 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
463 wait_for_view_load(gManagerWindow, function() {
464 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
466 var item = get_item_in_list(ID, list);
467 isnot(item, null, "Should have found the add-on in the list");
468 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
470 ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
472 // Force XBL to apply
473 item.clientTop;
475 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
476 isnot(button, null, "Should have a restart button");
477 ok(!button.hidden, "Restart button should not be hidden");
478 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
479 isnot(button, null, "Should have an undo button");
481 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
483 // Force XBL to apply
484 item.clientTop;
486 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
487 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
488 isnot(button, null, "Should have a remove button");
489 ok(!button.disabled, "Button should not be disabled");
491 run_next_test();
492 });
493 });
494 });
495 });
496 });
498 // Tests that uninstalling a restartless add-on from the details view switches
499 // back to the list view and can be undone
500 add_test(function() {
501 var ID = "addon2@tests.mozilla.org";
502 var list = gDocument.getElementById("addon-list");
504 // Select the extensions category
505 gCategoryUtilities.openType("extension", function() {
506 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
508 AddonManager.getAddonByID(ID, function(aAddon) {
509 ok(aAddon.isActive, "Add-on should be active");
510 ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
511 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
513 var item = get_item_in_list(ID, list);
514 isnot(item, null, "Should have found the add-on in the list");
516 EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
517 EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
518 wait_for_view_load(gManagerWindow, function() {
519 is(gDocument.getElementById("view-port").selectedPanel.id, "detail-view", "Should be in the detail view");
521 var button = gDocument.getElementById("detail-uninstall-btn");
522 isnot(button, null, "Should have a remove button");
523 ok(!button.disabled, "Button should not be disabled");
525 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
527 wait_for_view_load(gManagerWindow, function() {
528 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
530 var item = get_item_in_list(ID, list);
531 isnot(item, null, "Should have found the add-on in the list");
532 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
534 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
535 ok(!aAddon.isActive, "Add-on should be inactive");
537 // Force XBL to apply
538 item.clientTop;
540 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
541 isnot(button, null, "Should have a restart button");
542 ok(button.hidden, "Restart button should be hidden");
543 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
544 isnot(button, null, "Should have an undo button");
546 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
548 // Force XBL to apply
549 item.clientTop;
551 ok(aAddon.isActive, "Add-on should be active");
552 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
553 isnot(button, null, "Should have a remove button");
554 ok(!button.disabled, "Button should not be disabled");
556 run_next_test();
557 });
558 });
559 });
560 });
561 });
563 // Tests that uninstalling a restartless add-on from the details view switches
564 // back to the list view and can be undone and doesn't re-enable
565 add_test(function() {
566 var ID = "addon2@tests.mozilla.org";
567 var list = gDocument.getElementById("addon-list");
569 // Select the extensions category
570 gCategoryUtilities.openType("extension", function() {
571 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
573 AddonManager.getAddonByID(ID, function(aAddon) {
574 aAddon.userDisabled = true;
576 ok(!aAddon.isActive, "Add-on should be inactive");
577 ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
578 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
580 var item = get_item_in_list(ID, list);
581 isnot(item, null, "Should have found the add-on in the list");
583 EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
584 EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
585 wait_for_view_load(gManagerWindow, function() {
586 is(gDocument.getElementById("view-port").selectedPanel.id, "detail-view", "Should be in the detail view");
588 var button = gDocument.getElementById("detail-uninstall-btn");
589 isnot(button, null, "Should have a remove button");
590 ok(!button.disabled, "Button should not be disabled");
592 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
594 wait_for_view_load(gManagerWindow, function() {
595 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
597 var item = get_item_in_list(ID, list);
598 isnot(item, null, "Should have found the add-on in the list");
599 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
601 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
602 ok(!aAddon.isActive, "Add-on should be inactive");
604 // Force XBL to apply
605 item.clientTop;
607 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
608 isnot(button, null, "Should have a restart button");
609 ok(button.hidden, "Restart button should be hidden");
610 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
611 isnot(button, null, "Should have an undo button");
613 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
615 // Force XBL to apply
616 item.clientTop;
618 ok(!aAddon.isActive, "Add-on should be inactive");
619 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
620 isnot(button, null, "Should have a remove button");
621 ok(!button.disabled, "Button should not be disabled");
623 aAddon.userDisabled = false;
624 ok(aAddon.isActive, "Add-on should be active");
626 run_next_test();
627 });
628 });
629 });
630 });
631 });
633 // Tests that a normal add-on pending uninstall shows up in the list view
634 add_test(function() {
635 var ID = "addon1@tests.mozilla.org";
636 var list = gDocument.getElementById("addon-list");
638 // Select the extensions category
639 gCategoryUtilities.openType("extension", function() {
640 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
642 AddonManager.getAddonByID(ID, function(aAddon) {
643 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
644 ok(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL, "Add-on should require a restart to uninstall");
646 var item = get_item_in_list(ID, list);
647 isnot(item, null, "Should have found the add-on in the list");
649 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
650 isnot(button, null, "Should have a remove button");
651 ok(!button.disabled, "Button should not be disabled");
653 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
655 // Force XBL to apply
656 item.clientTop;
658 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
660 ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
662 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
663 isnot(button, null, "Should have a restart button");
664 ok(!button.hidden, "Restart button should not be hidden");
665 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
666 isnot(button, null, "Should have an undo button");
668 gCategoryUtilities.openType("plugin", function() {
669 is(gCategoryUtilities.selectedCategory, "plugin", "View should have changed to plugin");
670 gCategoryUtilities.openType("extension", function() {
671 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
673 var item = get_item_in_list(ID, list);
674 isnot(item, null, "Should have found the add-on in the list");
675 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
677 ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
679 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
680 isnot(button, null, "Should have a restart button");
681 ok(!button.hidden, "Restart button should not be hidden");
682 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
683 isnot(button, null, "Should have an undo button");
685 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
687 // Force XBL to apply
688 item.clientTop;
689 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
690 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
691 isnot(button, null, "Should have a remove button");
692 ok(!button.disabled, "Button should not be disabled");
694 run_next_test();
695 });
696 });
697 });
698 });
699 });
701 // Tests that a normal add-on pending uninstall shows up in the search view
702 add_test(function() {
703 var ID = "addon1@tests.mozilla.org";
704 var list = gDocument.getElementById("search-list");
706 var searchBox = gManagerWindow.document.getElementById("header-search");
707 searchBox.value = "Uninstall";
709 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
710 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
712 wait_for_view_load(gManagerWindow, function() {
713 is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
715 // Make sure to show local add-ons
716 EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
718 AddonManager.getAddonByID(ID, function(aAddon) {
719 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
720 ok(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL, "Add-on should require a restart to uninstall");
722 var item = get_item_in_list(ID, list);
723 isnot(item, null, "Should have found the add-on in the list");
725 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
726 isnot(button, null, "Should have a remove button");
727 ok(!button.disabled, "Button should not be disabled");
729 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
731 // Force XBL to apply
732 item.clientTop;
734 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
736 ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
738 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
739 isnot(button, null, "Should have a restart button");
740 ok(!button.hidden, "Restart button should not be hidden");
741 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
742 isnot(button, null, "Should have an undo button");
744 gCategoryUtilities.openType("plugin", function() {
745 is(gCategoryUtilities.selectedCategory, "plugin", "View should have changed to plugin");
746 searchBox.value = "Uninstall";
748 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
749 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
751 wait_for_view_load(gManagerWindow, function() {
752 is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
754 var item = get_item_in_list(ID, list);
755 isnot(item, null, "Should have found the add-on in the list");
756 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
758 ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
760 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
761 isnot(button, null, "Should have a restart button");
762 ok(!button.hidden, "Restart button should not be hidden");
763 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
764 isnot(button, null, "Should have an undo button");
766 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
768 // Force XBL to apply
769 item.clientTop;
770 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
771 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
772 isnot(button, null, "Should have a remove button");
773 ok(!button.disabled, "Button should not be disabled");
775 run_next_test();
776 });
777 });
778 });
779 });
780 });
782 // Tests that switching away from the list view finalises the uninstall of
783 // multiple restartless add-ons
784 add_test(function() {
785 var ID = "addon2@tests.mozilla.org";
786 var ID2 = "addon6@tests.mozilla.org";
787 var list = gDocument.getElementById("addon-list");
789 // Select the extensions category
790 gCategoryUtilities.openType("extension", function() {
791 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
793 AddonManager.getAddonByID(ID, function(aAddon) {
794 ok(aAddon.isActive, "Add-on should be active");
795 ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
796 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
798 var item = get_item_in_list(ID, list);
799 isnot(item, null, "Should have found the add-on in the list");
801 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
802 isnot(button, null, "Should have a remove button");
803 ok(!button.disabled, "Button should not be disabled");
805 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
807 // Force XBL to apply
808 item.clientTop;
810 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
812 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
813 ok(!aAddon.isActive, "Add-on should be inactive");
815 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
816 isnot(button, null, "Should have a restart button");
817 ok(button.hidden, "Restart button should be hidden");
818 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
819 isnot(button, null, "Should have an undo button");
821 item = get_item_in_list(ID2, list);
822 isnot(item, null, "Should have found the add-on in the list");
824 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
825 isnot(button, null, "Should have a remove button");
826 ok(!button.disabled, "Button should not be disabled");
828 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
830 gCategoryUtilities.openType("plugin", function() {
831 is(gCategoryUtilities.selectedCategory, "plugin", "View should have changed to extension");
833 AddonManager.getAddonsByIDs([ID, ID2], function([aAddon, aAddon2]) {
834 is(aAddon, null, "Add-on should no longer be installed");
835 is(aAddon2, null, "Second add-on should no longer be installed");
837 gCategoryUtilities.openType("extension", function() {
838 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
840 var item = get_item_in_list(ID, list);
841 is(item, null, "Should not have found the add-on in the list");
842 item = get_item_in_list(ID2, list);
843 is(item, null, "Should not have found the second add-on in the list");
845 run_next_test();
846 });
847 });
848 });
849 });
850 });
851 });
853 // Tests that switching away from the search view finalises the uninstall of
854 // multiple restartless add-ons
855 add_test(function() {
856 var ID = "addon3@tests.mozilla.org";
857 var ID2 = "addon7@tests.mozilla.org";
858 var list = gDocument.getElementById("search-list");
860 var searchBox = gManagerWindow.document.getElementById("header-search");
861 searchBox.value = "Uninstall";
863 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
864 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
866 wait_for_view_load(gManagerWindow, function() {
867 is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
869 // Make sure to show local add-ons
870 EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
872 AddonManager.getAddonByID(ID, function(aAddon) {
873 ok(aAddon.isActive, "Add-on should be active");
874 ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
875 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
877 var item = get_item_in_list(ID, list);
878 isnot(item, null, "Should have found the add-on in the list");
880 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
881 isnot(button, null, "Should have a remove button");
882 ok(!button.disabled, "Button should not be disabled");
884 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
886 // Force XBL to apply
887 item.clientTop;
889 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
891 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
892 ok(!aAddon.isActive, "Add-on should be inactive");
894 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
895 isnot(button, null, "Should have a restart button");
896 ok(button.hidden, "Restart button should be hidden");
897 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
898 isnot(button, null, "Should have an undo button");
900 item = get_item_in_list(ID2, list);
901 isnot(item, null, "Should have found the add-on in the list");
903 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
904 isnot(button, null, "Should have a remove button");
905 ok(!button.disabled, "Button should not be disabled");
907 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
909 gCategoryUtilities.openType("plugin", function() {
910 is(gCategoryUtilities.selectedCategory, "plugin", "View should have changed to extension");
912 AddonManager.getAddonsByIDs([ID, ID2], function([aAddon, aAddon2]) {
913 is(aAddon, null, "Add-on should no longer be installed");
914 is(aAddon2, null, "Second add-on should no longer be installed");
916 searchBox.value = "Uninstall";
918 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
919 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
921 wait_for_view_load(gManagerWindow, function() {
922 is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
924 var item = get_item_in_list(ID, list);
925 is(item, null, "Should not have found the add-on in the list");
926 item = get_item_in_list(ID2, list);
927 is(item, null, "Should not have found the second add-on in the list");
929 run_next_test();
930 });
931 });
932 });
933 });
934 });
935 });
937 // Tests that closing the manager from the list view finalises the uninstall of
938 // multiple restartless add-ons
939 add_test(function() {
940 var ID = "addon4@tests.mozilla.org";
941 var ID2 = "addon8@tests.mozilla.org";
942 var list = gDocument.getElementById("addon-list");
944 // Select the extensions category
945 gCategoryUtilities.openType("extension", function() {
946 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
948 AddonManager.getAddonByID(ID, function(aAddon) {
949 ok(aAddon.isActive, "Add-on should be active");
950 ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
951 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
953 var item = get_item_in_list(ID, list);
954 isnot(item, null, "Should have found the add-on in the list");
956 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
957 isnot(button, null, "Should have a remove button");
958 ok(!button.disabled, "Button should not be disabled");
960 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
962 // Force XBL to apply
963 item.clientTop;
965 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
967 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
968 ok(!aAddon.isActive, "Add-on should be inactive");
970 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
971 isnot(button, null, "Should have a restart button");
972 ok(button.hidden, "Restart button should be hidden");
973 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
974 isnot(button, null, "Should have an undo button");
976 item = get_item_in_list(ID2, list);
977 isnot(item, null, "Should have found the add-on in the list");
979 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
980 isnot(button, null, "Should have a remove button");
981 ok(!button.disabled, "Button should not be disabled");
983 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
985 close_manager(gManagerWindow, function() {
986 AddonManager.getAddonsByIDs([ID, ID2], function([aAddon, aAddon2]) {
987 is(aAddon, null, "Add-on should no longer be installed");
988 is(aAddon2, null, "Second add-on should no longer be installed");
990 open_manager(null, function(aWindow) {
991 gManagerWindow = aWindow;
992 gDocument = gManagerWindow.document;
993 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
994 var list = gDocument.getElementById("addon-list");
996 is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
998 var item = get_item_in_list(ID, list);
999 is(item, null, "Should not have found the add-on in the list");
1000 item = get_item_in_list(ID2, list);
1001 is(item, null, "Should not have found the second add-on in the list");
1003 run_next_test();
1004 });
1005 });
1006 });
1007 });
1008 });
1009 });
1011 // Tests that closing the manager from the search view finalises the uninstall
1012 // of multiple restartless add-ons
1013 add_test(function() {
1014 var ID = "addon5@tests.mozilla.org";
1015 var ID2 = "addon9@tests.mozilla.org";
1016 var list = gDocument.getElementById("search-list");
1018 var searchBox = gManagerWindow.document.getElementById("header-search");
1019 searchBox.value = "Uninstall";
1021 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
1022 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
1024 wait_for_view_load(gManagerWindow, function() {
1025 is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
1027 // Make sure to show local add-ons
1028 EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
1030 AddonManager.getAddonByID(ID, function(aAddon) {
1031 ok(aAddon.isActive, "Add-on should be active");
1032 ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
1033 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
1035 var item = get_item_in_list(ID, list);
1036 isnot(item, null, "Should have found the add-on in the list");
1038 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
1039 isnot(button, null, "Should have a remove button");
1040 ok(!button.disabled, "Button should not be disabled");
1042 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
1044 // Force XBL to apply
1045 item.clientTop;
1047 is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
1049 ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
1050 ok(!aAddon.isActive, "Add-on should be inactive");
1052 var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
1053 isnot(button, null, "Should have a restart button");
1054 ok(button.hidden, "Restart button should be hidden");
1055 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
1056 isnot(button, null, "Should have an undo button");
1058 item = get_item_in_list(ID2, list);
1059 isnot(item, null, "Should have found the add-on in the list");
1061 button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
1062 isnot(button, null, "Should have a remove button");
1063 ok(!button.disabled, "Button should not be disabled");
1065 EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
1067 close_manager(gManagerWindow, function() {
1068 AddonManager.getAddonsByIDs([ID, ID2], function([aAddon, aAddon2]) {
1069 is(aAddon, null, "Add-on should no longer be installed");
1070 is(aAddon2, null, "Second add-on should no longer be installed");
1072 open_manager(null, function(aWindow) {
1073 gManagerWindow = aWindow;
1074 gDocument = gManagerWindow.document;
1075 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
1076 var list = gDocument.getElementById("search-list");
1077 var searchBox = gManagerWindow.document.getElementById("header-search");
1079 searchBox.value = "Uninstall";
1081 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
1082 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
1084 wait_for_view_load(gManagerWindow, function() {
1085 is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
1087 var item = get_item_in_list(ID, list);
1088 is(item, null, "Should not have found the add-on in the list");
1089 item = get_item_in_list(ID2, list);
1090 is(item, null, "Should not have found the second add-on in the list");
1092 run_next_test();
1093 });
1094 });
1095 });
1096 });
1097 });
1098 });
1099 });