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

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

Issue 2963883002: Omnibox UI Experiments: Refactor HTTPS trimming into UrlFormatter. (Closed)
Patch Set: update comment 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, GetFormatForSuggestionDisplay) {
Peter Kasting 2017/06/29 01:05:44 It's OK I guess, but this test does seem a bit cha
tommycli 2017/06/29 16:46:46 Done. No problem. I changed it back to just sanity
115 struct FormatUrlTestData { 115 EXPECT_EQ(
116 const std::string url; 116 url_formatter::kFormatUrlOmitAll,
117 bool trim_scheme; 117 AutocompleteMatch::GetFormatForSuggestionDisplay(true /* trim_scheme */));
118 size_t offset_for_adjustment; 118 EXPECT_EQ(
119 const std::string expected_result; 119 url_formatter::kFormatUrlOmitAll & ~url_formatter::kFormatUrlOmitHTTP,
120 size_t expected_adjusted_offset; 120 AutocompleteMatch::GetFormatForSuggestionDisplay(
121 false /* trim_scheme */));
121 122
122 void Validate() { 123 // Test the hide scheme feature flag.
123 SCOPED_TRACE(testing::Message()
124 << " url= " << url << " trim_scheme=" << trim_scheme
125 << " offset_for_adjustment=" << offset_for_adjustment
126 << " expected_result=" << expected_result
127 << " expected_adjusted_offset=" << expected_adjusted_offset);
128
129 size_t offset_result = offset_for_adjustment;
130 base::string16 result = AutocompleteMatch::FormatUrlForSuggestionDisplay(
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 };
136 };
137
138 FormatUrlTestData normal_cases[] = {
139 {"http://google.com", true, 9, "google.com", 2},
140 {"https://google.com", true, 9, "https://google.com", 9},
141 {"http://google.com", false, 9, "http://google.com", 9},
142 {"https://google.com", false, 9, "https://google.com", 9},
143 };
144 for (size_t i = 0; i < arraysize(normal_cases); ++i) {
145 normal_cases[i].Validate();
146 }
147
148 std::unique_ptr<base::test::ScopedFeatureList> feature_list( 124 std::unique_ptr<base::test::ScopedFeatureList> feature_list(
149 new base::test::ScopedFeatureList); 125 new base::test::ScopedFeatureList);
150 feature_list->InitAndEnableFeature( 126 feature_list->InitAndEnableFeature(
151 omnibox::kUIExperimentHideSuggestionUrlScheme); 127 omnibox::kUIExperimentHideSuggestionUrlScheme);
152 128
153 FormatUrlTestData omit_scheme_cases[] = { 129 EXPECT_EQ(
154 {"http://google.com", true, 9, "google.com", 2}, 130 url_formatter::kFormatUrlOmitAll |
155 {"https://google.com", true, 9, "google.com", 1}, 131 url_formatter::kFormatUrlExperimentalOmitHTTPS,
156 {"https://username:password@google.com", true, 9, "google.com", 132 AutocompleteMatch::GetFormatForSuggestionDisplay(true /* trim_scheme */));
157 base::string16::npos}, 133 EXPECT_EQ(
158 {"https://username:password@google.com", true, 29, "google.com", 3}, 134 url_formatter::kFormatUrlOmitAll & ~url_formatter::kFormatUrlOmitHTTP,
159 {"http://google.com", false, 9, "http://google.com", 9}, 135 AutocompleteMatch::GetFormatForSuggestionDisplay(
160 {"https://google.com", false, 9, "https://google.com", 9}, 136 false /* trim_scheme */));
161 {"http://username:password@google.com", false, 9, "http://google.com",
162 base::string16::npos},
163 };
164 for (size_t i = 0; i < arraysize(omit_scheme_cases); ++i) {
165 omit_scheme_cases[i].Validate();
166 }
167 } 137 }
168 138
169 TEST(AutocompleteMatchTest, SupportsDeletion) { 139 TEST(AutocompleteMatchTest, SupportsDeletion) {
170 // A non-deletable match with no duplicates. 140 // A non-deletable match with no duplicates.
171 AutocompleteMatch m(NULL, 0, false, 141 AutocompleteMatch m(NULL, 0, false,
172 AutocompleteMatchType::URL_WHAT_YOU_TYPED); 142 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
173 EXPECT_FALSE(m.SupportsDeletion()); 143 EXPECT_FALSE(m.SupportsDeletion());
174 144
175 // A deletable match with no duplicates. 145 // A deletable match with no duplicates.
176 AutocompleteMatch m1(NULL, 0, true, 146 AutocompleteMatch m1(NULL, 0, true,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 m1.destination_url = GURL(cases[i].url1); 222 m1.destination_url = GURL(cases[i].url1);
253 m1.ComputeStrippedDestinationURL(input, nullptr); 223 m1.ComputeStrippedDestinationURL(input, nullptr);
254 AutocompleteMatch m2(nullptr, 100, false, 224 AutocompleteMatch m2(nullptr, 100, false,
255 AutocompleteMatchType::URL_WHAT_YOU_TYPED); 225 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
256 m2.destination_url = GURL(cases[i].url2); 226 m2.destination_url = GURL(cases[i].url2);
257 m2.ComputeStrippedDestinationURL(input, nullptr); 227 m2.ComputeStrippedDestinationURL(input, nullptr);
258 EXPECT_EQ(cases[i].expected_duplicate, 228 EXPECT_EQ(cases[i].expected_duplicate,
259 AutocompleteMatch::DestinationsEqual(m1, m2)); 229 AutocompleteMatch::DestinationsEqual(m1, m2));
260 } 230 }
261 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698