From 8051ddded9fc07293fe12e838ae3c9460a021bc5 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Sat, 26 Jun 2010 16:03:25 -0700 Subject: [PATCH] Bug 567175: Bootstrapped add-ons with invalid target applications should not be started up. r=robstrong --- toolkit/mozapps/extensions/XPIProvider.jsm | 2 + .../addons/test_bootstrap1_3/bootstrap.js | 19 ++++ .../test/addons/test_bootstrap1_3/install.rdf | 24 ++++ .../test/xpcshell/test_bootstrap.js | 107 ++++++++++++++++++ 4 files changed, 152 insertions(+) create mode 100644 toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/bootstrap.js create mode 100644 toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/install.rdf diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index a17fb07f600..ef3fdb0e595 100644 --- a/toolkit/mozapps/extensions/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/XPIProvider.jsm @@ -1479,6 +1479,8 @@ var XPIProvider = { XPIProvider.callBootstrapMethod(newAddon.id, newAddon.version, dir, "install", BOOTSTRAP_REASONS.ADDON_INSTALL); + if (!newAddon.active) + XPIProvider.unloadBootstrapScope(newAddon.id); } return false; diff --git a/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/bootstrap.js b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/bootstrap.js new file mode 100644 index 00000000000..0a44aa0b978 --- /dev/null +++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/bootstrap.js @@ -0,0 +1,19 @@ +Components.utils.import("resource://gre/modules/Services.jsm"); + +function install(data, reason) { + Services.prefs.setIntPref("bootstraptest.installed_version", 3); +} + +function startup(data, reason) { + Services.prefs.setIntPref("bootstraptest.active_version", 3); + Services.prefs.setIntPref("bootstraptest.startup_reason", reason); +} + +function shutdown(data, reason) { + Services.prefs.setIntPref("bootstraptest.active_version", 0); + Services.prefs.setIntPref("bootstraptest.shutdown_reason", reason); +} + +function uninstall(data, reason) { + Services.prefs.setIntPref("bootstraptest.installed_version", 0); +} diff --git a/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/install.rdf b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/install.rdf new file mode 100644 index 00000000000..e9385cbb376 --- /dev/null +++ b/toolkit/mozapps/extensions/test/addons/test_bootstrap1_3/install.rdf @@ -0,0 +1,24 @@ + + + + + + bootstrap1@tests.mozilla.org + 3.0 + true + + + Test Bootstrap 1 + Test Description + + + + undefined + 1 + 1 + + + + + diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js index 4d16e9f0765..1ab04358718 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js @@ -521,6 +521,113 @@ function run_test_12() { do_check_eq(getStartupReason(), APP_STARTUP); do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); + b1.uninstall(); + restartManager(0); + + run_test_13(); + }); +} + + +// Tests that installing a bootstrapped extension with an invalid application +// entry doesn't call it's startup method +function run_test_13() { + prepare_test({ }, [ + "onNewInstall" + ]); + + AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_3"), function(install) { + ensure_test_completed(); + + do_check_neq(install, null); + do_check_eq(install.type, "extension"); + do_check_eq(install.version, "3.0"); + do_check_eq(install.name, "Test Bootstrap 1"); + do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); + do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0"); + + prepare_test({ + "bootstrap1@tests.mozilla.org": [ + ["onInstalling", false], + "onInstalled" + ] + }, [ + "onInstallStarted", + "onInstallEnded", + ], check_test_13); + install.install(); + }); +} + +function check_test_13() { + AddonManager.getAllInstalls(function(installs) { + // There should be no active installs now since the install completed and + // doesn't require a restart. + do_check_eq(installs.length, 0); + + AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { + do_check_neq(b1, null); + do_check_eq(b1.version, "3.0"); + do_check_true(b1.appDisabled); + do_check_false(b1.userDisabled); + do_check_false(b1.isActive); + do_check_eq(getInstalledVersion(), 3); // We call install even for disabled add-ons + do_check_eq(getActiveVersion(), 0); // Should not have called startup though + do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0"); + + restartManager(); + + AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { + do_check_neq(b1, null); + do_check_eq(b1.version, "3.0"); + do_check_true(b1.appDisabled); + do_check_false(b1.userDisabled); + do_check_false(b1.isActive); + do_check_eq(getInstalledVersion(), 3); // We call install even for disabled add-ons + do_check_eq(getActiveVersion(), 0); // Should not have called startup though + do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0"); + + b1.uninstall(); + restartManager(0); + + run_test_14(); + }); + }); + }); +} + +// Tests that a bootstrapped extension with an invalid target application entry +// does not get loaded when detected during startup +function run_test_14() { + shutdownManager(); + + let dir = profileDir.clone(); + dir.append("bootstrap1@tests.mozilla.org"); + dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); + let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"]. + createInstance(AM_Ci.nsIZipReader); + zip.open(do_get_addon("test_bootstrap1_3")); + dir.append("install.rdf"); + zip.extract("install.rdf", dir); + dir = dir.parent; + dir.append("bootstrap.js"); + zip.extract("bootstrap.js", dir); + zip.close(); + + startupManager(0, false); + + AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { + do_check_neq(b1, null); + do_check_eq(b1.version, "3.0"); + do_check_true(b1.appDisabled); + do_check_false(b1.userDisabled); + do_check_false(b1.isActive); + do_check_eq(getInstalledVersion(), 3); // We call install even for disabled add-ons + do_check_eq(getActiveVersion(), 0); // Should not have called startup though + do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0"); + + b1.uninstall(); + do_test_finished(); }); }