diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/components/nimbus/test/unit/head.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/nimbus/test/unit/head.js')
-rw-r--r-- | toolkit/components/nimbus/test/unit/head.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/toolkit/components/nimbus/test/unit/head.js b/toolkit/components/nimbus/test/unit/head.js new file mode 100644 index 0000000000..e74212161c --- /dev/null +++ b/toolkit/components/nimbus/test/unit/head.js @@ -0,0 +1,82 @@ +"use strict"; +// Globals + +const { sinon } = ChromeUtils.importESModule( + "resource://testing-common/Sinon.sys.mjs" +); +const { XPCOMUtils } = ChromeUtils.importESModule( + "resource://gre/modules/XPCOMUtils.sys.mjs" +); +ChromeUtils.defineESModuleGetters(this, { + ExperimentFakes: "resource://testing-common/NimbusTestUtils.sys.mjs", + ExperimentTestUtils: "resource://testing-common/NimbusTestUtils.sys.mjs", + ObjectUtils: "resource://gre/modules/ObjectUtils.sys.mjs", +}); + +// Sinon does not support Set or Map in spy.calledWith() +function onFinalizeCalled(spyOrCallArgs, ...expectedArgs) { + function mapToObject(map) { + return Object.assign( + {}, + ...Array.from(map.entries()).map(([k, v]) => ({ [k]: v })) + ); + } + + function toPlainObjects(args) { + return [ + args[0], + { + ...args[1], + invalidBranches: mapToObject(args[1].invalidBranches), + invalidFeatures: mapToObject(args[1].invalidFeatures), + missingLocale: Array.from(args[1].missingLocale), + missingL10nIds: mapToObject(args[1].missingL10nIds), + }, + ]; + } + + const plainExpected = toPlainObjects(expectedArgs); + + if (Array.isArray(spyOrCallArgs)) { + return ObjectUtils.deepEqual(toPlainObjects(spyOrCallArgs), plainExpected); + } + + for (const args of spyOrCallArgs.args) { + if (ObjectUtils.deepEqual(toPlainObjects(args), plainExpected)) { + return true; + } + } + + return false; +} + +/** + * Assert the store has no active experiments or rollouts. + */ +async function assertEmptyStore(store, { cleanup = false } = {}) { + Assert.deepEqual( + store + .getAll() + .filter(e => e.active) + .map(e => e.slug), + [], + "Store should have no active enrollments" + ); + + Assert.deepEqual( + store + .getAll() + .filter(e => e.inactive) + .map(e => e.slug), + [], + "Store should have no inactive enrollments" + ); + + if (cleanup) { + // We need to call finalize first to ensure that any pending saves from + // JSONFile.saveSoon overwrite files on disk. + store._store.saveSoon(); + await store._store.finalize(); + await IOUtils.remove(store._store.path); + } +} |