toolkit/mozapps/extensions/test/browser/browser_bug596336.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_bug596336.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,182 @@
     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 upgrading bootstrapped add-ons behaves correctly while the
     1.9 +// manager is open
    1.10 +
    1.11 +var gManagerWindow;
    1.12 +var gCategoryUtilities;
    1.13 +
    1.14 +function test() {
    1.15 +  waitForExplicitFinish();
    1.16 +
    1.17 +  open_manager("addons://list/extension", function(aWindow) {
    1.18 +    gManagerWindow = aWindow;
    1.19 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    1.20 +    run_next_test();
    1.21 +  });
    1.22 +}
    1.23 +
    1.24 +function end_test() {
    1.25 +  close_manager(gManagerWindow, finish);
    1.26 +}
    1.27 +
    1.28 +function get_list_item_count() {
    1.29 +  return get_test_items_in_list(gManagerWindow).length;
    1.30 +}
    1.31 +
    1.32 +function get_node(parent, anonid) {
    1.33 +  return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
    1.34 +}
    1.35 +
    1.36 +function get_class_node(parent, cls) {
    1.37 +  return parent.ownerDocument.getAnonymousElementByAttribute(parent, "class", cls);
    1.38 +}
    1.39 +
    1.40 +function install_addon(aXpi, aCallback) {
    1.41 +  AddonManager.getInstallForURL(TESTROOT + "addons/" + aXpi + ".xpi",
    1.42 +                                function(aInstall) {
    1.43 +    aInstall.addListener({
    1.44 +      onInstallEnded: function(aInstall) {
    1.45 +        executeSoon(aCallback);
    1.46 +      }
    1.47 +    });
    1.48 +    aInstall.install();
    1.49 +  }, "application/x-xpinstall");
    1.50 +}
    1.51 +
    1.52 +function check_addon(aAddon, version) {
    1.53 +  is(get_list_item_count(), 1, "Should be one item in the list");
    1.54 +  is(aAddon.version, version, "Add-on should have the right version");
    1.55 +
    1.56 +  let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
    1.57 +  ok(!!item, "Should see the add-on in the list");
    1.58 +
    1.59 +  // Force XBL to apply
    1.60 +  item.clientTop;
    1.61 +
    1.62 +  is(get_node(item, "version").value, version, "Version should be correct");
    1.63 +
    1.64 +  if (aAddon.userDisabled)
    1.65 +    is_element_visible(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden");
    1.66 +  else
    1.67 +    is_element_hidden(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden");
    1.68 +}
    1.69 +
    1.70 +// Install version 1 then upgrade to version 2 with the manager open
    1.71 +add_test(function() {
    1.72 +  install_addon("browser_bug596336_1", function() {
    1.73 +    AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
    1.74 +      check_addon(aAddon, "1.0");
    1.75 +      ok(!aAddon.userDisabled, "Add-on should not be disabled");
    1.76 +
    1.77 +      install_addon("browser_bug596336_2", function() {
    1.78 +        AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
    1.79 +          check_addon(aAddon, "2.0");
    1.80 +          ok(!aAddon.userDisabled, "Add-on should not be disabled");
    1.81 +
    1.82 +          aAddon.uninstall();
    1.83 +
    1.84 +          is(get_list_item_count(), 0, "Should be no items in the list");
    1.85 +
    1.86 +          run_next_test();
    1.87 +        });
    1.88 +      });
    1.89 +    });
    1.90 +  });
    1.91 +});
    1.92 +
    1.93 +// Install version 1 mark it as disabled then upgrade to version 2 with the
    1.94 +// manager open
    1.95 +add_test(function() {
    1.96 +  install_addon("browser_bug596336_1", function() {
    1.97 +    AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
    1.98 +      aAddon.userDisabled = true;
    1.99 +      check_addon(aAddon, "1.0");
   1.100 +      ok(aAddon.userDisabled, "Add-on should be disabled");
   1.101 +
   1.102 +      install_addon("browser_bug596336_2", function() {
   1.103 +        AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
   1.104 +          check_addon(aAddon, "2.0");
   1.105 +          ok(aAddon.userDisabled, "Add-on should be disabled");
   1.106 +
   1.107 +          aAddon.uninstall();
   1.108 +
   1.109 +          is(get_list_item_count(), 0, "Should be no items in the list");
   1.110 +
   1.111 +          run_next_test();
   1.112 +        });
   1.113 +      });
   1.114 +    });
   1.115 +  });
   1.116 +});
   1.117 +
   1.118 +// Install version 1 click the remove button and then upgrade to version 2 with
   1.119 +// the manager open
   1.120 +add_test(function() {
   1.121 +  install_addon("browser_bug596336_1", function() {
   1.122 +    AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
   1.123 +      check_addon(aAddon, "1.0");
   1.124 +      ok(!aAddon.userDisabled, "Add-on should not be disabled");
   1.125 +
   1.126 +      let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
   1.127 +      EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);
   1.128 +
   1.129 +      // Force XBL to apply
   1.130 +      item.clientTop;
   1.131 +
   1.132 +      ok(aAddon.userDisabled, "Add-on should be disabled");
   1.133 +      ok(!aAddon.pendingUninstall, "Add-on should not be pending uninstall");
   1.134 +      is_element_visible(get_class_node(item, "pending"), "Pending message should be visible");
   1.135 +
   1.136 +      install_addon("browser_bug596336_2", function() {
   1.137 +        AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
   1.138 +          check_addon(aAddon, "2.0");
   1.139 +          ok(!aAddon.userDisabled, "Add-on should not be disabled");
   1.140 +
   1.141 +          aAddon.uninstall();
   1.142 +
   1.143 +          is(get_list_item_count(), 0, "Should be no items in the list");
   1.144 +
   1.145 +          run_next_test();
   1.146 +        });
   1.147 +      });
   1.148 +    });
   1.149 +  });
   1.150 +});
   1.151 +
   1.152 +// Install version 1, disable it, click the remove button and then upgrade to
   1.153 +// version 2 with the manager open
   1.154 +add_test(function() {
   1.155 +  install_addon("browser_bug596336_1", function() {
   1.156 +    AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
   1.157 +      aAddon.userDisabled = true;
   1.158 +      check_addon(aAddon, "1.0");
   1.159 +      ok(aAddon.userDisabled, "Add-on should be disabled");
   1.160 +
   1.161 +      let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
   1.162 +      EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);
   1.163 +
   1.164 +      // Force XBL to apply
   1.165 +      item.clientTop;
   1.166 +
   1.167 +      ok(aAddon.userDisabled, "Add-on should be disabled");
   1.168 +      ok(!aAddon.pendingUninstall, "Add-on should not be pending uninstall");
   1.169 +      is_element_visible(get_class_node(item, "pending"), "Pending message should be visible");
   1.170 +
   1.171 +      install_addon("browser_bug596336_2", function() {
   1.172 +        AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
   1.173 +          check_addon(aAddon, "2.0");
   1.174 +          ok(aAddon.userDisabled, "Add-on should be disabled");
   1.175 +
   1.176 +          aAddon.uninstall();
   1.177 +
   1.178 +          is(get_list_item_count(), 0, "Should be no items in the list");
   1.179 +
   1.180 +          run_next_test();
   1.181 +        });
   1.182 +      });
   1.183 +    });
   1.184 +  });
   1.185 +});

mercurial