summaryrefslogtreecommitdiffstats
path: root/toolkit/components/nimbus/test/unit/test_NimbusTestUtils.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/nimbus/test/unit/test_NimbusTestUtils.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/nimbus/test/unit/test_NimbusTestUtils.js')
-rw-r--r--toolkit/components/nimbus/test/unit/test_NimbusTestUtils.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/toolkit/components/nimbus/test/unit/test_NimbusTestUtils.js b/toolkit/components/nimbus/test/unit/test_NimbusTestUtils.js
new file mode 100644
index 0000000000..5b9aa301d0
--- /dev/null
+++ b/toolkit/components/nimbus/test/unit/test_NimbusTestUtils.js
@@ -0,0 +1,82 @@
+"use strict";
+
+const { ExperimentFakes, ExperimentTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/NimbusTestUtils.sys.mjs"
+);
+
+add_task(async function test_recipe_fake_validates() {
+ const recipe = ExperimentFakes.recipe("foo");
+ Assert.ok(
+ await ExperimentTestUtils.validateExperiment(recipe),
+ "should produce a valid experiment recipe"
+ );
+});
+
+add_task(async function test_enrollmentHelper() {
+ let recipe = ExperimentFakes.recipe("bar", {
+ branches: [
+ {
+ slug: "control",
+ ratio: 1,
+ features: [{ featureId: "aboutwelcome", value: {} }],
+ },
+ ],
+ });
+ let manager = ExperimentFakes.manager();
+
+ Assert.deepEqual(
+ recipe.featureIds,
+ ["aboutwelcome"],
+ "Helper sets correct featureIds"
+ );
+
+ await manager.onStartup();
+
+ let { enrollmentPromise, doExperimentCleanup } =
+ ExperimentFakes.enrollmentHelper(recipe, { manager });
+
+ await enrollmentPromise;
+
+ Assert.ok(manager.store.getAllActiveExperiments().length === 1, "Enrolled");
+ Assert.equal(
+ manager.store.getAllActiveExperiments()[0].slug,
+ recipe.slug,
+ "Has expected slug"
+ );
+ Assert.ok(
+ Services.prefs.prefHasUserValue("nimbus.syncdatastore.aboutwelcome"),
+ "Sync pref cache set"
+ );
+
+ await doExperimentCleanup();
+
+ Assert.ok(manager.store.getAll().length === 0, "Cleanup done");
+ Assert.ok(
+ !Services.prefs.prefHasUserValue("nimbus.syncdatastore.aboutwelcome"),
+ "Sync pref cache is cleared"
+ );
+});
+
+add_task(async function test_enrollWithFeatureConfig() {
+ let manager = ExperimentFakes.manager();
+ await manager.onStartup();
+ let doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig(
+ {
+ featureId: "enrollWithFeatureConfig",
+ value: { enabled: true },
+ },
+ { manager }
+ );
+
+ Assert.ok(
+ manager.store.hasExperimentForFeature("enrollWithFeatureConfig"),
+ "Enrolled successfully"
+ );
+
+ await doExperimentCleanup();
+
+ Assert.ok(
+ !manager.store.hasExperimentForFeature("enrollWithFeatureConfig"),
+ "Unenrolled successfully"
+ );
+});