Bug 563256: Re-enabling the active theme doesn't clear the pending switch preference. r=robstrong

This commit is contained in:
Dave Townsend 2010-05-06 16:02:04 -07:00
parent f7e298b8c5
commit 2839061c9b
2 changed files with 288 additions and 13 deletions

View File

@ -784,8 +784,11 @@ var XPIProvider = {
installs: null,
// The default skin for the application
defaultSkin: "classic/1.0",
// The currently selected skin or the skin that will be switched to after a
// restart
// The current skin used by the application
currentSkin: null,
// The selected skin to be used by the application when it is restarted. This
// will be the same as currentSkin when it is the skin to be used when the
// application is restarted
selectedSkin: null,
// The name of the checkCompatibility preference for the current application
// version
@ -889,8 +892,9 @@ var XPIProvider = {
this.defaultSkin = Prefs.getDefaultCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN,
"classic/1.0");
this.selectedSkin = Prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN,
this.defaultSkin);
this.currentSkin = Prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN,
this.defaultSkin);
this.selectedSkin = this.currentSkin;
// Tell the Chrome Registry which Skin to select
if (Prefs.getBoolPref(PREF_DSS_SWITCHPENDING, false)) {
@ -900,6 +904,7 @@ var XPIProvider = {
this.selectedSkin);
Services.prefs.clearUserPref(PREF_DSS_SKIN_TO_SELECT);
LOG("Changed skin to " + this.selectedSkin);
this.currentSkin = this.selectedSkin;
}
catch (e) {
ERROR(e);
@ -919,7 +924,7 @@ var XPIProvider = {
Services.appinfo instanceof Ci.nsICrashReporter) {
// Annotate the crash report with relevant add-on information.
try {
Services.appinfo.annotateCrashReport("Theme", this.selectedSkin);
Services.appinfo.annotateCrashReport("Theme", this.currentSkin);
} catch (e) { }
try {
Services.appinfo.annotateCrashReport("EMCheckCompatibility",
@ -1833,8 +1838,19 @@ var XPIProvider = {
Services.prefs.setBoolPref(PREF_DSS_SWITCHPENDING, true);
Services.prefs.setCharPref(PREF_DSS_SKIN_TO_SELECT, newSkin);
}
else if (newSkin == this.currentSkin) {
try {
Services.prefs.clearUserPref(PREF_DSS_SWITCHPENDING);
}
catch (e) { }
try {
Services.prefs.clearUserPref(PREF_DSS_SKIN_TO_SELECT);
}
catch (e) { }
}
else {
Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, newSkin);
this.currentSkin = newSkin;
}
this.selectedSkin = newSkin;
@ -1898,8 +1914,7 @@ var XPIProvider = {
// If the theme we're enabling is the skin currently selected then it doesn't
// require a restart to enable it.
if (aAddon.type == "theme")
return aAddon.internalName !=
Prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN);
return aAddon.internalName != this.currentSkin;
return !aAddon.bootstrap;
},
@ -1917,8 +1932,7 @@ var XPIProvider = {
// a restart if enabling the other theme does too. If the selected skin doesn't
// match the current skin then a restart is necessary.
if (aAddon.type == "theme")
return this.selectedSkin !=
Prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN);
return this.selectedSkin != this.currentSkin;
return !aAddon.bootstrap;
},
@ -1933,8 +1947,7 @@ var XPIProvider = {
installRequiresRestart: function XPI_installRequiresRestart(aAddon) {
// Themes not currently in use can be installed immediately
if (aAddon.type == "theme")
return aAddon.internalName ==
Prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN);
return aAddon.internalName == this.currentSkin;
return !aAddon.bootstrap;
},
@ -1949,8 +1962,7 @@ var XPIProvider = {
uninstallRequiresRestart: function XPI_uninstallRequiresRestart(aAddon) {
// Themes not currently in use can be uninstalled immediately
if (aAddon.type == "theme")
return aAddon.internalName ==
Prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN);
return aAddon.internalName == this.currentSkin;
return !aAddon.bootstrap;
},

View File

@ -0,0 +1,263 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// This verifies that the themes switch as expected
const PREF_GENERAL_SKINS_SELECTEDSKIN = "general.skins.selectedSkin";
const profileDir = gProfD.clone();
profileDir.append("extensions");
function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
dest = profileDir.clone();
dest.append("default@tests.mozilla.org");
writeInstallRDFToDir({
id: "default@tests.mozilla.org",
version: "1.0",
name: "Default",
internalName: "classic/1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "2"
}]
}, dest);
var dest = profileDir.clone();
dest.append("alternate@tests.mozilla.org");
writeInstallRDFToDir({
id: "alternate@tests.mozilla.org",
version: "1.0",
name: "Test 1",
type: 4,
internalName: "alternate/1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "2"
}]
}, dest);
startupManager(1);
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
"alternate@tests.mozilla.org"], function([d, a]) {
do_check_neq(d, null);
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_neq(a, null);
do_check_true(a.userDisabled);
do_check_false(a.appDisabled);
do_check_false(a.isActive);
do_check_false(isThemeInAddonsList(profileDir, a.id));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
run_test_1(d, a);
});
}
function end_test() {
do_test_finished();
}
// Checks switching to a different theme and back again leaves everything the
// same
function run_test_1(d, a) {
a.userDisabled = false;
do_check_true(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_false(a.userDisabled);
do_check_false(a.appDisabled);
do_check_false(a.isActive);
do_check_false(isThemeInAddonsList(profileDir, a.id));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
d.userDisabled = false;
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_true(a.userDisabled);
do_check_false(a.appDisabled);
do_check_false(a.isActive);
do_check_false(isThemeInAddonsList(profileDir, a.id));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
restartManager(0);
run_test_2();
}
// Tests that after the restart themes can be changed as expected
function run_test_2() {
AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
"alternate@tests.mozilla.org"], function([d, a]) {
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
do_check_neq(d, null);
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_neq(a, null);
do_check_true(a.userDisabled);
do_check_false(a.appDisabled);
do_check_false(a.isActive);
do_check_false(isThemeInAddonsList(profileDir, a.id));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
a.userDisabled = false;
do_check_true(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_false(a.userDisabled);
do_check_false(a.appDisabled);
do_check_false(a.isActive);
do_check_false(isThemeInAddonsList(profileDir, a.id));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
d.userDisabled = false;
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_true(a.userDisabled);
do_check_false(a.appDisabled);
do_check_false(a.isActive);
do_check_false(isThemeInAddonsList(profileDir, a.id));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
a.userDisabled = false;
do_check_true(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_false(a.userDisabled);
do_check_false(a.appDisabled);
do_check_false(a.isActive);
do_check_false(isThemeInAddonsList(profileDir, a.id));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
restartManager(0);
check_test_2();
});
}
function check_test_2() {
AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
"alternate@tests.mozilla.org"], function([d, a]) {
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "alternate/1.0");
do_check_true(d.userDisabled);
do_check_false(d.appDisabled);
do_check_false(d.isActive);
do_check_false(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_false(a.userDisabled);
do_check_false(a.appDisabled);
do_check_true(a.isActive);
do_check_true(isThemeInAddonsList(profileDir, a.id));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
d.userDisabled = false;
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_false(d.isActive);
do_check_false(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_true(a.userDisabled);
do_check_false(a.appDisabled);
do_check_true(a.isActive);
do_check_true(isThemeInAddonsList(profileDir, a.id));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "alternate/1.0");
restartManager(0);
do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
"alternate@tests.mozilla.org"], function([d, a]) {
do_check_neq(d, null);
do_check_false(d.userDisabled);
do_check_false(d.appDisabled);
do_check_true(d.isActive);
do_check_true(isThemeInAddonsList(profileDir, d.id));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_neq(a, null);
do_check_true(a.userDisabled);
do_check_false(a.appDisabled);
do_check_false(a.isActive);
do_check_false(isThemeInAddonsList(profileDir, a.id));
do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));
end_test();
});
});
}