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

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: Removed SupportsAssistedQueryStats. 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 AutocompleteMatch* wyt_match) { 200 AutocompleteMatch* wyt_match) {
201 QueryForInput(text, false); 201 QueryForInput(text, false);
202 profile_.BlockUntilHistoryProcessesPendingRequests(); 202 profile_.BlockUntilHistoryProcessesPendingRequests();
203 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); 203 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
204 EXPECT_NE(profile_.GetPrefs()->GetBoolean(prefs::kInstantEnabled), 204 EXPECT_NE(profile_.GetPrefs()->GetBoolean(prefs::kInstantEnabled),
205 provider_->done()); 205 provider_->done());
206 if (!wyt_match) 206 if (!wyt_match)
207 return; 207 return;
208 ASSERT_GE(provider_->matches().size(), 1u); 208 ASSERT_GE(provider_->matches().size(), 1u);
209 EXPECT_TRUE(FindMatchWithDestination(GURL( 209 EXPECT_TRUE(FindMatchWithDestination(GURL(
210 default_t_url_->url_ref().ReplaceSearchTerms(text, 210 default_t_url_->url_ref().ReplaceSearchTerms(SearchTermsArgs(text))),
211 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), wyt_match)); 211 wyt_match));
212 } 212 }
213 213
214 void SearchProviderTest::TearDown() { 214 void SearchProviderTest::TearDown() {
215 message_loop_.RunAllPending(); 215 message_loop_.RunAllPending();
216 216
217 // Shutdown the provider before the profile. 217 // Shutdown the provider before the profile.
218 provider_ = NULL; 218 provider_ = NULL;
219 } 219 }
220 220
221 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url, 221 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url,
222 string16 term, 222 string16 term,
223 int visit_count) { 223 int visit_count) {
224 HistoryService* history = 224 HistoryService* history =
225 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); 225 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS);
226 GURL search(t_url->url_ref().ReplaceSearchTerms(term, 226 GURL search(t_url->url_ref().ReplaceSearchTerms(SearchTermsArgs(term)));
227 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
228 static base::Time last_added_time; 227 static base::Time last_added_time;
229 last_added_time = std::max(base::Time::Now(), 228 last_added_time = std::max(base::Time::Now(),
230 last_added_time + base::TimeDelta::FromMicroseconds(1)); 229 last_added_time + base::TimeDelta::FromMicroseconds(1));
231 history->AddPageWithDetails(search, string16(), visit_count, visit_count, 230 history->AddPageWithDetails(search, string16(), visit_count, visit_count,
232 last_added_time, false, history::SOURCE_BROWSED); 231 last_added_time, false, history::SOURCE_BROWSED);
233 history->SetKeywordSearchTermsForURL(search, t_url->id(), term); 232 history->SetKeywordSearchTermsForURL(search, t_url->id(), term);
234 return search; 233 return search;
235 } 234 }
236 235
237 bool SearchProviderTest::FindMatchWithContents(const string16& contents, 236 bool SearchProviderTest::FindMatchWithContents(const string16& contents,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 string16 term = term1_.substr(0, term1_.length() - 1); 275 string16 term = term1_.substr(0, term1_.length() - 1);
277 QueryForInput(term, false); 276 QueryForInput(term, false);
278 277
279 // Make sure the default providers suggest service was queried. 278 // Make sure the default providers suggest service was queried.
280 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 279 TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
281 SearchProvider::kDefaultProviderURLFetcherID); 280 SearchProvider::kDefaultProviderURLFetcherID);
282 ASSERT_TRUE(fetcher); 281 ASSERT_TRUE(fetcher);
283 282
284 // And the URL matches what we expected. 283 // And the URL matches what we expected.
285 GURL expected_url(default_t_url_->suggestions_url_ref().ReplaceSearchTerms( 284 GURL expected_url(default_t_url_->suggestions_url_ref().ReplaceSearchTerms(
286 term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 285 SearchTermsArgs(term)));
287 ASSERT_TRUE(fetcher->GetOriginalURL() == expected_url); 286 ASSERT_TRUE(fetcher->GetOriginalURL() == expected_url);
288 287
289 // Tell the SearchProvider the suggest query is done. 288 // Tell the SearchProvider the suggest query is done.
290 fetcher->set_response_code(200); 289 fetcher->set_response_code(200);
291 fetcher->delegate()->OnURLFetchComplete(fetcher); 290 fetcher->delegate()->OnURLFetchComplete(fetcher);
292 fetcher = NULL; 291 fetcher = NULL;
293 292
294 // Run till the history results complete. 293 // Run till the history results complete.
295 RunTillProviderDone(); 294 RunTillProviderDone();
296 295
297 // The SearchProvider is done. Make sure it has a result for the history 296 // The SearchProvider is done. Make sure it has a result for the history
298 // term term1. 297 // term term1.
299 AutocompleteMatch term1_match; 298 AutocompleteMatch term1_match;
300 EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match)); 299 EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match));
301 // Term1 should not have a description, it's set later. 300 // Term1 should not have a description, it's set later.
302 EXPECT_TRUE(term1_match.description.empty()); 301 EXPECT_TRUE(term1_match.description.empty());
303 302
304 AutocompleteMatch wyt_match; 303 AutocompleteMatch wyt_match;
305 EXPECT_TRUE(FindMatchWithDestination( 304 EXPECT_TRUE(FindMatchWithDestination(
306 GURL(default_t_url_->url_ref().ReplaceSearchTerms(term, 305 GURL(default_t_url_->url_ref().ReplaceSearchTerms(
307 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), &wyt_match)); 306 SearchTermsArgs(term))), &wyt_match));
308 EXPECT_TRUE(wyt_match.description.empty()); 307 EXPECT_TRUE(wyt_match.description.empty());
309 308
310 // The match for term1 should be more relevant than the what you typed result. 309 // The match for term1 should be more relevant than the what you typed result.
311 EXPECT_GT(term1_match.relevance, wyt_match.relevance); 310 EXPECT_GT(term1_match.relevance, wyt_match.relevance);
312 } 311 }
313 312
314 TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) { 313 TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) {
315 string16 term = term1_.substr(0, term1_.length() - 1); 314 string16 term = term1_.substr(0, term1_.length() - 1);
316 QueryForInput(term, true); 315 QueryForInput(term, true);
317 316
(...skipping 18 matching lines...) Expand all
336 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 335 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
337 default_fetcher = NULL; 336 default_fetcher = NULL;
338 337
339 // Make sure the keyword providers suggest service was queried. 338 // Make sure the keyword providers suggest service was queried.
340 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( 339 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID(
341 SearchProvider::kKeywordProviderURLFetcherID); 340 SearchProvider::kKeywordProviderURLFetcherID);
342 ASSERT_TRUE(keyword_fetcher); 341 ASSERT_TRUE(keyword_fetcher);
343 342
344 // And the URL matches what we expected. 343 // And the URL matches what we expected.
345 GURL expected_url(keyword_t_url_->suggestions_url_ref().ReplaceSearchTerms( 344 GURL expected_url(keyword_t_url_->suggestions_url_ref().ReplaceSearchTerms(
346 term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 345 SearchTermsArgs(term)));
347 ASSERT_TRUE(keyword_fetcher->GetOriginalURL() == expected_url); 346 ASSERT_TRUE(keyword_fetcher->GetOriginalURL() == expected_url);
348 347
349 // Tell the SearchProvider the keyword suggest query is done. 348 // Tell the SearchProvider the keyword suggest query is done.
350 keyword_fetcher->set_response_code(200); 349 keyword_fetcher->set_response_code(200);
351 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); 350 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
352 keyword_fetcher = NULL; 351 keyword_fetcher = NULL;
353 352
354 // Run till the history results complete. 353 // Run till the history results complete.
355 RunTillProviderDone(); 354 RunTillProviderDone();
356 355
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // Tell the provider instant is done. 404 // Tell the provider instant is done.
406 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); 405 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
407 406
408 // The provider should now be done. 407 // The provider should now be done.
409 EXPECT_TRUE(provider_->done()); 408 EXPECT_TRUE(provider_->done());
410 409
411 // There should be two matches, one for what you typed, the other for 410 // There should be two matches, one for what you typed, the other for
412 // 'foobar'. 411 // 'foobar'.
413 EXPECT_EQ(2u, provider_->matches().size()); 412 EXPECT_EQ(2u, provider_->matches().size());
414 GURL instant_url(default_t_url_->url_ref().ReplaceSearchTerms( 413 GURL instant_url(default_t_url_->url_ref().ReplaceSearchTerms(
415 ASCIIToUTF16("foobar"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, 414 SearchTermsArgs(ASCIIToUTF16("foobar"))));
416 string16()));
417 AutocompleteMatch instant_match; 415 AutocompleteMatch instant_match;
418 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match)); 416 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match));
419 417
420 // And the 'foobar' match should not have a description, it'll be set later. 418 // And the 'foobar' match should not have a description, it'll be set later.
421 EXPECT_TRUE(instant_match.description.empty()); 419 EXPECT_TRUE(instant_match.description.empty());
422 420
423 // Make sure the what you typed match has no description. 421 // Make sure the what you typed match has no description.
424 AutocompleteMatch wyt_match; 422 AutocompleteMatch wyt_match;
425 EXPECT_TRUE(FindMatchWithDestination( 423 EXPECT_TRUE(FindMatchWithDestination(
426 GURL(default_t_url_->url_ref().ReplaceSearchTerms(ASCIIToUTF16("foo"), 424 GURL(default_t_url_->url_ref().ReplaceSearchTerms(
427 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), &wyt_match)); 425 SearchTermsArgs(ASCIIToUTF16("foo")))), &wyt_match));
428 EXPECT_TRUE(wyt_match.description.empty()); 426 EXPECT_TRUE(wyt_match.description.empty());
429 427
430 // The instant search should be more relevant. 428 // The instant search should be more relevant.
431 EXPECT_GT(instant_match.relevance, wyt_match.relevance); 429 EXPECT_GT(instant_match.relevance, wyt_match.relevance);
432 } 430 }
433 431
434 // Make sure that if FinalizeInstantQuery is invoked before suggest results 432 // Make sure that if FinalizeInstantQuery is invoked before suggest results
435 // return, the suggest text from FinalizeInstantQuery is remembered. 433 // return, the suggest text from FinalizeInstantQuery is remembered.
436 TEST_F(SearchProviderTest, RememberInstantQuery) { 434 TEST_F(SearchProviderTest, RememberInstantQuery) {
437 PrefService* service = profile_.GetPrefs(); 435 PrefService* service = profile_.GetPrefs();
438 service->SetBoolean(prefs::kInstantEnabled, true); 436 service->SetBoolean(prefs::kInstantEnabled, true);
439 437
440 QueryForInput(ASCIIToUTF16("foo"), false); 438 QueryForInput(ASCIIToUTF16("foo"), false);
441 439
442 // Finalize the instant query immediately. 440 // Finalize the instant query immediately.
443 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); 441 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
444 442
445 // There should be two matches, one for what you typed, the other for 443 // There should be two matches, one for what you typed, the other for
446 // 'foobar'. 444 // 'foobar'.
447 EXPECT_EQ(2u, provider_->matches().size()); 445 EXPECT_EQ(2u, provider_->matches().size());
448 GURL instant_url(default_t_url_->url_ref().ReplaceSearchTerms( 446 GURL instant_url(default_t_url_->url_ref().ReplaceSearchTerms(
449 ASCIIToUTF16("foobar"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, 447 SearchTermsArgs(ASCIIToUTF16("foobar"))));
450 string16()));
451 AutocompleteMatch instant_match; 448 AutocompleteMatch instant_match;
452 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match)); 449 EXPECT_TRUE(FindMatchWithDestination(instant_url, &instant_match));
453 450
454 // Wait until history and the suggest query complete. 451 // Wait until history and the suggest query complete.
455 profile_.BlockUntilHistoryProcessesPendingRequests(); 452 profile_.BlockUntilHistoryProcessesPendingRequests();
456 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); 453 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
457 454
458 // Provider should be done. 455 // Provider should be done.
459 EXPECT_TRUE(provider_->done()); 456 EXPECT_TRUE(provider_->done());
460 457
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 1050 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
1054 match.contents_class[0].style); 1051 match.contents_class[0].style);
1055 EXPECT_EQ(4U, match.contents_class[1].offset); 1052 EXPECT_EQ(4U, match.contents_class[1].offset);
1056 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | 1053 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL |
1057 AutocompleteMatch::ACMatchClassification::MATCH, 1054 AutocompleteMatch::ACMatchClassification::MATCH,
1058 match.contents_class[1].style); 1055 match.contents_class[1].style);
1059 EXPECT_EQ(5U, match.contents_class[2].offset); 1056 EXPECT_EQ(5U, match.contents_class[2].offset);
1060 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 1057 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
1061 match.contents_class[2].style); 1058 match.contents_class[2].style);
1062 } 1059 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698