Bug 1582942 - Port Search tests relating to the configuration to the modern configuration. r=mikedeboer

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2019-10-03 13:30:54 +00:00
parent 9238ced3bb
commit 7594d336de
7 changed files with 101 additions and 30 deletions

View File

@ -57,15 +57,17 @@ class SearchEngineSelector {
log(`fetchEngineConfiguration ${region}:${locale}`);
let cohort = Services.prefs.getCharPref("browser.search.cohort", null);
let engines = [];
const lcLocale = locale.toLowerCase();
const lcRegion = region.toLowerCase();
for (let config of this.configuration) {
const appliesTo = config.appliesTo || [];
const applies = appliesTo.filter(section => {
let included =
"included" in section &&
this._isInSection(region, locale, section.included);
this._isInSection(lcRegion, lcLocale, section.included);
let excluded =
"excluded" in section &&
this._isInSection(region, locale, section.excluded);
this._isInSection(lcRegion, lcLocale, section.excluded);
if ("cohort" in section && cohort != section.cohort) {
return false;
}
@ -242,8 +244,12 @@ class SearchEngineSelector {
return true;
}
let locales = config.locales || {};
let inLocales = locales.matches && locales.matches.includes(locale);
let inRegions = config.regions && config.regions.includes(region);
let inLocales =
"matches" in locales &&
!!locales.matches.find(e => e.toLowerCase() == locale);
let inRegions =
"regions" in config &&
!!config.regions.find(e => e.toLowerCase() == region);
if (
locales.startsWith &&
locales.startsWith.some(key => locale.startsWith(key))

View File

@ -4,6 +4,7 @@
"engineName": "Test search engine",
"webExtensionId": "engine@search.mozilla.org",
"webExtensionVersion": "1.0",
"orderHint": 10000,
"appliesTo": [{
"included": { "everywhere": true },
"default": "yes"
@ -13,45 +14,61 @@
"engineName": "engine-pref",
"webExtensionId": "engine-pref@search.mozilla.org",
"webExtensionVersion": "1.0",
"orderHint": 7000,
"appliesTo": [{
"included": { "everywhere": true },
"default": "yes"
"excluded": { "locales": { "matches": ["de"] } },
"default": "no",
"defaultPrivate": "yes"
}]
},
{
"engineName": "engine-rel-searchform-purpose",
"webExtensionId": "engine-rel-searchform-purpose@search.mozilla.org",
"webExtensionVersion": "1.0",
"orderHint": 6000,
"appliesTo": [{
"included": { "everywhere": true },
"default": "yes"
"excluded": { "locales": { "matches": ["de", "fr"] } },
"default": "no"
}]
},
{
"engineName": "engine-chromeicon",
"webExtensionId": "engine-chromeicon@search.mozilla.org",
"webExtensionVersion": "1.0",
"orderHint": 8000,
"appliesTo": [{
"included": { "everywhere": true },
"default": "yes"
"excluded": { "locales": { "matches": ["de", "fr"] } },
"default": "no"
}, {
"included": { "regions": ["ru"] },
"default": "no"
}]
},
{
"engineName": "engine-resourceicon",
"webExtensionId": "engine-resourceicon@search.mozilla.org",
"webExtensionVersion": "1.0",
"orderHint": 9000,
"appliesTo": [{
"included": { "everywhere": true },
"default": "yes"
"included": { "locales": { "matches": ["en-US", "fr"] } },
"excluded": {
"regions": ["ru"]
},
"default": "no"
}]
},
{
"engineName": "engine-reordered",
"webExtensionId": "engine-reordered@search.mozilla.org",
"webExtensionVersion": "1.0",
"orderHint": 5000,
"appliesTo": [{
"included": { "everywhere": true },
"default": "yes"
"excluded": { "locales": { "matches": ["de", "fr"] } },
"default": "no"
}]
}
]

View File

@ -0,0 +1,24 @@
{
"data": [
{
"engineName": "engine1",
"webExtensionId": "engine1@search.mozilla.org",
"webExtensionVersion": "1.0",
"orderHint": 10000,
"appliesTo": [{
"included": { "everywhere": true },
"default": "yes"
}]
},
{
"engineName": "engine2",
"webExtensionId": "engine2@search.mozilla.org",
"webExtensionVersion": "1.0",
"orderHint": 7000,
"appliesTo": [{
"included": { "everywhere": true },
"default": "no"
}]
}
]
}

View File

@ -12,6 +12,7 @@ add_task(function test_setup() {
SearchUtils.BROWSER_SEARCH_PREF + "separatePrivateDefault",
true
);
Services.prefs.setCharPref("browser.search.region", "US");
});
add_task(async function test_listJSONlocale() {

View File

@ -29,17 +29,39 @@ add_task(async function test_searchOrderJSON_no_separate_private() {
false
);
await checkOrder([
// Default engine
"Test search engine",
// Two engines listed in searchOrder.
"engine-resourceicon",
"engine-chromeicon",
// Rest of the engines in order.
"engine-pref",
"engine-rel-searchform-purpose",
"Test search engine (Reordered)",
]);
// With modern configuration, we have a slightly different order, since the
// default private engine will get placed second, regardless of if the
// separate private engine is enabled or not.
if (
Services.prefs.getBoolPref(
SearchUtils.BROWSER_SEARCH_PREF + "modernConfig",
false
)
) {
await checkOrder([
// Default engines
"Test search engine",
"engine-pref",
// Two engines listed in searchOrder.
"engine-resourceicon",
"engine-chromeicon",
// Rest of the engines in order.
"engine-rel-searchform-purpose",
"Test search engine (Reordered)",
]);
} else {
await checkOrder([
// Default engine
"Test search engine",
// Two engines listed in searchOrder.
"engine-resourceicon",
"engine-chromeicon",
// Rest of the engines in order.
"engine-pref",
"engine-rel-searchform-purpose",
"Test search engine (Reordered)",
]);
}
});
add_task(async function test_searchOrderJSON_separate_private() {

View File

@ -26,6 +26,16 @@ skip-if = true # Is confusing
[test_invalid_engine_from_dir.js]
[test_json_cache_ignorelist.js]
support-files = data/search_ignorelist.json
[test_list_json_locale.js]
[test_list_json_no_private_default.js]
support-files =
data1/engine1/manifest.json
data1/engine2/manifest.json
data1/list.json
data1/engines.json
[test_list_json_searchdefault_distro.js]
[test_list_json_searchdefault.js]
[test_list_json_searchorder.js]
[test_location_error.js]
[test_location_malformed_json.js]
[test_location_timeout_xhr.js]

View File

@ -74,15 +74,6 @@ support-files =
[test_require_engines_in_cache.js]
# Testing with list.json specifically - Bug 1582942
[test_list_json_locale.js]
[test_list_json_no_private_default.js]
support-files =
data1/engine1/manifest.json
data1/engine2/manifest.json
data1/list.json
[test_list_json_searchdefault.js]
[test_list_json_searchdefault_distro.js]
[test_list_json_searchorder.js]
# Use geoSpecificDefaults - Bug 1542269
[test_maybereloadengine_update.js]