Bug 720501 - urlInlineComplete should not attempt to case-preserve results, since that interferes with the controller's case-preservation.

r=gavin
This commit is contained in:
Marco Bonardo 2012-01-26 00:54:25 +01:00
parent 4c5eda8628
commit a8611d3d04
4 changed files with 109 additions and 9 deletions

View File

@ -785,6 +785,7 @@ nsPlacesAutoComplete.prototype = {
// Clear our state
delete this._originalSearchString;
delete this._currentSearchString;
delete this._strippedPrefix;
delete this._searchTokens;
delete this._listener;
delete this._result;
@ -1380,6 +1381,11 @@ urlInlineComplete.prototype = {
this._originalSearchString = aSearchString;
this._currentSearchString =
fixupSearchText(this._originalSearchString.toLowerCase());
// The protocol and the domain are lowercased by nsIURI, so it's fine to
// lowercase the typed prefix to add it back to the results later.
this._strippedPrefix = this._originalSearchString.slice(
0, this._originalSearchString.length - this._currentSearchString.length
).toLowerCase();
let result = Cc["@mozilla.org/autocomplete/simple-result;1"].
createInstance(Ci.nsIAutoCompleteSimpleResult);
@ -1419,8 +1425,7 @@ urlInlineComplete.prototype = {
if (hasDomainResult) {
// We got a match for a domain, we can add it immediately.
let appendResult = domain.slice(this._currentSearchString.length);
result.appendMatch(aSearchString + appendResult, "");
result.appendMatch(this._strippedPrefix + domain, "");
this._finishSearch();
return;
@ -1493,17 +1498,18 @@ urlInlineComplete.prototype = {
let url = fixupSearchText(row.getResultByIndex(0));
// We must complete the URL up to the next separator (which is /, ? or #).
let appendText = url.slice(this._currentSearchString.length);
let separatorIndex = appendText.search(/[\/\?\#]/);
let separatorIndex = url.slice(this._currentSearchString.length)
.search(/[\/\?\#]/);
if (separatorIndex != -1) {
if (appendText[separatorIndex] == "/") {
separatorIndex += this._currentSearchString.length;
if (url[separatorIndex] == "/") {
separatorIndex++; // Include the "/" separator
}
appendText = appendText.slice(0, separatorIndex);
url = url.slice(0, separatorIndex);
}
// Add the result
this._result.appendMatch(this._originalSearchString + appendText, "");
this._result.appendMatch(this._strippedPrefix + url, "");
// handleCompletion() will cause the result listener to be called, and
// will display the result in the UI.

View File

@ -53,6 +53,9 @@ AutoCompleteInput.prototype = {
this._selEnd = aEnd;
},
onTextEntered: function() false,
onTextReverted: function() false,
get searchCount() {
return this.searches.length;
},
@ -66,7 +69,7 @@ AutoCompleteInput.prototype = {
popupOpen: false,
popup: {
selectedIndex: 0,
selectedIndex: -1,
invalidate: function () {},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup])
@ -80,8 +83,24 @@ AutoCompleteInput.prototype = {
* String to search.
* @param aExpectedValue
* Expected value returned by autoFill.
* May be a string, or an object like
* {
* autoFilled: the value suggested by autofill,
* completed: the value completed on user's confirmation
* }
* In the latter case this will also check that on user's confirmation
* the result's casing is correctly applied.
*/
function ensure_results(aSearchString, aExpectedValue) {
let autoFilledValue, completedValue;
if (typeof(aExpectedValue) == "string") {
autoFilledValue = aExpectedValue;
}
else {
autoFilledValue = aExpectedValue.autoFilled;
completedValue = aExpectedValue.completed;
}
// Make an AutoCompleteInput that uses our searches and confirms results.
let input = new AutoCompleteInput(["urlinline"]);
input.textValue = aSearchString;
@ -107,7 +126,15 @@ function ensure_results(aSearchString, aExpectedValue) {
do_check_eq(numSearchesStarted, 1);
// Check the autoFilled result.
do_check_eq(input.textValue, aExpectedValue);
do_check_eq(input.textValue, autoFilledValue);
if (completedValue) {
// Now force completion and check correct casing of the result.
// This ensures the controller is able to do its magic case-preserving
// stuff and correct replacement of the user's casing with result's one.
controller.handleEnter(false);
do_check_eq(input.textValue, completedValue);
}
waitForCleanup(run_next_test);
};

View File

@ -0,0 +1,66 @@
/* 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/. */
add_autocomplete_test([
"Searching for cased entry 1",
"MOZ",
{ autoFilled: "MOZilla.org/", completed: "mozilla.org/" },
function () {
addBookmark({ url: "http://mozilla.org/test/" });
}
]);
add_autocomplete_test([
"Searching for cased entry 2",
"mozilla.org/T",
{ autoFilled: "mozilla.org/Test/", completed: "mozilla.org/test/" },
function () {
addBookmark({ url: "http://mozilla.org/test/" });
}
]);
add_autocomplete_test([
"Searching for cased entry 3",
"mOzilla.org/t",
{ autoFilled: "mOzilla.org/test/", completed: "mozilla.org/Test/" },
function () {
addBookmark({ url: "http://mozilla.org/Test/" });
},
]);
add_autocomplete_test([
"Searching for untrimmed cased entry",
"http://mOz",
{ autoFilled: "http://mOzilla.org/", completed: "http://mozilla.org/" },
function () {
addBookmark({ url: "http://mozilla.org/Test/" });
},
]);
add_autocomplete_test([
"Searching for untrimmed cased entry with www",
"http://www.mOz",
{ autoFilled: "http://www.mOzilla.org/", completed: "http://www.mozilla.org/" },
function () {
addBookmark({ url: "http://www.mozilla.org/Test/" });
},
]);
add_autocomplete_test([
"Searching for untrimmed cased entry with path",
"http://mOzilla.org/t",
{ autoFilled: "http://mOzilla.org/test/", completed: "http://mozilla.org/Test/" },
function () {
addBookmark({ url: "http://mozilla.org/Test/" });
},
]);
add_autocomplete_test([
"Searching for untrimmed cased entry with www and path",
"http://www.mOzilla.org/t",
{ autoFilled: "http://www.mOzilla.org/test/", completed: "http://www.mozilla.org/Test/" },
function () {
addBookmark({ url: "http://www.mozilla.org/Test/" });
},
]);

View File

@ -2,4 +2,5 @@
head = head_autocomplete.js
tail =
[test_casing.js]
[test_keywords.js]