summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-10 23:27:32 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-10 23:27:32 +0000
commit9e78974689a785e035d107fcf793880fd338e416 (patch)
tree5b670eeb39cd10aeb13e5c652342fb8abd9dab61 /chrome/browser/autocomplete
parent5894335286ebbaf32decd466f8f54e42dbada9f8 (diff)
downloadchromium_src-9e78974689a785e035d107fcf793880fd338e416.zip
chromium_src-9e78974689a785e035d107fcf793880fd338e416.tar.gz
chromium_src-9e78974689a785e035d107fcf793880fd338e416.tar.bz2
Adds lab for making instant suggest autocomplete immediately. As part
of this I encountered a bug in SearchProvider::FinalizeInstantQuery which has been fixed (with test). BUG=none TEST=none Review URL: http://codereview.chromium.org/6142008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70960 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/search_provider.cc19
-rw-r--r--chrome/browser/autocomplete/search_provider.h3
-rw-r--r--chrome/browser/autocomplete/search_provider_unittest.cc36
3 files changed, 55 insertions, 3 deletions
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 4c9da21..f7c7cb3 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -78,6 +78,8 @@ void SearchProvider::FinalizeInstantQuery(const std::wstring& input_text,
return;
}
+ default_provider_suggest_text_ = suggest_text;
+
std::wstring adjusted_input_text(input_text);
AutocompleteInput::RemoveForcedQueryStringIfNecessary(input_.type(),
&adjusted_input_text);
@@ -162,9 +164,12 @@ void SearchProvider::Start(const AutocompleteInput& input,
// If we're still running an old query but have since changed the query text
// or the providers, abort the query.
- if (!done_ && (!minimal_changes ||
- !providers_.equals(default_provider, keyword_provider))) {
- Stop();
+ if (!minimal_changes ||
+ !providers_.equals(default_provider, keyword_provider)) {
+ if (done_)
+ default_provider_suggest_text_.clear();
+ else
+ Stop();
}
providers_.Set(default_provider, keyword_provider);
@@ -218,6 +223,7 @@ void SearchProvider::Run() {
void SearchProvider::Stop() {
StopSuggest();
done_ = true;
+ default_provider_suggest_text_.clear();
}
void SearchProvider::OnURLFetchComplete(const URLFetcher* source,
@@ -531,6 +537,13 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() {
AutocompleteMatch::SEARCH_WHAT_YOU_TYPED,
did_not_accept_default_suggestion, false,
input_.initial_prevent_inline_autocomplete(), &map);
+ if (!default_provider_suggest_text_.empty()) {
+ AddMatchToMap(input_.text() + default_provider_suggest_text_,
+ input_.text(), CalculateRelevanceForWhatYouTyped() + 1,
+ AutocompleteMatch::SEARCH_SUGGEST,
+ did_not_accept_default_suggestion, false,
+ input_.initial_prevent_inline_autocomplete(), &map);
+ }
}
AddHistoryResultsToMap(keyword_history_results_, true,
diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h
index 9b83c3d..6f1d462 100644
--- a/chrome/browser/autocomplete/search_provider.h
+++ b/chrome/browser/autocomplete/search_provider.h
@@ -317,6 +317,9 @@ class SearchProvider : public AutocompleteProvider,
// Has FinalizeInstantQuery been invoked since the last |Start|?
bool instant_finalized_;
+ // The |suggest_text| parameter passed to FinalizeInstantQuery.
+ std::wstring default_provider_suggest_text_;
+
DISALLOW_COPY_AND_ASSIGN(SearchProvider);
};
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
index 7120a08..80ae91a 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -388,3 +388,39 @@ TEST_F(SearchProviderTest, FinalizeInstantQuery) {
// The instant search should be more relevant.
EXPECT_GT(instant_match.relevance, what_you_typed_match.relevance);
}
+
+// Make sure that if FinalizeInstantQuery is invoked before suggest results
+// return, the suggest text from FinalizeInstantQuery is remembered.
+TEST_F(SearchProviderTest, RememberInstantQuery) {
+ PrefService* service = profile_.GetPrefs();
+ service->SetBoolean(prefs::kInstantEnabled, true);
+
+ QueryForInput(ASCIIToUTF16("foo"), false);
+
+ // Finalize the instant query immediately.
+ provider_->FinalizeInstantQuery(L"foo", L"bar");
+
+ // There should be two matches, one for what you typed, the other for
+ // 'foobar'.
+ EXPECT_EQ(2u, provider_->matches().size());
+ GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms(
+ *default_t_url_, L"foobar", 0, std::wstring()));
+ AutocompleteMatch instant_match = FindMatchWithDestination(instant_url);
+ EXPECT_FALSE(instant_match.destination_url.is_empty());
+
+ // Wait until history and the suggest query complete.
+ profile_.BlockUntilHistoryProcessesPendingRequests();
+ ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
+
+ // Provider should be done.
+ EXPECT_TRUE(provider_->done());
+
+ // There should be two matches, one for what you typed, the other for
+ // 'foobar'.
+ EXPECT_EQ(2u, provider_->matches().size());
+ instant_match = FindMatchWithDestination(instant_url);
+ EXPECT_FALSE(instant_match.destination_url.is_empty());
+
+ // And the 'foobar' match should have a description.
+ EXPECT_FALSE(instant_match.description.empty());
+}