| 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 size_t offset_for_adjustment; | |
| 119 const std::string expected_result; | 118 const std::string expected_result; |
| 120 size_t expected_adjusted_offset; | |
| 121 | 119 |
| 122 void Validate() { | 120 void Validate() { |
| 123 SCOPED_TRACE(testing::Message() | 121 SCOPED_TRACE(testing::Message() |
| 124 << " url= " << url << " trim_scheme=" << trim_scheme | 122 << " url= " << url << " trim_scheme=" << trim_scheme |
| 125 << " offset_for_adjustment=" << offset_for_adjustment | 123 << " expected_result=" << expected_result); |
| 126 << " expected_result=" << expected_result | 124 auto format_types = AutocompleteMatch::GetFormatTypes(trim_scheme); |
| 127 << " expected_adjusted_offset=" << expected_adjusted_offset); | 125 EXPECT_EQ(expected_result, |
| 128 | 126 base::UTF16ToASCII(url_formatter::FormatUrl( |
| 129 size_t offset_result = offset_for_adjustment; | 127 GURL(url), format_types, net::UnescapeRule::SPACES, nullptr, |
| 130 base::string16 result = AutocompleteMatch::FormatUrlForSuggestionDisplay( | 128 nullptr, nullptr))); |
| 131 GURL(url), trim_scheme, &offset_result); | |
| 132 | |
| 133 EXPECT_EQ(expected_result, base::UTF16ToASCII(result)); | |
| 134 EXPECT_EQ(expected_adjusted_offset, offset_result); | |
| 135 }; | 129 }; |
| 136 }; | 130 }; |
| 137 | 131 |
| 132 // Sanity check that the trim_strings parameter works. |
| 138 FormatUrlTestData normal_cases[] = { | 133 FormatUrlTestData normal_cases[] = { |
| 139 {"http://google.com", true, 9, "google.com", 2}, | 134 {"http://google.com", true, "google.com"}, |
| 140 {"https://google.com", true, 9, "https://google.com", 9}, | 135 {"https://google.com", true, "https://google.com"}, |
| 141 {"http://google.com", false, 9, "http://google.com", 9}, | 136 {"http://google.com", false, "http://google.com"}, |
| 142 {"https://google.com", false, 9, "https://google.com", 9}, | 137 {"https://google.com", false, "https://google.com"}, |
| 143 }; | 138 }; |
| 144 for (size_t i = 0; i < arraysize(normal_cases); ++i) { | 139 for (FormatUrlTestData& test_case : normal_cases) |
| 145 normal_cases[i].Validate(); | 140 test_case.Validate(); |
| 146 } | |
| 147 | 141 |
| 142 // Test the hide-scheme feature flag. |
| 148 std::unique_ptr<base::test::ScopedFeatureList> feature_list( | 143 std::unique_ptr<base::test::ScopedFeatureList> feature_list( |
| 149 new base::test::ScopedFeatureList); | 144 new base::test::ScopedFeatureList); |
| 150 feature_list->InitAndEnableFeature( | 145 feature_list->InitAndEnableFeature( |
| 151 omnibox::kUIExperimentHideSuggestionUrlScheme); | 146 omnibox::kUIExperimentHideSuggestionUrlScheme); |
| 152 | 147 |
| 153 FormatUrlTestData omit_scheme_cases[] = { | 148 FormatUrlTestData omit_scheme_cases[] = { |
| 154 {"http://google.com", true, 9, "google.com", 2}, | 149 {"http://google.com", true, "google.com"}, |
| 155 {"https://google.com", true, 9, "google.com", 1}, | 150 {"https://google.com", true, "google.com"}, |
| 156 {"https://username:password@google.com", true, 9, "google.com", | 151 {"http://google.com", false, "http://google.com"}, |
| 157 base::string16::npos}, | 152 {"https://google.com", false, "https://google.com"}, |
| 158 {"https://username:password@google.com", true, 29, "google.com", 3}, | |
| 159 {"http://google.com", false, 9, "http://google.com", 9}, | |
| 160 {"https://google.com", false, 9, "https://google.com", 9}, | |
| 161 {"http://username:password@google.com", false, 9, "http://google.com", | |
| 162 base::string16::npos}, | |
| 163 }; | 153 }; |
| 164 for (size_t i = 0; i < arraysize(omit_scheme_cases); ++i) { | 154 for (FormatUrlTestData& test_case : omit_scheme_cases) |
| 165 omit_scheme_cases[i].Validate(); | 155 test_case.Validate(); |
| 166 } | |
| 167 } | 156 } |
| 168 | 157 |
| 169 TEST(AutocompleteMatchTest, SupportsDeletion) { | 158 TEST(AutocompleteMatchTest, SupportsDeletion) { |
| 170 // A non-deletable match with no duplicates. | 159 // A non-deletable match with no duplicates. |
| 171 AutocompleteMatch m(NULL, 0, false, | 160 AutocompleteMatch m(NULL, 0, false, |
| 172 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 161 AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 173 EXPECT_FALSE(m.SupportsDeletion()); | 162 EXPECT_FALSE(m.SupportsDeletion()); |
| 174 | 163 |
| 175 // A deletable match with no duplicates. | 164 // A deletable match with no duplicates. |
| 176 AutocompleteMatch m1(NULL, 0, true, | 165 AutocompleteMatch m1(NULL, 0, true, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 m1.destination_url = GURL(cases[i].url1); | 241 m1.destination_url = GURL(cases[i].url1); |
| 253 m1.ComputeStrippedDestinationURL(input, nullptr); | 242 m1.ComputeStrippedDestinationURL(input, nullptr); |
| 254 AutocompleteMatch m2(nullptr, 100, false, | 243 AutocompleteMatch m2(nullptr, 100, false, |
| 255 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 244 AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 256 m2.destination_url = GURL(cases[i].url2); | 245 m2.destination_url = GURL(cases[i].url2); |
| 257 m2.ComputeStrippedDestinationURL(input, nullptr); | 246 m2.ComputeStrippedDestinationURL(input, nullptr); |
| 258 EXPECT_EQ(cases[i].expected_duplicate, | 247 EXPECT_EQ(cases[i].expected_duplicate, |
| 259 AutocompleteMatch::DestinationsEqual(m1, m2)); | 248 AutocompleteMatch::DestinationsEqual(m1, m2)); |
| 260 } | 249 } |
| 261 } | 250 } |
| OLD | NEW |