summaryrefslogtreecommitdiffstats
path: root/toolkit/components/nimbus/test/unit/test_NimbusTestUtils.js
diff options
context:
space:
mode:
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"
+ );
+});