| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { |
| 115 // This test does not need to verify url_formatter's functionality in-depth, |
| 116 // since url_formatter has its own unit tests. This test is to validate that |
| 117 // flipping feature flags and varying the trim_scheme parameter toggles the |
| 118 // correct behavior within AutocompleteMatch::GetFormatTypes. |
| 115 struct FormatUrlTestData { | 119 struct FormatUrlTestData { |
| 116 const std::string url; | 120 const std::string url; |
| 117 bool trim_scheme; | 121 bool trim_scheme; |
| 118 const wchar_t* expected_result; | 122 const wchar_t* expected_result; |
| 119 | 123 |
| 120 void Validate() { | 124 void Validate() { |
| 121 SCOPED_TRACE(testing::Message() | 125 SCOPED_TRACE(testing::Message() |
| 122 << " url= " << url << " trim_scheme=" << trim_scheme | 126 << " url= " << url << " trim_scheme=" << trim_scheme |
| 123 << " expected_result=" << expected_result); | 127 << " expected_result=" << expected_result); |
| 124 auto format_types = AutocompleteMatch::GetFormatTypes(trim_scheme); | 128 auto format_types = AutocompleteMatch::GetFormatTypes(trim_scheme); |
| 125 EXPECT_EQ(base::WideToUTF16(expected_result), | 129 EXPECT_EQ(base::WideToUTF16(expected_result), |
| 126 url_formatter::FormatUrl(GURL(url), format_types, | 130 url_formatter::FormatUrl(GURL(url), format_types, |
| 127 net::UnescapeRule::SPACES, nullptr, | 131 net::UnescapeRule::SPACES, nullptr, |
| 128 nullptr, nullptr)); | 132 nullptr, nullptr)); |
| 129 }; | 133 }; |
| 130 }; | 134 }; |
| 131 | 135 |
| 132 FormatUrlTestData normal_cases[] = { | 136 FormatUrlTestData normal_cases[] = { |
| 133 // Sanity check that the trim_scheme parameter works. | 137 // Test trim_scheme parameter without any feature flags. |
| 134 {"http://google.com", true, L"google.com"}, | 138 {"http://google.com", true, L"google.com"}, |
| 135 {"https://google.com", true, L"https://google.com"}, | 139 {"https://google.com", true, L"https://google.com"}, |
| 136 {"http://google.com", false, L"http://google.com"}, | 140 {"http://google.com", false, L"http://google.com"}, |
| 137 {"https://google.com", false, L"https://google.com"}, | 141 {"https://google.com", false, L"https://google.com"}, |
| 138 | 142 |
| 139 // Test that paths are preserved in the default case. | 143 // Test that paths are preserved in the default case. |
| 140 {"http://google.com/foobar", true, L"google.com/foobar"}, | 144 {"http://google.com/foobar", true, L"google.com/foobar"}, |
| 141 }; | 145 |
| 146 // Verify that trivial subdomains are preserved in the normal case. |
| 147 {"http://www.google.com", false, L"http://www.google.com"}}; |
| 142 for (FormatUrlTestData& test_case : normal_cases) | 148 for (FormatUrlTestData& test_case : normal_cases) |
| 143 test_case.Validate(); | 149 test_case.Validate(); |
| 144 | 150 |
| 145 // Test the hide-scheme feature flag with the trim_scheme parameter. | 151 // Test the hide-scheme feature flag with the trim_scheme parameter. |
| 146 std::unique_ptr<base::test::ScopedFeatureList> feature_list( | 152 std::unique_ptr<base::test::ScopedFeatureList> feature_list( |
| 147 new base::test::ScopedFeatureList); | 153 new base::test::ScopedFeatureList); |
| 148 feature_list->InitAndEnableFeature( | 154 feature_list->InitAndEnableFeature( |
| 149 omnibox::kUIExperimentHideSuggestionUrlScheme); | 155 omnibox::kUIExperimentHideSuggestionUrlScheme); |
| 150 | 156 |
| 151 FormatUrlTestData omit_scheme_cases[] = { | 157 FormatUrlTestData omit_scheme_cases[] = { |
| 152 {"http://google.com", true, L"google.com"}, | 158 {"http://google.com", true, L"google.com"}, |
| 153 {"https://google.com", true, L"google.com"}, | 159 {"https://google.com", true, L"google.com"}, |
| 154 {"http://google.com", false, L"http://google.com"}, | 160 {"http://google.com", false, L"http://google.com"}, |
| 155 {"https://google.com", false, L"https://google.com"}, | 161 {"https://google.com", false, L"https://google.com"}, |
| 156 }; | 162 }; |
| 157 for (FormatUrlTestData& test_case : omit_scheme_cases) | 163 for (FormatUrlTestData& test_case : omit_scheme_cases) |
| 158 test_case.Validate(); | 164 test_case.Validate(); |
| 159 | 165 |
| 160 // Test the elide-after-host feature flag. | 166 // Test the elide-after-host feature flag. |
| 161 feature_list.reset(new base::test::ScopedFeatureList); | 167 feature_list.reset(new base::test::ScopedFeatureList); |
| 162 feature_list->InitAndEnableFeature( | 168 feature_list->InitAndEnableFeature( |
| 163 omnibox::kUIExperimentElideSuggestionUrlAfterHost); | 169 omnibox::kUIExperimentElideSuggestionUrlAfterHost); |
| 164 FormatUrlTestData hide_path_cases[] = { | 170 FormatUrlTestData hide_path_cases[] = { |
| 165 {"http://google.com/foobar", true, L"google.com/\x2026\x0000"}, | 171 {"http://google.com/foobar", true, L"google.com/\x2026\x0000"}, |
| 166 {"http://google.com/foobar", false, L"http://google.com/\x2026\x0000"}, | 172 {"http://google.com/foobar", false, L"http://google.com/\x2026\x0000"}, |
| 167 }; | 173 }; |
| 168 for (FormatUrlTestData& test_case : hide_path_cases) | 174 for (FormatUrlTestData& test_case : hide_path_cases) |
| 169 test_case.Validate(); | 175 test_case.Validate(); |
| 176 |
| 177 // Test the trim trivial subdomains feature flag. |
| 178 feature_list.reset(new base::test::ScopedFeatureList); |
| 179 feature_list->InitAndEnableFeature( |
| 180 omnibox::kUIExperimentHideSuggestionUrlTrivialSubdomains); |
| 181 |
| 182 FormatUrlTestData trim_trivial_subdomains_case = { |
| 183 "http://www.m.google.com", false, L"http://google.com"}; |
| 184 trim_trivial_subdomains_case.Validate(); |
| 170 } | 185 } |
| 171 | 186 |
| 172 TEST(AutocompleteMatchTest, SupportsDeletion) { | 187 TEST(AutocompleteMatchTest, SupportsDeletion) { |
| 173 // A non-deletable match with no duplicates. | 188 // A non-deletable match with no duplicates. |
| 174 AutocompleteMatch m(NULL, 0, false, | 189 AutocompleteMatch m(NULL, 0, false, |
| 175 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 190 AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 176 EXPECT_FALSE(m.SupportsDeletion()); | 191 EXPECT_FALSE(m.SupportsDeletion()); |
| 177 | 192 |
| 178 // A deletable match with no duplicates. | 193 // A deletable match with no duplicates. |
| 179 AutocompleteMatch m1(NULL, 0, true, | 194 AutocompleteMatch m1(NULL, 0, true, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 m1.destination_url = GURL(cases[i].url1); | 270 m1.destination_url = GURL(cases[i].url1); |
| 256 m1.ComputeStrippedDestinationURL(input, nullptr); | 271 m1.ComputeStrippedDestinationURL(input, nullptr); |
| 257 AutocompleteMatch m2(nullptr, 100, false, | 272 AutocompleteMatch m2(nullptr, 100, false, |
| 258 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 273 AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 259 m2.destination_url = GURL(cases[i].url2); | 274 m2.destination_url = GURL(cases[i].url2); |
| 260 m2.ComputeStrippedDestinationURL(input, nullptr); | 275 m2.ComputeStrippedDestinationURL(input, nullptr); |
| 261 EXPECT_EQ(cases[i].expected_duplicate, | 276 EXPECT_EQ(cases[i].expected_duplicate, |
| 262 AutocompleteMatch::DestinationsEqual(m1, m2)); | 277 AutocompleteMatch::DestinationsEqual(m1, m2)); |
| 263 } | 278 } |
| 264 } | 279 } |
| OLD | NEW |