tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 61440368f6511ef0a3736de2841a9a841b28c9fb
parent a0ac34d4a8e9c02cc61acd0a2d3a82ae054b6b8f
Author: Drew Willcoxon <adw@mozilla.com>
Date:   Mon, 27 Oct 2025 22:28:20 +0000

Bug 1995929 - Fix a broken old Suggest migration and improve migration tests. r=daisuke

This fixes the bug and updates `test_quicksuggest_defaultPrefs.js` so that it
makes sure a full migration does not unexpectedly set any prefs on the user
branch. That would have caught the bug.

I also went ahead and finished the improvements to the migration tests that I
was making when I found the bug. The tests were too complex and doing more than
they need to. The main points are: they each should test a single migration step
from one version to the next, and they only need to check user-branch values.

I made some changes to `QuickSuggest` too so that it's clearer that migrations
should only be concerned with user-branch values.

I removed the v3 test because we removed that migration recently, and now that
these tests only test a single migration step, it's not needed anymore.

Depends on D269324

Differential Revision: https://phabricator.services.mozilla.com/D269720

Diffstat:
Mbrowser/components/urlbar/QuickSuggest.sys.mjs | 115+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Mbrowser/components/urlbar/UrlbarPrefs.sys.mjs | 16+---------------
Mbrowser/components/urlbar/tests/quicksuggest/unit/head.js | 257+++++++++++++++++++++++++++++++------------------------------------------------
Mbrowser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_defaultPrefs.js | 25++++++++++++++++++++-----
Mbrowser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v1.js | 240++++++-------------------------------------------------------------------------
Mbrowser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v2.js | 228+++++++++++++------------------------------------------------------------------
Dbrowser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v3.js | 68--------------------------------------------------------------------
Mbrowser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v4.js | 63++++++++++++++-------------------------------------------------
Abrowser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v5.js | 171+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mbrowser/components/urlbar/tests/quicksuggest/unit/xpcshell.toml | 4++--
10 files changed, 435 insertions(+), 752 deletions(-)

