Bug 1605161 - The muxer shouldn't put non-search-suggestions results in the suggestions bucket. r=adw

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Bonardo 2020-01-23 16:53:04 +00:00
parent 1110c2bfad
commit dd6f2af24c
2 changed files with 69 additions and 16 deletions

View File

@ -24,15 +24,18 @@ XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Muxer.UnifiedComplete")
);
const RESULT_TYPE_TO_GROUP = new Map([
[UrlbarUtils.RESULT_TYPE.TAB_SWITCH, UrlbarUtils.RESULT_GROUP.GENERAL],
[UrlbarUtils.RESULT_TYPE.SEARCH, UrlbarUtils.RESULT_GROUP.SUGGESTION],
[UrlbarUtils.RESULT_TYPE.URL, UrlbarUtils.RESULT_GROUP.GENERAL],
[UrlbarUtils.RESULT_TYPE.KEYWORD, UrlbarUtils.RESULT_GROUP.GENERAL],
[UrlbarUtils.RESULT_TYPE.OMNIBOX, UrlbarUtils.RESULT_GROUP.EXTENSION],
[UrlbarUtils.RESULT_TYPE.REMOTE_TAB, UrlbarUtils.RESULT_GROUP.GENERAL],
[UrlbarUtils.RESULT_TYPE.TIP, UrlbarUtils.RESULT_GROUP.GENERAL],
]);
function groupFromResult(result) {
switch (result.type) {
case UrlbarUtils.RESULT_TYPE.SEARCH:
return result.payload.suggestion
? UrlbarUtils.RESULT_GROUP.SUGGESTION
: UrlbarUtils.RESULT_GROUP.GENERAL;
case UrlbarUtils.RESULT_TYPE.OMNIBOX:
return UrlbarUtils.RESULT_GROUP.EXTENSION;
default:
return UrlbarUtils.RESULT_GROUP.GENERAL;
}
}
/**
* Class used to create a muxer.
@ -112,7 +115,7 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
sortedResults.unshift(result);
handled.add(result);
slots--;
} else if (group == RESULT_TYPE_TO_GROUP.get(result.type)) {
} else if (group == groupFromResult(result)) {
// If there's no suggestedIndex, insert the result now, otherwise
// we'll handle it later.
if (result.suggestedIndex < 0) {
@ -120,12 +123,6 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
}
handled.add(result);
slots--;
} else if (!RESULT_TYPE_TO_GROUP.has(result.type)) {
let errorMsg = `Result type ${
result.type
} is not mapped to a match group.`;
logger.error(errorMsg);
Cu.reportError(errorMsg);
}
}
}

View File

@ -172,3 +172,59 @@ add_task(async function test_preselectedHeuristic_multiProviders() {
matches2[2],
]);
});
add_task(async function test_suggestions() {
let matches = [
new UrlbarResult(
UrlbarUtils.RESULT_TYPE.URL,
UrlbarUtils.RESULT_SOURCE.HISTORY,
{ url: "http://mozilla.org/a" }
),
new UrlbarResult(
UrlbarUtils.RESULT_TYPE.URL,
UrlbarUtils.RESULT_SOURCE.HISTORY,
{ url: "http://mozilla.org/b" }
),
new UrlbarResult(
UrlbarUtils.RESULT_TYPE.SEARCH,
UrlbarUtils.RESULT_SOURCE.SEARCH,
{
engine: "mozSearch",
query: "moz",
suggestion: "mozilla",
}
),
new UrlbarResult(
UrlbarUtils.RESULT_TYPE.SEARCH,
UrlbarUtils.RESULT_SOURCE.SEARCH,
{
engine: "mozSearch",
query: "moz",
keywordOffer: UrlbarUtils.KEYWORD_OFFER.SHOW,
keyword: "@moz",
}
),
new UrlbarResult(
UrlbarUtils.RESULT_TYPE.URL,
UrlbarUtils.RESULT_SOURCE.HISTORY,
{ url: "http://mozilla.org/c" }
),
];
let providerName = registerBasicTestProvider(matches);
let context = createContext(undefined, {
providers: [providerName],
});
let controller = UrlbarTestUtils.newMockController();
info("Check results, the order should be: moz, a, b, @moz, c");
await UrlbarProvidersManager.startQuery(context, controller);
Assert.deepEqual(context.results, [
matches[2],
matches[0],
matches[1],
matches[3],
matches[4],
]);
});