Chromium Code Reviews| 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 "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 | 10 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 {"http://intra/three", "Intranet three", 2, 2, 80}, | 135 {"http://intra/three", "Intranet three", 2, 2, 80}, |
| 136 {"http://moo/bar", "Intranet moo", 1, 1, 80}, | 136 {"http://moo/bar", "Intranet moo", 1, 1, 80}, |
| 137 {"http://typedhost/typedpath", "Intranet typed", 1, 1, 80}, | 137 {"http://typedhost/typedpath", "Intranet typed", 1, 1, 80}, |
| 138 {"http://typedhost/untypedpath", "Intranet untyped", 1, 0, 80}, | 138 {"http://typedhost/untypedpath", "Intranet untyped", 1, 0, 80}, |
| 139 | 139 |
| 140 {"http://x.com/one", "Internet", 2, 2, 80}, | 140 {"http://x.com/one", "Internet", 2, 2, 80}, |
| 141 {"http://x.com/two", "Internet two", 1, 1, 80}, | 141 {"http://x.com/two", "Internet two", 1, 1, 80}, |
| 142 {"http://x.com/three", "Internet three", 2, 2, 80}, | 142 {"http://x.com/three", "Internet three", 2, 2, 80}, |
| 143 | 143 |
| 144 // For punycode tests. | 144 // For punycode tests. |
| 145 {"http://puny.xn--1lq90ic7f1rc.cn/", "Punycode", 2, 2, 5 }, | 145 {"http://puny.xn--h2by8byc123p.in/", "Punycode", 2, 2, 5 }, |
| 146 {"http://two_puny.xn--1lq90ic7f1rc.cn/", | |
| 147 "Punycode to be rendered in Unicode", 2, 2, 5 }, | |
| 146 | 148 |
| 147 // For experimental HUP scoring test. | 149 // For experimental HUP scoring test. |
| 148 {"http://7.com/1a", "One", 8, 4, 4}, | 150 {"http://7.com/1a", "One", 8, 4, 4}, |
| 149 {"http://7.com/2a", "Two A", 4, 2, 8}, | 151 {"http://7.com/2a", "Two A", 4, 2, 8}, |
| 150 {"http://7.com/2b", "Two B", 4, 1, 8}, | 152 {"http://7.com/2b", "Two B", 4, 1, 8}, |
| 151 {"http://7.com/3a", "Three", 2, 1, 16}, | 153 {"http://7.com/3a", "Three", 2, 1, 16}, |
| 152 {"http://7.com/4a", "Four A", 1, 1, 32}, | 154 {"http://7.com/4a", "Four A", 1, 1, 32}, |
| 153 {"http://7.com/4b", "Four B", 1, 1, 64}, | 155 {"http://7.com/4b", "Four B", 1, 1, 64}, |
| 154 {"http://7.com/5a", "Five A", 8, 0, 64}, // never typed. | 156 {"http://7.com/5a", "Five A", 8, 0, 64}, // never typed. |
| 155 }; | 157 }; |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) { | 846 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) { |
| 845 AutocompleteInput input( | 847 AutocompleteInput input( |
| 846 ASCIIToUTF16("foo"), base::string16::npos, std::string(), GURL(), | 848 ASCIIToUTF16("foo"), base::string16::npos, std::string(), GURL(), |
| 847 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, | 849 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, |
| 848 TestSchemeClassifier()); | 850 TestSchemeClassifier()); |
| 849 autocomplete_->Start(input, false); | 851 autocomplete_->Start(input, false); |
| 850 EXPECT_TRUE(autocomplete_->matches().empty()); | 852 EXPECT_TRUE(autocomplete_->matches().empty()); |
| 851 } | 853 } |
| 852 | 854 |
| 853 TEST_F(HistoryURLProviderTest, DoesNotInlinePunycodeMatches) { | 855 TEST_F(HistoryURLProviderTest, DoesNotInlinePunycodeMatches) { |
| 854 // A URL that matches due to a match in the punycode URL are allowed to be the | 856 // A URL that matches due to a match in the punycode URL are allowed to be the |
|
Peter Kasting
2016/03/17 06:01:24
Nit: are -> is
jungshik at Google
2016/03/17 07:43:25
Done.
| |
| 855 // default match if the URL doesn't get rendered as international characters | 857 // default match if the URL doesn't get rendered as international characters. |
| 856 // in the given locale. | 858 const UrlAndLegalDefault expected1_true[] = { |
| 857 const UrlAndLegalDefault expected_true[] = { | 859 { "http://puny.xn--h2by8byc123p.in/", true }, |
| 858 { "http://puny.xn--1lq90ic7f1rc.cn/", true }, | |
| 859 }; | 860 }; |
| 860 UrlAndLegalDefault expected_false[] = { | 861 RunTest(ASCIIToUTF16("pun"), std::string(), false, expected1_true, |
| 861 { "http://puny.xn--1lq90ic7f1rc.cn/", false }, | 862 arraysize(expected1_true)); |
| 863 RunTest(ASCIIToUTF16("puny."), std::string(), false, expected1_true, | |
| 864 arraysize(expected1_true)); | |
| 865 RunTest(ASCIIToUTF16("puny.x"), std::string(), false, expected1_true, | |
| 866 arraysize(expected1_true)); | |
| 867 RunTest(ASCIIToUTF16("puny.xn"), std::string(), false, expected1_true, | |
| 868 arraysize(expected1_true)); | |
| 869 RunTest(ASCIIToUTF16("puny.xn--"), std::string(), false, expected1_true, | |
| 870 arraysize(expected1_true)); | |
| 871 RunTest(ASCIIToUTF16("puny.xn--h2"), std::string(), false, expected1_true, | |
| 872 arraysize(expected1_true)); | |
| 873 RunTest(ASCIIToUTF16("puny.xn--h2by8byc123p"), std::string(), false, | |
| 874 expected1_true, arraysize(expected1_true)); | |
| 875 RunTest(ASCIIToUTF16("puny.xn--h2by8byc123p."), std::string(), false, | |
| 876 expected1_true, arraysize(expected1_true)); | |
| 877 | |
| 878 // When the punycode part of the URL is rendered as international characters, | |
| 879 // this match should not be allowed to be the default match if the inline | |
| 880 // autocomplete text starts in the middle of the international characters. | |
| 881 const UrlAndLegalDefault expected2_true[] = { | |
| 882 { "http://two_puny.xn--1lq90ic7f1rc.cn/", true }, | |
| 862 }; | 883 }; |
| 863 RunTest(ASCIIToUTF16("pun"), std::string(), false, expected_true, | 884 const UrlAndLegalDefault expected2_false[] = { |
| 864 arraysize(expected_true)); | 885 { "http://two_puny.xn--1lq90ic7f1rc.cn/", false }, |
| 865 RunTest(ASCIIToUTF16("puny."), std::string(), false, expected_true, | 886 }; |
| 866 arraysize(expected_true)); | 887 RunTest(ASCIIToUTF16("two"), std::string(), false, expected2_true, |
| 867 RunTest(ASCIIToUTF16("puny.x"), std::string(), false, expected_true, | 888 arraysize(expected2_true)); |
| 868 arraysize(expected_true)); | 889 RunTest(ASCIIToUTF16("two_puny."), std::string(), false, expected2_true, |
| 869 RunTest(ASCIIToUTF16("puny.xn"), std::string(), false, expected_true, | 890 arraysize(expected2_true)); |
| 870 arraysize(expected_true)); | 891 RunTest(ASCIIToUTF16("two_puny.x"), std::string(), false, expected2_false, |
| 871 RunTest(ASCIIToUTF16("puny.xn--"), std::string(), false, expected_true, | 892 arraysize(expected2_false)); |
| 872 arraysize(expected_true)); | 893 RunTest(ASCIIToUTF16("two_puny.xn"), std::string(), false, expected2_false, |
| 873 RunTest(ASCIIToUTF16("puny.xn--1l"), std::string(), false, expected_true, | 894 arraysize(expected2_false)); |
| 874 arraysize(expected_true)); | 895 RunTest(ASCIIToUTF16("two_puny.xn--"), std::string(), false, expected2_false, |
| 875 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc"), std::string(), false, | 896 arraysize(expected2_false)); |
| 876 expected_true, arraysize(expected_true)); | 897 RunTest(ASCIIToUTF16("two_puny.xn--1l"), std::string(), false, |
| 877 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc."), std::string(), false, | 898 expected2_false, arraysize(expected2_false)); |
| 878 expected_true, arraysize(expected_true)); | 899 RunTest(ASCIIToUTF16("two_puny.xn--1lq90ic7f1rc"), std::string(), false, |
| 879 // Set the language so the punycode part of the URL is rendered as | 900 expected2_true, arraysize(expected2_true)); |
| 880 // international characters. Then this match should not be allowed to be | 901 RunTest(ASCIIToUTF16("two_puny.xn--1lq90ic7f1rc."), std::string(), false, |
| 881 // the default match if the inline autocomplete text starts in the middle | 902 expected2_true, arraysize(expected2_true)); |
| 882 // of the international characters. | |
| 883 EXPECT_CALL(*client_, GetAcceptLanguages()) | |
| 884 .WillRepeatedly(testing::Return("zh-CN")); | |
| 885 RunTest(ASCIIToUTF16("pun"), std::string(), false, expected_true, | |
| 886 arraysize(expected_true)); | |
| 887 RunTest(ASCIIToUTF16("puny."), std::string(), false, expected_true, | |
| 888 arraysize(expected_true)); | |
| 889 RunTest(ASCIIToUTF16("puny.x"), std::string(), false, expected_false, | |
| 890 arraysize(expected_false)); | |
| 891 RunTest(ASCIIToUTF16("puny.xn"), std::string(), false, expected_false, | |
| 892 arraysize(expected_false)); | |
| 893 RunTest(ASCIIToUTF16("puny.xn--"), std::string(), false, expected_false, | |
| 894 arraysize(expected_false)); | |
| 895 RunTest(ASCIIToUTF16("puny.xn--1l"), std::string(), false, expected_false, | |
| 896 arraysize(expected_false)); | |
| 897 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc"), std::string(), false, | |
| 898 expected_true, arraysize(expected_true)); | |
| 899 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc."), std::string(), false, | |
| 900 expected_true, arraysize(expected_true)); | |
| 901 } | 903 } |
| 902 | 904 |
| 903 TEST_F(HistoryURLProviderTest, CullSearchResults) { | 905 TEST_F(HistoryURLProviderTest, CullSearchResults) { |
| 904 // Set up a default search engine. | 906 // Set up a default search engine. |
| 905 TemplateURLData data; | 907 TemplateURLData data; |
| 906 data.SetShortName(ASCIIToUTF16("TestEngine")); | 908 data.SetShortName(ASCIIToUTF16("TestEngine")); |
| 907 data.SetKeyword(ASCIIToUTF16("TestEngine")); | 909 data.SetKeyword(ASCIIToUTF16("TestEngine")); |
| 908 data.SetURL("http://testsearch.com/?q={searchTerms}"); | 910 data.SetURL("http://testsearch.com/?q={searchTerms}"); |
| 909 TemplateURLService* template_url_service = client_->GetTemplateURLService(); | 911 TemplateURLService* template_url_service = client_->GetTemplateURLService(); |
| 910 TemplateURL* template_url = new TemplateURL(data); | 912 TemplateURL* template_url = new TemplateURL(data); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1118 // the default experimental scoring. | 1120 // the default experimental scoring. |
| 1119 autocomplete_->scoring_params_.experimental_scoring_enabled = true; | 1121 autocomplete_->scoring_params_.experimental_scoring_enabled = true; |
| 1120 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), | 1122 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), |
| 1121 std::string(), false, output, max_matches)); | 1123 std::string(), false, output, max_matches)); |
| 1122 for (int j = 0; j < max_matches; ++j) { | 1124 for (int j = 0; j < max_matches; ++j) { |
| 1123 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, | 1125 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, |
| 1124 matches_[j].relevance); | 1126 matches_[j].relevance); |
| 1125 } | 1127 } |
| 1126 } | 1128 } |
| 1127 } | 1129 } |
| OLD | NEW |