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/xpcshell/test_BuiltInThemeConfig.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/themes/test/xpcshell/test_BuiltInThemeConfig.js | 76 |
1 files changed, 76 insertions, 0 deletions
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" + ); +}); |