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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 // Tests that upgrading bootstrapped add-ons behaves correctly while the
michael@0 6 // manager is open
michael@0 7
michael@0 8 var gManagerWindow;
michael@0 9 var gCategoryUtilities;
michael@0 10
michael@0 11 function test() {
michael@0 12 waitForExplicitFinish();
michael@0 13
michael@0 14 open_manager("addons://list/extension", function(aWindow) {
michael@0 15 gManagerWindow = aWindow;
michael@0 16 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
michael@0 17 run_next_test();
michael@0 18 });
michael@0 19 }
michael@0 20
michael@0 21 function end_test() {
michael@0 22 close_manager(gManagerWindow, finish);
michael@0 23 }
michael@0 24
michael@0 25 function get_list_item_count() {
michael@0 26 return get_test_items_in_list(gManagerWindow).length;
michael@0 27 }
michael@0 28
michael@0 29 function get_node(parent, anonid) {
michael@0 30 return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
michael@0 31 }
michael@0 32
michael@0 33 function get_class_node(parent, cls) {
michael@0 34 return parent.ownerDocument.getAnonymousElementByAttribute(parent, "class", cls);
michael@0 35 }
michael@0 36
michael@0 37 function install_addon(aXpi, aCallback) {
michael@0 38 AddonManager.getInstallForURL(TESTROOT + "addons/" + aXpi + ".xpi",
michael@0 39 function(aInstall) {
michael@0 40 aInstall.addListener({
michael@0 41 onInstallEnded: function(aInstall) {
michael@0 42 executeSoon(aCallback);
michael@0 43 }
michael@0 44 });
michael@0 45 aInstall.install();
michael@0 46 }, "application/x-xpinstall");
michael@0 47 }
michael@0 48
michael@0 49 function check_addon(aAddon, version) {
michael@0 50 is(get_list_item_count(), 1, "Should be one item in the list");
michael@0 51 is(aAddon.version, version, "Add-on should have the right version");
michael@0 52
michael@0 53 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
michael@0 54 ok(!!item, "Should see the add-on in the list");
michael@0 55
michael@0 56 // Force XBL to apply
michael@0 57 item.clientTop;
michael@0 58
michael@0 59 is(get_node(item, "version").value, version, "Version should be correct");
michael@0 60
michael@0 61 if (aAddon.userDisabled)
michael@0 62 is_element_visible(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden");
michael@0 63 else
michael@0 64 is_element_hidden(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden");
michael@0 65 }
michael@0 66
michael@0 67 // Install version 1 then upgrade to version 2 with the manager open
michael@0 68 add_test(function() {
michael@0 69 install_addon("browser_bug596336_1", function() {
michael@0 70 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
michael@0 71 check_addon(aAddon, "1.0");
michael@0 72 ok(!aAddon.userDisabled, "Add-on should not be disabled");
michael@0 73
michael@0 74 install_addon("browser_bug596336_2", function() {
michael@0 75 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
michael@0 76 check_addon(aAddon, "2.0");
michael@0 77 ok(!aAddon.userDisabled, "Add-on should not be disabled");
michael@0 78
michael@0 79 aAddon.uninstall();
michael@0 80
michael@0 81 is(get_list_item_count(), 0, "Should be no items in the list");
michael@0 82
michael@0 83 run_next_test();
michael@0 84 });
michael@0 85 });
michael@0 86 });
michael@0 87 });
michael@0 88 });
michael@0 89
michael@0 90 // Install version 1 mark it as disabled then upgrade to version 2 with the
michael@0 91 // manager open
michael@0 92 add_test(function() {
michael@0 93 install_addon("browser_bug596336_1", function() {
michael@0 94 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
michael@0 95 aAddon.userDisabled = true;
michael@0 96 check_addon(aAddon, "1.0");
michael@0 97 ok(aAddon.userDisabled, "Add-on should be disabled");
michael@0 98
michael@0 99 install_addon("browser_bug596336_2", function() {
michael@0 100 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
michael@0 101 check_addon(aAddon, "2.0");
michael@0 102 ok(aAddon.userDisabled, "Add-on should be disabled");
michael@0 103
michael@0 104 aAddon.uninstall();
michael@0 105
michael@0 106 is(get_list_item_count(), 0, "Should be no items in the list");
michael@0 107
michael@0 108 run_next_test();
michael@0 109 });
michael@0 110 });
michael@0 111 });
michael@0 112 });
michael@0 113 });
michael@0 114
michael@0 115 // Install version 1 click the remove button and then upgrade to version 2 with
michael@0 116 // the manager open
michael@0 117 add_test(function() {
michael@0 118 install_addon("browser_bug596336_1", function() {
michael@0 119 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
michael@0 120 check_addon(aAddon, "1.0");
michael@0 121 ok(!aAddon.userDisabled, "Add-on should not be disabled");
michael@0 122
michael@0 123 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
michael@0 124 EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);
michael@0 125
michael@0 126 // Force XBL to apply
michael@0 127 item.clientTop;
michael@0 128
michael@0 129 ok(aAddon.userDisabled, "Add-on should be disabled");
michael@0 130 ok(!aAddon.pendingUninstall, "Add-on should not be pending uninstall");
michael@0 131 is_element_visible(get_class_node(item, "pending"), "Pending message should be visible");
michael@0 132
michael@0 133 install_addon("browser_bug596336_2", function() {
michael@0 134 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
michael@0 135 check_addon(aAddon, "2.0");
michael@0 136 ok(!aAddon.userDisabled, "Add-on should not be disabled");
michael@0 137
michael@0 138 aAddon.uninstall();
michael@0 139
michael@0 140 is(get_list_item_count(), 0, "Should be no items in the list");
michael@0 141
michael@0 142 run_next_test();
michael@0 143 });
michael@0 144 });
michael@0 145 });
michael@0 146 });
michael@0 147 });
michael@0 148
michael@0 149 // Install version 1, disable it, click the remove button and then upgrade to
michael@0 150 // version 2 with the manager open
michael@0 151 add_test(function() {
michael@0 152 install_addon("browser_bug596336_1", function() {
michael@0 153 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
michael@0 154 aAddon.userDisabled = true;
michael@0 155 check_addon(aAddon, "1.0");
michael@0 156 ok(aAddon.userDisabled, "Add-on should be disabled");
michael@0 157
michael@0 158 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
michael@0 159 EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);
michael@0 160
michael@0 161 // Force XBL to apply
michael@0 162 item.clientTop;
michael@0 163
michael@0 164 ok(aAddon.userDisabled, "Add-on should be disabled");
michael@0 165 ok(!aAddon.pendingUninstall, "Add-on should not be pending uninstall");
michael@0 166 is_element_visible(get_class_node(item, "pending"), "Pending message should be visible");
michael@0 167
michael@0 168 install_addon("browser_bug596336_2", function() {
michael@0 169 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
michael@0 170 check_addon(aAddon, "2.0");
michael@0 171 ok(aAddon.userDisabled, "Add-on should be disabled");
michael@0 172
michael@0 173 aAddon.uninstall();
michael@0 174
michael@0 175 is(get_list_item_count(), 0, "Should be no items in the list");
michael@0 176
michael@0 177 run_next_test();
michael@0 178 });
michael@0 179 });
michael@0 180 });
michael@0 181 });
michael@0 182 });

mercurial