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

Side by Side Diff: components/omnibox/browser/history_url_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 (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 "components/omnibox/browser/history_url_provider.h" 5 #include "components/omnibox/browser/history_url_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 false, history::SOURCE_BROWSED); 314 false, history::SOURCE_BROWSED);
315 } 315 }
316 316
317 void HistoryURLProviderTest::RunTest( 317 void HistoryURLProviderTest::RunTest(
318 const base::string16& text, 318 const base::string16& text,
319 const std::string& desired_tld, 319 const std::string& desired_tld,
320 bool prevent_inline_autocomplete, 320 bool prevent_inline_autocomplete,
321 const UrlAndLegalDefault* expected_urls, 321 const UrlAndLegalDefault* expected_urls,
322 size_t num_results, 322 size_t num_results,
323 metrics::OmniboxInputType::Type* identified_input_type) { 323 metrics::OmniboxInputType::Type* identified_input_type) {
324 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(), 324 AutocompleteInput input(
325 metrics::OmniboxEventProto::INVALID_SPEC, 325 text, base::string16::npos, desired_tld, GURL(), base::string16(),
326 prevent_inline_autocomplete, false, true, true, false, 326 metrics::OmniboxEventProto::INVALID_SPEC, prevent_inline_autocomplete,
327 TestSchemeClassifier()); 327 false, true, true, false, TestSchemeClassifier());
328 *identified_input_type = input.type(); 328 *identified_input_type = input.type();
329 autocomplete_->Start(input, false); 329 autocomplete_->Start(input, false);
330 if (!autocomplete_->done()) 330 if (!autocomplete_->done())
331 base::RunLoop().Run(); 331 base::RunLoop().Run();
332 332
333 matches_ = autocomplete_->matches(); 333 matches_ = autocomplete_->matches();
334 if (sort_matches_) { 334 if (sort_matches_) {
335 TemplateURLService* service = client_->GetTemplateURLService(); 335 TemplateURLService* service = client_->GetTemplateURLService();
336 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { 336 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) {
337 i->ComputeStrippedDestinationURL(input, service); 337 i->ComputeStrippedDestinationURL(input, service);
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 arraysize(fixup_5)); 643 arraysize(fixup_5));
644 } 644 }
645 645
646 // Make sure the results for the input 'p' don't change between the first and 646 // Make sure the results for the input 'p' don't change between the first and
647 // second passes. 647 // second passes.
648 TEST_F(HistoryURLProviderTest, EmptyVisits) { 648 TEST_F(HistoryURLProviderTest, EmptyVisits) {
649 // Wait for history to create the in memory DB. 649 // Wait for history to create the in memory DB.
650 history::BlockUntilHistoryProcessesPendingRequests( 650 history::BlockUntilHistoryProcessesPendingRequests(
651 client_->GetHistoryService()); 651 client_->GetHistoryService());
652 652
653 AutocompleteInput input( 653 AutocompleteInput input(ASCIIToUTF16("pa"), base::string16::npos,
654 ASCIIToUTF16("pa"), base::string16::npos, std::string(), GURL(), 654 std::string(), GURL(), base::string16(),
655 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, 655 metrics::OmniboxEventProto::INVALID_SPEC, false,
656 TestSchemeClassifier()); 656 false, true, true, false, TestSchemeClassifier());
657 autocomplete_->Start(input, false); 657 autocomplete_->Start(input, false);
658 // HistoryURLProvider shouldn't be done (waiting on async results). 658 // HistoryURLProvider shouldn't be done (waiting on async results).
659 EXPECT_FALSE(autocomplete_->done()); 659 EXPECT_FALSE(autocomplete_->done());
660 660
661 // We should get back an entry for pandora. 661 // We should get back an entry for pandora.
662 matches_ = autocomplete_->matches(); 662 matches_ = autocomplete_->matches();
663 ASSERT_GT(matches_.size(), 0u); 663 ASSERT_GT(matches_.size(), 0u);
664 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); 664 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url);
665 int pandora_relevance = matches_[0].relevance; 665 int pandora_relevance = matches_[0].relevance;
666 666
(...skipping 18 matching lines...) Expand all
685 UrlAndLegalDefault navigation_2[] = { 685 UrlAndLegalDefault navigation_2[] = {
686 { "http://slash/", false } 686 { "http://slash/", false }
687 }; 687 };
688 RunTest(ASCIIToUTF16("slash"), std::string(), false, navigation_2, 688 RunTest(ASCIIToUTF16("slash"), std::string(), false, navigation_2,
689 arraysize(navigation_2)); 689 arraysize(navigation_2));
690 690
691 RunTest(ASCIIToUTF16("this is a query"), std::string(), false, NULL, 0); 691 RunTest(ASCIIToUTF16("this is a query"), std::string(), false, NULL, 0);
692 } 692 }
693 693
694 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { 694 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) {
695 AutocompleteInput input( 695 AutocompleteInput input(ASCIIToUTF16("slash "), base::string16::npos,
696 ASCIIToUTF16("slash "), base::string16::npos, std::string(), GURL(), 696 std::string(), GURL(), base::string16(),
697 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, 697 metrics::OmniboxEventProto::INVALID_SPEC, false,
698 TestSchemeClassifier()); 698 false, true, true, false, TestSchemeClassifier());
699 autocomplete_->Start(input, false); 699 autocomplete_->Start(input, false);
700 if (!autocomplete_->done()) 700 if (!autocomplete_->done())
701 base::RunLoop().Run(); 701 base::RunLoop().Run();
702 702
703 // None of the matches should attempt to autocomplete. 703 // None of the matches should attempt to autocomplete.
704 matches_ = autocomplete_->matches(); 704 matches_ = autocomplete_->matches();
705 for (size_t i = 0; i < matches_.size(); ++i) { 705 for (size_t i = 0; i < matches_.size(); ++i) {
706 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); 706 EXPECT_TRUE(matches_[i].inline_autocompletion.empty());
707 EXPECT_FALSE(matches_[i].allowed_to_be_default_match); 707 EXPECT_FALSE(matches_[i].allowed_to_be_default_match);
708 } 708 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 } 824 }
825 825
826 TEST_F(HistoryURLProviderTest, CrashDueToFixup) { 826 TEST_F(HistoryURLProviderTest, CrashDueToFixup) {
827 // This test passes if we don't crash. The results don't matter. 827 // This test passes if we don't crash. The results don't matter.
828 const char* const test_cases[] = { 828 const char* const test_cases[] = {
829 "//c", 829 "//c",
830 "\\@st", 830 "\\@st",
831 "view-source:x", 831 "view-source:x",
832 }; 832 };
833 for (size_t i = 0; i < arraysize(test_cases); ++i) { 833 for (size_t i = 0; i < arraysize(test_cases); ++i) {
834 AutocompleteInput input( 834 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), base::string16::npos,
835 ASCIIToUTF16(test_cases[i]), base::string16::npos, std::string(), 835 std::string(), GURL(), base::string16(),
836 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, 836 metrics::OmniboxEventProto::INVALID_SPEC, false,
837 true, false, TestSchemeClassifier()); 837 false, true, true, false, TestSchemeClassifier());
838 autocomplete_->Start(input, false); 838 autocomplete_->Start(input, false);
839 if (!autocomplete_->done()) 839 if (!autocomplete_->done())
840 base::RunLoop().Run(); 840 base::RunLoop().Run();
841 } 841 }
842 } 842 }
843 843
844 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) { 844 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) {
845 AutocompleteInput input( 845 AutocompleteInput input(ASCIIToUTF16("foo"), base::string16::npos,
846 ASCIIToUTF16("foo"), base::string16::npos, std::string(), GURL(), 846 std::string(), GURL(), base::string16(),
847 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, 847 metrics::OmniboxEventProto::INVALID_SPEC, false,
848 TestSchemeClassifier()); 848 false, true, true, true, TestSchemeClassifier());
849 autocomplete_->Start(input, false); 849 autocomplete_->Start(input, false);
850 EXPECT_TRUE(autocomplete_->matches().empty()); 850 EXPECT_TRUE(autocomplete_->matches().empty());
851 } 851 }
852 852
853 TEST_F(HistoryURLProviderTest, DoesNotInlinePunycodeMatches) { 853 TEST_F(HistoryURLProviderTest, DoesNotInlinePunycodeMatches) {
854 // A URL that matches due to a match in the punycode URL is allowed to be the 854 // A URL that matches due to a match in the punycode URL is allowed to be the
855 // default match if the URL doesn't get rendered as international characters. 855 // default match if the URL doesn't get rendered as international characters.
856 const UrlAndLegalDefault expected1_true[] = { 856 const UrlAndLegalDefault expected1_true[] = {
857 { "http://puny.xn--h2by8byc123p.in/", true }, 857 { "http://puny.xn--h2by8byc123p.in/", true },
858 }; 858 };
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 { "mailto://a@b.com", true, 1001 { "mailto://a@b.com", true,
1002 "mailto://a@b.com", {0, npos, npos}, 0 }, 1002 "mailto://a@b.com", {0, npos, npos}, 0 },
1003 { "mailto://a@b.com", false, 1003 { "mailto://a@b.com", false,
1004 "mailto://a@b.com", {0, npos, npos}, 0 }, 1004 "mailto://a@b.com", {0, npos, npos}, 0 },
1005 }; 1005 };
1006 for (size_t i = 0; i < arraysize(test_cases); ++i) { 1006 for (size_t i = 0; i < arraysize(test_cases); ++i) {
1007 SCOPED_TRACE(testing::Message() << "Index " << i << " input: " 1007 SCOPED_TRACE(testing::Message() << "Index " << i << " input: "
1008 << test_cases[i].input << ", trim_http: " 1008 << test_cases[i].input << ", trim_http: "
1009 << test_cases[i].trim_http); 1009 << test_cases[i].trim_http);
1010 1010
1011 AutocompleteInput input( 1011 AutocompleteInput input(ASCIIToUTF16(test_cases[i].input),
1012 ASCIIToUTF16(test_cases[i].input), base::string16::npos, std::string(), 1012 base::string16::npos, std::string(),
1013 GURL("about:blank"), metrics::OmniboxEventProto::INVALID_SPEC, false, 1013 GURL("about:blank"), base::string16(),
1014 false, true, true, false, 1014 metrics::OmniboxEventProto::INVALID_SPEC, false,
1015 TestSchemeClassifier()); 1015 false, true, true, false, TestSchemeClassifier());
1016 AutocompleteMatch match(autocomplete_->SuggestExactInput( 1016 AutocompleteMatch match(autocomplete_->SuggestExactInput(
1017 input, input.canonicalized_url(), test_cases[i].trim_http)); 1017 input, input.canonicalized_url(), test_cases[i].trim_http));
1018 EXPECT_EQ(ASCIIToUTF16(test_cases[i].contents), match.contents); 1018 EXPECT_EQ(ASCIIToUTF16(test_cases[i].contents), match.contents);
1019 for (size_t match_index = 0; match_index < match.contents_class.size(); 1019 for (size_t match_index = 0; match_index < match.contents_class.size();
1020 ++match_index) { 1020 ++match_index) {
1021 EXPECT_EQ(test_cases[i].offsets[match_index], 1021 EXPECT_EQ(test_cases[i].offsets[match_index],
1022 match.contents_class[match_index].offset); 1022 match.contents_class[match_index].offset);
1023 EXPECT_EQ(ACMatchClassification::URL | 1023 EXPECT_EQ(ACMatchClassification::URL |
1024 (match_index == test_cases[i].match_classification_index ? 1024 (match_index == test_cases[i].match_classification_index ?
1025 ACMatchClassification::MATCH : 0), 1025 ACMatchClassification::MATCH : 0),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 // the default experimental scoring. 1118 // the default experimental scoring.
1119 autocomplete_->scoring_params_.experimental_scoring_enabled = true; 1119 autocomplete_->scoring_params_.experimental_scoring_enabled = true;
1120 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), 1120 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input),
1121 std::string(), false, output, max_matches)); 1121 std::string(), false, output, max_matches));
1122 for (int j = 0; j < max_matches; ++j) { 1122 for (int j = 0; j < max_matches; ++j) {
1123 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, 1123 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance,
1124 matches_[j].relevance); 1124 matches_[j].relevance);
1125 } 1125 }
1126 } 1126 }
1127 } 1127 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/history_quick_provider_unittest.cc ('k') | components/omnibox/browser/keyword_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698