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

Side by Side Diff: chrome/browser/autocomplete/search_provider_unittest.cc

Issue 105193002: Replace string16 with base::string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 class SearchProviderTest : public testing::Test, 102 class SearchProviderTest : public testing::Test,
103 public AutocompleteProviderListener { 103 public AutocompleteProviderListener {
104 public: 104 public:
105 struct ResultInfo { 105 struct ResultInfo {
106 ResultInfo() : result_type(AutocompleteMatchType::NUM_TYPES), 106 ResultInfo() : result_type(AutocompleteMatchType::NUM_TYPES),
107 allowed_to_be_default_match(false) { 107 allowed_to_be_default_match(false) {
108 } 108 }
109 ResultInfo(GURL gurl, 109 ResultInfo(GURL gurl,
110 AutocompleteMatch::Type result_type, 110 AutocompleteMatch::Type result_type,
111 bool allowed_to_be_default_match, 111 bool allowed_to_be_default_match,
112 string16 fill_into_edit) 112 base::string16 fill_into_edit)
113 : gurl(gurl), 113 : gurl(gurl),
114 result_type(result_type), 114 result_type(result_type),
115 allowed_to_be_default_match(allowed_to_be_default_match), 115 allowed_to_be_default_match(allowed_to_be_default_match),
116 fill_into_edit(fill_into_edit) { 116 fill_into_edit(fill_into_edit) {
117 } 117 }
118 118
119 const GURL gurl; 119 const GURL gurl;
120 const AutocompleteMatch::Type result_type; 120 const AutocompleteMatch::Type result_type;
121 const bool allowed_to_be_default_match; 121 const bool allowed_to_be_default_match;
122 const string16 fill_into_edit; 122 const base::string16 fill_into_edit;
123 }; 123 };
124 124
125 struct TestData { 125 struct TestData {
126 const string16 input; 126 const base::string16 input;
127 const size_t num_results; 127 const size_t num_results;
128 const ResultInfo output[3]; 128 const ResultInfo output[3];
129 }; 129 };
130 130
131 SearchProviderTest() 131 SearchProviderTest()
132 : default_t_url_(NULL), 132 : default_t_url_(NULL),
133 term1_(ASCIIToUTF16("term1")), 133 term1_(ASCIIToUTF16("term1")),
134 keyword_t_url_(NULL), 134 keyword_t_url_(NULL),
135 keyword_term_(ASCIIToUTF16("keyword")), 135 keyword_term_(ASCIIToUTF16("keyword")),
136 run_loop_(NULL) { 136 run_loop_(NULL) {
137 ResetFieldTrialList(); 137 ResetFieldTrialList();
138 } 138 }
139 139
140 // See description above class for what this registers. 140 // See description above class for what this registers.
141 virtual void SetUp() OVERRIDE; 141 virtual void SetUp() OVERRIDE;
142 virtual void TearDown() OVERRIDE; 142 virtual void TearDown() OVERRIDE;
143 143
144 void RunTest(TestData* cases, int num_cases, bool prefer_keyword); 144 void RunTest(TestData* cases, int num_cases, bool prefer_keyword);
145 145
146 protected: 146 protected:
147 // Needed for AutocompleteFieldTrial::ActivateStaticTrials(); 147 // Needed for AutocompleteFieldTrial::ActivateStaticTrials();
148 scoped_ptr<base::FieldTrialList> field_trial_list_; 148 scoped_ptr<base::FieldTrialList> field_trial_list_;
149 149
150 // Default value used for testing. 150 // Default value used for testing.
151 static const std::string kNotApplicable; 151 static const std::string kNotApplicable;
152 152
153 // Adds a search for |term|, using the engine |t_url| to the history, and 153 // Adds a search for |term|, using the engine |t_url| to the history, and
154 // returns the URL for that search. 154 // returns the URL for that search.
155 GURL AddSearchToHistory(TemplateURL* t_url, string16 term, int visit_count); 155 GURL AddSearchToHistory(TemplateURL* t_url, base::string16 term, int visit_cou nt);
156 156
157 // Looks for a match in |provider_| with |contents| equal to |contents|. 157 // Looks for a match in |provider_| with |contents| equal to |contents|.
158 // Sets |match| to it if found. Returns whether |match| was set. 158 // Sets |match| to it if found. Returns whether |match| was set.
159 bool FindMatchWithContents(const string16& contents, 159 bool FindMatchWithContents(const base::string16& contents,
160 AutocompleteMatch* match); 160 AutocompleteMatch* match);
161 161
162 // Looks for a match in |provider_| with destination |url|. Sets |match| to 162 // Looks for a match in |provider_| with destination |url|. Sets |match| to
163 // it if found. Returns whether |match| was set. 163 // it if found. Returns whether |match| was set.
164 bool FindMatchWithDestination(const GURL& url, AutocompleteMatch* match); 164 bool FindMatchWithDestination(const GURL& url, AutocompleteMatch* match);
165 165
166 // AutocompleteProviderListener: 166 // AutocompleteProviderListener:
167 // If we're waiting for the provider to finish, this exits the message loop. 167 // If we're waiting for the provider to finish, this exits the message loop.
168 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE; 168 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE;
169 169
170 // Runs a nested message loop until provider_ is done. The message loop is 170 // Runs a nested message loop until provider_ is done. The message loop is
171 // exited by way of OnProviderUpdate. 171 // exited by way of OnProviderUpdate.
172 void RunTillProviderDone(); 172 void RunTillProviderDone();
173 173
174 // Invokes Start on provider_, then runs all pending tasks. 174 // Invokes Start on provider_, then runs all pending tasks.
175 void QueryForInput(const string16& text, 175 void QueryForInput(const base::string16& text,
176 bool prevent_inline_autocomplete, 176 bool prevent_inline_autocomplete,
177 bool prefer_keyword); 177 bool prefer_keyword);
178 178
179 // Calls QueryForInput(), finishes any suggest query, then if |wyt_match| is 179 // Calls QueryForInput(), finishes any suggest query, then if |wyt_match| is
180 // non-NULL, sets it to the "what you typed" entry for |text|. 180 // non-NULL, sets it to the "what you typed" entry for |text|.
181 void QueryForInputAndSetWYTMatch(const string16& text, 181 void QueryForInputAndSetWYTMatch(const base::string16& text,
182 AutocompleteMatch* wyt_match); 182 AutocompleteMatch* wyt_match);
183 183
184 // Notifies the URLFetcher for the suggest query corresponding to the default 184 // Notifies the URLFetcher for the suggest query corresponding to the default
185 // search provider that it's done. 185 // search provider that it's done.
186 // Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE. 186 // Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE.
187 void FinishDefaultSuggestQuery(); 187 void FinishDefaultSuggestQuery();
188 188
189 // Runs SearchProvider on |input|, for which the suggest server replies 189 // Runs SearchProvider on |input|, for which the suggest server replies
190 // with |json|, and expects that the resulting matches' contents equals 190 // with |json|, and expects that the resulting matches' contents equals
191 // that in |matches|. An empty entry in |matches| means no match should 191 // that in |matches|. An empty entry in |matches| means no match should
192 // be returned in that position. Reports any errors with a message that 192 // be returned in that position. Reports any errors with a message that
193 // includes |error_description|. 193 // includes |error_description|.
194 void ForcedQueryTestHelper(const std::string& input, 194 void ForcedQueryTestHelper(const std::string& input,
195 const std::string& json, 195 const std::string& json,
196 const std::string matches[3], 196 const std::string matches[3],
197 const std::string& error_description); 197 const std::string& error_description);
198 198
199 void ResetFieldTrialList(); 199 void ResetFieldTrialList();
200 200
201 void ClearAllResults(); 201 void ClearAllResults();
202 202
203 // See description above class for details of these fields. 203 // See description above class for details of these fields.
204 TemplateURL* default_t_url_; 204 TemplateURL* default_t_url_;
205 const string16 term1_; 205 const base::string16 term1_;
206 GURL term1_url_; 206 GURL term1_url_;
207 TemplateURL* keyword_t_url_; 207 TemplateURL* keyword_t_url_;
208 const string16 keyword_term_; 208 const base::string16 keyword_term_;
209 GURL keyword_url_; 209 GURL keyword_url_;
210 210
211 content::TestBrowserThreadBundle thread_bundle_; 211 content::TestBrowserThreadBundle thread_bundle_;
212 212
213 // URLFetcherFactory implementation registered. 213 // URLFetcherFactory implementation registered.
214 net::TestURLFetcherFactory test_factory_; 214 net::TestURLFetcherFactory test_factory_;
215 215
216 // Profile we use. 216 // Profile we use.
217 TestingProfile profile_; 217 TestingProfile profile_;
218 218
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 // Shutdown the provider before the profile. 285 // Shutdown the provider before the profile.
286 provider_ = NULL; 286 provider_ = NULL;
287 } 287 }
288 288
289 void SearchProviderTest::RunTest(TestData* cases, 289 void SearchProviderTest::RunTest(TestData* cases,
290 int num_cases, 290 int num_cases,
291 bool prefer_keyword) { 291 bool prefer_keyword) {
292 ACMatches matches; 292 ACMatches matches;
293 for (int i = 0; i < num_cases; ++i) { 293 for (int i = 0; i < num_cases; ++i) {
294 AutocompleteInput input(cases[i].input, string16::npos, string16(), GURL(), 294 AutocompleteInput input(cases[i].input, base::string16::npos, base::string16 (), GURL(),
295 AutocompleteInput::INVALID_SPEC, false, 295 AutocompleteInput::INVALID_SPEC, false,
296 prefer_keyword, true, 296 prefer_keyword, true,
297 AutocompleteInput::ALL_MATCHES); 297 AutocompleteInput::ALL_MATCHES);
298 provider_->Start(input, false); 298 provider_->Start(input, false);
299 matches = provider_->matches(); 299 matches = provider_->matches();
300 string16 diagnostic_details = ASCIIToUTF16("Input was: ") + cases[i].input + 300 base::string16 diagnostic_details = ASCIIToUTF16("Input was: ") + cases[i].i nput +
301 ASCIIToUTF16("; prefer_keyword was: ") + 301 ASCIIToUTF16("; prefer_keyword was: ") +
302 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false")); 302 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false"));
303 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details; 303 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details;
304 if (matches.size() == cases[i].num_results) { 304 if (matches.size() == cases[i].num_results) {
305 for (size_t j = 0; j < cases[i].num_results; ++j) { 305 for (size_t j = 0; j < cases[i].num_results; ++j) {
306 EXPECT_EQ(cases[i].output[j].gurl, matches[j].destination_url) << 306 EXPECT_EQ(cases[i].output[j].gurl, matches[j].destination_url) <<
307 diagnostic_details; 307 diagnostic_details;
308 EXPECT_EQ(cases[i].output[j].result_type, matches[j].type) << 308 EXPECT_EQ(cases[i].output[j].result_type, matches[j].type) <<
309 diagnostic_details; 309 diagnostic_details;
310 EXPECT_EQ(cases[i].output[j].fill_into_edit, 310 EXPECT_EQ(cases[i].output[j].fill_into_edit,
(...skipping 14 matching lines...) Expand all
325 325
326 void SearchProviderTest::RunTillProviderDone() { 326 void SearchProviderTest::RunTillProviderDone() {
327 if (provider_->done()) 327 if (provider_->done())
328 return; 328 return;
329 329
330 base::RunLoop run_loop; 330 base::RunLoop run_loop;
331 run_loop_ = &run_loop; 331 run_loop_ = &run_loop;
332 run_loop.Run(); 332 run_loop.Run();
333 } 333 }
334 334
335 void SearchProviderTest::QueryForInput(const string16& text, 335 void SearchProviderTest::QueryForInput(const base::string16& text,
336 bool prevent_inline_autocomplete, 336 bool prevent_inline_autocomplete,
337 bool prefer_keyword) { 337 bool prefer_keyword) {
338 // Start a query. 338 // Start a query.
339 AutocompleteInput input(text, string16::npos, string16(), GURL(), 339 AutocompleteInput input(text, base::string16::npos, base::string16(), GURL(),
340 AutocompleteInput::INVALID_SPEC, 340 AutocompleteInput::INVALID_SPEC,
341 prevent_inline_autocomplete, prefer_keyword, true, 341 prevent_inline_autocomplete, prefer_keyword, true,
342 AutocompleteInput::ALL_MATCHES); 342 AutocompleteInput::ALL_MATCHES);
343 provider_->Start(input, false); 343 provider_->Start(input, false);
344 344
345 // RunUntilIdle so that the task scheduled by SearchProvider to create the 345 // RunUntilIdle so that the task scheduled by SearchProvider to create the
346 // URLFetchers runs. 346 // URLFetchers runs.
347 base::RunLoop().RunUntilIdle(); 347 base::RunLoop().RunUntilIdle();
348 } 348 }
349 349
350 void SearchProviderTest::QueryForInputAndSetWYTMatch( 350 void SearchProviderTest::QueryForInputAndSetWYTMatch(
351 const string16& text, 351 const base::string16& text,
352 AutocompleteMatch* wyt_match) { 352 AutocompleteMatch* wyt_match) {
353 QueryForInput(text, false, false); 353 QueryForInput(text, false, false);
354 profile_.BlockUntilHistoryProcessesPendingRequests(); 354 profile_.BlockUntilHistoryProcessesPendingRequests();
355 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); 355 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
356 if (!wyt_match) 356 if (!wyt_match)
357 return; 357 return;
358 ASSERT_GE(provider_->matches().size(), 1u); 358 ASSERT_GE(provider_->matches().size(), 1u);
359 EXPECT_TRUE(FindMatchWithDestination(GURL( 359 EXPECT_TRUE(FindMatchWithDestination(GURL(
360 default_t_url_->url_ref().ReplaceSearchTerms( 360 default_t_url_->url_ref().ReplaceSearchTerms(
361 TemplateURLRef::SearchTermsArgs(text))), 361 TemplateURLRef::SearchTermsArgs(text))),
362 wyt_match)); 362 wyt_match));
363 } 363 }
364 364
365 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url, 365 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url,
366 string16 term, 366 base::string16 term,
367 int visit_count) { 367 int visit_count) {
368 HistoryService* history = 368 HistoryService* history =
369 HistoryServiceFactory::GetForProfile(&profile_, 369 HistoryServiceFactory::GetForProfile(&profile_,
370 Profile::EXPLICIT_ACCESS); 370 Profile::EXPLICIT_ACCESS);
371 GURL search(t_url->url_ref().ReplaceSearchTerms( 371 GURL search(t_url->url_ref().ReplaceSearchTerms(
372 TemplateURLRef::SearchTermsArgs(term))); 372 TemplateURLRef::SearchTermsArgs(term)));
373 static base::Time last_added_time; 373 static base::Time last_added_time;
374 last_added_time = std::max(base::Time::Now(), 374 last_added_time = std::max(base::Time::Now(),
375 last_added_time + base::TimeDelta::FromMicroseconds(1)); 375 last_added_time + base::TimeDelta::FromMicroseconds(1));
376 history->AddPageWithDetails(search, string16(), visit_count, visit_count, 376 history->AddPageWithDetails(search, base::string16(), visit_count, visit_count ,
377 last_added_time, false, history::SOURCE_BROWSED); 377 last_added_time, false, history::SOURCE_BROWSED);
378 history->SetKeywordSearchTermsForURL(search, t_url->id(), term); 378 history->SetKeywordSearchTermsForURL(search, t_url->id(), term);
379 return search; 379 return search;
380 } 380 }
381 381
382 bool SearchProviderTest::FindMatchWithContents(const string16& contents, 382 bool SearchProviderTest::FindMatchWithContents(const base::string16& contents,
383 AutocompleteMatch* match) { 383 AutocompleteMatch* match) {
384 for (ACMatches::const_iterator i = provider_->matches().begin(); 384 for (ACMatches::const_iterator i = provider_->matches().begin();
385 i != provider_->matches().end(); ++i) { 385 i != provider_->matches().end(); ++i) {
386 if (i->contents == contents) { 386 if (i->contents == contents) {
387 *match = *i; 387 *match = *i;
388 return true; 388 return true;
389 } 389 }
390 } 390 }
391 return false; 391 return false;
392 } 392 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 457
458 void SearchProviderTest::ClearAllResults() { 458 void SearchProviderTest::ClearAllResults() {
459 provider_->ClearAllResults(); 459 provider_->ClearAllResults();
460 } 460 }
461 461
462 // Actual Tests --------------------------------------------------------------- 462 // Actual Tests ---------------------------------------------------------------
463 463
464 // Make sure we query history for the default provider and a URLFetcher is 464 // Make sure we query history for the default provider and a URLFetcher is
465 // created for the default provider suggest results. 465 // created for the default provider suggest results.
466 TEST_F(SearchProviderTest, QueryDefaultProvider) { 466 TEST_F(SearchProviderTest, QueryDefaultProvider) {
467 string16 term = term1_.substr(0, term1_.length() - 1); 467 base::string16 term = term1_.substr(0, term1_.length() - 1);
468 QueryForInput(term, false, false); 468 QueryForInput(term, false, false);
469 469
470 // Make sure the default providers suggest service was queried. 470 // Make sure the default providers suggest service was queried.
471 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 471 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
472 SearchProvider::kDefaultProviderURLFetcherID); 472 SearchProvider::kDefaultProviderURLFetcherID);
473 ASSERT_TRUE(fetcher); 473 ASSERT_TRUE(fetcher);
474 474
475 // And the URL matches what we expected. 475 // And the URL matches what we expected.
476 GURL expected_url(default_t_url_->suggestions_url_ref().ReplaceSearchTerms( 476 GURL expected_url(default_t_url_->suggestions_url_ref().ReplaceSearchTerms(
477 TemplateURLRef::SearchTermsArgs(term))); 477 TemplateURLRef::SearchTermsArgs(term)));
(...skipping 22 matching lines...) Expand all
500 500
501 // The match for term1 should be more relevant than the what you typed match. 501 // The match for term1 should be more relevant than the what you typed match.
502 EXPECT_GT(term1_match.relevance, wyt_match.relevance); 502 EXPECT_GT(term1_match.relevance, wyt_match.relevance);
503 // This longer match should be inlineable. 503 // This longer match should be inlineable.
504 EXPECT_TRUE(term1_match.allowed_to_be_default_match); 504 EXPECT_TRUE(term1_match.allowed_to_be_default_match);
505 // The what you typed match should be too, of course. 505 // The what you typed match should be too, of course.
506 EXPECT_TRUE(wyt_match.allowed_to_be_default_match); 506 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
507 } 507 }
508 508
509 TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) { 509 TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) {
510 string16 term = term1_.substr(0, term1_.length() - 1); 510 base::string16 term = term1_.substr(0, term1_.length() - 1);
511 QueryForInput(term, true, false); 511 QueryForInput(term, true, false);
512 512
513 ASSERT_FALSE(provider_->matches().empty()); 513 ASSERT_FALSE(provider_->matches().empty());
514 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 514 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
515 provider_->matches()[0].type); 515 provider_->matches()[0].type);
516 EXPECT_TRUE(provider_->matches()[0].allowed_to_be_default_match); 516 EXPECT_TRUE(provider_->matches()[0].allowed_to_be_default_match);
517 } 517 }
518 518
519 // Issues a query that matches the registered keyword and makes sure history 519 // Issues a query that matches the registered keyword and makes sure history
520 // is queried as well as URLFetchers getting created. 520 // is queried as well as URLFetchers getting created.
521 TEST_F(SearchProviderTest, QueryKeywordProvider) { 521 TEST_F(SearchProviderTest, QueryKeywordProvider) {
522 string16 term = keyword_term_.substr(0, keyword_term_.length() - 1); 522 base::string16 term = keyword_term_.substr(0, keyword_term_.length() - 1);
523 QueryForInput(keyword_t_url_->keyword() + ASCIIToUTF16(" ") + term, 523 QueryForInput(keyword_t_url_->keyword() + ASCIIToUTF16(" ") + term,
524 false, 524 false,
525 false); 525 false);
526 526
527 // Make sure the default providers suggest service was queried. 527 // Make sure the default providers suggest service was queried.
528 net::TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID( 528 net::TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID(
529 SearchProvider::kDefaultProviderURLFetcherID); 529 SearchProvider::kDefaultProviderURLFetcherID);
530 ASSERT_TRUE(default_fetcher); 530 ASSERT_TRUE(default_fetcher);
531 531
532 // Tell the SearchProvider the default suggest query is done. 532 // Tell the SearchProvider the default suggest query is done.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 } 618 }
619 619
620 TEST_F(SearchProviderTest, DontAutocompleteURLLikeTerms) { 620 TEST_F(SearchProviderTest, DontAutocompleteURLLikeTerms) {
621 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( 621 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
622 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor); 622 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor);
623 GURL url = AddSearchToHistory(default_t_url_, 623 GURL url = AddSearchToHistory(default_t_url_,
624 ASCIIToUTF16("docs.google.com"), 1); 624 ASCIIToUTF16("docs.google.com"), 1);
625 625
626 // Add the term as a url. 626 // Add the term as a url.
627 HistoryServiceFactory::GetForProfile(&profile_, Profile::EXPLICIT_ACCESS)-> 627 HistoryServiceFactory::GetForProfile(&profile_, Profile::EXPLICIT_ACCESS)->
628 AddPageWithDetails(GURL("http://docs.google.com"), string16(), 1, 1, 628 AddPageWithDetails(GURL("http://docs.google.com"), base::string16(), 1, 1,
629 base::Time::Now(), false, history::SOURCE_BROWSED); 629 base::Time::Now(), false, history::SOURCE_BROWSED);
630 profile_.BlockUntilHistoryProcessesPendingRequests(); 630 profile_.BlockUntilHistoryProcessesPendingRequests();
631 631
632 AutocompleteMatch wyt_match; 632 AutocompleteMatch wyt_match;
633 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("docs"), 633 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("docs"),
634 &wyt_match)); 634 &wyt_match));
635 635
636 // There should be two matches, one for what you typed, the other for 636 // There should be two matches, one for what you typed, the other for
637 // 'docs.google.com'. The search term should have a lower priority than the 637 // 'docs.google.com'. The search term should have a lower priority than the
638 // what you typed match. 638 // what you typed match.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 // Verifies AutocompleteControllers return results (including keyword 850 // Verifies AutocompleteControllers return results (including keyword
851 // results) in the right order and set descriptions for them correctly. 851 // results) in the right order and set descriptions for them correctly.
852 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { 852 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) {
853 // Add an entry that corresponds to a keyword search with 'term2'. 853 // Add an entry that corresponds to a keyword search with 'term2'.
854 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); 854 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1);
855 profile_.BlockUntilHistoryProcessesPendingRequests(); 855 profile_.BlockUntilHistoryProcessesPendingRequests();
856 856
857 AutocompleteController controller(&profile_, NULL, 857 AutocompleteController controller(&profile_, NULL,
858 AutocompleteProvider::TYPE_SEARCH); 858 AutocompleteProvider::TYPE_SEARCH);
859 controller.Start(AutocompleteInput( 859 controller.Start(AutocompleteInput(
860 ASCIIToUTF16("k t"), string16::npos, string16(), GURL(), 860 ASCIIToUTF16("k t"), base::string16::npos, base::string16(), GURL(),
861 AutocompleteInput::INVALID_SPEC, false, false, true, 861 AutocompleteInput::INVALID_SPEC, false, false, true,
862 AutocompleteInput::ALL_MATCHES)); 862 AutocompleteInput::ALL_MATCHES));
863 const AutocompleteResult& result = controller.result(); 863 const AutocompleteResult& result = controller.result();
864 864
865 // There should be three matches, one for the keyword history, one for 865 // There should be three matches, one for the keyword history, one for
866 // keyword provider's what-you-typed, and one for the default provider's 866 // keyword provider's what-you-typed, and one for the default provider's
867 // what you typed, in that order. 867 // what you typed, in that order.
868 ASSERT_EQ(3u, result.size()); 868 ASSERT_EQ(3u, result.size());
869 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type); 869 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type);
870 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE, 870 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE,
(...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) 2635 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
2636 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << 2636 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) <<
2637 "Case # " << i << " " << description; 2637 "Case # " << i << " " << description;
2638 } 2638 }
2639 } 2639 }
2640 2640
2641 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) { 2641 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) {
2642 // We hardcode the string "term1" below, so ensure that the search term that 2642 // We hardcode the string "term1" below, so ensure that the search term that
2643 // got added to history already is that string. 2643 // got added to history already is that string.
2644 ASSERT_EQ(ASCIIToUTF16("term1"), term1_); 2644 ASSERT_EQ(ASCIIToUTF16("term1"), term1_);
2645 string16 term = term1_.substr(0, term1_.length() - 1); 2645 base::string16 term = term1_.substr(0, term1_.length() - 1);
2646 2646
2647 AddSearchToHistory(default_t_url_, term + ASCIIToUTF16("2"), 2); 2647 AddSearchToHistory(default_t_url_, term + ASCIIToUTF16("2"), 2);
2648 profile_.BlockUntilHistoryProcessesPendingRequests(); 2648 profile_.BlockUntilHistoryProcessesPendingRequests();
2649 2649
2650 struct { 2650 struct {
2651 const string16 input; 2651 const base::string16 input;
2652 const std::string json; 2652 const std::string json;
2653 const std::string matches[6]; 2653 const std::string matches[6];
2654 } cases[] = { 2654 } cases[] = {
2655 // The history results outscore the default verbatim score. term2 has more 2655 // The history results outscore the default verbatim score. term2 has more
2656 // visits so it outscores term1. The suggestions are still returned since 2656 // visits so it outscores term1. The suggestions are still returned since
2657 // they're server-scored. 2657 // they're server-scored.
2658 { term, 2658 { term,
2659 "[\"term\",[\"a1\", \"a2\", \"a3\"],[],[]," 2659 "[\"term\",[\"a1\", \"a2\", \"a3\"],[],[],"
2660 "{\"google:suggesttype\":[\"QUERY\", \"QUERY\", \"QUERY\"]," 2660 "{\"google:suggesttype\":[\"QUERY\", \"QUERY\", \"QUERY\"],"
2661 "\"google:suggestrelevance\":[1, 2, 3]}]", 2661 "\"google:suggestrelevance\":[1, 2, 3]}]",
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
3170 { "?ab", "http://www.abc.com", 3170 { "?ab", "http://www.abc.com",
3171 "?www.abc.com", "c.com", true }, 3171 "?www.abc.com", "c.com", true },
3172 { "?abc.com", "http://www.abc.com", 3172 { "?abc.com", "http://www.abc.com",
3173 "?www.abc.com", "", true }, 3173 "?www.abc.com", "", true },
3174 }; 3174 };
3175 3175
3176 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 3176 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
3177 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); 3177 QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
3178 AutocompleteMatch match( 3178 AutocompleteMatch match(
3179 provider_->NavigationToMatch(SearchProvider::NavigationResult( 3179 provider_->NavigationToMatch(SearchProvider::NavigationResult(
3180 *provider_.get(), GURL(cases[i].url), string16(), false, 0, 3180 *provider_.get(), GURL(cases[i].url), base::string16(), false, 0,
3181 false))); 3181 false)));
3182 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 3182 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
3183 match.inline_autocompletion); 3183 match.inline_autocompletion);
3184 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); 3184 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit);
3185 EXPECT_EQ(cases[i].allowed_to_be_default_match, 3185 EXPECT_EQ(cases[i].allowed_to_be_default_match,
3186 match.allowed_to_be_default_match); 3186 match.allowed_to_be_default_match);
3187 } 3187 }
3188 } 3188 }
3189 3189
3190 // Verifies that "http://" is not trimmed for input that is a leading substring. 3190 // Verifies that "http://" is not trimmed for input that is a leading substring.
3191 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { 3191 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) {
3192 const string16 input(ASCIIToUTF16("ht")); 3192 const base::string16 input(ASCIIToUTF16("ht"));
3193 const string16 url(ASCIIToUTF16("http://a.com")); 3193 const base::string16 url(ASCIIToUTF16("http://a.com"));
3194 const SearchProvider::NavigationResult result( 3194 const SearchProvider::NavigationResult result(
3195 *provider_.get(), GURL(url), string16(), false, 0, false); 3195 *provider_.get(), GURL(url), base::string16(), false, 0, false);
3196 3196
3197 // Check the offset and strings when inline autocompletion is allowed. 3197 // Check the offset and strings when inline autocompletion is allowed.
3198 QueryForInput(input, false, false); 3198 QueryForInput(input, false, false);
3199 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); 3199 AutocompleteMatch match_inline(provider_->NavigationToMatch(result));
3200 EXPECT_EQ(url, match_inline.fill_into_edit); 3200 EXPECT_EQ(url, match_inline.fill_into_edit);
3201 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); 3201 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion);
3202 EXPECT_TRUE(match_inline.allowed_to_be_default_match); 3202 EXPECT_TRUE(match_inline.allowed_to_be_default_match);
3203 EXPECT_EQ(url, match_inline.contents); 3203 EXPECT_EQ(url, match_inline.contents);
3204 3204
3205 // Check the same offset and strings when inline autocompletion is prevented. 3205 // Check the same offset and strings when inline autocompletion is prevented.
3206 QueryForInput(input, true, false); 3206 QueryForInput(input, true, false);
3207 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); 3207 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result));
3208 EXPECT_EQ(url, match_prevent.fill_into_edit); 3208 EXPECT_EQ(url, match_prevent.fill_into_edit);
3209 EXPECT_TRUE(match_prevent.inline_autocompletion.empty()); 3209 EXPECT_TRUE(match_prevent.inline_autocompletion.empty());
3210 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); 3210 EXPECT_FALSE(match_prevent.allowed_to_be_default_match);
3211 EXPECT_EQ(url, match_prevent.contents); 3211 EXPECT_EQ(url, match_prevent.contents);
3212 } 3212 }
3213 3213
3214 // Verifies that input "w" marks a more significant domain label than "www.". 3214 // Verifies that input "w" marks a more significant domain label than "www.".
3215 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { 3215 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) {
3216 QueryForInput(ASCIIToUTF16("w"), false, false); 3216 QueryForInput(ASCIIToUTF16("w"), false, false);
3217 AutocompleteMatch match( 3217 AutocompleteMatch match(
3218 provider_->NavigationToMatch(SearchProvider::NavigationResult( 3218 provider_->NavigationToMatch(SearchProvider::NavigationResult(
3219 *provider_.get(), GURL("http://www.wow.com"), string16(), false, 0, 3219 *provider_.get(), GURL("http://www.wow.com"), base::string16(), false, 0,
3220 false))); 3220 false)));
3221 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); 3221 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion);
3222 EXPECT_TRUE(match.allowed_to_be_default_match); 3222 EXPECT_TRUE(match.allowed_to_be_default_match);
3223 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); 3223 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit);
3224 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); 3224 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents);
3225 3225
3226 // Ensure that the match for input "w" is marked on "wow" and not "www". 3226 // Ensure that the match for input "w" is marked on "wow" and not "www".
3227 ASSERT_EQ(3U, match.contents_class.size()); 3227 ASSERT_EQ(3U, match.contents_class.size());
3228 EXPECT_EQ(0U, match.contents_class[0].offset); 3228 EXPECT_EQ(0U, match.contents_class[0].offset);
3229 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 3229 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3372 cases[i].verbatim_relevance; 3372 cases[i].verbatim_relevance;
3373 provider_->default_results_.navigation_results.clear(); 3373 provider_->default_results_.navigation_results.clear();
3374 provider_->default_results_.suggest_results.clear(); 3374 provider_->default_results_.suggest_results.clear();
3375 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(cases[i].results); ++j) { 3375 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(cases[i].results); ++j) {
3376 const std::string& suggestion = cases[i].results[j].suggestion; 3376 const std::string& suggestion = cases[i].results[j].suggestion;
3377 if (suggestion == kNotApplicable) 3377 if (suggestion == kNotApplicable)
3378 break; 3378 break;
3379 if (cases[i].results[j].is_navigation_result) { 3379 if (cases[i].results[j].is_navigation_result) {
3380 provider_->default_results_.navigation_results.push_back( 3380 provider_->default_results_.navigation_results.push_back(
3381 SearchProvider::NavigationResult( 3381 SearchProvider::NavigationResult(
3382 *provider_.get(), GURL(suggestion), string16(), false, 3382 *provider_.get(), GURL(suggestion), base::string16(), false,
3383 cases[i].results[j].relevance, false)); 3383 cases[i].results[j].relevance, false));
3384 } else { 3384 } else {
3385 provider_->default_results_.suggest_results.push_back( 3385 provider_->default_results_.suggest_results.push_back(
3386 SearchProvider::SuggestResult(ASCIIToUTF16(suggestion), string16(), 3386 SearchProvider::SuggestResult(ASCIIToUTF16(suggestion), base::string 16(),
3387 string16(), std::string(), 3387 base::string16(), std::string(),
3388 std::string(), false, 3388 std::string(), false,
3389 cases[i].results[j].relevance, 3389 cases[i].results[j].relevance,
3390 false, false)); 3390 false, false));
3391 } 3391 }
3392 } 3392 }
3393 3393
3394 provider_->input_ = AutocompleteInput( 3394 provider_->input_ = AutocompleteInput(
3395 ASCIIToUTF16(cases[i].omnibox_input), string16::npos, string16(), 3395 ASCIIToUTF16(cases[i].omnibox_input), base::string16::npos, base::string 16(),
3396 GURL(), AutocompleteInput::INVALID_SPEC, false, false, true, 3396 GURL(), AutocompleteInput::INVALID_SPEC, false, false, true,
3397 AutocompleteInput::ALL_MATCHES); 3397 AutocompleteInput::ALL_MATCHES);
3398 provider_->RemoveAllStaleResults(); 3398 provider_->RemoveAllStaleResults();
3399 3399
3400 // Check cached results. 3400 // Check cached results.
3401 SearchProvider::SuggestResults::const_iterator sug_it = 3401 SearchProvider::SuggestResults::const_iterator sug_it =
3402 provider_->default_results_.suggest_results.begin(); 3402 provider_->default_results_.suggest_results.begin();
3403 const SearchProvider::SuggestResults::const_iterator sug_end = 3403 const SearchProvider::SuggestResults::const_iterator sug_end =
3404 provider_->default_results_.suggest_results.end(); 3404 provider_->default_results_.suggest_results.end();
3405 SearchProvider::NavigationResults::const_iterator nav_it = 3405 SearchProvider::NavigationResults::const_iterator nav_it =
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
3965 SCOPED_TRACE(" and match index: " + base::IntToString(j)); 3965 SCOPED_TRACE(" and match index: " + base::IntToString(j));
3966 EXPECT_EQ(match.contents, UTF16ToUTF8(matches[j].contents)); 3966 EXPECT_EQ(match.contents, UTF16ToUTF8(matches[j].contents));
3967 EXPECT_EQ(match.deletion_url, matches[j].GetAdditionalInfo( 3967 EXPECT_EQ(match.deletion_url, matches[j].GetAdditionalInfo(
3968 "deletion_url")); 3968 "deletion_url"));
3969 } 3969 }
3970 } 3970 }
3971 } 3971 }
3972 3972
3973 TEST_F(SearchProviderTest, ReflectsBookmarkBarState) { 3973 TEST_F(SearchProviderTest, ReflectsBookmarkBarState) {
3974 profile_.GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, false); 3974 profile_.GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, false);
3975 string16 term = term1_.substr(0, term1_.length() - 1); 3975 base::string16 term = term1_.substr(0, term1_.length() - 1);
3976 QueryForInput(term, true, false); 3976 QueryForInput(term, true, false);
3977 ASSERT_FALSE(provider_->matches().empty()); 3977 ASSERT_FALSE(provider_->matches().empty());
3978 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 3978 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
3979 provider_->matches()[0].type); 3979 provider_->matches()[0].type);
3980 ASSERT_TRUE(provider_->matches()[0].search_terms_args != NULL); 3980 ASSERT_TRUE(provider_->matches()[0].search_terms_args != NULL);
3981 EXPECT_FALSE(provider_->matches()[0].search_terms_args->bookmark_bar_pinned); 3981 EXPECT_FALSE(provider_->matches()[0].search_terms_args->bookmark_bar_pinned);
3982 3982
3983 profile_.GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); 3983 profile_.GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true);
3984 term = term1_.substr(0, term1_.length() - 1); 3984 term = term1_.substr(0, term1_.length() - 1);
3985 QueryForInput(term, true, false); 3985 QueryForInput(term, true, false);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
4143 EXPECT_FALSE(provider_->deletion_handlers_.empty()); 4143 EXPECT_FALSE(provider_->deletion_handlers_.empty());
4144 // Set up a default fetcher with provided results. 4144 // Set up a default fetcher with provided results.
4145 fetcher = test_factory_.GetFetcherByID( 4145 fetcher = test_factory_.GetFetcherByID(
4146 SearchProvider::kDeletionURLFetcherID); 4146 SearchProvider::kDeletionURLFetcherID);
4147 ASSERT_TRUE(fetcher); 4147 ASSERT_TRUE(fetcher);
4148 fetcher->set_response_code(500); 4148 fetcher->set_response_code(500);
4149 fetcher->delegate()->OnURLFetchComplete(fetcher); 4149 fetcher->delegate()->OnURLFetchComplete(fetcher);
4150 EXPECT_TRUE(provider_->deletion_handlers_.empty()); 4150 EXPECT_TRUE(provider_->deletion_handlers_.empty());
4151 EXPECT_FALSE(provider_->is_success()); 4151 EXPECT_FALSE(provider_->is_success());
4152 } 4152 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.h ('k') | chrome/browser/autocomplete/shortcuts_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698