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

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

Issue 836213002: Assume all providers may give zero suggest responses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation issue in athena Created 5 years, 11 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 (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/history_url_provider.h" 5 #include "chrome/browser/autocomplete/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 const std::string& desired_tld, 303 const std::string& desired_tld,
304 bool prevent_inline_autocomplete, 304 bool prevent_inline_autocomplete,
305 const UrlAndLegalDefault* expected_urls, 305 const UrlAndLegalDefault* expected_urls,
306 size_t num_results, 306 size_t num_results,
307 metrics::OmniboxInputType::Type* identified_input_type) { 307 metrics::OmniboxInputType::Type* identified_input_type) {
308 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(), 308 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(),
309 metrics::OmniboxEventProto::INVALID_SPEC, 309 metrics::OmniboxEventProto::INVALID_SPEC,
310 prevent_inline_autocomplete, false, true, true, 310 prevent_inline_autocomplete, false, true, true,
311 ChromeAutocompleteSchemeClassifier(profile_.get())); 311 ChromeAutocompleteSchemeClassifier(profile_.get()));
312 *identified_input_type = input.type(); 312 *identified_input_type = input.type();
313 autocomplete_->Start(input, false); 313 autocomplete_->Start(input, false, false);
314 if (!autocomplete_->done()) 314 if (!autocomplete_->done())
315 base::MessageLoop::current()->Run(); 315 base::MessageLoop::current()->Run();
316 316
317 matches_ = autocomplete_->matches(); 317 matches_ = autocomplete_->matches();
318 if (sort_matches_) { 318 if (sort_matches_) {
319 TemplateURLService* service = 319 TemplateURLService* service =
320 TemplateURLServiceFactory::GetForProfile(profile_.get()); 320 TemplateURLServiceFactory::GetForProfile(profile_.get());
321 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) 321 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i)
322 i->ComputeStrippedDestinationURL(service); 322 i->ComputeStrippedDestinationURL(service);
323 AutocompleteResult::DedupMatchesByDestination( 323 AutocompleteResult::DedupMatchesByDestination(
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 // second passes. 603 // second passes.
604 TEST_F(HistoryURLProviderTest, EmptyVisits) { 604 TEST_F(HistoryURLProviderTest, EmptyVisits) {
605 // Wait for history to create the in memory DB. 605 // Wait for history to create the in memory DB.
606 profile_->BlockUntilHistoryProcessesPendingRequests(); 606 profile_->BlockUntilHistoryProcessesPendingRequests();
607 607
608 AutocompleteInput input(ASCIIToUTF16("p"), base::string16::npos, 608 AutocompleteInput input(ASCIIToUTF16("p"), base::string16::npos,
609 std::string(), GURL(), 609 std::string(), GURL(),
610 metrics::OmniboxEventProto::INVALID_SPEC, false, 610 metrics::OmniboxEventProto::INVALID_SPEC, false,
611 false, true, true, 611 false, true, true,
612 ChromeAutocompleteSchemeClassifier(profile_.get())); 612 ChromeAutocompleteSchemeClassifier(profile_.get()));
613 autocomplete_->Start(input, false); 613 autocomplete_->Start(input, false, false);
614 // HistoryURLProvider shouldn't be done (waiting on async results). 614 // HistoryURLProvider shouldn't be done (waiting on async results).
615 EXPECT_FALSE(autocomplete_->done()); 615 EXPECT_FALSE(autocomplete_->done());
616 616
617 // We should get back an entry for pandora. 617 // We should get back an entry for pandora.
618 matches_ = autocomplete_->matches(); 618 matches_ = autocomplete_->matches();
619 ASSERT_GT(matches_.size(), 0u); 619 ASSERT_GT(matches_.size(), 0u);
620 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); 620 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url);
621 int pandora_relevance = matches_[0].relevance; 621 int pandora_relevance = matches_[0].relevance;
622 622
623 // Run the message loop. When |autocomplete_| finishes the loop is quit. 623 // Run the message loop. When |autocomplete_| finishes the loop is quit.
(...skipping 22 matching lines...) Expand all
646 646
647 RunTest(ASCIIToUTF16("this is a query"), std::string(), false, NULL, 0); 647 RunTest(ASCIIToUTF16("this is a query"), std::string(), false, NULL, 0);
648 } 648 }
649 649
650 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { 650 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) {
651 AutocompleteInput input(ASCIIToUTF16("slash "), base::string16::npos, 651 AutocompleteInput input(ASCIIToUTF16("slash "), base::string16::npos,
652 std::string(), GURL(), 652 std::string(), GURL(),
653 metrics::OmniboxEventProto::INVALID_SPEC, false, 653 metrics::OmniboxEventProto::INVALID_SPEC, false,
654 false, true, true, 654 false, true, true,
655 ChromeAutocompleteSchemeClassifier(profile_.get())); 655 ChromeAutocompleteSchemeClassifier(profile_.get()));
656 autocomplete_->Start(input, false); 656 autocomplete_->Start(input, false, false);
657 if (!autocomplete_->done()) 657 if (!autocomplete_->done())
658 base::MessageLoop::current()->Run(); 658 base::MessageLoop::current()->Run();
659 659
660 // None of the matches should attempt to autocomplete. 660 // None of the matches should attempt to autocomplete.
661 matches_ = autocomplete_->matches(); 661 matches_ = autocomplete_->matches();
662 for (size_t i = 0; i < matches_.size(); ++i) { 662 for (size_t i = 0; i < matches_.size(); ++i) {
663 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); 663 EXPECT_TRUE(matches_[i].inline_autocompletion.empty());
664 EXPECT_FALSE(matches_[i].allowed_to_be_default_match); 664 EXPECT_FALSE(matches_[i].allowed_to_be_default_match);
665 } 665 }
666 } 666 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 "//c", 784 "//c",
785 "\\@st", 785 "\\@st",
786 "view-source:x", 786 "view-source:x",
787 }; 787 };
788 for (size_t i = 0; i < arraysize(test_cases); ++i) { 788 for (size_t i = 0; i < arraysize(test_cases); ++i) {
789 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), base::string16::npos, 789 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), base::string16::npos,
790 std::string(), GURL(), 790 std::string(), GURL(),
791 metrics::OmniboxEventProto::INVALID_SPEC, 791 metrics::OmniboxEventProto::INVALID_SPEC,
792 false, false, true, true, 792 false, false, true, true,
793 ChromeAutocompleteSchemeClassifier(profile_.get())); 793 ChromeAutocompleteSchemeClassifier(profile_.get()));
794 autocomplete_->Start(input, false); 794 autocomplete_->Start(input, false, false);
795 if (!autocomplete_->done()) 795 if (!autocomplete_->done())
796 base::MessageLoop::current()->Run(); 796 base::MessageLoop::current()->Run();
797 } 797 }
798 } 798 }
799 799
800 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) {
801 AutocompleteInput input(ASCIIToUTF16("foo"), base::string16::npos,
802 std::string(), GURL(),
803 metrics::OmniboxEventProto::INVALID_SPEC,
804 false, false, true, true,
805 ChromeAutocompleteSchemeClassifier(profile_.get()));
806 autocomplete_->Start(input, false, true);
807 EXPECT_TRUE(autocomplete_->matches().empty());
808 }
809
800 TEST_F(HistoryURLProviderTest, CullSearchResults) { 810 TEST_F(HistoryURLProviderTest, CullSearchResults) {
801 // Set up a default search engine. 811 // Set up a default search engine.
802 TemplateURLData data; 812 TemplateURLData data;
803 data.SetKeyword(ASCIIToUTF16("TestEngine")); 813 data.SetKeyword(ASCIIToUTF16("TestEngine"));
804 data.SetURL("http://testsearch.com/?q={searchTerms}"); 814 data.SetURL("http://testsearch.com/?q={searchTerms}");
805 TemplateURLService* template_url_service = 815 TemplateURLService* template_url_service =
806 TemplateURLServiceFactory::GetForProfile(profile_.get()); 816 TemplateURLServiceFactory::GetForProfile(profile_.get());
807 TemplateURL* template_url = new TemplateURL(data); 817 TemplateURL* template_url = new TemplateURL(data);
808 template_url_service->Add(template_url); 818 template_url_service->Add(template_url);
809 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 819 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 // Test the experiment (scoring enabled). 1032 // Test the experiment (scoring enabled).
1023 autocomplete_->scoring_params_.experimental_scoring_enabled = true; 1033 autocomplete_->scoring_params_.experimental_scoring_enabled = true;
1024 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), 1034 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input),
1025 std::string(), false, output, max_matches)); 1035 std::string(), false, output, max_matches));
1026 for (int j = 0; j < max_matches; ++j) { 1036 for (int j = 0; j < max_matches; ++j) {
1027 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, 1037 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance,
1028 matches_[j].relevance); 1038 matches_[j].relevance);
1029 } 1039 }
1030 } 1040 }
1031 } 1041 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.cc ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698