summaryrefslogtreecommitdiffstats
path: root/toolkit/components/normandy/test/browser/browser_NormandyMigrations.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/normandy/test/browser/browser_NormandyMigrations.js')
-rw-r--r--toolkit/components/normandy/test/browser/browser_NormandyMigrations.js106
1 files changed, 106 insertions, 0 deletions
diff --git a/toolkit/components/normandy/test/browser/browser_NormandyMigrations.js b/toolkit/components/normandy/test/browser/browser_NormandyMigrations.js
new file mode 100644
index 0000000000..9e60219c8b
--- /dev/null
+++ b/toolkit/components/normandy/test/browser/browser_NormandyMigrations.js
@@ -0,0 +1,106 @@
+const { NormandyMigrations } = ChromeUtils.importESModule(
+ "resource://normandy/NormandyMigrations.sys.mjs"
+);
+
+decorate_task(
+ withMockPreferences(),
+ async function testApplyMigrations({ mockPreferences }) {
+ const migrationsAppliedPref = "app.normandy.migrationsApplied";
+ mockPreferences.set(migrationsAppliedPref, 0);
+
+ await NormandyMigrations.applyAll();
+
+ is(
+ Services.prefs.getIntPref(migrationsAppliedPref),
+ NormandyMigrations.migrations.length,
+ "All migrations should have been applied"
+ );
+ }
+);
+
+decorate_task(
+ withMockPreferences(),
+ async function testPrefMigration({ mockPreferences }) {
+ const legacyPref = "extensions.shield-recipe-client.test";
+ const migratedPref = "app.normandy.test";
+ mockPreferences.set(legacyPref, 1);
+
+ ok(
+ Services.prefs.prefHasUserValue(legacyPref),
+ "Legacy pref should have a user value before running migration"
+ );
+ ok(
+ !Services.prefs.prefHasUserValue(migratedPref),
+ "Migrated pref should not have a user value before running migration"
+ );
+
+ await NormandyMigrations.applyOne(0);
+
+ ok(
+ !Services.prefs.prefHasUserValue(legacyPref),
+ "Legacy pref should not have a user value after running migration"
+ );
+ ok(
+ Services.prefs.prefHasUserValue(migratedPref),
+ "Migrated pref should have a user value after running migration"
+ );
+ is(
+ Services.prefs.getIntPref(migratedPref),
+ 1,
+ "Value should have been migrated"
+ );
+
+ Services.prefs.clearUserPref(migratedPref);
+ }
+);
+
+decorate_task(
+ withMockPreferences(),
+ async function testMigration0({ mockPreferences }) {
+ const studiesEnabledPref = "app.shield.optoutstudies.enabled";
+ const healthReportUploadEnabledPref =
+ "datareporting.healthreport.uploadEnabled";
+
+ // Both enabled
+ mockPreferences.set(studiesEnabledPref, true);
+ mockPreferences.set(healthReportUploadEnabledPref, true);
+ await NormandyMigrations.applyOne(1);
+ ok(
+ Services.prefs.getBoolPref(studiesEnabledPref),
+ "Studies should be enabled."
+ );
+
+ mockPreferences.cleanup();
+
+ // Telemetry disabled, studies enabled
+ mockPreferences.set(studiesEnabledPref, true);
+ mockPreferences.set(healthReportUploadEnabledPref, false);
+ await NormandyMigrations.applyOne(1);
+ ok(
+ !Services.prefs.getBoolPref(studiesEnabledPref),
+ "Studies should be disabled."
+ );
+
+ mockPreferences.cleanup();
+
+ // Telemetry enabled, studies disabled
+ mockPreferences.set(studiesEnabledPref, false);
+ mockPreferences.set(healthReportUploadEnabledPref, true);
+ await NormandyMigrations.applyOne(1);
+ ok(
+ !Services.prefs.getBoolPref(studiesEnabledPref),
+ "Studies should be disabled."
+ );
+
+ mockPreferences.cleanup();
+
+ // Both disabled
+ mockPreferences.set(studiesEnabledPref, false);
+ mockPreferences.set(healthReportUploadEnabledPref, false);
+ await NormandyMigrations.applyOne(1);
+ ok(
+ !Services.prefs.getBoolPref(studiesEnabledPref),
+ "Studies should be disabled."
+ );
+ }
+);