diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/themes/test | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/themes/test')
-rw-r--r-- | browser/themes/test/browser/browser.ini | 3 | ||||
-rw-r--r-- | browser/themes/test/browser/browser_expireThemes.js | 111 | ||||
-rw-r--r-- | browser/themes/test/xpcshell/test_BuiltInThemeConfig.js | 76 | ||||
-rw-r--r-- | browser/themes/test/xpcshell/xpcshell.ini | 4 |
4 files changed, 194 insertions, 0 deletions
diff --git a/browser/themes/test/browser/browser.ini b/browser/themes/test/browser/browser.ini new file mode 100644 index 0000000000..525f4f8f4b --- /dev/null +++ b/browser/themes/test/browser/browser.ini @@ -0,0 +1,3 @@ +[DEFAULT] + +[browser_expireThemes.js] diff --git a/browser/themes/test/browser/browser_expireThemes.js b/browser/themes/test/browser/browser_expireThemes.js new file mode 100644 index 0000000000..64fef950ae --- /dev/null +++ b/browser/themes/test/browser/browser_expireThemes.js @@ -0,0 +1,111 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm"); + +const { XPCOMUtils } = ChromeUtils.importESModule( + "resource://gre/modules/XPCOMUtils.sys.mjs" +); + +const { AddonTestUtils } = ChromeUtils.import( + "resource://testing-common/AddonTestUtils.jsm" +); + +ChromeUtils.defineESModuleGetters(this, { + BuiltInThemes: "resource:///modules/BuiltInThemes.sys.mjs", +}); + +XPCOMUtils.defineLazyModuleGetters(this, { + AddonManager: "resource://gre/modules/AddonManager.jsm", +}); + +const kLushSoftID = "lush-soft-colorway@mozilla.org"; +const kLushBoldID = "lush-bold-colorway@mozilla.org"; +const kRetainedThemesPref = "browser.theme.retainedExpiredThemes"; + +add_task(async function retainExpiredActiveTheme() { + let today = new Date().toISOString().split("T")[0]; + let tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); + tomorrow = tomorrow.toISOString().split("T")[0]; + let config = new Map([ + [ + kLushSoftID, + { + version: "1.1", + path: "resource://builtin-themes/colorways/2021lush/soft/", + expiry: tomorrow, + }, + ], + [ + kLushBoldID, + { + version: "1.1", + path: "resource://builtin-themes/colorways/2021lush/bold/", + expiry: tomorrow, + }, + ], + ]); + const oldBuiltInThemeMap = BuiltInThemes.builtInThemeMap; + BuiltInThemes.builtInThemeMap = config; + Assert.equal( + Services.prefs.getStringPref(kRetainedThemesPref, "[]"), + "[]", + "There are no retained themes." + ); + + AddonTestUtils.initMochitest(this); + registerCleanupFunction(async function() { + Services.prefs.clearUserPref(kRetainedThemesPref); + BuiltInThemes.builtInThemeMap = oldBuiltInThemeMap; + await BuiltInThemes.ensureBuiltInThemes(); + }); + + // Install our test themes and enable Lush (Soft). + await BuiltInThemes.ensureBuiltInThemes(); + let lushSoft = await AddonManager.getAddonByID(kLushSoftID); + let lushBold = await AddonManager.getAddonByID(kLushBoldID); + await lushSoft.enable(); + Assert.ok( + lushSoft && lushSoft.isActive, + "Sanity check: Lush Soft is the active theme." + ); + Assert.ok( + lushBold && !lushBold.isActive, + "Lush Bold is installed but inactive." + ); + + // Now, change the expiry dates on the themes to simulate the expiry date + // passing. + BuiltInThemes.builtInThemeMap.forEach( + themeInfo => (themeInfo.expiry = today) + ); + // Normally, ensureBuiltInThemes uninstalls expired themes. We + // expect it will not uninstall Lush (Soft) since it is the active theme. + await BuiltInThemes.ensureBuiltInThemes(); + lushSoft = await AddonManager.getAddonByID(kLushSoftID); + lushBold = await AddonManager.getAddonByID(kLushBoldID); + Assert.ok( + lushSoft && lushSoft.isActive, + "Lush Soft is still the active theme." + ); + Assert.ok(!lushBold, "Lush Bold has been uninstalled."); + Assert.equal( + Services.prefs.getStringPref(kRetainedThemesPref, "[]"), + JSON.stringify([kLushSoftID]), + "Lush Soft is set as a retained theme." + ); + + // Disable Lush (Soft) and re-run ensureBuiltInThemes. We're checking that + // Lush Soft is not uninstalled despite being inactive and expired, since it + // is a retained theme. + await lushSoft.disable(); + await BuiltInThemes.ensureBuiltInThemes(); + lushSoft = await AddonManager.getAddonByID(kLushSoftID); + Assert.ok( + lushSoft && !lushSoft.isActive, + "Lush Soft is installed but inactive." + ); + + await lushSoft.uninstall(); +}); diff --git a/browser/themes/test/xpcshell/test_BuiltInThemeConfig.js b/browser/themes/test/xpcshell/test_BuiltInThemeConfig.js new file mode 100644 index 0000000000..b6596014c9 --- /dev/null +++ b/browser/themes/test/xpcshell/test_BuiltInThemeConfig.js @@ -0,0 +1,76 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { _applyColorwayConfig, BuiltInThemeConfig } = ChromeUtils.importESModule( + "resource:///modules/BuiltInThemeConfig.sys.mjs" +); + +add_task(async function test_importConfig() { + Assert.ok( + BuiltInThemeConfig, + "Was able to import BuiltInThemeConfig and it is not empty." + ); +}); + +add_task(function test_recoverEmptyHomepage() { + for (let [id, config] of BuiltInThemeConfig.entries()) { + if (id.endsWith("-colorway@mozilla.org")) { + Assert.ok(config.collection, "Colorway theme has collection property."); + Assert.ok(config.expiry, "Colorway theme has expiry date."); + } + } +}); + +add_task(function test_findActiveColorwayCollection() { + // get valid collection name from config + const id = BuiltInThemeConfig.entries().next().value[1].collection; + let collectionsList = [ + new Date("2012-01-01"), + new Date("2012-02-01"), + new Date("2012-03-01"), + new Date("2012-04-01"), + new Date("2012-04-02"), + ].map((expiry, i) => ({ id, expiry, test_id: i + 1 })); + // set all other collection names as expired + for (const [, { collection }] of BuiltInThemeConfig.entries()) { + if (collection != id) { + collectionsList.push({ id: collection, expiry: new Date(0) }); + } + } + _applyColorwayConfig(collectionsList); + Assert.ok( + BuiltInThemeConfig.findActiveColorwayCollection(new Date("2010-01-01")), + "Found active collection" + ); + Assert.equal( + BuiltInThemeConfig.findActiveColorwayCollection(new Date("2015-01-01")), + null, + "Found no active collection" + ); + Assert.equal( + BuiltInThemeConfig.findActiveColorwayCollection(new Date("2011-12-31")) + .test_id, + 1, + "First collection is active" + ); + Assert.equal( + BuiltInThemeConfig.findActiveColorwayCollection(new Date("2012-02-03")) + .test_id, + 3, + "Middle collection is active" + ); + Assert.equal( + BuiltInThemeConfig.findActiveColorwayCollection(new Date("2012-04-02")) + .test_id, + 5, + "Last collection is active" + ); + Assert.equal( + BuiltInThemeConfig.findActiveColorwayCollection(new Date("2012-01-02")) + .test_id, + 2, + "Second collection is active" + ); +}); diff --git a/browser/themes/test/xpcshell/xpcshell.ini b/browser/themes/test/xpcshell/xpcshell.ini new file mode 100644 index 0000000000..59e0276fbd --- /dev/null +++ b/browser/themes/test/xpcshell/xpcshell.ini @@ -0,0 +1,4 @@ +[DEFAULT] +firefox-appdir = browser + +[test_BuiltInThemeConfig.js] |