Bug 1043942 - UnifiedComplete disables inline autocomplete if urlbar behavior is not the default. r=ttaubert

This commit is contained in:
Marco Bonardo 2014-08-01 16:53:05 +02:00
Родитель 679d802ec0
Коммит a61c0773bb
5 изменённых файлов: 350 добавлений и 21 удалений

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

@ -198,10 +198,30 @@ const SQL_HOST_QUERY = sql(
const SQL_TYPED_HOST_QUERY = SQL_HOST_QUERY.replace("/*CONDITIONS*/",
"AND typed = 1");
const SQL_BOOKMARKED_HOST_QUERY = sql(
"/* 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 ",
"WHERE rev_host = get_unreversed_host(host || '.') || '.'",
"OR rev_host = get_unreversed_host(host || '.') || '.www.'",
") AS bookmarked, NULL, NULL, NULL, NULL, NULL, NULL, frecency",
"FROM moz_hosts",
"WHERE host BETWEEN :searchString AND :searchString || X'FFFF'",
"AND bookmarked",
"AND frecency <> 0",
"/*CONDITIONS*/",
"ORDER BY frecency DESC",
"LIMIT 1");
const SQL_BOOKMARKED_TYPED_HOST_QUERY =
SQL_BOOKMARKED_HOST_QUERY.replace("/*CONDITIONS*/", "AND typed = 1");
const SQL_URL_QUERY = sql(
"/* do not warn (bug no): cannot use an index */",
"SELECT :query_type, h.url, NULL,",
"NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, h.frecency",
"NULL, foreign_count > 0 AS bookmarked, NULL, NULL, NULL, NULL, NULL, NULL, h.frecency",
"FROM moz_places h",
"WHERE h.frecency <> 0",
"/*CONDITIONS*/",
@ -215,6 +235,13 @@ const SQL_URL_QUERY = sql(
const SQL_TYPED_URL_QUERY = SQL_URL_QUERY.replace("/*CONDITIONS*/",
"AND typed = 1");
// TODO (bug 1045924): use foreign_count once available.
const SQL_BOOKMARKED_URL_QUERY =
SQL_URL_QUERY.replace("/*CONDITIONS*/", "AND bookmarked");
const SQL_BOOKMARKED_TYPED_URL_QUERY =
SQL_URL_QUERY.replace("/*CONDITIONS*/", "AND bookmarked AND typed = 1");
////////////////////////////////////////////////////////////////////////////////
//// Getters
@ -784,7 +811,8 @@ Search.prototype = {
}
match.value = this._strippedPrefix + trimmedHost;
match.comment = trimmedHost;
// Remove the trailing slash.
match.comment = stripHttpAndTrim(trimmedHost);
match.finalCompleteValue = untrimmedHost;
match.frecency = frecency;
return match;
@ -1020,8 +1048,18 @@ Search.prototype = {
// Then, we should not try to autofill if the behavior is not the default.
// TODO (bug 751709): Ideally we should have a more fine-grained behavior
// here, but for now it's enough to just check for default behavior.
if (Prefs.defaultBehavior != DEFAULT_BEHAVIOR)
return false;
if (Prefs.defaultBehavior != DEFAULT_BEHAVIOR) {
// autoFill can only cope with history or bookmarks entries
// (typed or not).
if (!this.hasBehavior("typed") &&
!this.hasBehavior("history") &&
!this.hasBehavior("bookmark"))
return false;
// autoFill doesn't search titles or tags.
if (this.hasBehavior("title") || this.hasBehavior("tags"))
return false;
}
// Don't try to autofill if the search term includes any whitespace.
// This may confuse completeDefaultIndex cause the AUTOCOMPLETE_MATCH
@ -1049,13 +1087,21 @@ Search.prototype = {
* @return an array consisting of the correctly optimized query to search the
* database with and an object containing the params to bound.
*/
get _hostQuery() [
Prefs.autofillTyped ? SQL_TYPED_HOST_QUERY : SQL_HOST_QUERY,
{
query_type: QUERYTYPE_AUTOFILL_HOST,
searchString: this._searchString.toLowerCase()
}
],
get _hostQuery() {
let typed = Prefs.autofillTyped || this.hasBehavior("typed");
let bookmarked = this.hasBehavior("bookmark");
return [
bookmarked ? typed ? SQL_BOOKMARKED_TYPED_HOST_QUERY
: SQL_BOOKMARKED_HOST_QUERY
: typed ? SQL_TYPED_HOST_QUERY
: SQL_HOST_QUERY,
{
query_type: QUERYTYPE_AUTOFILL_HOST,
searchString: this._searchString.toLowerCase()
}
];
},
/**
* Obtains the query to search for autoFill url results.
@ -1063,15 +1109,23 @@ Search.prototype = {
* @return an array consisting of the correctly optimized query to search the
* database with and an object containing the params to bound.
*/
get _urlQuery() [
Prefs.autofillTyped ? SQL_TYPED_URL_QUERY : SQL_URL_QUERY,
{
query_type: QUERYTYPE_AUTOFILL_URL,
searchString: this._autofillUrlSearchString,
matchBehavior: MATCH_BEGINNING_CASE_SENSITIVE,
searchBehavior: Ci.mozIPlacesAutoComplete.BEHAVIOR_URL
}
],
get _urlQuery() {
let typed = Prefs.autofillTyped || this.hasBehavior("typed");
let bookmarked = this.hasBehavior("bookmark");
return [
bookmarked ? typed ? SQL_BOOKMARKED_TYPED_URL_QUERY
: SQL_BOOKMARKED_URL_QUERY
: typed ? SQL_TYPED_URL_QUERY
: SQL_URL_QUERY,
{
query_type: QUERYTYPE_AUTOFILL_URL,
searchString: this._autofillUrlSearchString,
matchBehavior: MATCH_BEGINNING_CASE_SENSITIVE,
searchBehavior: Ci.mozIPlacesAutoComplete.BEHAVIOR_URL
}
];
},
/**
* Notifies the listener about results.

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

@ -0,0 +1,269 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test autoFill for different default behaviors.
*/
add_task(function* test_default_behavior_host() {
let uri1 = NetUtil.newURI("http://typed/");
let uri2 = NetUtil.newURI("http://visited/");
let uri3 = NetUtil.newURI("http://bookmarked/");
let uri4 = NetUtil.newURI("http://tpbk/");
yield promiseAddVisits([
{ uri: uri1, title: "typed", transition: TRANSITION_TYPED },
{ uri: uri2, title: "visited" },
{ uri: uri4, title: "tpbk", transition: TRANSITION_TYPED },
]);
addBookmark( { uri: uri3, title: "bookmarked" } );
addBookmark( { uri: uri4, title: "tpbk" } );
// RESTRICT TO HISTORY.
Services.prefs.setIntPref("browser.urlbar.default.behavior", 1);
do_log_info("Restrict history, common visit, should not autoFill");
yield check_autocomplete({
search: "vi",
matches: [ { uri: uri2, title: "visited" } ],
autofilled: "vi",
completed: "vi"
});
do_log_info("Restrict history, typed visit, should autoFill");
yield check_autocomplete({
search: "ty",
matches: [ { uri: uri1, title: "typed" } ],
autofilled: "typed/",
completed: "typed/"
});
// Don't autoFill this one cause it's not typed.
do_log_info("Restrict history, bookmark, should not autoFill");
yield check_autocomplete({
search: "bo",
matches: [ ],
autofilled: "bo",
completed: "bo"
});
// Note we don't show this one cause it's not typed.
do_log_info("Restrict history, typed bookmark, should autoFill");
yield check_autocomplete({
search: "tp",
matches: [ { uri: uri4, title: "tpbk" } ],
autofilled: "tpbk/",
completed: "tpbk/"
});
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
// We are not restricting on typed, so we autoFill the bookmark even if we
// are restricted to history. We accept that cause not doing that
// would be a perf hit and the privacy implications are very weak.
do_log_info("Restrict history, bookmark, autoFill.typed = false, should autoFill");
yield check_autocomplete({
search: "bo",
matches: [ { uri: uri3, title: "bookmarked" } ],
autofilled: "bookmarked/",
completed: "bookmarked/"
});
do_log_info("Restrict history, common visit, autoFill.typed = false, should autoFill");
yield check_autocomplete({
search: "vi",
matches: [ { uri: uri2, title: "visited" } ],
autofilled: "visited/",
completed: "visited/"
});
// RESTRICT TO TYPED.
// This should basically ignore autoFill.typed and acts as if it would be set.
Services.prefs.setIntPref("browser.urlbar.default.behavior", 32);
// Typed behavior basically acts like history, but filters on typed.
do_log_info("Restrict typed, common visit, autoFill.typed = false, should not autoFill");
yield check_autocomplete({
search: "vi",
matches: [ ],
autofilled: "vi",
completed: "vi"
});
do_log_info("Restrict typed, typed visit, autofill.typed = false, should autoFill");
yield check_autocomplete({
search: "ty",
matches: [ { uri: uri1, title: "typed" } ],
autofilled: "typed/",
completed: "typed/"
});
do_log_info("Restrict typed, bookmark, autofill.typed = false, should not autoFill");
yield check_autocomplete({
search: "bo",
matches: [ ],
autofilled: "bo",
completed: "bo"
});
do_log_info("Restrict typed, typed bookmark, autofill.typed = false, should autoFill");
yield check_autocomplete({
search: "tp",
matches: [ { uri: uri4, title: "tpbk" } ],
autofilled: "tpbk/",
completed: "tpbk/"
});
// RESTRICT BOOKMARKS.
Services.prefs.setIntPref("browser.urlbar.default.behavior", 2);
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", true);
do_log_info("Restrict bookmarks, common visit, should not autoFill");
yield check_autocomplete({
search: "vi",
matches: [ ],
autofilled: "vi",
completed: "vi"
});
do_log_info("Restrict bookmarks, typed visit, should not autoFill");
yield check_autocomplete({
search: "ty",
matches: [ ],
autofilled: "ty",
completed: "ty"
});
// Don't autoFill this one cause it's not typed.
do_log_info("Restrict bookmarks, bookmark, should not autoFill");
yield check_autocomplete({
search: "bo",
matches: [ { uri: uri3, title: "bookmarked" } ],
autofilled: "bo",
completed: "bo"
});
// Note we don't show this one cause it's not typed.
do_log_info("Restrict bookmarks, typed bookmark, should autoFill");
yield check_autocomplete({
search: "tp",
matches: [ { uri: uri4, title: "tpbk" } ],
autofilled: "tpbk/",
completed: "tpbk/"
});
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
do_log_info("Restrict bookmarks, bookmark, autofill.typed = false, should autoFill");
yield check_autocomplete({
search: "bo",
matches: [ { uri: uri3, title: "bookmarked" } ],
autofilled: "bookmarked/",
completed: "bookmarked/"
});
yield cleanup();
});
add_task(function* test_default_behavior_url() {
let uri1 = NetUtil.newURI("http://typed/ty/");
let uri2 = NetUtil.newURI("http://visited/vi/");
let uri3 = NetUtil.newURI("http://bookmarked/bo/");
let uri4 = NetUtil.newURI("http://tpbk/tp/");
yield promiseAddVisits([
{ uri: uri1, title: "typed", transition: TRANSITION_TYPED },
{ uri: uri2, title: "visited" },
{ uri: uri4, title: "tpbk", transition: TRANSITION_TYPED },
]);
addBookmark( { uri: uri3, title: "bookmarked" } );
addBookmark( { uri: uri4, title: "tpbk" } );
// RESTRICT TO HISTORY.
Services.prefs.setIntPref("browser.urlbar.default.behavior", 1);
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", true);
do_log_info("URL: Restrict history, common visit, should not autoFill");
yield check_autocomplete({
search: "visited/v",
matches: [ { uri: uri2, title: "visited" } ],
autofilled: "visited/v",
completed: "visited/v"
});
do_log_info("URL: Restrict history, typed visit, should autoFill");
yield check_autocomplete({
search: "typed/t",
matches: [ { uri: uri1, title: "typed/ty/" } ],
autofilled: "typed/ty/",
completed: "http://typed/ty/"
});
// Don't autoFill this one cause it's not typed.
do_log_info("URL: Restrict history, bookmark, should not autoFill");
yield check_autocomplete({
search: "bookmarked/b",
matches: [ ],
autofilled: "bookmarked/b",
completed: "bookmarked/b"
});
// Note we don't show this one cause it's not typed.
do_log_info("URL: Restrict history, typed bookmark, should autoFill");
yield check_autocomplete({
search: "tpbk/t",
matches: [ { uri: uri4, title: "tpbk/tp/" } ],
autofilled: "tpbk/tp/",
completed: "http://tpbk/tp/"
});
// RESTRICT BOOKMARKS.
Services.prefs.setIntPref("browser.urlbar.default.behavior", 2);
do_log_info("URL: Restrict bookmarks, common visit, should not autoFill");
yield check_autocomplete({
search: "visited/v",
matches: [ ],
autofilled: "visited/v",
completed: "visited/v"
});
do_log_info("URL: Restrict bookmarks, typed visit, should not autoFill");
yield check_autocomplete({
search: "typed/t",
matches: [ ],
autofilled: "typed/t",
completed: "typed/t"
});
// Don't autoFill this one cause it's not typed.
do_log_info("URL: Restrict bookmarks, bookmark, should not autoFill");
yield check_autocomplete({
search: "bookmarked/b",
matches: [ { uri: uri3, title: "bookmarked" } ],
autofilled: "bookmarked/b",
completed: "bookmarked/b"
});
// Note we don't show this one cause it's not typed.
do_log_info("URL: Restrict bookmarks, typed bookmark, should autoFill");
yield check_autocomplete({
search: "tpbk/t",
matches: [ { uri: uri4, title: "tpbk/tp/" } ],
autofilled: "tpbk/tp/",
completed: "http://tpbk/tp/"
});
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
do_log_info("URL: Restrict bookmarks, bookmark, autofill.typed = false, should autoFill");
yield check_autocomplete({
search: "bookmarked/b",
matches: [ { uri: uri3, title: "bookmarked/bo/" } ],
autofilled: "bookmarked/bo/",
completed: "http://bookmarked/bo/"
});
yield cleanup();
});

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

@ -12,7 +12,8 @@ add_task(function* test_dupe_urls() {
search: "moz",
autofilled: "mozilla.org/",
completed: "mozilla.org/",
matches: [ { uri: NetUtil.newURI("http://mozilla.org/"), title: "mozilla.org/" } ]
matches: [ { uri: NetUtil.newURI("http://mozilla.org/"),
title: "mozilla.org" } ]
});
yield cleanup();
});

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

@ -358,6 +358,10 @@ add_task(function* test_special_searches() {
matches: [ { uri: uri11, title: "title", tags: [ "foo.bar" ] } ]
});
// Disable autoFill for the next tests, see test_autoFill_default_behavior.js
// for specific tests.
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
// Test default usage by setting certain bits of default.behavior to 1
do_log_info("foo -> default history");
Services.prefs.setIntPref("browser.urlbar.default.behavior", 1);

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

@ -9,6 +9,7 @@ tail =
[test_422277.js]
[test_autocomplete_functional.js]
[test_autocomplete_on_value_removed_479089.js]
[test_autoFill_default_behavior.js]
[test_casing.js]
[test_do_not_trim.js]
[test_download_embed_bookmarks.js]