Chromium Code Reviews| 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/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 { | 28 enum SupportedPlatforms { |
| 33 ALL = 0, | 29 ALL = 0, |
| 34 NO_IOS9_OR_LATER, | |
| 35 NO_IOS, | 30 NO_IOS, |
| 36 } platforms; | 31 } platforms; |
| 37 }; | 32 }; |
| 38 | 33 |
| 39 #if !defined(OS_ANDROID) | 34 #if !defined(OS_ANDROID) |
| 40 void RunUrlTest(Testcase* testcases, size_t num_testcases) { | 35 void RunUrlTest(Testcase* testcases, size_t num_testcases) { |
| 41 static const gfx::FontList font_list; | 36 static const gfx::FontList font_list; |
| 42 for (size_t i = 0; i < num_testcases; ++i) { | 37 for (size_t i = 0; i < num_testcases; ++i) { |
| 43 const GURL url(testcases[i].input); | 38 const GURL url(testcases[i].input); |
| 44 const float available_width = | 39 const float available_width = |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 {"file://filer/foo/", "filer/foo/"}, | 172 {"file://filer/foo/", "filer/foo/"}, |
| 178 {"file://filer/foo/", "filer" + kEllipsisStr}, | 173 {"file://filer/foo/", "filer" + kEllipsisStr}, |
| 179 // Eliding file URLs with nothing after the ':' shouldn't crash. | 174 // Eliding file URLs with nothing after the ':' shouldn't crash. |
| 180 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:", "aaa" + kEllipsisStr}, | 175 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:", "aaa" + kEllipsisStr}, |
| 181 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:/", "aaa" + kEllipsisStr}, | 176 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:/", "aaa" + kEllipsisStr}, |
| 182 }; | 177 }; |
| 183 | 178 |
| 184 RunUrlTest(testcases, arraysize(testcases)); | 179 RunUrlTest(testcases, arraysize(testcases)); |
| 185 } | 180 } |
| 186 | 181 |
| 187 TEST(TextEliderTest, TestHostEliding) { | 182 TEST(TextEliderTest, TestHostEliding) { |
|
Peter Kasting
2017/02/16 21:03:43
It seems like this is the only test that uses NO_I
pkl (ping after 24h if needed)
2017/02/22 14:47:57
Yes, makes a lot of sense. Thank you!
| |
| 188 const std::string kEllipsisStr(gfx::kEllipsis); | 183 const std::string kEllipsisStr(gfx::kEllipsis); |
| 189 Testcase testcases[] = { | 184 Testcase testcases[] = { |
| 190 {"http://google.com", "google.com"}, | 185 {"http://google.com", "google.com"}, |
| 191 // iOS width calculations are off by a letter from other platforms for | 186 // iOS width calculations are off by a letter from other platforms for |
| 192 // strings with too many kerned letters on the default font set. | 187 // strings with too many kerned letters on the default font set. |
| 193 // TODO(rohitrao): Fix secure_display::ElideHost for iOS | 188 // TODO(rohitrao): Fix secure_display::ElideHost for iOS |
| 194 // (crbug.com/517604). | 189 // (crbug.com/517604). |
| 195 {"http://subdomain.google.com", kEllipsisStr + ".google.com", | 190 {"http://subdomain.google.com", kEllipsisStr + ".google.com", |
| 196 Testcase::NO_IOS9_OR_LATER}, | 191 Testcase::NO_IOS}, |
| 197 {"http://reallyreallyreallylongdomainname.com", | 192 {"http://reallyreallyreallylongdomainname.com", |
| 198 "reallyreallyreallylongdomainname.com"}, | 193 "reallyreallyreallylongdomainname.com"}, |
| 199 {"http://a.b.c.d.e.f.com", kEllipsisStr + "f.com", | 194 {"http://a.b.c.d.e.f.com", kEllipsisStr + "f.com", Testcase::NO_IOS}, |
| 200 Testcase::NO_IOS9_OR_LATER}, | |
| 201 {"http://foo", "foo"}, | 195 {"http://foo", "foo"}, |
| 202 {"http://foo.bar", "foo.bar"}, | 196 {"http://foo.bar", "foo.bar"}, |
| 203 {"http://subdomain.foo.bar", kEllipsisStr + "in.foo.bar", | 197 {"http://subdomain.foo.bar", kEllipsisStr + "in.foo.bar", |
| 204 Testcase::NO_IOS9_OR_LATER}, | 198 Testcase::NO_IOS}, |
| 205 {"http://subdomain.reallylongdomainname.com", | 199 {"http://subdomain.reallylongdomainname.com", |
| 206 kEllipsisStr + "ain.reallylongdomainname.com", Testcase::NO_IOS}, | 200 kEllipsisStr + "ain.reallylongdomainname.com", Testcase::NO_IOS}, |
| 207 {"http://a.b.c.d.e.f.com", kEllipsisStr + ".e.f.com", Testcase::NO_IOS}, | 201 {"http://a.b.c.d.e.f.com", kEllipsisStr + ".e.f.com", Testcase::NO_IOS}, |
| 208 // IDN - Greek alpha.beta.gamma.delta.epsilon.zeta.com | 202 // IDN - Greek alpha.beta.gamma.delta.epsilon.zeta.com |
| 209 {"http://xn--mxa.xn--nxa.xn--oxa.xn--pxa.xn--qxa.xn--rxa.com", | 203 {"http://xn--mxa.xn--nxa.xn--oxa.xn--pxa.xn--qxa.xn--rxa.com", |
| 210 kEllipsisStr + ".\xCE\xB5.\xCE\xB6.com", Testcase::NO_IOS}, | 204 kEllipsisStr + ".\xCE\xB5.\xCE\xB6.com", Testcase::NO_IOS}, |
| 211 }; | 205 }; |
| 212 | 206 |
| 213 for (size_t i = 0; i < arraysize(testcases); ++i) { | 207 for (size_t i = 0; i < arraysize(testcases); ++i) { |
| 214 #if defined(OS_IOS) | 208 #if defined(OS_IOS) |
| 215 if (testcases[i].platforms == Testcase::NO_IOS || | 209 if (testcases[i].platforms == Testcase::NO_IOS) { |
|
Peter Kasting
2017/02/16 21:03:43
Nit: No {}
| |
| 216 (testcases[i].platforms == Testcase::NO_IOS9_OR_LATER && | |
| 217 base::ios::IsRunningOnIOS9OrLater())) { | |
| 218 continue; | 210 continue; |
| 219 } | 211 } |
| 220 #endif | 212 #endif |
| 221 const float available_width = gfx::GetStringWidthF( | 213 const float available_width = gfx::GetStringWidthF( |
| 222 base::UTF8ToUTF16(testcases[i].output), gfx::FontList()); | 214 base::UTF8ToUTF16(testcases[i].output), gfx::FontList()); |
| 223 EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output), | 215 EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output), |
| 224 url_formatter::ElideHost(GURL(testcases[i].input), | 216 url_formatter::ElideHost(GURL(testcases[i].input), |
| 225 gfx::FontList(), available_width)); | 217 gfx::FontList(), available_width)); |
| 226 } | 218 } |
| 227 | 219 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 EXPECT_EQ(base::string16(), formatted_omit_scheme) | 512 EXPECT_EQ(base::string16(), formatted_omit_scheme) |
| 521 << "Explicitly test the url::Origin which takes an empty, invalid URL"; | 513 << "Explicitly test the url::Origin which takes an empty, invalid URL"; |
| 522 | 514 |
| 523 formatted_omit_scheme = url_formatter::FormatOriginForSecurityDisplay( | 515 formatted_omit_scheme = url_formatter::FormatOriginForSecurityDisplay( |
| 524 url::Origin(GURL()), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); | 516 url::Origin(GURL()), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); |
| 525 EXPECT_EQ(base::string16(), formatted_omit_scheme) | 517 EXPECT_EQ(base::string16(), formatted_omit_scheme) |
| 526 << "Explicitly test the url::Origin which takes an empty, invalid URL"; | 518 << "Explicitly test the url::Origin which takes an empty, invalid URL"; |
| 527 } | 519 } |
| 528 | 520 |
| 529 } // namespace | 521 } // namespace |
| OLD | NEW |