Bug 1687767 - Don't highlight url heuristic results without autocompleted parts. r=harry

Avoid the cost of highligthing unvisited heuristic url results, since the whole
string would just be copied over and highlighted, paying an unnecessary cost.
Note, here we could go with an HIGHLIGHT.ALL mode, to retain the current behavior,
but highlighting the full url just makes it less readable, and we're not adding
anything to it, so highligting the typed part is not useful regardless.

Also don't try to autofill very long strings, it's expensive and not useful,
since the autofilled part would be out of screen anyway.

Differential Revision: https://phabricator.services.mozilla.com/D102485
This commit is contained in:
Marco Bonardo 2021-01-21 11:21:58 +00:00
Родитель 4460528639
Коммит 8c5544a801
4 изменённых файлов: 43 добавлений и 16 удалений

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

@ -286,6 +286,12 @@ class ProviderAutofill extends UrlbarProvider {
return false;
}
// Trying to autofill an extremely long string would be expensive, and
// not particularly useful since the filled part falls out of screen anyway.
if (queryContext.searchString.length > UrlbarUtils.MAX_TEXT_LENGTH) {
return false;
}
// autoFill can only cope with history, bookmarks, and about: entries.
if (
!queryContext.sources.includes(UrlbarUtils.RESULT_SOURCE.HISTORY) &&

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

@ -161,8 +161,8 @@ class ProviderHeuristicFallback extends UrlbarProvider {
UrlbarUtils.RESULT_TYPE.URL,
UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, {
title: [searchUrl, UrlbarUtils.HIGHLIGHT.TYPED],
url: [searchUrl, UrlbarUtils.HIGHLIGHT.TYPED],
title: [searchUrl, UrlbarUtils.HIGHLIGHT.NONE],
url: [searchUrl, UrlbarUtils.HIGHLIGHT.NONE],
})
);
result.heuristic = true;
@ -219,8 +219,8 @@ class ProviderHeuristicFallback extends UrlbarProvider {
UrlbarUtils.RESULT_TYPE.URL,
UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, {
title: [displayURL, UrlbarUtils.HIGHLIGHT.TYPED],
url: [escapedURL, UrlbarUtils.HIGHLIGHT.TYPED],
title: [displayURL, UrlbarUtils.HIGHLIGHT.NONE],
url: [escapedURL, UrlbarUtils.HIGHLIGHT.NONE],
icon: iconUri,
})
);

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

@ -158,6 +158,7 @@ var UrlbarUtils = {
// Whether a result should be highlighted up to the point the user has typed
// or after that point.
HIGHLIGHT: {
NONE: 0,
TYPED: 1,
SUGGESTED: 2,
},

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

@ -17,21 +17,22 @@ add_task(async function setup() {
});
});
async function testResult(input, expected) {
async function testResult(input, expected, index = 1) {
const ESCAPED_URL = encodeURI(input.url);
await PlacesUtils.history.clear();
await PlacesTestUtils.addVisits({
uri: input.url,
title: input.title,
});
if (index > 0) {
await PlacesTestUtils.addVisits({
uri: input.url,
title: input.title,
});
}
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: input.query,
});
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, index);
Assert.equal(result.url, ESCAPED_URL, "Should have the correct url to load");
Assert.equal(
result.displayed.url,
@ -48,11 +49,13 @@ async function testResult(input, expected) {
"none",
"Should not have a type icon"
);
Assert.equal(
result.image,
`page-icon:${ESCAPED_URL}`,
"Should have the correct favicon"
);
if (index > 0) {
Assert.equal(
result.image,
`page-icon:${ESCAPED_URL}`,
"Should have the correct favicon"
);
}
assertDisplayedHighlights(
"title",
@ -332,3 +335,20 @@ add_task(async function test_case_insensitive_highlights_6() {
}
);
});
add_task(async function test_no_highlight_fallback_heuristic_url() {
info("Test unvisited heuristic (fallback provider)");
await testResult(
{
query: "nonexisting.com",
title: "http://nonexisting.com/",
url: "http://nonexisting.com/",
},
{
displayedUrl: "", // URL heuristic only has title.
highlightedTitle: [["http://nonexisting.com/", false]],
highlightedUrl: [],
},
0 // Test the heuristic result.
);
});