toolkit/mozapps/extensions/test/browser/browser_uninstalling.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_uninstalling.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1099 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +// Tests that searching for add-ons works correctly
     1.9 +
    1.10 +var gManagerWindow;
    1.11 +var gDocument;
    1.12 +var gCategoryUtilities;
    1.13 +var gProvider;
    1.14 +
    1.15 +function test() {
    1.16 +  requestLongerTimeout(2);
    1.17 +  waitForExplicitFinish();
    1.18 +
    1.19 +  gProvider = new MockProvider();
    1.20 +
    1.21 +  gProvider.createAddons([{
    1.22 +    id: "addon1@tests.mozilla.org",
    1.23 +    name: "Uninstall needs restart",
    1.24 +    type: "extension",
    1.25 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_UNINSTALL
    1.26 +  }, {
    1.27 +    id: "addon2@tests.mozilla.org",
    1.28 +    name: "Uninstall doesn't need restart 1",
    1.29 +    type: "extension",
    1.30 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
    1.31 +  }, {
    1.32 +    id: "addon3@tests.mozilla.org",
    1.33 +    name: "Uninstall doesn't need restart 2",
    1.34 +    type: "extension",
    1.35 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
    1.36 +  }, {
    1.37 +    id: "addon4@tests.mozilla.org",
    1.38 +    name: "Uninstall doesn't need restart 3",
    1.39 +    type: "extension",
    1.40 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
    1.41 +  }, {
    1.42 +    id: "addon5@tests.mozilla.org",
    1.43 +    name: "Uninstall doesn't need restart 4",
    1.44 +    type: "extension",
    1.45 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
    1.46 +  }, {
    1.47 +    id: "addon6@tests.mozilla.org",
    1.48 +    name: "Uninstall doesn't need restart 5",
    1.49 +    type: "extension",
    1.50 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
    1.51 +  }, {
    1.52 +    id: "addon7@tests.mozilla.org",
    1.53 +    name: "Uninstall doesn't need restart 6",
    1.54 +    type: "extension",
    1.55 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
    1.56 +  }, {
    1.57 +    id: "addon8@tests.mozilla.org",
    1.58 +    name: "Uninstall doesn't need restart 7",
    1.59 +    type: "extension",
    1.60 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
    1.61 +  }, {
    1.62 +    id: "addon9@tests.mozilla.org",
    1.63 +    name: "Uninstall doesn't need restart 8",
    1.64 +    type: "extension",
    1.65 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
    1.66 +  }]);
    1.67 +
    1.68 +  open_manager(null, function(aWindow) {
    1.69 +    gManagerWindow = aWindow;
    1.70 +    gDocument = gManagerWindow.document;
    1.71 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    1.72 +    run_next_test();
    1.73 +  });
    1.74 +}
    1.75 +
    1.76 +function end_test() {
    1.77 +  close_manager(gManagerWindow, function() {
    1.78 +    finish();
    1.79 +  });
    1.80 +}
    1.81 +
    1.82 +function get_item_in_list(aId, aList) {
    1.83 +  var item = aList.firstChild;
    1.84 +  while (item) {
    1.85 +    if ("mAddon" in item && item.mAddon.id == aId) {
    1.86 +      aList.ensureElementIsVisible(item);
    1.87 +      return item;
    1.88 +    }
    1.89 +    item = item.nextSibling;
    1.90 +  }
    1.91 +  return null;
    1.92 +}
    1.93 +
    1.94 +// Tests that uninstalling a normal add-on from the list view can be undone
    1.95 +add_test(function() {
    1.96 +  var ID = "addon1@tests.mozilla.org";
    1.97 +  var list = gDocument.getElementById("addon-list");
    1.98 +
    1.99 +  // Select the extensions category
   1.100 +  gCategoryUtilities.openType("extension", function() {
   1.101 +    is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.102 +
   1.103 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.104 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.105 +      ok(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL, "Add-on should require a restart to uninstall");
   1.106 +
   1.107 +      var item = get_item_in_list(ID, list);
   1.108 +      isnot(item, null, "Should have found the add-on in the list");
   1.109 +
   1.110 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.111 +      isnot(button, null, "Should have a remove button");
   1.112 +      ok(!button.disabled, "Button should not be disabled");
   1.113 +
   1.114 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.115 +
   1.116 +      // Force XBL to apply
   1.117 +      item.clientTop;
   1.118 +
   1.119 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.120 +
   1.121 +      ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
   1.122 +
   1.123 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.124 +      isnot(button, null, "Should have a restart button");
   1.125 +      ok(!button.hidden, "Restart button should not be hidden");
   1.126 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.127 +      isnot(button, null, "Should have an undo button");
   1.128 +
   1.129 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.130 +
   1.131 +      // Force XBL to apply
   1.132 +      item.clientTop;
   1.133 +
   1.134 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.135 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.136 +      isnot(button, null, "Should have a remove button");
   1.137 +      ok(!button.disabled, "Button should not be disabled");
   1.138 +
   1.139 +      run_next_test();
   1.140 +    });
   1.141 +  });
   1.142 +});
   1.143 +
   1.144 +// Tests that uninstalling a restartless add-on from the list view can be undone
   1.145 +add_test(function() {
   1.146 +  var ID = "addon2@tests.mozilla.org";
   1.147 +  var list = gDocument.getElementById("addon-list");
   1.148 +
   1.149 +  // Select the extensions category
   1.150 +  gCategoryUtilities.openType("extension", function() {
   1.151 +    is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.152 +
   1.153 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.154 +      ok(aAddon.isActive, "Add-on should be active");
   1.155 +      ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
   1.156 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.157 +
   1.158 +      var item = get_item_in_list(ID, list);
   1.159 +      isnot(item, null, "Should have found the add-on in the list");
   1.160 +
   1.161 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.162 +      isnot(button, null, "Should have a remove button");
   1.163 +      ok(!button.disabled, "Button should not be disabled");
   1.164 +
   1.165 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.166 +
   1.167 +      // Force XBL to apply
   1.168 +      item.clientTop;
   1.169 +
   1.170 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.171 +
   1.172 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.173 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.174 +
   1.175 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.176 +      isnot(button, null, "Should have a restart button");
   1.177 +      ok(button.hidden, "Restart button should be hidden");
   1.178 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.179 +      isnot(button, null, "Should have an undo button");
   1.180 +
   1.181 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.182 +
   1.183 +      // Force XBL to apply
   1.184 +      item.clientTop;
   1.185 +
   1.186 +      ok(aAddon.isActive, "Add-on should be active");
   1.187 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.188 +      isnot(button, null, "Should have a remove button");
   1.189 +      ok(!button.disabled, "Button should not be disabled");
   1.190 +
   1.191 +      run_next_test();
   1.192 +    });
   1.193 +  });
   1.194 +});
   1.195 +
   1.196 +// Tests that uninstalling a disabled restartless add-on from the list view can
   1.197 +// be undone and doesn't re-enable
   1.198 +add_test(function() {
   1.199 +  var ID = "addon2@tests.mozilla.org";
   1.200 +  var list = gDocument.getElementById("addon-list");
   1.201 +
   1.202 +  // Select the extensions category
   1.203 +  gCategoryUtilities.openType("extension", function() {
   1.204 +    is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.205 +
   1.206 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.207 +      aAddon.userDisabled = true;
   1.208 +
   1.209 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.210 +      ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
   1.211 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.212 +
   1.213 +      var item = get_item_in_list(ID, list);
   1.214 +      isnot(item, null, "Should have found the add-on in the list");
   1.215 +
   1.216 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.217 +      isnot(button, null, "Should have a remove button");
   1.218 +      ok(!button.disabled, "Button should not be disabled");
   1.219 +
   1.220 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.221 +
   1.222 +      // Force XBL to apply
   1.223 +      item.clientTop;
   1.224 +
   1.225 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.226 +
   1.227 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.228 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.229 +
   1.230 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.231 +      isnot(button, null, "Should have a restart button");
   1.232 +      ok(button.hidden, "Restart button should be hidden");
   1.233 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.234 +      isnot(button, null, "Should have an undo button");
   1.235 +
   1.236 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.237 +
   1.238 +      // Force XBL to apply
   1.239 +      item.clientTop;
   1.240 +
   1.241 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.242 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.243 +      isnot(button, null, "Should have a remove button");
   1.244 +      ok(!button.disabled, "Button should not be disabled");
   1.245 +
   1.246 +      aAddon.userDisabled = false;
   1.247 +      ok(aAddon.isActive, "Add-on should be active");
   1.248 +
   1.249 +      run_next_test();
   1.250 +    });
   1.251 +  });
   1.252 +});
   1.253 +
   1.254 +// Tests that uninstalling a normal add-on from the search view can be undone
   1.255 +add_test(function() {
   1.256 +  var ID = "addon1@tests.mozilla.org";
   1.257 +  var list = gDocument.getElementById("search-list");
   1.258 +
   1.259 +  var searchBox = gManagerWindow.document.getElementById("header-search");
   1.260 +  searchBox.value = "Uninstall";
   1.261 +
   1.262 +  EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
   1.263 +  EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
   1.264 +
   1.265 +  wait_for_view_load(gManagerWindow, function() {
   1.266 +    is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
   1.267 +
   1.268 +    // Make sure to show local add-ons
   1.269 +    EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
   1.270 +
   1.271 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.272 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.273 +      ok(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL, "Add-on should require a restart to uninstall");
   1.274 +
   1.275 +      var item = get_item_in_list(ID, list);
   1.276 +      isnot(item, null, "Should have found the add-on in the list");
   1.277 +
   1.278 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.279 +      isnot(button, null, "Should have a remove button");
   1.280 +      ok(!button.disabled, "Button should not be disabled");
   1.281 +
   1.282 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.283 +
   1.284 +      // Force XBL to apply
   1.285 +      item.clientTop;
   1.286 +
   1.287 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.288 +
   1.289 +      ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
   1.290 +
   1.291 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.292 +      isnot(button, null, "Should have a restart button");
   1.293 +      ok(!button.hidden, "Restart button should not be hidden");
   1.294 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.295 +      isnot(button, null, "Should have an undo button");
   1.296 +
   1.297 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.298 +
   1.299 +      // Force XBL to apply
   1.300 +      item.clientTop;
   1.301 +
   1.302 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.303 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.304 +      isnot(button, null, "Should have a remove button");
   1.305 +      ok(!button.disabled, "Button should not be disabled");
   1.306 +
   1.307 +      run_next_test();
   1.308 +    });
   1.309 +  });
   1.310 +});
   1.311 +
   1.312 +// Tests that uninstalling a restartless add-on from the search view can be undone
   1.313 +add_test(function() {
   1.314 +  var ID = "addon2@tests.mozilla.org";
   1.315 +  var list = gDocument.getElementById("search-list");
   1.316 +
   1.317 +  var searchBox = gManagerWindow.document.getElementById("header-search");
   1.318 +  searchBox.value = "Uninstall";
   1.319 +
   1.320 +  EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
   1.321 +  EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
   1.322 +
   1.323 +  wait_for_view_load(gManagerWindow, function() {
   1.324 +    is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
   1.325 +
   1.326 +    // Make sure to show local add-ons
   1.327 +    EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
   1.328 +
   1.329 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.330 +      ok(aAddon.isActive, "Add-on should be active");
   1.331 +      ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
   1.332 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.333 +
   1.334 +      var item = get_item_in_list(ID, list);
   1.335 +      isnot(item, null, "Should have found the add-on in the list");
   1.336 +
   1.337 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.338 +      isnot(button, null, "Should have a remove button");
   1.339 +      ok(!button.disabled, "Button should not be disabled");
   1.340 +
   1.341 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.342 +
   1.343 +      // Force XBL to apply
   1.344 +      item.clientTop;
   1.345 +
   1.346 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.347 +
   1.348 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.349 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.350 +
   1.351 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.352 +      isnot(button, null, "Should have a restart button");
   1.353 +      ok(button.hidden, "Restart button should be hidden");
   1.354 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.355 +      isnot(button, null, "Should have an undo button");
   1.356 +
   1.357 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.358 +
   1.359 +      // Force XBL to apply
   1.360 +      item.clientTop;
   1.361 +
   1.362 +      ok(aAddon.isActive, "Add-on should be active");
   1.363 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.364 +      isnot(button, null, "Should have a remove button");
   1.365 +      ok(!button.disabled, "Button should not be disabled");
   1.366 +
   1.367 +      run_next_test();
   1.368 +    });
   1.369 +  });
   1.370 +});
   1.371 +
   1.372 +// Tests that uninstalling a disabled restartless add-on from the search view can
   1.373 +// be undone and doesn't re-enable
   1.374 +add_test(function() {
   1.375 +  var ID = "addon2@tests.mozilla.org";
   1.376 +  var list = gDocument.getElementById("search-list");
   1.377 +
   1.378 +  var searchBox = gManagerWindow.document.getElementById("header-search");
   1.379 +  searchBox.value = "Uninstall";
   1.380 +
   1.381 +  EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
   1.382 +  EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
   1.383 +
   1.384 +  wait_for_view_load(gManagerWindow, function() {
   1.385 +    is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
   1.386 +
   1.387 +    // Make sure to show local add-ons
   1.388 +    EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
   1.389 +
   1.390 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.391 +      aAddon.userDisabled = true;
   1.392 +
   1.393 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.394 +      ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
   1.395 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.396 +
   1.397 +      var item = get_item_in_list(ID, list);
   1.398 +      isnot(item, null, "Should have found the add-on in the list");
   1.399 +
   1.400 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.401 +      isnot(button, null, "Should have a remove button");
   1.402 +      ok(!button.disabled, "Button should not be disabled");
   1.403 +
   1.404 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.405 +
   1.406 +      // Force XBL to apply
   1.407 +      item.clientTop;
   1.408 +
   1.409 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.410 +
   1.411 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.412 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.413 +
   1.414 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.415 +      isnot(button, null, "Should have a restart button");
   1.416 +      ok(button.hidden, "Restart button should be hidden");
   1.417 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.418 +      isnot(button, null, "Should have an undo button");
   1.419 +
   1.420 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.421 +
   1.422 +      // Force XBL to apply
   1.423 +      item.clientTop;
   1.424 +
   1.425 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.426 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.427 +      isnot(button, null, "Should have a remove button");
   1.428 +      ok(!button.disabled, "Button should not be disabled");
   1.429 +
   1.430 +      aAddon.userDisabled = false;
   1.431 +      ok(aAddon.isActive, "Add-on should be active");
   1.432 +
   1.433 +      run_next_test();
   1.434 +    });
   1.435 +  });
   1.436 +});
   1.437 +
   1.438 +// Tests that uninstalling a normal add-on from the details view switches back
   1.439 +// to the list view and can be undone
   1.440 +add_test(function() {
   1.441 +  var ID = "addon1@tests.mozilla.org";
   1.442 +  var list = gDocument.getElementById("addon-list");
   1.443 +
   1.444 +  // Select the extensions category
   1.445 +  gCategoryUtilities.openType("extension", function() {
   1.446 +    is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.447 +
   1.448 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.449 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.450 +      ok(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL, "Add-on should require a restart to uninstall");
   1.451 +
   1.452 +      var item = get_item_in_list(ID, list);
   1.453 +      isnot(item, null, "Should have found the add-on in the list");
   1.454 +
   1.455 +      EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
   1.456 +      EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
   1.457 +      wait_for_view_load(gManagerWindow, function() {
   1.458 +        is(gDocument.getElementById("view-port").selectedPanel.id, "detail-view", "Should be in the detail view");
   1.459 +
   1.460 +        var button = gDocument.getElementById("detail-uninstall-btn");
   1.461 +        isnot(button, null, "Should have a remove button");
   1.462 +        ok(!button.disabled, "Button should not be disabled");
   1.463 +
   1.464 +        EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.465 +
   1.466 +        wait_for_view_load(gManagerWindow, function() {
   1.467 +          is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.468 +
   1.469 +          var item = get_item_in_list(ID, list);
   1.470 +          isnot(item, null, "Should have found the add-on in the list");
   1.471 +          is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.472 +
   1.473 +          ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
   1.474 +
   1.475 +          // Force XBL to apply
   1.476 +          item.clientTop;
   1.477 +
   1.478 +          var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.479 +          isnot(button, null, "Should have a restart button");
   1.480 +          ok(!button.hidden, "Restart button should not be hidden");
   1.481 +          button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.482 +          isnot(button, null, "Should have an undo button");
   1.483 +
   1.484 +          EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.485 +
   1.486 +          // Force XBL to apply
   1.487 +          item.clientTop;
   1.488 +
   1.489 +          ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.490 +          button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.491 +          isnot(button, null, "Should have a remove button");
   1.492 +          ok(!button.disabled, "Button should not be disabled");
   1.493 +
   1.494 +          run_next_test();
   1.495 +        });
   1.496 +      });
   1.497 +    });
   1.498 +  });
   1.499 +});
   1.500 +
   1.501 +// Tests that uninstalling a restartless add-on from the details view switches
   1.502 +// back to the list view and can be undone
   1.503 +add_test(function() {
   1.504 +  var ID = "addon2@tests.mozilla.org";
   1.505 +  var list = gDocument.getElementById("addon-list");
   1.506 +
   1.507 +  // Select the extensions category
   1.508 +  gCategoryUtilities.openType("extension", function() {
   1.509 +    is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.510 +
   1.511 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.512 +      ok(aAddon.isActive, "Add-on should be active");
   1.513 +      ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
   1.514 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.515 +
   1.516 +      var item = get_item_in_list(ID, list);
   1.517 +      isnot(item, null, "Should have found the add-on in the list");
   1.518 +
   1.519 +      EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
   1.520 +      EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
   1.521 +      wait_for_view_load(gManagerWindow, function() {
   1.522 +        is(gDocument.getElementById("view-port").selectedPanel.id, "detail-view", "Should be in the detail view");
   1.523 +
   1.524 +        var button = gDocument.getElementById("detail-uninstall-btn");
   1.525 +        isnot(button, null, "Should have a remove button");
   1.526 +        ok(!button.disabled, "Button should not be disabled");
   1.527 +
   1.528 +        EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.529 +
   1.530 +        wait_for_view_load(gManagerWindow, function() {
   1.531 +          is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.532 +
   1.533 +          var item = get_item_in_list(ID, list);
   1.534 +          isnot(item, null, "Should have found the add-on in the list");
   1.535 +          is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.536 +
   1.537 +          ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.538 +          ok(!aAddon.isActive, "Add-on should be inactive");
   1.539 +
   1.540 +          // Force XBL to apply
   1.541 +          item.clientTop;
   1.542 +
   1.543 +          var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.544 +          isnot(button, null, "Should have a restart button");
   1.545 +          ok(button.hidden, "Restart button should be hidden");
   1.546 +          button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.547 +          isnot(button, null, "Should have an undo button");
   1.548 +
   1.549 +          EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.550 +
   1.551 +          // Force XBL to apply
   1.552 +          item.clientTop;
   1.553 +
   1.554 +          ok(aAddon.isActive, "Add-on should be active");
   1.555 +          button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.556 +          isnot(button, null, "Should have a remove button");
   1.557 +          ok(!button.disabled, "Button should not be disabled");
   1.558 +
   1.559 +          run_next_test();
   1.560 +        });
   1.561 +      });
   1.562 +    });
   1.563 +  });
   1.564 +});
   1.565 +
   1.566 +// Tests that uninstalling a restartless add-on from the details view switches
   1.567 +// back to the list view and can be undone and doesn't re-enable
   1.568 +add_test(function() {
   1.569 +  var ID = "addon2@tests.mozilla.org";
   1.570 +  var list = gDocument.getElementById("addon-list");
   1.571 +
   1.572 +  // Select the extensions category
   1.573 +  gCategoryUtilities.openType("extension", function() {
   1.574 +    is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.575 +
   1.576 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.577 +      aAddon.userDisabled = true;
   1.578 +
   1.579 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.580 +      ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
   1.581 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.582 +
   1.583 +      var item = get_item_in_list(ID, list);
   1.584 +      isnot(item, null, "Should have found the add-on in the list");
   1.585 +
   1.586 +      EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
   1.587 +      EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
   1.588 +      wait_for_view_load(gManagerWindow, function() {
   1.589 +        is(gDocument.getElementById("view-port").selectedPanel.id, "detail-view", "Should be in the detail view");
   1.590 +
   1.591 +        var button = gDocument.getElementById("detail-uninstall-btn");
   1.592 +        isnot(button, null, "Should have a remove button");
   1.593 +        ok(!button.disabled, "Button should not be disabled");
   1.594 +
   1.595 +        EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.596 +
   1.597 +        wait_for_view_load(gManagerWindow, function() {
   1.598 +          is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.599 +
   1.600 +          var item = get_item_in_list(ID, list);
   1.601 +          isnot(item, null, "Should have found the add-on in the list");
   1.602 +          is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.603 +
   1.604 +          ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.605 +          ok(!aAddon.isActive, "Add-on should be inactive");
   1.606 +
   1.607 +          // Force XBL to apply
   1.608 +          item.clientTop;
   1.609 +
   1.610 +          var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.611 +          isnot(button, null, "Should have a restart button");
   1.612 +          ok(button.hidden, "Restart button should be hidden");
   1.613 +          button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.614 +          isnot(button, null, "Should have an undo button");
   1.615 +
   1.616 +          EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.617 +
   1.618 +          // Force XBL to apply
   1.619 +          item.clientTop;
   1.620 +
   1.621 +          ok(!aAddon.isActive, "Add-on should be inactive");
   1.622 +          button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.623 +          isnot(button, null, "Should have a remove button");
   1.624 +          ok(!button.disabled, "Button should not be disabled");
   1.625 +
   1.626 +          aAddon.userDisabled = false;
   1.627 +          ok(aAddon.isActive, "Add-on should be active");
   1.628 +
   1.629 +          run_next_test();
   1.630 +        });
   1.631 +      });
   1.632 +    });
   1.633 +  });
   1.634 +});
   1.635 +
   1.636 +// Tests that a normal add-on pending uninstall shows up in the list view
   1.637 +add_test(function() {
   1.638 +  var ID = "addon1@tests.mozilla.org";
   1.639 +  var list = gDocument.getElementById("addon-list");
   1.640 +
   1.641 +  // Select the extensions category
   1.642 +  gCategoryUtilities.openType("extension", function() {
   1.643 +    is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.644 +
   1.645 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.646 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.647 +      ok(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL, "Add-on should require a restart to uninstall");
   1.648 +
   1.649 +      var item = get_item_in_list(ID, list);
   1.650 +      isnot(item, null, "Should have found the add-on in the list");
   1.651 +
   1.652 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.653 +      isnot(button, null, "Should have a remove button");
   1.654 +      ok(!button.disabled, "Button should not be disabled");
   1.655 +
   1.656 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.657 +
   1.658 +      // Force XBL to apply
   1.659 +      item.clientTop;
   1.660 +
   1.661 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.662 +
   1.663 +      ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
   1.664 +
   1.665 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.666 +      isnot(button, null, "Should have a restart button");
   1.667 +      ok(!button.hidden, "Restart button should not be hidden");
   1.668 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.669 +      isnot(button, null, "Should have an undo button");
   1.670 +
   1.671 +      gCategoryUtilities.openType("plugin", function() {
   1.672 +        is(gCategoryUtilities.selectedCategory, "plugin", "View should have changed to plugin");
   1.673 +        gCategoryUtilities.openType("extension", function() {
   1.674 +          is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.675 +
   1.676 +          var item = get_item_in_list(ID, list);
   1.677 +          isnot(item, null, "Should have found the add-on in the list");
   1.678 +          is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.679 +
   1.680 +          ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
   1.681 +
   1.682 +          var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.683 +          isnot(button, null, "Should have a restart button");
   1.684 +          ok(!button.hidden, "Restart button should not be hidden");
   1.685 +          button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.686 +          isnot(button, null, "Should have an undo button");
   1.687 +
   1.688 +          EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.689 +
   1.690 +          // Force XBL to apply
   1.691 +          item.clientTop;
   1.692 +          ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.693 +          button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.694 +          isnot(button, null, "Should have a remove button");
   1.695 +          ok(!button.disabled, "Button should not be disabled");
   1.696 +
   1.697 +          run_next_test();
   1.698 +        });
   1.699 +      });
   1.700 +    });
   1.701 +  });
   1.702 +});
   1.703 +
   1.704 +// Tests that a normal add-on pending uninstall shows up in the search view
   1.705 +add_test(function() {
   1.706 +  var ID = "addon1@tests.mozilla.org";
   1.707 +  var list = gDocument.getElementById("search-list");
   1.708 +
   1.709 +  var searchBox = gManagerWindow.document.getElementById("header-search");
   1.710 +  searchBox.value = "Uninstall";
   1.711 +
   1.712 +  EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
   1.713 +  EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
   1.714 +
   1.715 +  wait_for_view_load(gManagerWindow, function() {
   1.716 +    is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
   1.717 +
   1.718 +    // Make sure to show local add-ons
   1.719 +    EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
   1.720 +
   1.721 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.722 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.723 +      ok(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL, "Add-on should require a restart to uninstall");
   1.724 +
   1.725 +      var item = get_item_in_list(ID, list);
   1.726 +      isnot(item, null, "Should have found the add-on in the list");
   1.727 +
   1.728 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.729 +      isnot(button, null, "Should have a remove button");
   1.730 +      ok(!button.disabled, "Button should not be disabled");
   1.731 +
   1.732 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.733 +
   1.734 +      // Force XBL to apply
   1.735 +      item.clientTop;
   1.736 +
   1.737 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.738 +
   1.739 +      ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
   1.740 +
   1.741 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.742 +      isnot(button, null, "Should have a restart button");
   1.743 +      ok(!button.hidden, "Restart button should not be hidden");
   1.744 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.745 +      isnot(button, null, "Should have an undo button");
   1.746 +
   1.747 +      gCategoryUtilities.openType("plugin", function() {
   1.748 +        is(gCategoryUtilities.selectedCategory, "plugin", "View should have changed to plugin");
   1.749 +        searchBox.value = "Uninstall";
   1.750 +
   1.751 +        EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
   1.752 +        EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
   1.753 +
   1.754 +        wait_for_view_load(gManagerWindow, function() {
   1.755 +          is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
   1.756 +
   1.757 +          var item = get_item_in_list(ID, list);
   1.758 +          isnot(item, null, "Should have found the add-on in the list");
   1.759 +          is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.760 +
   1.761 +          ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
   1.762 +
   1.763 +          var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.764 +          isnot(button, null, "Should have a restart button");
   1.765 +          ok(!button.hidden, "Restart button should not be hidden");
   1.766 +          button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.767 +          isnot(button, null, "Should have an undo button");
   1.768 +
   1.769 +          EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.770 +
   1.771 +          // Force XBL to apply
   1.772 +          item.clientTop;
   1.773 +          ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.774 +          button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.775 +          isnot(button, null, "Should have a remove button");
   1.776 +          ok(!button.disabled, "Button should not be disabled");
   1.777 +
   1.778 +          run_next_test();
   1.779 +        });
   1.780 +      });
   1.781 +    });
   1.782 +  });
   1.783 +});
   1.784 +
   1.785 +// Tests that switching away from the list view finalises the uninstall of
   1.786 +// multiple restartless add-ons
   1.787 +add_test(function() {
   1.788 +  var ID = "addon2@tests.mozilla.org";
   1.789 +  var ID2 = "addon6@tests.mozilla.org";
   1.790 +  var list = gDocument.getElementById("addon-list");
   1.791 +
   1.792 +  // Select the extensions category
   1.793 +  gCategoryUtilities.openType("extension", function() {
   1.794 +    is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.795 +
   1.796 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.797 +      ok(aAddon.isActive, "Add-on should be active");
   1.798 +      ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
   1.799 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.800 +
   1.801 +      var item = get_item_in_list(ID, list);
   1.802 +      isnot(item, null, "Should have found the add-on in the list");
   1.803 +
   1.804 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.805 +      isnot(button, null, "Should have a remove button");
   1.806 +      ok(!button.disabled, "Button should not be disabled");
   1.807 +
   1.808 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.809 +
   1.810 +      // Force XBL to apply
   1.811 +      item.clientTop;
   1.812 +
   1.813 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.814 +
   1.815 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.816 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.817 +
   1.818 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.819 +      isnot(button, null, "Should have a restart button");
   1.820 +      ok(button.hidden, "Restart button should be hidden");
   1.821 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.822 +      isnot(button, null, "Should have an undo button");
   1.823 +
   1.824 +      item = get_item_in_list(ID2, list);
   1.825 +      isnot(item, null, "Should have found the add-on in the list");
   1.826 +
   1.827 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.828 +      isnot(button, null, "Should have a remove button");
   1.829 +      ok(!button.disabled, "Button should not be disabled");
   1.830 +
   1.831 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.832 +
   1.833 +      gCategoryUtilities.openType("plugin", function() {
   1.834 +        is(gCategoryUtilities.selectedCategory, "plugin", "View should have changed to extension");
   1.835 +
   1.836 +        AddonManager.getAddonsByIDs([ID, ID2], function([aAddon, aAddon2]) {
   1.837 +          is(aAddon, null, "Add-on should no longer be installed");
   1.838 +          is(aAddon2, null, "Second add-on should no longer be installed");
   1.839 +
   1.840 +          gCategoryUtilities.openType("extension", function() {
   1.841 +            is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.842 +
   1.843 +            var item = get_item_in_list(ID, list);
   1.844 +            is(item, null, "Should not have found the add-on in the list");
   1.845 +            item = get_item_in_list(ID2, list);
   1.846 +            is(item, null, "Should not have found the second add-on in the list");
   1.847 +
   1.848 +            run_next_test();
   1.849 +          });
   1.850 +        });
   1.851 +      });
   1.852 +    });
   1.853 +  });
   1.854 +});
   1.855 +
   1.856 +// Tests that switching away from the search view finalises the uninstall of
   1.857 +// multiple restartless add-ons
   1.858 +add_test(function() {
   1.859 +  var ID = "addon3@tests.mozilla.org";
   1.860 +  var ID2 = "addon7@tests.mozilla.org";
   1.861 +  var list = gDocument.getElementById("search-list");
   1.862 +
   1.863 +  var searchBox = gManagerWindow.document.getElementById("header-search");
   1.864 +  searchBox.value = "Uninstall";
   1.865 +
   1.866 +  EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
   1.867 +  EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
   1.868 +
   1.869 +  wait_for_view_load(gManagerWindow, function() {
   1.870 +    is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
   1.871 +
   1.872 +    // Make sure to show local add-ons
   1.873 +    EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
   1.874 +
   1.875 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.876 +      ok(aAddon.isActive, "Add-on should be active");
   1.877 +      ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
   1.878 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.879 +
   1.880 +      var item = get_item_in_list(ID, list);
   1.881 +      isnot(item, null, "Should have found the add-on in the list");
   1.882 +
   1.883 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.884 +      isnot(button, null, "Should have a remove button");
   1.885 +      ok(!button.disabled, "Button should not be disabled");
   1.886 +
   1.887 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.888 +
   1.889 +      // Force XBL to apply
   1.890 +      item.clientTop;
   1.891 +
   1.892 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.893 +
   1.894 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.895 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.896 +
   1.897 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.898 +      isnot(button, null, "Should have a restart button");
   1.899 +      ok(button.hidden, "Restart button should be hidden");
   1.900 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.901 +      isnot(button, null, "Should have an undo button");
   1.902 +
   1.903 +      item = get_item_in_list(ID2, list);
   1.904 +      isnot(item, null, "Should have found the add-on in the list");
   1.905 +
   1.906 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.907 +      isnot(button, null, "Should have a remove button");
   1.908 +      ok(!button.disabled, "Button should not be disabled");
   1.909 +
   1.910 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.911 +
   1.912 +      gCategoryUtilities.openType("plugin", function() {
   1.913 +        is(gCategoryUtilities.selectedCategory, "plugin", "View should have changed to extension");
   1.914 +
   1.915 +        AddonManager.getAddonsByIDs([ID, ID2], function([aAddon, aAddon2]) {
   1.916 +          is(aAddon, null, "Add-on should no longer be installed");
   1.917 +          is(aAddon2, null, "Second add-on should no longer be installed");
   1.918 +
   1.919 +          searchBox.value = "Uninstall";
   1.920 +
   1.921 +          EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
   1.922 +          EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
   1.923 +
   1.924 +          wait_for_view_load(gManagerWindow, function() {
   1.925 +            is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
   1.926 +
   1.927 +            var item = get_item_in_list(ID, list);
   1.928 +            is(item, null, "Should not have found the add-on in the list");
   1.929 +            item = get_item_in_list(ID2, list);
   1.930 +            is(item, null, "Should not have found the second add-on in the list");
   1.931 +
   1.932 +            run_next_test();
   1.933 +          });
   1.934 +        });
   1.935 +      });
   1.936 +    });
   1.937 +  });
   1.938 +});
   1.939 +
   1.940 +// Tests that closing the manager from the list view finalises the uninstall of
   1.941 +// multiple restartless add-ons
   1.942 +add_test(function() {
   1.943 +  var ID = "addon4@tests.mozilla.org";
   1.944 +  var ID2 = "addon8@tests.mozilla.org";
   1.945 +  var list = gDocument.getElementById("addon-list");
   1.946 +
   1.947 +  // Select the extensions category
   1.948 +  gCategoryUtilities.openType("extension", function() {
   1.949 +    is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
   1.950 +
   1.951 +    AddonManager.getAddonByID(ID, function(aAddon) {
   1.952 +      ok(aAddon.isActive, "Add-on should be active");
   1.953 +      ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
   1.954 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.955 +
   1.956 +      var item = get_item_in_list(ID, list);
   1.957 +      isnot(item, null, "Should have found the add-on in the list");
   1.958 +
   1.959 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.960 +      isnot(button, null, "Should have a remove button");
   1.961 +      ok(!button.disabled, "Button should not be disabled");
   1.962 +
   1.963 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.964 +
   1.965 +      // Force XBL to apply
   1.966 +      item.clientTop;
   1.967 +
   1.968 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
   1.969 +
   1.970 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
   1.971 +      ok(!aAddon.isActive, "Add-on should be inactive");
   1.972 +
   1.973 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
   1.974 +      isnot(button, null, "Should have a restart button");
   1.975 +      ok(button.hidden, "Restart button should be hidden");
   1.976 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
   1.977 +      isnot(button, null, "Should have an undo button");
   1.978 +
   1.979 +      item = get_item_in_list(ID2, list);
   1.980 +      isnot(item, null, "Should have found the add-on in the list");
   1.981 +
   1.982 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
   1.983 +      isnot(button, null, "Should have a remove button");
   1.984 +      ok(!button.disabled, "Button should not be disabled");
   1.985 +
   1.986 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
   1.987 +
   1.988 +      close_manager(gManagerWindow, function() {
   1.989 +        AddonManager.getAddonsByIDs([ID, ID2], function([aAddon, aAddon2]) {
   1.990 +          is(aAddon, null, "Add-on should no longer be installed");
   1.991 +          is(aAddon2, null, "Second add-on should no longer be installed");
   1.992 +
   1.993 +          open_manager(null, function(aWindow) {
   1.994 +            gManagerWindow = aWindow;
   1.995 +            gDocument = gManagerWindow.document;
   1.996 +            gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.997 +            var list = gDocument.getElementById("addon-list");
   1.998 +
   1.999 +            is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension");
  1.1000 +
  1.1001 +            var item = get_item_in_list(ID, list);
  1.1002 +            is(item, null, "Should not have found the add-on in the list");
  1.1003 +            item = get_item_in_list(ID2, list);
  1.1004 +            is(item, null, "Should not have found the second add-on in the list");
  1.1005 +
  1.1006 +            run_next_test();
  1.1007 +          });
  1.1008 +        });
  1.1009 +      });
  1.1010 +    });
  1.1011 +  });
  1.1012 +});
  1.1013 +
  1.1014 +// Tests that closing the manager from the search view finalises the uninstall
  1.1015 +// of multiple restartless add-ons
  1.1016 +add_test(function() {
  1.1017 +  var ID = "addon5@tests.mozilla.org";
  1.1018 +  var ID2 = "addon9@tests.mozilla.org";
  1.1019 +  var list = gDocument.getElementById("search-list");
  1.1020 +
  1.1021 +  var searchBox = gManagerWindow.document.getElementById("header-search");
  1.1022 +  searchBox.value = "Uninstall";
  1.1023 +
  1.1024 +  EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
  1.1025 +  EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
  1.1026 +
  1.1027 +  wait_for_view_load(gManagerWindow, function() {
  1.1028 +    is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
  1.1029 +
  1.1030 +    // Make sure to show local add-ons
  1.1031 +    EventUtils.synthesizeMouseAtCenter(gDocument.getElementById("search-filter-local"), { }, gManagerWindow);
  1.1032 +
  1.1033 +    AddonManager.getAddonByID(ID, function(aAddon) {
  1.1034 +      ok(aAddon.isActive, "Add-on should be active");
  1.1035 +      ok(!(aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL), "Add-on should not require a restart to uninstall");
  1.1036 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
  1.1037 +
  1.1038 +      var item = get_item_in_list(ID, list);
  1.1039 +      isnot(item, null, "Should have found the add-on in the list");
  1.1040 +
  1.1041 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
  1.1042 +      isnot(button, null, "Should have a remove button");
  1.1043 +      ok(!button.disabled, "Button should not be disabled");
  1.1044 +
  1.1045 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
  1.1046 +
  1.1047 +      // Force XBL to apply
  1.1048 +      item.clientTop;
  1.1049 +
  1.1050 +      is(item.getAttribute("pending"), "uninstall", "Add-on should be uninstalling");
  1.1051 +
  1.1052 +      ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
  1.1053 +      ok(!aAddon.isActive, "Add-on should be inactive");
  1.1054 +
  1.1055 +      var button = gDocument.getAnonymousElementByAttribute(item, "anonid", "restart-btn");
  1.1056 +      isnot(button, null, "Should have a restart button");
  1.1057 +      ok(button.hidden, "Restart button should be hidden");
  1.1058 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "undo-btn");
  1.1059 +      isnot(button, null, "Should have an undo button");
  1.1060 +
  1.1061 +      item = get_item_in_list(ID2, list);
  1.1062 +      isnot(item, null, "Should have found the add-on in the list");
  1.1063 +
  1.1064 +      button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
  1.1065 +      isnot(button, null, "Should have a remove button");
  1.1066 +      ok(!button.disabled, "Button should not be disabled");
  1.1067 +
  1.1068 +      EventUtils.synthesizeMouseAtCenter(button, { }, gManagerWindow);
  1.1069 +
  1.1070 +      close_manager(gManagerWindow, function() {
  1.1071 +        AddonManager.getAddonsByIDs([ID, ID2], function([aAddon, aAddon2]) {
  1.1072 +          is(aAddon, null, "Add-on should no longer be installed");
  1.1073 +          is(aAddon2, null, "Second add-on should no longer be installed");
  1.1074 +
  1.1075 +          open_manager(null, function(aWindow) {
  1.1076 +            gManagerWindow = aWindow;
  1.1077 +            gDocument = gManagerWindow.document;
  1.1078 +            gCategoryUtilities = new CategoryUtilities(gManagerWindow);
  1.1079 +            var list = gDocument.getElementById("search-list");
  1.1080 +            var searchBox = gManagerWindow.document.getElementById("header-search");
  1.1081 +
  1.1082 +            searchBox.value = "Uninstall";
  1.1083 +
  1.1084 +            EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
  1.1085 +            EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
  1.1086 +
  1.1087 +            wait_for_view_load(gManagerWindow, function() {
  1.1088 +              is(gCategoryUtilities.selectedCategory, "search", "View should have changed to search");
  1.1089 +
  1.1090 +              var item = get_item_in_list(ID, list);
  1.1091 +              is(item, null, "Should not have found the add-on in the list");
  1.1092 +              item = get_item_in_list(ID2, list);
  1.1093 +              is(item, null, "Should not have found the second add-on in the list");
  1.1094 +
  1.1095 +              run_next_test();
  1.1096 +            });
  1.1097 +          });
  1.1098 +        });
  1.1099 +      });
  1.1100 +    });
  1.1101 +  });
  1.1102 +});

mercurial