forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1664949 - don't clear the active theme pref on startup so it gets…
… synced wrong, r=zombie,mixedpuppy Before bug 1660557, this was actually clearing an old migration pref, but now it's clearing the actual theme pref used by Sync. Differential Revision: https://phabricator.services.mozilla.com/D90194
- Loading branch information
Showing
4 changed files
with
107 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,7 +113,7 @@ const PREF_XPI_DIRECT_WHITELISTED = "xpinstall.whitelist.directRequest"; | |
const PREF_XPI_FILE_WHITELISTED = "xpinstall.whitelist.fileRequest"; | ||
const PREF_XPI_WHITELIST_REQUIRED = "xpinstall.whitelist.required"; | ||
|
||
const PREF_SELECTED_LWT = "extensions.activeThemeID"; | ||
const PREF_SELECTED_THEME = "extensions.activeThemeID"; | ||
|
||
const TOOLKIT_ID = "[email protected]"; | ||
|
||
|
@@ -210,10 +210,10 @@ const LOGGER_ID = "addons.xpi"; | |
// (Requires AddonManager.jsm) | ||
var logger = Log.repository.getLogger(LOGGER_ID); | ||
|
||
// Stores the ID of the lightweight theme which was selected during the | ||
// last session, if any. When installing a new built-in theme with this | ||
// ID, it will be automatically enabled. | ||
let lastLightweightTheme = null; | ||
// Stores the ID of the theme which was selected during the last session, | ||
// if any. When installing a new built-in theme with this ID, it will be | ||
// automatically enabled. | ||
let lastSelectedTheme = null; | ||
|
||
function getJarURI(file, path = "") { | ||
if (file instanceof Ci.nsIFile) { | ||
|
@@ -4378,9 +4378,11 @@ var XPIInstall = { | |
* installed. | ||
*/ | ||
async installBuiltinAddon(base) { | ||
if (lastLightweightTheme === null) { | ||
lastLightweightTheme = Services.prefs.getCharPref(PREF_SELECTED_LWT, ""); | ||
Services.prefs.clearUserPref(PREF_SELECTED_LWT); | ||
// We have to get this before the install, as the install will overwrite | ||
// the pref. We then keep the value for this run, so we can restore | ||
// the selected theme once it becomes available. | ||
if (lastSelectedTheme === null) { | ||
lastSelectedTheme = Services.prefs.getCharPref(PREF_SELECTED_THEME, ""); | ||
} | ||
|
||
let baseURL = Services.io.newURI(base); | ||
|
@@ -4400,20 +4402,14 @@ var XPIInstall = { | |
// If this is a theme, decide whether to enable it. Themes are | ||
// disabled by default. However: | ||
// | ||
// If a lightweight theme was selected in the last session, and this | ||
// theme has the same ID, then we clearly want to enable it. | ||
// | ||
// If it is the default theme, more specialized behavior applies: | ||
// | ||
// We always want one theme to be active, falling back to the | ||
// default theme when the active theme is disabled. The first time | ||
// we install the default theme, though, there likely aren't any | ||
// other theme add-ons installed yet, in which case we want to | ||
// enable it immediately. | ||
// default theme when the active theme is disabled. | ||
// During a theme migration, such as a change in the path to the addon, we | ||
// will need to ensure a correct theme is enabled. | ||
if (addon.type === "theme") { | ||
if ( | ||
addon.id === lastLightweightTheme || | ||
(!lastLightweightTheme.endsWith("@mozilla.org") && | ||
addon.id === lastSelectedTheme || | ||
(!lastSelectedTheme.endsWith("@mozilla.org") && | ||
addon.id === AddonSettings.DEFAULT_THEME_ID && | ||
!XPIDatabase.getAddonsByType("theme").some(theme => !theme.disabled)) | ||
) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ XPCOMUtils.defineLazyGetter(this, "Management", () => { | |
}); | ||
|
||
add_task(async function setup() { | ||
let scopes = AddonManager.SCOPE_PROFILE | AddonManager.SCOPE_APPLICATION; | ||
Services.prefs.setIntPref("extensions.enabledScopes", scopes); | ||
createAppInfo("[email protected]", "XPCShell", "42.0", "42.0"); | ||
|
||
await promiseStartupManager(); | ||
|
@@ -49,3 +51,82 @@ add_task(async function test_update_of_disabled_theme() { | |
ok(addon.userDisabled, "Theme is still disabled after an update"); | ||
await addon.uninstall(); | ||
}); | ||
|
||
add_task(async function test_builtin_location_migration() { | ||
const ADDON_ID = "[email protected]"; | ||
|
||
let themeDef = { | ||
manifest: { | ||
applications: { gecko: { id: ADDON_ID } }, | ||
version: "1.0", | ||
theme: {}, | ||
}, | ||
}; | ||
|
||
await setupBuiltinExtension(themeDef, "first-loc", false); | ||
let themeInstalled = AddonTestUtils.promiseAddonEvent( | ||
"onInstalled", | ||
aAddon => aAddon.id == ADDON_ID | ||
); | ||
await AddonManager.maybeInstallBuiltinAddon( | ||
ADDON_ID, | ||
"1.0", | ||
"resource://first-loc/" | ||
); | ||
await themeInstalled; | ||
|
||
let addon = await AddonManager.getAddonByID(ADDON_ID); | ||
await addon.enable(); | ||
Assert.ok(!addon.userDisabled, "Add-on should be enabled."); | ||
|
||
Assert.equal( | ||
Services.prefs.getCharPref("extensions.activeThemeID", ""), | ||
ADDON_ID, | ||
"Pref should be set." | ||
); | ||
|
||
let { addons: activeThemes } = await AddonManager.getActiveAddons(["theme"]); | ||
Assert.equal(activeThemes.length, 1, "Should have 1 theme."); | ||
Assert.equal(activeThemes[0].id, ADDON_ID, "Should have enabled the theme."); | ||
|
||
// If we restart and update, and install a newer version of the theme, | ||
// it should be activated. | ||
await promiseShutdownManager(); | ||
|
||
// Force schema change and restart | ||
Services.prefs.setIntPref("extensions.databaseSchema", 0); | ||
await promiseStartupManager(); | ||
|
||
// Set up a new version of the builtin add-on. | ||
let newDef = { manifest: Object.assign({}, themeDef.manifest) }; | ||
newDef.manifest.version = "1.1"; | ||
await setupBuiltinExtension(newDef, "second-loc"); | ||
themeInstalled = AddonTestUtils.promiseAddonEvent( | ||
"onInstalled", | ||
aAddon => aAddon.id == ADDON_ID | ||
); | ||
|
||
await AddonManager.maybeInstallBuiltinAddon( | ||
ADDON_ID, | ||
"1.1", | ||
"resource://second-loc/" | ||
); | ||
await themeInstalled; | ||
|
||
let newAddon = await AddonManager.getAddonByID(ADDON_ID); | ||
Assert.ok(!newAddon.userDisabled, "Add-on should be enabled."); | ||
|
||
({ addons: activeThemes } = await AddonManager.getActiveAddons(["theme"])); | ||
Assert.equal(activeThemes.length, 1, "Should still have 1 theme."); | ||
Assert.equal( | ||
activeThemes[0].id, | ||
ADDON_ID, | ||
"Should still have the theme enabled." | ||
); | ||
Assert.equal( | ||
Services.prefs.getCharPref("extensions.activeThemeID", ""), | ||
ADDON_ID, | ||
"Pref should still be set." | ||
); | ||
await promiseShutdownManager(); | ||
}); |