summaryrefslogtreecommitdiffstats
path: root/toolkit/components/normandy/test/browser/browser_ShieldPreferences.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/normandy/test/browser/browser_ShieldPreferences.js
parentInitial commit. (diff)
downloadfirefox-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 'toolkit/components/normandy/test/browser/browser_ShieldPreferences.js')
-rw-r--r--toolkit/components/normandy/test/browser/browser_ShieldPreferences.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/toolkit/components/normandy/test/browser/browser_ShieldPreferences.js b/toolkit/components/normandy/test/browser/browser_ShieldPreferences.js
new file mode 100644
index 0000000000..48482d82f7
--- /dev/null
+++ b/toolkit/components/normandy/test/browser/browser_ShieldPreferences.js
@@ -0,0 +1,93 @@
+"use strict";
+
+const { PreferenceExperiments } = ChromeUtils.import(
+ "resource://normandy/lib/PreferenceExperiments.jsm"
+);
+const { ShieldPreferences } = ChromeUtils.import(
+ "resource://normandy/lib/ShieldPreferences.jsm"
+);
+
+const OPT_OUT_STUDIES_ENABLED_PREF = "app.shield.optoutstudies.enabled";
+
+const { NormandyTestUtils } = ChromeUtils.import(
+ "resource://testing-common/NormandyTestUtils.jsm"
+);
+const {
+ addonStudyFactory,
+ preferenceStudyFactory,
+} = NormandyTestUtils.factories;
+
+ShieldPreferences.init();
+
+decorate_task(
+ withMockPreferences(),
+ AddonStudies.withStudies([
+ addonStudyFactory({ active: true }),
+ addonStudyFactory({ active: true }),
+ ]),
+ async function testDisableStudiesWhenOptOutDisabled({
+ mockPreferences,
+ addonStudies: [study1, study2],
+ }) {
+ mockPreferences.set(OPT_OUT_STUDIES_ENABLED_PREF, true);
+ const observers = [
+ studyEndObserved(study1.recipeId),
+ studyEndObserved(study2.recipeId),
+ ];
+ Services.prefs.setBoolPref(OPT_OUT_STUDIES_ENABLED_PREF, false);
+ await Promise.all(observers);
+
+ const newStudy1 = await AddonStudies.get(study1.recipeId);
+ const newStudy2 = await AddonStudies.get(study2.recipeId);
+ ok(
+ !newStudy1.active && !newStudy2.active,
+ "Setting the opt-out pref to false stops all active opt-out studies."
+ );
+ }
+);
+
+decorate_task(
+ withMockPreferences(),
+ PreferenceExperiments.withMockExperiments([
+ preferenceStudyFactory({ active: true }),
+ preferenceStudyFactory({ active: true }),
+ ]),
+ withStub(PreferenceExperiments, "stop"),
+ async function testDisableExperimentsWhenOptOutDisabled({
+ mockPreferences,
+ prefExperiments: [study1, study2],
+ stopStub,
+ }) {
+ mockPreferences.set(OPT_OUT_STUDIES_ENABLED_PREF, true);
+ let stopArgs = [];
+ let stoppedBoth = new Promise(resolve => {
+ let calls = 0;
+ stopStub.callsFake(function() {
+ stopArgs.push(Array.from(arguments));
+ calls++;
+ if (calls == 2) {
+ resolve();
+ }
+ });
+ });
+ Services.prefs.setBoolPref(OPT_OUT_STUDIES_ENABLED_PREF, false);
+ await stoppedBoth;
+
+ Assert.deepEqual(stopArgs, [
+ [
+ study1.slug,
+ {
+ reason: "general-opt-out",
+ caller: "observePrefChange::general-opt-out",
+ },
+ ],
+ [
+ study2.slug,
+ {
+ reason: "general-opt-out",
+ caller: "observePrefChange::general-opt-out",
+ },
+ ],
+ ]);
+ }
+);