Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: components/omnibox/browser/autocomplete_match_unittest.cc

Issue 2961393002: Omnibox UI Experiments: Hook up elide-after-host feature flag. (Closed)
Patch Set: merge Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_cases[] = {
165 {"http://google.com/foobar", true, L"google.com/\x2026\x0000"},
166 {"http://google.com/foobar", false, L"http://google.com/\x2026\x0000"},
167 };
168 for (FormatUrlTestData& test_case : hide_path_cases)
169 test_case.Validate();
156 } 170 }
157 171
158 TEST(AutocompleteMatchTest, SupportsDeletion) { 172 TEST(AutocompleteMatchTest, SupportsDeletion) {
159 // A non-deletable match with no duplicates. 173 // A non-deletable match with no duplicates.
160 AutocompleteMatch m(NULL, 0, false, 174 AutocompleteMatch m(NULL, 0, false,
161 AutocompleteMatchType::URL_WHAT_YOU_TYPED); 175 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
162 EXPECT_FALSE(m.SupportsDeletion()); 176 EXPECT_FALSE(m.SupportsDeletion());
163 177
164 // A deletable match with no duplicates. 178 // A deletable match with no duplicates.
165 AutocompleteMatch m1(NULL, 0, true, 179 AutocompleteMatch m1(NULL, 0, true,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 m1.destination_url = GURL(cases[i].url1); 255 m1.destination_url = GURL(cases[i].url1);
242 m1.ComputeStrippedDestinationURL(input, nullptr); 256 m1.ComputeStrippedDestinationURL(input, nullptr);
243 AutocompleteMatch m2(nullptr, 100, false, 257 AutocompleteMatch m2(nullptr, 100, false,
244 AutocompleteMatchType::URL_WHAT_YOU_TYPED); 258 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
245 m2.destination_url = GURL(cases[i].url2); 259 m2.destination_url = GURL(cases[i].url2);
246 m2.ComputeStrippedDestinationURL(input, nullptr); 260 m2.ComputeStrippedDestinationURL(input, nullptr);
247 EXPECT_EQ(cases[i].expected_duplicate, 261 EXPECT_EQ(cases[i].expected_duplicate,
248 AutocompleteMatch::DestinationsEqual(m1, m2)); 262 AutocompleteMatch::DestinationsEqual(m1, m2));
249 } 263 }
250 } 264 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/autocomplete_match.cc ('k') | components/omnibox/browser/omnibox_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698