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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) { |
| 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 wchar_t* 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(base::WideToUTF16(expected_result), |
| 126 base::UTF16ToASCII(url_formatter::FormatUrl( | 126 url_formatter::FormatUrl(GURL(url), format_types, |
| 127 GURL(url), format_types, net::UnescapeRule::SPACES, nullptr, | 127 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[] = { |
| 134 {"http://google.com", true, "google.com"}, | 133 // Sanity check that the trim_scheme parameter works. |
| 135 {"https://google.com", true, "https://google.com"}, | 134 {"http://google.com", true, L"google.com"}, |
| 136 {"http://google.com", false, "http://google.com"}, | 135 {"https://google.com", true, L"https://google.com"}, |
| 137 {"https://google.com", false, "https://google.com"}, | 136 {"http://google.com", false, L"http://google.com"}, |
| 137 {"https://google.com", false, L"https://google.com"}, | |
| 138 | |
| 139 // Test that paths are preserved in the default case. | |
| 140 {"http://google.com/foobar", true, L"google.com/foobar"}, | |
| 138 }; | 141 }; |
| 139 for (FormatUrlTestData& test_case : normal_cases) | 142 for (FormatUrlTestData& test_case : normal_cases) |
| 140 test_case.Validate(); | 143 test_case.Validate(); |
| 141 | 144 |
| 142 // Test the hide-scheme feature flag. | 145 // Test the hide-scheme feature flag with the trim_scheme parameter. |
| 143 std::unique_ptr<base::test::ScopedFeatureList> feature_list( | 146 std::unique_ptr<base::test::ScopedFeatureList> feature_list( |
| 144 new base::test::ScopedFeatureList); | 147 new base::test::ScopedFeatureList); |
| 145 feature_list->InitAndEnableFeature( | 148 feature_list->InitAndEnableFeature( |
| 146 omnibox::kUIExperimentHideSuggestionUrlScheme); | 149 omnibox::kUIExperimentHideSuggestionUrlScheme); |
| 147 | 150 |
| 148 FormatUrlTestData omit_scheme_cases[] = { | 151 FormatUrlTestData omit_scheme_cases[] = { |
| 149 {"http://google.com", true, "google.com"}, | 152 {"http://google.com", true, L"google.com"}, |
| 150 {"https://google.com", true, "google.com"}, | 153 {"https://google.com", true, L"google.com"}, |
| 151 {"http://google.com", false, "http://google.com"}, | 154 {"http://google.com", false, L"http://google.com"}, |
| 152 {"https://google.com", false, "https://google.com"}, | 155 {"https://google.com", false, L"https://google.com"}, |
| 153 }; | 156 }; |
| 154 for (FormatUrlTestData& test_case : omit_scheme_cases) | 157 for (FormatUrlTestData& test_case : omit_scheme_cases) |
| 155 test_case.Validate(); | 158 test_case.Validate(); |
| 159 | |
| 160 // Test the elide-after-host feature flag. | |
| 161 feature_list.reset(new base::test::ScopedFeatureList); | |
| 162 feature_list->InitAndEnableFeature( | |
| 163 omnibox::kUIExperimentElideSuggestionUrlAfterHost); | |
| 164 FormatUrlTestData hide_path_case = {"http://google.com/foobar", true, | |
| 165 L"google.com/\x2026\x0000"}; | |
|
Mark P
2017/07/05 18:38:45
Care to test the case when we're not hiding the sc
tommycli
2017/07/05 19:38:26
Done.
| |
| 166 hide_path_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 |