зеркало из https://github.com/mozilla/gecko-dev.git
Bug 995092 - Ensure we can enable Unified Autocomplete in Nightly. r=ttaubert
This commit is contained in:
Родитель
4d31269447
Коммит
4c1e833e43
|
@ -72,6 +72,7 @@
|
|||
try {
|
||||
if (this._prefs.getBoolPref("unifiedcomplete")) {
|
||||
this.setAttribute("autocompletesearch", "unifiedcomplete");
|
||||
this.mSearchNames = null;
|
||||
}
|
||||
} catch (ex) {}
|
||||
|
||||
|
@ -612,6 +613,7 @@
|
|||
this.setAttribute("autocompletesearch",
|
||||
useUnifiedComplete ? "unifiedcomplete"
|
||||
: "urlinline history");
|
||||
this.mSearchNames = null;
|
||||
}
|
||||
}
|
||||
]]></body>
|
||||
|
|
|
@ -434,6 +434,26 @@ function stripPrefix(spec)
|
|||
return spec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip http and trailing separators from a spec.
|
||||
*
|
||||
* @param spec
|
||||
* The text to modify.
|
||||
* @return the modified spec.
|
||||
*/
|
||||
function stripHttpAndTrim(spec) {
|
||||
if (spec.startsWith("http://")) {
|
||||
spec = spec.slice(7);
|
||||
}
|
||||
if (spec.endsWith("?")) {
|
||||
spec = spec.slice(0, -1);
|
||||
}
|
||||
if (spec.endsWith("/")) {
|
||||
spec = spec.slice(0, -1);
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Search Class
|
||||
//// Manages a single instance of an autocomplete search.
|
||||
|
@ -716,8 +736,9 @@ Search.prototype = {
|
|||
}
|
||||
|
||||
// Must check both id and url, cause keywords dinamically modify the url.
|
||||
let urlMapKey = stripHttpAndTrim(match.value);
|
||||
if ((!match.placeId || !this._usedPlaceIds.has(match.placeId)) &&
|
||||
!this._usedURLs.has(match.value)) {
|
||||
!this._usedURLs.has(urlMapKey)) {
|
||||
// Add this to our internal tracker to ensure duplicates do not end up in
|
||||
// the result.
|
||||
// Not all entries have a place id, thus we fallback to the url for them.
|
||||
|
@ -726,7 +747,7 @@ Search.prototype = {
|
|||
// are faster too.
|
||||
if (match.placeId)
|
||||
this._usedPlaceIds.add(match.placeId);
|
||||
this._usedURLs.add(match.value);
|
||||
this._usedURLs.add(urlMapKey);
|
||||
|
||||
this._result.appendMatch(match.value,
|
||||
match.comment,
|
||||
|
@ -759,7 +780,6 @@ Search.prototype = {
|
|||
// ignore it and complete to the found host.
|
||||
if (untrimmedHost &&
|
||||
!untrimmedHost.toLowerCase().contains(this._trimmedOriginalSearchString.toLowerCase())) {
|
||||
// THIS CAUSES null TO BE SHOWN AS TITLE.
|
||||
untrimmedHost = null;
|
||||
}
|
||||
|
||||
|
@ -794,7 +814,6 @@ Search.prototype = {
|
|||
let untrimmedURL = prefix + url;
|
||||
if (untrimmedURL &&
|
||||
!untrimmedURL.toLowerCase().contains(this._trimmedOriginalSearchString.toLowerCase())) {
|
||||
// THIS CAUSES null TO BE SHOWN AS TITLE.
|
||||
untrimmedURL = null;
|
||||
}
|
||||
|
||||
|
@ -872,6 +891,9 @@ Search.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
if (action)
|
||||
match.style = "action " + match.style;
|
||||
|
||||
match.value = url;
|
||||
match.comment = title;
|
||||
if (iconurl) {
|
||||
|
|
|
@ -150,10 +150,14 @@ function* check_autocomplete(test) {
|
|||
|
||||
do_log_info("Checking against expected '" + uri.spec + "', '" + title + "'...");
|
||||
// Got a match on both uri and title?
|
||||
if (uri.spec == value && title == comment) {
|
||||
if (stripPrefix(uri.spec) == stripPrefix(value) && title == comment) {
|
||||
do_log_info("Got a match at index " + j + "!");
|
||||
// Make it undefined so we don't process it again
|
||||
test.matches[j] = undefined;
|
||||
if (uri.spec.startsWith("moz-action:")) {
|
||||
let style = controller.getStyleAt(i);
|
||||
Assert.ok(style.contains("action"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -242,3 +246,26 @@ function resetRestrict(aType) {
|
|||
|
||||
Services.prefs.clearUserPref(branch + aType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip prefixes from the URI that we don't care about for searching.
|
||||
*
|
||||
* @param spec
|
||||
* The text to modify.
|
||||
* @return the modified spec.
|
||||
*/
|
||||
function stripPrefix(spec)
|
||||
{
|
||||
["http://", "https://", "ftp://"].some(scheme => {
|
||||
if (spec.startsWith(scheme)) {
|
||||
spec = spec.slice(scheme.length);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (spec.startsWith("www.")) {
|
||||
spec = spec.slice(4);
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Ensure inline autocomplete doesn't return zero frecency pages.
|
||||
|
||||
add_task(function* test_dupe_urls() {
|
||||
do_log_info("Searching for urls with dupes should only show one");
|
||||
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/"),
|
||||
transition: TRANSITION_TYPED },
|
||||
{ uri: NetUtil.newURI("http://mozilla.org/?") });
|
||||
yield check_autocomplete({
|
||||
search: "moz",
|
||||
autofilled: "mozilla.org/",
|
||||
completed: "mozilla.org/",
|
||||
matches: [ { uri: NetUtil.newURI("http://mozilla.org/"), title: "mozilla.org/" } ]
|
||||
});
|
||||
yield cleanup();
|
||||
});
|
|
@ -12,6 +12,7 @@ tail =
|
|||
[test_casing.js]
|
||||
[test_do_not_trim.js]
|
||||
[test_download_embed_bookmarks.js]
|
||||
[test_dupe_urls.js]
|
||||
[test_empty_search.js]
|
||||
[test_enabled.js]
|
||||
[test_escape_self.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче