OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Unit tests for eliding and formatting utility functions. | 5 // Unit tests for eliding and formatting utility functions. |
6 | 6 |
7 #include "ui/base/text/text_elider.h" | 7 #include "ui/base/text/text_elider.h" |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 // That's kinda redundant with net_util_unittests. | 48 // That's kinda redundant with net_util_unittests. |
49 EXPECT_EQ(UTF8ToUTF16(testcases[i].output), | 49 EXPECT_EQ(UTF8ToUTF16(testcases[i].output), |
50 ElideUrl(url, font, | 50 ElideUrl(url, font, |
51 font.GetStringWidth(UTF8ToUTF16(testcases[i].output)), | 51 font.GetStringWidth(UTF8ToUTF16(testcases[i].output)), |
52 std::string())); | 52 std::string())); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 #if defined(OS_IOS) | |
59 // TODO(ios): complex eliding is off by one for some of those tests on iOS. | |
stuartmorgan
2012/10/06 11:47:04
Don't indent.
| |
60 // See crbug.com/154019 | |
61 TEST(TextEliderTest, DISABLED_ElideEmail) { | |
stuartmorgan
2012/10/06 11:47:04
The standard Chromium practice is to use MAYBE_.
| |
62 #else | |
58 TEST(TextEliderTest, ElideEmail) { | 63 TEST(TextEliderTest, ElideEmail) { |
64 #endif // defined(OS_IOS) | |
stuartmorgan
2012/10/06 11:47:04
We generally omit the closing comment on ifdefs th
| |
59 const std::string kEllipsisStr(kEllipsis); | 65 const std::string kEllipsisStr(kEllipsis); |
60 | 66 |
61 // Test emails and their expected elided forms (from which the available | 67 // Test emails and their expected elided forms (from which the available |
62 // widths will be derived). | 68 // widths will be derived). |
63 // For elided forms in which both the username and domain must be elided: | 69 // For elided forms in which both the username and domain must be elided: |
64 // the result (how many characters are left on each side) can be font | 70 // the result (how many characters are left on each side) can be font |
65 // dependent. To avoid this, the username is prefixed with the characters | 71 // dependent. To avoid this, the username is prefixed with the characters |
66 // expected to remain in the domain. | 72 // expected to remain in the domain. |
67 Testcase testcases[] = { | 73 Testcase testcases[] = { |
68 {"g@g.c", "g@g.c"}, | 74 {"g@g.c", "g@g.c"}, |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 "C:/" + kEllipsisStr + "/filename"}, | 246 "C:/" + kEllipsisStr + "/filename"}, |
241 #endif | 247 #endif |
242 {"file://filer/foo/bar/file", "filer/foo/bar/file"}, | 248 {"file://filer/foo/bar/file", "filer/foo/bar/file"}, |
243 {"file://filer/foo/bar/file", "filer/foo/" + kEllipsisStr + "/file"}, | 249 {"file://filer/foo/bar/file", "filer/foo/" + kEllipsisStr + "/file"}, |
244 {"file://filer/foo/bar/file", "filer/" + kEllipsisStr + "/file"}, | 250 {"file://filer/foo/bar/file", "filer/" + kEllipsisStr + "/file"}, |
245 }; | 251 }; |
246 | 252 |
247 RunUrlTest(testcases, arraysize(testcases)); | 253 RunUrlTest(testcases, arraysize(testcases)); |
248 } | 254 } |
249 | 255 |
256 #if defined(OS_IOS) | |
257 // TODO(ios): complex eliding is off by one for some of those tests on iOS. | |
258 // See crbug.com/154019 | |
259 TEST(TextEliderTest, DISABLED_TestFilenameEliding) { | |
260 #else | |
250 TEST(TextEliderTest, TestFilenameEliding) { | 261 TEST(TextEliderTest, TestFilenameEliding) { |
262 #endif // defined(OS_IOS) | |
251 const std::string kEllipsisStr(kEllipsis); | 263 const std::string kEllipsisStr(kEllipsis); |
252 const FilePath::StringType kPathSeparator = | 264 const FilePath::StringType kPathSeparator = |
253 FilePath::StringType().append(1, FilePath::kSeparators[0]); | 265 FilePath::StringType().append(1, FilePath::kSeparators[0]); |
254 | 266 |
255 FileTestcase testcases[] = { | 267 FileTestcase testcases[] = { |
256 {FILE_PATH_LITERAL(""), ""}, | 268 {FILE_PATH_LITERAL(""), ""}, |
257 {FILE_PATH_LITERAL("."), "."}, | 269 {FILE_PATH_LITERAL("."), "."}, |
258 {FILE_PATH_LITERAL("filename.exe"), "filename.exe"}, | 270 {FILE_PATH_LITERAL("filename.exe"), "filename.exe"}, |
259 {FILE_PATH_LITERAL(".longext"), ".longext"}, | 271 {FILE_PATH_LITERAL(".longext"), ".longext"}, |
260 {FILE_PATH_LITERAL("pie"), "pie"}, | 272 {FILE_PATH_LITERAL("pie"), "pie"}, |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 | 885 |
874 // Test adds ... at right spot when there is not enough room to break at a | 886 // Test adds ... at right spot when there is not enough room to break at a |
875 // word boundary. | 887 // word boundary. |
876 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); | 888 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); |
877 | 889 |
878 // Test completely truncates string if break is on initial whitespace. | 890 // Test completely truncates string if break is on initial whitespace. |
879 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); | 891 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); |
880 } | 892 } |
881 | 893 |
882 } // namespace ui | 894 } // namespace ui |
OLD | NEW |