Wed, 31 Dec 2014 06:09:35 +0100
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 tha installs and undoing installs show up correctly |
michael@0 | 6 | |
michael@0 | 7 | var gManagerWindow; |
michael@0 | 8 | var gCategoryUtilities; |
michael@0 | 9 | |
michael@0 | 10 | var gApp = document.getElementById("bundle_brand").getString("brandShortName"); |
michael@0 | 11 | var gSearchCount = 0; |
michael@0 | 12 | |
michael@0 | 13 | function test() { |
michael@0 | 14 | requestLongerTimeout(2); |
michael@0 | 15 | waitForExplicitFinish(); |
michael@0 | 16 | |
michael@0 | 17 | // Turn on searching for this test |
michael@0 | 18 | Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); |
michael@0 | 19 | Services.prefs.setCharPref("extensions.getAddons.search.url", TESTROOT + "browser_install.xml"); |
michael@0 | 20 | // Allow http update checks |
michael@0 | 21 | Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); |
michael@0 | 22 | |
michael@0 | 23 | open_manager(null, function(aWindow) { |
michael@0 | 24 | gManagerWindow = aWindow; |
michael@0 | 25 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 26 | run_next_test(); |
michael@0 | 27 | }); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function end_test() { |
michael@0 | 31 | close_manager(gManagerWindow, function() { |
michael@0 | 32 | Services.prefs.clearUserPref("extensions.checkUpdateSecurity"); |
michael@0 | 33 | |
michael@0 | 34 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { |
michael@0 | 35 | aAddon.uninstall(); |
michael@0 | 36 | finish(); |
michael@0 | 37 | }); |
michael@0 | 38 | }); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function get_node(parent, anonid) { |
michael@0 | 42 | return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function installAddon(aCallback) { |
michael@0 | 46 | AddonManager.getInstallForURL(TESTROOT + "addons/browser_install1_2.xpi", |
michael@0 | 47 | function(aInstall) { |
michael@0 | 48 | aInstall.addListener({ |
michael@0 | 49 | onInstallEnded: function() { |
michael@0 | 50 | executeSoon(aCallback); |
michael@0 | 51 | } |
michael@0 | 52 | }); |
michael@0 | 53 | aInstall.install(); |
michael@0 | 54 | }, "application/x-xpinstall"); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function installUpgrade(aCallback) { |
michael@0 | 58 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { |
michael@0 | 59 | aAddon.findUpdates({ |
michael@0 | 60 | onUpdateAvailable: function(aAddon, aInstall) { |
michael@0 | 61 | is(get_list_item_count(), 1, "Should be only one item in the list"); |
michael@0 | 62 | |
michael@0 | 63 | aInstall.addListener({ |
michael@0 | 64 | onDownloadEnded: function() { |
michael@0 | 65 | is(get_list_item_count(), 1, "Should be only one item in the list once the update has started"); |
michael@0 | 66 | }, |
michael@0 | 67 | onInstallEnded: function() { |
michael@0 | 68 | executeSoon(aCallback); |
michael@0 | 69 | } |
michael@0 | 70 | }); |
michael@0 | 71 | aInstall.install(); |
michael@0 | 72 | } |
michael@0 | 73 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 74 | }); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function cancelInstall(aCallback) { |
michael@0 | 78 | AddonManager.getInstallForURL(TESTROOT + "addons/browser_install1_2.xpi", |
michael@0 | 79 | function(aInstall) { |
michael@0 | 80 | aInstall.addListener({ |
michael@0 | 81 | onDownloadEnded: function(aInstall) { |
michael@0 | 82 | executeSoon(function() { |
michael@0 | 83 | aInstall.cancel(); |
michael@0 | 84 | aCallback(); |
michael@0 | 85 | }); |
michael@0 | 86 | return false; |
michael@0 | 87 | } |
michael@0 | 88 | }); |
michael@0 | 89 | aInstall.install(); |
michael@0 | 90 | }, "application/x-xpinstall"); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function installSearchResult(aCallback) { |
michael@0 | 94 | var searchBox = gManagerWindow.document.getElementById("header-search"); |
michael@0 | 95 | // Search for something different each time |
michael@0 | 96 | searchBox.value = "foo" + gSearchCount; |
michael@0 | 97 | gSearchCount++; |
michael@0 | 98 | |
michael@0 | 99 | EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); |
michael@0 | 100 | EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); |
michael@0 | 101 | |
michael@0 | 102 | wait_for_view_load(gManagerWindow, function() { |
michael@0 | 103 | let remote = gManagerWindow.document.getElementById("search-filter-remote") |
michael@0 | 104 | EventUtils.synthesizeMouseAtCenter(remote, { }, gManagerWindow); |
michael@0 | 105 | |
michael@0 | 106 | let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
michael@0 | 107 | ok(!!item, "Should see the search result in the list"); |
michael@0 | 108 | |
michael@0 | 109 | let status = get_node(item, "install-status"); |
michael@0 | 110 | EventUtils.synthesizeMouseAtCenter(get_node(status, "install-remote-btn"), {}, gManagerWindow); |
michael@0 | 111 | |
michael@0 | 112 | item.mInstall.addListener({ |
michael@0 | 113 | onInstallEnded: function() { |
michael@0 | 114 | executeSoon(aCallback); |
michael@0 | 115 | } |
michael@0 | 116 | }); |
michael@0 | 117 | }); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function get_list_item_count() { |
michael@0 | 121 | return get_test_items_in_list(gManagerWindow).length; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function check_undo_install() { |
michael@0 | 125 | is(get_list_item_count(), 1, "Should be only one item in the list"); |
michael@0 | 126 | |
michael@0 | 127 | let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
michael@0 | 128 | ok(!!item, "Should see the pending install in the list"); |
michael@0 | 129 | // Force XBL to apply |
michael@0 | 130 | item.clientTop; |
michael@0 | 131 | is_element_visible(get_node(item, "pending"), "Pending message should be visible"); |
michael@0 | 132 | is(get_node(item, "pending").textContent, "Install Tests will be installed after you restart " + gApp + ".", "Pending message should be correct"); |
michael@0 | 133 | |
michael@0 | 134 | EventUtils.synthesizeMouseAtCenter(get_node(item, "undo-btn"), {}, gManagerWindow); |
michael@0 | 135 | |
michael@0 | 136 | is(get_list_item_count(), 0, "Should be no items in the list"); |
michael@0 | 137 | |
michael@0 | 138 | item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
michael@0 | 139 | ok(!item, "Should no longer see the pending install"); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | function check_undo_upgrade() { |
michael@0 | 143 | is(get_list_item_count(), 1, "Should be only one item in the list"); |
michael@0 | 144 | |
michael@0 | 145 | let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
michael@0 | 146 | ok(!!item, "Should see the pending upgrade in the list"); |
michael@0 | 147 | // Force XBL to apply |
michael@0 | 148 | item.clientTop; |
michael@0 | 149 | is_element_visible(get_node(item, "pending"), "Pending message should be visible"); |
michael@0 | 150 | is(get_node(item, "pending").textContent, "Install Tests will be updated after you restart " + gApp + ".", "Pending message should be correct"); |
michael@0 | 151 | |
michael@0 | 152 | EventUtils.synthesizeMouseAtCenter(get_node(item, "undo-btn"), {}, gManagerWindow); |
michael@0 | 153 | |
michael@0 | 154 | is(get_list_item_count(), 1, "Should be only one item in the list"); |
michael@0 | 155 | |
michael@0 | 156 | item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
michael@0 | 157 | ok(!!item, "Should still see installed item in the list"); |
michael@0 | 158 | is_element_hidden(get_node(item, "pending"), "Pending message should be hidden"); |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | // Install an add-on through the API with the manager open |
michael@0 | 162 | add_test(function() { |
michael@0 | 163 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 164 | installAddon(function() { |
michael@0 | 165 | check_undo_install(); |
michael@0 | 166 | run_next_test(); |
michael@0 | 167 | }); |
michael@0 | 168 | }); |
michael@0 | 169 | }); |
michael@0 | 170 | |
michael@0 | 171 | // Install an add-on with the manager closed then open it |
michael@0 | 172 | add_test(function() { |
michael@0 | 173 | close_manager(gManagerWindow, function() { |
michael@0 | 174 | installAddon(function() { |
michael@0 | 175 | open_manager(null, function(aWindow) { |
michael@0 | 176 | gManagerWindow = aWindow; |
michael@0 | 177 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 178 | check_undo_install(); |
michael@0 | 179 | run_next_test(); |
michael@0 | 180 | }); |
michael@0 | 181 | }); |
michael@0 | 182 | }); |
michael@0 | 183 | }); |
michael@0 | 184 | |
michael@0 | 185 | // Install an add-on through the search page and then undo it |
michael@0 | 186 | add_test(function() { |
michael@0 | 187 | installSearchResult(function() { |
michael@0 | 188 | check_undo_install(); |
michael@0 | 189 | run_next_test(); |
michael@0 | 190 | }); |
michael@0 | 191 | }); |
michael@0 | 192 | |
michael@0 | 193 | // Install an add-on through the search page then switch to the extensions page |
michael@0 | 194 | // and then undo it |
michael@0 | 195 | add_test(function() { |
michael@0 | 196 | installSearchResult(function() { |
michael@0 | 197 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 198 | check_undo_install(); |
michael@0 | 199 | run_next_test(); |
michael@0 | 200 | }); |
michael@0 | 201 | }); |
michael@0 | 202 | }); |
michael@0 | 203 | |
michael@0 | 204 | // Install an add-on through the search page then re-open the manager and then |
michael@0 | 205 | // undo it |
michael@0 | 206 | add_test(function() { |
michael@0 | 207 | installSearchResult(function() { |
michael@0 | 208 | close_manager(gManagerWindow, function() { |
michael@0 | 209 | open_manager("addons://list/extension", function(aWindow) { |
michael@0 | 210 | gManagerWindow = aWindow; |
michael@0 | 211 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 212 | check_undo_install(); |
michael@0 | 213 | run_next_test(); |
michael@0 | 214 | }); |
michael@0 | 215 | }); |
michael@0 | 216 | }); |
michael@0 | 217 | }); |
michael@0 | 218 | |
michael@0 | 219 | // Cancel an install after download with the manager open |
michael@0 | 220 | add_test(function() { |
michael@0 | 221 | cancelInstall(function() { |
michael@0 | 222 | is(get_list_item_count(), 0, "Should be no items in the list"); |
michael@0 | 223 | |
michael@0 | 224 | run_next_test(); |
michael@0 | 225 | }); |
michael@0 | 226 | }); |
michael@0 | 227 | |
michael@0 | 228 | // Cancel an install after download with the manager closed |
michael@0 | 229 | add_test(function() { |
michael@0 | 230 | close_manager(gManagerWindow, function() { |
michael@0 | 231 | cancelInstall(function() { |
michael@0 | 232 | open_manager(null, function(aWindow) { |
michael@0 | 233 | gManagerWindow = aWindow; |
michael@0 | 234 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 235 | is(get_list_item_count(), 0, "Should be no items in the list"); |
michael@0 | 236 | |
michael@0 | 237 | run_next_test(); |
michael@0 | 238 | }); |
michael@0 | 239 | }); |
michael@0 | 240 | }); |
michael@0 | 241 | }); |
michael@0 | 242 | |
michael@0 | 243 | // Install an existing add-on for the subsequent tests |
michael@0 | 244 | add_test(function() { |
michael@0 | 245 | AddonManager.getInstallForURL(TESTROOT + "addons/browser_install1_1.xpi", |
michael@0 | 246 | function(aInstall) { |
michael@0 | 247 | aInstall.addListener({ |
michael@0 | 248 | onInstallEnded: function() { |
michael@0 | 249 | executeSoon(run_next_test); |
michael@0 | 250 | } |
michael@0 | 251 | }); |
michael@0 | 252 | aInstall.install(); |
michael@0 | 253 | }, "application/x-xpinstall"); |
michael@0 | 254 | }); |
michael@0 | 255 | |
michael@0 | 256 | // Install an upgrade through the API with the manager open |
michael@0 | 257 | add_test(function() { |
michael@0 | 258 | installAddon(function() { |
michael@0 | 259 | check_undo_upgrade(); |
michael@0 | 260 | run_next_test(); |
michael@0 | 261 | }); |
michael@0 | 262 | }); |
michael@0 | 263 | |
michael@0 | 264 | // Install an upgrade through the API with the manager open |
michael@0 | 265 | add_test(function() { |
michael@0 | 266 | installUpgrade(function() { |
michael@0 | 267 | check_undo_upgrade(); |
michael@0 | 268 | run_next_test(); |
michael@0 | 269 | }); |
michael@0 | 270 | }); |
michael@0 | 271 | |
michael@0 | 272 | // Install an upgrade through the API with the manager closed |
michael@0 | 273 | add_test(function() { |
michael@0 | 274 | close_manager(gManagerWindow, function() { |
michael@0 | 275 | installAddon(function() { |
michael@0 | 276 | open_manager(null, function(aWindow) { |
michael@0 | 277 | gManagerWindow = aWindow; |
michael@0 | 278 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 279 | check_undo_upgrade(); |
michael@0 | 280 | run_next_test(); |
michael@0 | 281 | }); |
michael@0 | 282 | }); |
michael@0 | 283 | }); |
michael@0 | 284 | }); |
michael@0 | 285 | |
michael@0 | 286 | // Cancel an upgrade after download with the manager open |
michael@0 | 287 | add_test(function() { |
michael@0 | 288 | cancelInstall(function() { |
michael@0 | 289 | is(get_list_item_count(), 1, "Should be no items in the list"); |
michael@0 | 290 | let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
michael@0 | 291 | ok(!!item, "Should still see installed item in the list"); |
michael@0 | 292 | is_element_hidden(get_node(item, "pending"), "Pending message should be hidden"); |
michael@0 | 293 | |
michael@0 | 294 | run_next_test(); |
michael@0 | 295 | }); |
michael@0 | 296 | }); |
michael@0 | 297 | |
michael@0 | 298 | // Cancel an upgrade after download with the manager closed |
michael@0 | 299 | add_test(function() { |
michael@0 | 300 | close_manager(gManagerWindow, function() { |
michael@0 | 301 | cancelInstall(function() { |
michael@0 | 302 | open_manager(null, function(aWindow) { |
michael@0 | 303 | gManagerWindow = aWindow; |
michael@0 | 304 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 305 | is(get_list_item_count(), 1, "Should be no items in the list"); |
michael@0 | 306 | let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
michael@0 | 307 | ok(!!item, "Should still see installed item in the list"); |
michael@0 | 308 | is_element_hidden(get_node(item, "pending"), "Pending message should be hidden"); |
michael@0 | 309 | |
michael@0 | 310 | run_next_test(); |
michael@0 | 311 | }); |
michael@0 | 312 | }); |
michael@0 | 313 | }); |
michael@0 | 314 | }); |