Bug 1599839 - Merge sources and acceptableSources in UrlbarQueryContext. r=adw,mixedpuppy

Rename acceptableSources to just sources, merge it with the existing sources property.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Bonardo 2019-12-02 17:20:39 +00:00
Родитель b913159811
Коммит 4b9e5194b2
6 изменённых файлов: 23 добавлений и 26 удалений

Просмотреть файл

@ -49,7 +49,7 @@
"type": "string",
"description": "The query's search string."
},
"acceptableSources": {
"sources": {
"type": "array",
"description": "List of acceptable source types to return.",
"items": {

Просмотреть файл

@ -117,8 +117,8 @@ add_task(async function test_registerProvider() {
"SearchString is non empty"
);
browser.test.assertTrue(
Array.isArray(query.acceptableSources),
"acceptableSources is an array"
Array.isArray(query.sources),
"sources is an array"
);
return state;
}, name);
@ -193,7 +193,7 @@ add_task(async function test_onProviderResultsRequested() {
browser.test.assertFalse(query.isPrivate);
browser.test.assertEq(query.maxResults, 10);
browser.test.assertEq(query.searchString, "test");
browser.test.assertTrue(Array.isArray(query.acceptableSources));
browser.test.assertTrue(Array.isArray(query.sources));
return [
{
type: "remote_tab",

Просмотреть файл

@ -168,11 +168,10 @@ class ProvidersManager {
// Apply tokenization.
UrlbarTokenizer.tokenize(queryContext);
// Array of acceptable RESULT_SOURCE values for this query. Providers can
// use queryContext.acceptableSources to decide whether they want to be
// Providers can use queryContext.sources to decide whether they want to be
// invoked or not.
queryContext.acceptableSources = getAcceptableMatchSources(queryContext);
logger.debug(`Acceptable sources ${queryContext.acceptableSources}`);
updateSourcesIfEmpty(queryContext);
logger.debug(`Context sources ${queryContext.sources}`);
let query = new Query(queryContext, controller, muxer, providers);
this.queries.set(queryContext, query);
@ -269,7 +268,7 @@ class Query {
// This is used as a last safety filter in add(), thus we keep an unmodified
// copy of it.
this.acceptableSources = queryContext.acceptableSources.slice();
this.acceptableSources = queryContext.sources.slice();
}
/**
@ -431,11 +430,13 @@ class Query {
}
/**
* Gets an array of the provider sources accepted for a given UrlbarQueryContext.
* Updates in place the sources for a given UrlbarQueryContext.
* @param {UrlbarQueryContext} context The query context to examine
* @returns {array} Array of accepted sources
*/
function getAcceptableMatchSources(context) {
function updateSourcesIfEmpty(context) {
if (context.sources && context.sources.length) {
return;
}
let acceptedSources = [];
// There can be only one restrict token about sources.
let restrictToken = context.tokens.find(t =>
@ -506,5 +507,5 @@ function getAcceptableMatchSources(context) {
break;
}
}
return acceptedSources;
context.sources = acceptedSources;
}

Просмотреть файл

@ -542,6 +542,8 @@ class UrlbarQueryContext {
* Whether or not to allow providers to include autofill results.
* @param {number} options.userContextId
* The container id where this context was generated, if any.
* @param {array} [options.sources]
* A list of acceptable UrlbarUtils.RESULT_SOURCE for the context.
*/
constructor(options = {}) {
this._checkRequiredOptions(options, [

Просмотреть файл

@ -42,15 +42,15 @@ It is augmented as it progresses through the system, with various information:
// through the UrlbarProvidersManager.
providers; // {array} List of registered provider names. Providers can be
// registered through the UrlbarProvidersManager.
sources; // {array} If provided is the list of sources, as defined by
// RESULT_SOURCE.*, that can be returned by the model.
sources: {array} list of accepted UrlbarUtils.RESULT_SOURCE for the context.
// This allows to switch between different search modes. If not
// provided, a default will be generated by the Model, depending on
// the search string.
// Properties added by the Model.
results; // {array} list of UrlbarResult objects.
tokens; // {array} tokens extracted from the searchString, each token is an
// object in the form {type, value, lowerCaseValue}.
acceptableSources; // {array} list of UrlbarUtils.RESULT_SOURCE that the
// model will accept for this context.
}

Просмотреть файл

@ -159,10 +159,8 @@ add_task(async function test_filter_isActive() {
return UrlbarUtils.PROVIDER_TYPE.PROFILE;
}
isActive(context) {
info("Acceptable sources: " + context.acceptableSources);
return context.acceptableSources.includes(
UrlbarUtils.RESULT_SOURCE.BOOKMARKS
);
info("Acceptable sources: " + context.sources);
return context.sources.includes(UrlbarUtils.RESULT_SOURCE.BOOKMARKS);
}
isRestricting(context) {
return false;
@ -316,11 +314,7 @@ add_task(async function test_nofilter_restrict() {
return UrlbarUtils.PROVIDER_TYPE.IMMEDIATE;
}
isActive(context) {
Assert.equal(
context.acceptableSources.length,
1,
"Check acceptableSources"
);
Assert.equal(context.sources.length, 1, "Check acceptable sources");
return true;
}
isRestricting(context) {