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

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

Issue 2738003002: Add title to current page in zero suggest. (Closed)
Patch Set: Remove debugging info. Created 3 years, 7 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
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 "components/omnibox/browser/search_provider.h" 5 #include "components/omnibox/browser/search_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // Shutdown the provider before the profile. 323 // Shutdown the provider before the profile.
324 provider_ = NULL; 324 provider_ = NULL;
325 } 325 }
326 326
327 void SearchProviderTest::RunTest(TestData* cases, 327 void SearchProviderTest::RunTest(TestData* cases,
328 int num_cases, 328 int num_cases,
329 bool prefer_keyword) { 329 bool prefer_keyword) {
330 ACMatches matches; 330 ACMatches matches;
331 for (int i = 0; i < num_cases; ++i) { 331 for (int i = 0; i < num_cases; ++i) {
332 AutocompleteInput input(cases[i].input, base::string16::npos, std::string(), 332 AutocompleteInput input(cases[i].input, base::string16::npos, std::string(),
333 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, 333 GURL(), base::string16(),
334 false, prefer_keyword, true, true, false, 334 metrics::OmniboxEventProto::INVALID_SPEC, false,
335 prefer_keyword, true, true, false,
335 ChromeAutocompleteSchemeClassifier(&profile_)); 336 ChromeAutocompleteSchemeClassifier(&profile_));
336 provider_->Start(input, false); 337 provider_->Start(input, false);
337 matches = provider_->matches(); 338 matches = provider_->matches();
338 SCOPED_TRACE( 339 SCOPED_TRACE(
339 ASCIIToUTF16("Input was: ") + 340 ASCIIToUTF16("Input was: ") +
340 cases[i].input + 341 cases[i].input +
341 ASCIIToUTF16("; prefer_keyword was: ") + 342 ASCIIToUTF16("; prefer_keyword was: ") +
342 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false"))); 343 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false")));
343 EXPECT_EQ(cases[i].num_results, matches.size()); 344 EXPECT_EQ(cases[i].num_results, matches.size());
344 if (matches.size() == cases[i].num_results) { 345 if (matches.size() == cases[i].num_results) {
(...skipping 22 matching lines...) Expand all
367 368
368 base::RunLoop run_loop; 369 base::RunLoop run_loop;
369 run_loop_ = &run_loop; 370 run_loop_ = &run_loop;
370 run_loop.Run(); 371 run_loop.Run();
371 } 372 }
372 373
373 void SearchProviderTest::QueryForInput(const base::string16& text, 374 void SearchProviderTest::QueryForInput(const base::string16& text,
374 bool prevent_inline_autocomplete, 375 bool prevent_inline_autocomplete,
375 bool prefer_keyword) { 376 bool prefer_keyword) {
376 // Start a query. 377 // Start a query.
377 AutocompleteInput input(text, base::string16::npos, std::string(), GURL(), 378 AutocompleteInput input(
378 metrics::OmniboxEventProto::INVALID_SPEC, 379 text, base::string16::npos, std::string(), GURL(), base::string16(),
379 prevent_inline_autocomplete, prefer_keyword, true, 380 metrics::OmniboxEventProto::INVALID_SPEC, prevent_inline_autocomplete,
380 true, false, 381 prefer_keyword, true, true, false,
381 ChromeAutocompleteSchemeClassifier(&profile_)); 382 ChromeAutocompleteSchemeClassifier(&profile_));
382 provider_->Start(input, false); 383 provider_->Start(input, false);
383 384
384 // RunUntilIdle so that the task scheduled by SearchProvider to create the 385 // RunUntilIdle so that the task scheduled by SearchProvider to create the
385 // URLFetchers runs. 386 // URLFetchers runs.
386 base::RunLoop().RunUntilIdle(); 387 base::RunLoop().RunUntilIdle();
387 } 388 }
388 389
389 void SearchProviderTest::QueryForInputAndSetWYTMatch( 390 void SearchProviderTest::QueryForInputAndSetWYTMatch(
390 const base::string16& text, 391 const base::string16& text,
391 AutocompleteMatch* wyt_match) { 392 AutocompleteMatch* wyt_match) {
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { 1002 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) {
1002 // Add an entry that corresponds to a keyword search with 'term2'. 1003 // Add an entry that corresponds to a keyword search with 'term2'.
1003 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); 1004 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1);
1004 profile_.BlockUntilHistoryProcessesPendingRequests(); 1005 profile_.BlockUntilHistoryProcessesPendingRequests();
1005 1006
1006 AutocompleteController controller( 1007 AutocompleteController controller(
1007 base::WrapUnique(new ChromeAutocompleteProviderClient(&profile_)), 1008 base::WrapUnique(new ChromeAutocompleteProviderClient(&profile_)),
1008 nullptr, AutocompleteProvider::TYPE_SEARCH); 1009 nullptr, AutocompleteProvider::TYPE_SEARCH);
1009 controller.Start(AutocompleteInput( 1010 controller.Start(AutocompleteInput(
1010 ASCIIToUTF16("k t"), base::string16::npos, std::string(), GURL(), 1011 ASCIIToUTF16("k t"), base::string16::npos, std::string(), GURL(),
1011 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, 1012 base::string16(), metrics::OmniboxEventProto::INVALID_SPEC, false, false,
1012 ChromeAutocompleteSchemeClassifier(&profile_))); 1013 true, true, false, ChromeAutocompleteSchemeClassifier(&profile_)));
1013 const AutocompleteResult& result = controller.result(); 1014 const AutocompleteResult& result = controller.result();
1014 1015
1015 // There should be three matches, one for the keyword history, one for 1016 // There should be three matches, one for the keyword history, one for
1016 // keyword provider's what-you-typed, and one for the default provider's 1017 // keyword provider's what-you-typed, and one for the default provider's
1017 // what you typed, in that order. 1018 // what you typed, in that order.
1018 ASSERT_EQ(3u, result.size()); 1019 ASSERT_EQ(3u, result.size());
1019 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type); 1020 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type);
1020 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE, 1021 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE,
1021 result.match_at(1).type); 1022 result.match_at(1).type);
1022 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 1023 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
(...skipping 2571 matching lines...) Expand 10 before | Expand all | Expand 10 after
3594 EXPECT_TRUE(matches[3].answer_type.empty()); 3595 EXPECT_TRUE(matches[3].answer_type.empty());
3595 EXPECT_FALSE(matches[3].answer); 3596 EXPECT_FALSE(matches[3].answer);
3596 EXPECT_TRUE(matches[4].answer_contents.empty()); 3597 EXPECT_TRUE(matches[4].answer_contents.empty());
3597 EXPECT_TRUE(matches[4].answer_type.empty()); 3598 EXPECT_TRUE(matches[4].answer_type.empty());
3598 EXPECT_FALSE(matches[4].answer); 3599 EXPECT_FALSE(matches[4].answer);
3599 } 3600 }
3600 3601
3601 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { 3602 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) {
3602 AutocompleteInput input( 3603 AutocompleteInput input(
3603 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), 3604 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(),
3604 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, 3605 base::string16(), metrics::OmniboxEventProto::INVALID_SPEC, false, true,
3605 ChromeAutocompleteSchemeClassifier(&profile_)); 3606 true, true, true, ChromeAutocompleteSchemeClassifier(&profile_));
3606 provider_->Start(input, false); 3607 provider_->Start(input, false);
3607 EXPECT_TRUE(provider_->matches().empty()); 3608 EXPECT_TRUE(provider_->matches().empty());
3608 } 3609 }
3609 3610
3610 TEST_F(SearchProviderTest, SendsWarmUpRequestOnFocus) { 3611 TEST_F(SearchProviderTest, SendsWarmUpRequestOnFocus) {
3611 AutocompleteInput input( 3612 AutocompleteInput input(
3612 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), 3613 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(),
3613 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, 3614 base::string16(), metrics::OmniboxEventProto::INVALID_SPEC, false, true,
3614 ChromeAutocompleteSchemeClassifier(&profile_)); 3615 true, true, true, ChromeAutocompleteSchemeClassifier(&profile_));
3615 3616
3616 // First, verify that without the warm-up feature enabled, the provider 3617 // First, verify that without the warm-up feature enabled, the provider
3617 // immediately terminates with no matches. 3618 // immediately terminates with no matches.
3618 provider_->Start(input, false); 3619 provider_->Start(input, false);
3619 // RunUntilIdle so that SearchProvider has a chance to create the URLFetchers 3620 // RunUntilIdle so that SearchProvider has a chance to create the URLFetchers
3620 // (if it wants to, which it shouldn't in this case). 3621 // (if it wants to, which it shouldn't in this case).
3621 base::RunLoop().RunUntilIdle(); 3622 base::RunLoop().RunUntilIdle();
3622 EXPECT_TRUE(provider_->done()); 3623 EXPECT_TRUE(provider_->done());
3623 EXPECT_TRUE(provider_->matches().empty()); 3624 EXPECT_TRUE(provider_->matches().empty());
3624 3625
(...skipping 11 matching lines...) Expand all
3636 EXPECT_TRUE(fetcher); 3637 EXPECT_TRUE(fetcher);
3637 // Even if the fetcher returns results, we should still have no suggestions 3638 // Even if the fetcher returns results, we should still have no suggestions
3638 // (though the provider should now be done). 3639 // (though the provider should now be done).
3639 fetcher->set_response_code(200); 3640 fetcher->set_response_code(200);
3640 fetcher->SetResponseString(R"(["",["a", "b"],[],[],{}])"); 3641 fetcher->SetResponseString(R"(["",["a", "b"],[],[],{}])");
3641 fetcher->delegate()->OnURLFetchComplete(fetcher); 3642 fetcher->delegate()->OnURLFetchComplete(fetcher);
3642 RunTillProviderDone(); 3643 RunTillProviderDone();
3643 EXPECT_TRUE(provider_->done()); 3644 EXPECT_TRUE(provider_->done());
3644 EXPECT_TRUE(provider_->matches().empty()); 3645 EXPECT_TRUE(provider_->matches().empty());
3645 } 3646 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698