1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_bug587970.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,180 @@ 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 +// Bug 587970 - Provide ability "Update all now" within 'Available Updates' screen 1.9 + 1.10 +var gManagerWindow; 1.11 +var gProvider; 1.12 + 1.13 +function test() { 1.14 + waitForExplicitFinish(); 1.15 + 1.16 + gProvider = new MockProvider(); 1.17 + 1.18 + gProvider.createAddons([{ 1.19 + id: "addon1@tests.mozilla.org", 1.20 + name: "addon 1", 1.21 + version: "1.0", 1.22 + applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE 1.23 + }, { 1.24 + id: "addon2@tests.mozilla.org", 1.25 + name: "addon 2", 1.26 + version: "2.0", 1.27 + applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE 1.28 + }, { 1.29 + id: "addon3@tests.mozilla.org", 1.30 + name: "addon 3", 1.31 + version: "3.0", 1.32 + applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE 1.33 + }]); 1.34 + 1.35 + 1.36 + open_manager("addons://updates/available", function(aWindow) { 1.37 + gManagerWindow = aWindow; 1.38 + run_next_test(); 1.39 + }); 1.40 +} 1.41 + 1.42 + 1.43 +function end_test() { 1.44 + close_manager(gManagerWindow, finish); 1.45 +} 1.46 + 1.47 + 1.48 +add_test(function() { 1.49 + var list = gManagerWindow.document.getElementById("updates-list"); 1.50 + is(list.childNodes.length, 0, "Available updates list should be empty"); 1.51 + 1.52 + var emptyNotice = gManagerWindow.document.getElementById("empty-availableUpdates-msg"); 1.53 + is_element_visible(emptyNotice, "Empty notice should be visible"); 1.54 + 1.55 + var updateSelected = gManagerWindow.document.getElementById("update-selected-btn"); 1.56 + is_element_hidden(updateSelected, "Update Selected button should be hidden"); 1.57 + 1.58 + info("Adding updates"); 1.59 + gProvider.createInstalls([{ 1.60 + name: "addon 1", 1.61 + version: "1.1", 1.62 + existingAddon: gProvider.addons[0] 1.63 + }, { 1.64 + name: "addon 2", 1.65 + version: "2.1", 1.66 + existingAddon: gProvider.addons[1] 1.67 + }, { 1.68 + name: "addon 3", 1.69 + version: "3.1", 1.70 + existingAddon: gProvider.addons[2] 1.71 + }]); 1.72 + 1.73 + function wait_for_refresh() { 1.74 + if (list.childNodes.length == 3 && 1.75 + list.childNodes[0].mManualUpdate && 1.76 + list.childNodes[1].mManualUpdate && 1.77 + list.childNodes[2].mManualUpdate) { 1.78 + run_next_test(); 1.79 + } else { 1.80 + info("Waiting for pane to refresh"); 1.81 + setTimeout(wait_for_refresh, 10); 1.82 + } 1.83 + } 1.84 + info("Waiting for pane to refresh"); 1.85 + setTimeout(wait_for_refresh, 10); 1.86 +}); 1.87 + 1.88 + 1.89 +add_test(function() { 1.90 + var list = gManagerWindow.document.getElementById("updates-list"); 1.91 + is(list.childNodes.length, 3, "Available updates list should have 2 items"); 1.92 + 1.93 + var item1 = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); 1.94 + isnot(item1, null, "Item for addon1@tests.mozilla.org should be in list"); 1.95 + var item2 = get_addon_element(gManagerWindow, "addon2@tests.mozilla.org"); 1.96 + isnot(item2, null, "Item for addon2@tests.mozilla.org should be in list"); 1.97 + var item3 = get_addon_element(gManagerWindow, "addon3@tests.mozilla.org"); 1.98 + isnot(item3, null, "Item for addon3@tests.mozilla.org should be in list"); 1.99 + 1.100 + var emptyNotice = gManagerWindow.document.getElementById("empty-availableUpdates-msg"); 1.101 + is_element_hidden(emptyNotice, "Empty notice should be hidden"); 1.102 + 1.103 + var updateSelected = gManagerWindow.document.getElementById("update-selected-btn"); 1.104 + is_element_visible(updateSelected, "Update Selected button should be visible"); 1.105 + is(updateSelected.disabled, false, "Update Selected button should be enabled by default"); 1.106 + 1.107 + is(item1._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon1"); 1.108 + is(item2._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon2"); 1.109 + is(item3._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon3"); 1.110 + 1.111 + info("Unchecking Include Update checkbox for addon1"); 1.112 + EventUtils.synthesizeMouse(item1._includeUpdate, 2, 2, { }, gManagerWindow); 1.113 + is(item1._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon1"); 1.114 + is(updateSelected.disabled, false, "Update Selected button should still be enabled"); 1.115 + 1.116 + info("Unchecking Include Update checkbox for addon2"); 1.117 + EventUtils.synthesizeMouse(item2._includeUpdate, 2, 2, { }, gManagerWindow); 1.118 + is(item2._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon2"); 1.119 + is(updateSelected.disabled, false, "Update Selected button should still be enabled"); 1.120 + 1.121 + info("Unchecking Include Update checkbox for addon3"); 1.122 + EventUtils.synthesizeMouse(item3._includeUpdate, 2, 2, { }, gManagerWindow); 1.123 + is(item3._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon3"); 1.124 + is(updateSelected.disabled, true, "Update Selected button should now be disabled"); 1.125 + 1.126 + info("Checking Include Update checkbox for addon2"); 1.127 + EventUtils.synthesizeMouse(item2._includeUpdate, 2, 2, { }, gManagerWindow); 1.128 + is(item2._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon2"); 1.129 + is(updateSelected.disabled, false, "Update Selected button should now be enabled"); 1.130 + 1.131 + info("Checking Include Update checkbox for addon3"); 1.132 + EventUtils.synthesizeMouse(item3._includeUpdate, 2, 2, { }, gManagerWindow); 1.133 + is(item3._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon3"); 1.134 + is(updateSelected.disabled, false, "Update Selected button should now be enabled"); 1.135 + 1.136 + var installCount = 0; 1.137 + var listener = { 1.138 + onDownloadStarted: function(aInstall) { 1.139 + isnot(aInstall.existingAddon.id, "addon1@tests.mozilla.org", "Should not have seen a download start for addon1"); 1.140 + }, 1.141 + 1.142 + onInstallEnded: function(aInstall) { 1.143 + if (++installCount < 2) 1.144 + return; 1.145 + 1.146 + gProvider.installs[0].removeTestListener(listener); 1.147 + gProvider.installs[1].removeTestListener(listener); 1.148 + gProvider.installs[2].removeTestListener(listener); 1.149 + 1.150 + // Installs are started synchronously so by the time an executeSoon is 1.151 + // executed all installs that are going to start will have started 1.152 + executeSoon(function() { 1.153 + is(gProvider.installs[0].state, AddonManager.STATE_AVAILABLE, "addon1 should not have been upgraded"); 1.154 + is(gProvider.installs[1].state, AddonManager.STATE_INSTALLED, "addon2 should have been upgraded"); 1.155 + is(gProvider.installs[2].state, AddonManager.STATE_INSTALLED, "addon3 should have been upgraded"); 1.156 + 1.157 + run_next_test(); 1.158 + }); 1.159 + } 1.160 + } 1.161 + gProvider.installs[0].addTestListener(listener); 1.162 + gProvider.installs[1].addTestListener(listener); 1.163 + gProvider.installs[2].addTestListener(listener); 1.164 + info("Clicking Update Selected button"); 1.165 + EventUtils.synthesizeMouseAtCenter(updateSelected, { }, gManagerWindow); 1.166 +}); 1.167 + 1.168 + 1.169 +add_test(function() { 1.170 + var updateSelected = gManagerWindow.document.getElementById("update-selected-btn"); 1.171 + is(updateSelected.disabled, true, "Update Selected button should be disabled"); 1.172 + 1.173 + var item1 = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); 1.174 + isnot(item1, null, "Item for addon1@tests.mozilla.org should be in list"); 1.175 + is(item1._includeUpdate.checked, false, "Include Update checkbox should not have changed"); 1.176 + 1.177 + info("Checking Include Update checkbox for addon1"); 1.178 + EventUtils.synthesizeMouse(item1._includeUpdate, 2, 2, { }, gManagerWindow); 1.179 + is(item1._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon1"); 1.180 + is(updateSelected.disabled, false, "Update Selected button should now not be disabled"); 1.181 + 1.182 + run_next_test(); 1.183 +});