Bug 1565507 - Enable default theme on theme uninstallation r=aswan

... and re-enable the original theme when the uninstallation is undone,
iff it was enabled before.

Differential Revision: https://phabricator.services.mozilla.com/D39381

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Rob Wu 2019-08-03 12:40:53 +00:00
parent c4d18735be
commit 281ccf69b0
4 changed files with 107 additions and 42 deletions

View File

@ -1874,7 +1874,7 @@ this.XPIDatabase = {
if (theme.visible) {
if (!aId && theme.id == DEFAULT_THEME_ID) {
enableTheme = theme;
} else if (theme.id != aId) {
} else if (theme.id != aId && !theme.pendingUninstall) {
this.updateAddonDisabledState(theme, true, undefined, true);
}
}

View File

@ -4422,6 +4422,7 @@ var XPIInstall = {
aAddon._updateCheck.cancel();
}
let wasActive = aAddon.active;
let wasPending = aAddon.pendingUninstall;
if (aForcePending) {
@ -4524,7 +4525,8 @@ var XPIInstall = {
}
// Notify any other providers that a new theme has been enabled
if (aAddon.type === "theme" && aAddon.active) {
// (when the active theme is uninstalled, the default theme is enabled).
if (aAddon.type === "theme" && wasActive) {
AddonManagerPrivate.notifyAddonChanged(null, aAddon.type);
}
},

View File

@ -597,13 +597,17 @@ add_task(async function testThemeList() {
"There is one enabled theme"
);
let themesChanged = waitForThemeChange(list);
card.querySelector('[action="toggle-disabled"]').click();
await themesChanged;
let toggleThemeEnabled = async () => {
let themesChanged = waitForThemeChange(list);
card.querySelector('[action="toggle-disabled"]').click();
await themesChanged;
await TestUtils.waitForCondition(
() => enabledSection.querySelectorAll("addon-card").length == 1
);
await TestUtils.waitForCondition(
() => enabledSection.querySelectorAll("addon-card").length == 1
);
};
await toggleThemeEnabled();
is(
card.parentNode,
@ -616,6 +620,31 @@ add_task(async function testThemeList() {
"There is one enabled theme"
);
// Re-enable the theme.
await toggleThemeEnabled();
is(card.parentNode, enabledSection, "Card is back in the Enabled section");
// Remove theme and verify that the default theme is re-enabled.
let removed = BrowserTestUtils.waitForEvent(list, "remove");
// Confirm removal.
promptService._response = 0;
card.querySelector('[action="remove"]').click();
await removed;
is(card.parentNode, null, "Card has been removed from the view");
await TestUtils.waitForCondition(
() => enabledSection.querySelectorAll("addon-card").length == 1
);
let defaultTheme = getCardByAddonId(doc, "default-theme@mozilla.org");
is(defaultTheme.parentNode, enabledSection, "The default theme is reenabled");
await testUndoPendingUninstall(list, card.addon);
await TestUtils.waitForCondition(
() => enabledSection.querySelectorAll("addon-card").length == 1
);
is(defaultTheme.parentNode, disabledSection, "The default theme is disabled");
ok(getCardByAddonId(enabledSection, theme.id), "Theme should be reenabled");
await theme.unload();
await closeView(win);
});

View File

@ -50,9 +50,7 @@ add_task(async function setup_to_default_browserish_state() {
if (AppConstants.MOZ_DEV_EDITION) {
// Developer Edition selects the wrong theme by default.
let defaultTheme = await AddonManager.getAddonByID(
"default-theme@mozilla.org"
);
let defaultTheme = await AddonManager.getAddonByID(DEFAULT_THEME);
await defaultTheme.enable();
}
@ -178,48 +176,84 @@ add_task(async function test_default_theme() {
});
add_task(async function uninstall_offers_undo() {
let defaultTheme = await AddonManager.getAddonByID(DEFAULT_THEME);
const ID = THEME_IDS[0];
let theme = await promiseAddonByID(ID);
Assert.ok(theme, "Webextension theme is present");
Assert.ok(!theme.isActive, "Webextension theme is not active");
function promiseAddonEvent(event, id) {
return new Promise(resolve => {
let listener = {
// eslint-disable-next-line object-shorthand
[event]: function(addon) {
if (id) {
Assert.equal(addon.id, id, "Got event for expected addon");
}
AddonManager.removeAddonListener(listener);
resolve();
},
};
AddonManager.addAddonListener(listener);
});
async function promiseAddonEvent(event, id) {
let [addon] = await AddonTestUtils.promiseAddonEvent(event);
if (id) {
Assert.equal(addon.id, id, `Got event for expected addon (${event})`);
}
}
let uninstallingPromise = promiseAddonEvent("onUninstalling", ID);
await theme.uninstall(true);
await uninstallingPromise;
async function uninstallTheme() {
let uninstallingPromise = promiseAddonEvent("onUninstalling", ID);
await theme.uninstall(true);
await uninstallingPromise;
Assert.ok(
hasFlag(theme.pendingOperations, AddonManager.PENDING_UNINSTALL),
"Theme being uninstalled has PENDING_UNINSTALL flag"
);
Assert.ok(
hasFlag(theme.pendingOperations, AddonManager.PENDING_UNINSTALL),
"Theme being uninstalled has PENDING_UNINSTALL flag"
);
}
let cancelPromise = promiseAddonEvent("onOperationCancelled", ID);
theme.cancelUninstall();
await cancelPromise;
async function cancelUninstallTheme() {
let cancelPromise = promiseAddonEvent("onOperationCancelled", ID);
theme.cancelUninstall();
await cancelPromise;
Assert.equal(
theme.pendingOperations,
AddonManager.PENDING_NONE,
"PENDING_UNINSTALL flag is cleared when uninstall is canceled"
);
Assert.equal(
theme.pendingOperations,
AddonManager.PENDING_NONE,
"PENDING_UNINSTALL flag is cleared when uninstall is canceled"
);
}
// A theme should still be disabled if the uninstallation of a disabled theme
// is undone.
Assert.ok(!theme.isActive, "Webextension theme is not active");
Assert.ok(defaultTheme.isActive, "Default theme is active");
await uninstallTheme();
await cancelUninstallTheme();
Assert.ok(!theme.isActive, "Webextension theme is still not active");
Assert.ok(defaultTheme.isActive, "Default theme is still active");
// Enable theme, the previously active theme should be disabled.
await Promise.all([
promiseAddonEvent("onDisabled", DEFAULT_THEME),
promiseAddonEvent("onEnabled", ID),
theme.enable(),
]);
Assert.ok(theme.isActive, "Webextension theme is active after enabling");
Assert.ok(!defaultTheme.isActive, "Default theme is not active any more");
// Uninstall active theme, default theme should become active.
await Promise.all([
// Note: no listener for onDisabled & ID because the uninstall is pending.
promiseAddonEvent("onEnabled", DEFAULT_THEME),
uninstallTheme(),
]);
Assert.ok(!theme.isActive, "Webextension theme is not active upon uninstall");
Assert.ok(defaultTheme.isActive, "Default theme is active again");
// Undo uninstall, default theme should be deactivated.
await Promise.all([
// Note: no listener for onEnabled & ID because the uninstall was pending.
promiseAddonEvent("onDisabled", DEFAULT_THEME),
cancelUninstallTheme(),
]);
Assert.ok(theme.isActive, "Webextension theme is active upon undo uninstall");
Assert.ok(!defaultTheme.isActive, "Default theme is not active again");
// Immediately remove the theme. Default theme should be activated.
await Promise.all([
promiseAddonEvent("onEnabled", DEFAULT_THEME),
theme.uninstall(),
]);
await theme.uninstall();
await promiseRestartManager();
});