Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4344)

Unified Diff: chrome/browser/autocomplete/search_provider_unittest.cc

Issue 7314018: Don't autocomplete searches of >1 word if they've only been visited once and the user has not yet... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/search_provider_unittest.cc
===================================================================
--- chrome/browser/autocomplete/search_provider_unittest.cc (revision 92729)
+++ chrome/browser/autocomplete/search_provider_unittest.cc (working copy)
@@ -52,10 +52,14 @@
virtual void TearDown();
protected:
- // Returns an AutocompleteMatch in provider_'s set of matches that matches
- // |url|. If there is no matching URL, an empty match is returned.
- AutocompleteMatch FindMatchWithDestination(const GURL& url);
+ // Adds a search for |term|, using the engine |t_url| to the history, and
+ // returns the URL for that search.
+ GURL AddSearchToHistory(TemplateURL* t_url, string16 term, int visit_count);
+ // Looks for a match in |provider_| with destination |url|. Sets |match| to
+ // it if found. Returns whether |match| was set.
+ bool FindMatchWithDestination(const GURL& url, AutocompleteMatch* match);
+
// ACProviderListener method. If we're waiting for the provider to finish,
// this exits the message loop.
virtual void OnProviderUpdate(bool updated_matches);
@@ -65,10 +69,13 @@
void RunTillProviderDone();
// Invokes Start on provider_, then runs all pending tasks.
- void QueryForInput(const string16& text,
- bool prevent_inline_autocomplete,
- bool minimal_changes);
+ void QueryForInput(const string16& text, bool prevent_inline_autocomplete);
+ // Calls QueryForInput(), finishes any suggest query, then if |wyt_match| is
+ // non-NULL, sets it to the "what you typed" entry for |text|.
+ void QueryForInputAndSetWYTMatch(const string16& text,
+ AutocompleteMatch* wyt_match);
+
// Notifies the URLFetcher for the suggest query corresponding to the default
// search provider that it's done.
// Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE.
@@ -123,15 +130,7 @@
ASSERT_NE(0, default_provider_id);
// Add url1, with search term term1_.
- HistoryService* history =
- profile_.GetHistoryService(Profile::EXPLICIT_ACCESS);
- term1_url_ = GURL(default_t_url_->url()->ReplaceSearchTerms(
- *default_t_url_, term1_, 0, string16()));
- history->AddPageWithDetails(term1_url_, string16(), 1, 1,
- base::Time::Now(), false,
- history::SOURCE_BROWSED);
- history->SetKeywordSearchTermsForURL(term1_url_, default_t_url_->id(),
- term1_);
+ term1_url_ = AddSearchToHistory(default_t_url_, term1_, 1);
// Create another TemplateURL.
keyword_t_url_ = new TemplateURL();
@@ -144,13 +143,7 @@
ASSERT_NE(0, keyword_t_url_->id());
// Add a page and search term for keyword_t_url_.
- keyword_url_ = GURL(keyword_t_url_->url()->ReplaceSearchTerms(
- *keyword_t_url_, keyword_term_, 0, string16()));
- history->AddPageWithDetails(keyword_url_, string16(), 1, 1,
- base::Time::Now(), false,
- history::SOURCE_BROWSED);
- history->SetKeywordSearchTermsForURL(keyword_url_, keyword_t_url_->id(),
- keyword_term_);
+ keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1);
// Keywords are updated by the InMemoryHistoryBackend only after the message
// has been processed on the history thread. Block until history processes all
@@ -182,18 +175,33 @@
}
void SearchProviderTest::QueryForInput(const string16& text,
- bool prevent_inline_autocomplete,
- bool minimal_changes) {
+ bool prevent_inline_autocomplete) {
// Start a query.
AutocompleteInput input(text, string16(), prevent_inline_autocomplete,
false, true, AutocompleteInput::ALL_MATCHES);
- provider_->Start(input, minimal_changes);
+ provider_->Start(input, false);
// RunAllPending so that the task scheduled by SearchProvider to create the
// URLFetchers runs.
message_loop_.RunAllPending();
}
+void SearchProviderTest::QueryForInputAndSetWYTMatch(
+ const string16& text,
+ AutocompleteMatch* wyt_match) {
+ QueryForInput(text, false);
+ profile_.BlockUntilHistoryProcessesPendingRequests();
+ ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
+ EXPECT_NE(profile_.GetPrefs()->GetBoolean(prefs::kInstantEnabled),
+ provider_->done());
+ if (!wyt_match)
+ return;
+ ASSERT_GE(provider_->matches().size(), 1u);
+ EXPECT_TRUE(FindMatchWithDestination(GURL(
+ default_t_url_->url()->ReplaceSearchTerms(*default_t_url_, text, 0,
+ string16())), wyt_match));
+}
+
void SearchProviderTest::TearDown() {
message_loop_.RunAllPending();
@@ -203,14 +211,31 @@
provider_ = NULL;
}
-AutocompleteMatch SearchProviderTest::FindMatchWithDestination(
- const GURL& url) {
+GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url,
+ string16 term,
+ int visit_count) {
+ HistoryService* history =
+ profile_.GetHistoryService(Profile::EXPLICIT_ACCESS);
+ GURL search(t_url->url()->ReplaceSearchTerms(*t_url, term, 0, string16()));
+ static base::Time last_added_time;
+ last_added_time = std::max(base::Time::Now(),
+ last_added_time + base::TimeDelta::FromMicroseconds(1));
+ history->AddPageWithDetails(search, string16(), visit_count, visit_count,
+ last_added_time, false, history::SOURCE_BROWSED);
+ history->SetKeywordSearchTermsForURL(search, t_url->id(), term);
+ return search;
+}
+
+bool SearchProviderTest::FindMatchWithDestination(const GURL& url,
+ AutocompleteMatch* match) {
for (ACMatches::const_iterator i = provider_->matches().begin();
i != provider_->matches().end(); ++i) {
- if (i->destination_url == url)
- return *i;
+ if (i->destination_url == url) {
+ *match = *i;
+ return true;
+ }
}
- return AutocompleteMatch(NULL, 1, false, AutocompleteMatch::HISTORY_URL);
+ return false;
}
void SearchProviderTest::FinishDefaultSuggestQuery() {
@@ -230,7 +255,7 @@
// created for the default provider suggest results.
TEST_F(SearchProviderTest, QueryDefaultProvider) {
string16 term = term1_.substr(0, term1_.length() - 1);
- QueryForInput(term, false, false);
+ QueryForInput(term, false);
// Make sure the default providers suggest service was queried.
TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
@@ -253,25 +278,24 @@
// The SearchProvider is done. Make sure it has a result for the history
// term term1.
- AutocompleteMatch term1_match = FindMatchWithDestination(term1_url_);
- EXPECT_TRUE(!term1_match.destination_url.is_empty());
+ AutocompleteMatch term1_match;
+ EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match));
// Term1 should not have a description, it's set later.
EXPECT_TRUE(term1_match.description.empty());
- GURL what_you_typed_url = GURL(default_t_url_->url()->ReplaceSearchTerms(
- *default_t_url_, term, 0, string16()));
- AutocompleteMatch what_you_typed_match =
- FindMatchWithDestination(what_you_typed_url);
- EXPECT_TRUE(!what_you_typed_match.destination_url.is_empty());
- EXPECT_TRUE(what_you_typed_match.description.empty());
+ AutocompleteMatch wyt_match;
+ EXPECT_TRUE(FindMatchWithDestination(GURL(
+ default_t_url_->url()->ReplaceSearchTerms(*default_t_url_, term, 0,
+ string16())), &wyt_match));
+ EXPECT_TRUE(wyt_match.description.empty());
// The match for term1 should be more relevant than the what you typed result.
- EXPECT_GT(term1_match.relevance, what_you_typed_match.relevance);
+ EXPECT_GT(term1_match.relevance, wyt_match.relevance);
}
TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) {
string16 term = term1_.substr(0, term1_.length() - 1);
- QueryForInput(term, true, false);
+ QueryForInput(term, true);
ASSERT_FALSE(provider_->matches().empty());
ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED,
@@ -282,8 +306,7 @@
// is queried as well as URLFetchers getting created.
TEST_F(SearchProviderTest, QueryKeywordProvider) {
string16 term = keyword_term_.substr(0, keyword_term_.length() - 1);
- QueryForInput(keyword_t_url_->keyword() + UTF8ToUTF16(" ") + term, false,
- false);
+ QueryForInput(keyword_t_url_->keyword() + UTF8ToUTF16(" ") + term, false);
// Make sure the default providers suggest service was queried.
TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID(
@@ -317,8 +340,8 @@
// The SearchProvider is done. Make sure it has a result for the history
// term keyword.
- AutocompleteMatch match = FindMatchWithDestination(keyword_url_);
- ASSERT_TRUE(!match.destination_url.is_empty());
+ AutocompleteMatch match;
+ EXPECT_TRUE(FindMatchWithDestination(keyword_url_, &match));
// The match should have a TemplateURL.
EXPECT_TRUE(match.template_url);
@@ -346,7 +369,7 @@
};
for (size_t i = 0; i < arraysize(inputs); ++i) {
- QueryForInput(ASCIIToUTF16(inputs[i]), false, false);
+ QueryForInput(ASCIIToUTF16(inputs[i]), false);
// Make sure the default providers suggest service was not queried.
ASSERT_TRUE(test_factory_.GetFetcherByID(
SearchProvider::kDefaultProviderURLFetcherID) == NULL);
@@ -360,16 +383,9 @@
PrefService* service = profile_.GetPrefs();
service->SetBoolean(prefs::kInstantEnabled, true);
- QueryForInput(ASCIIToUTF16("foo"), false, false);
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("foo"),
+ NULL));
- // Wait until history and the suggest query complete.
- profile_.BlockUntilHistoryProcessesPendingRequests();
- ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
-
- // When instant is enabled the provider isn't done until it hears from
- // instant.
- EXPECT_FALSE(provider_->done());
-
// Tell the provider instant is done.
provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
@@ -381,22 +397,21 @@
EXPECT_EQ(2u, provider_->matches().size());
GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms(
*default_t_url_, ASCIIToUTF16("foobar"), 0, string16()));
- AutocompleteMatch instant_match = FindMatchWithDestination(instant_url);
- EXPECT_TRUE(!instant_match.destination_url.is_empty());
+ AutocompleteMatch instant_match;
+ EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match));
// And the 'foobar' match should not have a description, it'll be set later.
EXPECT_TRUE(instant_match.description.empty());
// Make sure the what you typed match has no description.
- GURL what_you_typed_url = GURL(default_t_url_->url()->ReplaceSearchTerms(
- *default_t_url_, ASCIIToUTF16("foo"), 0, string16()));
- AutocompleteMatch what_you_typed_match =
- FindMatchWithDestination(what_you_typed_url);
- EXPECT_TRUE(!what_you_typed_match.destination_url.is_empty());
- EXPECT_TRUE(what_you_typed_match.description.empty());
+ AutocompleteMatch wyt_match;
+ EXPECT_TRUE(FindMatchWithDestination(GURL(
+ default_t_url_->url()->ReplaceSearchTerms(*default_t_url_,
+ ASCIIToUTF16("foo"), 0, string16())), &wyt_match));
+ EXPECT_TRUE(wyt_match.description.empty());
// The instant search should be more relevant.
- EXPECT_GT(instant_match.relevance, what_you_typed_match.relevance);
+ EXPECT_GT(instant_match.relevance, wyt_match.relevance);
}
// Make sure that if FinalizeInstantQuery is invoked before suggest results
@@ -405,7 +420,7 @@
PrefService* service = profile_.GetPrefs();
service->SetBoolean(prefs::kInstantEnabled, true);
- QueryForInput(ASCIIToUTF16("foo"), false, false);
+ QueryForInput(ASCIIToUTF16("foo"), false);
// Finalize the instant query immediately.
provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
@@ -413,10 +428,10 @@
// 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_, ASCIIToUTF16("foobar"), 0, string16()));
- AutocompleteMatch instant_match = FindMatchWithDestination(instant_url);
- EXPECT_FALSE(instant_match.destination_url.is_empty());
+ GURL instant_url(default_t_url_->url()->ReplaceSearchTerms(*default_t_url_,
+ ASCIIToUTF16("foobar"), 0, string16()));
+ AutocompleteMatch instant_match;
+ EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match));
// Wait until history and the suggest query complete.
profile_.BlockUntilHistoryProcessesPendingRequests();
@@ -428,8 +443,7 @@
// 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());
+ EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match));
// And the 'foobar' match should not have a description, it'll be set later.
EXPECT_TRUE(instant_match.description.empty());
@@ -441,118 +455,169 @@
PrefService* service = profile_.GetPrefs();
service->SetBoolean(prefs::kInstantEnabled, true);
- QueryForInput(ASCIIToUTF16("foo"), false, false);
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("foo"),
+ NULL));
- // Wait until history and the suggest query complete.
- profile_.BlockUntilHistoryProcessesPendingRequests();
- ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
-
// Finalize the instant query immediately.
provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
// Query with the same input text, but trailing whitespace.
- QueryForInput(ASCIIToUTF16("foo "), false, false);
+ AutocompleteMatch instant_match;
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("foo "),
+ &instant_match));
// There should only one match, for what you typed.
EXPECT_EQ(1u, provider_->matches().size());
- GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms(
- *default_t_url_, ASCIIToUTF16("foo "), 0, string16()));
- AutocompleteMatch instant_match = FindMatchWithDestination(instant_url);
EXPECT_FALSE(instant_match.destination_url.is_empty());
}
TEST_F(SearchProviderTest, DontAutocompleteURLLikeTerms) {
profile_.CreateAutocompleteClassifier();
- string16 term(ASCIIToUTF16("docs.google.com"));
- HistoryService* history =
- profile_.GetHistoryService(Profile::EXPLICIT_ACCESS);
- GURL url = GURL(default_t_url_->url()->ReplaceSearchTerms(
- *default_t_url_, term, 0, string16()));
- history->AddPageWithDetails(
- url, string16(), 1, 1, base::Time::Now(), false, history::SOURCE_BROWSED);
- history->SetKeywordSearchTermsForURL(url, default_t_url_->id(), term);
+ GURL url = AddSearchToHistory(default_t_url_,
+ ASCIIToUTF16("docs.google.com"), 1);
// Add the term as a url.
- history->AddPageWithDetails(
+ profile_.GetHistoryService(Profile::EXPLICIT_ACCESS)->AddPageWithDetails(
GURL("http://docs.google.com"), string16(), 1, 1, base::Time::Now(),
false, history::SOURCE_BROWSED);
-
profile_.BlockUntilHistoryProcessesPendingRequests();
- QueryForInput(ASCIIToUTF16("docs"), false, false);
+ AutocompleteMatch wyt_match;
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("docs"),
+ &wyt_match));
- // 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
// 'docs.google.com'. The search term should have a lower priority than the
// what you typed match.
ASSERT_EQ(2u, provider_->matches().size());
- AutocompleteMatch term_match = FindMatchWithDestination(url);
- GURL what_you_typed_url = GURL(default_t_url_->url()->ReplaceSearchTerms(
- *default_t_url_, ASCIIToUTF16("docs"), 0, string16()));
- AutocompleteMatch what_you_typed_match =
- FindMatchWithDestination(what_you_typed_url);
- EXPECT_GT(what_you_typed_match.relevance, term_match.relevance);
+ AutocompleteMatch term_match;
+ EXPECT_TRUE(FindMatchWithDestination(url, &term_match));
+ EXPECT_GT(wyt_match.relevance, term_match.relevance);
}
-// Verifies autocomplete of previously typed words works on word boundaries.
-TEST_F(SearchProviderTest, AutocompletePreviousSearchOnSpace) {
- // Add an entry that corresponds to a search with two words.
- string16 term(ASCIIToUTF16("two words"));
- HistoryService* history =
- profile_.GetHistoryService(Profile::EXPLICIT_ACCESS);
- GURL term_url(default_t_url_->url()->ReplaceSearchTerms(
- *default_t_url_, term, 0, string16()));
- history->AddPageWithDetails(term_url, string16(), 1, 1,
- base::Time::Now(), false,
- history::SOURCE_BROWSED);
- history->SetKeywordSearchTermsForURL(term_url, default_t_url_->id(), term);
+// A multiword search with one visit should not autocomplete until multiple
+// words are typed.
+TEST_F(SearchProviderTest, DontAutocompleteUntilMultipleWordsTyped) {
+ GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("one search"),
+ 1));
+ profile_.BlockUntilHistoryProcessesPendingRequests();
+ AutocompleteMatch wyt_match;
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("on"),
+ &wyt_match));
+ ASSERT_EQ(2u, provider_->matches().size());
+ AutocompleteMatch term_match;
+ EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
+ EXPECT_GT(wyt_match.relevance, term_match.relevance);
+
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("one se"),
+ &wyt_match));
+ ASSERT_EQ(2u, provider_->matches().size());
+ EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
+ EXPECT_GT(term_match.relevance, wyt_match.relevance);
+}
+
+// A multiword search with more than one visit should autocomplete immediately.
+TEST_F(SearchProviderTest, AutocompleteMultipleVisitsImmediately) {
+ GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("two searches"),
+ 2));
profile_.BlockUntilHistoryProcessesPendingRequests();
- QueryForInput(ASCIIToUTF16("two "), false, false);
+ AutocompleteMatch wyt_match;
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("tw"),
+ &wyt_match));
+ ASSERT_EQ(2u, provider_->matches().size());
+ AutocompleteMatch term_match;
+ EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
+ EXPECT_GT(term_match.relevance, wyt_match.relevance);
+}
- // Wait until history and the suggest query complete.
+// Autocompletion should work at a word boundary after a space.
+TEST_F(SearchProviderTest, AutocompleteAfterSpace) {
+ GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("two searches"),
+ 2));
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
- // 'two words'.
+ AutocompleteMatch wyt_match;
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("two "),
+ &wyt_match));
ASSERT_EQ(2u, provider_->matches().size());
- AutocompleteMatch term_match = FindMatchWithDestination(term_url);
- EXPECT_FALSE(term_match.destination_url.is_empty());
- GURL what_you_typed_url = GURL(default_t_url_->url()->ReplaceSearchTerms(
- *default_t_url_, ASCIIToUTF16("two "), 0, string16()));
- AutocompleteMatch what_you_typed_match =
- FindMatchWithDestination(what_you_typed_url);
- EXPECT_FALSE(what_you_typed_match.destination_url.is_empty());
- // term_match should be autocompleted.
- EXPECT_GT(term_match.relevance, what_you_typed_match.relevance);
- // And the offset should be at 4.
- EXPECT_EQ(4u, term_match.inline_autocomplete_offset);
+ AutocompleteMatch term_match;
+ EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
+ EXPECT_GT(term_match.relevance, wyt_match.relevance);
}
+// Newer multiword searches should score more highly than older ones.
+TEST_F(SearchProviderTest, ScoreNewerSearchesHigher) {
+ GURL term_url_a(AddSearchToHistory(default_t_url_,
+ ASCIIToUTF16("three searches aaa"), 1));
+ GURL term_url_b(AddSearchToHistory(default_t_url_,
+ ASCIIToUTF16("three searches bbb"), 1));
+ profile_.BlockUntilHistoryProcessesPendingRequests();
+
+ AutocompleteMatch wyt_match;
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("three se"),
+ &wyt_match));
+ ASSERT_EQ(3u, provider_->matches().size());
+ AutocompleteMatch term_match_a;
+ EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
+ AutocompleteMatch term_match_b;
+ EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
+ EXPECT_GT(term_match_b.relevance, term_match_a.relevance);
+ EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
+}
+
+// An autocompleted multiword search should not be replaced by a different
+// autocompletion while the user is still typing a valid prefix.
+TEST_F(SearchProviderTest, DontReplacePreviousAutocompletion) {
+ GURL term_url_a(AddSearchToHistory(default_t_url_,
+ ASCIIToUTF16("four searches aaa"), 2));
+ GURL term_url_b(AddSearchToHistory(default_t_url_,
+ ASCIIToUTF16("four searches bbb"), 1));
+ profile_.BlockUntilHistoryProcessesPendingRequests();
+
+ AutocompleteMatch wyt_match;
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("fo"),
+ &wyt_match));
+ ASSERT_EQ(3u, provider_->matches().size());
+ AutocompleteMatch term_match_a;
+ EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
+ AutocompleteMatch term_match_b;
+ EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
+ EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
+ EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
+
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("four se"),
+ &wyt_match));
+ ASSERT_EQ(3u, provider_->matches().size());
+ EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
+ EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
+ EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
+ EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
+}
+
+// Non-completable multiword searches should not crowd out single-word searches.
+TEST_F(SearchProviderTest, DontCrowdOutSingleWords) {
+ GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("five"), 1));
+ AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches bbb"), 1);
+ AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches ccc"), 1);
+ AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches ddd"), 1);
+ AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches eee"), 1);
+ profile_.BlockUntilHistoryProcessesPendingRequests();
+
+ AutocompleteMatch wyt_match;
+ ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("fi"),
+ &wyt_match));
+ ASSERT_EQ(AutocompleteProvider::kMaxMatches + 1, provider_->matches().size());
+ AutocompleteMatch term_match;
+ EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
+ EXPECT_GT(term_match.relevance, wyt_match.relevance);
+}
+
// Verifies AutocompleteControllers sets descriptions for results correctly.
TEST_F(SearchProviderTest, UpdateKeywordDescriptions) {
// Add an entry that corresponds to a keyword search with 'term2'.
- string16 term(ASCIIToUTF16("term2"));
- HistoryService* history =
- profile_.GetHistoryService(Profile::EXPLICIT_ACCESS);
- GURL term_url(keyword_t_url_->url()->ReplaceSearchTerms(
- *keyword_t_url_, term, 0, string16()));
- history->AddPageWithDetails(term_url, string16(), 1, 1,
- base::Time::Now(), false,
- history::SOURCE_BROWSED);
- history->SetKeywordSearchTermsForURL(term_url, keyword_t_url_->id(), term);
-
+ AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1);
profile_.BlockUntilHistoryProcessesPendingRequests();
ACProviders providers;

Powered by Google App Engine
This is Rietveld 408576698