зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1890698 - Change general search engine handling to use data from the new search configuration. r=mcheang
Differential Revision: https://phabricator.services.mozilla.com/D207270
This commit is contained in:
Родитель
db0104dbc2
Коммит
04ac08bf45
|
@ -283,6 +283,13 @@ export class AppProvidedSearchEngine extends SearchEngine {
|
|||
*/
|
||||
#configurationId = null;
|
||||
|
||||
/**
|
||||
* Whether or not this is a general purpose search engine.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
#isGeneralPurposeSearchEngine = false;
|
||||
|
||||
/**
|
||||
* @param {object} options
|
||||
* The options for this search engine.
|
||||
|
@ -389,11 +396,15 @@ export class AppProvidedSearchEngine extends SearchEngine {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this engine is a "general" search engine, e.g. is it for
|
||||
* generally searching the web, or does it have a specific purpose like
|
||||
* shopping.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
get isGeneralPurposeEngine() {
|
||||
return !!(
|
||||
this._extensionID &&
|
||||
lazy.SearchUtils.GENERAL_SEARCH_ENGINE_IDS.has(this._extensionID)
|
||||
);
|
||||
return this.#isGeneralPurposeSearchEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -471,6 +482,8 @@ export class AppProvidedSearchEngine extends SearchEngine {
|
|||
#init(engineConfig) {
|
||||
this._orderHint = engineConfig.orderHint;
|
||||
this._telemetryId = engineConfig.identifier;
|
||||
this.#isGeneralPurposeSearchEngine =
|
||||
engineConfig.classification == "general";
|
||||
|
||||
if (engineConfig.charset) {
|
||||
this._queryCharset = engineConfig.charset;
|
||||
|
|
|
@ -112,6 +112,7 @@
|
|||
"recordType": "engine",
|
||||
"identifier": "engine-resourceicon",
|
||||
"base": {
|
||||
"classification": "general",
|
||||
"name": "engine-resourceicon",
|
||||
"urls": {
|
||||
"search": {
|
||||
|
@ -151,6 +152,7 @@
|
|||
"recordType": "engine",
|
||||
"identifier": "engine-reordered",
|
||||
"base": {
|
||||
"classification": "general",
|
||||
"name": "Test search engine (Reordered)",
|
||||
"urls": {
|
||||
"search": {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"searchTermParamName": "q"
|
||||
}
|
||||
},
|
||||
"classification": "unknown"
|
||||
"classification": "general"
|
||||
},
|
||||
"variants": [{ "environment": { "allRegionsAndLocales": true } }],
|
||||
"identifier": "engine1",
|
||||
|
@ -24,7 +24,7 @@
|
|||
"searchTermParamName": "q"
|
||||
}
|
||||
},
|
||||
"classification": "unknown"
|
||||
"classification": "general"
|
||||
},
|
||||
"variants": [{ "environment": { "allRegionsAndLocales": true } }],
|
||||
"identifier": "engine2",
|
||||
|
@ -39,7 +39,7 @@
|
|||
"searchTermParamName": "q"
|
||||
}
|
||||
},
|
||||
"classification": "unknown"
|
||||
"classification": "general"
|
||||
},
|
||||
"variants": [
|
||||
{
|
||||
|
@ -58,7 +58,7 @@
|
|||
"searchTermParamName": "q"
|
||||
}
|
||||
},
|
||||
"classification": "unknown"
|
||||
"classification": "general"
|
||||
},
|
||||
"variants": [
|
||||
{
|
||||
|
|
|
@ -15,6 +15,7 @@ let CONFIG = [
|
|||
base: {
|
||||
aliases: ["testEngine1", "testEngine2"],
|
||||
charset: "EUC-JP",
|
||||
classification: "general",
|
||||
name: "testEngine name",
|
||||
partnerCode: "pc",
|
||||
urls: {
|
||||
|
@ -55,6 +56,7 @@ let CONFIG = [
|
|||
identifier: "testOtherValuesEngine",
|
||||
recordType: "engine",
|
||||
base: {
|
||||
classification: "unknown",
|
||||
name: "testOtherValuesEngine name",
|
||||
urls: {
|
||||
search: {
|
||||
|
@ -97,6 +99,10 @@ add_task(async function test_engine_with_all_params_set() {
|
|||
["@testEngine1", "@testEngine2"],
|
||||
"Should have the correct aliases"
|
||||
);
|
||||
Assert.ok(
|
||||
engine.isGeneralPurposeEngine,
|
||||
"Should be a general purpose engine"
|
||||
);
|
||||
Assert.equal(
|
||||
engine.wrappedJSObject.queryCharset,
|
||||
"EUC-JP",
|
||||
|
@ -149,6 +155,10 @@ add_task(async function test_engine_with_some_params_set() {
|
|||
"Should have the correct engine name"
|
||||
);
|
||||
Assert.deepEqual(engine.aliases, [], "Should have no aliases");
|
||||
Assert.ok(
|
||||
!engine.isGeneralPurposeEngine,
|
||||
"Should not be a general purpose engine"
|
||||
);
|
||||
Assert.equal(
|
||||
engine.wrappedJSObject.queryCharset,
|
||||
"UTF-8",
|
||||
|
|
|
@ -17,6 +17,15 @@
|
|||
let appDefault;
|
||||
let appPrivateDefault;
|
||||
|
||||
async function getSearchConfig() {
|
||||
let workDir = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
|
||||
let configFileName =
|
||||
"file://" + PathUtils.join(workDir.path, "data", "search-config-v2.json");
|
||||
|
||||
let response = await fetch(configFileName);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
add_setup(async function () {
|
||||
useHttpServer();
|
||||
await SearchTestUtils.useTestEngines();
|
||||
|
@ -292,10 +301,33 @@ add_task(async function test_default_fallback_remove_default_no_visible() {
|
|||
|
||||
add_task(
|
||||
async function test_default_fallback_remove_default_no_visible_or_general() {
|
||||
// Reset.
|
||||
Services.search.restoreDefaultEngines();
|
||||
Services.search.defaultEngine = Services.search.defaultPrivateEngine =
|
||||
appPrivateDefault;
|
||||
|
||||
// For this test, we need to change any general search engines to unknown,
|
||||
// so that we can test what happens in the unlikely event that there are no
|
||||
// general search engines.
|
||||
if (SearchUtils.newSearchConfigEnabled) {
|
||||
let searchConfig = await getSearchConfig();
|
||||
for (let entry of searchConfig.data) {
|
||||
if (
|
||||
entry.recordType == "engine" &&
|
||||
entry.base.classification == "general"
|
||||
) {
|
||||
entry.base.classification = "unknown";
|
||||
}
|
||||
}
|
||||
const settings = await RemoteSettings(SearchUtils.SETTINGS_KEY);
|
||||
settings.get.returns(searchConfig.data);
|
||||
Services.search.wrappedJSObject.reset();
|
||||
await Services.search.init();
|
||||
|
||||
appPrivateDefault = await Services.search.getDefaultPrivate();
|
||||
|
||||
Services.search.defaultEngine = appPrivateDefault;
|
||||
} else {
|
||||
Services.search.defaultEngine = Services.search.defaultPrivateEngine =
|
||||
appPrivateDefault;
|
||||
}
|
||||
|
||||
// Remove all but the default engine.
|
||||
let visibleEngines = await Services.search.getVisibleEngines();
|
||||
|
@ -310,7 +342,9 @@ add_task(
|
|||
"Should only have one visible engine"
|
||||
);
|
||||
|
||||
SearchUtils.GENERAL_SEARCH_ENGINE_IDS.clear();
|
||||
if (!SearchUtils.newSearchConfigEnabled) {
|
||||
SearchUtils.GENERAL_SEARCH_ENGINE_IDS.clear();
|
||||
}
|
||||
|
||||
const observer = new SearchObserver(
|
||||
[
|
||||
|
|
Загрузка…
Ссылка в новой задаче