зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
b913159811
Коммит
4b9e5194b2
|
@ -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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче