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 063d93d4a9
commit 26d4f75f0c
4 changed files with 67 additions and 9 deletions

View File

@ -1419,8 +1419,7 @@ urlInlineComplete.prototype = {
if (hasDomainResult) { if (hasDomainResult) {
// We got a match for a domain, we can add it immediately. // We got a match for a domain, we can add it immediately.
let appendResult = domain.slice(this._currentSearchString.length); result.appendMatch(domain, "");
result.appendMatch(aSearchString + appendResult, "");
this._finishSearch(); this._finishSearch();
return; return;
@ -1493,17 +1492,18 @@ urlInlineComplete.prototype = {
let url = fixupSearchText(row.getResultByIndex(0)); let url = fixupSearchText(row.getResultByIndex(0));
// We must complete the URL up to the next separator (which is /, ? or #). // We must complete the URL up to the next separator (which is /, ? or #).
let appendText = url.slice(this._currentSearchString.length); let separatorIndex = url.slice(this._currentSearchString.length)
let separatorIndex = appendText.search(/[\/\?\#]/); .search(/[\/\?\#]/);
if (separatorIndex != -1) { if (separatorIndex != -1) {
if (appendText[separatorIndex] == "/") { separatorIndex += this._currentSearchString.length;
if (url[separatorIndex] == "/") {
separatorIndex++; // Include the "/" separator separatorIndex++; // Include the "/" separator
} }
appendText = appendText.slice(0, separatorIndex); url = url.slice(0, separatorIndex);
} }
// Add the result // Add the result
this._result.appendMatch(this._originalSearchString + appendText, ""); this._result.appendMatch(url, "");
// handleCompletion() will cause the result listener to be called, and // handleCompletion() will cause the result listener to be called, and
// will display the result in the UI. // will display the result in the UI.

View File

@ -53,6 +53,9 @@ AutoCompleteInput.prototype = {
this._selEnd = aEnd; this._selEnd = aEnd;
}, },
onTextEntered: function() false,
onTextReverted: function() false,
get searchCount() { get searchCount() {
return this.searches.length; return this.searches.length;
}, },
@ -66,7 +69,7 @@ AutoCompleteInput.prototype = {
popupOpen: false, popupOpen: false,
popup: { popup: {
selectedIndex: 0, selectedIndex: -1,
invalidate: function () {}, invalidate: function () {},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup]) QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup])
@ -80,8 +83,24 @@ AutoCompleteInput.prototype = {
* String to search. * String to search.
* @param aExpectedValue * @param aExpectedValue
* Expected value returned by autoFill. * 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) { 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. // Make an AutoCompleteInput that uses our searches and confirms results.
let input = new AutoCompleteInput(["urlinline"]); let input = new AutoCompleteInput(["urlinline"]);
input.textValue = aSearchString; input.textValue = aSearchString;
@ -107,7 +126,15 @@ function ensure_results(aSearchString, aExpectedValue) {
do_check_eq(numSearchesStarted, 1); do_check_eq(numSearchesStarted, 1);
// Check the autoFilled result. // 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); waitForCleanup(run_next_test);
}; };

View File

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

View File

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