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 | // This verifies that add-ons can be installed from XPI files |
michael@0 | 6 | const Cc = Components.classes; |
michael@0 | 7 | const Ci = Components.interfaces; |
michael@0 | 8 | const Cu = Components.utils; |
michael@0 | 9 | |
michael@0 | 10 | // Maximum error in file modification times. Some file systems don't store |
michael@0 | 11 | // modification times exactly. As long as we are closer than this then it |
michael@0 | 12 | // still passes. |
michael@0 | 13 | const MAX_TIME_DIFFERENCE = 3000; |
michael@0 | 14 | |
michael@0 | 15 | // install.rdf size, icon.png, icon64.png size |
michael@0 | 16 | const ADDON1_SIZE = 705 + 16 + 16; |
michael@0 | 17 | |
michael@0 | 18 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 19 | Cu.import("resource://gre/modules/NetUtil.jsm"); |
michael@0 | 20 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 21 | |
michael@0 | 22 | var testserver; |
michael@0 | 23 | var gInstallDate; |
michael@0 | 24 | var gInstall = null; |
michael@0 | 25 | |
michael@0 | 26 | // The test extension uses an insecure update url. |
michael@0 | 27 | Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); |
michael@0 | 28 | Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true); |
michael@0 | 29 | |
michael@0 | 30 | |
michael@0 | 31 | const profileDir = gProfD.clone(); |
michael@0 | 32 | profileDir.append("extensions"); |
michael@0 | 33 | |
michael@0 | 34 | function run_test() { |
michael@0 | 35 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 36 | |
michael@0 | 37 | startupManager(); |
michael@0 | 38 | // Make sure we only register once despite multiple calls |
michael@0 | 39 | AddonManager.addInstallListener(InstallListener); |
michael@0 | 40 | AddonManager.addAddonListener(AddonListener); |
michael@0 | 41 | AddonManager.addInstallListener(InstallListener); |
michael@0 | 42 | AddonManager.addAddonListener(AddonListener); |
michael@0 | 43 | |
michael@0 | 44 | // Create and configure the HTTP server. |
michael@0 | 45 | testserver = new HttpServer(); |
michael@0 | 46 | testserver.registerDirectory("/addons/", do_get_file("addons")); |
michael@0 | 47 | testserver.registerDirectory("/data/", do_get_file("data")); |
michael@0 | 48 | testserver.registerPathHandler("/redirect", function(aRequest, aResponse) { |
michael@0 | 49 | aResponse.setStatusLine(null, 301, "Moved Permanently"); |
michael@0 | 50 | let url = aRequest.host + ":" + aRequest.port + aRequest.queryString; |
michael@0 | 51 | aResponse.setHeader("Location", "http://" + url); |
michael@0 | 52 | }); |
michael@0 | 53 | testserver.start(4444); |
michael@0 | 54 | |
michael@0 | 55 | do_test_pending(); |
michael@0 | 56 | run_test_1(); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function end_test() { |
michael@0 | 60 | testserver.stop(do_test_finished); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | // Checks that an install from a local file proceeds as expected |
michael@0 | 64 | function run_test_1() { |
michael@0 | 65 | prepare_test({ }, [ |
michael@0 | 66 | "onNewInstall" |
michael@0 | 67 | ]); |
michael@0 | 68 | |
michael@0 | 69 | AddonManager.getInstallForFile(do_get_addon("test_install1"), function(install) { |
michael@0 | 70 | ensure_test_completed(); |
michael@0 | 71 | |
michael@0 | 72 | do_check_neq(install, null); |
michael@0 | 73 | do_check_eq(install.linkedInstalls, null); |
michael@0 | 74 | do_check_eq(install.type, "extension"); |
michael@0 | 75 | do_check_eq(install.version, "1.0"); |
michael@0 | 76 | do_check_eq(install.name, "Test 1"); |
michael@0 | 77 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 78 | do_check_true(install.addon.hasResource("install.rdf")); |
michael@0 | 79 | do_check_eq(install.addon.install, install); |
michael@0 | 80 | do_check_eq(install.addon.size, ADDON1_SIZE); |
michael@0 | 81 | do_check_true(hasFlag(install.addon.operationsRequiringRestart, |
michael@0 | 82 | AddonManager.OP_NEEDS_RESTART_INSTALL)); |
michael@0 | 83 | let file = do_get_addon("test_install1"); |
michael@0 | 84 | let uri = Services.io.newFileURI(file).spec; |
michael@0 | 85 | do_check_eq(install.addon.getResourceURI("install.rdf").spec, "jar:" + uri + "!/install.rdf"); |
michael@0 | 86 | do_check_eq(install.addon.iconURL, "jar:" + uri + "!/icon.png"); |
michael@0 | 87 | do_check_eq(install.addon.icon64URL, "jar:" + uri + "!/icon64.png"); |
michael@0 | 88 | do_check_eq(install.iconURL, null); |
michael@0 | 89 | |
michael@0 | 90 | do_check_eq(install.sourceURI.spec, uri); |
michael@0 | 91 | do_check_eq(install.addon.sourceURI.spec, uri); |
michael@0 | 92 | |
michael@0 | 93 | AddonManager.getAllInstalls(function(activeInstalls) { |
michael@0 | 94 | do_check_eq(activeInstalls.length, 1); |
michael@0 | 95 | do_check_eq(activeInstalls[0], install); |
michael@0 | 96 | |
michael@0 | 97 | AddonManager.getInstallsByTypes(["foo"], function(fooInstalls) { |
michael@0 | 98 | do_check_eq(fooInstalls.length, 0); |
michael@0 | 99 | |
michael@0 | 100 | AddonManager.getInstallsByTypes(["extension"], function(extensionInstalls) { |
michael@0 | 101 | do_check_eq(extensionInstalls.length, 1); |
michael@0 | 102 | do_check_eq(extensionInstalls[0], install); |
michael@0 | 103 | |
michael@0 | 104 | prepare_test({ |
michael@0 | 105 | "addon1@tests.mozilla.org": [ |
michael@0 | 106 | "onInstalling" |
michael@0 | 107 | ] |
michael@0 | 108 | }, [ |
michael@0 | 109 | "onInstallStarted", |
michael@0 | 110 | "onInstallEnded", |
michael@0 | 111 | ], check_test_1); |
michael@0 | 112 | install.install(); |
michael@0 | 113 | }); |
michael@0 | 114 | }); |
michael@0 | 115 | }); |
michael@0 | 116 | }); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | function check_test_1() { |
michael@0 | 120 | ensure_test_completed(); |
michael@0 | 121 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(olda1) { |
michael@0 | 122 | do_check_eq(olda1, null); |
michael@0 | 123 | |
michael@0 | 124 | AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(pendingAddons) { |
michael@0 | 125 | do_check_eq(pendingAddons.length, 1); |
michael@0 | 126 | do_check_eq(pendingAddons[0].id, "addon1@tests.mozilla.org"); |
michael@0 | 127 | let uri = NetUtil.newURI(pendingAddons[0].iconURL); |
michael@0 | 128 | if (uri instanceof AM_Ci.nsIJARURI) { |
michael@0 | 129 | let jarURI = uri.QueryInterface(AM_Ci.nsIJARURI); |
michael@0 | 130 | let archiveURI = jarURI.JARFile; |
michael@0 | 131 | let archiveFile = archiveURI.QueryInterface(AM_Ci.nsIFileURL).file; |
michael@0 | 132 | let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]. |
michael@0 | 133 | createInstance(Ci.nsIZipReader); |
michael@0 | 134 | try { |
michael@0 | 135 | zipReader.open(archiveFile); |
michael@0 | 136 | do_check_true(zipReader.hasEntry(jarURI.JAREntry)); |
michael@0 | 137 | } |
michael@0 | 138 | finally { |
michael@0 | 139 | zipReader.close(); |
michael@0 | 140 | } |
michael@0 | 141 | } |
michael@0 | 142 | else { |
michael@0 | 143 | let iconFile = uri.QueryInterface(AM_Ci.nsIFileURL).file; |
michael@0 | 144 | do_check_true(iconFile.exists()); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | // Make the pending install have a sensible date |
michael@0 | 148 | let updateDate = Date.now(); |
michael@0 | 149 | let extURI = pendingAddons[0].getResourceURI(""); |
michael@0 | 150 | let ext = extURI.QueryInterface(AM_Ci.nsIFileURL).file; |
michael@0 | 151 | setExtensionModifiedTime(ext, updateDate); |
michael@0 | 152 | |
michael@0 | 153 | // The pending add-on cannot be disabled or enabled. |
michael@0 | 154 | do_check_false(hasFlag(pendingAddons[0].permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 155 | do_check_false(hasFlag(pendingAddons[0].permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 156 | |
michael@0 | 157 | restartManager(); |
michael@0 | 158 | |
michael@0 | 159 | AddonManager.getAllInstalls(function(activeInstalls) { |
michael@0 | 160 | do_check_eq(activeInstalls, 0); |
michael@0 | 161 | |
michael@0 | 162 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 163 | do_check_neq(a1, null); |
michael@0 | 164 | do_check_eq(a1.type, "extension"); |
michael@0 | 165 | do_check_eq(a1.version, "1.0"); |
michael@0 | 166 | do_check_eq(a1.name, "Test 1"); |
michael@0 | 167 | do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
michael@0 | 168 | do_check_true(do_get_addon("test_install1").exists()); |
michael@0 | 169 | do_check_in_crash_annotation(a1.id, a1.version); |
michael@0 | 170 | do_check_eq(a1.size, ADDON1_SIZE); |
michael@0 | 171 | |
michael@0 | 172 | do_check_eq(a1.sourceURI.spec, |
michael@0 | 173 | Services.io.newFileURI(do_get_addon("test_install1")).spec); |
michael@0 | 174 | let difference = a1.installDate.getTime() - updateDate; |
michael@0 | 175 | if (Math.abs(difference) > MAX_TIME_DIFFERENCE) |
michael@0 | 176 | do_throw("Add-on install time was out by " + difference + "ms"); |
michael@0 | 177 | |
michael@0 | 178 | difference = a1.updateDate.getTime() - updateDate; |
michael@0 | 179 | if (Math.abs(difference) > MAX_TIME_DIFFERENCE) |
michael@0 | 180 | do_throw("Add-on update time was out by " + difference + "ms"); |
michael@0 | 181 | |
michael@0 | 182 | do_check_true(a1.hasResource("install.rdf")); |
michael@0 | 183 | do_check_false(a1.hasResource("foo.bar")); |
michael@0 | 184 | |
michael@0 | 185 | let uri = do_get_addon_root_uri(profileDir, "addon1@tests.mozilla.org"); |
michael@0 | 186 | do_check_eq(a1.getResourceURI("install.rdf").spec, uri + "install.rdf"); |
michael@0 | 187 | do_check_eq(a1.iconURL, uri + "icon.png"); |
michael@0 | 188 | do_check_eq(a1.icon64URL, uri + "icon64.png"); |
michael@0 | 189 | |
michael@0 | 190 | a1.uninstall(); |
michael@0 | 191 | do_execute_soon(function(){run_test_2(a1)}); |
michael@0 | 192 | }); |
michael@0 | 193 | }); |
michael@0 | 194 | })); |
michael@0 | 195 | }); |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | // Tests that an install from a url downloads. |
michael@0 | 199 | function run_test_2(aAddon) { |
michael@0 | 200 | restartManager(); |
michael@0 | 201 | do_check_not_in_crash_annotation(aAddon.id, aAddon.version); |
michael@0 | 202 | |
michael@0 | 203 | let url = "http://localhost:4444/addons/test_install2_1.xpi"; |
michael@0 | 204 | AddonManager.getInstallForURL(url, function(install) { |
michael@0 | 205 | do_check_neq(install, null); |
michael@0 | 206 | do_check_eq(install.linkedInstalls, null); |
michael@0 | 207 | do_check_eq(install.version, "1.0"); |
michael@0 | 208 | do_check_eq(install.name, "Test 2"); |
michael@0 | 209 | do_check_eq(install.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 210 | do_check_eq(install.iconURL, null); |
michael@0 | 211 | do_check_eq(install.sourceURI.spec, url); |
michael@0 | 212 | |
michael@0 | 213 | AddonManager.getAllInstalls(function(activeInstalls) { |
michael@0 | 214 | do_check_eq(activeInstalls.length, 1); |
michael@0 | 215 | do_check_eq(activeInstalls[0], install); |
michael@0 | 216 | |
michael@0 | 217 | prepare_test({}, [ |
michael@0 | 218 | "onDownloadStarted", |
michael@0 | 219 | "onDownloadEnded", |
michael@0 | 220 | ], check_test_2); |
michael@0 | 221 | |
michael@0 | 222 | install.addListener({ |
michael@0 | 223 | onDownloadProgress: function(install) { |
michael@0 | 224 | do_execute_soon(function() { |
michael@0 | 225 | Components.utils.forceGC(); |
michael@0 | 226 | }); |
michael@0 | 227 | } |
michael@0 | 228 | }); |
michael@0 | 229 | |
michael@0 | 230 | install.install(); |
michael@0 | 231 | }); |
michael@0 | 232 | }, "application/x-xpinstall", null, "Test 2", null, "1.0"); |
michael@0 | 233 | } |
michael@0 | 234 | |
michael@0 | 235 | function check_test_2(install) { |
michael@0 | 236 | ensure_test_completed(); |
michael@0 | 237 | do_check_eq(install.version, "2.0"); |
michael@0 | 238 | do_check_eq(install.name, "Real Test 2"); |
michael@0 | 239 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 240 | do_check_eq(install.addon.install, install); |
michael@0 | 241 | do_check_true(hasFlag(install.addon.operationsRequiringRestart, |
michael@0 | 242 | AddonManager.OP_NEEDS_RESTART_INSTALL)); |
michael@0 | 243 | do_check_eq(install.iconURL, null); |
michael@0 | 244 | |
michael@0 | 245 | // Pause the install here and start it again in run_test_3 |
michael@0 | 246 | do_execute_soon(function() { run_test_3(install); }); |
michael@0 | 247 | return false; |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | // Tests that the downloaded XPI installs ok |
michael@0 | 251 | function run_test_3(install) { |
michael@0 | 252 | prepare_test({ |
michael@0 | 253 | "addon2@tests.mozilla.org": [ |
michael@0 | 254 | "onInstalling" |
michael@0 | 255 | ] |
michael@0 | 256 | }, [ |
michael@0 | 257 | "onInstallStarted", |
michael@0 | 258 | "onInstallEnded", |
michael@0 | 259 | ], check_test_3); |
michael@0 | 260 | install.install(); |
michael@0 | 261 | } |
michael@0 | 262 | |
michael@0 | 263 | function check_test_3(aInstall) { |
michael@0 | 264 | // Make the pending install have a sensible date |
michael@0 | 265 | let updateDate = Date.now(); |
michael@0 | 266 | let extURI = aInstall.addon.getResourceURI(""); |
michael@0 | 267 | let ext = extURI.QueryInterface(AM_Ci.nsIFileURL).file; |
michael@0 | 268 | setExtensionModifiedTime(ext, updateDate); |
michael@0 | 269 | |
michael@0 | 270 | ensure_test_completed(); |
michael@0 | 271 | AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(function(olda2) { |
michael@0 | 272 | do_check_eq(olda2, null); |
michael@0 | 273 | restartManager(); |
michael@0 | 274 | |
michael@0 | 275 | AddonManager.getAllInstalls(function(installs) { |
michael@0 | 276 | do_check_eq(installs, 0); |
michael@0 | 277 | |
michael@0 | 278 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 279 | do_check_neq(a2, null); |
michael@0 | 280 | do_check_eq(a2.type, "extension"); |
michael@0 | 281 | do_check_eq(a2.version, "2.0"); |
michael@0 | 282 | do_check_eq(a2.name, "Real Test 2"); |
michael@0 | 283 | do_check_true(isExtensionInAddonsList(profileDir, a2.id)); |
michael@0 | 284 | do_check_true(do_get_addon("test_install2_1").exists()); |
michael@0 | 285 | do_check_in_crash_annotation(a2.id, a2.version); |
michael@0 | 286 | do_check_eq(a2.sourceURI.spec, |
michael@0 | 287 | "http://localhost:4444/addons/test_install2_1.xpi"); |
michael@0 | 288 | |
michael@0 | 289 | let difference = a2.installDate.getTime() - updateDate; |
michael@0 | 290 | if (Math.abs(difference) > MAX_TIME_DIFFERENCE) |
michael@0 | 291 | do_throw("Add-on install time was out by " + difference + "ms"); |
michael@0 | 292 | |
michael@0 | 293 | difference = a2.updateDate.getTime() - updateDate; |
michael@0 | 294 | if (Math.abs(difference) > MAX_TIME_DIFFERENCE) |
michael@0 | 295 | do_throw("Add-on update time was out by " + difference + "ms"); |
michael@0 | 296 | |
michael@0 | 297 | gInstallDate = a2.installDate.getTime(); |
michael@0 | 298 | |
michael@0 | 299 | run_test_4(); |
michael@0 | 300 | }); |
michael@0 | 301 | }); |
michael@0 | 302 | })); |
michael@0 | 303 | } |
michael@0 | 304 | |
michael@0 | 305 | // Tests that installing a new version of an existing add-on works |
michael@0 | 306 | function run_test_4() { |
michael@0 | 307 | prepare_test({ }, [ |
michael@0 | 308 | "onNewInstall" |
michael@0 | 309 | ]); |
michael@0 | 310 | |
michael@0 | 311 | let url = "http://localhost:4444/addons/test_install2_2.xpi"; |
michael@0 | 312 | AddonManager.getInstallForURL(url, function(install) { |
michael@0 | 313 | ensure_test_completed(); |
michael@0 | 314 | |
michael@0 | 315 | do_check_neq(install, null); |
michael@0 | 316 | do_check_eq(install.version, "3.0"); |
michael@0 | 317 | do_check_eq(install.name, "Test 3"); |
michael@0 | 318 | do_check_eq(install.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 319 | |
michael@0 | 320 | AddonManager.getAllInstalls(function(activeInstalls) { |
michael@0 | 321 | do_check_eq(activeInstalls.length, 1); |
michael@0 | 322 | do_check_eq(activeInstalls[0], install); |
michael@0 | 323 | do_check_eq(install.existingAddon, null); |
michael@0 | 324 | |
michael@0 | 325 | prepare_test({}, [ |
michael@0 | 326 | "onDownloadStarted", |
michael@0 | 327 | "onDownloadEnded", |
michael@0 | 328 | ], check_test_4); |
michael@0 | 329 | install.install(); |
michael@0 | 330 | }); |
michael@0 | 331 | }, "application/x-xpinstall", null, "Test 3", null, "3.0"); |
michael@0 | 332 | } |
michael@0 | 333 | |
michael@0 | 334 | function check_test_4(install) { |
michael@0 | 335 | ensure_test_completed(); |
michael@0 | 336 | |
michael@0 | 337 | do_check_eq(install.version, "3.0"); |
michael@0 | 338 | do_check_eq(install.name, "Real Test 3"); |
michael@0 | 339 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 340 | do_check_neq(install.existingAddon); |
michael@0 | 341 | do_check_eq(install.existingAddon.id, "addon2@tests.mozilla.org"); |
michael@0 | 342 | do_check_eq(install.addon.install, install); |
michael@0 | 343 | do_check_true(hasFlag(install.addon.operationsRequiringRestart, |
michael@0 | 344 | AddonManager.OP_NEEDS_RESTART_INSTALL)); |
michael@0 | 345 | |
michael@0 | 346 | run_test_5(); |
michael@0 | 347 | // Installation will continue when there is nothing returned. |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | // Continue installing the new version |
michael@0 | 351 | function run_test_5() { |
michael@0 | 352 | prepare_test({ |
michael@0 | 353 | "addon2@tests.mozilla.org": [ |
michael@0 | 354 | "onInstalling" |
michael@0 | 355 | ] |
michael@0 | 356 | }, [ |
michael@0 | 357 | "onInstallStarted", |
michael@0 | 358 | "onInstallEnded", |
michael@0 | 359 | ], check_test_5); |
michael@0 | 360 | } |
michael@0 | 361 | |
michael@0 | 362 | function check_test_5(install) { |
michael@0 | 363 | ensure_test_completed(); |
michael@0 | 364 | |
michael@0 | 365 | do_check_eq(install.existingAddon.pendingUpgrade.install, install); |
michael@0 | 366 | |
michael@0 | 367 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(olda2) { |
michael@0 | 368 | do_check_neq(olda2, null); |
michael@0 | 369 | do_check_true(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE)); |
michael@0 | 370 | |
michael@0 | 371 | AddonManager.getInstallsByTypes(null, callback_soon(function(installs) { |
michael@0 | 372 | do_check_eq(installs.length, 1); |
michael@0 | 373 | do_check_eq(installs[0].addon, olda2.pendingUpgrade); |
michael@0 | 374 | restartManager(); |
michael@0 | 375 | |
michael@0 | 376 | AddonManager.getInstallsByTypes(null, function(installs) { |
michael@0 | 377 | do_check_eq(installs.length, 0); |
michael@0 | 378 | |
michael@0 | 379 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 380 | do_check_neq(a2, null); |
michael@0 | 381 | do_check_eq(a2.type, "extension"); |
michael@0 | 382 | do_check_eq(a2.version, "3.0"); |
michael@0 | 383 | do_check_eq(a2.name, "Real Test 3"); |
michael@0 | 384 | do_check_true(a2.isActive); |
michael@0 | 385 | do_check_true(isExtensionInAddonsList(profileDir, a2.id)); |
michael@0 | 386 | do_check_true(do_get_addon("test_install2_2").exists()); |
michael@0 | 387 | do_check_in_crash_annotation(a2.id, a2.version); |
michael@0 | 388 | do_check_eq(a2.sourceURI.spec, |
michael@0 | 389 | "http://localhost:4444/addons/test_install2_2.xpi"); |
michael@0 | 390 | |
michael@0 | 391 | do_check_eq(a2.installDate.getTime(), gInstallDate); |
michael@0 | 392 | // Update date should be later (or the same if this test is too fast) |
michael@0 | 393 | do_check_true(a2.installDate <= a2.updateDate); |
michael@0 | 394 | |
michael@0 | 395 | a2.uninstall(); |
michael@0 | 396 | do_execute_soon(run_test_6); |
michael@0 | 397 | }); |
michael@0 | 398 | }); |
michael@0 | 399 | })); |
michael@0 | 400 | }); |
michael@0 | 401 | } |
michael@0 | 402 | |
michael@0 | 403 | // Tests that an install that requires a compatibility update works |
michael@0 | 404 | function run_test_6() { |
michael@0 | 405 | restartManager(); |
michael@0 | 406 | |
michael@0 | 407 | prepare_test({ }, [ |
michael@0 | 408 | "onNewInstall" |
michael@0 | 409 | ]); |
michael@0 | 410 | |
michael@0 | 411 | let url = "http://localhost:4444/addons/test_install3.xpi"; |
michael@0 | 412 | AddonManager.getInstallForURL(url, function(install) { |
michael@0 | 413 | ensure_test_completed(); |
michael@0 | 414 | |
michael@0 | 415 | do_check_neq(install, null); |
michael@0 | 416 | do_check_eq(install.version, "1.0"); |
michael@0 | 417 | do_check_eq(install.name, "Real Test 4"); |
michael@0 | 418 | do_check_eq(install.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 419 | |
michael@0 | 420 | AddonManager.getInstallsByTypes(null, function(activeInstalls) { |
michael@0 | 421 | do_check_eq(activeInstalls.length, 1); |
michael@0 | 422 | do_check_eq(activeInstalls[0], install); |
michael@0 | 423 | |
michael@0 | 424 | prepare_test({}, [ |
michael@0 | 425 | "onDownloadStarted", |
michael@0 | 426 | "onDownloadEnded", |
michael@0 | 427 | ], check_test_6); |
michael@0 | 428 | install.install(); |
michael@0 | 429 | }); |
michael@0 | 430 | }, "application/x-xpinstall", null, "Real Test 4", null, "1.0"); |
michael@0 | 431 | } |
michael@0 | 432 | |
michael@0 | 433 | function check_test_6(install) { |
michael@0 | 434 | ensure_test_completed(); |
michael@0 | 435 | do_check_eq(install.version, "1.0"); |
michael@0 | 436 | do_check_eq(install.name, "Real Test 4"); |
michael@0 | 437 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 438 | do_check_eq(install.existingAddon, null); |
michael@0 | 439 | do_check_false(install.addon.appDisabled); |
michael@0 | 440 | run_test_7(); |
michael@0 | 441 | return true; |
michael@0 | 442 | } |
michael@0 | 443 | |
michael@0 | 444 | // Continue the install |
michael@0 | 445 | function run_test_7() { |
michael@0 | 446 | prepare_test({ |
michael@0 | 447 | "addon3@tests.mozilla.org": [ |
michael@0 | 448 | "onInstalling" |
michael@0 | 449 | ] |
michael@0 | 450 | }, [ |
michael@0 | 451 | "onInstallStarted", |
michael@0 | 452 | "onInstallEnded", |
michael@0 | 453 | ], check_test_7); |
michael@0 | 454 | } |
michael@0 | 455 | |
michael@0 | 456 | function check_test_7() { |
michael@0 | 457 | ensure_test_completed(); |
michael@0 | 458 | AddonManager.getAddonByID("addon3@tests.mozilla.org", callback_soon(function(olda3) { |
michael@0 | 459 | do_check_eq(olda3, null); |
michael@0 | 460 | restartManager(); |
michael@0 | 461 | |
michael@0 | 462 | AddonManager.getAllInstalls(function(installs) { |
michael@0 | 463 | do_check_eq(installs, 0); |
michael@0 | 464 | |
michael@0 | 465 | AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) { |
michael@0 | 466 | do_check_neq(a3, null); |
michael@0 | 467 | do_check_eq(a3.type, "extension"); |
michael@0 | 468 | do_check_eq(a3.version, "1.0"); |
michael@0 | 469 | do_check_eq(a3.name, "Real Test 4"); |
michael@0 | 470 | do_check_true(a3.isActive); |
michael@0 | 471 | do_check_false(a3.appDisabled); |
michael@0 | 472 | do_check_true(isExtensionInAddonsList(profileDir, a3.id)); |
michael@0 | 473 | do_check_true(do_get_addon("test_install3").exists()); |
michael@0 | 474 | a3.uninstall(); |
michael@0 | 475 | do_execute_soon(run_test_8); |
michael@0 | 476 | }); |
michael@0 | 477 | }); |
michael@0 | 478 | })); |
michael@0 | 479 | } |
michael@0 | 480 | |
michael@0 | 481 | function run_test_8() { |
michael@0 | 482 | restartManager(); |
michael@0 | 483 | |
michael@0 | 484 | AddonManager.addInstallListener(InstallListener); |
michael@0 | 485 | AddonManager.addAddonListener(AddonListener); |
michael@0 | 486 | |
michael@0 | 487 | prepare_test({ }, [ |
michael@0 | 488 | "onNewInstall" |
michael@0 | 489 | ]); |
michael@0 | 490 | |
michael@0 | 491 | AddonManager.getInstallForFile(do_get_addon("test_install3"), function(install) { |
michael@0 | 492 | do_check_true(install.addon.isCompatible); |
michael@0 | 493 | |
michael@0 | 494 | prepare_test({ |
michael@0 | 495 | "addon3@tests.mozilla.org": [ |
michael@0 | 496 | "onInstalling" |
michael@0 | 497 | ] |
michael@0 | 498 | }, [ |
michael@0 | 499 | "onInstallStarted", |
michael@0 | 500 | "onInstallEnded", |
michael@0 | 501 | ], callback_soon(check_test_8)); |
michael@0 | 502 | install.install(); |
michael@0 | 503 | }); |
michael@0 | 504 | } |
michael@0 | 505 | |
michael@0 | 506 | function check_test_8() { |
michael@0 | 507 | restartManager(); |
michael@0 | 508 | |
michael@0 | 509 | AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) { |
michael@0 | 510 | do_check_neq(a3, null); |
michael@0 | 511 | do_check_eq(a3.type, "extension"); |
michael@0 | 512 | do_check_eq(a3.version, "1.0"); |
michael@0 | 513 | do_check_eq(a3.name, "Real Test 4"); |
michael@0 | 514 | do_check_true(a3.isActive); |
michael@0 | 515 | do_check_false(a3.appDisabled); |
michael@0 | 516 | do_check_true(isExtensionInAddonsList(profileDir, a3.id)); |
michael@0 | 517 | do_check_true(do_get_addon("test_install3").exists()); |
michael@0 | 518 | a3.uninstall(); |
michael@0 | 519 | do_execute_soon(run_test_9); |
michael@0 | 520 | }); |
michael@0 | 521 | } |
michael@0 | 522 | |
michael@0 | 523 | // Test that after cancelling a download it is removed from the active installs |
michael@0 | 524 | function run_test_9() { |
michael@0 | 525 | restartManager(); |
michael@0 | 526 | |
michael@0 | 527 | prepare_test({ }, [ |
michael@0 | 528 | "onNewInstall" |
michael@0 | 529 | ]); |
michael@0 | 530 | |
michael@0 | 531 | let url = "http://localhost:4444/addons/test_install3.xpi"; |
michael@0 | 532 | AddonManager.getInstallForURL(url, function(install) { |
michael@0 | 533 | ensure_test_completed(); |
michael@0 | 534 | |
michael@0 | 535 | do_check_neq(install, null); |
michael@0 | 536 | do_check_eq(install.version, "1.0"); |
michael@0 | 537 | do_check_eq(install.name, "Real Test 4"); |
michael@0 | 538 | do_check_eq(install.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 539 | |
michael@0 | 540 | AddonManager.getInstallsByTypes(null, function(activeInstalls) { |
michael@0 | 541 | do_check_eq(activeInstalls.length, 1); |
michael@0 | 542 | do_check_eq(activeInstalls[0], install); |
michael@0 | 543 | |
michael@0 | 544 | prepare_test({}, [ |
michael@0 | 545 | "onDownloadStarted", |
michael@0 | 546 | "onDownloadEnded", |
michael@0 | 547 | ], check_test_9); |
michael@0 | 548 | install.install(); |
michael@0 | 549 | }); |
michael@0 | 550 | }, "application/x-xpinstall", null, "Real Test 4", null, "1.0"); |
michael@0 | 551 | } |
michael@0 | 552 | |
michael@0 | 553 | function check_test_9(install) { |
michael@0 | 554 | prepare_test({}, [ |
michael@0 | 555 | "onDownloadCancelled" |
michael@0 | 556 | ]); |
michael@0 | 557 | |
michael@0 | 558 | install.cancel(); |
michael@0 | 559 | |
michael@0 | 560 | ensure_test_completed(); |
michael@0 | 561 | |
michael@0 | 562 | AddonManager.getAllInstalls(function(activeInstalls) { |
michael@0 | 563 | do_check_eq(activeInstalls.length, 0); |
michael@0 | 564 | |
michael@0 | 565 | run_test_10(); |
michael@0 | 566 | }); |
michael@0 | 567 | } |
michael@0 | 568 | |
michael@0 | 569 | // Tests that after cancelling a pending install it is removed from the active |
michael@0 | 570 | // installs |
michael@0 | 571 | function run_test_10() { |
michael@0 | 572 | prepare_test({ }, [ |
michael@0 | 573 | "onNewInstall" |
michael@0 | 574 | ]); |
michael@0 | 575 | |
michael@0 | 576 | let url = "http://localhost:4444/addons/test_install3.xpi"; |
michael@0 | 577 | AddonManager.getInstallForURL(url, function(install) { |
michael@0 | 578 | ensure_test_completed(); |
michael@0 | 579 | |
michael@0 | 580 | do_check_neq(install, null); |
michael@0 | 581 | do_check_eq(install.version, "1.0"); |
michael@0 | 582 | do_check_eq(install.name, "Real Test 4"); |
michael@0 | 583 | do_check_eq(install.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 584 | |
michael@0 | 585 | AddonManager.getInstallsByTypes(null, function(activeInstalls) { |
michael@0 | 586 | do_check_eq(activeInstalls.length, 1); |
michael@0 | 587 | do_check_eq(activeInstalls[0], install); |
michael@0 | 588 | |
michael@0 | 589 | prepare_test({ |
michael@0 | 590 | "addon3@tests.mozilla.org": [ |
michael@0 | 591 | "onInstalling" |
michael@0 | 592 | ] |
michael@0 | 593 | }, [ |
michael@0 | 594 | "onDownloadStarted", |
michael@0 | 595 | "onDownloadEnded", |
michael@0 | 596 | "onInstallStarted", |
michael@0 | 597 | "onInstallEnded" |
michael@0 | 598 | ], check_test_10); |
michael@0 | 599 | install.install(); |
michael@0 | 600 | }); |
michael@0 | 601 | }, "application/x-xpinstall", null, "Real Test 4", null, "1.0"); |
michael@0 | 602 | } |
michael@0 | 603 | |
michael@0 | 604 | function check_test_10(install) { |
michael@0 | 605 | prepare_test({ |
michael@0 | 606 | "addon3@tests.mozilla.org": [ |
michael@0 | 607 | "onOperationCancelled" |
michael@0 | 608 | ] |
michael@0 | 609 | }, [ |
michael@0 | 610 | "onInstallCancelled" |
michael@0 | 611 | ]); |
michael@0 | 612 | |
michael@0 | 613 | install.cancel(); |
michael@0 | 614 | |
michael@0 | 615 | ensure_test_completed(); |
michael@0 | 616 | |
michael@0 | 617 | AddonManager.getAllInstalls(callback_soon(function(activeInstalls) { |
michael@0 | 618 | do_check_eq(activeInstalls.length, 0); |
michael@0 | 619 | |
michael@0 | 620 | restartManager(); |
michael@0 | 621 | |
michael@0 | 622 | // Check that the install did not complete |
michael@0 | 623 | AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) { |
michael@0 | 624 | do_check_eq(a3, null); |
michael@0 | 625 | |
michael@0 | 626 | run_test_11(); |
michael@0 | 627 | }); |
michael@0 | 628 | })); |
michael@0 | 629 | } |
michael@0 | 630 | |
michael@0 | 631 | // Tests that a multi-package install shows up as multiple installs with the |
michael@0 | 632 | // correct sourceURI. |
michael@0 | 633 | function run_test_11() { |
michael@0 | 634 | prepare_test({ }, [ |
michael@0 | 635 | "onNewInstall", |
michael@0 | 636 | "onNewInstall", |
michael@0 | 637 | "onNewInstall", |
michael@0 | 638 | "onNewInstall" |
michael@0 | 639 | ]); |
michael@0 | 640 | |
michael@0 | 641 | AddonManager.getInstallForFile(do_get_addon("test_install4"), function(install) { |
michael@0 | 642 | ensure_test_completed(); |
michael@0 | 643 | do_check_neq(install, null); |
michael@0 | 644 | do_check_neq(install.linkedInstalls, null); |
michael@0 | 645 | do_check_eq(install.linkedInstalls.length, 3); |
michael@0 | 646 | |
michael@0 | 647 | // Might be in any order so sort them based on ID |
michael@0 | 648 | let installs = [install].concat(install.linkedInstalls); |
michael@0 | 649 | installs.sort(function(a, b) { |
michael@0 | 650 | if (a.addon.id < b.addon.id) |
michael@0 | 651 | return -1; |
michael@0 | 652 | if (a.addon.id > b.addon.id) |
michael@0 | 653 | return 1; |
michael@0 | 654 | return 0; |
michael@0 | 655 | }); |
michael@0 | 656 | |
michael@0 | 657 | // Comes from addon4.xpi and is made compatible by an update check |
michael@0 | 658 | do_check_eq(installs[0].sourceURI, install.sourceURI); |
michael@0 | 659 | do_check_eq(installs[0].addon.id, "addon4@tests.mozilla.org"); |
michael@0 | 660 | do_check_false(installs[0].addon.appDisabled); |
michael@0 | 661 | do_check_eq(installs[0].version, "1.0"); |
michael@0 | 662 | do_check_eq(installs[0].name, "Multi Test 1"); |
michael@0 | 663 | do_check_eq(installs[0].state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 664 | do_check_true(hasFlag(installs[0].addon.operationsRequiringRestart, |
michael@0 | 665 | AddonManager.OP_NEEDS_RESTART_INSTALL)); |
michael@0 | 666 | |
michael@0 | 667 | // Comes from addon5.jar and is compatible by default |
michael@0 | 668 | do_check_eq(installs[1].sourceURI, install.sourceURI); |
michael@0 | 669 | do_check_eq(installs[1].addon.id, "addon5@tests.mozilla.org"); |
michael@0 | 670 | do_check_false(installs[1].addon.appDisabled); |
michael@0 | 671 | do_check_eq(installs[1].version, "3.0"); |
michael@0 | 672 | do_check_eq(installs[1].name, "Multi Test 2"); |
michael@0 | 673 | do_check_eq(installs[1].state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 674 | do_check_true(hasFlag(installs[1].addon.operationsRequiringRestart, |
michael@0 | 675 | AddonManager.OP_NEEDS_RESTART_INSTALL)); |
michael@0 | 676 | |
michael@0 | 677 | // Comes from addon6.xpi and is incompatible |
michael@0 | 678 | do_check_eq(installs[2].sourceURI, install.sourceURI); |
michael@0 | 679 | do_check_eq(installs[2].addon.id, "addon6@tests.mozilla.org"); |
michael@0 | 680 | do_check_true(installs[2].addon.appDisabled); |
michael@0 | 681 | do_check_eq(installs[2].version, "2.0"); |
michael@0 | 682 | do_check_eq(installs[2].name, "Multi Test 3"); |
michael@0 | 683 | do_check_eq(installs[2].state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 684 | do_check_false(hasFlag(installs[2].addon.operationsRequiringRestart, |
michael@0 | 685 | AddonManager.OP_NEEDS_RESTART_INSTALL)); |
michael@0 | 686 | |
michael@0 | 687 | // Comes from addon7.jar and is made compatible by an update check |
michael@0 | 688 | do_check_eq(installs[3].sourceURI, install.sourceURI); |
michael@0 | 689 | do_check_eq(installs[3].addon.id, "addon7@tests.mozilla.org"); |
michael@0 | 690 | do_check_false(installs[3].addon.appDisabled); |
michael@0 | 691 | do_check_eq(installs[3].version, "5.0"); |
michael@0 | 692 | do_check_eq(installs[3].name, "Multi Test 4"); |
michael@0 | 693 | do_check_eq(installs[3].state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 694 | do_check_true(hasFlag(installs[3].addon.operationsRequiringRestart, |
michael@0 | 695 | AddonManager.OP_NEEDS_RESTART_INSTALL)); |
michael@0 | 696 | |
michael@0 | 697 | AddonManager.getAllInstalls(function(aInstalls) { |
michael@0 | 698 | do_check_eq(aInstalls.length, 4); |
michael@0 | 699 | |
michael@0 | 700 | prepare_test({ |
michael@0 | 701 | "addon4@tests.mozilla.org": [ |
michael@0 | 702 | "onInstalling" |
michael@0 | 703 | ], |
michael@0 | 704 | "addon5@tests.mozilla.org": [ |
michael@0 | 705 | "onInstalling" |
michael@0 | 706 | ], |
michael@0 | 707 | "addon6@tests.mozilla.org": [ |
michael@0 | 708 | ["onInstalling", false], |
michael@0 | 709 | "onInstalled" |
michael@0 | 710 | ], |
michael@0 | 711 | "addon7@tests.mozilla.org": [ |
michael@0 | 712 | "onInstalling" |
michael@0 | 713 | ] |
michael@0 | 714 | }, { |
michael@0 | 715 | "addon4@tests.mozilla.org": [ |
michael@0 | 716 | "onInstallStarted", |
michael@0 | 717 | "onInstallEnded" |
michael@0 | 718 | ], |
michael@0 | 719 | "addon5@tests.mozilla.org": [ |
michael@0 | 720 | "onInstallStarted", |
michael@0 | 721 | "onInstallEnded" |
michael@0 | 722 | ], |
michael@0 | 723 | "addon6@tests.mozilla.org": [ |
michael@0 | 724 | "onInstallStarted", |
michael@0 | 725 | "onInstallEnded" |
michael@0 | 726 | ], |
michael@0 | 727 | "addon7@tests.mozilla.org": [ |
michael@0 | 728 | "onInstallStarted", |
michael@0 | 729 | "onInstallEnded" |
michael@0 | 730 | ] |
michael@0 | 731 | }, callback_soon(check_test_11)); |
michael@0 | 732 | |
michael@0 | 733 | installs[0].install(); |
michael@0 | 734 | installs[1].install(); |
michael@0 | 735 | installs[3].install(); |
michael@0 | 736 | |
michael@0 | 737 | // Note that we install addon6 last. Since it doesn't need a restart to |
michael@0 | 738 | // install it completes asynchronously which would otherwise make the |
michael@0 | 739 | // onInstallStarted/onInstallEnded events go out of sequence unless this |
michael@0 | 740 | // is the last install operation |
michael@0 | 741 | installs[2].install(); |
michael@0 | 742 | }); |
michael@0 | 743 | }); |
michael@0 | 744 | } |
michael@0 | 745 | |
michael@0 | 746 | function check_test_11() { |
michael@0 | 747 | restartManager(); |
michael@0 | 748 | |
michael@0 | 749 | AddonManager.getAddonsByIDs(["addon4@tests.mozilla.org", |
michael@0 | 750 | "addon5@tests.mozilla.org", |
michael@0 | 751 | "addon6@tests.mozilla.org", |
michael@0 | 752 | "addon7@tests.mozilla.org"], |
michael@0 | 753 | function([a4, a5, a6, a7]) { |
michael@0 | 754 | do_check_neq(a4, null); |
michael@0 | 755 | do_check_neq(a5, null); |
michael@0 | 756 | do_check_neq(a6, null); |
michael@0 | 757 | do_check_neq(a7, null); |
michael@0 | 758 | |
michael@0 | 759 | a4.uninstall(); |
michael@0 | 760 | a5.uninstall(); |
michael@0 | 761 | a6.uninstall(); |
michael@0 | 762 | a7.uninstall(); |
michael@0 | 763 | |
michael@0 | 764 | do_execute_soon(run_test_12); |
michael@0 | 765 | }); |
michael@0 | 766 | } |
michael@0 | 767 | |
michael@0 | 768 | // Same as test 11 but for a remote XPI |
michael@0 | 769 | function run_test_12() { |
michael@0 | 770 | restartManager(); |
michael@0 | 771 | |
michael@0 | 772 | prepare_test({ }, [ |
michael@0 | 773 | "onNewInstall", |
michael@0 | 774 | ]); |
michael@0 | 775 | |
michael@0 | 776 | let url = "http://localhost:4444/addons/test_install4.xpi"; |
michael@0 | 777 | AddonManager.getInstallForURL(url, function(install) { |
michael@0 | 778 | gInstall = install; |
michael@0 | 779 | |
michael@0 | 780 | ensure_test_completed(); |
michael@0 | 781 | do_check_neq(install, null); |
michael@0 | 782 | do_check_eq(install.linkedInstalls, null); |
michael@0 | 783 | do_check_eq(install.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 784 | |
michael@0 | 785 | prepare_test({ |
michael@0 | 786 | "addon4@tests.mozilla.org": [ |
michael@0 | 787 | "onInstalling" |
michael@0 | 788 | ], |
michael@0 | 789 | "addon5@tests.mozilla.org": [ |
michael@0 | 790 | "onInstalling" |
michael@0 | 791 | ], |
michael@0 | 792 | "addon6@tests.mozilla.org": [ |
michael@0 | 793 | ["onInstalling", false], |
michael@0 | 794 | "onInstalled" |
michael@0 | 795 | ], |
michael@0 | 796 | "addon7@tests.mozilla.org": [ |
michael@0 | 797 | "onInstalling" |
michael@0 | 798 | ] |
michael@0 | 799 | }, { |
michael@0 | 800 | "NO_ID": [ |
michael@0 | 801 | "onDownloadStarted", |
michael@0 | 802 | "onNewInstall", |
michael@0 | 803 | "onNewInstall", |
michael@0 | 804 | "onNewInstall", |
michael@0 | 805 | "onDownloadEnded" |
michael@0 | 806 | ], |
michael@0 | 807 | "addon4@tests.mozilla.org": [ |
michael@0 | 808 | "onInstallStarted", |
michael@0 | 809 | "onInstallEnded" |
michael@0 | 810 | ], |
michael@0 | 811 | "addon5@tests.mozilla.org": [ |
michael@0 | 812 | "onInstallStarted", |
michael@0 | 813 | "onInstallEnded" |
michael@0 | 814 | ], |
michael@0 | 815 | "addon6@tests.mozilla.org": [ |
michael@0 | 816 | "onInstallStarted", |
michael@0 | 817 | "onInstallEnded" |
michael@0 | 818 | ], |
michael@0 | 819 | "addon7@tests.mozilla.org": [ |
michael@0 | 820 | "onInstallStarted", |
michael@0 | 821 | "onInstallEnded" |
michael@0 | 822 | ] |
michael@0 | 823 | }, callback_soon(check_test_12)); |
michael@0 | 824 | install.install(); |
michael@0 | 825 | }, "application/x-xpinstall", null, "Multi Test 4"); |
michael@0 | 826 | } |
michael@0 | 827 | |
michael@0 | 828 | function check_test_12() { |
michael@0 | 829 | do_check_eq(gInstall.linkedInstalls.length, 3); |
michael@0 | 830 | |
michael@0 | 831 | // Might be in any order so sort them based on ID |
michael@0 | 832 | let installs = [gInstall].concat(gInstall.linkedInstalls); |
michael@0 | 833 | installs.sort(function(a, b) { |
michael@0 | 834 | if (a.addon.id < b.addon.id) |
michael@0 | 835 | return -1; |
michael@0 | 836 | if (a.addon.id > b.addon.id) |
michael@0 | 837 | return 1; |
michael@0 | 838 | return 0; |
michael@0 | 839 | }); |
michael@0 | 840 | |
michael@0 | 841 | // Comes from addon4.xpi and is made compatible by an update check |
michael@0 | 842 | do_check_eq(installs[0].sourceURI, gInstall.sourceURI); |
michael@0 | 843 | do_check_eq(installs[0].addon.id, "addon4@tests.mozilla.org"); |
michael@0 | 844 | do_check_false(installs[0].addon.appDisabled); |
michael@0 | 845 | do_check_eq(installs[0].version, "1.0"); |
michael@0 | 846 | do_check_eq(installs[0].name, "Multi Test 1"); |
michael@0 | 847 | do_check_eq(installs[0].state, AddonManager.STATE_INSTALLED); |
michael@0 | 848 | |
michael@0 | 849 | // Comes from addon5.jar and is compatible by default |
michael@0 | 850 | do_check_eq(installs[1].sourceURI, gInstall.sourceURI); |
michael@0 | 851 | do_check_eq(installs[1].addon.id, "addon5@tests.mozilla.org"); |
michael@0 | 852 | do_check_false(installs[1].addon.appDisabled); |
michael@0 | 853 | do_check_eq(installs[1].version, "3.0"); |
michael@0 | 854 | do_check_eq(installs[1].name, "Multi Test 2"); |
michael@0 | 855 | do_check_eq(installs[1].state, AddonManager.STATE_INSTALLED); |
michael@0 | 856 | |
michael@0 | 857 | // Comes from addon6.xpi and is incompatible |
michael@0 | 858 | do_check_eq(installs[2].sourceURI, gInstall.sourceURI); |
michael@0 | 859 | do_check_eq(installs[2].addon.id, "addon6@tests.mozilla.org"); |
michael@0 | 860 | do_check_true(installs[2].addon.appDisabled); |
michael@0 | 861 | do_check_eq(installs[2].version, "2.0"); |
michael@0 | 862 | do_check_eq(installs[2].name, "Multi Test 3"); |
michael@0 | 863 | do_check_eq(installs[2].state, AddonManager.STATE_INSTALLED); |
michael@0 | 864 | |
michael@0 | 865 | // Comes from addon7.jar and is made compatible by an update check |
michael@0 | 866 | do_check_eq(installs[3].sourceURI, gInstall.sourceURI); |
michael@0 | 867 | do_check_eq(installs[3].addon.id, "addon7@tests.mozilla.org"); |
michael@0 | 868 | do_check_false(installs[3].addon.appDisabled); |
michael@0 | 869 | do_check_eq(installs[3].version, "5.0"); |
michael@0 | 870 | do_check_eq(installs[3].name, "Multi Test 4"); |
michael@0 | 871 | do_check_eq(installs[3].state, AddonManager.STATE_INSTALLED); |
michael@0 | 872 | |
michael@0 | 873 | restartManager(); |
michael@0 | 874 | |
michael@0 | 875 | AddonManager.getAddonsByIDs(["addon4@tests.mozilla.org", |
michael@0 | 876 | "addon5@tests.mozilla.org", |
michael@0 | 877 | "addon6@tests.mozilla.org", |
michael@0 | 878 | "addon7@tests.mozilla.org"], |
michael@0 | 879 | function([a4, a5, a6, a7]) { |
michael@0 | 880 | do_check_neq(a4, null); |
michael@0 | 881 | do_check_neq(a5, null); |
michael@0 | 882 | do_check_neq(a6, null); |
michael@0 | 883 | do_check_neq(a7, null); |
michael@0 | 884 | |
michael@0 | 885 | a4.uninstall(); |
michael@0 | 886 | a5.uninstall(); |
michael@0 | 887 | a6.uninstall(); |
michael@0 | 888 | a7.uninstall(); |
michael@0 | 889 | |
michael@0 | 890 | do_execute_soon(run_test_13); |
michael@0 | 891 | }); |
michael@0 | 892 | } |
michael@0 | 893 | |
michael@0 | 894 | |
michael@0 | 895 | // Tests that cancelling an upgrade leaves the original add-on's pendingOperations |
michael@0 | 896 | // correct |
michael@0 | 897 | function run_test_13() { |
michael@0 | 898 | restartManager(); |
michael@0 | 899 | |
michael@0 | 900 | installAllFiles([do_get_addon("test_install2_1")], function() { |
michael@0 | 901 | restartManager(); |
michael@0 | 902 | |
michael@0 | 903 | prepare_test({ }, [ |
michael@0 | 904 | "onNewInstall" |
michael@0 | 905 | ]); |
michael@0 | 906 | |
michael@0 | 907 | let url = "http://localhost:4444/addons/test_install2_2.xpi"; |
michael@0 | 908 | AddonManager.getInstallForURL(url, function(install) { |
michael@0 | 909 | ensure_test_completed(); |
michael@0 | 910 | |
michael@0 | 911 | do_check_neq(install, null); |
michael@0 | 912 | do_check_eq(install.version, "3.0"); |
michael@0 | 913 | do_check_eq(install.name, "Test 3"); |
michael@0 | 914 | do_check_eq(install.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 915 | |
michael@0 | 916 | AddonManager.getAllInstalls(function(activeInstalls) { |
michael@0 | 917 | do_check_eq(activeInstalls.length, 1); |
michael@0 | 918 | do_check_eq(activeInstalls[0], install); |
michael@0 | 919 | do_check_eq(install.existingAddon, null); |
michael@0 | 920 | |
michael@0 | 921 | prepare_test({ |
michael@0 | 922 | "addon2@tests.mozilla.org": [ |
michael@0 | 923 | "onInstalling" |
michael@0 | 924 | ] |
michael@0 | 925 | }, [ |
michael@0 | 926 | "onDownloadStarted", |
michael@0 | 927 | "onDownloadEnded", |
michael@0 | 928 | "onInstallStarted", |
michael@0 | 929 | "onInstallEnded", |
michael@0 | 930 | ], check_test_13); |
michael@0 | 931 | install.install(); |
michael@0 | 932 | }); |
michael@0 | 933 | }, "application/x-xpinstall", null, "Test 3", null, "3.0"); |
michael@0 | 934 | }); |
michael@0 | 935 | } |
michael@0 | 936 | |
michael@0 | 937 | function check_test_13(install) { |
michael@0 | 938 | ensure_test_completed(); |
michael@0 | 939 | |
michael@0 | 940 | do_check_eq(install.version, "3.0"); |
michael@0 | 941 | do_check_eq(install.name, "Real Test 3"); |
michael@0 | 942 | do_check_eq(install.state, AddonManager.STATE_INSTALLED); |
michael@0 | 943 | do_check_neq(install.existingAddon, null); |
michael@0 | 944 | do_check_eq(install.existingAddon.id, "addon2@tests.mozilla.org"); |
michael@0 | 945 | do_check_eq(install.addon.install, install); |
michael@0 | 946 | |
michael@0 | 947 | AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(function(olda2) { |
michael@0 | 948 | do_check_neq(olda2, null); |
michael@0 | 949 | do_check_true(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE)); |
michael@0 | 950 | do_check_eq(olda2.pendingUpgrade, install.addon); |
michael@0 | 951 | |
michael@0 | 952 | do_check_true(hasFlag(install.addon.pendingOperations, |
michael@0 | 953 | AddonManager.PENDING_INSTALL)); |
michael@0 | 954 | |
michael@0 | 955 | prepare_test({ |
michael@0 | 956 | "addon2@tests.mozilla.org": [ |
michael@0 | 957 | "onOperationCancelled" |
michael@0 | 958 | ] |
michael@0 | 959 | }, [ |
michael@0 | 960 | "onInstallCancelled", |
michael@0 | 961 | ]); |
michael@0 | 962 | |
michael@0 | 963 | install.cancel(); |
michael@0 | 964 | |
michael@0 | 965 | do_check_false(hasFlag(install.addon.pendingOperations, AddonManager.PENDING_INSTALL)); |
michael@0 | 966 | |
michael@0 | 967 | do_check_false(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE)); |
michael@0 | 968 | do_check_eq(olda2.pendingUpgrade, null); |
michael@0 | 969 | |
michael@0 | 970 | restartManager(); |
michael@0 | 971 | |
michael@0 | 972 | // Check that the upgrade did not complete |
michael@0 | 973 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 974 | do_check_eq(a2.version, "2.0"); |
michael@0 | 975 | |
michael@0 | 976 | a2.uninstall(); |
michael@0 | 977 | |
michael@0 | 978 | do_execute_soon(run_test_14); |
michael@0 | 979 | }); |
michael@0 | 980 | })); |
michael@0 | 981 | } |
michael@0 | 982 | |
michael@0 | 983 | // Check that cancelling the install from onDownloadStarted actually cancels it |
michael@0 | 984 | function run_test_14() { |
michael@0 | 985 | restartManager(); |
michael@0 | 986 | |
michael@0 | 987 | prepare_test({ }, [ |
michael@0 | 988 | "onNewInstall" |
michael@0 | 989 | ]); |
michael@0 | 990 | |
michael@0 | 991 | let url = "http://localhost:4444/addons/test_install2_1.xpi"; |
michael@0 | 992 | AddonManager.getInstallForURL(url, function(install) { |
michael@0 | 993 | ensure_test_completed(); |
michael@0 | 994 | |
michael@0 | 995 | do_check_eq(install.file, null); |
michael@0 | 996 | |
michael@0 | 997 | prepare_test({ }, [ |
michael@0 | 998 | "onDownloadStarted" |
michael@0 | 999 | ], check_test_14); |
michael@0 | 1000 | install.install(); |
michael@0 | 1001 | }, "application/x-xpinstall"); |
michael@0 | 1002 | } |
michael@0 | 1003 | |
michael@0 | 1004 | function check_test_14(install) { |
michael@0 | 1005 | prepare_test({ }, [ |
michael@0 | 1006 | "onDownloadCancelled" |
michael@0 | 1007 | ]); |
michael@0 | 1008 | |
michael@0 | 1009 | install.cancel(); |
michael@0 | 1010 | |
michael@0 | 1011 | ensure_test_completed(); |
michael@0 | 1012 | |
michael@0 | 1013 | install.addListener({ |
michael@0 | 1014 | onDownloadProgress: function() { |
michael@0 | 1015 | do_throw("Download should not have continued"); |
michael@0 | 1016 | }, |
michael@0 | 1017 | onDownloadEnded: function() { |
michael@0 | 1018 | do_throw("Download should not have continued"); |
michael@0 | 1019 | } |
michael@0 | 1020 | }); |
michael@0 | 1021 | |
michael@0 | 1022 | // Allow the listener to return to see if it continues downloading. The |
michael@0 | 1023 | // The listener only really tests if we give it time to see progress, the |
michael@0 | 1024 | // file check isn't ideal either |
michael@0 | 1025 | do_execute_soon(function() { |
michael@0 | 1026 | do_check_eq(install.file, null); |
michael@0 | 1027 | |
michael@0 | 1028 | run_test_15(); |
michael@0 | 1029 | }); |
michael@0 | 1030 | } |
michael@0 | 1031 | |
michael@0 | 1032 | // Checks that cancelling the install from onDownloadEnded actually cancels it |
michael@0 | 1033 | function run_test_15() { |
michael@0 | 1034 | prepare_test({ }, [ |
michael@0 | 1035 | "onNewInstall" |
michael@0 | 1036 | ]); |
michael@0 | 1037 | |
michael@0 | 1038 | let url = "http://localhost:4444/addons/test_install2_1.xpi"; |
michael@0 | 1039 | AddonManager.getInstallForURL(url, function(install) { |
michael@0 | 1040 | ensure_test_completed(); |
michael@0 | 1041 | |
michael@0 | 1042 | do_check_eq(install.file, null); |
michael@0 | 1043 | |
michael@0 | 1044 | prepare_test({ }, [ |
michael@0 | 1045 | "onDownloadStarted", |
michael@0 | 1046 | "onDownloadEnded" |
michael@0 | 1047 | ], check_test_15); |
michael@0 | 1048 | install.install(); |
michael@0 | 1049 | }, "application/x-xpinstall"); |
michael@0 | 1050 | } |
michael@0 | 1051 | |
michael@0 | 1052 | function check_test_15(install) { |
michael@0 | 1053 | prepare_test({ }, [ |
michael@0 | 1054 | "onDownloadCancelled" |
michael@0 | 1055 | ]); |
michael@0 | 1056 | |
michael@0 | 1057 | install.cancel(); |
michael@0 | 1058 | |
michael@0 | 1059 | ensure_test_completed(); |
michael@0 | 1060 | |
michael@0 | 1061 | install.addListener({ |
michael@0 | 1062 | onInstallStarted: function() { |
michael@0 | 1063 | do_throw("Install should not have continued"); |
michael@0 | 1064 | } |
michael@0 | 1065 | }); |
michael@0 | 1066 | |
michael@0 | 1067 | // Allow the listener to return to see if it starts installing |
michael@0 | 1068 | do_execute_soon(run_test_16); |
michael@0 | 1069 | } |
michael@0 | 1070 | |
michael@0 | 1071 | // Verify that the userDisabled value carries over to the upgrade by default |
michael@0 | 1072 | function run_test_16() { |
michael@0 | 1073 | restartManager(); |
michael@0 | 1074 | |
michael@0 | 1075 | let url = "http://localhost:4444/addons/test_install2_1.xpi"; |
michael@0 | 1076 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1077 | aInstall.addListener({ |
michael@0 | 1078 | onInstallStarted: function() { |
michael@0 | 1079 | do_check_false(aInstall.addon.userDisabled); |
michael@0 | 1080 | aInstall.addon.userDisabled = true; |
michael@0 | 1081 | }, |
michael@0 | 1082 | |
michael@0 | 1083 | onInstallEnded: function() { |
michael@0 | 1084 | do_execute_soon(function test16_install1() { |
michael@0 | 1085 | restartManager(); |
michael@0 | 1086 | |
michael@0 | 1087 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 1088 | do_check_true(a2.userDisabled); |
michael@0 | 1089 | do_check_false(a2.isActive); |
michael@0 | 1090 | |
michael@0 | 1091 | let url = "http://localhost:4444/addons/test_install2_2.xpi"; |
michael@0 | 1092 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1093 | aInstall.addListener({ |
michael@0 | 1094 | onInstallEnded: function() { |
michael@0 | 1095 | do_execute_soon(function test16_install2() { |
michael@0 | 1096 | do_check_true(aInstall.addon.userDisabled); |
michael@0 | 1097 | |
michael@0 | 1098 | restartManager(); |
michael@0 | 1099 | |
michael@0 | 1100 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 1101 | do_check_true(a2.userDisabled); |
michael@0 | 1102 | do_check_false(a2.isActive); |
michael@0 | 1103 | |
michael@0 | 1104 | a2.uninstall(); |
michael@0 | 1105 | do_execute_soon(run_test_17); |
michael@0 | 1106 | }); |
michael@0 | 1107 | }); |
michael@0 | 1108 | } |
michael@0 | 1109 | }); |
michael@0 | 1110 | aInstall.install(); |
michael@0 | 1111 | }, "application/x-xpinstall"); |
michael@0 | 1112 | }); |
michael@0 | 1113 | }); |
michael@0 | 1114 | } |
michael@0 | 1115 | }); |
michael@0 | 1116 | aInstall.install(); |
michael@0 | 1117 | }, "application/x-xpinstall"); |
michael@0 | 1118 | } |
michael@0 | 1119 | |
michael@0 | 1120 | // Verify that changing the userDisabled value before onInstallEnded works |
michael@0 | 1121 | function run_test_17() { |
michael@0 | 1122 | restartManager(); |
michael@0 | 1123 | |
michael@0 | 1124 | let url = "http://localhost:4444/addons/test_install2_1.xpi"; |
michael@0 | 1125 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1126 | aInstall.addListener({ |
michael@0 | 1127 | onInstallEnded: function() { |
michael@0 | 1128 | do_execute_soon(function test17_install1() { |
michael@0 | 1129 | do_check_false(aInstall.addon.userDisabled); |
michael@0 | 1130 | |
michael@0 | 1131 | restartManager(); |
michael@0 | 1132 | |
michael@0 | 1133 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 1134 | do_check_false(a2.userDisabled); |
michael@0 | 1135 | do_check_true(a2.isActive); |
michael@0 | 1136 | |
michael@0 | 1137 | let url = "http://localhost:4444/addons/test_install2_2.xpi"; |
michael@0 | 1138 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1139 | aInstall.addListener({ |
michael@0 | 1140 | onInstallStarted: function() { |
michael@0 | 1141 | do_check_false(aInstall.addon.userDisabled); |
michael@0 | 1142 | aInstall.addon.userDisabled = true; |
michael@0 | 1143 | }, |
michael@0 | 1144 | |
michael@0 | 1145 | onInstallEnded: function() { |
michael@0 | 1146 | do_execute_soon(function test17_install1() { |
michael@0 | 1147 | restartManager(); |
michael@0 | 1148 | |
michael@0 | 1149 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 1150 | do_check_true(a2.userDisabled); |
michael@0 | 1151 | do_check_false(a2.isActive); |
michael@0 | 1152 | |
michael@0 | 1153 | a2.uninstall(); |
michael@0 | 1154 | do_execute_soon(run_test_18); |
michael@0 | 1155 | }); |
michael@0 | 1156 | }); |
michael@0 | 1157 | } |
michael@0 | 1158 | }); |
michael@0 | 1159 | aInstall.install(); |
michael@0 | 1160 | }, "application/x-xpinstall"); |
michael@0 | 1161 | }); |
michael@0 | 1162 | }); |
michael@0 | 1163 | } |
michael@0 | 1164 | }); |
michael@0 | 1165 | aInstall.install(); |
michael@0 | 1166 | }, "application/x-xpinstall"); |
michael@0 | 1167 | } |
michael@0 | 1168 | |
michael@0 | 1169 | // Verify that changing the userDisabled value before onInstallEnded works |
michael@0 | 1170 | function run_test_18() { |
michael@0 | 1171 | restartManager(); |
michael@0 | 1172 | |
michael@0 | 1173 | let url = "http://localhost:4444/addons/test_install2_1.xpi"; |
michael@0 | 1174 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1175 | aInstall.addListener({ |
michael@0 | 1176 | onInstallStarted: function() { |
michael@0 | 1177 | do_check_false(aInstall.addon.userDisabled); |
michael@0 | 1178 | aInstall.addon.userDisabled = true; |
michael@0 | 1179 | }, |
michael@0 | 1180 | |
michael@0 | 1181 | onInstallEnded: function() { |
michael@0 | 1182 | do_execute_soon(function test18_install1() { |
michael@0 | 1183 | restartManager(); |
michael@0 | 1184 | |
michael@0 | 1185 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 1186 | do_check_true(a2.userDisabled); |
michael@0 | 1187 | do_check_false(a2.isActive); |
michael@0 | 1188 | |
michael@0 | 1189 | let url = "http://localhost:4444/addons/test_install2_2.xpi"; |
michael@0 | 1190 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1191 | aInstall.addListener({ |
michael@0 | 1192 | onInstallStarted: function() { |
michael@0 | 1193 | do_check_true(aInstall.addon.userDisabled); |
michael@0 | 1194 | aInstall.addon.userDisabled = false; |
michael@0 | 1195 | }, |
michael@0 | 1196 | |
michael@0 | 1197 | onInstallEnded: function() { |
michael@0 | 1198 | do_execute_soon(function test18_install2() { |
michael@0 | 1199 | restartManager(); |
michael@0 | 1200 | |
michael@0 | 1201 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 1202 | do_check_false(a2.userDisabled); |
michael@0 | 1203 | do_check_true(a2.isActive); |
michael@0 | 1204 | |
michael@0 | 1205 | a2.uninstall(); |
michael@0 | 1206 | do_execute_soon(run_test_18_1); |
michael@0 | 1207 | }); |
michael@0 | 1208 | }); |
michael@0 | 1209 | } |
michael@0 | 1210 | }); |
michael@0 | 1211 | aInstall.install(); |
michael@0 | 1212 | }, "application/x-xpinstall"); |
michael@0 | 1213 | }); |
michael@0 | 1214 | }); |
michael@0 | 1215 | } |
michael@0 | 1216 | }); |
michael@0 | 1217 | aInstall.install(); |
michael@0 | 1218 | }, "application/x-xpinstall"); |
michael@0 | 1219 | } |
michael@0 | 1220 | |
michael@0 | 1221 | |
michael@0 | 1222 | // Checks that metadata is not stored if the pref is set to false |
michael@0 | 1223 | function run_test_18_1() { |
michael@0 | 1224 | restartManager(); |
michael@0 | 1225 | |
michael@0 | 1226 | Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true); |
michael@0 | 1227 | Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, |
michael@0 | 1228 | "http://localhost:4444/data/test_install.xml"); |
michael@0 | 1229 | |
michael@0 | 1230 | Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", false); |
michael@0 | 1231 | |
michael@0 | 1232 | let url = "http://localhost:4444/addons/test_install2_1.xpi"; |
michael@0 | 1233 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1234 | aInstall.addListener({ |
michael@0 | 1235 | onInstallEnded: function(aInstall, aAddon) { |
michael@0 | 1236 | do_execute_soon(function test18_install() { |
michael@0 | 1237 | do_check_neq(aAddon.fullDescription, "Repository description"); |
michael@0 | 1238 | |
michael@0 | 1239 | restartManager(); |
michael@0 | 1240 | |
michael@0 | 1241 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 1242 | do_check_neq(a2.fullDescription, "Repository description"); |
michael@0 | 1243 | |
michael@0 | 1244 | a2.uninstall(); |
michael@0 | 1245 | do_execute_soon(run_test_19); |
michael@0 | 1246 | }); |
michael@0 | 1247 | }); |
michael@0 | 1248 | } |
michael@0 | 1249 | }); |
michael@0 | 1250 | aInstall.install(); |
michael@0 | 1251 | }, "application/x-xpinstall"); |
michael@0 | 1252 | } |
michael@0 | 1253 | |
michael@0 | 1254 | // Checks that metadata is downloaded for new installs and is visible before and |
michael@0 | 1255 | // after restart |
michael@0 | 1256 | function run_test_19() { |
michael@0 | 1257 | restartManager(); |
michael@0 | 1258 | Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", true); |
michael@0 | 1259 | |
michael@0 | 1260 | let url = "http://localhost:4444/addons/test_install2_1.xpi"; |
michael@0 | 1261 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1262 | aInstall.addListener({ |
michael@0 | 1263 | onInstallEnded: function(aInstall, aAddon) { |
michael@0 | 1264 | do_execute_soon(function test19_install() { |
michael@0 | 1265 | do_check_eq(aAddon.fullDescription, "Repository description"); |
michael@0 | 1266 | |
michael@0 | 1267 | restartManager(); |
michael@0 | 1268 | |
michael@0 | 1269 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 1270 | do_check_eq(a2.fullDescription, "Repository description"); |
michael@0 | 1271 | |
michael@0 | 1272 | a2.uninstall(); |
michael@0 | 1273 | do_execute_soon(run_test_20); |
michael@0 | 1274 | }); |
michael@0 | 1275 | }); |
michael@0 | 1276 | } |
michael@0 | 1277 | }); |
michael@0 | 1278 | aInstall.install(); |
michael@0 | 1279 | }, "application/x-xpinstall"); |
michael@0 | 1280 | } |
michael@0 | 1281 | |
michael@0 | 1282 | // Do the same again to make sure it works when the data is already in the cache |
michael@0 | 1283 | function run_test_20() { |
michael@0 | 1284 | restartManager(); |
michael@0 | 1285 | |
michael@0 | 1286 | let url = "http://localhost:4444/addons/test_install2_1.xpi"; |
michael@0 | 1287 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1288 | aInstall.addListener({ |
michael@0 | 1289 | onInstallEnded: function(aInstall, aAddon) { |
michael@0 | 1290 | do_execute_soon(function test20_install() { |
michael@0 | 1291 | do_check_eq(aAddon.fullDescription, "Repository description"); |
michael@0 | 1292 | |
michael@0 | 1293 | restartManager(); |
michael@0 | 1294 | |
michael@0 | 1295 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 1296 | do_check_eq(a2.fullDescription, "Repository description"); |
michael@0 | 1297 | |
michael@0 | 1298 | a2.uninstall(); |
michael@0 | 1299 | do_execute_soon(run_test_21); |
michael@0 | 1300 | }); |
michael@0 | 1301 | }); |
michael@0 | 1302 | } |
michael@0 | 1303 | }); |
michael@0 | 1304 | aInstall.install(); |
michael@0 | 1305 | }, "application/x-xpinstall"); |
michael@0 | 1306 | } |
michael@0 | 1307 | |
michael@0 | 1308 | // Verify that installing an add-on that is already pending install cancels the |
michael@0 | 1309 | // first install |
michael@0 | 1310 | function run_test_21() { |
michael@0 | 1311 | restartManager(); |
michael@0 | 1312 | Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false); |
michael@0 | 1313 | |
michael@0 | 1314 | installAllFiles([do_get_addon("test_install2_1")], function() { |
michael@0 | 1315 | AddonManager.getAllInstalls(function(aInstalls) { |
michael@0 | 1316 | do_check_eq(aInstalls.length, 1); |
michael@0 | 1317 | |
michael@0 | 1318 | prepare_test({ |
michael@0 | 1319 | "addon2@tests.mozilla.org": [ |
michael@0 | 1320 | "onOperationCancelled", |
michael@0 | 1321 | "onInstalling" |
michael@0 | 1322 | ] |
michael@0 | 1323 | }, [ |
michael@0 | 1324 | "onNewInstall", |
michael@0 | 1325 | "onDownloadStarted", |
michael@0 | 1326 | "onDownloadEnded", |
michael@0 | 1327 | "onInstallStarted", |
michael@0 | 1328 | "onInstallCancelled", |
michael@0 | 1329 | "onInstallEnded", |
michael@0 | 1330 | ], check_test_21); |
michael@0 | 1331 | |
michael@0 | 1332 | let url = "http://localhost:4444/addons/test_install2_1.xpi"; |
michael@0 | 1333 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1334 | aInstall.install(); |
michael@0 | 1335 | }, "application/x-xpinstall"); |
michael@0 | 1336 | }); |
michael@0 | 1337 | }); |
michael@0 | 1338 | } |
michael@0 | 1339 | |
michael@0 | 1340 | function check_test_21(aInstall) { |
michael@0 | 1341 | AddonManager.getAllInstalls(callback_soon(function(aInstalls) { |
michael@0 | 1342 | do_check_eq(aInstalls.length, 1); |
michael@0 | 1343 | do_check_eq(aInstalls[0], aInstall); |
michael@0 | 1344 | |
michael@0 | 1345 | prepare_test({ |
michael@0 | 1346 | "addon2@tests.mozilla.org": [ |
michael@0 | 1347 | "onOperationCancelled" |
michael@0 | 1348 | ] |
michael@0 | 1349 | }, [ |
michael@0 | 1350 | "onInstallCancelled", |
michael@0 | 1351 | ]); |
michael@0 | 1352 | |
michael@0 | 1353 | aInstall.cancel(); |
michael@0 | 1354 | |
michael@0 | 1355 | ensure_test_completed(); |
michael@0 | 1356 | |
michael@0 | 1357 | restartManager(); |
michael@0 | 1358 | |
michael@0 | 1359 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 1360 | do_check_eq(a2, null); |
michael@0 | 1361 | |
michael@0 | 1362 | run_test_22(); |
michael@0 | 1363 | }); |
michael@0 | 1364 | })); |
michael@0 | 1365 | } |
michael@0 | 1366 | |
michael@0 | 1367 | // Tests that an install can be restarted after being cancelled |
michael@0 | 1368 | function run_test_22() { |
michael@0 | 1369 | prepare_test({ }, [ |
michael@0 | 1370 | "onNewInstall" |
michael@0 | 1371 | ]); |
michael@0 | 1372 | |
michael@0 | 1373 | let url = "http://localhost:4444/addons/test_install3.xpi"; |
michael@0 | 1374 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1375 | ensure_test_completed(); |
michael@0 | 1376 | |
michael@0 | 1377 | do_check_neq(aInstall, null); |
michael@0 | 1378 | do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 1379 | |
michael@0 | 1380 | prepare_test({}, [ |
michael@0 | 1381 | "onDownloadStarted", |
michael@0 | 1382 | "onDownloadEnded", |
michael@0 | 1383 | ], check_test_22); |
michael@0 | 1384 | aInstall.install(); |
michael@0 | 1385 | }, "application/x-xpinstall"); |
michael@0 | 1386 | } |
michael@0 | 1387 | |
michael@0 | 1388 | function check_test_22(aInstall) { |
michael@0 | 1389 | prepare_test({}, [ |
michael@0 | 1390 | "onDownloadCancelled" |
michael@0 | 1391 | ]); |
michael@0 | 1392 | |
michael@0 | 1393 | aInstall.cancel(); |
michael@0 | 1394 | |
michael@0 | 1395 | ensure_test_completed(); |
michael@0 | 1396 | |
michael@0 | 1397 | prepare_test({ |
michael@0 | 1398 | "addon3@tests.mozilla.org": [ |
michael@0 | 1399 | "onInstalling" |
michael@0 | 1400 | ] |
michael@0 | 1401 | }, [ |
michael@0 | 1402 | "onDownloadStarted", |
michael@0 | 1403 | "onDownloadEnded", |
michael@0 | 1404 | "onInstallStarted", |
michael@0 | 1405 | "onInstallEnded" |
michael@0 | 1406 | ], finish_test_22); |
michael@0 | 1407 | |
michael@0 | 1408 | aInstall.install(); |
michael@0 | 1409 | } |
michael@0 | 1410 | |
michael@0 | 1411 | function finish_test_22(aInstall) { |
michael@0 | 1412 | prepare_test({ |
michael@0 | 1413 | "addon3@tests.mozilla.org": [ |
michael@0 | 1414 | "onOperationCancelled" |
michael@0 | 1415 | ] |
michael@0 | 1416 | }, [ |
michael@0 | 1417 | "onInstallCancelled" |
michael@0 | 1418 | ]); |
michael@0 | 1419 | |
michael@0 | 1420 | aInstall.cancel(); |
michael@0 | 1421 | |
michael@0 | 1422 | ensure_test_completed(); |
michael@0 | 1423 | |
michael@0 | 1424 | run_test_23(); |
michael@0 | 1425 | } |
michael@0 | 1426 | |
michael@0 | 1427 | // Tests that an install can be restarted after being cancelled when a hash |
michael@0 | 1428 | // was provided |
michael@0 | 1429 | function run_test_23() { |
michael@0 | 1430 | prepare_test({ }, [ |
michael@0 | 1431 | "onNewInstall" |
michael@0 | 1432 | ]); |
michael@0 | 1433 | |
michael@0 | 1434 | let url = "http://localhost:4444/addons/test_install3.xpi"; |
michael@0 | 1435 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1436 | ensure_test_completed(); |
michael@0 | 1437 | |
michael@0 | 1438 | do_check_neq(aInstall, null); |
michael@0 | 1439 | do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 1440 | |
michael@0 | 1441 | prepare_test({}, [ |
michael@0 | 1442 | "onDownloadStarted", |
michael@0 | 1443 | "onDownloadEnded", |
michael@0 | 1444 | ], check_test_23); |
michael@0 | 1445 | aInstall.install(); |
michael@0 | 1446 | }, "application/x-xpinstall", do_get_addon_hash("test_install3")); |
michael@0 | 1447 | } |
michael@0 | 1448 | |
michael@0 | 1449 | function check_test_23(aInstall) { |
michael@0 | 1450 | prepare_test({}, [ |
michael@0 | 1451 | "onDownloadCancelled" |
michael@0 | 1452 | ]); |
michael@0 | 1453 | |
michael@0 | 1454 | aInstall.cancel(); |
michael@0 | 1455 | |
michael@0 | 1456 | ensure_test_completed(); |
michael@0 | 1457 | |
michael@0 | 1458 | prepare_test({ |
michael@0 | 1459 | "addon3@tests.mozilla.org": [ |
michael@0 | 1460 | "onInstalling" |
michael@0 | 1461 | ] |
michael@0 | 1462 | }, [ |
michael@0 | 1463 | "onDownloadStarted", |
michael@0 | 1464 | "onDownloadEnded", |
michael@0 | 1465 | "onInstallStarted", |
michael@0 | 1466 | "onInstallEnded" |
michael@0 | 1467 | ], finish_test_23); |
michael@0 | 1468 | |
michael@0 | 1469 | aInstall.install(); |
michael@0 | 1470 | } |
michael@0 | 1471 | |
michael@0 | 1472 | function finish_test_23(aInstall) { |
michael@0 | 1473 | prepare_test({ |
michael@0 | 1474 | "addon3@tests.mozilla.org": [ |
michael@0 | 1475 | "onOperationCancelled" |
michael@0 | 1476 | ] |
michael@0 | 1477 | }, [ |
michael@0 | 1478 | "onInstallCancelled" |
michael@0 | 1479 | ]); |
michael@0 | 1480 | |
michael@0 | 1481 | aInstall.cancel(); |
michael@0 | 1482 | |
michael@0 | 1483 | ensure_test_completed(); |
michael@0 | 1484 | |
michael@0 | 1485 | run_test_24(); |
michael@0 | 1486 | } |
michael@0 | 1487 | |
michael@0 | 1488 | // Tests that an install with a bad hash can be restarted after it fails, though |
michael@0 | 1489 | // it will only fail again |
michael@0 | 1490 | function run_test_24() { |
michael@0 | 1491 | prepare_test({ }, [ |
michael@0 | 1492 | "onNewInstall" |
michael@0 | 1493 | ]); |
michael@0 | 1494 | |
michael@0 | 1495 | let url = "http://localhost:4444/addons/test_install3.xpi"; |
michael@0 | 1496 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1497 | ensure_test_completed(); |
michael@0 | 1498 | |
michael@0 | 1499 | do_check_neq(aInstall, null); |
michael@0 | 1500 | do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 1501 | |
michael@0 | 1502 | prepare_test({}, [ |
michael@0 | 1503 | "onDownloadStarted", |
michael@0 | 1504 | "onDownloadFailed", |
michael@0 | 1505 | ], check_test_24); |
michael@0 | 1506 | aInstall.install(); |
michael@0 | 1507 | }, "application/x-xpinstall", "sha1:foo"); |
michael@0 | 1508 | } |
michael@0 | 1509 | |
michael@0 | 1510 | function check_test_24(aInstall) { |
michael@0 | 1511 | prepare_test({ }, [ |
michael@0 | 1512 | "onDownloadStarted", |
michael@0 | 1513 | "onDownloadFailed" |
michael@0 | 1514 | ], run_test_25); |
michael@0 | 1515 | |
michael@0 | 1516 | aInstall.install(); |
michael@0 | 1517 | } |
michael@0 | 1518 | |
michael@0 | 1519 | // Tests that installs with a hash for a local file work |
michael@0 | 1520 | function run_test_25() { |
michael@0 | 1521 | prepare_test({ }, [ |
michael@0 | 1522 | "onNewInstall" |
michael@0 | 1523 | ]); |
michael@0 | 1524 | |
michael@0 | 1525 | let url = Services.io.newFileURI(do_get_addon("test_install3")).spec; |
michael@0 | 1526 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1527 | ensure_test_completed(); |
michael@0 | 1528 | |
michael@0 | 1529 | do_check_neq(aInstall, null); |
michael@0 | 1530 | do_check_eq(aInstall.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 1531 | do_check_eq(aInstall.error, 0); |
michael@0 | 1532 | |
michael@0 | 1533 | prepare_test({ }, [ |
michael@0 | 1534 | "onDownloadCancelled" |
michael@0 | 1535 | ]); |
michael@0 | 1536 | |
michael@0 | 1537 | aInstall.cancel(); |
michael@0 | 1538 | |
michael@0 | 1539 | ensure_test_completed(); |
michael@0 | 1540 | |
michael@0 | 1541 | run_test_26(); |
michael@0 | 1542 | }, "application/x-xpinstall", do_get_addon_hash("test_install3")); |
michael@0 | 1543 | } |
michael@0 | 1544 | |
michael@0 | 1545 | function run_test_26() { |
michael@0 | 1546 | prepare_test({ }, [ |
michael@0 | 1547 | "onNewInstall", |
michael@0 | 1548 | "onDownloadStarted", |
michael@0 | 1549 | "onDownloadCancelled" |
michael@0 | 1550 | ]); |
michael@0 | 1551 | |
michael@0 | 1552 | let observerService = AM_Cc["@mozilla.org/network/http-activity-distributor;1"]. |
michael@0 | 1553 | getService(AM_Ci.nsIHttpActivityDistributor); |
michael@0 | 1554 | observerService.addObserver({ |
michael@0 | 1555 | observeActivity: function(aChannel, aType, aSubtype, aTimestamp, aSizeData, |
michael@0 | 1556 | aStringData) { |
michael@0 | 1557 | aChannel.QueryInterface(AM_Ci.nsIChannel); |
michael@0 | 1558 | // Wait for the final event for the redirected URL |
michael@0 | 1559 | if (aChannel.URI.spec != "http://localhost:4444/addons/test_install1.xpi" || |
michael@0 | 1560 | aType != AM_Ci.nsIHttpActivityObserver.ACTIVITY_TYPE_HTTP_TRANSACTION || |
michael@0 | 1561 | aSubtype != AM_Ci.nsIHttpActivityObserver.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE) |
michael@0 | 1562 | return; |
michael@0 | 1563 | |
michael@0 | 1564 | // Request should have been cancelled |
michael@0 | 1565 | do_check_eq(aChannel.status, Components.results.NS_BINDING_ABORTED); |
michael@0 | 1566 | |
michael@0 | 1567 | observerService.removeObserver(this); |
michael@0 | 1568 | |
michael@0 | 1569 | run_test_27(); |
michael@0 | 1570 | } |
michael@0 | 1571 | }); |
michael@0 | 1572 | |
michael@0 | 1573 | let url = "http://localhost:4444/redirect?/addons/test_install1.xpi"; |
michael@0 | 1574 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1575 | aInstall.addListener({ |
michael@0 | 1576 | onDownloadProgress: function(aInstall) { |
michael@0 | 1577 | aInstall.cancel(); |
michael@0 | 1578 | } |
michael@0 | 1579 | }); |
michael@0 | 1580 | |
michael@0 | 1581 | aInstall.install(); |
michael@0 | 1582 | }, "application/x-xpinstall"); |
michael@0 | 1583 | } |
michael@0 | 1584 | |
michael@0 | 1585 | |
michael@0 | 1586 | // Tests that an install can be restarted during onDownloadCancelled after being |
michael@0 | 1587 | // cancelled in mid-download |
michael@0 | 1588 | function run_test_27() { |
michael@0 | 1589 | prepare_test({ }, [ |
michael@0 | 1590 | "onNewInstall" |
michael@0 | 1591 | ]); |
michael@0 | 1592 | |
michael@0 | 1593 | let url = "http://localhost:4444/addons/test_install3.xpi"; |
michael@0 | 1594 | AddonManager.getInstallForURL(url, function(aInstall) { |
michael@0 | 1595 | ensure_test_completed(); |
michael@0 | 1596 | |
michael@0 | 1597 | do_check_neq(aInstall, null); |
michael@0 | 1598 | do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 1599 | |
michael@0 | 1600 | aInstall.addListener({ |
michael@0 | 1601 | onDownloadProgress: function() { |
michael@0 | 1602 | aInstall.removeListener(this); |
michael@0 | 1603 | aInstall.cancel(); |
michael@0 | 1604 | } |
michael@0 | 1605 | }); |
michael@0 | 1606 | |
michael@0 | 1607 | prepare_test({}, [ |
michael@0 | 1608 | "onDownloadStarted", |
michael@0 | 1609 | "onDownloadCancelled", |
michael@0 | 1610 | ], check_test_27); |
michael@0 | 1611 | aInstall.install(); |
michael@0 | 1612 | }, "application/x-xpinstall"); |
michael@0 | 1613 | } |
michael@0 | 1614 | |
michael@0 | 1615 | function check_test_27(aInstall) { |
michael@0 | 1616 | prepare_test({ |
michael@0 | 1617 | "addon3@tests.mozilla.org": [ |
michael@0 | 1618 | "onInstalling" |
michael@0 | 1619 | ] |
michael@0 | 1620 | }, [ |
michael@0 | 1621 | "onDownloadStarted", |
michael@0 | 1622 | "onDownloadEnded", |
michael@0 | 1623 | "onInstallStarted", |
michael@0 | 1624 | "onInstallEnded" |
michael@0 | 1625 | ], finish_test_27); |
michael@0 | 1626 | |
michael@0 | 1627 | aInstall.install(); |
michael@0 | 1628 | } |
michael@0 | 1629 | |
michael@0 | 1630 | function finish_test_27(aInstall) { |
michael@0 | 1631 | prepare_test({ |
michael@0 | 1632 | "addon3@tests.mozilla.org": [ |
michael@0 | 1633 | "onOperationCancelled" |
michael@0 | 1634 | ] |
michael@0 | 1635 | }, [ |
michael@0 | 1636 | "onInstallCancelled" |
michael@0 | 1637 | ]); |
michael@0 | 1638 | |
michael@0 | 1639 | aInstall.cancel(); |
michael@0 | 1640 | |
michael@0 | 1641 | ensure_test_completed(); |
michael@0 | 1642 | |
michael@0 | 1643 | end_test(); |
michael@0 | 1644 | } |