зеркало из https://github.com/mozilla/gecko-dev.git
Bug 553022: Remove cancelled and failed installs from the active installs list. r=robstrong
This commit is contained in:
Родитель
3c42041548
Коммит
1234610a27
|
@ -1644,6 +1644,10 @@ var XPIProvider = {
|
|||
}, file);
|
||||
},
|
||||
|
||||
removeActiveInstall: function XPI_removeActiveInstall(install) {
|
||||
this.installs = this.installs.filter(function(i) i != install);
|
||||
},
|
||||
|
||||
/**
|
||||
* Called to get an Addon with a particular ID.
|
||||
*
|
||||
|
@ -3353,6 +3357,7 @@ AddonInstall.prototype = {
|
|||
case AddonManager.STATE_DOWNLOADED:
|
||||
LOG("Cancelling download of " + this.sourceURL.spec);
|
||||
this.state = AddonManager.STATE_CANCELLED;
|
||||
XPIProvider.removeActiveInstall(this);
|
||||
AddonManagerPrivate.callInstallListeners("onDownloadCancelled",
|
||||
this.listeners, this.wrapper);
|
||||
if (this.file && !(this.sourceURL instanceof Ci.nsIFileURL))
|
||||
|
@ -3369,6 +3374,7 @@ AddonInstall.prototype = {
|
|||
if (stagedJSON.exists())
|
||||
stagedJSON.remove(true);
|
||||
this.state = AddonManager.STATE_CANCELLED;
|
||||
XPIProvider.removeActiveInstall(this);
|
||||
AddonManagerPrivate.callInstallListeners("onInstallCancelled",
|
||||
this.listeners, this.wrapper);
|
||||
break;
|
||||
|
@ -3472,6 +3478,7 @@ AddonInstall.prototype = {
|
|||
if (!AddonManagerPrivate.callInstallListeners("onDownloadStarted",
|
||||
this.listeners, this.wrapper)) {
|
||||
this.state = AddonManager.STATE_CANCELLED;
|
||||
XPIProvider.removeActiveInstall(this);
|
||||
AddonManagerPrivate.callInstallListeners("onDownloadCancelled",
|
||||
this.listeners, this.wrapper)
|
||||
return;
|
||||
|
@ -3488,6 +3495,7 @@ AddonInstall.prototype = {
|
|||
catch (e) {
|
||||
WARN("Unknown hash algorithm " + alg);
|
||||
this.state = AddonManager.STATE_DOWNLOAD_FAILED;
|
||||
XPIProvider.removeActiveInstall(this);
|
||||
AddonManagerPrivate.callInstallListeners("onDownloadFailed",
|
||||
this.listeners, this.wrapper,
|
||||
AddonManager.ERROR_INCORRECT_HASH);
|
||||
|
@ -3528,6 +3536,7 @@ AddonInstall.prototype = {
|
|||
catch (e) {
|
||||
WARN("Failed to start download: " + e);
|
||||
this.state = AddonManager.STATE_DOWNLOAD_FAILED;
|
||||
XPIProvider.removeActiveInstall(this);
|
||||
AddonManagerPrivate.callInstallListeners("onDownloadFailed",
|
||||
this.listeners, this.wrapper,
|
||||
AddonManager.ERROR_NETWORK_FAILURE);
|
||||
|
@ -3664,6 +3673,7 @@ AddonInstall.prototype = {
|
|||
downloadFailed: function(reason, error) {
|
||||
WARN("Download failed: " + error + "\n");
|
||||
this.state = AddonManager.STATE_DOWNLOAD_FAILED;
|
||||
XPIProvider.removeActiveInstall(this);
|
||||
AddonManagerPrivate.callInstallListeners("onDownloadFailed", this.listeners,
|
||||
this.wrapper, reason);
|
||||
this.file.remove(true);
|
||||
|
@ -3695,6 +3705,7 @@ AddonInstall.prototype = {
|
|||
if (!AddonManagerPrivate.callInstallListeners("onInstallStarted",
|
||||
this.listeners, this.wrapper)) {
|
||||
this.state = AddonManager.STATE_DOWNLOADED;
|
||||
XPIProvider.removeActiveInstall(this);
|
||||
AddonManagerPrivate.callInstallListeners("onInstallCancelled",
|
||||
this.listeners, this.wrapper)
|
||||
return;
|
||||
|
@ -3830,6 +3841,7 @@ AddonInstall.prototype = {
|
|||
if (stagedAddon.exists())
|
||||
stagedAddon.remove(true);
|
||||
this.state = AddonManager.STATE_INSTALL_FAILED;
|
||||
XPIProvider.removeActiveInstall(this);
|
||||
AddonManagerPrivate.callInstallListeners("onInstallFailed",
|
||||
this.listeners,
|
||||
this.wrapper, e);
|
||||
|
|
|
@ -453,7 +453,6 @@ const InstallListener = {
|
|||
onDownloadEnded: function(install) {
|
||||
do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
|
||||
do_check_eq("onDownloadEnded", gExpectedInstalls.shift());
|
||||
// gNext should determine whether installation continues
|
||||
return check_test_completed(arguments);
|
||||
},
|
||||
|
||||
|
@ -463,6 +462,12 @@ const InstallListener = {
|
|||
return check_test_completed(arguments);
|
||||
},
|
||||
|
||||
onDownloadCancelled: function(install) {
|
||||
do_check_eq(install.state, AddonManager.STATE_CANCELLED);
|
||||
do_check_eq("onDownloadCancelled", gExpectedInstalls.shift());
|
||||
return check_test_completed(arguments);
|
||||
},
|
||||
|
||||
onInstallStarted: function(install) {
|
||||
do_check_eq(install.state, AddonManager.STATE_INSTALLING);
|
||||
do_check_eq("onInstallStarted", gExpectedInstalls.shift());
|
||||
|
@ -481,6 +486,12 @@ const InstallListener = {
|
|||
return check_test_completed(arguments);
|
||||
},
|
||||
|
||||
onInstallCancelled: function(install) {
|
||||
do_check_eq(install.state, AddonManager.STATE_CANCELLED);
|
||||
do_check_eq("onInstallCancelled", gExpectedInstalls.shift());
|
||||
return check_test_completed(arguments);
|
||||
},
|
||||
|
||||
onExternalInstall: function(addon, existingAddon, requiresRestart) {
|
||||
do_check_eq("onExternalInstall", gExpectedInstalls.shift());
|
||||
do_check_false(requiresRestart);
|
||||
|
|
|
@ -441,6 +441,101 @@ function check_test_8() {
|
|||
a3.uninstall();
|
||||
restartManager(0);
|
||||
|
||||
run_test_9();
|
||||
});
|
||||
}
|
||||
|
||||
// Test that after cancelling a download it is removed from the active installs
|
||||
function run_test_9() {
|
||||
prepare_test({ }, [
|
||||
"onNewInstall"
|
||||
]);
|
||||
|
||||
let url = "http://localhost:4444/addons/test_install3.xpi";
|
||||
AddonManager.getInstallForURL(url, function(install) {
|
||||
ensure_test_completed();
|
||||
|
||||
do_check_neq(install, null);
|
||||
do_check_eq(install.version, "1.0");
|
||||
do_check_eq(install.name, "Real Test 4");
|
||||
do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
|
||||
|
||||
AddonManager.getInstalls(null, function(activeInstalls) {
|
||||
do_check_eq(activeInstalls.length, 1);
|
||||
do_check_eq(activeInstalls[0], install);
|
||||
|
||||
prepare_test({}, [
|
||||
"onDownloadStarted",
|
||||
"onDownloadEnded",
|
||||
], check_test_9);
|
||||
install.install();
|
||||
});
|
||||
}, "application/x-xpinstall", null, "Real Test 4", null, "1.0");
|
||||
}
|
||||
|
||||
function check_test_9(install) {
|
||||
prepare_test({}, [
|
||||
"onDownloadCancelled"
|
||||
]);
|
||||
|
||||
install.cancel();
|
||||
|
||||
ensure_test_completed();
|
||||
|
||||
AddonManager.getInstalls(null, function(activeInstalls) {
|
||||
do_check_eq(activeInstalls.length, 0);
|
||||
|
||||
run_test_10();
|
||||
});
|
||||
}
|
||||
|
||||
// Tests that after cancelling a pending install it is removed from the active
|
||||
// installs
|
||||
function run_test_10() {
|
||||
prepare_test({ }, [
|
||||
"onNewInstall"
|
||||
]);
|
||||
|
||||
let url = "http://localhost:4444/addons/test_install3.xpi";
|
||||
AddonManager.getInstallForURL(url, function(install) {
|
||||
ensure_test_completed();
|
||||
|
||||
do_check_neq(install, null);
|
||||
do_check_eq(install.version, "1.0");
|
||||
do_check_eq(install.name, "Real Test 4");
|
||||
do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
|
||||
|
||||
AddonManager.getInstalls(null, function(activeInstalls) {
|
||||
do_check_eq(activeInstalls.length, 1);
|
||||
do_check_eq(activeInstalls[0], install);
|
||||
|
||||
prepare_test({
|
||||
"addon3@tests.mozilla.org": [
|
||||
"onInstalling"
|
||||
]
|
||||
}, [
|
||||
"onDownloadStarted",
|
||||
"onDownloadEnded",
|
||||
"onInstallStarted",
|
||||
"onInstallEnded"
|
||||
], check_test_10);
|
||||
install.install();
|
||||
});
|
||||
}, "application/x-xpinstall", null, "Real Test 4", null, "1.0");
|
||||
}
|
||||
|
||||
function check_test_10(install) {
|
||||
prepare_test({}, [
|
||||
"onInstallCancelled"
|
||||
]);
|
||||
|
||||
install.cancel();
|
||||
|
||||
ensure_test_completed();
|
||||
|
||||
AddonManager.getInstalls(null, function(activeInstalls) {
|
||||
do_check_eq(activeInstalls.length, 0);
|
||||
|
||||
end_test();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -180,6 +180,7 @@ function run_test_1() {
|
|||
|
||||
AddonManager.getAddonsByTypes(["extension"], function(extensionAddons) {
|
||||
do_check_eq(extensionAddons.length, 3);
|
||||
|
||||
run_test_2();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -417,10 +417,8 @@ function test_7_complete() {
|
|||
is(item.status, "Failed", "Should have been a failed install");
|
||||
|
||||
AddonManager.getInstalls(null, function(installs) {
|
||||
is(installs.length, 4, "Should be just one install");
|
||||
is(installs[3].state, AddonManager.STATE_DOWNLOAD_FAILED, "Should have failed to download");
|
||||
is(installs[3].addon.id, "bug435788_1@tests.mozilla.org", "Should have installed the extension");
|
||||
installs[3].cancel();
|
||||
is(installs.length, 1, "Should be one active installs");
|
||||
installs[0].cancel();
|
||||
|
||||
gPFS.document.documentElement.getButton("finish").click();
|
||||
});
|
||||
|
@ -473,7 +471,7 @@ function test_8_complete() {
|
|||
is(item.status, "Failed", "Should have not been a successful install");
|
||||
|
||||
AddonManager.getInstalls(null, function(installs) {
|
||||
is(installs.length, 5, "Should not be any installs");
|
||||
is(installs.length, 0, "Should not be any installs");
|
||||
|
||||
gPFS.document.documentElement.getButton("finish").click();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче