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/normandy/test/browser/browser_NormandyMigrations.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/normandy/test/browser/browser_NormandyMigrations.js')
-rw-r--r-- | toolkit/components/normandy/test/browser/browser_NormandyMigrations.js | 106 |
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." + ); + } +); |