Bug 666437: Allow add-ons to install disabled in some install locations. r=robstrong

This commit is contained in:
Dave Townsend 2011-06-28 11:44:51 -07:00
parent 583c41b045
commit ce833caa75
3 changed files with 120 additions and 1 deletions

View File

@ -66,6 +66,7 @@ const PREF_EM_UPDATE_URL = "extensions.update.url";
const PREF_EM_ENABLED_ADDONS = "extensions.enabledAddons";
const PREF_EM_EXTENSION_FORMAT = "extensions.";
const PREF_EM_ENABLED_SCOPES = "extensions.enabledScopes";
const PREF_EM_AUTO_DISABLED_SCOPES = "extensions.autoDisableScopes";
const PREF_EM_SHOW_MISMATCH_UI = "extensions.showMismatchUI";
const PREF_EM_DISABLED_ADDONS_LIST = "extensions.disabledAddons";
const PREF_XPI_ENABLED = "xpinstall.enabled";
@ -2559,6 +2560,11 @@ var XPIProvider = {
newAddon.installDate = aAddonState.mtime;
newAddon.updateDate = aAddonState.mtime;
// Check if the add-on is in a scope where add-ons should install disabled
let disablingScopes = Prefs.getIntPref(PREF_EM_AUTO_DISABLED_SCOPES, 0);
if (aInstallLocation.scope & disablingScopes)
newAddon.userDisabled = true;
// If there is migration data then apply it.
if (aMigrateData) {
LOG("Migrating data from old database");

View File

@ -1063,6 +1063,9 @@ Services.prefs.setBoolPref("extensions.logging.enabled", true);
// By default only load extensions from the profile install location
Services.prefs.setIntPref("extensions.enabledScopes", AddonManager.SCOPE_PROFILE);
// By default don't disable add-ons from any scope
Services.prefs.setIntPref("extensions.autoDisableScopes", 0);
// By default, don't cache add-ons in AddonRepository.jsm
Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);

View File

@ -717,6 +717,116 @@ function run_test_11() {
do_check_not_in_crash_annotation(addon1.id, addon1.version);
do_check_not_in_crash_annotation(addon2.id, addon2.version);
end_test();
run_test_12();
});
}
// Test that auto-disabling for specific scopes works
function run_test_12() {
Services.prefs.setIntPref("extensions.autoDisableScopes", AddonManager.SCOPE_USER);
writeInstallRDFForExtension(addon1, profileDir);
writeInstallRDFForExtension(addon2, userDir);
writeInstallRDFForExtension(addon3, globalDir);
restartManager();
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org",
"addon3@tests.mozilla.org",
"addon4@tests.mozilla.org",
"addon5@tests.mozilla.org"],
function([a1, a2, a3, a4, a5]) {
do_check_neq(a1, null);
do_check_false(a1.userDisabled);
do_check_true(a1.isActive);
do_check_neq(a2, null);
do_check_true(a2.userDisabled);
do_check_false(a2.isActive);
do_check_neq(a3, null);
do_check_false(a3.userDisabled);
do_check_true(a3.isActive);
var dest = profileDir.clone();
dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
dest.remove(true);
dest = userDir.clone();
dest.append(do_get_expected_addon_name("addon2@tests.mozilla.org"));
dest.remove(true);
dest = globalDir.clone();
dest.append(do_get_expected_addon_name("addon3@tests.mozilla.org"));
dest.remove(true);
restartManager();
Services.prefs.setIntPref("extensions.autoDisableScopes", AddonManager.SCOPE_SYSTEM);
writeInstallRDFForExtension(addon1, profileDir);
writeInstallRDFForExtension(addon2, userDir);
writeInstallRDFForExtension(addon3, globalDir);
restartManager();
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org",
"addon3@tests.mozilla.org",
"addon4@tests.mozilla.org",
"addon5@tests.mozilla.org"],
function([a1, a2, a3, a4, a5]) {
do_check_neq(a1, null);
do_check_false(a1.userDisabled);
do_check_true(a1.isActive);
do_check_neq(a2, null);
do_check_false(a2.userDisabled);
do_check_true(a2.isActive);
do_check_neq(a3, null);
do_check_true(a3.userDisabled);
do_check_false(a3.isActive);
var dest = profileDir.clone();
dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
dest.remove(true);
dest = userDir.clone();
dest.append(do_get_expected_addon_name("addon2@tests.mozilla.org"));
dest.remove(true);
dest = globalDir.clone();
dest.append(do_get_expected_addon_name("addon3@tests.mozilla.org"));
dest.remove(true);
restartManager();
Services.prefs.setIntPref("extensions.autoDisableScopes", AddonManager.SCOPE_USER + AddonManager.SCOPE_SYSTEM);
writeInstallRDFForExtension(addon1, profileDir);
writeInstallRDFForExtension(addon2, userDir);
writeInstallRDFForExtension(addon3, globalDir);
restartManager();
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org",
"addon3@tests.mozilla.org",
"addon4@tests.mozilla.org",
"addon5@tests.mozilla.org"],
function([a1, a2, a3, a4, a5]) {
do_check_neq(a1, null);
do_check_false(a1.userDisabled);
do_check_true(a1.isActive);
do_check_neq(a2, null);
do_check_true(a2.userDisabled);
do_check_false(a2.isActive);
do_check_neq(a3, null);
do_check_true(a3.userDisabled);
do_check_false(a3.isActive);
end_test();
});
});
});
}