diff --git a/browser/components/urlbar/QuickSuggest.sys.mjs b/browser/components/urlbar/QuickSuggest.sys.mjs @@ -45,7 +45,7 @@ const EN_LOCALES = ["en-CA", "en-GB", "en-US", "en-ZA"]; * @property {string} [nimbusVariableIfExposedInUi] * If the pref is exposed in the settings UI and it's a fallback for a Nimbus * variable, then this should be set to the variable's name. See point 3 in - * the comment in `#initDefaultPrefs()` for more. + * the comment in `#initPrefs()` for more. */ /** @@ -314,7 +314,7 @@ class _QuickSuggest { * Initializes Suggest. It's safe to call more than once. * * @param {object} testOverrides - * This is intended for tests only. See `#initDefaultPrefs()`. + * This is intended for tests only. See `#initPrefs()`. */ async init(testOverrides = null) { if (this.#initStarted) { @@ -337,7 +337,7 @@ class _QuickSuggest { await lazy.TelemetryEnvironment.onInitialized(); } - this.#initDefaultPrefs(testOverrides); + this.#initPrefs(testOverrides); // Create an instance of each feature and keep it in `#featuresByName`. for (let [name, uri] of Object.entries(FEATURES)) { @@ -727,7 +727,7 @@ class _QuickSuggest { * This is intended for tests only. Pass to force the following: * `{ region, locale, migrationVersion, defaultPrefs }` */ - #initDefaultPrefs(testOverrides = null) { + #initPrefs(testOverrides = null) { // Updating prefs is tricky and it's important to preserve the user's // choices, so we describe the process in detail below. tl;dr: // @@ -829,10 +829,10 @@ class _QuickSuggest { // settings UI and configurable via Nimbus. this.#syncNimbusVariablesToUiPrefs(); - // 4. Migrate prefs across app versions. + // 4. Migrate user-branch prefs across app versions. let shouldEnableSuggest = !!this.#intendedDefaultPrefs["quicksuggest.enabled"]; - this._ensureFirefoxSuggestPrefsMigrated(shouldEnableSuggest, testOverrides); + this.#ensureUserPrefsMigrated(shouldEnableSuggest, testOverrides); } /** @@ -889,12 +889,12 @@ class _QuickSuggest { * @returns {number} */ get MIGRATION_VERSION() { - return 4; + return 5; } /** - * Migrates Firefox Suggest prefs to the current version if they haven't been - * migrated already. + * Migrates user-branch Suggest prefs to the current version if they haven't + * been migrated already. * * @param {boolean} shouldEnableSuggest * Whether Suggest should be enabled right now. @@ -902,7 +902,7 @@ class _QuickSuggest { * This is intended for tests only. Pass to force a migration version: * `{ migrationVersion }` */ - _ensureFirefoxSuggestPrefsMigrated(shouldEnableSuggest, testOverrides) { + #ensureUserPrefsMigrated(shouldEnableSuggest, testOverrides) { let currentVersion = testOverrides?.migrationVersion !== undefined ? testOverrides.migrationVersion @@ -917,12 +917,13 @@ class _QuickSuggest { } // Migrate from the last-seen version up to the current version. + let userBranch = Services.prefs.getBranch("browser.urlbar."); let version = lastSeenVersion; for (; version < currentVersion; version++) { let nextVersion = version + 1; - let methodName = "_migrateFirefoxSuggestPrefsTo_" + nextVersion; + let methodName = "_migrateUserPrefsTo_" + nextVersion; try { - this[methodName](shouldEnableSuggest); + this[methodName](userBranch, shouldEnableSuggest); } catch (error) { console.error( `Error migrating Firefox Suggest prefs to version ${nextVersion}:`, @@ -936,16 +937,29 @@ class _QuickSuggest { lazy.UrlbarPrefs.set("quicksuggest.migrationVersion", version); } - _migrateFirefoxSuggestPrefsTo_1(shouldEnableSuggest) { + _migrateUserPrefsTo_1(userBranch, shouldEnableSuggest) { + // Previously prefs were unversioned and worked like this: When + // `suggest.quicksuggest` is false, all quick suggest results are disabled + // and `suggest.quicksuggest.sponsored` is ignored. To show sponsored + // suggestions, both prefs must be true. + // + // Version 1 makes the following changes: + // + // `suggest.quicksuggest` is removed, `suggest.quicksuggest.nonsponsored` is + // introduced. `suggest.quicksuggest.nonsponsored` and + // `suggest.quicksuggest.sponsored` are independent: + // `suggest.quicksuggest.nonsponsored` controls non-sponsored results and + // `suggest.quicksuggest.sponsored` controls sponsored results. + // `quicksuggest.dataCollection.enabled` is introduced. + // Copy `suggest.quicksuggest` to `suggest.quicksuggest.nonsponsored` and // clear the first. - let suggestQuicksuggest = "browser.urlbar.suggest.quicksuggest"; - if (Services.prefs.prefHasUserValue(suggestQuicksuggest)) { - lazy.UrlbarPrefs.set( + if (userBranch.prefHasUserValue("suggest.quicksuggest")) { + userBranch.setBoolPref( "suggest.quicksuggest.nonsponsored", - Services.prefs.getBoolPref(suggestQuicksuggest) + userBranch.getBoolPref("suggest.quicksuggest") ); - Services.prefs.clearUserPref(suggestQuicksuggest); + userBranch.clearUserPref("suggest.quicksuggest"); } // In the unversioned prefs, sponsored suggestions were shown only if the @@ -953,56 +967,75 @@ class _QuickSuggest { // two independent prefs, so disable sponsored if the main pref was false. if ( shouldEnableSuggest && - !lazy.UrlbarPrefs.get("suggest.quicksuggest.nonsponsored") + userBranch.prefHasUserValue("suggest.quicksuggest.nonsponsored") && + !userBranch.getBoolPref("suggest.quicksuggest.nonsponsored") ) { // Set the pref on the user branch. Suggestions are enabled by default // for offline; we want to preserve the user's choice of opting out, // and we want to preserve the default-branch true value. - lazy.UrlbarPrefs.set("suggest.quicksuggest.sponsored", false); + userBranch.setBoolPref("suggest.quicksuggest.sponsored", false); } } - _migrateFirefoxSuggestPrefsTo_2() { + _migrateUserPrefsTo_2(userBranch) { + // For online, the defaults for `suggest.quicksuggest.nonsponsored` and + // `suggest.quicksuggest.sponsored` are now true. Previously they were + // false. + // In previous versions of the prefs for online, suggestions were disabled // by default; in version 2, they're enabled by default. For users who were // already in online and did not enable suggestions (because they did not // opt in, they did opt in but later disabled suggestions, or they were not // shown the modal) we don't want to suddenly enable them, so if the prefs // do not have user-branch values, set them to false. - let scenario = Services.prefs.getCharPref( - "browser.urlbar.quicksuggest.scenario", - "" - ); + let scenario = userBranch.getCharPref("quicksuggest.scenario", ""); if (scenario == "online") { - if ( - !Services.prefs.prefHasUserValue( - "browser.urlbar.suggest.quicksuggest.nonsponsored" - ) - ) { - lazy.UrlbarPrefs.set("suggest.quicksuggest.nonsponsored", false); + if (!userBranch.prefHasUserValue("suggest.quicksuggest.nonsponsored")) { + userBranch.setBoolPref("suggest.quicksuggest.nonsponsored", false); } - if ( - !Services.prefs.prefHasUserValue( - "browser.urlbar.suggest.quicksuggest.sponsored" - ) - ) { - lazy.UrlbarPrefs.set("suggest.quicksuggest.sponsored", false); + if (!userBranch.prefHasUserValue("suggest.quicksuggest.sponsored")) { + userBranch.setBoolPref("suggest.quicksuggest.sponsored", false); } } } - _migrateFirefoxSuggestPrefsTo_3() { + _migrateUserPrefsTo_3() { // This used to check the `quicksuggest.dataCollection.enabled` preference // and set `quicksuggest.settingsUi` to `SETTINGS_UI.FULL` if data collection // was enabled. However, this is now cleared for everyone in the v4 migration, // hence there is nothing to do here. } - _migrateFirefoxSuggestPrefsTo_4() { + _migrateUserPrefsTo_4(userBranch) { // This will reset the pref to the default value, i.e. SETTINGS_UI.OFFLINE_ONLY // for users where suggest is enabled, or SETTINGS_UI.NONE where it is not // enabled. - lazy.UrlbarPrefs.clear("quicksuggest.settingsUi"); + userBranch.clearUserPref("quicksuggest.settingsUi"); + } + + _migrateUserPrefsTo_5(userBranch) { + // This migration clears the sponsored pref for region-locales where, at the + // time of this migration, the Suggest technical platform is enabled + // (`quicksuggest.enabled` is true) but features that are part of the + // Suggest brand are not. It was incorrectly set to false on the user branch + // due to the combination of two things: + // + // 1. In 146, bug 1992811 enabled the Suggest platform for `en` locales in + // DE, FR, and IT in order to ship important-dates suggestions, which + // aren't considered part of the Suggest brand. For these region-locales, + // `quicksuggest.enabled` was defaulted to true and the sponsored and + // nonsponsored prefs retained their false values from `firefox.js`. + // 2. A previous implementation of the version 1 migration incorrectly set + // the sponsored pref to false on the user branch if + // `quicksuggest.enabled` is true and the nonsponsored pref is false on + // either the user or default branch. The migration should have only + // checked the user branch and has since been fixed. + if ( + ["DE", "FR", "IT"].includes(lazy.Region.home) && + EN_LOCALES.includes(Services.locale.appLocaleAsBCP47) + ) { + userBranch.clearUserPref("suggest.quicksuggest.sponsored"); + } } async _test_reset(testOverrides = null) { @@ -1014,7 +1047,7 @@ class _QuickSuggest { await this.rustBackend.ingestPromise; } - this.#initDefaultPrefs(testOverrides); + this.#initPrefs(testOverrides); this.#updateAll(); if (this.rustBackend) { // `#updateAll()` triggers ingest, so wait for it to finish. diff --git a/browser/components/urlbar/UrlbarPrefs.sys.mjs b/browser/components/urlbar/UrlbarPrefs.sys.mjs @@ -320,21 +320,7 @@ const PREF_URLBAR_DEFAULTS = /** @type {PreferenceDefinition[]} */ ([ // If the user has gone through a quick suggest prefs migration, then this // pref will have a user-branch value that records the latest prefs version. - // Version changelog: - // - // 0: (Unversioned) When `suggest.quicksuggest` is false, all quick suggest - // results are disabled and `suggest.quicksuggest.sponsored` is ignored. To - // show sponsored suggestions, both prefs must be true. - // - // 1: `suggest.quicksuggest` is removed, `suggest.quicksuggest.nonsponsored` - // is introduced. `suggest.quicksuggest.nonsponsored` and - // `suggest.quicksuggest.sponsored` are independent: - // `suggest.quicksuggest.nonsponsored` controls non-sponsored results and - // `suggest.quicksuggest.sponsored` controls sponsored results. - // `quicksuggest.dataCollection.enabled` is introduced. - // - // 2: For online, the defaults for `suggest.quicksuggest.nonsponsored` and - // `suggest.quicksuggest.sponsored` are true. Previously they were false. + // See `QuickSuggest` for details on each version. ["quicksuggest.migrationVersion", 0], // Whether Suggest will use the ML backend in addition to Rust. diff --git a/browser/components/urlbar/tests/quicksuggest/unit/head.js b/browser/components/urlbar/tests/quicksuggest/unit/head.js @@ -5,6 +5,7 @@ /* eslint-disable jsdoc/require-param */ ChromeUtils.defineESModuleGetters(this, { + Preferences: "resource://gre/modules/Preferences.sys.mjs", QuickSuggest: "moz-src:///browser/components/urlbar/QuickSuggest.sys.mjs", SearchUtils: "moz-src:///toolkit/components/search/SearchUtils.sys.mjs", TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.sys.mjs", @@ -25,203 +26,143 @@ add_setup(async function setUpQuickSuggestXpcshellTest() { }); /** - * Tests quick suggest prefs migrations. + * Sets up a test so it can use `doMigrateTest`. The app's region and locale + * will be set to US and en-US. Use `QuickSuggestTestUtils.withRegionAndLocale` + * or `setRegionAndLocale` if you need to test migration in a different region + * or locale. + */ +async function setUpMigrateTest() { + await UrlbarTestUtils.initNimbusFeature(); + await QuickSuggestTestUtils.setRegionAndLocale({ + region: "US", + locale: "en-US", + }); +} + +/** + * Tests a single Suggest prefs migration, from one version to the next. Call + * `setUpMigrateTest` in your setup task before using this. To test migration in + * a region and locale other than US and en-US, wrap your `doMigrateTest` call + * in `QuickSuggestTestUtils.withRegionAndLocale`. * * @param {object} options * The options object. - * @param {object} options.testOverrides - * An object that modifies how migration is performed. It has the following - * properties, and all are optional: - * - * {number} migrationVersion - * Migration will stop at this version, so for example you can test - * migration only up to version 1 even when the current actual version is - * larger than 1. - * {object} defaultPrefs - * An object that maps pref names (relative to `browser.urlbar`) to - * default-branch values. These should be the default prefs for the given - * `migrationVersion` and will be set as defaults before migration occurs. - * - * @param {object} options.expectedPrefs - * The expected prefs after migration: `{ defaultBranch, userBranch }` - * Pref names should be relative to `browser.urlbar`. - * @param {boolean} options.shouldEnable - * Whether Suggest should be enabled when migration occurs. - * @param {object} [options.initialUserBranch] - * Prefs to set on the user branch before migration ocurs. Use these to - * simulate user actions like disabling prefs or opting in or out of the - * online modal. Pref names should be relative to `browser.urlbar`. + * @param {number} options.toVersion + * The version to test. Migration from `toVersion - 1` to `toVersion` will be + * performed. + * @param {object} [options.preMigrationUserPrefs] + * Prefs to set on the user branch before migration. An object that maps pref + * names relative to `browser.urlbar.` to values. + * @param {object} [options.expectedPostMigrationUserPrefs] + * Prefs that are expected to be set on the user branch after migration. An + * object that maps pref names relative to `browser.urlbar.` to values. If a + * pref is expected to be set on the user branch before migration but cleared + * after migration, set its value to `null`. */ async function doMigrateTest({ - testOverrides, - expectedPrefs, - shouldEnable = true, - initialUserBranch = {}, + toVersion, + preMigrationUserPrefs = {}, + expectedPostMigrationUserPrefs = {}, }) { info( "Testing migration: " + JSON.stringify({ - testOverrides, - initialUserBranch, - shouldEnable, - expectedPrefs, + toVersion, + preMigrationUserPrefs, + expectedPostMigrationUserPrefs, }) ); - function setPref(branch, name, value) { - switch (typeof value) { - case "boolean": - branch.setBoolPref(name, value); - break; - case "number": - branch.setIntPref(name, value); - break; - case "string": - branch.setCharPref(name, value); - break; - default: - Assert.ok( - false, - `Pref type not handled for setPref: ${name} = ${value}` - ); - break; - } - } + // Prefs whose user-branch values we should always make sure to check. + // Includes obsolete prefs since they're relevant to some older migrations. + let userPrefsToAlwaysCheck = [ + "quicksuggest.dataCollection.enabled", + "quicksuggest.enabled", + "suggest.quicksuggest", + "suggest.quicksuggest.nonsponsored", + "suggest.quicksuggest.sponsored", + ]; - function getPref(branch, name) { - let type = typeof UrlbarPrefs.get(name); - switch (type) { - case "boolean": - return branch.getBoolPref(name); - case "number": - return branch.getIntPref(name); - case "string": - return branch.getCharPref(name); - default: - Assert.ok(false, `Pref type not handled for getPref: ${name} ${type}`); - break; - } - return null; + let userBranch = new Preferences({ + branch: "browser.urlbar.", + defaultBranch: false, + }); + + // Set the last-seen migration version to `toVersion - 1`. + if (toVersion == 1) { + userBranch.reset("quicksuggest.migrationVersion"); + } else { + userBranch.set("quicksuggest.migrationVersion", toVersion - 1); } - let defaultBranch = Services.prefs.getDefaultBranch("browser.urlbar."); - let userBranch = Services.prefs.getBranch("browser.urlbar."); - - // Set initial prefs. `initialDefaultBranch` are firefox.js values, i.e., - // defaults immediately after startup, before Suggest init and migration. - UrlbarPrefs.clear("quicksuggest.migrationVersion"); - let initialDefaultBranch = { - "suggest.quicksuggest.nonsponsored": false, - "suggest.quicksuggest.sponsored": false, - // This pref is obsolete but it's used by old migrations that we still test. - "quicksuggest.dataCollection.enabled": false, - }; - for (let name of Object.keys(initialDefaultBranch)) { - userBranch.clearUserPref(name); + // Set pre-migration user prefs. + for (let [name, value] of Object.entries(preMigrationUserPrefs)) { + userBranch.set(name, value); } - for (let [branch, prefs] of [ - [defaultBranch, initialDefaultBranch], - [userBranch, initialUserBranch], - ]) { - for (let [name, value] of Object.entries(prefs)) { - if (value !== undefined) { - setPref(branch, name, value); - } + + // Record values for prefs in `userPrefsToAlwaysCheck` that weren't just set + // above, so that we can use them later. + for (let name of userPrefsToAlwaysCheck) { + if (!preMigrationUserPrefs.hasOwnProperty(name)) { + preMigrationUserPrefs[name] = userBranch.isSet(name) + ? userBranch.get(name) + : null; } } + // The entire set of prefs that should be checked after migration. + let userPrefsToCheckPostMigration = new Set([ + ...Object.keys(preMigrationUserPrefs), + ...Object.keys(expectedPostMigrationUserPrefs), + ]); + // Reinitialize Suggest and check prefs twice. The first time the migration // should happen, and the second time the migration should not happen and // all the prefs should stay the same. for (let i = 0; i < 2; i++) { info(`Reinitializing Suggest, i=${i}`); - // Reinitialize Suggest. + // Reinitialize Suggest, which includes migration. await QuickSuggest._test_reset({ - ...testOverrides, - region: shouldEnable ? "US" : "XX", - locale: shouldEnable ? "en-US" : "xx-XX", + migrationVersion: toVersion, }); - // Check expected pref values. Store expected effective values as we go so - // we can check them afterward. For a given pref, the expected effective - // value is the user value, or if there's not a user value, the default - // value. - let expectedEffectivePrefs = {}; - let { - defaultBranch: expectedDefaultBranch, - userBranch: expectedUserBranch, - } = expectedPrefs; - expectedDefaultBranch = expectedDefaultBranch || {}; - expectedUserBranch = expectedUserBranch || {}; - for (let [branch, prefs, branchType] of [ - [defaultBranch, expectedDefaultBranch, "default"], - [userBranch, expectedUserBranch, "user"], - ]) { - let entries = Object.entries(prefs); - if (!entries.length) { - continue; - } - - info( - `Checking expected prefs on ${branchType} branch after Suggest init` - ); - for (let [name, value] of entries) { - expectedEffectivePrefs[name] = value; - if (branch == userBranch) { - Assert.ok( - userBranch.prefHasUserValue(name), - `Pref ${name} is on user branch` - ); - } - Assert.equal( - getPref(branch, name), - value, - `Pref ${name} value on ${branchType} branch` + for (let name of userPrefsToCheckPostMigration) { + // The expected value is the expected post-migration value, if any; + // otherwise it's the pre-migration value. + let expectedValue = expectedPostMigrationUserPrefs.hasOwnProperty(name) + ? expectedPostMigrationUserPrefs[name] + : preMigrationUserPrefs[name]; + if (expectedValue === null) { + Assert.ok( + !userBranch.isSet(name), + "Pref should not have a user value after migration: " + name ); - } - } - - info( - `Making sure prefs on the default branch without expected user-branch values are not on the user branch` - ); - for (let name of Object.keys(initialDefaultBranch)) { - if (!expectedUserBranch.hasOwnProperty(name)) { + } else { Assert.ok( - !userBranch.prefHasUserValue(name), - `Pref ${name} is not on user branch` + userBranch.isSet(name), + "Pref should have a user value after migration: " + name + ); + Assert.equal( + userBranch.get(name), + expectedValue, + "Pref should have been set to the expected value after migration: " + + name ); } } - info(`Checking expected effective prefs`); - for (let [name, value] of Object.entries(expectedEffectivePrefs)) { - Assert.equal( - UrlbarPrefs.get(name), - value, - `Pref ${name} effective value` - ); - } - - let currentVersion = - testOverrides?.migrationVersion === undefined - ? QuickSuggest.MIGRATION_VERSION - : testOverrides.migrationVersion; Assert.equal( - UrlbarPrefs.get("quicksuggest.migrationVersion"), - currentVersion, - "quicksuggest.migrationVersion is correct after migration" + userBranch.get("quicksuggest.migrationVersion"), + toVersion, + "quicksuggest.migrationVersion should be updated after migration" ); } // Clean up. - UrlbarPrefs.clear("quicksuggest.migrationVersion"); - let userBranchNames = [ - ...Object.keys(initialUserBranch), - ...Object.keys(expectedPrefs.userBranch || {}), - ]; - for (let name of userBranchNames) { - userBranch.clearUserPref(name); + userBranch.reset("quicksuggest.migrationVersion"); + for (let name of userPrefsToCheckPostMigration) { + userBranch.reset(name); } } diff --git a/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_defaultPrefs.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_defaultPrefs.js @@ -156,18 +156,27 @@ async function doTest({ locale, region }) { EXPECTED_PREFS_BY_LOCALE_BY_REGION[region]?.[locale] ?? EXPECTED_PREFS_SUGGEST_DISABLED; - let defaults = new Preferences({ + let defaultBranch = new Preferences({ branch: "browser.urlbar.", defaultBranch: true, }); + let userBranch = new Preferences({ + branch: "browser.urlbar.", + defaultBranch: false, + }); // Setup: Clear any user values and save original default-branch values. let originalDefaults = {}; for (let name of Object.keys(expectedPrefs)) { - Services.prefs.clearUserPref("browser.urlbar." + name); - originalDefaults[name] = defaults.get(name); + userBranch.reset(name); + originalDefaults[name] = defaultBranch.get(name); } + // Clear the migration version to simulate a new profile. `QuickSuggest` will + // perform a full migration process, applying each migration version in turn + // until it reaches the current version. + userBranch.reset("quicksuggest.migrationVersion"); + // Set the region and locale, call the function, check the pref values. await QuickSuggestTestUtils.withRegionAndLocale({ region, @@ -176,7 +185,7 @@ async function doTest({ locale, region }) { for (let [name, value] of Object.entries(expectedPrefs)) { // Check the default-branch value. Assert.strictEqual( - defaults.get(name), + defaultBranch.get(name), value, `Default pref value for ${name}, locale ${locale}, region ${region}` ); @@ -189,6 +198,12 @@ async function doTest({ locale, region }) { value, `UrlbarPrefs.get() value for ${name}, locale ${locale}, region ${region}` ); + + // Make sure migration didn't unexpectedly set any user-branch values. + Assert.ok( + !userBranch.isSet(name), + "Pref should not be set on the user branch: " + name + ); } }, }); @@ -198,7 +213,7 @@ async function doTest({ locale, region }) { if (originalDefault === undefined) { Services.prefs.deleteBranch("browser.urlbar." + name); } else { - defaults.set(name, originalDefault); + defaultBranch.set(name, originalDefault); } } } diff --git a/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v1.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v1.js @@ -2,254 +2,48 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -// Tests quick suggest prefs migration from unversioned prefs to version 1. +// Tests Suggest prefs migration from unversioned prefs to version 1. "use strict"; -// Expected version 1 default-branch prefs -const DEFAULT_PREFS = { - "quicksuggest.enabled": true, - "quicksuggest.dataCollection.enabled": false, - "suggest.quicksuggest.nonsponsored": true, - "suggest.quicksuggest.sponsored": true, -}; - -// Migration will use these values to migrate only up to version 1 instead of -// the current version. -const TEST_OVERRIDES = { - migrationVersion: 1, - defaultPrefs: DEFAULT_PREFS, -}; +const TO_VERSION = 1; add_setup(async () => { - await UrlbarTestUtils.initNimbusFeature(); + await setUpMigrateTest(); }); -// The following tasks test OFFLINE to version 1 when SUGGEST IS ENABLED - -// Migrating from: -// * Offline (Suggest enabled by default) -// * User did not override any defaults -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * Non-sponsored suggestions: remain on -// * Sponsored suggestions: remain on -// * Data collection: off +// No user-branch values set add_task(async function () { await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - shouldEnable: true, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - }, - }); -}); - -// Migrating from: -// * Offline (Suggest enabled by default) -// * Main suggestions pref: user left on -// * Sponsored suggestions: user turned off -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * Non-sponsored suggestions: on -// * Sponsored suggestions: remain off -// * Data collection: off -add_task(async function () { - await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "suggest.quicksuggest.sponsored": false, - }, - shouldEnable: true, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.sponsored": false, - }, - }, + toVersion: TO_VERSION, }); }); -// Migrating from: -// * Offline (Suggest enabled by default) -// * Main suggestions pref: user turned off -// * Sponsored suggestions: user left on (but ignored since main was off) -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * Non-sponsored suggestions: off -// * Sponsored suggestions: off -// * Data collection: off +// Migrating from Suggest disabled add_task(async function () { await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { + toVersion: TO_VERSION, + preMigrationUserPrefs: { "suggest.quicksuggest": false, }, - shouldEnable: true, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.nonsponsored": false, - "suggest.quicksuggest.sponsored": false, - }, - }, - }); -}); - -// Migrating from: -// * Offline (Suggest enabled by default) -// * Main suggestions pref: user turned off -// * Sponsored suggestions: user turned off -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * Non-sponsored suggestions: off -// * Sponsored suggestions: off -// * Data collection: off -add_task(async function () { - await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "suggest.quicksuggest": false, + expectedPostMigrationUserPrefs: { + "suggest.quicksuggest": null, + "suggest.quicksuggest.nonsponsored": false, "suggest.quicksuggest.sponsored": false, }, - shouldEnable: true, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.nonsponsored": false, - "suggest.quicksuggest.sponsored": false, - }, - }, - }); -}); - -// The following tasks test ONLINE to version 1 when SUGGEST IS ENABLED - -// Migrating from: -// * Online (Suggest enabled but suggestions off by default) -// * User did not override any defaults -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * Non-sponsored suggestions: on (since main pref had default value) -// * Sponsored suggestions: on (since main & sponsored prefs had default values) -// * Data collection: off -add_task(async function () { - await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - shouldEnable: true, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - }, - }); -}); - -// Migrating from: -// * Online (Suggest enabled but suggestions off by default) -// * Main suggestions pref: user left off -// * Sponsored suggestions: user turned on (but ignored since main was off) -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * Non-sponsored suggestions: off -// * Sponsored suggestions: on (see below) -// * Data collection: off -// -// It's unfortunate that sponsored suggestions are ultimately on since before -// the migration no suggestions were shown to the user. There's nothing we can -// do about it, aside from forcing off suggestions in more cases than we want. -// The reason is that at the time of migration we can't tell that the previous -// scenario was online -- or more precisely that it wasn't history. If we knew -// it wasn't history, then we'd know to turn sponsored off; if we knew it *was* -// history, then we'd know to turn sponsored -- and non-sponsored -- on, since -// the scenario at the time of migration is offline, where suggestions should be -// enabled by default. -add_task(async function () { - await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "suggest.quicksuggest.sponsored": true, - }, - shouldEnable: true, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.sponsored": true, - }, - }, - }); -}); - -// Migrating from: -// * Online (Suggest enabled but suggestions off by default) -// * Main suggestions pref: user turned on -// * Sponsored suggestions: user left off -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * Non-sponsored suggestions: remain on -// * Sponsored suggestions: remain off -// * Data collection: off -add_task(async function () { - await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "suggest.quicksuggest": true, - }, - shouldEnable: true, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.nonsponsored": true, - }, - }, }); }); -// Migrating from: -// * Online (Suggest enabled but suggestions off by default) -// * Main suggestions pref: user turned on -// * Sponsored suggestions: user turned on -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * Non-sponsored suggestions: remain on -// * Sponsored suggestions: remain on -// * Data collection: off +// Migrating from Suggest enabled add_task(async function () { await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { + toVersion: TO_VERSION, + preMigrationUserPrefs: { "suggest.quicksuggest": true, - "suggest.quicksuggest.sponsored": true, }, - shouldEnable: true, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.nonsponsored": true, - "suggest.quicksuggest.sponsored": true, - }, + expectedPostMigrationUserPrefs: { + "suggest.quicksuggest": null, + "suggest.quicksuggest.nonsponsored": true, }, }); }); diff --git a/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v2.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v2.js @@ -2,235 +2,81 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -// Tests quick suggest prefs migration to version 2. +// Tests Suggest prefs migration from version 1 to 2. "use strict"; -// Expected version 2 default-branch prefs -const DEFAULT_PREFS = { - "quicksuggest.enabled": true, - "quicksuggest.dataCollection.enabled": false, - "suggest.quicksuggest.nonsponsored": true, - "suggest.quicksuggest.sponsored": true, -}; - -// Migration will use these values to migrate only up to version 1 instead of -// the current version. -const TEST_OVERRIDES = { - migrationVersion: 2, -}; +const TO_VERSION = 2; add_setup(async () => { - await UrlbarTestUtils.initNimbusFeature(); -}); - -// The following tasks test OFFLINE UNVERSIONED to version 2 - -// Migrating from: -// * Unversioned prefs -// * Offline -// * Main suggestions pref: user left on -// * Sponsored suggestions: user left on -// -// Expected: -// * Non-sponsored suggestions: on -// * Sponsored suggestions: on -// * Data collection: off -add_task(async function () { - await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - }, - }); -}); - -// Migrating from: -// * Unversioned prefs -// * Offline -// * Main suggestions pref: user turned off -// * Sponsored suggestions: user left on (but ignored since main was off) -// -// Expected: -// * Non-sponsored suggestions: off -// * Sponsored suggestions: off -// * Data collection: off -add_task(async function () { - await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "suggest.quicksuggest": false, - }, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.nonsponsored": false, - "suggest.quicksuggest.sponsored": false, - }, - }, - }); -}); - -// Migrating from: -// * Unversioned prefs -// * Offline -// * Main suggestions pref: user left on -// * Sponsored suggestions: user turned off -// -// Expected: -// * Non-sponsored suggestions: on -// * Sponsored suggestions: off -// * Data collection: off -add_task(async function () { - await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "suggest.quicksuggest.sponsored": false, - }, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.sponsored": false, - }, - }, - }); + await setUpMigrateTest(); }); -// Migrating from: -// * Unversioned prefs -// * Offline -// * Main suggestions pref: user turned off -// * Sponsored suggestions: user turned off -// -// Expected: -// * Non-sponsored suggestions: off -// * Sponsored suggestions: off -// * Data collection: off +// No user-branch values set add_task(async function () { await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "suggest.quicksuggest": false, - "suggest.quicksuggest.sponsored": false, - }, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.nonsponsored": false, - "suggest.quicksuggest.sponsored": false, - }, - }, + toVersion: TO_VERSION, }); }); -// The following tasks test OFFLINE VERSION 1 to version 2 - -// Migrating from: -// * Version 1 prefs -// * Offline -// * Non-sponsored suggestions: user left on -// * Sponsored suggestions: user left on -// * Data collection: user left off -// -// Expected: -// * Non-sponsored suggestions: on -// * Sponsored suggestions: on -// * Data collection: off +// Migrating from offline scenario add_task(async function () { await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "quicksuggest.migrationVersion": 1, + toVersion: TO_VERSION, + preMigrationUserPrefs: { "quicksuggest.scenario": "offline", }, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, + expectedPostMigrationUserPrefs: { + "quicksuggest.scenario": "offline", }, }); }); -// Migrating from: -// * Version 1 prefs -// * Offline -// * Non-sponsored suggestions: user left on -// * Sponsored suggestions: user left on -// * Data collection: user turned on -// -// Expected: -// * Non-sponsored suggestions: on -// * Sponsored suggestions: on -// * Data collection: on +// Migrating from offline scenario, no user prefs set add_task(async function () { await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "quicksuggest.migrationVersion": 1, - "quicksuggest.scenario": "offline", - "quicksuggest.dataCollection.enabled": true, + toVersion: TO_VERSION, + preMigrationUserPrefs: { + "quicksuggest.scenario": "online", }, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "quicksuggest.dataCollection.enabled": true, - }, + expectedPostMigrationUserPrefs: { + "quicksuggest.scenario": "online", + "suggest.quicksuggest.nonsponsored": false, + "suggest.quicksuggest.sponsored": false, }, }); }); -// Migrating from: -// * Version 1 prefs -// * Offline -// * Non-sponsored suggestions: user left on -// * Sponsored suggestions: user turned off -// * Data collection: user left off -// -// Expected: -// * Non-sponsored suggestions: on -// * Sponsored suggestions: off -// * Data collection: off +// Migrating from offline scenario, sponsored/nonsponsored set to false add_task(async function () { await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "quicksuggest.migrationVersion": 1, - "quicksuggest.scenario": "offline", + toVersion: TO_VERSION, + preMigrationUserPrefs: { + "quicksuggest.scenario": "online", + "suggest.quicksuggest.nonsponsored": false, "suggest.quicksuggest.sponsored": false, }, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.sponsored": false, - }, + expectedPostMigrationUserPrefs: { + "quicksuggest.scenario": "online", + "suggest.quicksuggest.nonsponsored": false, + "suggest.quicksuggest.sponsored": false, }, }); }); -// Migrating from: -// * Version 1 prefs -// * Offline -// * Non-sponsored suggestions: user turned off -// * Sponsored suggestions: user turned off -// * Data collection: user left off -// -// Expected: -// * Non-sponsored suggestions: off -// * Sponsored suggestions: off -// * Data collection: off +// Migrating from offline scenario, sponsored/nonsponsored set to true add_task(async function () { await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "quicksuggest.migrationVersion": 1, - "quicksuggest.scenario": "offline", - "suggest.quicksuggest.nonsponsored": false, - "suggest.quicksuggest.sponsored": false, + toVersion: TO_VERSION, + preMigrationUserPrefs: { + "quicksuggest.scenario": "online", + "suggest.quicksuggest.nonsponsored": true, + "suggest.quicksuggest.sponsored": true, }, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "suggest.quicksuggest.nonsponsored": false, - "suggest.quicksuggest.sponsored": false, - }, + expectedPostMigrationUserPrefs: { + "quicksuggest.scenario": "online", + "suggest.quicksuggest.nonsponsored": true, + "suggest.quicksuggest.sponsored": true, }, }); }); diff --git a/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v3.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v3.js @@ -1,68 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Tests quick suggest prefs migration from version 2 to 4. - -"use strict"; - -// Expected version 2 default-branch prefs (important core prefs only, assuming -// US region and en-US locale). -const DEFAULT_PREFS = { - "quicksuggest.enabled": true, - "quicksuggest.dataCollection.enabled": false, - "quicksuggest.settingsUi": QuickSuggest.SETTINGS_UI.OFFLINE_ONLY, - "suggest.quicksuggest.nonsponsored": true, - "suggest.quicksuggest.sponsored": true, -}; - -const TEST_OVERRIDES = { - migrationVersion: 3, - defaultPrefs: DEFAULT_PREFS, -}; - -add_setup(async () => { - await UrlbarTestUtils.initNimbusFeature(); -}); - -// The following tasks test OFFLINE version 2 to version 4 when SUGGEST IS ENABLED. - -// Migrating from: -// * User enabled `quicksuggest.dataCollection.enabled` -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * quicksuggest.settingsUi is not set on the user branch. -add_task(async function test_migrate_with_datacollection_enabled() { - await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "quicksuggest.dataCollection.enabled": true, - }, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "quicksuggest.dataCollection.enabled": true, - }, - }, - }); -}); - -// Migrating from: -// * User has not enabled `quicksuggest.dataCollection.enabled` -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * quicksuggest.settingsUi not set on the User Branch -add_task(async function test_migrate_with_datacollection_disabled() { - await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - }, - }); -}); diff --git a/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v4.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v4.js @@ -2,67 +2,32 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -// Tests quick suggest prefs migration from version 3 to 4. +// Tests Suggest prefs migration from version 3 to 4. "use strict"; -// Expected version 3 default-branch prefs (important core prefs only, assuming -// US region and en-US locale). -const DEFAULT_PREFS = { - "quicksuggest.enabled": true, - "quicksuggest.dataCollection.enabled": false, - "quicksuggest.settingsUi": QuickSuggest.SETTINGS_UI.FULL, - "suggest.quicksuggest.nonsponsored": true, - "suggest.quicksuggest.sponsored": true, -}; - -const TEST_OVERRIDES = { - migrationVersion: 4, - defaultPrefs: DEFAULT_PREFS, -}; +const TO_VERSION = 4; add_setup(async () => { - await UrlbarTestUtils.initNimbusFeature(); + await setUpMigrateTest(); }); -// The following tasks test OFFLINE version 3 to version 4 when SUGGEST IS ENABLED. - -// Migrating from: -// * User enabled `quicksuggest.dataCollection.enabled` -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * quicksuggest.settingsUi not set on the User Branch -add_task(async function test_migrate_with_datacollection_enabled() { +// No user-branch values set +add_task(async function () { await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - initialUserBranch: { - "quicksuggest.dataCollection.enabled": true, - }, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, - userBranch: { - "quicksuggest.dataCollection.enabled": true, - }, - }, + toVersion: TO_VERSION, }); }); -// Migrating from: -// * User has not enabled `quicksuggest.dataCollection.enabled` -// -// Suggest enabled when migration occurs: -// * Yes -// -// Expected: -// * quicksuggest.settingsUi not set on the User Branch -add_task(async function test_migrate_with_datacollection_disabled() { +// Settings UI set to full +add_task(async function () { await doMigrateTest({ - testOverrides: TEST_OVERRIDES, - expectedPrefs: { - defaultBranch: DEFAULT_PREFS, + toVersion: TO_VERSION, + preMigrationUserPrefs: { + "quicksuggest.settingsUi": QuickSuggest.SETTINGS_UI.FULL, + }, + expectedPostMigrationUserPrefs: { + "quicksuggest.settingsUi": null, }, }); }); diff --git a/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v5.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v5.js @@ -0,0 +1,171 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Tests Suggest prefs migration from version 4 to 5. + +"use strict"; + +const TO_VERSION = 5; + +add_setup(async () => { + await setUpMigrateTest(); +}); + +// Region=US, locale=en-US => Suggest proper is enabled. No user-branch values +// set before migration. +add_task(async function () { + await QuickSuggestTestUtils.withRegionAndLocale({ + region: "US", + locale: "en-US", + skipSuggestReset: true, + callback: async () => { + await doMigrateTest({ + toVersion: TO_VERSION, + }); + }, + }); +}); + +// Region=US, locale=en-US => Suggest proper is enabled. The sponsored pref is +// false on the user branch and should keep its value after migration. +add_task(async function () { + await QuickSuggestTestUtils.withRegionAndLocale({ + region: "US", + locale: "en-US", + skipSuggestReset: true, + callback: async () => { + await doMigrateTest({ + toVersion: TO_VERSION, + preMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": false, + }, + expectedPostMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": false, + }, + }); + }, + }); +}); + +// Region=US, locale=en-US => Suggest proper is enabled. The sponsored pref is +// true on the user branch and should keep its value after migration. +add_task(async function () { + await QuickSuggestTestUtils.withRegionAndLocale({ + region: "US", + locale: "en-US", + skipSuggestReset: true, + callback: async () => { + await doMigrateTest({ + toVersion: TO_VERSION, + preMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": true, + }, + expectedPostMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": true, + }, + }); + }, + }); +}); + +// Region=DE, locale=de => Suggest proper is enabled. No user-branch values set +// before migration. +add_task(async function () { + await QuickSuggestTestUtils.withRegionAndLocale({ + region: "DE", + locale: "de", + skipSuggestReset: true, + callback: async () => { + await doMigrateTest({ + toVersion: TO_VERSION, + }); + }, + }); +}); + +// Region=DE, locale=de => Suggest proper is enabled. The sponsored pref is +// false on the user branch and should keep its value after migration. +add_task(async function () { + await QuickSuggestTestUtils.withRegionAndLocale({ + region: "DE", + locale: "de", + skipSuggestReset: true, + callback: async () => { + await doMigrateTest({ + toVersion: TO_VERSION, + preMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": false, + }, + expectedPostMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": false, + }, + }); + }, + }); +}); + +// Region=DE, locale=de => Suggest proper is enabled. The sponsored pref is +// true on the user branch and should keep its value after migration. +add_task(async function () { + await QuickSuggestTestUtils.withRegionAndLocale({ + region: "DE", + locale: "de", + skipSuggestReset: true, + callback: async () => { + await doMigrateTest({ + toVersion: TO_VERSION, + preMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": true, + }, + expectedPostMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": true, + }, + }); + }, + }); +}); + +// Region=DE, locale=en-US => Suggest proper is *not* enabled as of this +// migration version. The sponsored pref is false on the user branch and should +// be cleared after migration. +add_task(async function () { + await QuickSuggestTestUtils.withRegionAndLocale({ + region: "DE", + locale: "en-US", + skipSuggestReset: true, + callback: async () => { + await doMigrateTest({ + toVersion: TO_VERSION, + preMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": false, + }, + expectedPostMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": null, + }, + }); + }, + }); +}); + +// Region=DE, locale=en-US => Suggest proper is *not* enabled as of this +// migration version. The sponsored pref is true on the user branch and should +// be cleared after migration. +add_task(async function () { + await QuickSuggestTestUtils.withRegionAndLocale({ + region: "DE", + locale: "en-US", + skipSuggestReset: true, + callback: async () => { + await doMigrateTest({ + toVersion: TO_VERSION, + preMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": true, + }, + expectedPostMigrationUserPrefs: { + "suggest.quicksuggest.sponsored": null, + }, + }); + }, + }); +}); diff --git a/browser/components/urlbar/tests/quicksuggest/unit/xpcshell.toml b/browser/components/urlbar/tests/quicksuggest/unit/xpcshell.toml @@ -47,10 +47,10 @@ skip-if = ["true"] # Bug 1880214 ["test_quicksuggest_migrate_v2.js"] -["test_quicksuggest_migrate_v3.js"] - ["test_quicksuggest_migrate_v4.js"] +["test_quicksuggest_migrate_v5.js"] + ["test_quicksuggest_relevanceRanking.js"] ["test_quicksuggest_remoteSettingsFilter.js"]