michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests that upgrading bootstrapped add-ons behaves correctly while the michael@0: // manager is open michael@0: michael@0: var gManagerWindow; michael@0: var gCategoryUtilities; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: open_manager("addons://list/extension", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: close_manager(gManagerWindow, finish); michael@0: } michael@0: michael@0: function get_list_item_count() { michael@0: return get_test_items_in_list(gManagerWindow).length; michael@0: } michael@0: michael@0: function get_node(parent, anonid) { michael@0: return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid); michael@0: } michael@0: michael@0: function get_class_node(parent, cls) { michael@0: return parent.ownerDocument.getAnonymousElementByAttribute(parent, "class", cls); michael@0: } michael@0: michael@0: function install_addon(aXpi, aCallback) { michael@0: AddonManager.getInstallForURL(TESTROOT + "addons/" + aXpi + ".xpi", michael@0: function(aInstall) { michael@0: aInstall.addListener({ michael@0: onInstallEnded: function(aInstall) { michael@0: executeSoon(aCallback); michael@0: } michael@0: }); michael@0: aInstall.install(); michael@0: }, "application/x-xpinstall"); michael@0: } michael@0: michael@0: function check_addon(aAddon, version) { michael@0: is(get_list_item_count(), 1, "Should be one item in the list"); michael@0: is(aAddon.version, version, "Add-on should have the right version"); michael@0: michael@0: let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); michael@0: ok(!!item, "Should see the add-on in the list"); michael@0: michael@0: // Force XBL to apply michael@0: item.clientTop; michael@0: michael@0: is(get_node(item, "version").value, version, "Version should be correct"); michael@0: michael@0: if (aAddon.userDisabled) michael@0: is_element_visible(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden"); michael@0: else michael@0: is_element_hidden(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden"); michael@0: } michael@0: michael@0: // Install version 1 then upgrade to version 2 with the manager open michael@0: add_test(function() { michael@0: install_addon("browser_bug596336_1", function() { michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { michael@0: check_addon(aAddon, "1.0"); michael@0: ok(!aAddon.userDisabled, "Add-on should not be disabled"); michael@0: michael@0: install_addon("browser_bug596336_2", function() { michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { michael@0: check_addon(aAddon, "2.0"); michael@0: ok(!aAddon.userDisabled, "Add-on should not be disabled"); michael@0: michael@0: aAddon.uninstall(); michael@0: michael@0: is(get_list_item_count(), 0, "Should be no items in the list"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: // Install version 1 mark it as disabled then upgrade to version 2 with the michael@0: // manager open michael@0: add_test(function() { michael@0: install_addon("browser_bug596336_1", function() { michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { michael@0: aAddon.userDisabled = true; michael@0: check_addon(aAddon, "1.0"); michael@0: ok(aAddon.userDisabled, "Add-on should be disabled"); michael@0: michael@0: install_addon("browser_bug596336_2", function() { michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { michael@0: check_addon(aAddon, "2.0"); michael@0: ok(aAddon.userDisabled, "Add-on should be disabled"); michael@0: michael@0: aAddon.uninstall(); michael@0: michael@0: is(get_list_item_count(), 0, "Should be no items in the list"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: // Install version 1 click the remove button and then upgrade to version 2 with michael@0: // the manager open michael@0: add_test(function() { michael@0: install_addon("browser_bug596336_1", function() { michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { michael@0: check_addon(aAddon, "1.0"); michael@0: ok(!aAddon.userDisabled, "Add-on should not be disabled"); michael@0: michael@0: let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); michael@0: EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow); michael@0: michael@0: // Force XBL to apply michael@0: item.clientTop; michael@0: michael@0: ok(aAddon.userDisabled, "Add-on should be disabled"); michael@0: ok(!aAddon.pendingUninstall, "Add-on should not be pending uninstall"); michael@0: is_element_visible(get_class_node(item, "pending"), "Pending message should be visible"); michael@0: michael@0: install_addon("browser_bug596336_2", function() { michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { michael@0: check_addon(aAddon, "2.0"); michael@0: ok(!aAddon.userDisabled, "Add-on should not be disabled"); michael@0: michael@0: aAddon.uninstall(); michael@0: michael@0: is(get_list_item_count(), 0, "Should be no items in the list"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: // Install version 1, disable it, click the remove button and then upgrade to michael@0: // version 2 with the manager open michael@0: add_test(function() { michael@0: install_addon("browser_bug596336_1", function() { michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { michael@0: aAddon.userDisabled = true; michael@0: check_addon(aAddon, "1.0"); michael@0: ok(aAddon.userDisabled, "Add-on should be disabled"); michael@0: michael@0: let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); michael@0: EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow); michael@0: michael@0: // Force XBL to apply michael@0: item.clientTop; michael@0: michael@0: ok(aAddon.userDisabled, "Add-on should be disabled"); michael@0: ok(!aAddon.pendingUninstall, "Add-on should not be pending uninstall"); michael@0: is_element_visible(get_class_node(item, "pending"), "Pending message should be visible"); michael@0: michael@0: install_addon("browser_bug596336_2", function() { michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { michael@0: check_addon(aAddon, "2.0"); michael@0: ok(aAddon.userDisabled, "Add-on should be disabled"); michael@0: michael@0: aAddon.uninstall(); michael@0: michael@0: is(get_list_item_count(), 0, "Should be no items in the list"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: });