michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // This verifies that add-on update check failures are propogated correctly michael@0: michael@0: // The test extension uses an insecure update url. michael@0: Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var testserver; michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: function run_test() { michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: michael@0: // Create and configure the HTTP server. michael@0: testserver = new HttpServer(); michael@0: testserver.registerDirectory("/data/", do_get_file("data")); michael@0: testserver.registerDirectory("/addons/", do_get_file("addons")); michael@0: testserver.start(-1); michael@0: gPort = testserver.identity.primaryPort; michael@0: michael@0: writeInstallRDFForExtension({ michael@0: id: "addon1@tests.mozilla.org", michael@0: version: "1.0", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_missing.rdf", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }], michael@0: name: "Test Addon 1", michael@0: }, profileDir); michael@0: michael@0: startupManager(); michael@0: michael@0: do_test_pending(); michael@0: run_test_1(); michael@0: } michael@0: michael@0: function end_test() { michael@0: testserver.stop(do_test_finished); michael@0: } michael@0: michael@0: // Verify that an update check returns the correct errors. michael@0: function run_test_1() { michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { michael@0: do_check_neq(a1, null); michael@0: do_check_eq(a1.version, "1.0"); michael@0: michael@0: let sawCompat = false; michael@0: let sawUpdate = false; michael@0: a1.findUpdates({ michael@0: onNoCompatibilityUpdateAvailable: function(addon) { michael@0: sawCompat = true; michael@0: }, michael@0: michael@0: onCompatibilityUpdateAvailable: function(addon) { michael@0: do_throw("Should not have seen a compatibility update"); michael@0: }, michael@0: michael@0: onNoUpdateAvailable: function(addon) { michael@0: sawUpdate = true; michael@0: }, michael@0: michael@0: onUpdateAvailable: function(addon, install) { michael@0: do_throw("Should not have seen an update"); michael@0: }, michael@0: michael@0: onUpdateFinished: function(addon, error) { michael@0: do_check_true(sawCompat); michael@0: do_check_true(sawUpdate); michael@0: do_check_eq(error, AddonManager.UPDATE_STATUS_DOWNLOAD_ERROR); michael@0: end_test(); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_USER_REQUESTED); michael@0: }); michael@0: }