diff options
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_install.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_install.js | 190 |
1 files changed, 54 insertions, 136 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_install.js b/toolkit/mozapps/extensions/test/xpcshell/test_install.js index 60af3a9fd..16db604c5 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_install.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_install.js @@ -3,9 +3,14 @@ */ // This verifies that add-ons can be installed from XPI files -var Cc = Components.classes; -var Ci = Components.interfaces; -var Cu = Components.utils; +const Cc = Components.classes; +const Ci = Components.interfaces; +const Cu = Components.utils; + +// Maximum error in file modification times. Some file systems don't store +// modification times exactly. As long as we are closer than this then it +// still passes. +const MAX_TIME_DIFFERENCE = 3000; // install.rdf size, icon.png, icon64.png size const ADDON1_SIZE = 705 + 16 + 16; @@ -140,8 +145,6 @@ function check_test_1(installSyncGUID) { else { let iconFile = uri.QueryInterface(AM_Ci.nsIFileURL).file; do_check_true(iconFile.exists()); - // Make the iconFile predictably old. - iconFile.lastModifiedTime = Date.now() - MAKE_FILE_OLD_DIFFERENCE; } // Make the pending install have a sensible date @@ -186,23 +189,14 @@ function check_test_1(installSyncGUID) { do_check_true(a1.hasResource("install.rdf")); do_check_false(a1.hasResource("foo.bar")); - let uri2 = do_get_addon_root_uri(profileDir, "addon1@tests.mozilla.org"); - do_check_eq(a1.getResourceURI("install.rdf").spec, uri2 + "install.rdf"); - do_check_eq(a1.iconURL, uri2 + "icon.png"); - do_check_eq(a1.icon64URL, uri2 + "icon64.png"); - - // Ensure that extension bundle (or icon if unpacked) has updated - // lastModifiedDate. - let testURI = a1.getResourceURI(TEST_UNPACKED ? "icon.png" : ""); - let testFile = testURI.QueryInterface(Components.interfaces.nsIFileURL).file; - do_check_true(testFile.exists()); - difference = testFile.lastModifiedTime - Date.now(); - do_check_true(Math.abs(difference) < MAX_TIME_DIFFERENCE); + let uri = do_get_addon_root_uri(profileDir, "addon1@tests.mozilla.org"); + do_check_eq(a1.getResourceURI("install.rdf").spec, uri + "install.rdf"); + do_check_eq(a1.iconURL, uri + "icon.png"); + do_check_eq(a1.icon64URL, uri + "icon64.png"); a1.uninstall(); - let { id, version } = a1; restartManager(); - do_check_not_in_crash_annotation(id, version); + do_check_not_in_crash_annotation(a1.id, a1.version); do_execute_soon(run_test_2); })); @@ -233,7 +227,7 @@ function run_test_2() { ], check_test_2); install.addListener({ - onDownloadProgress: function() { + onDownloadProgress: function(install) { do_execute_soon(function() { Components.utils.forceGC(); }); @@ -387,8 +381,8 @@ function check_test_5(install) { do_check_eq(installs[0].addon, olda2.pendingUpgrade); restartManager(); - AddonManager.getInstallsByTypes(null, function(installs2) { - do_check_eq(installs2.length, 0); + AddonManager.getInstallsByTypes(null, function(installs) { + do_check_eq(installs.length, 0); AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { do_check_neq(a2, null); @@ -656,8 +650,6 @@ function run_test_11() { "onNewInstall", "onNewInstall", "onNewInstall", - "onNewInstall", - "onNewInstall", "onNewInstall" ]); @@ -665,22 +657,11 @@ function run_test_11() { ensure_test_completed(); do_check_neq(install, null); do_check_neq(install.linkedInstalls, null); - do_check_eq(install.linkedInstalls.length, 5); + do_check_eq(install.linkedInstalls.length, 3); // Might be in any order so sort them based on ID let installs = [install].concat(install.linkedInstalls); installs.sort(function(a, b) { - if (a.state != b.state) { - if (a.state == AddonManager.STATE_DOWNLOAD_FAILED) - return 1; - else if (b.state == AddonManager.STATE_DOWNLOAD_FAILED) - return -1; - } - - // Don't care what order the failed installs show up in - if (a.state == AddonManager.STATE_DOWNLOAD_FAILED) - return 0; - if (a.addon.id < b.addon.id) return -1; if (a.addon.id > b.addon.id) @@ -728,12 +709,6 @@ function run_test_11() { do_check_true(hasFlag(installs[3].addon.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_INSTALL)); - do_check_eq(installs[4].state, AddonManager.STATE_DOWNLOAD_FAILED); - do_check_eq(installs[4].error, AddonManager.ERROR_CORRUPT_FILE); - - do_check_eq(installs[5].state, AddonManager.STATE_DOWNLOAD_FAILED); - do_check_eq(installs[5].error, AddonManager.ERROR_CORRUPT_FILE); - AddonManager.getAllInstalls(function(aInstalls) { do_check_eq(aInstalls.length, 4); @@ -840,8 +815,6 @@ function run_test_12() { "onNewInstall", "onNewInstall", "onNewInstall", - "onNewInstall", - "onNewInstall", "onDownloadEnded" ], "addon4@tests.mozilla.org": [ @@ -866,22 +839,11 @@ function run_test_12() { } function check_test_12() { - do_check_eq(gInstall.linkedInstalls.length, 5); + do_check_eq(gInstall.linkedInstalls.length, 3); // Might be in any order so sort them based on ID let installs = [gInstall].concat(gInstall.linkedInstalls); installs.sort(function(a, b) { - if (a.state != b.state) { - if (a.state == AddonManager.STATE_DOWNLOAD_FAILED) - return 1; - else if (b.state == AddonManager.STATE_DOWNLOAD_FAILED) - return -1; - } - - // Don't care what order the failed installs show up in - if (a.state == AddonManager.STATE_DOWNLOAD_FAILED) - return 0; - if (a.addon.id < b.addon.id) return -1; if (a.addon.id > b.addon.id) @@ -921,12 +883,6 @@ function check_test_12() { do_check_eq(installs[3].name, "Multi Test 4"); do_check_eq(installs[3].state, AddonManager.STATE_INSTALLED); - do_check_eq(installs[4].state, AddonManager.STATE_DOWNLOAD_FAILED); - do_check_eq(installs[4].error, AddonManager.ERROR_CORRUPT_FILE); - - do_check_eq(installs[5].state, AddonManager.STATE_DOWNLOAD_FAILED); - do_check_eq(installs[5].error, AddonManager.ERROR_CORRUPT_FILE); - restartManager(); AddonManager.getAddonsByIDs(["addon4@tests.mozilla.org", @@ -1148,26 +1104,26 @@ function run_test_16() { do_check_true(a2.userDisabled); do_check_false(a2.isActive); - let url_2 = "http://localhost:" + gPort + "/addons/test_install2_2.xpi"; - AddonManager.getInstallForURL(url_2, function(aInstall_2) { - aInstall_2.addListener({ + let url = "http://localhost:" + gPort + "/addons/test_install2_2.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ onInstallEnded: function() { do_execute_soon(function install2_2_ended() { - do_check_true(aInstall_2.addon.userDisabled); + do_check_true(aInstall.addon.userDisabled); restartManager(); - AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2_2) { - do_check_true(a2_2.userDisabled); - do_check_false(a2_2.isActive); + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_true(a2.userDisabled); + do_check_false(a2.isActive); - a2_2.uninstall(); + a2.uninstall(); do_execute_soon(run_test_17); }); }); } }); - aInstall_2.install(); + aInstall.install(); }, "application/x-xpinstall"); }); }); @@ -1194,29 +1150,29 @@ function run_test_17() { do_check_false(a2.userDisabled); do_check_true(a2.isActive); - let url_2 = "http://localhost:" + gPort + "/addons/test_install2_2.xpi"; - AddonManager.getInstallForURL(url_2, function(aInstall_2) { - aInstall_2.addListener({ + let url = "http://localhost:" + gPort + "/addons/test_install2_2.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ onInstallStarted: function() { - do_check_false(aInstall_2.addon.userDisabled); - aInstall_2.addon.userDisabled = true; + do_check_false(aInstall.addon.userDisabled); + aInstall.addon.userDisabled = true; }, onInstallEnded: function() { do_execute_soon(function install2_2_ended2() { restartManager(); - AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2_2) { - do_check_true(a2_2.userDisabled); - do_check_false(a2_2.isActive); + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_true(a2.userDisabled); + do_check_false(a2.isActive); - a2_2.uninstall(); + a2.uninstall(); do_execute_soon(run_test_18); }); }); } }); - aInstall_2.install(); + aInstall.install(); }, "application/x-xpinstall"); }); }); @@ -1246,29 +1202,29 @@ function run_test_18() { do_check_true(a2.userDisabled); do_check_false(a2.isActive); - let url_2 = "http://localhost:" + gPort + "/addons/test_install2_2.xpi"; - AddonManager.getInstallForURL(url_2, function(aInstall_2) { - aInstall_2.addListener({ + let url = "http://localhost:" + gPort + "/addons/test_install2_2.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ onInstallStarted: function() { - do_check_true(aInstall_2.addon.userDisabled); - aInstall_2.addon.userDisabled = false; + do_check_true(aInstall.addon.userDisabled); + aInstall.addon.userDisabled = false; }, onInstallEnded: function() { do_execute_soon(function install_2_2_ended3() { restartManager(); - AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2_2) { - do_check_false(a2_2.userDisabled); - do_check_true(a2_2.isActive); + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_false(a2.userDisabled); + do_check_true(a2.isActive); - a2_2.uninstall(); + a2.uninstall(); do_execute_soon(run_test_18_1); }); }); } }); - aInstall_2.install(); + aInstall.install(); }, "application/x-xpinstall"); }); }); @@ -1292,7 +1248,7 @@ function run_test_18_1() { let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi"; AddonManager.getInstallForURL(url, function(aInstall) { aInstall.addListener({ - onInstallEnded: function(unused, aAddon) { + onInstallEnded: function(aInstall, aAddon) { do_execute_soon(function test18_1_install_ended() { do_check_neq(aAddon.fullDescription, "Repository description"); @@ -1320,7 +1276,7 @@ function run_test_19() { let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi"; AddonManager.getInstallForURL(url, function(aInstall) { aInstall.addListener({ - onInstallEnded: function(unused, aAddon) { + onInstallEnded: function(aInstall, aAddon) { do_execute_soon(function test19_install_ended() { do_check_eq(aAddon.fullDescription, "Repository description"); @@ -1346,7 +1302,7 @@ function run_test_20() { let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi"; AddonManager.getInstallForURL(url, function(aInstall) { aInstall.addListener({ - onInstallEnded: function(unused, aAddon) { + onInstallEnded: function(aInstall, aAddon) { do_execute_soon(function test20_install_ended() { do_check_eq(aAddon.fullDescription, "Repository description"); @@ -1633,8 +1589,8 @@ function run_test_26() { let url = "http://localhost:" + gPort + "/redirect?/addons/test_install1.xpi"; AddonManager.getInstallForURL(url, function(aInstall) { aInstall.addListener({ - onDownloadProgress: function(aDownloadProgressInstall) { - aDownloadProgressInstall.cancel(); + onDownloadProgress: function(aInstall) { + aInstall.cancel(); } }); @@ -1791,7 +1747,7 @@ function run_test_29() { } function check_test_29(install) { - // ensure_test_completed(); + //ensure_test_completed(); do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); do_check_neq(install.addon, null); do_check_false(install.addon.isCompatible); @@ -1799,45 +1755,7 @@ function check_test_29(install) { prepare_test({}, [ "onDownloadCancelled" - ], run_test_30); + ], do_test_finished); install.cancel(); return false; } - -// Tests that a multi-package XPI with no add-ons inside shows up as a -// corrupt file -function run_test_30() { - prepare_test({ }, [ - "onNewInstall" - ]); - - AddonManager.getInstallForFile(do_get_addon("test_install7"), function(install) { - ensure_test_completed(); - - do_check_neq(install, null); - do_check_eq(install.state, AddonManager.STATE_DOWNLOAD_FAILED); - do_check_eq(install.error, AddonManager.ERROR_CORRUPT_FILE); - do_check_eq(install.linkedInstalls, null); - - run_test_31(); - }); -} - -// Tests that a multi-package XPI with no valid add-ons inside shows up as a -// corrupt file -function run_test_31() { - prepare_test({ }, [ - "onNewInstall" - ]); - - AddonManager.getInstallForFile(do_get_addon("test_install8"), function(install) { - ensure_test_completed(); - - do_check_neq(install, null); - do_check_eq(install.state, AddonManager.STATE_DOWNLOAD_FAILED); - do_check_eq(install.error, AddonManager.ERROR_CORRUPT_FILE); - do_check_eq(install.linkedInstalls, null); - - end_test(); - }); -} |