Bug 1163888 - Autofilled entries in unified complete are missing the favicon even if it's available. r=markh

This commit is contained in:
Marco Bonardo 2015-06-03 21:11:58 +02:00
Родитель e20b2bd833
Коммит 0ac53c78a6
3 изменённых файлов: 79 добавлений и 39 удалений

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

@ -158,7 +158,12 @@ function hostQuery(conditions = "") {
let query =
`/* do not warn (bug NA): not worth to index on (typed, frecency) */
SELECT :query_type, host || '/', IFNULL(prefix, '') || host || '/',
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, frecency
( SELECT f.url FROM moz_favicons f
JOIN moz_places h ON h.favicon_id = f.id
WHERE rev_host = get_unreversed_host(host || '.') || '.'
OR rev_host = get_unreversed_host(host || '.') || '.www.'
) AS favicon_url,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, frecency
FROM moz_hosts
WHERE host BETWEEN :searchString AND :searchString || X'FFFF'
AND frecency <> 0
@ -176,8 +181,12 @@ function bookmarkedHostQuery(conditions = "") {
let query =
`/* do not warn (bug NA): not worth to index on (typed, frecency) */
SELECT :query_type, host || '/', IFNULL(prefix, '') || host || '/',
NULL, (
SELECT foreign_count > 0 FROM moz_places
( SELECT f.url FROM moz_favicons f
JOIN moz_places h ON h.favicon_id = f.id
WHERE rev_host = get_unreversed_host(host || '.') || '.'
OR rev_host = get_unreversed_host(host || '.') || '.www.'
) AS favicon_url,
( SELECT foreign_count > 0 FROM moz_places
WHERE rev_host = get_unreversed_host(host || '.') || '.'
OR rev_host = get_unreversed_host(host || '.') || '.www.'
) AS bookmarked, NULL, NULL, NULL, NULL, NULL, NULL, frecency
@ -198,9 +207,11 @@ const SQL_BOOKMARKED_TYPED_HOST_QUERY = bookmarkedHostQuery("AND typed = 1");
function urlQuery(conditions = "") {
let query =
`/* do not warn (bug no): cannot use an index */
SELECT :query_type, h.url, NULL,
NULL, foreign_count > 0 AS bookmarked, NULL, NULL, NULL, NULL, NULL, NULL, h.frecency
SELECT :query_type, h.url, NULL, f.url AS favicon_url,
foreign_count > 0 AS bookmarked,
NULL, NULL, NULL, NULL, NULL, NULL, h.frecency
FROM moz_places h
LEFT JOIN moz_favicons f ON h.favicon_id = f.id
WHERE h.frecency <> 0
${conditions}
AND AUTOCOMPLETE_MATCH(:searchString, h.url,
@ -1176,6 +1187,7 @@ Search.prototype = {
let trimmedHost = row.getResultByIndex(QUERYINDEX_URL);
let untrimmedHost = row.getResultByIndex(QUERYINDEX_TITLE);
let frecency = row.getResultByIndex(QUERYINDEX_FRECENCY);
let faviconUrl = row.getResultByIndex(QUERYINDEX_ICONURL);
// If the untrimmed value doesn't preserve the user's input just
// ignore it and complete to the found host.
@ -1188,15 +1200,7 @@ Search.prototype = {
// Remove the trailing slash.
match.comment = stripHttpAndTrim(trimmedHost);
match.finalCompleteValue = untrimmedHost;
try {
let iconURI = NetUtil.newURI(untrimmedHost);
iconURI.path = "/favicon.ico";
match.icon = PlacesUtils.favicons.getFaviconLinkForIcon(iconURI).spec;
} catch (e) {
// This can fail, which is ok.
}
match.icon = faviconUrl;
// Although this has a frecency, this query is executed before any other
// queries that would result in frecency matches.
match.frecency = frecency;
@ -1209,6 +1213,7 @@ Search.prototype = {
let value = row.getResultByIndex(QUERYINDEX_URL);
let url = fixupSearchText(value);
let frecency = row.getResultByIndex(QUERYINDEX_FRECENCY);
let faviconUrl = row.getResultByIndex(QUERYINDEX_ICONURL);
let prefix = value.slice(0, value.length - stripPrefix(value).length);
@ -1234,6 +1239,7 @@ Search.prototype = {
match.value = this._strippedPrefix + url;
match.comment = url;
match.finalCompleteValue = untrimmedURL;
match.icon = faviconUrl;
// Although this has a frecency, this query is executed before any other
// queries that would result in frecency matches.
match.frecency = frecency;

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

@ -99,9 +99,8 @@ AutoCompleteInput.prototype = {
// A helper for check_autocomplete to check a specific match against data from
// the controller.
function _check_autocomplete_matches(match, controllerInfo) {
function _check_autocomplete_matches(match, result) {
let { uri, title, tags, searchEngine, style } = match;
let { controllerValue, controllerComment, controllerStyle } = controllerInfo;
if (tags)
title += " \u2013 " + tags.sort().join(", ");
if (searchEngine)
@ -113,15 +112,20 @@ function _check_autocomplete_matches(match, controllerInfo) {
do_print("Checking against expected '" + uri.spec + "', '" + title + "'...");
// Got a match on both uri and title?
if (stripPrefix(uri.spec) != stripPrefix(controllerValue) || title != controllerComment) {
if (stripPrefix(uri.spec) != stripPrefix(result.value) || title != result.comment) {
return false;
}
let actualStyle = controllerStyle.split(/\s+/).sort();
let actualStyle = result.style.split(/\s+/).sort();
if (style)
Assert.equal(actualStyle.toString(), style.toString(), "Match should have expected style");
if (uri.spec.startsWith("moz-action:")) {
Assert.ok(actualStyle.indexOf("action") != -1, "moz-action results should always have 'action' in their style");
}
if (match.icon)
Assert.equal(result.image, match.icon, "Match should have expected image");
return true;
}
@ -184,27 +188,31 @@ function* check_autocomplete(test) {
if (test.searchParam && test.searchParam == "enable-actions") {
firstIndexToCheck = 1;
do_print("Checking first match is first autocomplete entry")
let controllerValue = controller.getValueAt(0);
let controllerComment = controller.getCommentAt(0);
let controllerStyle = controller.getStyleAt(0);
do_print("First match is '" + controllerValue + "', '" + controllerComment + "");
let controllerInfo = { controllerValue, controllerComment, controllerStyle };
Assert.ok(_check_autocomplete_matches(matches[0], controllerInfo), "first item is correct");
let result = {
value: controller.getValueAt(0),
comment: controller.getCommentAt(0),
style: controller.getStyleAt(0),
image: controller.getImageAt(0),
}
do_print(`First match is "${result.value}", " ${result.comment}"`);
Assert.ok(_check_autocomplete_matches(matches[0], result), "first item is correct");
do_print("Checking rest of the matches");
}
for (let i = firstIndexToCheck; i < controller.matchCount; i++) {
let controllerValue = controller.getValueAt(i);
let controllerComment = controller.getCommentAt(i);
let controllerStyle = controller.getStyleAt(i);
let controllerInfo = { controllerValue, controllerComment, controllerStyle };
do_print("Looking for '" + controllerValue + "', '" + controllerComment + "' in expected results...");
let result = {
value: controller.getValueAt(i),
comment: controller.getCommentAt(i),
style: controller.getStyleAt(i),
image: controller.getImageAt(i),
}
do_print(`Looking for "${result.value}", "${result.comment}" in expected results...`);
let j;
for (j = firstIndexToCheck; j < matches.length; j++) {
// Skip processed expected results
if (matches[j] == undefined)
continue;
if (_check_autocomplete_matches(matches[j], controllerInfo)) {
if (_check_autocomplete_matches(matches[j], result)) {
do_print("Got a match at index " + j + "!");
// Make it undefined so we don't process it again
matches[j] = undefined;
@ -214,7 +222,7 @@ function* check_autocomplete(test) {
// We didn't hit the break, so we must have not found it
if (j == matches.length)
do_throw("Didn't find the current result ('" + controllerValue + "', '" + controllerComment + "') in matches");
do_throw(`Didn't find the current result ("${result.value}", "${result.comment}") in matches`);
}
Assert.equal(controller.matchCount, matches.length,
@ -373,6 +381,18 @@ function makeSwitchToTabMatch(url, extra = {}) {
}
}
function setFaviconForHref(href, iconHref) {
return new Promise(resolve => {
PlacesUtils.favicons.setAndFetchFaviconForPage(
NetUtil.newURI(href),
NetUtil.newURI(iconHref),
true,
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
resolve
);
});
}
// Ensure we have a default search engine and the keyword.enabled preference
// set.
add_task(function ensure_search_engine() {

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

@ -22,6 +22,9 @@ add_task(function* test_default_behavior_host() {
yield addBookmark( { uri: uri4, title: "tpbk" } );
yield addBookmark( { uri: uri5, title: "title", tags: ["foo"] } );
yield setFaviconForHref(uri1.spec, "chrome://global/skin/icons/information-16.png");
yield setFaviconForHref(uri3.spec, "chrome://global/skin/icons/error-16.png");
// RESTRICT TO HISTORY.
Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
Services.prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", false);
@ -38,7 +41,8 @@ add_task(function* test_default_behavior_host() {
do_print("Restrict history, typed visit, should autoFill");
yield check_autocomplete({
search: "ty",
matches: [ { uri: uri1, title: "typed", style: [ "autofill" ] } ],
matches: [ { uri: uri1, title: "typed", style: [ "autofill" ],
icon: "chrome://global/skin/icons/information-16.png" } ],
autofilled: "typed/",
completed: "typed/"
});
@ -69,7 +73,8 @@ add_task(function* test_default_behavior_host() {
do_print("Restrict history, bookmark, autoFill.typed = false, should autoFill");
yield check_autocomplete({
search: "bo",
matches: [ { uri: uri3, title: "bookmarked", style: [ "bookmark" ], style: [ "autofill" ] } ],
matches: [ { uri: uri3, title: "bookmarked", style: [ "bookmark" ], style: [ "autofill" ],
icon: "chrome://global/skin/icons/error-16.png" } ],
autofilled: "bookmarked/",
completed: "bookmarked/"
});
@ -98,7 +103,8 @@ add_task(function* test_default_behavior_host() {
do_print("Restrict typed, typed visit, autofill.typed = false, should autoFill");
yield check_autocomplete({
search: "ty",
matches: [ { uri: uri1, title: "typed", style: [ "autofill" ] } ],
matches: [ { uri: uri1, title: "typed", style: [ "autofill" ],
icon: "chrome://global/skin/icons/information-16.png"} ],
autofilled: "typed/",
completed: "typed/"
});
@ -144,7 +150,8 @@ add_task(function* test_default_behavior_host() {
do_print("Restrict bookmarks, bookmark, should not autoFill");
yield check_autocomplete({
search: "bo",
matches: [ { uri: uri3, title: "bookmarked", style: [ "bookmark" ] } ],
matches: [ { uri: uri3, title: "bookmarked", style: [ "bookmark" ],
icon: "chrome://global/skin/icons/error-16.png"} ],
autofilled: "bo",
completed: "bo"
});
@ -163,7 +170,8 @@ add_task(function* test_default_behavior_host() {
do_print("Restrict bookmarks, bookmark, autofill.typed = false, should autoFill");
yield check_autocomplete({
search: "bo",
matches: [ { uri: uri3, title: "bookmarked", style: [ "autofill" ] } ],
matches: [ { uri: uri3, title: "bookmarked", style: [ "autofill" ],
icon: "chrome://global/skin/icons/error-16.png" } ],
autofilled: "bookmarked/",
completed: "bookmarked/"
});
@ -203,6 +211,9 @@ add_task(function* test_default_behavior_url() {
yield addBookmark( { uri: uri3, title: "bookmarked" } );
yield addBookmark( { uri: uri4, title: "tpbk" } );
yield setFaviconForHref(uri1.spec, "chrome://global/skin/icons/information-16.png");
yield setFaviconForHref(uri3.spec, "chrome://global/skin/icons/error-16.png");
// RESTRICT TO HISTORY.
Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
Services.prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", false);
@ -221,7 +232,8 @@ add_task(function* test_default_behavior_url() {
do_print("URL: Restrict history, typed visit, should autoFill");
yield check_autocomplete({
search: "typed/t",
matches: [ { uri: uri1, title: "typed/ty/", style: [ "autofill" ] } ],
matches: [ { uri: uri1, title: "typed/ty/", style: [ "autofill" ],
icon: "chrome://global/skin/icons/information-16.png"} ],
autofilled: "typed/ty/",
completed: "http://typed/ty/"
});
@ -268,7 +280,8 @@ add_task(function* test_default_behavior_url() {
do_print("URL: Restrict bookmarks, bookmark, should not autoFill");
yield check_autocomplete({
search: "bookmarked/b",
matches: [ { uri: uri3, title: "bookmarked", style: [ "bookmark" ] } ],
matches: [ { uri: uri3, title: "bookmarked", style: [ "bookmark" ],
icon: "chrome://global/skin/icons/error-16.png" } ],
autofilled: "bookmarked/b",
completed: "bookmarked/b"
});
@ -287,7 +300,8 @@ add_task(function* test_default_behavior_url() {
do_print("URL: Restrict bookmarks, bookmark, autofill.typed = false, should autoFill");
yield check_autocomplete({
search: "bookmarked/b",
matches: [ { uri: uri3, title: "bookmarked/bo/", style: [ "autofill" ] } ],
matches: [ { uri: uri3, title: "bookmarked/bo/", style: [ "autofill" ],
icon: "chrome://global/skin/icons/error-16.png" } ],
autofilled: "bookmarked/bo/",
completed: "http://bookmarked/bo/"
});