Bug 1792988 - Dont reset prefs on startup for users not in experiment. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D158889
This commit is contained in:
Dale Harvey 2022-10-11 14:09:50 +00:00
parent d3ca5130e4
commit 743488f1ab
2 changed files with 35 additions and 2 deletions

View File

@ -136,3 +136,24 @@ add_task(async function test_nimbus_experiment_urlbar_result_enabled() {
"Should turn off private default and restore default engine after experiment"
);
});
add_task(async function test_non_experiment_prefs() {
await SpecialPowers.pushPrefEnv({
set: [["browser.search.separatePrivateDefault.ui.enabled", false]],
});
let uiPref = () =>
Services.prefs.getBoolPref(
"browser.search.separatePrivateDefault.ui.enabled"
);
Assert.equal(uiPref(), false, "defaulted false");
await ExperimentAPI.ready();
let doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
featureId: "privatesearch",
value: {
seperatePrivateDefaultUIEnabled: true,
},
});
Assert.equal(uiPref(), false, "Pref did not change without experiment");
await doExperimentCleanup();
await SpecialPowers.popPrefEnv();
});

View File

@ -1370,7 +1370,7 @@ export class SearchService {
// we started listening, so do a check on startup.
Services.tm.dispatchToMainThread(async () => {
await lazy.NimbusFeatures.search.ready();
this.#checkNimbusPrefs();
this.#checkNimbusPrefs(true);
});
return this.#initRV;
@ -3279,7 +3279,19 @@ export class SearchService {
);
}
#checkNimbusPrefs() {
/**
* Check the prefs are correctly updated for users enrolled in a Nimbus experiment.
*
* @param {boolean} isStartup
* Whether this function was called as part of the startup flow.
*/
#checkNimbusPrefs(isStartup = false) {
// If we are in an experiment we may need to check the status on startup, otherwise
// ignore the call to check on startup so we do not reset users prefs when they are
// not an experiment.
if (isStartup && !lazy.NimbusFeatures.search.getVariable("experiment")) {
return;
}
let nimbusPrivateDefaultUIEnabled = lazy.NimbusFeatures.search.getVariable(
"seperatePrivateDefaultUIEnabled"
);