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

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

Issue 10537154: A working implementation of AQS (Assisted Query Stats). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Addressed comments and added more docs. Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 AutocompleteMatch* wyt_match) { 204 AutocompleteMatch* wyt_match) {
205 QueryForInput(text, string16(), false); 205 QueryForInput(text, string16(), false);
206 profile_.BlockUntilHistoryProcessesPendingRequests(); 206 profile_.BlockUntilHistoryProcessesPendingRequests();
207 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); 207 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
208 EXPECT_NE(profile_.GetPrefs()->GetBoolean(prefs::kInstantEnabled), 208 EXPECT_NE(profile_.GetPrefs()->GetBoolean(prefs::kInstantEnabled),
209 provider_->done()); 209 provider_->done());
210 if (!wyt_match) 210 if (!wyt_match)
211 return; 211 return;
212 ASSERT_GE(provider_->matches().size(), 1u); 212 ASSERT_GE(provider_->matches().size(), 1u);
213 EXPECT_TRUE(FindMatchWithDestination(GURL( 213 EXPECT_TRUE(FindMatchWithDestination(GURL(
214 default_t_url_->url_ref().ReplaceSearchTerms(text, 214 default_t_url_->url_ref().ReplaceSearchTerms(
215 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), wyt_match)); 215 TemplateURLRef::SearchTermsArgs(text))),
216 wyt_match));
216 } 217 }
217 218
218 void SearchProviderTest::TearDown() { 219 void SearchProviderTest::TearDown() {
219 message_loop_.RunAllPending(); 220 message_loop_.RunAllPending();
220 221
221 // Shutdown the provider before the profile. 222 // Shutdown the provider before the profile.
222 provider_ = NULL; 223 provider_ = NULL;
223 } 224 }
224 225
225 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url, 226 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url,
226 string16 term, 227 string16 term,
227 int visit_count) { 228 int visit_count) {
228 HistoryService* history = 229 HistoryService* history =
229 HistoryServiceFactory::GetForProfile(&profile_, 230 HistoryServiceFactory::GetForProfile(&profile_,
230 Profile::EXPLICIT_ACCESS); 231 Profile::EXPLICIT_ACCESS);
231 GURL search(t_url->url_ref().ReplaceSearchTerms(term, 232 GURL search(t_url->url_ref().ReplaceSearchTerms(
232 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 233 TemplateURLRef::SearchTermsArgs(term)));
233 static base::Time last_added_time; 234 static base::Time last_added_time;
234 last_added_time = std::max(base::Time::Now(), 235 last_added_time = std::max(base::Time::Now(),
235 last_added_time + base::TimeDelta::FromMicroseconds(1)); 236 last_added_time + base::TimeDelta::FromMicroseconds(1));
236 history->AddPageWithDetails(search, string16(), visit_count, visit_count, 237 history->AddPageWithDetails(search, string16(), visit_count, visit_count,
237 last_added_time, false, history::SOURCE_BROWSED); 238 last_added_time, false, history::SOURCE_BROWSED);
238 history->SetKeywordSearchTermsForURL(search, t_url->id(), term); 239 history->SetKeywordSearchTermsForURL(search, t_url->id(), term);
239 return search; 240 return search;
240 } 241 }
241 242
242 bool SearchProviderTest::FindMatchWithContents(const string16& contents, 243 bool SearchProviderTest::FindMatchWithContents(const string16& contents,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 string16 term = term1_.substr(0, term1_.length() - 1); 282 string16 term = term1_.substr(0, term1_.length() - 1);
282 QueryForInput(term, string16(), false); 283 QueryForInput(term, string16(), false);
283 284
284 // Make sure the default providers suggest service was queried. 285 // Make sure the default providers suggest service was queried.
285 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 286 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
286 SearchProvider::kDefaultProviderURLFetcherID); 287 SearchProvider::kDefaultProviderURLFetcherID);
287 ASSERT_TRUE(fetcher); 288 ASSERT_TRUE(fetcher);
288 289
289 // And the URL matches what we expected. 290 // And the URL matches what we expected.
290 GURL expected_url(default_t_url_->suggestions_url_ref().ReplaceSearchTerms( 291 GURL expected_url(default_t_url_->suggestions_url_ref().ReplaceSearchTerms(
291 term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 292 TemplateURLRef::SearchTermsArgs(term)));
292 ASSERT_TRUE(fetcher->GetOriginalURL() == expected_url); 293 ASSERT_TRUE(fetcher->GetOriginalURL() == expected_url);
293 294
294 // Tell the SearchProvider the suggest query is done. 295 // Tell the SearchProvider the suggest query is done.
295 fetcher->set_response_code(200); 296 fetcher->set_response_code(200);
296 fetcher->delegate()->OnURLFetchComplete(fetcher); 297 fetcher->delegate()->OnURLFetchComplete(fetcher);
297 fetcher = NULL; 298 fetcher = NULL;
298 299
299 // Run till the history results complete. 300 // Run till the history results complete.
300 RunTillProviderDone(); 301 RunTillProviderDone();
301 302
302 // The SearchProvider is done. Make sure it has a result for the history 303 // The SearchProvider is done. Make sure it has a result for the history
303 // term term1. 304 // term term1.
304 AutocompleteMatch term1_match; 305 AutocompleteMatch term1_match;
305 EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match)); 306 EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match));
306 // Term1 should not have a description, it's set later. 307 // Term1 should not have a description, it's set later.
307 EXPECT_TRUE(term1_match.description.empty()); 308 EXPECT_TRUE(term1_match.description.empty());
308 309
309 AutocompleteMatch wyt_match; 310 AutocompleteMatch wyt_match;
310 EXPECT_TRUE(FindMatchWithDestination( 311 EXPECT_TRUE(FindMatchWithDestination(
311 GURL(default_t_url_->url_ref().ReplaceSearchTerms(term, 312 GURL(default_t_url_->url_ref().ReplaceSearchTerms(
312 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), &wyt_match)); 313 TemplateURLRef::SearchTermsArgs(term))), &wyt_match));
313 EXPECT_TRUE(wyt_match.description.empty()); 314 EXPECT_TRUE(wyt_match.description.empty());
314 315
315 // The match for term1 should be more relevant than the what you typed result. 316 // The match for term1 should be more relevant than the what you typed result.
316 EXPECT_GT(term1_match.relevance, wyt_match.relevance); 317 EXPECT_GT(term1_match.relevance, wyt_match.relevance);
317 } 318 }
318 319
319 TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) { 320 TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) {
320 string16 term = term1_.substr(0, term1_.length() - 1); 321 string16 term = term1_.substr(0, term1_.length() - 1);
321 QueryForInput(term, string16(), true); 322 QueryForInput(term, string16(), true);
322 323
(...skipping 19 matching lines...) Expand all
342 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 343 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
343 default_fetcher = NULL; 344 default_fetcher = NULL;
344 345
345 // Make sure the keyword providers suggest service was queried. 346 // Make sure the keyword providers suggest service was queried.
346 net::TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( 347 net::TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID(
347 SearchProvider::kKeywordProviderURLFetcherID); 348 SearchProvider::kKeywordProviderURLFetcherID);
348 ASSERT_TRUE(keyword_fetcher); 349 ASSERT_TRUE(keyword_fetcher);
349 350
350 // And the URL matches what we expected. 351 // And the URL matches what we expected.
351 GURL expected_url(keyword_t_url_->suggestions_url_ref().ReplaceSearchTerms( 352 GURL expected_url(keyword_t_url_->suggestions_url_ref().ReplaceSearchTerms(
352 term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 353 TemplateURLRef::SearchTermsArgs(term)));
353 ASSERT_TRUE(keyword_fetcher->GetOriginalURL() == expected_url); 354 ASSERT_TRUE(keyword_fetcher->GetOriginalURL() == expected_url);
354 355
355 // Tell the SearchProvider the keyword suggest query is done. 356 // Tell the SearchProvider the keyword suggest query is done.
356 keyword_fetcher->set_response_code(200); 357 keyword_fetcher->set_response_code(200);
357 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); 358 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
358 keyword_fetcher = NULL; 359 keyword_fetcher = NULL;
359 360
360 // Run till the history results complete. 361 // Run till the history results complete.
361 RunTillProviderDone(); 362 RunTillProviderDone();
362 363
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // Tell the provider instant is done. 412 // Tell the provider instant is done.
412 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); 413 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
413 414
414 // The provider should now be done. 415 // The provider should now be done.
415 EXPECT_TRUE(provider_->done()); 416 EXPECT_TRUE(provider_->done());
416 417
417 // There should be two matches, one for what you typed, the other for 418 // There should be two matches, one for what you typed, the other for
418 // 'foobar'. 419 // 'foobar'.
419 EXPECT_EQ(2u, provider_->matches().size()); 420 EXPECT_EQ(2u, provider_->matches().size());
420 GURL instant_url(default_t_url_->url_ref().ReplaceSearchTerms( 421 GURL instant_url(default_t_url_->url_ref().ReplaceSearchTerms(
421 ASCIIToUTF16("foobar"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, 422 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("foobar"))));
422 string16()));
423 AutocompleteMatch instant_match; 423 AutocompleteMatch instant_match;
424 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match)); 424 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match));
425 425
426 // And the 'foobar' match should not have a description, it'll be set later. 426 // And the 'foobar' match should not have a description, it'll be set later.
427 EXPECT_TRUE(instant_match.description.empty()); 427 EXPECT_TRUE(instant_match.description.empty());
428 428
429 // Make sure the what you typed match has no description. 429 // Make sure the what you typed match has no description.
430 AutocompleteMatch wyt_match; 430 AutocompleteMatch wyt_match;
431 EXPECT_TRUE(FindMatchWithDestination( 431 EXPECT_TRUE(FindMatchWithDestination(
432 GURL(default_t_url_->url_ref().ReplaceSearchTerms(ASCIIToUTF16("foo"), 432 GURL(default_t_url_->url_ref().ReplaceSearchTerms(
433 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), &wyt_match)); 433 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("foo")))),
434 &wyt_match));
434 EXPECT_TRUE(wyt_match.description.empty()); 435 EXPECT_TRUE(wyt_match.description.empty());
435 436
436 // The instant search should be more relevant. 437 // The instant search should be more relevant.
437 EXPECT_GT(instant_match.relevance, wyt_match.relevance); 438 EXPECT_GT(instant_match.relevance, wyt_match.relevance);
438 } 439 }
439 440
440 // Make sure that if FinalizeInstantQuery is invoked before suggest results 441 // Make sure that if FinalizeInstantQuery is invoked before suggest results
441 // return, the suggest text from FinalizeInstantQuery is remembered. 442 // return, the suggest text from FinalizeInstantQuery is remembered.
442 TEST_F(SearchProviderTest, RememberInstantQuery) { 443 TEST_F(SearchProviderTest, RememberInstantQuery) {
443 PrefService* service = profile_.GetPrefs(); 444 PrefService* service = profile_.GetPrefs();
444 service->SetBoolean(prefs::kInstantEnabled, true); 445 service->SetBoolean(prefs::kInstantEnabled, true);
445 446
446 QueryForInput(ASCIIToUTF16("foo"), string16(), false); 447 QueryForInput(ASCIIToUTF16("foo"), string16(), false);
447 448
448 // Finalize the instant query immediately. 449 // Finalize the instant query immediately.
449 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); 450 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
450 451
451 // There should be two matches, one for what you typed, the other for 452 // There should be two matches, one for what you typed, the other for
452 // 'foobar'. 453 // 'foobar'.
453 EXPECT_EQ(2u, provider_->matches().size()); 454 EXPECT_EQ(2u, provider_->matches().size());
454 GURL instant_url(default_t_url_->url_ref().ReplaceSearchTerms( 455 GURL instant_url(default_t_url_->url_ref().ReplaceSearchTerms(
455 ASCIIToUTF16("foobar"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, 456 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("foobar"))));
456 string16()));
457 AutocompleteMatch instant_match; 457 AutocompleteMatch instant_match;
458 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match)); 458 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match));
459 459
460 // Wait until history and the suggest query complete. 460 // Wait until history and the suggest query complete.
461 profile_.BlockUntilHistoryProcessesPendingRequests(); 461 profile_.BlockUntilHistoryProcessesPendingRequests();
462 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); 462 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
463 463
464 // Provider should be done. 464 // Provider should be done.
465 EXPECT_TRUE(provider_->done()); 465 EXPECT_TRUE(provider_->done());
466 466
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 1227 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
1228 match.contents_class[0].style); 1228 match.contents_class[0].style);
1229 EXPECT_EQ(4U, match.contents_class[1].offset); 1229 EXPECT_EQ(4U, match.contents_class[1].offset);
1230 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | 1230 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL |
1231 AutocompleteMatch::ACMatchClassification::MATCH, 1231 AutocompleteMatch::ACMatchClassification::MATCH,
1232 match.contents_class[1].style); 1232 match.contents_class[1].style);
1233 EXPECT_EQ(5U, match.contents_class[2].offset); 1233 EXPECT_EQ(5U, match.contents_class[2].offset);
1234 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 1234 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
1235 match.contents_class[2].style); 1235 match.contents_class[2].style);
1236 } 1236 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.cc ('k') | chrome/browser/importer/profile_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698