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

Side by Side Diff: components/url_formatter/elide_url_unittest.cc

Issue 2694363004: Remove IsRunningOnIOS9OrLater check from elide_url_unittest (Closed)
Patch Set: simplified conditionals Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/url_formatter/elide_url.h" 5 #include "components/url_formatter/elide_url.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/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "url/gurl.h" 14 #include "url/gurl.h"
15 #include "url/origin.h" 15 #include "url/origin.h"
16 16
17 #if !defined(OS_ANDROID) 17 #if !defined(OS_ANDROID)
18 #include "ui/gfx/font_list.h" // nogncheck 18 #include "ui/gfx/font_list.h" // nogncheck
19 #include "ui/gfx/text_elider.h" // nogncheck 19 #include "ui/gfx/text_elider.h" // nogncheck
20 #include "ui/gfx/text_utils.h" // nogncheck 20 #include "ui/gfx/text_utils.h" // nogncheck
21 #endif 21 #endif
22 22
23 #if defined(OS_IOS)
24 #include "base/ios/ios_util.h"
25 #endif
26
27 namespace { 23 namespace {
28 24
29 struct Testcase { 25 struct Testcase {
30 const std::string input; 26 const std::string input;
31 const std::string output; 27 const std::string output;
32 enum SupportedPlatforms {
33 ALL = 0,
34 NO_IOS9_OR_LATER,
35 NO_IOS,
36 } platforms;
37 }; 28 };
38 29
39 #if !defined(OS_ANDROID) 30 #if !defined(OS_ANDROID)
40 void RunUrlTest(Testcase* testcases, size_t num_testcases) { 31 void RunUrlTest(Testcase* testcases, size_t num_testcases) {
41 static const gfx::FontList font_list; 32 static const gfx::FontList font_list;
42 for (size_t i = 0; i < num_testcases; ++i) { 33 for (size_t i = 0; i < num_testcases; ++i) {
43 const GURL url(testcases[i].input); 34 const GURL url(testcases[i].input);
44 const float available_width = 35 const float available_width =
45 gfx::GetStringWidthF(base::UTF8ToUTF16(testcases[i].output), font_list); 36 gfx::GetStringWidthF(base::UTF8ToUTF16(testcases[i].output), font_list);
46 EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output), 37 EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output),
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:", "aaa" + kEllipsisStr}, 171 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:", "aaa" + kEllipsisStr},
181 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:/", "aaa" + kEllipsisStr}, 172 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:/", "aaa" + kEllipsisStr},
182 }; 173 };
183 174
184 RunUrlTest(testcases, arraysize(testcases)); 175 RunUrlTest(testcases, arraysize(testcases));
185 } 176 }
186 177
187 TEST(TextEliderTest, TestHostEliding) { 178 TEST(TextEliderTest, TestHostEliding) {
188 const std::string kEllipsisStr(gfx::kEllipsis); 179 const std::string kEllipsisStr(gfx::kEllipsis);
189 Testcase testcases[] = { 180 Testcase testcases[] = {
190 {"http://google.com", "google.com"}, 181 {"http://google.com", "google.com"},
191 // iOS width calculations are off by a letter from other platforms for 182 {"http://reallyreallyreallylongdomainname.com",
192 // strings with too many kerned letters on the default font set. 183 "reallyreallyreallylongdomainname.com"},
193 // TODO(rohitrao): Fix secure_display::ElideHost for iOS 184 {"http://foo", "foo"},
194 // (crbug.com/517604). 185 {"http://foo.bar", "foo.bar"},
195 {"http://subdomain.google.com", kEllipsisStr + ".google.com", 186 #if !defined(OS_IOS)
196 Testcase::NO_IOS9_OR_LATER}, 187 // iOS width calculations are off by a letter from other platforms for
197 {"http://reallyreallyreallylongdomainname.com", 188 // strings with too many kerned letters on the default font set.
198 "reallyreallyreallylongdomainname.com"}, 189 // TODO(rohitrao): Fix secure_display::ElideHost for iOS
199 {"http://a.b.c.d.e.f.com", kEllipsisStr + "f.com", 190 // (crbug.com/517604).
200 Testcase::NO_IOS9_OR_LATER}, 191 {"http://subdomain.google.com", kEllipsisStr + ".google.com"},
201 {"http://foo", "foo"}, 192 {"http://a.b.c.d.e.f.com", kEllipsisStr + "f.com"},
202 {"http://foo.bar", "foo.bar"}, 193 {"http://subdomain.foo.bar", kEllipsisStr + "in.foo.bar"},
203 {"http://subdomain.foo.bar", kEllipsisStr + "in.foo.bar", 194 {"http://subdomain.reallylongdomainname.com",
204 Testcase::NO_IOS9_OR_LATER}, 195 kEllipsisStr + "ain.reallylongdomainname.com"},
205 {"http://subdomain.reallylongdomainname.com", 196 {"http://a.b.c.d.e.f.com", kEllipsisStr + ".e.f.com"},
206 kEllipsisStr + "ain.reallylongdomainname.com", Testcase::NO_IOS}, 197 // IDN - Greek alpha.beta.gamma.delta.epsilon.zeta.com
207 {"http://a.b.c.d.e.f.com", kEllipsisStr + ".e.f.com", Testcase::NO_IOS}, 198 {"http://xn--mxa.xn--nxa.xn--oxa.xn--pxa.xn--qxa.xn--rxa.com",
208 // IDN - Greek alpha.beta.gamma.delta.epsilon.zeta.com 199 kEllipsisStr + ".\xCE\xB5.\xCE\xB6.com"},
209 {"http://xn--mxa.xn--nxa.xn--oxa.xn--pxa.xn--qxa.xn--rxa.com", 200 #endif // !defined(OS_IOS)
210 kEllipsisStr + ".\xCE\xB5.\xCE\xB6.com", Testcase::NO_IOS},
211 }; 201 };
212 202
213 for (size_t i = 0; i < arraysize(testcases); ++i) { 203 for (size_t i = 0; i < arraysize(testcases); ++i) {
214 #if defined(OS_IOS)
215 if (testcases[i].platforms == Testcase::NO_IOS ||
216 (testcases[i].platforms == Testcase::NO_IOS9_OR_LATER &&
217 base::ios::IsRunningOnIOS9OrLater())) {
218 continue;
219 }
220 #endif
221 const float available_width = gfx::GetStringWidthF( 204 const float available_width = gfx::GetStringWidthF(
222 base::UTF8ToUTF16(testcases[i].output), gfx::FontList()); 205 base::UTF8ToUTF16(testcases[i].output), gfx::FontList());
223 EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output), 206 EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output),
224 url_formatter::ElideHost(GURL(testcases[i].input), 207 url_formatter::ElideHost(GURL(testcases[i].input),
225 gfx::FontList(), available_width)); 208 gfx::FontList(), available_width));
226 } 209 }
227 210
228 // Trying to elide to a really short length will still keep the full TLD+1 211 // Trying to elide to a really short length will still keep the full TLD+1
229 EXPECT_EQ( 212 EXPECT_EQ(
230 base::ASCIIToUTF16("google.com"), 213 base::ASCIIToUTF16("google.com"),
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 EXPECT_EQ(base::string16(), formatted_omit_scheme) 503 EXPECT_EQ(base::string16(), formatted_omit_scheme)
521 << "Explicitly test the url::Origin which takes an empty, invalid URL"; 504 << "Explicitly test the url::Origin which takes an empty, invalid URL";
522 505
523 formatted_omit_scheme = url_formatter::FormatOriginForSecurityDisplay( 506 formatted_omit_scheme = url_formatter::FormatOriginForSecurityDisplay(
524 url::Origin(GURL()), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); 507 url::Origin(GURL()), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
525 EXPECT_EQ(base::string16(), formatted_omit_scheme) 508 EXPECT_EQ(base::string16(), formatted_omit_scheme)
526 << "Explicitly test the url::Origin which takes an empty, invalid URL"; 509 << "Explicitly test the url::Origin which takes an empty, invalid URL";
527 } 510 }
528 511
529 } // namespace 512 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698