Bug 1947053 - Remove the quickSuggestScenario Nimbus variable. r=daisuke

Depends on D237314

Differential Revision: https://phabricator.services.mozilla.com/D237505
This commit is contained in:
Drew Willcoxon
2025-02-12 09:12:49 +00:00
parent 5d192f4a2e
commit 0e869a558b
3 changed files with 13 additions and 544 deletions

View File

@@ -387,13 +387,9 @@ class _QuickSuggest {
* The name of the variable.
*/
async onNimbusChanged(variable) {
if (
variable == "quickSuggestScenario" ||
this.UI_PREFS_BY_VARIABLE.hasOwnProperty(variable)
) {
// If a change occurred to the Firefox Suggest scenario variable or any
// variables that correspond to prefs exposed in the UI, we need to update
// the scenario.
if (this.UI_PREFS_BY_VARIABLE.hasOwnProperty(variable)) {
// If a change occurred to any variables that correspond to prefs exposed
// in the UI, we need to update the scenario.
await this.updateFirefoxSuggestScenario();
} else {
// If the current default-branch value of any pref is incorrect for the
@@ -615,11 +611,7 @@ class _QuickSuggest {
//
// The scenario-update process is described next.
//
// 1. Pick a scenario. If the user is in a Nimbus rollout, then Nimbus will
// define it. Otherwise the user may be in a "hardcoded" rollout
// depending on their region and locale. If the user is not in any
// rollouts, then the scenario is "history", which means no Firefox
// Suggest suggestions should appear.
// 1. Pick a scenario, which depends on the user's region and locale.
//
// 2. Set prefs on the default branch appropriate for the scenario. We use
// the default branch and not the user branch because conceptually each
@@ -720,24 +712,15 @@ class _QuickSuggest {
* The scenario the user should be enrolled in.
*/
_getIntendedFirefoxSuggestScenario() {
// If the user is in a Nimbus rollout, then Nimbus will define the scenario.
// Otherwise the user may be in a "hardcoded" rollout depending on their
// region and locale. If the user is not in any rollouts, then the scenario
// is "history", which means no Firefox Suggest suggestions will appear.
let scenario = lazy.NimbusFeatures.urlbar.getVariable(
"quickSuggestScenario"
);
if (!scenario) {
if (
lazy.Region.home == "US" &&
Services.locale.appLocaleAsBCP47.substring(0, 2) == "en"
) {
// offline rollout for en locales in the US region
scenario = "offline";
} else {
// no rollout
scenario = "history";
}
// The scenario depends on the user's region and locale. If Suggest should
// be disabled, then the scenario is "history".
let scenario = "history";
if (
lazy.Region.home == "US" &&
Services.locale.appLocaleAsBCP47.substring(0, 2) == "en"
) {
// offline rollout for en locales in the US region
scenario = "offline";
}
if (!this.DEFAULT_PREFS.hasOwnProperty(scenario)) {
console.error(`Unrecognized Firefox Suggest scenario "${scenario}"`);

View File

@@ -72,513 +72,6 @@ add_task(async function test_merino() {
});
});
add_task(async function test_scenario_offline() {
await doBasicScenarioTest("offline", {
urlbarPrefs: {
// prefs
"quicksuggest.scenario": "offline",
"quicksuggest.enabled": true,
"quicksuggest.dataCollection.enabled": false,
"suggest.quicksuggest.nonsponsored": true,
"suggest.quicksuggest.sponsored": true,
// Nimbus variables
quickSuggestScenario: "offline",
quickSuggestEnabled: true,
},
defaults: [
{
name: "browser.urlbar.quicksuggest.enabled",
value: true,
},
{
name: "browser.urlbar.quicksuggest.dataCollection.enabled",
value: false,
},
{
name: "browser.urlbar.suggest.quicksuggest.nonsponsored",
value: true,
},
{
name: "browser.urlbar.suggest.quicksuggest.sponsored",
value: true,
},
],
});
});
add_task(async function test_scenario_history() {
await doBasicScenarioTest("history", {
urlbarPrefs: {
// prefs
"quicksuggest.scenario": "history",
"quicksuggest.enabled": false,
// Nimbus variables
quickSuggestScenario: "history",
quickSuggestEnabled: false,
},
defaults: [
{
name: "browser.urlbar.quicksuggest.enabled",
value: false,
},
],
});
});
async function doBasicScenarioTest(scenario, expectedPrefs) {
await QuickSuggestTestUtils.withExperiment({
valueOverrides: {
quickSuggestScenario: scenario,
},
callback: () => {
// Pref updates should always settle down by the time enrollment is done.
Assert.ok(
!UrlbarPrefs.updatingFirefoxSuggestScenario,
"updatingFirefoxSuggestScenario is false"
);
assertScenarioPrefs(expectedPrefs);
},
});
// Similarly, pref updates should always settle down by the time unenrollment
// is done.
Assert.ok(
!UrlbarPrefs.updatingFirefoxSuggestScenario,
"updatingFirefoxSuggestScenario is false"
);
assertDefaultScenarioPrefs();
}
function assertScenarioPrefs({ urlbarPrefs, defaults }) {
for (let [name, value] of Object.entries(urlbarPrefs)) {
Assert.equal(UrlbarPrefs.get(name), value, `UrlbarPrefs.get("${name}")`);
}
let prefs = Services.prefs.getDefaultBranch("");
for (let { name, getter, value } of defaults) {
Assert.equal(
prefs[getter || "getBoolPref"](name),
value,
`Default branch pref: ${name}`
);
}
}
function assertDefaultScenarioPrefs() {
assertScenarioPrefs({
urlbarPrefs: {
"quicksuggest.scenario": "offline",
"quicksuggest.enabled": true,
"quicksuggest.dataCollection.enabled": false,
"suggest.quicksuggest.nonsponsored": true,
"suggest.quicksuggest.sponsored": true,
// No Nimbus variables since they're only available when an experiment is
// installed.
},
defaults: [
{
name: "browser.urlbar.quicksuggest.enabled",
value: true,
},
{
name: "browser.urlbar.quicksuggest.dataCollection.enabled",
value: false,
},
{
name: "browser.urlbar.suggest.quicksuggest.nonsponsored",
value: true,
},
{
name: "browser.urlbar.suggest.quicksuggest.sponsored",
value: true,
},
],
});
}
function clearOnboardingPrefs() {
UrlbarPrefs.clear("suggest.quicksuggest.nonsponsored");
UrlbarPrefs.clear("suggest.quicksuggest.sponsored");
UrlbarPrefs.clear("quicksuggest.dataCollection.enabled");
UrlbarPrefs.clear("quicksuggest.showedOnboardingDialog");
UrlbarPrefs.clear("quicksuggest.seenRestarts");
}
// The following tasks test Nimbus enrollments
// Initial state:
// * History (quick suggest feature disabled)
//
// Enrollment:
// * History
//
// Expected:
// * All history prefs set on the default branch
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.history,
},
valueOverrides: {
quickSuggestScenario: "history",
},
expectedPrefs: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.history,
},
});
});
// Initial state:
// * History (quick suggest feature disabled)
//
// Enrollment:
// * Offline
//
// Expected:
// * All offline prefs set on the default branch
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.history,
},
valueOverrides: {
quickSuggestScenario: "offline",
},
expectedPrefs: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
},
});
});
// The following tasks test OFFLINE TO OFFLINE
// Initial state:
// * Offline (suggestions on and data collection off by default)
// * User did not override any defaults
//
// Enrollment:
// * Offline
//
// Expected:
// * All offline prefs set on the default branch
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
},
valueOverrides: {
quickSuggestScenario: "offline",
},
expectedPrefs: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
},
});
});
// Initial state:
// * Offline (suggestions on and data collection off by default)
// * Non-sponsored suggestions: user left on
// * Sponsored suggestions: user turned off
// * Data collection: user left off
//
// Enrollment:
// * Offline
//
// Expected:
// * Non-sponsored suggestions: remain on
// * Sponsored suggestions: remain off
// * Data collection: remains off
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"suggest.quicksuggest.sponsored": false,
},
},
valueOverrides: {
quickSuggestScenario: "offline",
},
expectedPrefs: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"suggest.quicksuggest.sponsored": false,
},
},
});
});
// Initial state:
// * Offline (suggestions on and data collection off by default)
// * Non-sponsored suggestions: user turned off
// * Sponsored suggestions: user left on
// * Data collection: user left off
//
// Enrollment:
// * Offline
//
// Expected:
// * Non-sponsored suggestions: remain off
// * Sponsored suggestions: remain on
// * Data collection: remains off
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"suggest.quicksuggest.nonsponsored": false,
},
},
valueOverrides: {
quickSuggestScenario: "offline",
},
expectedPrefs: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"suggest.quicksuggest.nonsponsored": false,
},
},
});
});
// Initial state:
// * Offline (suggestions on and data collection off by default)
// * Non-sponsored suggestions: user turned off
// * Sponsored suggestions: user turned off
// * Data collection: user left off
//
// Enrollment:
// * Offline
//
// Expected:
// * Non-sponsored suggestions: remain off
// * Sponsored suggestions: remain off
// * Data collection: remains off
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"suggest.quicksuggest.nonsponsored": false,
"suggest.quicksuggest.sponsored": false,
},
},
valueOverrides: {
quickSuggestScenario: "offline",
},
expectedPrefs: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"suggest.quicksuggest.nonsponsored": false,
"suggest.quicksuggest.sponsored": false,
},
},
});
});
// Initial state:
// * Offline (suggestions on and data collection off by default)
// * Non-sponsored suggestions: user left on
// * Sponsored suggestions: user left on
// * Data collection: user turned on
//
// Enrollment:
// * Offline
//
// Expected:
// * Non-sponsored suggestions: remain on
// * Sponsored suggestions: remain on
// * Data collection: remains on
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"quicksuggest.dataCollection.enabled": true,
},
},
valueOverrides: {
quickSuggestScenario: "offline",
},
expectedPrefs: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"quicksuggest.dataCollection.enabled": true,
},
},
});
});
// Initial state:
// * Offline (suggestions on and data collection off by default)
// * Non-sponsored suggestions: user turned off
// * Sponsored suggestions: user turned off
// * Data collection: user turned on
//
// Enrollment:
// * Offline
//
// Expected:
// * Non-sponsored suggestions: remain off
// * Sponsored suggestions: remain off
// * Data collection: remains on
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"suggest.quicksuggest.nonsponsored": false,
"suggest.quicksuggest.sponsored": false,
"quicksuggest.dataCollection.enabled": true,
},
},
valueOverrides: {
quickSuggestScenario: "offline",
},
expectedPrefs: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"suggest.quicksuggest.nonsponsored": false,
"suggest.quicksuggest.sponsored": false,
"quicksuggest.dataCollection.enabled": true,
},
},
});
});
// The following tasks test scenarios in conjunction with individual Nimbus
// variables
// Initial state:
// * Offline (suggestions on and data collection off by default)
// * User did not override any defaults
//
// Enrollment:
// * Offline
// * Sponsored suggestions individually forced on
//
// Expected:
// * Sponsored suggestions: on
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
},
valueOverrides: {
quickSuggestScenario: "offline",
quickSuggestSponsoredEnabled: true,
},
expectedPrefs: {
defaultBranch: {
...QuickSuggest.DEFAULT_PREFS.offline,
"suggest.quicksuggest.sponsored": true,
},
},
});
});
// Initial state:
// * Offline (suggestions on and data collection off by default)
// * Sponsored suggestions: user turned off
//
// Enrollment:
// * Offline
// * Sponsored suggestions individually forced on
//
// Expected:
// * Sponsored suggestions: remain off
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"suggest.quicksuggest.sponsored": false,
},
},
valueOverrides: {
quickSuggestScenario: "offline",
quickSuggestSponsoredEnabled: true,
},
expectedPrefs: {
defaultBranch: {
...QuickSuggest.DEFAULT_PREFS.offline,
"suggest.quicksuggest.sponsored": true,
},
userBranch: {
"suggest.quicksuggest.sponsored": false,
},
},
});
});
// Initial state:
// * Offline (suggestions on and data collection off by default)
// * User did not override any defaults
//
// Enrollment:
// * Offline
// * Data collection individually forced on
//
// Expected:
// * Data collection: on
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
},
valueOverrides: {
quickSuggestScenario: "offline",
quickSuggestDataCollectionEnabled: true,
},
expectedPrefs: {
defaultBranch: {
...QuickSuggest.DEFAULT_PREFS.offline,
"quicksuggest.dataCollection.enabled": true,
},
},
});
});
// Initial state:
// * Offline (suggestions on and data collection off by default)
// * Data collection: user turned off (it's off by default, so this simulates
// when the user toggled it on and then back off)
//
// Enrollment:
// * Offline
// * Data collection individually forced on
//
// Expected:
// * Data collection: remains off
add_task(async function () {
await checkEnrollments({
initialPrefsToSet: {
defaultBranch: QuickSuggest.DEFAULT_PREFS.offline,
userBranch: {
"quicksuggest.dataCollection.enabled": false,
},
},
valueOverrides: {
quickSuggestScenario: "offline",
quickSuggestDataCollectionEnabled: true,
},
expectedPrefs: {
defaultBranch: {
...QuickSuggest.DEFAULT_PREFS.offline,
"quicksuggest.dataCollection.enabled": true,
},
userBranch: {
"quicksuggest.dataCollection.enabled": false,
},
},
});
});
// The following tasks test individual Nimbus variables without scenarios
// Initial state:

View File

@@ -445,13 +445,6 @@ urlbar:
- default
- interest
- random
quickSuggestScenario:
# IMPORTANT: This should not have a fallbackPref. See UrlbarPrefs.sys.mjs.
type: string
description: The Firefox Suggest scenario in which the user is enrolled
enum:
- history
- offline
quickSuggestScoreMap:
type: json
description: >-