зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1616617 - Add distribution handling to the modern search configuration. r=daleharvey
Differential Revision: https://phabricator.services.mozilla.com/D65316 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
98aa9cef59
Коммит
0fc1fa6a39
|
@ -45,6 +45,25 @@ function sectionExcludes(config, key, value) {
|
|||
return hasAppKey(config, key) && !config.application[key].includes(value);
|
||||
}
|
||||
|
||||
function sectionIncludes(config, key, value) {
|
||||
return hasAppKey(config, key) && config.application[key].includes(value);
|
||||
}
|
||||
|
||||
function isDistroExcluded(config, key, distroID) {
|
||||
// Should be excluded when:
|
||||
// - There's a distroID and that is not in the non-empty distroID list.
|
||||
// - There's no distroID and the distroID list is not empty.
|
||||
const appKey = hasAppKey(config, key);
|
||||
if (!appKey) {
|
||||
return false;
|
||||
}
|
||||
const distroList = config.application[key];
|
||||
if (distroID) {
|
||||
return distroList.length && !distroList.includes(distroID);
|
||||
}
|
||||
return !!distroList.length;
|
||||
}
|
||||
|
||||
function belowMinVersion(config, version) {
|
||||
return (
|
||||
hasAppKey(config, "minVersion") &&
|
||||
|
@ -85,17 +104,18 @@ class SearchEngineSelector {
|
|||
* @param {string} locale - Users locale.
|
||||
* @param {string} region - Users region.
|
||||
* @param {string} channel - The update channel the application is running on.
|
||||
* @param {string} distroID - The distribution ID of the application.
|
||||
* @returns {object}
|
||||
* An object with "engines" field, a sorted list of engines and
|
||||
* optionally "privateDefault" which is an object containing the engine
|
||||
* details for the engine which should be the default in Private Browsing mode.
|
||||
*/
|
||||
fetchEngineConfiguration(locale, region, channel) {
|
||||
fetchEngineConfiguration(locale, region, channel, distroID) {
|
||||
let cohort = Services.prefs.getCharPref("browser.search.cohort", null);
|
||||
let name = getAppInfo("name");
|
||||
let version = getAppInfo("version");
|
||||
log(
|
||||
`fetchEngineConfiguration ${region}:${locale}:${channel}:${cohort}:${name}:${version}`
|
||||
`fetchEngineConfiguration ${region}:${locale}:${channel}:${distroID}:${cohort}:${name}:${version}`
|
||||
);
|
||||
let engines = [];
|
||||
const lcLocale = locale.toLowerCase();
|
||||
|
@ -109,6 +129,9 @@ class SearchEngineSelector {
|
|||
if (
|
||||
sectionExcludes(section, "channel", channel) ||
|
||||
sectionExcludes(section, "name", name) ||
|
||||
(distroID &&
|
||||
sectionIncludes(section, "excludedDistributions", distroID)) ||
|
||||
isDistroExcluded(section, "distributions", distroID) ||
|
||||
belowMinVersion(section, version) ||
|
||||
aboveMaxVersion(section, version)
|
||||
) {
|
||||
|
|
|
@ -1842,7 +1842,8 @@ SearchService.prototype = {
|
|||
let { engines, privateDefault } = engineSelector.fetchEngineConfiguration(
|
||||
locale,
|
||||
region,
|
||||
channel
|
||||
channel,
|
||||
SearchUtils.distroID
|
||||
);
|
||||
|
||||
const defaultEngine = engines[0];
|
||||
|
|
|
@ -219,6 +219,47 @@ channels.
|
|||
]}
|
||||
}
|
||||
|
||||
Distributions
|
||||
-------------
|
||||
|
||||
Distributions may be specified to be included or excluded in an ``appliesTo``
|
||||
section. The ``distributions`` field in the ``application`` section is an array
|
||||
of distribution identifiers. The identifiers match those supplied by the
|
||||
``distribution.id`` preference.
|
||||
|
||||
In the following, ``web@ext`` would be included in only the ``cake``
|
||||
distribution. ``web1@ext`` would be excluded from the ``apples`` distribution
|
||||
but included in the main desktop application, and all other distributions.
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
{
|
||||
"webExtension": {
|
||||
"id": "web@ext"
|
||||
},
|
||||
"appliesTo": [{
|
||||
"included": {
|
||||
"everywhere": true
|
||||
"application": {
|
||||
"distributions": ["cake"]
|
||||
}
|
||||
}
|
||||
]}
|
||||
},
|
||||
{
|
||||
"webExtension": {
|
||||
"id": "web1@ext"
|
||||
},
|
||||
"appliesTo": [{
|
||||
"included": {
|
||||
"everywhere": true
|
||||
"application": {
|
||||
"excludedDistributions": ["apples"]
|
||||
}
|
||||
}
|
||||
]}
|
||||
}
|
||||
|
||||
Version
|
||||
-------
|
||||
|
||||
|
|
|
@ -67,6 +67,24 @@
|
|||
},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"distributions": {
|
||||
"type": "array",
|
||||
"title": "Distributions",
|
||||
"description": "Which distributions this applies to.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"excludedDistributions": {
|
||||
"type": "array",
|
||||
"title": "Exlucuded Distributions",
|
||||
"description": "Which distributions this does not apply to.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"minVersion": {
|
||||
"type": "string",
|
||||
"title": "Minimum Version",
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
SearchEngineSelector: "resource://gre/modules/SearchEngineSelector.jsm",
|
||||
});
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const CONFIG = [
|
||||
{
|
||||
webExtension: {
|
||||
id: "aol@example.com",
|
||||
},
|
||||
appliesTo: [
|
||||
{
|
||||
included: { everywhere: true },
|
||||
},
|
||||
],
|
||||
default: "yes-if-no-other",
|
||||
},
|
||||
{
|
||||
webExtension: {
|
||||
id: "excite@example.com",
|
||||
},
|
||||
appliesTo: [
|
||||
{
|
||||
included: { everywhere: true },
|
||||
// Test with a application/distributions section present but an
|
||||
// empty list.
|
||||
application: {
|
||||
distributions: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
webExtension: {
|
||||
id: "lycos@example.com",
|
||||
},
|
||||
appliesTo: [
|
||||
{
|
||||
included: { everywhere: true },
|
||||
application: {
|
||||
distributions: ["cake"],
|
||||
},
|
||||
},
|
||||
],
|
||||
default: "yes",
|
||||
},
|
||||
{
|
||||
webExtension: {
|
||||
id: "altavista@example.com",
|
||||
},
|
||||
appliesTo: [
|
||||
{
|
||||
included: { everywhere: true },
|
||||
application: {
|
||||
excludedDistributions: ["apples"],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const engineSelector = new SearchEngineSelector();
|
||||
add_task(async function setup() {
|
||||
await useTestEngines("data", null, CONFIG);
|
||||
await AddonTestUtils.promiseStartupManager();
|
||||
|
||||
await engineSelector.init();
|
||||
});
|
||||
|
||||
add_task(async function test_no_distribution_preference() {
|
||||
let { engines } = await engineSelector.fetchEngineConfiguration(
|
||||
"default",
|
||||
"default",
|
||||
"",
|
||||
""
|
||||
);
|
||||
const engineIds = engines.map(obj => obj.webExtension.id);
|
||||
Assert.deepEqual(
|
||||
engineIds,
|
||||
["aol@example.com", "excite@example.com", "altavista@example.com"],
|
||||
`Should have the expected engines for a normal build.`
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_distribution_included() {
|
||||
let { engines } = await engineSelector.fetchEngineConfiguration(
|
||||
"default",
|
||||
"default",
|
||||
"",
|
||||
"cake"
|
||||
);
|
||||
const engineIds = engines.map(obj => obj.webExtension.id);
|
||||
Assert.deepEqual(
|
||||
engineIds,
|
||||
[
|
||||
"lycos@example.com",
|
||||
"aol@example.com",
|
||||
"excite@example.com",
|
||||
"altavista@example.com",
|
||||
],
|
||||
`Should have the expected engines for the "cake" distribution.`
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_distribution_excluded() {
|
||||
let { engines } = await engineSelector.fetchEngineConfiguration(
|
||||
"default",
|
||||
"default",
|
||||
"",
|
||||
"apples"
|
||||
);
|
||||
const engineIds = engines.map(obj => obj.webExtension.id);
|
||||
Assert.deepEqual(
|
||||
engineIds,
|
||||
["aol@example.com", "excite@example.com"],
|
||||
`Should have the expected engines for the "apples" distribution.`
|
||||
);
|
||||
});
|
|
@ -54,6 +54,7 @@ support-files =
|
|||
|
||||
[include:xpcshell-common.ini]
|
||||
|
||||
[test_engine_selector_application_distribution.js]
|
||||
[test_engine_selector_application_name.js]
|
||||
[test_reload_engines.js]
|
||||
[test_location_timeout.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче