forked from mirrors/gecko-dev
Bug 1872757 - Update SearchTestUtils.useTestEngines to be able to load search-config-v2 configurations. r=mcheang
This also adds data1/search-config-v2.json which uses it and starts to get some tests passing when search-config-v2 is enabled. Differential Revision: https://phabricator.services.mozilla.com/D197547
This commit is contained in:
parent
7c1fff554e
commit
a1ed3bd737
3 changed files with 140 additions and 13 deletions
|
|
@ -120,37 +120,62 @@ export var SearchTestUtils = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Load engines from test data located in particular folders.
|
||||
* For xpcshell tests, configures loading engines from test data located in
|
||||
* particular folders.
|
||||
*
|
||||
* @param {string} [folder]
|
||||
* The folder name to use.
|
||||
* @param {string} [subFolder]
|
||||
* The subfolder to use, if any.
|
||||
* @param {Array} [config]
|
||||
* @param {Array} [configData]
|
||||
* An array which contains the configuration to set.
|
||||
* @returns {object}
|
||||
* An object that is a sinon stub for the configuration getter.
|
||||
*/
|
||||
async useTestEngines(folder = "data", subFolder = null, config = null) {
|
||||
let url = `resource://test/${folder}/`;
|
||||
if (subFolder) {
|
||||
url += `${subFolder}/`;
|
||||
async useTestEngines(folder = "data", subFolder = null, configData = null) {
|
||||
if (!lazy.SearchUtils.newSearchConfigEnabled) {
|
||||
let url = `resource://test/${folder}/`;
|
||||
if (subFolder) {
|
||||
url += `${subFolder}/`;
|
||||
}
|
||||
let resProt = Services.io
|
||||
.getProtocolHandler("resource")
|
||||
.QueryInterface(Ci.nsIResProtocolHandler);
|
||||
resProt.setSubstitution("search-extensions", Services.io.newURI(url));
|
||||
}
|
||||
let resProt = Services.io
|
||||
.getProtocolHandler("resource")
|
||||
.QueryInterface(Ci.nsIResProtocolHandler);
|
||||
resProt.setSubstitution("search-extensions", Services.io.newURI(url));
|
||||
|
||||
const settings = await lazy.RemoteSettings(lazy.SearchUtils.SETTINGS_KEY);
|
||||
if (config) {
|
||||
return lazy.sinon.stub(settings, "get").returns(config);
|
||||
if (configData) {
|
||||
return lazy.sinon.stub(settings, "get").returns(configData);
|
||||
}
|
||||
|
||||
let response = await fetch(`resource://search-extensions/engines.json`);
|
||||
let workDir = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
|
||||
let configFileName =
|
||||
"file://" +
|
||||
PathUtils.join(
|
||||
workDir.path,
|
||||
folder,
|
||||
subFolder ?? "",
|
||||
lazy.SearchUtils.newSearchConfigEnabled
|
||||
? "search-config-v2.json"
|
||||
: "engines.json"
|
||||
);
|
||||
|
||||
let response = await fetch(configFileName);
|
||||
let json = await response.json();
|
||||
return lazy.sinon.stub(settings, "get").returns(json.data);
|
||||
},
|
||||
|
||||
/**
|
||||
* For mochitests, configures loading engines from test data located in
|
||||
* particular folders. This will cleanup at the end of the test.
|
||||
*
|
||||
* This will be removed when the old configuration is removed
|
||||
* (newSearchConfigEnabled = false).
|
||||
*
|
||||
* @param {nsIFile} testDir
|
||||
* The test directory to use.
|
||||
*/
|
||||
async useMochitestEngines(testDir) {
|
||||
// Replace the path we load search engines from with
|
||||
// the path to our test data.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,101 @@
|
|||
{
|
||||
"data": [
|
||||
{
|
||||
"base": {
|
||||
"name": "engine1",
|
||||
"urls": {
|
||||
"search": {
|
||||
"base": "https://1.example.com/search",
|
||||
"searchTermParamName": "q"
|
||||
}
|
||||
},
|
||||
"classification": "unknown"
|
||||
},
|
||||
"variants": [{ "environment": { "allRegionsAndLocales": true } }],
|
||||
"identifier": "engine1",
|
||||
"recordType": "engine"
|
||||
},
|
||||
{
|
||||
"base": {
|
||||
"name": "engine2",
|
||||
"urls": {
|
||||
"search": {
|
||||
"base": "https://2.example.com/search",
|
||||
"searchTermParamName": "q"
|
||||
}
|
||||
},
|
||||
"classification": "unknown"
|
||||
},
|
||||
"variants": [{ "environment": { "allRegionsAndLocales": true } }],
|
||||
"identifier": "engine2",
|
||||
"recordType": "engine"
|
||||
},
|
||||
{
|
||||
"base": {
|
||||
"name": "exp2",
|
||||
"urls": {
|
||||
"search": {
|
||||
"base": "https://2.example.com/searchexp",
|
||||
"searchTermParamName": "q"
|
||||
}
|
||||
},
|
||||
"classification": "unknown"
|
||||
},
|
||||
"variants": [
|
||||
{
|
||||
"environment": { "allRegionsAndLocales": true, "experiment": "exp2" }
|
||||
}
|
||||
],
|
||||
"identifier": "exp2",
|
||||
"recordType": "engine"
|
||||
},
|
||||
{
|
||||
"base": {
|
||||
"name": "exp3",
|
||||
"urls": {
|
||||
"search": {
|
||||
"base": "https://3.example.com/searchexp",
|
||||
"searchTermParamName": "q"
|
||||
}
|
||||
},
|
||||
"classification": "unknown"
|
||||
},
|
||||
"variants": [
|
||||
{
|
||||
"environment": { "allRegionsAndLocales": true, "experiment": "exp3" }
|
||||
}
|
||||
],
|
||||
"identifier": "exp3",
|
||||
"recordType": "engine"
|
||||
},
|
||||
{
|
||||
"recordType": "defaultEngines",
|
||||
"globalDefault": "engine1",
|
||||
"globalDefaultPrivate": "engine1",
|
||||
"specificDefaults": [
|
||||
{
|
||||
"environment": { "experiment": "exp1" },
|
||||
"default": "engine2"
|
||||
},
|
||||
{
|
||||
"environment": { "experiment": "exp2" },
|
||||
"defaultPrivate": "exp2"
|
||||
},
|
||||
{
|
||||
"environment": { "experiment": "exp3" },
|
||||
"default": "exp3"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"recordType": "engineOrders",
|
||||
"orders": [
|
||||
{
|
||||
"environment": { "allRegionsAndLocales": true },
|
||||
"order": ["exp3", "engine1", "engine2", "exp2"]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"timestamp": 1704229342821
|
||||
}
|
||||
|
|
@ -54,6 +54,7 @@ support-files = [
|
|||
"data1/exp2/manifest.json",
|
||||
"data1/exp3/manifest.json",
|
||||
"data1/engines.json",
|
||||
"data1/search-config-v2.json",
|
||||
"simple-engines/engines.json",
|
||||
"simple-engines/basic/manifest.json",
|
||||
"simple-engines/hidden/manifest.json",
|
||||
|
|
|
|||
Loading…
Reference in a new issue