1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_install.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,314 @@ 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 tha installs and undoing installs show up correctly 1.9 + 1.10 +var gManagerWindow; 1.11 +var gCategoryUtilities; 1.12 + 1.13 +var gApp = document.getElementById("bundle_brand").getString("brandShortName"); 1.14 +var gSearchCount = 0; 1.15 + 1.16 +function test() { 1.17 + requestLongerTimeout(2); 1.18 + waitForExplicitFinish(); 1.19 + 1.20 + // Turn on searching for this test 1.21 + Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); 1.22 + Services.prefs.setCharPref("extensions.getAddons.search.url", TESTROOT + "browser_install.xml"); 1.23 + // Allow http update checks 1.24 + Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); 1.25 + 1.26 + open_manager(null, function(aWindow) { 1.27 + gManagerWindow = aWindow; 1.28 + gCategoryUtilities = new CategoryUtilities(gManagerWindow); 1.29 + run_next_test(); 1.30 + }); 1.31 +} 1.32 + 1.33 +function end_test() { 1.34 + close_manager(gManagerWindow, function() { 1.35 + Services.prefs.clearUserPref("extensions.checkUpdateSecurity"); 1.36 + 1.37 + AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { 1.38 + aAddon.uninstall(); 1.39 + finish(); 1.40 + }); 1.41 + }); 1.42 +} 1.43 + 1.44 +function get_node(parent, anonid) { 1.45 + return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid); 1.46 +} 1.47 + 1.48 +function installAddon(aCallback) { 1.49 + AddonManager.getInstallForURL(TESTROOT + "addons/browser_install1_2.xpi", 1.50 + function(aInstall) { 1.51 + aInstall.addListener({ 1.52 + onInstallEnded: function() { 1.53 + executeSoon(aCallback); 1.54 + } 1.55 + }); 1.56 + aInstall.install(); 1.57 + }, "application/x-xpinstall"); 1.58 +} 1.59 + 1.60 +function installUpgrade(aCallback) { 1.61 + AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { 1.62 + aAddon.findUpdates({ 1.63 + onUpdateAvailable: function(aAddon, aInstall) { 1.64 + is(get_list_item_count(), 1, "Should be only one item in the list"); 1.65 + 1.66 + aInstall.addListener({ 1.67 + onDownloadEnded: function() { 1.68 + is(get_list_item_count(), 1, "Should be only one item in the list once the update has started"); 1.69 + }, 1.70 + onInstallEnded: function() { 1.71 + executeSoon(aCallback); 1.72 + } 1.73 + }); 1.74 + aInstall.install(); 1.75 + } 1.76 + }, AddonManager.UPDATE_WHEN_USER_REQUESTED); 1.77 + }); 1.78 +} 1.79 + 1.80 +function cancelInstall(aCallback) { 1.81 + AddonManager.getInstallForURL(TESTROOT + "addons/browser_install1_2.xpi", 1.82 + function(aInstall) { 1.83 + aInstall.addListener({ 1.84 + onDownloadEnded: function(aInstall) { 1.85 + executeSoon(function() { 1.86 + aInstall.cancel(); 1.87 + aCallback(); 1.88 + }); 1.89 + return false; 1.90 + } 1.91 + }); 1.92 + aInstall.install(); 1.93 + }, "application/x-xpinstall"); 1.94 +} 1.95 + 1.96 +function installSearchResult(aCallback) { 1.97 + var searchBox = gManagerWindow.document.getElementById("header-search"); 1.98 + // Search for something different each time 1.99 + searchBox.value = "foo" + gSearchCount; 1.100 + gSearchCount++; 1.101 + 1.102 + EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); 1.103 + EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); 1.104 + 1.105 + wait_for_view_load(gManagerWindow, function() { 1.106 + let remote = gManagerWindow.document.getElementById("search-filter-remote") 1.107 + EventUtils.synthesizeMouseAtCenter(remote, { }, gManagerWindow); 1.108 + 1.109 + let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); 1.110 + ok(!!item, "Should see the search result in the list"); 1.111 + 1.112 + let status = get_node(item, "install-status"); 1.113 + EventUtils.synthesizeMouseAtCenter(get_node(status, "install-remote-btn"), {}, gManagerWindow); 1.114 + 1.115 + item.mInstall.addListener({ 1.116 + onInstallEnded: function() { 1.117 + executeSoon(aCallback); 1.118 + } 1.119 + }); 1.120 + }); 1.121 +} 1.122 + 1.123 +function get_list_item_count() { 1.124 + return get_test_items_in_list(gManagerWindow).length; 1.125 +} 1.126 + 1.127 +function check_undo_install() { 1.128 + is(get_list_item_count(), 1, "Should be only one item in the list"); 1.129 + 1.130 + let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); 1.131 + ok(!!item, "Should see the pending install in the list"); 1.132 + // Force XBL to apply 1.133 + item.clientTop; 1.134 + is_element_visible(get_node(item, "pending"), "Pending message should be visible"); 1.135 + is(get_node(item, "pending").textContent, "Install Tests will be installed after you restart " + gApp + ".", "Pending message should be correct"); 1.136 + 1.137 + EventUtils.synthesizeMouseAtCenter(get_node(item, "undo-btn"), {}, gManagerWindow); 1.138 + 1.139 + is(get_list_item_count(), 0, "Should be no items in the list"); 1.140 + 1.141 + item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); 1.142 + ok(!item, "Should no longer see the pending install"); 1.143 +} 1.144 + 1.145 +function check_undo_upgrade() { 1.146 + is(get_list_item_count(), 1, "Should be only one item in the list"); 1.147 + 1.148 + let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); 1.149 + ok(!!item, "Should see the pending upgrade in the list"); 1.150 + // Force XBL to apply 1.151 + item.clientTop; 1.152 + is_element_visible(get_node(item, "pending"), "Pending message should be visible"); 1.153 + is(get_node(item, "pending").textContent, "Install Tests will be updated after you restart " + gApp + ".", "Pending message should be correct"); 1.154 + 1.155 + EventUtils.synthesizeMouseAtCenter(get_node(item, "undo-btn"), {}, gManagerWindow); 1.156 + 1.157 + is(get_list_item_count(), 1, "Should be only one item in the list"); 1.158 + 1.159 + item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); 1.160 + ok(!!item, "Should still see installed item in the list"); 1.161 + is_element_hidden(get_node(item, "pending"), "Pending message should be hidden"); 1.162 +} 1.163 + 1.164 +// Install an add-on through the API with the manager open 1.165 +add_test(function() { 1.166 + gCategoryUtilities.openType("extension", function() { 1.167 + installAddon(function() { 1.168 + check_undo_install(); 1.169 + run_next_test(); 1.170 + }); 1.171 + }); 1.172 +}); 1.173 + 1.174 +// Install an add-on with the manager closed then open it 1.175 +add_test(function() { 1.176 + close_manager(gManagerWindow, function() { 1.177 + installAddon(function() { 1.178 + open_manager(null, function(aWindow) { 1.179 + gManagerWindow = aWindow; 1.180 + gCategoryUtilities = new CategoryUtilities(gManagerWindow); 1.181 + check_undo_install(); 1.182 + run_next_test(); 1.183 + }); 1.184 + }); 1.185 + }); 1.186 +}); 1.187 + 1.188 +// Install an add-on through the search page and then undo it 1.189 +add_test(function() { 1.190 + installSearchResult(function() { 1.191 + check_undo_install(); 1.192 + run_next_test(); 1.193 + }); 1.194 +}); 1.195 + 1.196 +// Install an add-on through the search page then switch to the extensions page 1.197 +// and then undo it 1.198 +add_test(function() { 1.199 + installSearchResult(function() { 1.200 + gCategoryUtilities.openType("extension", function() { 1.201 + check_undo_install(); 1.202 + run_next_test(); 1.203 + }); 1.204 + }); 1.205 +}); 1.206 + 1.207 +// Install an add-on through the search page then re-open the manager and then 1.208 +// undo it 1.209 +add_test(function() { 1.210 + installSearchResult(function() { 1.211 + close_manager(gManagerWindow, function() { 1.212 + open_manager("addons://list/extension", function(aWindow) { 1.213 + gManagerWindow = aWindow; 1.214 + gCategoryUtilities = new CategoryUtilities(gManagerWindow); 1.215 + check_undo_install(); 1.216 + run_next_test(); 1.217 + }); 1.218 + }); 1.219 + }); 1.220 +}); 1.221 + 1.222 +// Cancel an install after download with the manager open 1.223 +add_test(function() { 1.224 + cancelInstall(function() { 1.225 + is(get_list_item_count(), 0, "Should be no items in the list"); 1.226 + 1.227 + run_next_test(); 1.228 + }); 1.229 +}); 1.230 + 1.231 +// Cancel an install after download with the manager closed 1.232 +add_test(function() { 1.233 + close_manager(gManagerWindow, function() { 1.234 + cancelInstall(function() { 1.235 + open_manager(null, function(aWindow) { 1.236 + gManagerWindow = aWindow; 1.237 + gCategoryUtilities = new CategoryUtilities(gManagerWindow); 1.238 + is(get_list_item_count(), 0, "Should be no items in the list"); 1.239 + 1.240 + run_next_test(); 1.241 + }); 1.242 + }); 1.243 + }); 1.244 +}); 1.245 + 1.246 +// Install an existing add-on for the subsequent tests 1.247 +add_test(function() { 1.248 + AddonManager.getInstallForURL(TESTROOT + "addons/browser_install1_1.xpi", 1.249 + function(aInstall) { 1.250 + aInstall.addListener({ 1.251 + onInstallEnded: function() { 1.252 + executeSoon(run_next_test); 1.253 + } 1.254 + }); 1.255 + aInstall.install(); 1.256 + }, "application/x-xpinstall"); 1.257 +}); 1.258 + 1.259 +// Install an upgrade through the API with the manager open 1.260 +add_test(function() { 1.261 + installAddon(function() { 1.262 + check_undo_upgrade(); 1.263 + run_next_test(); 1.264 + }); 1.265 +}); 1.266 + 1.267 +// Install an upgrade through the API with the manager open 1.268 +add_test(function() { 1.269 + installUpgrade(function() { 1.270 + check_undo_upgrade(); 1.271 + run_next_test(); 1.272 + }); 1.273 +}); 1.274 + 1.275 +// Install an upgrade through the API with the manager closed 1.276 +add_test(function() { 1.277 + close_manager(gManagerWindow, function() { 1.278 + installAddon(function() { 1.279 + open_manager(null, function(aWindow) { 1.280 + gManagerWindow = aWindow; 1.281 + gCategoryUtilities = new CategoryUtilities(gManagerWindow); 1.282 + check_undo_upgrade(); 1.283 + run_next_test(); 1.284 + }); 1.285 + }); 1.286 + }); 1.287 +}); 1.288 + 1.289 +// Cancel an upgrade after download with the manager open 1.290 +add_test(function() { 1.291 + cancelInstall(function() { 1.292 + is(get_list_item_count(), 1, "Should be no items in the list"); 1.293 + let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); 1.294 + ok(!!item, "Should still see installed item in the list"); 1.295 + is_element_hidden(get_node(item, "pending"), "Pending message should be hidden"); 1.296 + 1.297 + run_next_test(); 1.298 + }); 1.299 +}); 1.300 + 1.301 +// Cancel an upgrade after download with the manager closed 1.302 +add_test(function() { 1.303 + close_manager(gManagerWindow, function() { 1.304 + cancelInstall(function() { 1.305 + open_manager(null, function(aWindow) { 1.306 + gManagerWindow = aWindow; 1.307 + gCategoryUtilities = new CategoryUtilities(gManagerWindow); 1.308 + is(get_list_item_count(), 1, "Should be no items in the list"); 1.309 + let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); 1.310 + ok(!!item, "Should still see installed item in the list"); 1.311 + is_element_hidden(get_node(item, "pending"), "Pending message should be hidden"); 1.312 + 1.313 + run_next_test(); 1.314 + }); 1.315 + }); 1.316 + }); 1.317 +});