Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/autocomplete_match.h" | 5 #include "components/omnibox/browser/autocomplete_match.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 // Test an arbitrary complicated case. | 104 // Test an arbitrary complicated case. |
| 105 EXPECT_EQ("0,2," "1,0," "2,1," "4,3," "5,7," "6,3," "7,7," "15,1," "17,0", | 105 EXPECT_EQ("0,2," "1,0," "2,1," "4,3," "5,7," "6,3," "7,7," "15,1," "17,0", |
| 106 AutocompleteMatch::ClassificationsToString( | 106 AutocompleteMatch::ClassificationsToString( |
| 107 AutocompleteMatch::MergeClassifications( | 107 AutocompleteMatch::MergeClassifications( |
| 108 AutocompleteMatch::ClassificationsFromString( | 108 AutocompleteMatch::ClassificationsFromString( |
| 109 "0,0," "2,1," "4,3," "7,7," "10,6," "15,0"), | 109 "0,0," "2,1," "4,3," "7,7," "10,6," "15,0"), |
| 110 AutocompleteMatch::ClassificationsFromString( | 110 AutocompleteMatch::ClassificationsFromString( |
| 111 "0,2," "1,0," "5,7," "6,1," "17,0")))); | 111 "0,2," "1,0," "5,7," "6,1," "17,0")))); |
| 112 } | 112 } |
| 113 | 113 |
| 114 TEST(AutocompleteMatchTest, FormatUrlForSuggestionDisplay) { | 114 TEST(AutocompleteMatchTest, FormatUrlForSuggestionDisplay) { |
|
Peter Kasting
2017/07/06 06:01:21
Nit: Might want a comment somewhere in this functi
tommycli
2017/07/06 16:25:46
Done.
| |
| 115 struct FormatUrlTestData { | 115 struct FormatUrlTestData { |
| 116 const std::string url; | 116 const std::string url; |
| 117 bool trim_scheme; | 117 bool trim_scheme; |
| 118 const std::string expected_result; | 118 const std::string expected_result; |
| 119 | 119 |
| 120 void Validate() { | 120 void Validate() { |
| 121 SCOPED_TRACE(testing::Message() | 121 SCOPED_TRACE(testing::Message() |
| 122 << " url= " << url << " trim_scheme=" << trim_scheme | 122 << " url= " << url << " trim_scheme=" << trim_scheme |
| 123 << " expected_result=" << expected_result); | 123 << " expected_result=" << expected_result); |
| 124 auto format_types = AutocompleteMatch::GetFormatTypes(trim_scheme); | 124 auto format_types = AutocompleteMatch::GetFormatTypes(trim_scheme); |
| 125 EXPECT_EQ(expected_result, | 125 EXPECT_EQ(expected_result, |
| 126 base::UTF16ToASCII(url_formatter::FormatUrl( | 126 base::UTF16ToASCII(url_formatter::FormatUrl( |
| 127 GURL(url), format_types, net::UnescapeRule::SPACES, nullptr, | 127 GURL(url), format_types, net::UnescapeRule::SPACES, nullptr, |
| 128 nullptr, nullptr))); | 128 nullptr, nullptr))); |
| 129 }; | 129 }; |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 // Sanity check that the trim_strings parameter works. | |
| 133 FormatUrlTestData normal_cases[] = { | 132 FormatUrlTestData normal_cases[] = { |
| 133 // Test trim_scheme parameter without any feature flags. | |
| 134 {"http://google.com", true, "google.com"}, | 134 {"http://google.com", true, "google.com"}, |
| 135 {"https://google.com", true, "https://google.com"}, | 135 {"https://google.com", true, "https://google.com"}, |
| 136 {"http://google.com", false, "http://google.com"}, | 136 {"http://google.com", false, "http://google.com"}, |
| 137 {"https://google.com", false, "https://google.com"}, | 137 {"https://google.com", false, "https://google.com"}, |
| 138 }; | 138 |
| 139 // Verify that trivial subdomains are preserved in the normal case. | |
| 140 {"http://www.google.com", false, "http://www.google.com"}}; | |
| 139 for (FormatUrlTestData& test_case : normal_cases) | 141 for (FormatUrlTestData& test_case : normal_cases) |
| 140 test_case.Validate(); | 142 test_case.Validate(); |
| 141 | 143 |
| 142 // Test the hide-scheme feature flag. | 144 // Test the hide-scheme feature flag with the trim_scheme paramater. |
| 143 std::unique_ptr<base::test::ScopedFeatureList> feature_list( | 145 std::unique_ptr<base::test::ScopedFeatureList> feature_list( |
| 144 new base::test::ScopedFeatureList); | 146 new base::test::ScopedFeatureList); |
| 145 feature_list->InitAndEnableFeature( | 147 feature_list->InitAndEnableFeature( |
| 146 omnibox::kUIExperimentHideSuggestionUrlScheme); | 148 omnibox::kUIExperimentHideSuggestionUrlScheme); |
| 147 | 149 |
| 148 FormatUrlTestData omit_scheme_cases[] = { | 150 FormatUrlTestData omit_scheme_cases[] = { |
| 149 {"http://google.com", true, "google.com"}, | 151 {"http://google.com", true, "google.com"}, |
| 150 {"https://google.com", true, "google.com"}, | 152 {"https://google.com", true, "google.com"}, |
| 151 {"http://google.com", false, "http://google.com"}, | 153 {"http://google.com", false, "http://google.com"}, |
| 152 {"https://google.com", false, "https://google.com"}, | 154 {"https://google.com", false, "https://google.com"}, |
| 153 }; | 155 }; |
| 154 for (FormatUrlTestData& test_case : omit_scheme_cases) | 156 for (FormatUrlTestData& test_case : omit_scheme_cases) |
| 155 test_case.Validate(); | 157 test_case.Validate(); |
| 158 | |
| 159 // Test the trim trivial subdomains feature flag. | |
| 160 feature_list.reset(new base::test::ScopedFeatureList); | |
| 161 feature_list->InitAndEnableFeature( | |
| 162 omnibox::kUIExperimentHideSuggestionUrlTrivialSubdomains); | |
| 163 | |
| 164 FormatUrlTestData trim_trivial_subdomains_case = {"http://www.m.google.com", | |
| 165 false, "http://google.com"}; | |
| 166 trim_trivial_subdomains_case.Validate(); | |
| 156 } | 167 } |
| 157 | 168 |
| 158 TEST(AutocompleteMatchTest, SupportsDeletion) { | 169 TEST(AutocompleteMatchTest, SupportsDeletion) { |
| 159 // A non-deletable match with no duplicates. | 170 // A non-deletable match with no duplicates. |
| 160 AutocompleteMatch m(NULL, 0, false, | 171 AutocompleteMatch m(NULL, 0, false, |
| 161 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 172 AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 162 EXPECT_FALSE(m.SupportsDeletion()); | 173 EXPECT_FALSE(m.SupportsDeletion()); |
| 163 | 174 |
| 164 // A deletable match with no duplicates. | 175 // A deletable match with no duplicates. |
| 165 AutocompleteMatch m1(NULL, 0, true, | 176 AutocompleteMatch m1(NULL, 0, true, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 m1.destination_url = GURL(cases[i].url1); | 252 m1.destination_url = GURL(cases[i].url1); |
| 242 m1.ComputeStrippedDestinationURL(input, nullptr); | 253 m1.ComputeStrippedDestinationURL(input, nullptr); |
| 243 AutocompleteMatch m2(nullptr, 100, false, | 254 AutocompleteMatch m2(nullptr, 100, false, |
| 244 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 255 AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 245 m2.destination_url = GURL(cases[i].url2); | 256 m2.destination_url = GURL(cases[i].url2); |
| 246 m2.ComputeStrippedDestinationURL(input, nullptr); | 257 m2.ComputeStrippedDestinationURL(input, nullptr); |
| 247 EXPECT_EQ(cases[i].expected_duplicate, | 258 EXPECT_EQ(cases[i].expected_duplicate, |
| 248 AutocompleteMatch::DestinationsEqual(m1, m2)); | 259 AutocompleteMatch::DestinationsEqual(m1, m2)); |
| 249 } | 260 } |
| 250 } | 261 } |
| OLD | NEW |