forked from mirrors/gecko-dev
Bug 1792819 - Only prompt about the default search engine change when the previous engine is actually removed. r=daleharvey
Differential Revision: https://phabricator.services.mozilla.com/D158329
This commit is contained in:
parent
d3ee24dbfd
commit
aa9d8ed88b
2 changed files with 72 additions and 6 deletions
|
|
@ -416,6 +416,14 @@ export class SearchService {
|
|||
this._settings._batchTask?.disarm();
|
||||
}
|
||||
|
||||
// Test-only function to reset just the engine selector so that it can
|
||||
// load a different configuration.
|
||||
resetEngineSelector() {
|
||||
this.#engineSelector = new lazy.SearchEngineSelector(
|
||||
this.#handleConfigurationUpdated.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
resetToAppDefaultEngine() {
|
||||
let appDefaultEngine = this.appDefaultEngine;
|
||||
appDefaultEngine.hidden = false;
|
||||
|
|
@ -1589,8 +1597,8 @@ export class SearchService {
|
|||
* The user's new current default engine.
|
||||
* @param { object } prevCurrentEngine
|
||||
* The user's previous default engine.
|
||||
* @param { object } prevAppDefaultEngine
|
||||
* The user's previous app default engine.
|
||||
* @param { string } prevAppDefaultEngine
|
||||
* The name of the user's previous app default engine.
|
||||
* @returns { boolean }
|
||||
* Return true if the previous default engine has been removed and
|
||||
* notification box should be displayed.
|
||||
|
|
@ -1614,6 +1622,15 @@ export class SearchService {
|
|||
return false;
|
||||
}
|
||||
|
||||
// If the previous engine is still available, don't show the notification
|
||||
// box.
|
||||
if (prevCurrentEngine && this._engines.has(prevCurrentEngine.name)) {
|
||||
return false;
|
||||
}
|
||||
if (!prevCurrentEngine && this._engines.has(prevAppDefaultEngine)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the user's previous engine is different than the new current engine,
|
||||
// or if the user was using the app default engine and the app default
|
||||
// engine is different than the new current engine, we check if the user's
|
||||
|
|
@ -1878,6 +1895,7 @@ export class SearchService {
|
|||
prevMetaData &&
|
||||
settings.metaData &&
|
||||
!this.#didSettingsMetaDataUpdate(prevMetaData) &&
|
||||
enginesToRemove.includes(prevCurrentEngine) &&
|
||||
Services.prefs.getBoolPref("browser.search.removeEngineInfobar.enabled")
|
||||
) {
|
||||
this._showRemovalOfSearchEngineNotificationBox(
|
||||
|
|
|
|||
|
|
@ -206,6 +206,28 @@ add_task(async function test_current_engine_is_null() {
|
|||
);
|
||||
});
|
||||
|
||||
add_task(async function test_default_changed_and_metadata_unchanged_exists() {
|
||||
info("Update region to FR to change engine.");
|
||||
Region._setHomeRegion("FR", false);
|
||||
|
||||
info("Set user settings metadata to the same properties as cached metadata.");
|
||||
await Services.search.wrappedJSObject._fetchEngineSelectorEngines();
|
||||
userSettings.metaData = {
|
||||
...Services.search.wrappedJSObject._settings.getSettingsMetaData(),
|
||||
appDefaultEngine: "Test search engine",
|
||||
};
|
||||
|
||||
await reloadEngines(structuredClone(userSettings));
|
||||
Assert.ok(
|
||||
stub.notCalled,
|
||||
"_reloadEngines should not show the notification box as the engine still exists."
|
||||
);
|
||||
|
||||
// Reset.
|
||||
Region._setHomeRegion("US", false);
|
||||
await reloadEngines(structuredClone(userSettings));
|
||||
});
|
||||
|
||||
add_task(async function test_default_engine_changed_and_metadata_unchanged() {
|
||||
info("Update region to FR to change engine.");
|
||||
Region._setHomeRegion("FR", false);
|
||||
|
|
@ -219,8 +241,12 @@ add_task(async function test_default_engine_changed_and_metadata_unchanged() {
|
|||
await Services.search.wrappedJSObject._fetchEngineSelectorEngines();
|
||||
userSettings.metaData = {
|
||||
...Services.search.wrappedJSObject._settings.getSettingsMetaData(),
|
||||
appDefaultEngine: "Test search engine",
|
||||
};
|
||||
|
||||
// Update config by removing the app default engine
|
||||
await setConfigToLoad(CONFIG_UPDATED);
|
||||
|
||||
await reloadEngines(structuredClone(userSettings));
|
||||
Assert.ok(
|
||||
stub.calledOnce,
|
||||
|
|
@ -249,11 +275,8 @@ add_task(async function test_app_default_engine_changed_on_start_up() {
|
|||
// default
|
||||
settings.metaData.current = "";
|
||||
|
||||
let searchSettingsObj = await RemoteSettings(SearchUtils.SETTINGS_KEY);
|
||||
// Restore the get method in order to stub it again in useTestEngines
|
||||
searchSettingsObj.get.restore();
|
||||
// Update config by removing the app default engine
|
||||
await SearchTestUtils.useTestEngines("data", null, CONFIG_UPDATED);
|
||||
await setConfigToLoad(CONFIG_UPDATED);
|
||||
|
||||
await loadEngines(settings);
|
||||
Assert.ok(
|
||||
|
|
@ -261,6 +284,31 @@ add_task(async function test_app_default_engine_changed_on_start_up() {
|
|||
"_loadEngines should show the notification box."
|
||||
);
|
||||
});
|
||||
add_task(async function test_app_default_engine_change_start_up_still_exists() {
|
||||
stub.resetHistory();
|
||||
let settings = structuredClone(userSettings);
|
||||
|
||||
// Set the current engine to "" so we can use the app default engine as
|
||||
// default
|
||||
settings.metaData.current = "";
|
||||
settings.metaData.appDefaultEngine = "Test search engine";
|
||||
|
||||
await setConfigToLoad(CONFIG);
|
||||
|
||||
await loadEngines(settings);
|
||||
Assert.ok(
|
||||
stub.notCalled,
|
||||
"_loadEngines should not show the notification box."
|
||||
);
|
||||
});
|
||||
|
||||
async function setConfigToLoad(config) {
|
||||
let searchSettingsObj = await RemoteSettings(SearchUtils.SETTINGS_KEY);
|
||||
// Restore the get method in order to stub it again in useTestEngines
|
||||
searchSettingsObj.get.restore();
|
||||
Services.search.wrappedJSObject.resetEngineSelector();
|
||||
await SearchTestUtils.useTestEngines("data", null, config);
|
||||
}
|
||||
|
||||
function writeSettings(settings) {
|
||||
return IOUtils.writeJSON(settingsFilePath, settings, { compress: true });
|
||||
|
|
|
|||
Loading…
Reference in a new issue