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: // Bug 587970 - Provide ability "Update all now" within 'Available Updates' screen michael@0: michael@0: var gManagerWindow; michael@0: var gProvider; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gProvider = new MockProvider(); michael@0: michael@0: gProvider.createAddons([{ michael@0: id: "addon1@tests.mozilla.org", michael@0: name: "addon 1", michael@0: version: "1.0", michael@0: applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE michael@0: }, { michael@0: id: "addon2@tests.mozilla.org", michael@0: name: "addon 2", michael@0: version: "2.0", michael@0: applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE michael@0: }, { michael@0: id: "addon3@tests.mozilla.org", michael@0: name: "addon 3", michael@0: version: "3.0", michael@0: applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE michael@0: }]); michael@0: michael@0: michael@0: open_manager("addons://updates/available", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: michael@0: function end_test() { michael@0: close_manager(gManagerWindow, finish); michael@0: } michael@0: michael@0: michael@0: add_test(function() { michael@0: var list = gManagerWindow.document.getElementById("updates-list"); michael@0: is(list.childNodes.length, 0, "Available updates list should be empty"); michael@0: michael@0: var emptyNotice = gManagerWindow.document.getElementById("empty-availableUpdates-msg"); michael@0: is_element_visible(emptyNotice, "Empty notice should be visible"); michael@0: michael@0: var updateSelected = gManagerWindow.document.getElementById("update-selected-btn"); michael@0: is_element_hidden(updateSelected, "Update Selected button should be hidden"); michael@0: michael@0: info("Adding updates"); michael@0: gProvider.createInstalls([{ michael@0: name: "addon 1", michael@0: version: "1.1", michael@0: existingAddon: gProvider.addons[0] michael@0: }, { michael@0: name: "addon 2", michael@0: version: "2.1", michael@0: existingAddon: gProvider.addons[1] michael@0: }, { michael@0: name: "addon 3", michael@0: version: "3.1", michael@0: existingAddon: gProvider.addons[2] michael@0: }]); michael@0: michael@0: function wait_for_refresh() { michael@0: if (list.childNodes.length == 3 && michael@0: list.childNodes[0].mManualUpdate && michael@0: list.childNodes[1].mManualUpdate && michael@0: list.childNodes[2].mManualUpdate) { michael@0: run_next_test(); michael@0: } else { michael@0: info("Waiting for pane to refresh"); michael@0: setTimeout(wait_for_refresh, 10); michael@0: } michael@0: } michael@0: info("Waiting for pane to refresh"); michael@0: setTimeout(wait_for_refresh, 10); michael@0: }); michael@0: michael@0: michael@0: add_test(function() { michael@0: var list = gManagerWindow.document.getElementById("updates-list"); michael@0: is(list.childNodes.length, 3, "Available updates list should have 2 items"); michael@0: michael@0: var item1 = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); michael@0: isnot(item1, null, "Item for addon1@tests.mozilla.org should be in list"); michael@0: var item2 = get_addon_element(gManagerWindow, "addon2@tests.mozilla.org"); michael@0: isnot(item2, null, "Item for addon2@tests.mozilla.org should be in list"); michael@0: var item3 = get_addon_element(gManagerWindow, "addon3@tests.mozilla.org"); michael@0: isnot(item3, null, "Item for addon3@tests.mozilla.org should be in list"); michael@0: michael@0: var emptyNotice = gManagerWindow.document.getElementById("empty-availableUpdates-msg"); michael@0: is_element_hidden(emptyNotice, "Empty notice should be hidden"); michael@0: michael@0: var updateSelected = gManagerWindow.document.getElementById("update-selected-btn"); michael@0: is_element_visible(updateSelected, "Update Selected button should be visible"); michael@0: is(updateSelected.disabled, false, "Update Selected button should be enabled by default"); michael@0: michael@0: is(item1._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon1"); michael@0: is(item2._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon2"); michael@0: is(item3._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon3"); michael@0: michael@0: info("Unchecking Include Update checkbox for addon1"); michael@0: EventUtils.synthesizeMouse(item1._includeUpdate, 2, 2, { }, gManagerWindow); michael@0: is(item1._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon1"); michael@0: is(updateSelected.disabled, false, "Update Selected button should still be enabled"); michael@0: michael@0: info("Unchecking Include Update checkbox for addon2"); michael@0: EventUtils.synthesizeMouse(item2._includeUpdate, 2, 2, { }, gManagerWindow); michael@0: is(item2._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon2"); michael@0: is(updateSelected.disabled, false, "Update Selected button should still be enabled"); michael@0: michael@0: info("Unchecking Include Update checkbox for addon3"); michael@0: EventUtils.synthesizeMouse(item3._includeUpdate, 2, 2, { }, gManagerWindow); michael@0: is(item3._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon3"); michael@0: is(updateSelected.disabled, true, "Update Selected button should now be disabled"); michael@0: michael@0: info("Checking Include Update checkbox for addon2"); michael@0: EventUtils.synthesizeMouse(item2._includeUpdate, 2, 2, { }, gManagerWindow); michael@0: is(item2._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon2"); michael@0: is(updateSelected.disabled, false, "Update Selected button should now be enabled"); michael@0: michael@0: info("Checking Include Update checkbox for addon3"); michael@0: EventUtils.synthesizeMouse(item3._includeUpdate, 2, 2, { }, gManagerWindow); michael@0: is(item3._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon3"); michael@0: is(updateSelected.disabled, false, "Update Selected button should now be enabled"); michael@0: michael@0: var installCount = 0; michael@0: var listener = { michael@0: onDownloadStarted: function(aInstall) { michael@0: isnot(aInstall.existingAddon.id, "addon1@tests.mozilla.org", "Should not have seen a download start for addon1"); michael@0: }, michael@0: michael@0: onInstallEnded: function(aInstall) { michael@0: if (++installCount < 2) michael@0: return; michael@0: michael@0: gProvider.installs[0].removeTestListener(listener); michael@0: gProvider.installs[1].removeTestListener(listener); michael@0: gProvider.installs[2].removeTestListener(listener); michael@0: michael@0: // Installs are started synchronously so by the time an executeSoon is michael@0: // executed all installs that are going to start will have started michael@0: executeSoon(function() { michael@0: is(gProvider.installs[0].state, AddonManager.STATE_AVAILABLE, "addon1 should not have been upgraded"); michael@0: is(gProvider.installs[1].state, AddonManager.STATE_INSTALLED, "addon2 should have been upgraded"); michael@0: is(gProvider.installs[2].state, AddonManager.STATE_INSTALLED, "addon3 should have been upgraded"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: } michael@0: gProvider.installs[0].addTestListener(listener); michael@0: gProvider.installs[1].addTestListener(listener); michael@0: gProvider.installs[2].addTestListener(listener); michael@0: info("Clicking Update Selected button"); michael@0: EventUtils.synthesizeMouseAtCenter(updateSelected, { }, gManagerWindow); michael@0: }); michael@0: michael@0: michael@0: add_test(function() { michael@0: var updateSelected = gManagerWindow.document.getElementById("update-selected-btn"); michael@0: is(updateSelected.disabled, true, "Update Selected button should be disabled"); michael@0: michael@0: var item1 = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); michael@0: isnot(item1, null, "Item for addon1@tests.mozilla.org should be in list"); michael@0: is(item1._includeUpdate.checked, false, "Include Update checkbox should not have changed"); michael@0: michael@0: info("Checking Include Update checkbox for addon1"); michael@0: EventUtils.synthesizeMouse(item1._includeUpdate, 2, 2, { }, gManagerWindow); michael@0: is(item1._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon1"); michael@0: is(updateSelected.disabled, false, "Update Selected button should now not be disabled"); michael@0: michael@0: run_next_test(); michael@0: });