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

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

Issue 7558014: Add a URL param to indicate group selection in Instant field trial. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Passing NULL as far as possible Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 AutocompleteMatch* wyt_match) { 193 AutocompleteMatch* wyt_match) {
194 QueryForInput(text, false); 194 QueryForInput(text, false);
195 profile_.BlockUntilHistoryProcessesPendingRequests(); 195 profile_.BlockUntilHistoryProcessesPendingRequests();
196 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); 196 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
197 EXPECT_NE(profile_.GetPrefs()->GetBoolean(prefs::kInstantEnabled), 197 EXPECT_NE(profile_.GetPrefs()->GetBoolean(prefs::kInstantEnabled),
198 provider_->done()); 198 provider_->done());
199 if (!wyt_match) 199 if (!wyt_match)
200 return; 200 return;
201 ASSERT_GE(provider_->matches().size(), 1u); 201 ASSERT_GE(provider_->matches().size(), 1u);
202 EXPECT_TRUE(FindMatchWithDestination(GURL( 202 EXPECT_TRUE(FindMatchWithDestination(GURL(
203 default_t_url_->url()->ReplaceSearchTerms(*default_t_url_, text, 0, 203 default_t_url_->url()->ReplaceSearchTerms(
204 string16())), wyt_match)); 204 &profile_, *default_t_url_, text, 0, string16())), wyt_match));
Peter Kasting 2011/08/11 00:35:17 Seems like this file should generally pass NULL as
205 } 205 }
206 206
207 void SearchProviderTest::TearDown() { 207 void SearchProviderTest::TearDown() {
208 message_loop_.RunAllPending(); 208 message_loop_.RunAllPending();
209 209
210 // Shutdown the provider before the profile. 210 // Shutdown the provider before the profile.
211 provider_ = NULL; 211 provider_ = NULL;
212 } 212 }
213 213
214 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url, 214 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url,
215 string16 term, 215 string16 term,
216 int visit_count) { 216 int visit_count) {
217 HistoryService* history = 217 HistoryService* history =
218 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); 218 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS);
219 GURL search(t_url->url()->ReplaceSearchTerms(*t_url, term, 0, string16())); 219 GURL search(t_url->url()->ReplaceSearchTerms(&profile_, *t_url, term, 0,
220 string16()));
220 static base::Time last_added_time; 221 static base::Time last_added_time;
221 last_added_time = std::max(base::Time::Now(), 222 last_added_time = std::max(base::Time::Now(),
222 last_added_time + base::TimeDelta::FromMicroseconds(1)); 223 last_added_time + base::TimeDelta::FromMicroseconds(1));
223 history->AddPageWithDetails(search, string16(), visit_count, visit_count, 224 history->AddPageWithDetails(search, string16(), visit_count, visit_count,
224 last_added_time, false, history::SOURCE_BROWSED); 225 last_added_time, false, history::SOURCE_BROWSED);
225 history->SetKeywordSearchTermsForURL(search, t_url->id(), term); 226 history->SetKeywordSearchTermsForURL(search, t_url->id(), term);
226 return search; 227 return search;
227 } 228 }
228 229
229 bool SearchProviderTest::FindMatchWithDestination(const GURL& url, 230 bool SearchProviderTest::FindMatchWithDestination(const GURL& url,
(...skipping 27 matching lines...) Expand all
257 string16 term = term1_.substr(0, term1_.length() - 1); 258 string16 term = term1_.substr(0, term1_.length() - 1);
258 QueryForInput(term, false); 259 QueryForInput(term, false);
259 260
260 // Make sure the default providers suggest service was queried. 261 // Make sure the default providers suggest service was queried.
261 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 262 TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
262 SearchProvider::kDefaultProviderURLFetcherID); 263 SearchProvider::kDefaultProviderURLFetcherID);
263 ASSERT_TRUE(fetcher); 264 ASSERT_TRUE(fetcher);
264 265
265 // And the URL matches what we expected. 266 // And the URL matches what we expected.
266 GURL expected_url = GURL(default_t_url_->suggestions_url()-> 267 GURL expected_url = GURL(default_t_url_->suggestions_url()->
267 ReplaceSearchTerms(*default_t_url_, term, 0, string16())); 268 ReplaceSearchTerms(&profile_, *default_t_url_, term, 0, string16()));
268 ASSERT_TRUE(fetcher->original_url() == expected_url); 269 ASSERT_TRUE(fetcher->original_url() == expected_url);
269 270
270 // Tell the SearchProvider the suggest query is done. 271 // Tell the SearchProvider the suggest query is done.
271 fetcher->delegate()->OnURLFetchComplete( 272 fetcher->delegate()->OnURLFetchComplete(
272 fetcher, GURL(), net::URLRequestStatus(), 200, net::ResponseCookies(), 273 fetcher, GURL(), net::URLRequestStatus(), 200, net::ResponseCookies(),
273 std::string()); 274 std::string());
274 fetcher = NULL; 275 fetcher = NULL;
275 276
276 // Run till the history results complete. 277 // Run till the history results complete.
277 RunTillProviderDone(); 278 RunTillProviderDone();
278 279
279 // The SearchProvider is done. Make sure it has a result for the history 280 // The SearchProvider is done. Make sure it has a result for the history
280 // term term1. 281 // term term1.
281 AutocompleteMatch term1_match; 282 AutocompleteMatch term1_match;
282 EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match)); 283 EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match));
283 // Term1 should not have a description, it's set later. 284 // Term1 should not have a description, it's set later.
284 EXPECT_TRUE(term1_match.description.empty()); 285 EXPECT_TRUE(term1_match.description.empty());
285 286
286 AutocompleteMatch wyt_match; 287 AutocompleteMatch wyt_match;
287 EXPECT_TRUE(FindMatchWithDestination(GURL( 288 EXPECT_TRUE(FindMatchWithDestination(GURL(
288 default_t_url_->url()->ReplaceSearchTerms(*default_t_url_, term, 0, 289 default_t_url_->url()->ReplaceSearchTerms(
289 string16())), &wyt_match)); 290 &profile_, *default_t_url_, term, 0, string16())), &wyt_match));
290 EXPECT_TRUE(wyt_match.description.empty()); 291 EXPECT_TRUE(wyt_match.description.empty());
291 292
292 // The match for term1 should be more relevant than the what you typed result. 293 // The match for term1 should be more relevant than the what you typed result.
293 EXPECT_GT(term1_match.relevance, wyt_match.relevance); 294 EXPECT_GT(term1_match.relevance, wyt_match.relevance);
294 } 295 }
295 296
296 TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) { 297 TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) {
297 string16 term = term1_.substr(0, term1_.length() - 1); 298 string16 term = term1_.substr(0, term1_.length() - 1);
298 QueryForInput(term, true); 299 QueryForInput(term, true);
299 300
(...skipping 19 matching lines...) Expand all
319 net::ResponseCookies(), std::string()); 320 net::ResponseCookies(), std::string());
320 default_fetcher = NULL; 321 default_fetcher = NULL;
321 322
322 // Make sure the keyword providers suggest service was queried. 323 // Make sure the keyword providers suggest service was queried.
323 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( 324 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID(
324 SearchProvider::kKeywordProviderURLFetcherID); 325 SearchProvider::kKeywordProviderURLFetcherID);
325 ASSERT_TRUE(keyword_fetcher); 326 ASSERT_TRUE(keyword_fetcher);
326 327
327 // And the URL matches what we expected. 328 // And the URL matches what we expected.
328 GURL expected_url = GURL(keyword_t_url_->suggestions_url()-> 329 GURL expected_url = GURL(keyword_t_url_->suggestions_url()->
329 ReplaceSearchTerms(*keyword_t_url_, term, 0, string16())); 330 ReplaceSearchTerms(&profile_, *keyword_t_url_, term, 0, string16()));
330 ASSERT_TRUE(keyword_fetcher->original_url() == expected_url); 331 ASSERT_TRUE(keyword_fetcher->original_url() == expected_url);
331 332
332 // Tell the SearchProvider the keyword suggest query is done. 333 // Tell the SearchProvider the keyword suggest query is done.
333 keyword_fetcher->delegate()->OnURLFetchComplete( 334 keyword_fetcher->delegate()->OnURLFetchComplete(
334 keyword_fetcher, GURL(), net::URLRequestStatus(), 200, 335 keyword_fetcher, GURL(), net::URLRequestStatus(), 200,
335 net::ResponseCookies(), std::string()); 336 net::ResponseCookies(), std::string());
336 keyword_fetcher = NULL; 337 keyword_fetcher = NULL;
337 338
338 // Run till the history results complete. 339 // Run till the history results complete.
339 RunTillProviderDone(); 340 RunTillProviderDone();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // Tell the provider instant is done. 390 // Tell the provider instant is done.
390 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); 391 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
391 392
392 // The provider should now be done. 393 // The provider should now be done.
393 EXPECT_TRUE(provider_->done()); 394 EXPECT_TRUE(provider_->done());
394 395
395 // There should be two matches, one for what you typed, the other for 396 // There should be two matches, one for what you typed, the other for
396 // 'foobar'. 397 // 'foobar'.
397 EXPECT_EQ(2u, provider_->matches().size()); 398 EXPECT_EQ(2u, provider_->matches().size());
398 GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( 399 GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms(
399 *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); 400 &profile_, *default_t_url_, ASCIIToUTF16("foobar"), 0, string16()));
400 AutocompleteMatch instant_match; 401 AutocompleteMatch instant_match;
401 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match)); 402 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match));
402 403
403 // And the 'foobar' match should not have a description, it'll be set later. 404 // And the 'foobar' match should not have a description, it'll be set later.
404 EXPECT_TRUE(instant_match.description.empty()); 405 EXPECT_TRUE(instant_match.description.empty());
405 406
406 // Make sure the what you typed match has no description. 407 // Make sure the what you typed match has no description.
407 AutocompleteMatch wyt_match; 408 AutocompleteMatch wyt_match;
408 EXPECT_TRUE(FindMatchWithDestination(GURL( 409 EXPECT_TRUE(FindMatchWithDestination(GURL(
409 default_t_url_->url()->ReplaceSearchTerms(*default_t_url_, 410 default_t_url_->url()->ReplaceSearchTerms(&profile_, *default_t_url_,
410 ASCIIToUTF16("foo"), 0, string16())), &wyt_match)); 411 ASCIIToUTF16("foo"), 0, string16())), &wyt_match));
411 EXPECT_TRUE(wyt_match.description.empty()); 412 EXPECT_TRUE(wyt_match.description.empty());
412 413
413 // The instant search should be more relevant. 414 // The instant search should be more relevant.
414 EXPECT_GT(instant_match.relevance, wyt_match.relevance); 415 EXPECT_GT(instant_match.relevance, wyt_match.relevance);
415 } 416 }
416 417
417 // Make sure that if FinalizeInstantQuery is invoked before suggest results 418 // Make sure that if FinalizeInstantQuery is invoked before suggest results
418 // return, the suggest text from FinalizeInstantQuery is remembered. 419 // return, the suggest text from FinalizeInstantQuery is remembered.
419 TEST_F(SearchProviderTest, RememberInstantQuery) { 420 TEST_F(SearchProviderTest, RememberInstantQuery) {
420 PrefService* service = profile_.GetPrefs(); 421 PrefService* service = profile_.GetPrefs();
421 service->SetBoolean(prefs::kInstantEnabled, true); 422 service->SetBoolean(prefs::kInstantEnabled, true);
422 423
423 QueryForInput(ASCIIToUTF16("foo"), false); 424 QueryForInput(ASCIIToUTF16("foo"), false);
424 425
425 // Finalize the instant query immediately. 426 // Finalize the instant query immediately.
426 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); 427 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
427 428
428 // There should be two matches, one for what you typed, the other for 429 // There should be two matches, one for what you typed, the other for
429 // 'foobar'. 430 // 'foobar'.
430 EXPECT_EQ(2u, provider_->matches().size()); 431 EXPECT_EQ(2u, provider_->matches().size());
431 GURL instant_url(default_t_url_->url()->ReplaceSearchTerms(*default_t_url_, 432 GURL instant_url(default_t_url_->url()->ReplaceSearchTerms(&profile_,
432 ASCIIToUTF16("foobar"), 0, string16())); 433 *default_t_url_, ASCIIToUTF16("foobar"), 0, string16()));
433 AutocompleteMatch instant_match; 434 AutocompleteMatch instant_match;
434 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match)); 435 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match));
435 436
436 // Wait until history and the suggest query complete. 437 // Wait until history and the suggest query complete.
437 profile_.BlockUntilHistoryProcessesPendingRequests(); 438 profile_.BlockUntilHistoryProcessesPendingRequests();
438 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); 439 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
439 440
440 // Provider should be done. 441 // Provider should be done.
441 EXPECT_TRUE(provider_->done()); 442 EXPECT_TRUE(provider_->done());
442 443
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 fetcher = NULL; 663 fetcher = NULL;
663 664
664 // Run till the history results complete. 665 // Run till the history results complete.
665 RunTillProviderDone(); 666 RunTillProviderDone();
666 667
667 // Make sure there is a match for 'a.com' and it doesn't have a template_url. 668 // Make sure there is a match for 'a.com' and it doesn't have a template_url.
668 AutocompleteMatch nav_match; 669 AutocompleteMatch nav_match;
669 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); 670 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match));
670 EXPECT_FALSE(nav_match.template_url); 671 EXPECT_FALSE(nav_match.template_url);
671 } 672 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698