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 1738325 - Part 2 - Show expired but retained themes among the reg…
…ular themes in about:addons. r=rpl,dao Differential Revision: https://phabricator.services.mozilla.com/D130940
- Loading branch information
Showing
5 changed files
with
136 additions
and
18 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 |
---|---|---|
|
@@ -4596,7 +4596,7 @@ gViewController.defineView("list", async type => { | |
|
||
// If monochromatic themes are enabled and any are builtin to Firefox, we | ||
// display those themes together in a separate subsection. | ||
let isMonochromaticTheme = addon => | ||
const isMonochromaticTheme = addon => | ||
addon.id.endsWith("[email protected]"); | ||
|
||
let frag = document.createDocumentFragment(); | ||
|
@@ -4615,21 +4615,32 @@ gViewController.defineView("list", async type => { | |
!addon.hidden && | ||
!addon.isActive && | ||
!isPending(addon, "uninstall") && | ||
!isMonochromaticTheme(addon), | ||
// For performance related details about this check see the | ||
// documentation for themeIsExpired in BuiltInThemeConfig.jsm. | ||
(!isMonochromaticTheme(addon) || | ||
BuiltInThemes.isRetainedExpiredTheme(addon.id)), | ||
}, | ||
]; | ||
list.setSections(sections); | ||
frag.appendChild(list); | ||
|
||
if (type == "theme") { | ||
const areColorwayThemesInstalled = async () => | ||
(await AddonManager.getAllAddons()).some( | ||
addon => | ||
isMonochromaticTheme(addon) && !BuiltInThemes.themeIsExpired(addon.id) | ||
); | ||
if (type == "theme" && (await areColorwayThemesInstalled())) { | ||
let monochromaticList = document.createElement("addon-list"); | ||
monochromaticList.classList.add("monochromatic-addon-list"); | ||
monochromaticList.type = type; | ||
monochromaticList.setSections([ | ||
{ | ||
headingId: type + "-monochromatic-heading", | ||
subheadingId: type + "-monochromatic-subheading", | ||
filterFn: addon => !addon.hidden && isMonochromaticTheme(addon), | ||
filterFn: addon => | ||
!addon.hidden && | ||
isMonochromaticTheme(addon) && | ||
!BuiltInThemes.themeIsExpired(addon.id), | ||
}, | ||
]); | ||
frag.appendChild(monochromaticList); | ||
|
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 |
---|---|---|
|
@@ -4,15 +4,20 @@ | |
const { AddonTestUtils } = ChromeUtils.import( | ||
"resource://testing-common/AddonTestUtils.jsm" | ||
); | ||
const { BuiltInThemes } = ChromeUtils.import( | ||
"resource:///modules/BuiltInThemes.jsm" | ||
); | ||
|
||
AddonTestUtils.initMochitest(this); | ||
|
||
const kTestThemeId = "[email protected]"; | ||
|
||
add_task(async function testMonochromaticList() { | ||
// Install test theme before loading view. | ||
const themeXpi = AddonTestUtils.createTempWebExtensionFile({ | ||
manifest: { | ||
name: "Monochromatic Theme", | ||
applications: { gecko: { id: "[email protected]" } }, | ||
applications: { gecko: { id: kTestThemeId } }, | ||
theme: {}, | ||
}, | ||
}); | ||
|
@@ -49,7 +54,8 @@ add_task(async function testMonochromaticList() { | |
"Subheader string is correct." | ||
); | ||
|
||
// Check that the test theme is in the colorways section. | ||
// Check that the test theme is in the colorways section. It should be there | ||
// because it hasn't yet expired. | ||
let card = colorwayList.querySelector( | ||
"addon-card[addon-id='[email protected]']" | ||
); | ||
|
@@ -61,19 +67,18 @@ add_task(async function testMonochromaticList() { | |
|
||
// Check that the test theme is in the enabled section. | ||
let addon = await AddonManager.getAddonByID("[email protected]"); | ||
let enabledSection = doc.querySelector("section[section='0']"); | ||
let enabledSection = getSection(doc, "enabled"); | ||
let mutationPromise = BrowserTestUtils.waitForMutationCondition( | ||
enabledSection, | ||
{ childList: true }, | ||
() => | ||
enabledSection.children.length > 1 && | ||
enabledSection.children[1].getAttribute("addon-id") == | ||
"[email protected]" | ||
enabledSection.children[1].getAttribute("addon-id") == kTestThemeId | ||
); | ||
await addon.enable(); | ||
await mutationPromise; | ||
let enabledCard = enabledSection.querySelector( | ||
"addon-card[addon-id='[email protected]']" | ||
`addon-card[addon-id='${kTestThemeId}']` | ||
); | ||
ok( | ||
enabledSection.contains(enabledCard), | ||
|
@@ -104,3 +109,78 @@ add_task(async function testMonochromaticList() { | |
await closeView(win); | ||
await themeAddon.uninstall(true); | ||
}); | ||
|
||
add_task(async function testExpiredThemes() { | ||
const themeXpi = AddonTestUtils.createTempWebExtensionFile({ | ||
manifest: { | ||
name: "Monochromatic Theme", | ||
applications: { gecko: { id: kTestThemeId } }, | ||
theme: {}, | ||
}, | ||
}); | ||
|
||
// Make the test theme appear expired. | ||
let yesterday = new Date(); | ||
yesterday.setDate(yesterday.getDate() - 1); | ||
yesterday = yesterday.toISOString().split("T")[0]; | ||
// Add the test theme to our list of built-in themes so that aboutaddons.js | ||
// will think this theme is expired. | ||
BuiltInThemes.builtInThemeMap.set(kTestThemeId, { | ||
version: "1.0", | ||
expiry: yesterday, | ||
// We use the manifest from Light theme since we know it will be in-tree | ||
// indefinitely. | ||
path: "resource://builtin-themes/light/", | ||
}); | ||
registerCleanupFunction(() => { | ||
BuiltInThemes.builtInThemeMap.delete(kTestThemeId); | ||
}); | ||
|
||
// Make the test theme appear retained. | ||
const retainedThemePrefName = "browser.theme.retainedExpiredThemes"; | ||
Services.prefs.setStringPref( | ||
retainedThemePrefName, | ||
JSON.stringify([kTestThemeId]) | ||
); | ||
registerCleanupFunction(() => { | ||
Services.prefs.clearUserPref(retainedThemePrefName); | ||
}); | ||
|
||
const expiredAddon = await AddonManager.installTemporaryAddon(themeXpi); | ||
let addon = await AddonManager.getAddonByID(kTestThemeId); | ||
await addon.disable(); | ||
|
||
let win = await loadInitialView("theme"); | ||
let doc = win.document; | ||
|
||
let colorwayList = doc.querySelector(".monochromatic-addon-list"); | ||
|
||
// We need branching logic here since the outcome depends on whether there | ||
// are active non-test Colorway themes when the test runs. | ||
if (colorwayList) { | ||
let card = colorwayList.querySelector( | ||
`addon-card[addon-id='${kTestThemeId}']` | ||
); | ||
ok( | ||
!colorwayList.contains(card), | ||
"Colorways section does not contain expired theme." | ||
); | ||
} else { | ||
ok( | ||
true, | ||
"The Colorways section is not in the DOM because all Colorway themes are expired." | ||
); | ||
} | ||
|
||
let disabledSection = getSection(doc, "disabled"); | ||
let card = disabledSection.querySelector( | ||
`addon-card[addon-id='${kTestThemeId}']` | ||
); | ||
ok( | ||
disabledSection.contains(card), | ||
"The regular, non-Colorways 'Disabled' section contains the expired theme." | ||
); | ||
|
||
await closeView(win); | ||
await expiredAddon.uninstall(true); | ||
}); |
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