Bug 1124238 - The autofill placeholder should not override keywords. r=mak
MozReview-Commit-ID: D6gBdkQxMrW
--- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp
@@ -1524,18 +1524,30 @@ nsAutoCompleteController::CompleteDefaul
bool shouldComplete;
input->GetCompleteDefaultIndex(&shouldComplete);
if (!shouldComplete)
return NS_OK;
nsAutoString resultValue;
if (NS_SUCCEEDED(GetDefaultCompleteValue(aResultIndex, true, resultValue))) {
CompleteValue(resultValue);
-
mDefaultIndexCompleted = true;
+ } else {
+ // Reset the search string again, in case it was completed with
+ // mPlaceholderCompletionString, but the actually received result doesn't
+ // have a default index result. Only reset the input when necessary, to
+ // avoid triggering unnecessary new searches.
+ nsAutoString inputValue;
+ input->GetTextValue(inputValue);
+ if (!inputValue.Equals(mSearchString)) {
+ SetValueOfInputTo(mSearchString,
+ nsIAutoCompleteInput::TEXTVALUE_REASON_REVERT);
+ input->SelectTextRange(mSearchString.Length(), mSearchString.Length());
+ }
+ mPlaceholderCompletionString.Truncate();
}
return NS_OK;
}
nsresult
nsAutoCompleteController::GetDefaultCompleteResult(int32_t aResultIndex,
nsIAutoCompleteResult** _result,
--- a/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
+++ b/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
@@ -167,17 +167,17 @@ async function _check_autocomplete_match
async function check_autocomplete(test) {
// At this point frecency could still be updating due to latest pages
// updates.
// This is not a problem in real life, but autocomplete tests should
// return reliable resultsets, thus we have to wait.
await PlacesTestUtils.promiseAsyncUpdates();
// Make an AutoCompleteInput that uses our searches and confirms results.
- let input = new AutoCompleteInput(["unifiedcomplete"]);
+ let input = test.input || new AutoCompleteInput(["unifiedcomplete"]);
input.textValue = test.search;
if (test.searchParam)
input.searchParam = test.searchParam;
// Caret must be at the end for autoFill to happen.
let strLen = test.search.length;
input.selectTextRange(strLen, strLen);
@@ -281,16 +281,17 @@ async function check_autocomplete(test)
// 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);
Assert.equal(input.textValue, test.completed,
"Completed value is correct");
}
+ return input;
}
var addBookmark = async function(aBookmarkObj) {
Assert.ok(!!aBookmarkObj.uri, "Bookmark object contains an uri");
let parentId = aBookmarkObj.parentId ? aBookmarkObj.parentId
: PlacesUtils.unfiledBookmarksFolderId;
let bm = await PlacesUtils.bookmarks.insert({
--- a/toolkit/components/places/tests/unifiedcomplete/test_keywords.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_keywords.js
@@ -1,73 +1,113 @@
/* 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_task(async function test_non_keyword() {
info("Searching for non-keyworded entry should autoFill it");
await PlacesTestUtils.addVisits({
- uri: NetUtil.newURI("http://mozilla.org/test/"),
+ uri: Services.io.newURI("http://mozilla.org/test/"),
});
- await addBookmark({ uri: NetUtil.newURI("http://mozilla.org/test/") });
+ await addBookmark({ uri: Services.io.newURI("http://mozilla.org/test/") });
await check_autocomplete({
search: "moz",
autofilled: "mozilla.org/",
completed: "http://mozilla.org/"
});
await cleanup();
});
add_task(async function test_keyword() {
info("Searching for keyworded entry should not autoFill it");
await PlacesTestUtils.addVisits({
- uri: NetUtil.newURI("http://mozilla.org/test/"),
+ uri: Services.io.newURI("http://mozilla.org/test/"),
});
- await addBookmark({ uri: NetUtil.newURI("http://mozilla.org/test/"), keyword: "moz" });
+ await addBookmark({ uri: Services.io.newURI("http://mozilla.org/test/"), keyword: "moz" });
await check_autocomplete({
search: "moz",
autofilled: "moz",
completed: "moz",
});
await cleanup();
});
add_task(async function test_more_than_keyword() {
info("Searching for more than keyworded entry should autoFill it");
await PlacesTestUtils.addVisits({
- uri: NetUtil.newURI("http://mozilla.org/test/"),
+ uri: Services.io.newURI("http://mozilla.org/test/"),
});
- await addBookmark({ uri: NetUtil.newURI("http://mozilla.org/test/"), keyword: "moz" });
+ await addBookmark({ uri: Services.io.newURI("http://mozilla.org/test/"), keyword: "moz" });
await check_autocomplete({
search: "mozi",
autofilled: "mozilla.org/",
completed: "http://mozilla.org/"
});
await cleanup();
});
add_task(async function test_less_than_keyword() {
info("Searching for less than keyworded entry should autoFill it");
await PlacesTestUtils.addVisits({
- uri: NetUtil.newURI("http://mozilla.org/test/"),
+ uri: Services.io.newURI("http://mozilla.org/test/"),
});
- await addBookmark({ uri: NetUtil.newURI("http://mozilla.org/test/"), keyword: "moz" });
+ await addBookmark({ uri: Services.io.newURI("http://mozilla.org/test/"), keyword: "moz" });
await check_autocomplete({
search: "mo",
autofilled: "mozilla.org/",
completed: "http://mozilla.org/",
});
await cleanup();
});
add_task(async function test_keyword_casing() {
info("Searching for keyworded entry is case-insensitive");
await PlacesTestUtils.addVisits({
- uri: NetUtil.newURI("http://mozilla.org/test/"),
+ uri: Services.io.newURI("http://mozilla.org/test/"),
});
- await addBookmark({ uri: NetUtil.newURI("http://mozilla.org/test/"), keyword: "moz" });
+ await addBookmark({ uri: Services.io.newURI("http://mozilla.org/test/"), keyword: "moz" });
await check_autocomplete({
search: "MoZ",
autofilled: "MoZ",
completed: "MoZ"
});
await cleanup();
});
+
+add_task(async function test_less_then_equal_than_keyword_bug_1124238() {
+ info("Searching for less than keyworded entry should autoFill it");
+ await PlacesTestUtils.addVisits({
+ uri: Services.io.newURI("http://mozilla.org/test/"),
+ transition: TRANSITION_TYPED
+ });
+ await PlacesTestUtils.addVisits("http://mozilla.com/");
+ addBookmark({ uri: Services.io.newURI("http://mozilla.com/"), keyword: "moz" });
+
+ let input = await check_autocomplete({
+ search: "mo",
+ autofilled: "mozilla.org/",
+ completed: "http://mozilla.org/",
+ });
+
+ info(input.textValue);
+
+ // Emulate the input of an additional character. As the input matches a
+ // keyword, the completion should equal the keyword and not the URI as before.
+ input.textValue = "moz";
+ await check_autocomplete({
+ input,
+ search: "moz",
+ autofilled: "moz",
+ completed: "moz",
+ });
+
+ // Emulate the input of an additional character. The input doesn't match a
+ // keyword anymore, it should be autofilled.
+ input.textValue = "moz";
+ await check_autocomplete({
+ input,
+ search: "mozi",
+ autofilled: "mozilla.org/",
+ completed: "http://mozilla.org/",
+ });
+
+ await cleanup();
+});