Bug 570173: Errors from findUpdates aren't passed out to the listener correctly. r=robstrong

This commit is contained in:
Dave Townsend 2010-06-10 11:11:16 -07:00
Родитель a125cec320
Коммит 48a647c429
5 изменённых файлов: 145 добавлений и 24 удалений

Просмотреть файл

@ -810,6 +810,20 @@ var AddonManager = {
// The downloaded file seems to be corrupted in some way.
ERROR_CORRUPT_FILE: -3,
// These must be kept in sync with AddonUpdateChecker.
// No error was encountered.
UPDATE_STATUS_NO_ERROR: 0,
// The update check timed out
UPDATE_STATUS_TIMEOUT: -1,
// There was an error while downloading the update information.
UPDATE_STATUS_DOWNLOAD_ERROR: -2,
// The update information was malformed in some way.
UPDATE_STATUS_PARSE_ERROR: -3,
// The update information was not in any known format.
UPDATE_STATUS_UNKNOWN_FORMAT: -4,
// The update information was not correctly signed or there was an SSL error.
UPDATE_STATUS_SECURITY_ERROR: -5,
// Constants to indicate why an update check is being performed
// Update check has been requested by the user.
UPDATE_WHEN_USER_REQUESTED: 1,

Просмотреть файл

@ -467,6 +467,13 @@ UpdateParser.prototype = {
return;
}
let channel = request.channel;
if (channel instanceof Ci.nsIHttpChannel && !channel.requestSucceeded) {
WARN("Request failed: " + channel.responseStatus + ": " + channel.responseStatusText);
this.notifyError(AddonUpdateChecker.ERROR_DOWNLOAD_ERROR);
return;
}
let xml = request.responseXML;
if (!xml || xml.documentElement.namespaceURI == XMLURI_PARSE_ERROR) {
WARN("Update manifest was not valid XML");
@ -502,7 +509,24 @@ UpdateParser.prototype = {
this.timer.cancel();
this.timer = null;
WARN("Request failed: " + this.request.status);
if (!Components.isSuccessCode(this.request.status)) {
WARN("Request failed: " + request.status);
}
else if (this.request.channel instanceof Ci.nsIHttpChannel) {
try {
if (this.request.channel.requestSucceeded) {
WARN("Request failed: " + this.request.channel.responseStatus + ": " +
this.request.channel.responseStatusText);
}
}
catch (e) {
WARN("HTTP Request failed for an unknown reason");
}
}
else {
WARN("Request failed for an unknown reason");
}
this.request = null;
this.notifyError(AddonUpdateChecker.ERROR_DOWNLOAD_ERROR);
@ -558,10 +582,16 @@ function matchesVersions(aUpdate, aAppVersion, aPlatformVersion) {
}
var AddonUpdateChecker = {
// These must be kept in sync with AddonManager
// The update check timed out
ERROR_TIMEOUT: -1,
// There was an error while downloading the update information.
ERROR_DOWNLOAD_ERROR: -2,
// The update information was malformed in some way.
ERROR_PARSE_ERROR: -3,
// The update information was not in any known format.
ERROR_UNKNOWN_FORMAT: -4,
// The update information was not correctly signed or there was an SSL error.
ERROR_SECURITY_ERROR: -5,
/**

Просмотреть файл

@ -4424,19 +4424,24 @@ UpdateChecker.prototype = {
AddonInstall.createUpdate(function(install) {
self.listener.onUpdateAvailable(createWrapper(self.addon),
install.wrapper);
if ("onUpdateFinished" in self.listener)
self.listener.onUpdateFinished(createWrapper(self.addon));
if ("onUpdateFinished" in self.listener) {
self.listener.onUpdateFinished(createWrapper(self.addon),
AddonManager.UPDATE_STATUS_NO_ERROR);
}
}, this.addon, update);
}
else if ("onUpdateFinished" in this.listener) {
this.listener.onUpdateFinished(createWrapper(this.addon));
this.listener.onUpdateFinished(createWrapper(this.addon),
AddonManager.UPDATE_STATUS_NO_ERROR);
}
}
else {
if ("onNoUpdateAvailable" in this.listener)
this.listener.onNoUpdateAvailable(createWrapper(this.addon));
if ("onUpdateFinished" in this.listener)
this.listener.onUpdateFinished(createWrapper(this.addon));
if ("onUpdateFinished" in this.listener) {
this.listener.onUpdateFinished(createWrapper(this.addon),
AddonManager.UPDATE_STATUS_NO_ERROR);
}
}
},
@ -4447,10 +4452,12 @@ UpdateChecker.prototype = {
* An error status
*/
onUpdateCheckError: function UC_onUpdateCheckError(aError) {
if ("onNoCompatibilityUpdateAvailable" in this.listener)
this.listener.onNoCompatibilityUpdateAvailable(createWrapper(this.addon));
if ("onNoUpdateAvailable" in this.listener)
this.listener.onNoUpdateAvailable(createWrapper(this.addon), aError);
this.listener.onNoUpdateAvailable(createWrapper(this.addon));
if ("onUpdateFinished" in this.listener)
this.listener.onUpdateFinished(createWrapper(this.addon));
this.listener.onUpdateFinished(createWrapper(this.addon), aError);
}
};

Просмотреть файл

@ -105,27 +105,16 @@ function run_test()
AddonManager.getAddonByID("test@mozilla.org", function(item) {
// Initiate update
item.findUpdates({
onNoCompatibilityUpdateAvailable: function(addon) {
do_throw("Should not have seen no compatibility update");
onCompatibilityUpdateAvailable: function(addon) {
do_throw("Should not have seen a compatibility update");
},
onUpdateAvailable: function(addon, install) {
ensure_test_completed();
do_check_eq(addon, a1);
do_check_eq(install.name, addon.name);
do_check_eq(install.version, "2.0");
do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
do_check_eq(install.existingAddon, addon);
prepare_test({}, [
"onDownloadStarted",
"onDownloadEnded",
], check_test_1);
install.install();
do_throw("Should not have seen an available update");
},
onUpdateFinished: function(addon) {
onUpdateFinished: function(addon, error) {
do_check_eq(error, AddonManager.UPDATE_STATUS_DOWNLOAD_ERROR);
do_check_true(gSeenExpectedURL);
shutdownTest();
}

Просмотреть файл

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