From 50fbaf5ecd204011b3614e6d87d381e33935fe1f Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Tue, 12 Oct 2010 12:15:40 -0700 Subject: [PATCH] Bug 596336: Allow modifying the userDisabled property of new installs. r=robstrong, a=blocks-betaN --- toolkit/mozapps/extensions/XPIProvider.jsm | 7 +- .../test/xpcshell/test_bootstrap.js | 73 ++++++++- .../extensions/test/xpcshell/test_install.js | 146 +++++++++++++++++- 3 files changed, 223 insertions(+), 3 deletions(-) diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index cd8224c2b5c..d1c36eee7db 100644 --- a/toolkit/mozapps/extensions/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/XPIProvider.jsm @@ -1537,6 +1537,8 @@ var XPIProvider = { newAddon = loadManifestFromZipFile(file); else newAddon = loadManifestFromDir(file); + // Carry over the userDisabled setting for add-ons that just appeared + newAddon.userDisabled = aOldAddon.userDisabled; } // The ID in the manifest that was loaded must match the ID of the old @@ -3936,7 +3938,6 @@ var XPIDatabase = { // Any errors in here should rollback the transaction try { this.removeAddonMetadata(aOldAddon); - aNewAddon.userDisabled = aOldAddon.userDisabled; aNewAddon.installDate = aOldAddon.installDate; aNewAddon.applyBackgroundUpdates = aOldAddon.applyBackgroundUpdates; this.addAddonMetadata(aNewAddon, aDescriptor); @@ -4218,6 +4219,8 @@ function AddonInstall(aCallback, aInstallLocation, aUrl, aHash, aName, aType, this.loadManifest(function() { XPIDatabase.getVisibleAddonForID(self.addon.id, function(aAddon) { self.existingAddon = aAddon; + if (aAddon) + self.addon.userDisabled = aAddon.userDisabled; self.addon.updateDate = Date.now(); self.addon.installDate = aAddon ? aAddon.installDate : self.addon.updateDate; @@ -4871,6 +4874,8 @@ AddonInstall.prototype = { let self = this; XPIDatabase.getVisibleAddonForID(this.addon.id, function(aAddon) { self.existingAddon = aAddon; + if (aAddon) + self.addon.userDisabled = aAddon.userDisabled; self.addon.updateDate = Date.now(); self.addon.installDate = aAddon ? aAddon.installDate : self.addon.updateDate; self.state = AddonManager.STATE_DOWNLOADED; diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js index ff5e74249e4..464c75fd41a 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js @@ -637,8 +637,79 @@ function run_test_14() { }); } -// Tests that bootstrapped extensions don't get loaded when in safe mode +// Tests that upgrading a disabled bootstrapped extension still calls uninstall +// and install but doesn't startup the new version function run_test_15() { + installAllFiles([do_get_addon("test_bootstrap1_1")], function() { + AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { + do_check_neq(b1, null); + do_check_eq(b1.version, "1.0"); + do_check_false(b1.appDisabled); + do_check_false(b1.userDisabled); + do_check_true(b1.isActive); + do_check_eq(getInstalledVersion(), 1); + do_check_eq(getActiveVersion(), 1); + + b1.userDisabled = true; + do_check_false(b1.isActive); + do_check_eq(getInstalledVersion(), 1); + do_check_eq(getActiveVersion(), 0); + + prepare_test({ }, [ + "onNewInstall" + ]); + + AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_2"), function(install) { + ensure_test_completed(); + + do_check_neq(install, null); + do_check_true(install.addon.userDisabled); + + prepare_test({ + "bootstrap1@tests.mozilla.org": [ + ["onInstalling", false], + "onInstalled" + ] + }, [ + "onInstallStarted", + "onInstallEnded", + ], check_test_15); + install.install(); + }); + }); + }); +} + +function check_test_15() { + AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { + do_check_neq(b1, null); + do_check_eq(b1.version, "2.0"); + do_check_false(b1.appDisabled); + do_check_true(b1.userDisabled); + do_check_false(b1.isActive); + do_check_eq(getInstalledVersion(), 2); + do_check_eq(getActiveVersion(), 0); + + restartManager(); + + AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { + do_check_neq(b1, null); + do_check_eq(b1.version, "2.0"); + do_check_false(b1.appDisabled); + do_check_true(b1.userDisabled); + do_check_false(b1.isActive); + do_check_eq(getInstalledVersion(), 2); + do_check_eq(getActiveVersion(), 0); + + b1.uninstall(); + + run_test_16(); + }); + }); +} + +// Tests that bootstrapped extensions don't get loaded when in safe mode +function run_test_16() { installAllFiles([do_get_addon("test_bootstrap1_1")], function() { AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { // Should have installed and started diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_install.js b/toolkit/mozapps/extensions/test/xpcshell/test_install.js index 8739bbbf8c4..1e5080030eb 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_install.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_install.js @@ -947,6 +947,10 @@ function check_test_13(install) { AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { do_check_eq(a2.version, "2.0"); + a2.uninstall(); + + restartManager(); + run_test_14(); }); }); @@ -1035,5 +1039,145 @@ function check_test_15(install) { }); // Allow the listener to return to see if it starts installing - do_execute_soon(end_test); + do_execute_soon(run_test_16); +} + +// Verify that the userDisabled value carries over to the upgrade by default +function run_test_16() { + restartManager(); + + let url = "http://localhost:4444/addons/test_install2_1.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ + onInstallStarted: function() { + do_check_false(aInstall.addon.userDisabled); + aInstall.addon.userDisabled = true; + }, + + onInstallEnded: function() { + restartManager(); + + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_true(a2.userDisabled); + do_check_false(a2.isActive); + + let url = "http://localhost:4444/addons/test_install2_2.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ + onInstallEnded: function() { + do_check_true(aInstall.addon.userDisabled); + + restartManager(); + + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_true(a2.userDisabled); + do_check_false(a2.isActive); + + a2.uninstall(); + restartManager(); + + run_test_17(); + }); + } + }); + aInstall.install(); + }, "application/x-xpinstall"); + }); + } + }); + aInstall.install(); + }, "application/x-xpinstall"); +} + +// Verify that changing the userDisabled value before onInstallEnded works +function run_test_17() { + let url = "http://localhost:4444/addons/test_install2_1.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ + onInstallEnded: function() { + do_check_false(aInstall.addon.userDisabled); + + restartManager(); + + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_false(a2.userDisabled); + do_check_true(a2.isActive); + + let url = "http://localhost:4444/addons/test_install2_2.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ + onInstallStarted: function() { + do_check_false(aInstall.addon.userDisabled); + aInstall.addon.userDisabled = true; + }, + + onInstallEnded: function() { + restartManager(); + + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_true(a2.userDisabled); + do_check_false(a2.isActive); + + a2.uninstall(); + restartManager(); + + run_test_18(); + }); + } + }); + aInstall.install(); + }, "application/x-xpinstall"); + }); + } + }); + aInstall.install(); + }, "application/x-xpinstall"); +} + +// Verify that changing the userDisabled value before onInstallEnded works +function run_test_18() { + let url = "http://localhost:4444/addons/test_install2_1.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ + onInstallStarted: function() { + do_check_false(aInstall.addon.userDisabled); + aInstall.addon.userDisabled = true; + }, + + onInstallEnded: function() { + restartManager(); + + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_true(a2.userDisabled); + do_check_false(a2.isActive); + + let url = "http://localhost:4444/addons/test_install2_2.xpi"; + AddonManager.getInstallForURL(url, function(aInstall) { + aInstall.addListener({ + onInstallStarted: function() { + do_check_true(aInstall.addon.userDisabled); + aInstall.addon.userDisabled = false; + }, + + onInstallEnded: function() { + restartManager(); + + AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { + do_check_false(a2.userDisabled); + do_check_true(a2.isActive); + + a2.uninstall(); + restartManager(); + + end_test(); + }); + } + }); + aInstall.install(); + }, "application/x-xpinstall"); + }); + } + }); + aInstall.install(); + }, "application/x-xpinstall"); }