OLD | NEW |
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/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 void FillData(); | 182 void FillData(); |
183 | 183 |
184 // Runs an autocomplete query on |text| and checks to see that the returned | 184 // Runs an autocomplete query on |text| and checks to see that the returned |
185 // results' destination URLs match those provided. Also allows checking | 185 // results' destination URLs match those provided. Also allows checking |
186 // that the input type was identified correctly. | 186 // that the input type was identified correctly. |
187 void RunTest(const base::string16 text, | 187 void RunTest(const base::string16 text, |
188 const base::string16& desired_tld, | 188 const base::string16& desired_tld, |
189 bool prevent_inline_autocomplete, | 189 bool prevent_inline_autocomplete, |
190 const UrlAndLegalDefault* expected_urls, | 190 const UrlAndLegalDefault* expected_urls, |
191 size_t num_results, | 191 size_t num_results, |
192 AutocompleteInput::Type* identified_input_type); | 192 metrics::OmniboxInputType::Type* identified_input_type); |
193 | 193 |
194 // A version of the above without the final |type| output parameter. | 194 // A version of the above without the final |type| output parameter. |
195 void RunTest(const base::string16 text, | 195 void RunTest(const base::string16 text, |
196 const base::string16& desired_tld, | 196 const base::string16& desired_tld, |
197 bool prevent_inline_autocomplete, | 197 bool prevent_inline_autocomplete, |
198 const UrlAndLegalDefault* expected_urls, | 198 const UrlAndLegalDefault* expected_urls, |
199 size_t num_results) { | 199 size_t num_results) { |
200 AutocompleteInput::Type type; | 200 metrics::OmniboxInputType::Type type; |
201 return RunTest(text, desired_tld, prevent_inline_autocomplete, | 201 return RunTest(text, desired_tld, prevent_inline_autocomplete, |
202 expected_urls, num_results, &type); | 202 expected_urls, num_results, &type); |
203 } | 203 } |
204 | 204 |
205 content::TestBrowserThreadBundle thread_bundle_; | 205 content::TestBrowserThreadBundle thread_bundle_; |
206 ACMatches matches_; | 206 ACMatches matches_; |
207 scoped_ptr<TestingProfile> profile_; | 207 scoped_ptr<TestingProfile> profile_; |
208 HistoryService* history_service_; | 208 HistoryService* history_service_; |
209 scoped_refptr<HistoryURLProvider> autocomplete_; | 209 scoped_refptr<HistoryURLProvider> autocomplete_; |
210 // Should the matches be sorted and duplicates removed? | 210 // Should the matches be sorted and duplicates removed? |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), | 271 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), |
272 false, history::SOURCE_BROWSED); | 272 false, history::SOURCE_BROWSED); |
273 } | 273 } |
274 | 274 |
275 void HistoryURLProviderTest::RunTest( | 275 void HistoryURLProviderTest::RunTest( |
276 const base::string16 text, | 276 const base::string16 text, |
277 const base::string16& desired_tld, | 277 const base::string16& desired_tld, |
278 bool prevent_inline_autocomplete, | 278 bool prevent_inline_autocomplete, |
279 const UrlAndLegalDefault* expected_urls, | 279 const UrlAndLegalDefault* expected_urls, |
280 size_t num_results, | 280 size_t num_results, |
281 AutocompleteInput::Type* identified_input_type) { | 281 metrics::OmniboxInputType::Type* identified_input_type) { |
282 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(), | 282 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(), |
283 AutocompleteInput::INVALID_SPEC, | 283 metrics::OmniboxEventProto::INVALID_SPEC, |
284 prevent_inline_autocomplete, false, true, true); | 284 prevent_inline_autocomplete, false, true, true); |
285 *identified_input_type = input.type(); | 285 *identified_input_type = input.type(); |
286 autocomplete_->Start(input, false); | 286 autocomplete_->Start(input, false); |
287 if (!autocomplete_->done()) | 287 if (!autocomplete_->done()) |
288 base::MessageLoop::current()->Run(); | 288 base::MessageLoop::current()->Run(); |
289 | 289 |
290 matches_ = autocomplete_->matches(); | 290 matches_ = autocomplete_->matches(); |
291 if (sort_matches_) { | 291 if (sort_matches_) { |
292 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) | 292 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) |
293 i->ComputeStrippedDestinationURL(profile_.get()); | 293 i->ComputeStrippedDestinationURL(profile_.get()); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 } | 552 } |
553 | 553 |
554 // Make sure the results for the input 'p' don't change between the first and | 554 // Make sure the results for the input 'p' don't change between the first and |
555 // second passes. | 555 // second passes. |
556 TEST_F(HistoryURLProviderTest, EmptyVisits) { | 556 TEST_F(HistoryURLProviderTest, EmptyVisits) { |
557 // Wait for history to create the in memory DB. | 557 // Wait for history to create the in memory DB. |
558 profile_->BlockUntilHistoryProcessesPendingRequests(); | 558 profile_->BlockUntilHistoryProcessesPendingRequests(); |
559 | 559 |
560 AutocompleteInput input(ASCIIToUTF16("p"), base::string16::npos, | 560 AutocompleteInput input(ASCIIToUTF16("p"), base::string16::npos, |
561 base::string16(), GURL(), | 561 base::string16(), GURL(), |
562 AutocompleteInput::INVALID_SPEC, false, false, true, | 562 metrics::OmniboxEventProto::INVALID_SPEC, false, |
563 true); | 563 false, true, true); |
564 autocomplete_->Start(input, false); | 564 autocomplete_->Start(input, false); |
565 // HistoryURLProvider shouldn't be done (waiting on async results). | 565 // HistoryURLProvider shouldn't be done (waiting on async results). |
566 EXPECT_FALSE(autocomplete_->done()); | 566 EXPECT_FALSE(autocomplete_->done()); |
567 | 567 |
568 // We should get back an entry for pandora. | 568 // We should get back an entry for pandora. |
569 matches_ = autocomplete_->matches(); | 569 matches_ = autocomplete_->matches(); |
570 ASSERT_GT(matches_.size(), 0u); | 570 ASSERT_GT(matches_.size(), 0u); |
571 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); | 571 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); |
572 int pandora_relevance = matches_[0].relevance; | 572 int pandora_relevance = matches_[0].relevance; |
573 | 573 |
(...skipping 20 matching lines...) Expand all Loading... |
594 }; | 594 }; |
595 RunTest(ASCIIToUTF16("slash"), base::string16(), false, navigation_2, | 595 RunTest(ASCIIToUTF16("slash"), base::string16(), false, navigation_2, |
596 arraysize(navigation_2)); | 596 arraysize(navigation_2)); |
597 | 597 |
598 RunTest(ASCIIToUTF16("this is a query"), base::string16(), false, NULL, 0); | 598 RunTest(ASCIIToUTF16("this is a query"), base::string16(), false, NULL, 0); |
599 } | 599 } |
600 | 600 |
601 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { | 601 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { |
602 AutocompleteInput input(ASCIIToUTF16("slash "), base::string16::npos, | 602 AutocompleteInput input(ASCIIToUTF16("slash "), base::string16::npos, |
603 base::string16(), GURL(), | 603 base::string16(), GURL(), |
604 AutocompleteInput::INVALID_SPEC, false, false, | 604 metrics::OmniboxEventProto::INVALID_SPEC, false, |
605 true, true); | 605 false, true, true); |
606 autocomplete_->Start(input, false); | 606 autocomplete_->Start(input, false); |
607 if (!autocomplete_->done()) | 607 if (!autocomplete_->done()) |
608 base::MessageLoop::current()->Run(); | 608 base::MessageLoop::current()->Run(); |
609 | 609 |
610 // None of the matches should attempt to autocomplete. | 610 // None of the matches should attempt to autocomplete. |
611 matches_ = autocomplete_->matches(); | 611 matches_ = autocomplete_->matches(); |
612 for (size_t i = 0; i < matches_.size(); ++i) { | 612 for (size_t i = 0; i < matches_.size(); ++i) { |
613 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); | 613 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); |
614 EXPECT_FALSE(matches_[i].allowed_to_be_default_match); | 614 EXPECT_FALSE(matches_[i].allowed_to_be_default_match); |
615 } | 615 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); | 660 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); |
661 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); | 661 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); |
662 } | 662 } |
663 } | 663 } |
664 } | 664 } |
665 | 665 |
666 TEST_F(HistoryURLProviderTest, IntranetURLsWithRefs) { | 666 TEST_F(HistoryURLProviderTest, IntranetURLsWithRefs) { |
667 struct TestCase { | 667 struct TestCase { |
668 const char* input; | 668 const char* input; |
669 int relevance; | 669 int relevance; |
670 AutocompleteInput::Type type; | 670 metrics::OmniboxInputType::Type type; |
671 } test_cases[] = { | 671 } test_cases[] = { |
672 { "gooey", 1410, metrics::OmniboxInputType::UNKNOWN }, | 672 { "gooey", 1410, metrics::OmniboxInputType::UNKNOWN }, |
673 { "gooey/", 1410, metrics::OmniboxInputType::URL }, | 673 { "gooey/", 1410, metrics::OmniboxInputType::URL }, |
674 { "gooey#", 1200, metrics::OmniboxInputType::UNKNOWN }, | 674 { "gooey#", 1200, metrics::OmniboxInputType::UNKNOWN }, |
675 { "gooey/#", 1200, metrics::OmniboxInputType::URL }, | 675 { "gooey/#", 1200, metrics::OmniboxInputType::URL }, |
676 { "gooey#foo", 1200, metrics::OmniboxInputType::UNKNOWN }, | 676 { "gooey#foo", 1200, metrics::OmniboxInputType::UNKNOWN }, |
677 { "gooey/#foo", 1200, metrics::OmniboxInputType::URL }, | 677 { "gooey/#foo", 1200, metrics::OmniboxInputType::URL }, |
678 { "gooey# foo", 1200, metrics::OmniboxInputType::UNKNOWN }, | 678 { "gooey# foo", 1200, metrics::OmniboxInputType::UNKNOWN }, |
679 { "gooey/# foo", 1200, metrics::OmniboxInputType::URL }, | 679 { "gooey/# foo", 1200, metrics::OmniboxInputType::URL }, |
680 }; | 680 }; |
681 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 681 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
682 SCOPED_TRACE(test_cases[i].input); | 682 SCOPED_TRACE(test_cases[i].input); |
683 const UrlAndLegalDefault output[] = { | 683 const UrlAndLegalDefault output[] = { |
684 {url_fixer::FixupURL(test_cases[i].input, std::string()).spec(), true}}; | 684 {url_fixer::FixupURL(test_cases[i].input, std::string()).spec(), true}}; |
685 AutocompleteInput::Type type; | 685 metrics::OmniboxInputType::Type type; |
686 ASSERT_NO_FATAL_FAILURE( | 686 ASSERT_NO_FATAL_FAILURE( |
687 RunTest(ASCIIToUTF16(test_cases[i].input), | 687 RunTest(ASCIIToUTF16(test_cases[i].input), |
688 base::string16(), false, output, arraysize(output), &type)); | 688 base::string16(), false, output, arraysize(output), &type)); |
689 // Actual relevance should be at least what test_cases expects and | 689 // Actual relevance should be at least what test_cases expects and |
690 // and no more than 10 more. | 690 // and no more than 10 more. |
691 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); | 691 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); |
692 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); | 692 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); |
693 // Input type should be what we expect. This is important because | 693 // Input type should be what we expect. This is important because |
694 // this provider counts on SearchProvider to give queries a relevance | 694 // this provider counts on SearchProvider to give queries a relevance |
695 // score >1200 for UNKNOWN inputs and <1200 for URL inputs. (That's | 695 // score >1200 for UNKNOWN inputs and <1200 for URL inputs. (That's |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 TEST_F(HistoryURLProviderTest, CrashDueToFixup) { | 770 TEST_F(HistoryURLProviderTest, CrashDueToFixup) { |
771 // This test passes if we don't crash. The results don't matter. | 771 // This test passes if we don't crash. The results don't matter. |
772 const char* const test_cases[] = { | 772 const char* const test_cases[] = { |
773 "//c", | 773 "//c", |
774 "\\@st", | 774 "\\@st", |
775 "view-source:x", | 775 "view-source:x", |
776 }; | 776 }; |
777 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 777 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
778 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), base::string16::npos, | 778 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), base::string16::npos, |
779 base::string16(), GURL(), | 779 base::string16(), GURL(), |
780 AutocompleteInput::INVALID_SPEC, | 780 metrics::OmniboxEventProto::INVALID_SPEC, |
781 false, false, true, true); | 781 false, false, true, true); |
782 autocomplete_->Start(input, false); | 782 autocomplete_->Start(input, false); |
783 if (!autocomplete_->done()) | 783 if (!autocomplete_->done()) |
784 base::MessageLoop::current()->Run(); | 784 base::MessageLoop::current()->Run(); |
785 } | 785 } |
786 } | 786 } |
787 | 787 |
788 TEST_F(HistoryURLProviderTest, CullSearchResults) { | 788 TEST_F(HistoryURLProviderTest, CullSearchResults) { |
789 // Set up a default search engine. | 789 // Set up a default search engine. |
790 TemplateURLData data; | 790 TemplateURLData data; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 "mailto://a@b.com", {0, npos, npos}, 0 }, | 888 "mailto://a@b.com", {0, npos, npos}, 0 }, |
889 }; | 889 }; |
890 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 890 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
891 SCOPED_TRACE(testing::Message() << "Index " << i << " input: " | 891 SCOPED_TRACE(testing::Message() << "Index " << i << " input: " |
892 << test_cases[i].input << ", trim_http: " | 892 << test_cases[i].input << ", trim_http: " |
893 << test_cases[i].trim_http); | 893 << test_cases[i].trim_http); |
894 | 894 |
895 AutocompleteInput input(ASCIIToUTF16(test_cases[i].input), | 895 AutocompleteInput input(ASCIIToUTF16(test_cases[i].input), |
896 base::string16::npos, base::string16(), | 896 base::string16::npos, base::string16(), |
897 GURL("about:blank"), | 897 GURL("about:blank"), |
898 AutocompleteInput::INVALID_SPEC, false, false, true, | 898 metrics::OmniboxEventProto::INVALID_SPEC, false, |
899 true); | 899 false, true, true); |
900 AutocompleteMatch match(autocomplete_->SuggestExactInput( | 900 AutocompleteMatch match(autocomplete_->SuggestExactInput( |
901 input.text(), input.canonicalized_url(), test_cases[i].trim_http)); | 901 input.text(), input.canonicalized_url(), test_cases[i].trim_http)); |
902 EXPECT_EQ(ASCIIToUTF16(test_cases[i].contents), match.contents); | 902 EXPECT_EQ(ASCIIToUTF16(test_cases[i].contents), match.contents); |
903 for (size_t match_index = 0; match_index < match.contents_class.size(); | 903 for (size_t match_index = 0; match_index < match.contents_class.size(); |
904 ++match_index) { | 904 ++match_index) { |
905 EXPECT_EQ(test_cases[i].offsets[match_index], | 905 EXPECT_EQ(test_cases[i].offsets[match_index], |
906 match.contents_class[match_index].offset); | 906 match.contents_class[match_index].offset); |
907 EXPECT_EQ(ACMatchClassification::URL | | 907 EXPECT_EQ(ACMatchClassification::URL | |
908 (match_index == test_cases[i].match_classification_index ? | 908 (match_index == test_cases[i].match_classification_index ? |
909 ACMatchClassification::MATCH : 0), | 909 ACMatchClassification::MATCH : 0), |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 autocomplete_->scoring_params_.experimental_scoring_enabled = true; | 1011 autocomplete_->scoring_params_.experimental_scoring_enabled = true; |
1012 ASSERT_NO_FATAL_FAILURE( | 1012 ASSERT_NO_FATAL_FAILURE( |
1013 RunTest(ASCIIToUTF16(test_cases[i].input), | 1013 RunTest(ASCIIToUTF16(test_cases[i].input), |
1014 base::string16(), false, output, max_matches)); | 1014 base::string16(), false, output, max_matches)); |
1015 for (int j = 0; j < max_matches; ++j) { | 1015 for (int j = 0; j < max_matches; ++j) { |
1016 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, | 1016 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, |
1017 matches_[j].relevance); | 1017 matches_[j].relevance); |
1018 } | 1018 } |
1019 } | 1019 } |
1020 } | 1020 } |
OLD | NEW |