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
3 // found in the LICENSE file.
5 // Unit tests for eliding and formatting utility functions.
7 #include "ui/gfx/text_elider.h"
9 #include "base/files/file_path.h"
10 #include "base/i18n/rtl.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/font.h"
16 #include "ui/gfx/font_list.h"
17 #include "ui/gfx/font_render_params.h"
18 #include "ui/gfx/text_utils.h"
20 using base::ASCIIToUTF16
;
21 using base::UTF16ToUTF8
;
22 using base::UTF16ToWide
;
23 using base::UTF8ToUTF16
;
24 using base::WideToUTF16
;
31 const std::string input
;
32 const std::string output
;
36 const base::FilePath::StringType input
;
37 const std::string output
;
40 struct UTF16Testcase
{
41 const base::string16 input
;
42 const base::string16 output
;
48 const int compare_result
;
53 // TODO(ios): This test fails on iOS because iOS version of GetStringWidthF
54 // that calls [NSString sizeWithFont] returns the rounded string width.
55 // TODO(338784): Enable this on android.
56 #if defined(OS_IOS) || defined(OS_ANDROID)
57 #define MAYBE_ElideEmail DISABLED_ElideEmail
59 #define MAYBE_ElideEmail ElideEmail
61 TEST(TextEliderTest
, MAYBE_ElideEmail
) {
62 const std::string
kEllipsisStr(kEllipsis
);
64 // Test emails and their expected elided forms (from which the available
65 // widths will be derived).
66 // For elided forms in which both the username and domain must be elided:
67 // the result (how many characters are left on each side) can be font
68 // dependent. To avoid this, the username is prefixed with the characters
69 // expected to remain in the domain.
70 Testcase testcases
[] = {
72 {"g@g.c", kEllipsisStr
},
73 {"ga@co.ca", "ga@c" + kEllipsisStr
+ "a"},
74 {"short@small.com", "s" + kEllipsisStr
+ "@s" + kEllipsisStr
},
75 {"short@small.com", "s" + kEllipsisStr
+ "@small.com"},
76 {"short@longbutlotsofspace.com", "short@longbutlotsofspace.com"},
77 {"short@longbutnotverymuchspace.com",
78 "short@long" + kEllipsisStr
+ ".com"},
79 {"la_short@longbutverytightspace.ca",
80 "la" + kEllipsisStr
+ "@l" + kEllipsisStr
+ "a"},
81 {"longusername@gmail.com", "long" + kEllipsisStr
+ "@gmail.com"},
82 {"elidetothemax@justfits.com", "e" + kEllipsisStr
+ "@justfits.com"},
83 {"thatom_somelongemail@thatdoesntfit.com",
84 "thatom" + kEllipsisStr
+ "@tha" + kEllipsisStr
+ "om"},
85 {"namefits@butthedomaindoesnt.com",
86 "namefits@butthedo" + kEllipsisStr
+ "snt.com"},
87 {"widthtootight@nospace.com", kEllipsisStr
},
88 {"nospaceforusername@l", kEllipsisStr
},
89 {"little@littlespace.com", "l" + kEllipsisStr
+ "@l" + kEllipsisStr
},
90 {"l@llllllllllllllllllllllll.com", "l@lllll" + kEllipsisStr
+ ".com"},
91 {"messed\"up@whyanat\"++@notgoogley.com",
92 "messed\"up@whyanat\"++@notgoogley.com"},
93 {"messed\"up@whyanat\"++@notgoogley.com",
94 "messed\"up@why" + kEllipsisStr
+ "@notgoogley.com"},
95 {"noca_messed\"up@whyanat\"++@notgoogley.ca",
96 "noca" + kEllipsisStr
+ "@no" + kEllipsisStr
+ "ca"},
97 {"at\"@@@@@@@@@...@@.@.@.@@@\"@madness.com",
98 "at\"@@@@@@@@@...@@.@." + kEllipsisStr
+ "@madness.com"},
99 // Special case: "m..." takes more than half of the available width; thus
100 // the domain must elide to "l..." and not "l...l" as it must allow enough
101 // space for the minimal username elision although its half of the
102 // available width would normally allow it to elide to "l...l".
103 {"mmmmm@llllllllll", "m" + kEllipsisStr
+ "@l" + kEllipsisStr
},
106 const FontList font_list
;
107 for (size_t i
= 0; i
< arraysize(testcases
); ++i
) {
108 const base::string16 expected_output
= UTF8ToUTF16(testcases
[i
].output
);
109 EXPECT_EQ(expected_output
,
110 ElideText(UTF8ToUTF16(testcases
[i
].input
), font_list
,
111 GetStringWidthF(expected_output
, font_list
),
116 // TODO(338784): Enable this on android.
117 #if defined(OS_ANDROID)
118 #define MAYBE_ElideEmailMoreSpace DISABLED_ElideEmailMoreSpace
120 #define MAYBE_ElideEmailMoreSpace ElideEmailMoreSpace
122 TEST(TextEliderTest
, MAYBE_ElideEmailMoreSpace
) {
123 const int test_width_factors
[] = {
128 const std::string test_emails
[] = {
131 "short@verysuperdupperlongdomain.com",
132 "supermegalongusername@withasuperlonnnggggdomain.gouv.qc.ca",
135 const FontList font_list
;
136 for (size_t i
= 0; i
< arraysize(test_width_factors
); ++i
) {
137 const int test_width
=
138 font_list
.GetExpectedTextWidth(test_width_factors
[i
]);
139 for (size_t j
= 0; j
< arraysize(test_emails
); ++j
) {
140 // Extra space is available: the email should not be elided.
141 const base::string16 test_email
= UTF8ToUTF16(test_emails
[j
]);
142 EXPECT_EQ(test_email
,
143 ElideText(test_email
, font_list
, test_width
, ELIDE_EMAIL
));
148 // TODO(ios): This test fails on iOS because iOS version of GetStringWidthF
149 // that calls [NSString sizeWithFont] returns the rounded string width.
150 // TODO(338784): Enable this on android.
151 #if defined(OS_IOS) || defined(OS_ANDROID)
152 #define MAYBE_TestFilenameEliding DISABLED_TestFilenameEliding
154 #define MAYBE_TestFilenameEliding TestFilenameEliding
156 TEST(TextEliderTest
, MAYBE_TestFilenameEliding
) {
157 const std::string
kEllipsisStr(kEllipsis
);
158 const base::FilePath::StringType kPathSeparator
=
159 base::FilePath::StringType().append(1, base::FilePath::kSeparators
[0]);
161 FileTestcase testcases
[] = {
162 {FILE_PATH_LITERAL(""), ""},
163 {FILE_PATH_LITERAL("."), "."},
164 {FILE_PATH_LITERAL("filename.exe"), "filename.exe"},
165 {FILE_PATH_LITERAL(".longext"), ".longext"},
166 {FILE_PATH_LITERAL("pie"), "pie"},
167 {FILE_PATH_LITERAL("c:") + kPathSeparator
+ FILE_PATH_LITERAL("path") +
168 kPathSeparator
+ FILE_PATH_LITERAL("filename.pie"),
170 {FILE_PATH_LITERAL("c:") + kPathSeparator
+ FILE_PATH_LITERAL("path") +
171 kPathSeparator
+ FILE_PATH_LITERAL("longfilename.pie"),
172 "long" + kEllipsisStr
+ ".pie"},
173 {FILE_PATH_LITERAL("http://path.com/filename.pie"), "filename.pie"},
174 {FILE_PATH_LITERAL("http://path.com/longfilename.pie"),
175 "long" + kEllipsisStr
+ ".pie"},
176 {FILE_PATH_LITERAL("piesmashingtacularpants"), "pie" + kEllipsisStr
},
177 {FILE_PATH_LITERAL(".piesmashingtacularpants"), ".pie" + kEllipsisStr
},
178 {FILE_PATH_LITERAL("cheese."), "cheese."},
179 {FILE_PATH_LITERAL("file name.longext"),
180 "file" + kEllipsisStr
+ ".longext"},
181 {FILE_PATH_LITERAL("fil ename.longext"),
182 "fil " + kEllipsisStr
+ ".longext"},
183 {FILE_PATH_LITERAL("filename.longext"),
184 "file" + kEllipsisStr
+ ".longext"},
185 {FILE_PATH_LITERAL("filename.middleext.longext"),
186 "filename.mid" + kEllipsisStr
+ ".longext"},
187 {FILE_PATH_LITERAL("filename.superduperextremelylongext"),
188 "filename.sup" + kEllipsisStr
+ "emelylongext"},
189 {FILE_PATH_LITERAL("filenamereallylongtext.superduperextremelylongext"),
190 "filenamereall" + kEllipsisStr
+ "emelylongext"},
191 {FILE_PATH_LITERAL("file.name.really.long.text.superduperextremelylongext"),
192 "file.name.re" + kEllipsisStr
+ "emelylongext"}
195 static const FontList font_list
;
196 for (size_t i
= 0; i
< arraysize(testcases
); ++i
) {
197 base::FilePath
filepath(testcases
[i
].input
);
198 base::string16 expected
= UTF8ToUTF16(testcases
[i
].output
);
199 expected
= base::i18n::GetDisplayStringInLTRDirectionality(expected
);
200 EXPECT_EQ(expected
, ElideFilename(filepath
, font_list
,
201 GetStringWidthF(UTF8ToUTF16(testcases
[i
].output
), font_list
)));
205 // TODO(338784): Enable this on android.
206 #if defined(OS_ANDROID)
207 #define MAYBE_ElideTextTruncate DISABLED_ElideTextTruncate
209 #define MAYBE_ElideTextTruncate ElideTextTruncate
211 TEST(TextEliderTest
, MAYBE_ElideTextTruncate
) {
212 const FontList font_list
;
213 const float kTestWidth
= GetStringWidthF(ASCIIToUTF16("Test"), font_list
);
221 { "", kTestWidth
, "" },
222 { "Tes", kTestWidth
, "Tes" },
223 { "Test", kTestWidth
, "Test" },
224 { "Tests", kTestWidth
, "Test" },
227 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
228 base::string16 result
= ElideText(UTF8ToUTF16(cases
[i
].input
), font_list
,
229 cases
[i
].width
, TRUNCATE
);
230 EXPECT_EQ(cases
[i
].output
, UTF16ToUTF8(result
));
234 // TODO(338784): Enable this on android.
235 #if defined(OS_ANDROID)
236 #define MAYBE_ElideTextEllipsis DISABLED_ElideTextEllipsis
238 #define MAYBE_ElideTextEllipsis ElideTextEllipsis
240 TEST(TextEliderTest
, MAYBE_ElideTextEllipsis
) {
241 const FontList font_list
;
242 const float kTestWidth
= GetStringWidthF(ASCIIToUTF16("Test"), font_list
);
243 const char* kEllipsis
= "\xE2\x80\xA6";
244 const float kEllipsisWidth
=
245 GetStringWidthF(UTF8ToUTF16(kEllipsis
), font_list
);
253 { "Test", kEllipsisWidth
, kEllipsis
},
254 { "", kTestWidth
, "" },
255 { "Tes", kTestWidth
, "Tes" },
256 { "Test", kTestWidth
, "Test" },
259 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
260 base::string16 result
= ElideText(UTF8ToUTF16(cases
[i
].input
), font_list
,
261 cases
[i
].width
, ELIDE_TAIL
);
262 EXPECT_EQ(cases
[i
].output
, UTF16ToUTF8(result
));
266 // TODO(338784): Enable this on android.
267 #if defined(OS_ANDROID)
268 #define MAYBE_ElideTextEllipsisFront DISABLED_ElideTextEllipsisFront
270 #define MAYBE_ElideTextEllipsisFront ElideTextEllipsisFront
272 TEST(TextEliderTest
, MAYBE_ElideTextEllipsisFront
) {
273 const FontList font_list
;
274 const float kTestWidth
= GetStringWidthF(ASCIIToUTF16("Test"), font_list
);
275 const std::string
kEllipsisStr(kEllipsis
);
276 const float kEllipsisWidth
=
277 GetStringWidthF(UTF8ToUTF16(kEllipsis
), font_list
);
278 const float kEllipsis23Width
=
279 GetStringWidthF(UTF8ToUTF16(kEllipsisStr
+ "23"), font_list
);
283 const base::string16 output
;
285 { "", 0, base::string16() },
286 { "Test", 0, base::string16() },
287 { "Test", kEllipsisWidth
, UTF8ToUTF16(kEllipsisStr
) },
288 { "", kTestWidth
, base::string16() },
289 { "Tes", kTestWidth
, ASCIIToUTF16("Tes") },
290 { "Test", kTestWidth
, ASCIIToUTF16("Test") },
291 { "Test123", kEllipsis23Width
, UTF8ToUTF16(kEllipsisStr
+ "23") },
294 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
295 base::string16 result
= ElideText(UTF8ToUTF16(cases
[i
].input
), font_list
,
296 cases
[i
].width
, ELIDE_HEAD
);
297 EXPECT_EQ(cases
[i
].output
, result
);
301 // Checks that all occurrences of |first_char| are followed by |second_char| and
302 // all occurrences of |second_char| are preceded by |first_char| in |text|.
303 static void CheckSurrogatePairs(const base::string16
& text
,
304 base::char16 first_char
,
305 base::char16 second_char
) {
306 for (size_t index
= 0; index
< text
.length(); ++index
) {
307 EXPECT_NE(second_char
, text
[index
]);
308 if (text
[index
] == first_char
) {
309 ASSERT_LT(++index
, text
.length());
310 EXPECT_EQ(second_char
, text
[index
]);
315 // TODO(338784): Enable this on android.
316 #if defined(OS_ANDROID)
317 #define MAYBE_ElideTextSurrogatePairs DISABLED_ElideTextSurrogatePairs
319 #define MAYBE_ElideTextSurrogatePairs ElideTextSurrogatePairs
321 TEST(TextEliderTest
, MAYBE_ElideTextSurrogatePairs
) {
322 const FontList font_list
;
323 // The below is 'MUSICAL SYMBOL G CLEF', which is represented in UTF-16 as
324 // two characters forming a surrogate pair 0x0001D11E.
325 const std::string kSurrogate
= "\xF0\x9D\x84\x9E";
326 const base::string16 kTestString
= UTF8ToUTF16(kSurrogate
+ "x" + kSurrogate
);
327 const float kTestStringWidth
= GetStringWidthF(kTestString
, font_list
);
328 const base::char16 kSurrogateFirstChar
= kTestString
[0];
329 const base::char16 kSurrogateSecondChar
= kTestString
[1];
330 base::string16 result
;
332 // Elide |kTextString| to all possible widths and check that no instance of
333 // |kSurrogate| was split in two.
334 for (float width
= 0; width
<= kTestStringWidth
; width
++) {
335 result
= ElideText(kTestString
, font_list
, width
, TRUNCATE
);
336 CheckSurrogatePairs(result
, kSurrogateFirstChar
, kSurrogateSecondChar
);
338 result
= ElideText(kTestString
, font_list
, width
, ELIDE_TAIL
);
339 CheckSurrogatePairs(result
, kSurrogateFirstChar
, kSurrogateSecondChar
);
341 result
= ElideText(kTestString
, font_list
, width
, ELIDE_MIDDLE
);
342 CheckSurrogatePairs(result
, kSurrogateFirstChar
, kSurrogateSecondChar
);
344 result
= ElideText(kTestString
, font_list
, width
, ELIDE_HEAD
);
345 CheckSurrogatePairs(result
, kSurrogateFirstChar
, kSurrogateSecondChar
);
349 // TODO(338784): Enable this on android.
350 #if defined(OS_ANDROID)
351 #define MAYBE_ElideTextLongStrings DISABLED_ElideTextLongStrings
353 #define MAYBE_ElideTextLongStrings ElideTextLongStrings
355 TEST(TextEliderTest
, MAYBE_ElideTextLongStrings
) {
356 const base::string16 kEllipsisStr
= UTF8ToUTF16(kEllipsis
);
357 base::string16
data_scheme(UTF8ToUTF16("data:text/plain,"));
358 size_t data_scheme_length
= data_scheme
.length();
360 base::string16
ten_a(10, 'a');
361 base::string16
hundred_a(100, 'a');
362 base::string16
thousand_a(1000, 'a');
363 base::string16
ten_thousand_a(10000, 'a');
364 base::string16
hundred_thousand_a(100000, 'a');
365 base::string16
million_a(1000000, 'a');
367 // TODO(gbillock): Improve these tests by adding more string diversity and
368 // doing string compares instead of length compares. See bug 338836.
370 size_t number_of_as
= 156;
371 base::string16
long_string_end(
372 data_scheme
+ base::string16(number_of_as
, 'a') + kEllipsisStr
);
373 UTF16Testcase testcases_end
[] = {
374 { data_scheme
+ ten_a
, data_scheme
+ ten_a
},
375 { data_scheme
+ hundred_a
, data_scheme
+ hundred_a
},
376 { data_scheme
+ thousand_a
, long_string_end
},
377 { data_scheme
+ ten_thousand_a
, long_string_end
},
378 { data_scheme
+ hundred_thousand_a
, long_string_end
},
379 { data_scheme
+ million_a
, long_string_end
},
382 const FontList font_list
;
383 float ellipsis_width
= GetStringWidthF(kEllipsisStr
, font_list
);
384 for (size_t i
= 0; i
< arraysize(testcases_end
); ++i
) {
385 // Compare sizes rather than actual contents because if the test fails,
386 // output is rather long.
387 EXPECT_EQ(testcases_end
[i
].output
.size(),
388 ElideText(testcases_end
[i
].input
, font_list
,
389 GetStringWidthF(testcases_end
[i
].output
, font_list
),
391 EXPECT_EQ(kEllipsisStr
,
392 ElideText(testcases_end
[i
].input
, font_list
, ellipsis_width
,
396 size_t number_of_trailing_as
= (data_scheme_length
+ number_of_as
) / 2;
397 base::string16
long_string_middle(data_scheme
+
398 base::string16(number_of_as
- number_of_trailing_as
, 'a') + kEllipsisStr
+
399 base::string16(number_of_trailing_as
, 'a'));
400 UTF16Testcase testcases_middle
[] = {
401 { data_scheme
+ ten_a
, data_scheme
+ ten_a
},
402 { data_scheme
+ hundred_a
, data_scheme
+ hundred_a
},
403 { data_scheme
+ thousand_a
, long_string_middle
},
404 { data_scheme
+ ten_thousand_a
, long_string_middle
},
405 { data_scheme
+ hundred_thousand_a
, long_string_middle
},
406 { data_scheme
+ million_a
, long_string_middle
},
409 for (size_t i
= 0; i
< arraysize(testcases_middle
); ++i
) {
410 // Compare sizes rather than actual contents because if the test fails,
411 // output is rather long.
412 EXPECT_EQ(testcases_middle
[i
].output
.size(),
413 ElideText(testcases_middle
[i
].input
, font_list
,
414 GetStringWidthF(testcases_middle
[i
].output
, font_list
),
415 ELIDE_MIDDLE
).size());
416 EXPECT_EQ(kEllipsisStr
,
417 ElideText(testcases_middle
[i
].input
, font_list
, ellipsis_width
,
421 base::string16
long_string_beginning(
422 kEllipsisStr
+ base::string16(number_of_as
, 'a'));
423 UTF16Testcase testcases_beginning
[] = {
424 { data_scheme
+ ten_a
, data_scheme
+ ten_a
},
425 { data_scheme
+ hundred_a
, data_scheme
+ hundred_a
},
426 { data_scheme
+ thousand_a
, long_string_beginning
},
427 { data_scheme
+ ten_thousand_a
, long_string_beginning
},
428 { data_scheme
+ hundred_thousand_a
, long_string_beginning
},
429 { data_scheme
+ million_a
, long_string_beginning
},
431 for (size_t i
= 0; i
< arraysize(testcases_beginning
); ++i
) {
432 EXPECT_EQ(testcases_beginning
[i
].output
.size(),
434 testcases_beginning
[i
].input
, font_list
,
435 GetStringWidthF(testcases_beginning
[i
].output
, font_list
),
437 EXPECT_EQ(kEllipsisStr
,
438 ElideText(testcases_beginning
[i
].input
, font_list
, ellipsis_width
,
443 TEST(TextEliderTest
, ElideString
) {
450 { "Hello", 0, true, "" },
451 { "", 0, false, "" },
452 { "Hello, my name is Tom", 1, true, "H" },
453 { "Hello, my name is Tom", 2, true, "He" },
454 { "Hello, my name is Tom", 3, true, "H.m" },
455 { "Hello, my name is Tom", 4, true, "H..m" },
456 { "Hello, my name is Tom", 5, true, "H...m" },
457 { "Hello, my name is Tom", 6, true, "He...m" },
458 { "Hello, my name is Tom", 7, true, "He...om" },
459 { "Hello, my name is Tom", 10, true, "Hell...Tom" },
460 { "Hello, my name is Tom", 100, false, "Hello, my name is Tom" }
462 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
463 base::string16 output
;
464 EXPECT_EQ(cases
[i
].result
,
465 ElideString(UTF8ToUTF16(cases
[i
].input
),
466 cases
[i
].max_len
, &output
));
467 EXPECT_EQ(cases
[i
].output
, UTF16ToUTF8(output
));
471 // TODO(338784): Enable this on android.
472 #if defined(OS_ANDROID)
473 #define MAYBE_ElideRectangleText DISABLED_ElideRectangleText
475 #define MAYBE_ElideRectangleText ElideRectangleText
477 TEST(TextEliderTest
, MAYBE_ElideRectangleText
) {
478 const FontList font_list
;
479 const int line_height
= font_list
.GetHeight();
480 const float test_width
= GetStringWidthF(ASCIIToUTF16("Test"), font_list
);
484 float available_pixel_width
;
485 int available_pixel_height
;
489 { "", 0, 0, false, NULL
},
490 { "", 1, 1, false, NULL
},
491 { "Test", test_width
, 0, true, NULL
},
492 { "Test", test_width
, 1, false, "Test" },
493 { "Test", test_width
, line_height
, false, "Test" },
494 { "Test Test", test_width
, line_height
, true, "Test" },
495 { "Test Test", test_width
, line_height
+ 1, false, "Test|Test" },
496 { "Test Test", test_width
, line_height
* 2, false, "Test|Test" },
497 { "Test Test", test_width
, line_height
* 3, false, "Test|Test" },
498 { "Test Test", test_width
* 2, line_height
* 2, false, "Test|Test" },
499 { "Test Test", test_width
* 3, line_height
, false, "Test Test" },
500 { "Test\nTest", test_width
* 3, line_height
* 2, false, "Test|Test" },
501 { "Te\nst Te", test_width
, line_height
* 3, false, "Te|st|Te" },
502 { "\nTest", test_width
, line_height
* 2, false, "|Test" },
503 { "\nTest", test_width
, line_height
, true, "" },
504 { "\n\nTest", test_width
, line_height
* 3, false, "||Test" },
505 { "\n\nTest", test_width
, line_height
* 2, true, "|" },
506 { "Test\n", 2 * test_width
, line_height
* 5, false, "Test|" },
507 { "Test\n\n", 2 * test_width
, line_height
* 5, false, "Test||" },
508 { "Test\n\n\n", 2 * test_width
, line_height
* 5, false, "Test|||" },
509 { "Test\nTest\n\n", 2 * test_width
, line_height
* 5, false, "Test|Test||" },
510 { "Test\n\nTest\n", 2 * test_width
, line_height
* 5, false, "Test||Test|" },
511 { "Test\n\n\nTest", 2 * test_width
, line_height
* 5, false, "Test|||Test" },
512 { "Te ", test_width
, line_height
, false, "Te" },
513 { "Te Te Test", test_width
, 3 * line_height
, false, "Te|Te|Test" },
516 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
517 std::vector
<base::string16
> lines
;
518 EXPECT_EQ(cases
[i
].truncated_y
? INSUFFICIENT_SPACE_VERTICAL
: 0,
519 ElideRectangleText(UTF8ToUTF16(cases
[i
].input
),
521 cases
[i
].available_pixel_width
,
522 cases
[i
].available_pixel_height
,
525 if (cases
[i
].output
) {
526 const std::string result
= UTF16ToUTF8(JoinString(lines
, '|'));
527 EXPECT_EQ(cases
[i
].output
, result
) << "Case " << i
<< " failed!";
529 EXPECT_TRUE(lines
.empty()) << "Case " << i
<< " failed!";
534 // TODO(338784): Enable this on android.
535 #if defined(OS_ANDROID)
536 #define MAYBE_ElideRectangleTextPunctuation \
537 DISABLED_ElideRectangleTextPunctuation
539 #define MAYBE_ElideRectangleTextPunctuation ElideRectangleTextPunctuation
541 TEST(TextEliderTest
, MAYBE_ElideRectangleTextPunctuation
) {
542 const FontList font_list
;
543 const int line_height
= font_list
.GetHeight();
544 const float test_width
= GetStringWidthF(ASCIIToUTF16("Test"), font_list
);
545 const float test_t_width
= GetStringWidthF(ASCIIToUTF16("Test T"), font_list
);
549 float available_pixel_width
;
550 int available_pixel_height
;
555 { "Test T.", test_t_width
, line_height
* 2, false, false, "Test|T." },
556 { "Test T ?", test_t_width
, line_height
* 2, false, false, "Test|T ?" },
557 { "Test. Test", test_width
, line_height
* 3, false, true, "Test|Test" },
558 { "Test. Test", test_width
, line_height
* 3, true, false, "Test|.|Test" },
561 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
562 std::vector
<base::string16
> lines
;
563 const WordWrapBehavior wrap_behavior
=
564 (cases
[i
].wrap_words
? WRAP_LONG_WORDS
: TRUNCATE_LONG_WORDS
);
565 EXPECT_EQ(cases
[i
].truncated_x
? INSUFFICIENT_SPACE_HORIZONTAL
: 0,
566 ElideRectangleText(UTF8ToUTF16(cases
[i
].input
),
568 cases
[i
].available_pixel_width
,
569 cases
[i
].available_pixel_height
,
572 if (cases
[i
].output
) {
573 const std::string result
= UTF16ToUTF8(JoinString(lines
, '|'));
574 EXPECT_EQ(cases
[i
].output
, result
) << "Case " << i
<< " failed!";
576 EXPECT_TRUE(lines
.empty()) << "Case " << i
<< " failed!";
581 // TODO(338784): Enable this on android.
582 #if defined(OS_ANDROID)
583 #define MAYBE_ElideRectangleTextLongWords DISABLED_ElideRectangleTextLongWords
585 #define MAYBE_ElideRectangleTextLongWords ElideRectangleTextLongWords
587 TEST(TextEliderTest
, MAYBE_ElideRectangleTextLongWords
) {
588 const FontList font_list
;
589 const int kAvailableHeight
= 1000;
590 const base::string16 kElidedTesting
=
591 UTF8ToUTF16(std::string("Tes") + kEllipsis
);
592 const float elided_width
= GetStringWidthF(kElidedTesting
, font_list
);
593 const float test_width
= GetStringWidthF(ASCIIToUTF16("Test"), font_list
);
597 float available_pixel_width
;
598 WordWrapBehavior wrap_behavior
;
602 { "Testing", test_width
, IGNORE_LONG_WORDS
, false, "Testing" },
603 { "X Testing", test_width
, IGNORE_LONG_WORDS
, false, "X|Testing" },
604 { "Test Testing", test_width
, IGNORE_LONG_WORDS
, false, "Test|Testing" },
605 { "Test\nTesting", test_width
, IGNORE_LONG_WORDS
, false, "Test|Testing" },
606 { "Test Tests ", test_width
, IGNORE_LONG_WORDS
, false, "Test|Tests" },
607 { "Test Tests T", test_width
, IGNORE_LONG_WORDS
, false, "Test|Tests|T" },
609 { "Testing", elided_width
, ELIDE_LONG_WORDS
, true, "Tes..." },
610 { "X Testing", elided_width
, ELIDE_LONG_WORDS
, true, "X|Tes..." },
611 { "Test Testing", elided_width
, ELIDE_LONG_WORDS
, true, "Test|Tes..." },
612 { "Test\nTesting", elided_width
, ELIDE_LONG_WORDS
, true, "Test|Tes..." },
614 { "Testing", test_width
, TRUNCATE_LONG_WORDS
, true, "Test" },
615 { "X Testing", test_width
, TRUNCATE_LONG_WORDS
, true, "X|Test" },
616 { "Test Testing", test_width
, TRUNCATE_LONG_WORDS
, true, "Test|Test" },
617 { "Test\nTesting", test_width
, TRUNCATE_LONG_WORDS
, true, "Test|Test" },
618 { "Test Tests ", test_width
, TRUNCATE_LONG_WORDS
, true, "Test|Test" },
619 { "Test Tests T", test_width
, TRUNCATE_LONG_WORDS
, true, "Test|Test|T" },
621 { "Testing", test_width
, WRAP_LONG_WORDS
, false, "Test|ing" },
622 { "X Testing", test_width
, WRAP_LONG_WORDS
, false, "X|Test|ing" },
623 { "Test Testing", test_width
, WRAP_LONG_WORDS
, false, "Test|Test|ing" },
624 { "Test\nTesting", test_width
, WRAP_LONG_WORDS
, false, "Test|Test|ing" },
625 { "Test Tests ", test_width
, WRAP_LONG_WORDS
, false, "Test|Test|s" },
626 { "Test Tests T", test_width
, WRAP_LONG_WORDS
, false, "Test|Test|s T" },
627 { "TestTestTest", test_width
, WRAP_LONG_WORDS
, false, "Test|Test|Test" },
628 { "TestTestTestT", test_width
, WRAP_LONG_WORDS
, false, "Test|Test|Test|T" },
631 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
632 std::vector
<base::string16
> lines
;
633 EXPECT_EQ(cases
[i
].truncated_x
? INSUFFICIENT_SPACE_HORIZONTAL
: 0,
634 ElideRectangleText(UTF8ToUTF16(cases
[i
].input
),
636 cases
[i
].available_pixel_width
,
638 cases
[i
].wrap_behavior
,
640 std::string
expected_output(cases
[i
].output
);
641 ReplaceSubstringsAfterOffset(&expected_output
, 0, "...", kEllipsis
);
642 const std::string result
= UTF16ToUTF8(JoinString(lines
, '|'));
643 EXPECT_EQ(expected_output
, result
) << "Case " << i
<< " failed!";
647 // This test is to make sure that the width of each wrapped line does not
648 // exceed the available width. On some platform like Mac, this test used to
649 // fail because the truncated integer width is returned for the string
650 // and the accumulation of the truncated values causes the elide function
651 // to wrap incorrectly.
652 // TODO(338784): Enable this on android.
653 #if defined(OS_ANDROID)
654 #define MAYBE_ElideRectangleTextCheckLineWidth \
655 DISABLED_ElideRectangleTextCheckLineWidth
657 #define MAYBE_ElideRectangleTextCheckLineWidth ElideRectangleTextCheckLineWidth
659 TEST(TextEliderTest
, MAYBE_ElideRectangleTextCheckLineWidth
) {
661 #if defined(OS_MACOSX) && !defined(OS_IOS)
662 // Use a specific font to expose the line width exceeding problem.
663 font_list
= FontList(Font("LucidaGrande", 12));
665 const float kAvailableWidth
= 235;
666 const int kAvailableHeight
= 1000;
667 const char text
[] = "that Russian place we used to go to after fencing";
668 std::vector
<base::string16
> lines
;
669 EXPECT_EQ(0, ElideRectangleText(UTF8ToUTF16(text
),
675 ASSERT_EQ(2u, lines
.size());
676 EXPECT_LE(GetStringWidthF(lines
[0], font_list
), kAvailableWidth
);
677 EXPECT_LE(GetStringWidthF(lines
[1], font_list
), kAvailableWidth
);
681 // This test was created specifically to test a message from crbug.com/415213.
682 // It tests that width of concatenation of words equals sum of widths of the
684 TEST(TextEliderTest
, ElideRectangleTextCheckConcatWidthEqualsSumOfWidths
) {
686 font_list
= FontList("Noto Sans UI,ui-sans, 12px");
687 SetFontRenderParamsDeviceScaleFactor(1.25f
);
688 #define WIDTH(x) GetStringWidthF(UTF8ToUTF16(x), font_list)
689 EXPECT_EQ(WIDTH("The administrator for this account has"),
690 WIDTH("The ") + WIDTH("administrator ") + WIDTH("for ") +
691 WIDTH("this ") + WIDTH("account ") + WIDTH("has"));
693 SetFontRenderParamsDeviceScaleFactor(1.0f
);
695 #endif // OS_CHROMEOS
697 TEST(TextEliderTest
, ElideRectangleString
) {
705 { "", 0, 0, false, "" },
706 { "", 1, 1, false, "" },
707 { "Hi, my name is\nTom", 0, 0, true, "..." },
708 { "Hi, my name is\nTom", 1, 0, true, "\n..." },
709 { "Hi, my name is\nTom", 0, 1, true, "..." },
710 { "Hi, my name is\nTom", 1, 1, true, "H\n..." },
711 { "Hi, my name is\nTom", 2, 1, true, "H\ni\n..." },
712 { "Hi, my name is\nTom", 3, 1, true, "H\ni\n,\n..." },
713 { "Hi, my name is\nTom", 4, 1, true, "H\ni\n,\n \n..." },
714 { "Hi, my name is\nTom", 5, 1, true, "H\ni\n,\n \nm\n..." },
715 { "Hi, my name is\nTom", 0, 2, true, "..." },
716 { "Hi, my name is\nTom", 1, 2, true, "Hi\n..." },
717 { "Hi, my name is\nTom", 2, 2, true, "Hi\n, \n..." },
718 { "Hi, my name is\nTom", 3, 2, true, "Hi\n, \nmy\n..." },
719 { "Hi, my name is\nTom", 4, 2, true, "Hi\n, \nmy\n n\n..." },
720 { "Hi, my name is\nTom", 5, 2, true, "Hi\n, \nmy\n n\nam\n..." },
721 { "Hi, my name is\nTom", 0, 3, true, "..." },
722 { "Hi, my name is\nTom", 1, 3, true, "Hi,\n..." },
723 { "Hi, my name is\nTom", 2, 3, true, "Hi,\n my\n..." },
724 { "Hi, my name is\nTom", 3, 3, true, "Hi,\n my\n na\n..." },
725 { "Hi, my name is\nTom", 4, 3, true, "Hi,\n my\n na\nme \n..." },
726 { "Hi, my name is\nTom", 5, 3, true, "Hi,\n my\n na\nme \nis\n..." },
727 { "Hi, my name is\nTom", 1, 4, true, "Hi, \n..." },
728 { "Hi, my name is\nTom", 2, 4, true, "Hi, \nmy n\n..." },
729 { "Hi, my name is\nTom", 3, 4, true, "Hi, \nmy n\name \n..." },
730 { "Hi, my name is\nTom", 4, 4, true, "Hi, \nmy n\name \nis\n..." },
731 { "Hi, my name is\nTom", 5, 4, false, "Hi, \nmy n\name \nis\nTom" },
732 { "Hi, my name is\nTom", 1, 5, true, "Hi, \n..." },
733 { "Hi, my name is\nTom", 2, 5, true, "Hi, \nmy na\n..." },
734 { "Hi, my name is\nTom", 3, 5, true, "Hi, \nmy na\nme \n..." },
735 { "Hi, my name is\nTom", 4, 5, true, "Hi, \nmy na\nme \nis\n..." },
736 { "Hi, my name is\nTom", 5, 5, false, "Hi, \nmy na\nme \nis\nTom" },
737 { "Hi, my name is\nTom", 1, 6, true, "Hi, \n..." },
738 { "Hi, my name is\nTom", 2, 6, true, "Hi, \nmy \n..." },
739 { "Hi, my name is\nTom", 3, 6, true, "Hi, \nmy \nname \n..." },
740 { "Hi, my name is\nTom", 4, 6, true, "Hi, \nmy \nname \nis\n..." },
741 { "Hi, my name is\nTom", 5, 6, false, "Hi, \nmy \nname \nis\nTom" },
742 { "Hi, my name is\nTom", 1, 7, true, "Hi, \n..." },
743 { "Hi, my name is\nTom", 2, 7, true, "Hi, \nmy \n..." },
744 { "Hi, my name is\nTom", 3, 7, true, "Hi, \nmy \nname \n..." },
745 { "Hi, my name is\nTom", 4, 7, true, "Hi, \nmy \nname \nis\n..." },
746 { "Hi, my name is\nTom", 5, 7, false, "Hi, \nmy \nname \nis\nTom" },
747 { "Hi, my name is\nTom", 1, 8, true, "Hi, my \n..." },
748 { "Hi, my name is\nTom", 2, 8, true, "Hi, my \nname \n..." },
749 { "Hi, my name is\nTom", 3, 8, true, "Hi, my \nname \nis\n..." },
750 { "Hi, my name is\nTom", 4, 8, false, "Hi, my \nname \nis\nTom" },
751 { "Hi, my name is\nTom", 1, 9, true, "Hi, my \n..." },
752 { "Hi, my name is\nTom", 2, 9, true, "Hi, my \nname is\n..." },
753 { "Hi, my name is\nTom", 3, 9, false, "Hi, my \nname is\nTom" },
754 { "Hi, my name is\nTom", 1, 10, true, "Hi, my \n..." },
755 { "Hi, my name is\nTom", 2, 10, true, "Hi, my \nname is\n..." },
756 { "Hi, my name is\nTom", 3, 10, false, "Hi, my \nname is\nTom" },
757 { "Hi, my name is\nTom", 1, 11, true, "Hi, my \n..." },
758 { "Hi, my name is\nTom", 2, 11, true, "Hi, my \nname is\n..." },
759 { "Hi, my name is\nTom", 3, 11, false, "Hi, my \nname is\nTom" },
760 { "Hi, my name is\nTom", 1, 12, true, "Hi, my \n..." },
761 { "Hi, my name is\nTom", 2, 12, true, "Hi, my \nname is\n..." },
762 { "Hi, my name is\nTom", 3, 12, false, "Hi, my \nname is\nTom" },
763 { "Hi, my name is\nTom", 1, 13, true, "Hi, my name \n..." },
764 { "Hi, my name is\nTom", 2, 13, true, "Hi, my name \nis\n..." },
765 { "Hi, my name is\nTom", 3, 13, false, "Hi, my name \nis\nTom" },
766 { "Hi, my name is\nTom", 1, 20, true, "Hi, my name is\n..." },
767 { "Hi, my name is\nTom", 2, 20, false, "Hi, my name is\nTom" },
768 { "Hi, my name is Tom", 1, 40, false, "Hi, my name is Tom" },
770 base::string16 output
;
771 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
772 EXPECT_EQ(cases
[i
].result
,
773 ElideRectangleString(UTF8ToUTF16(cases
[i
].input
),
774 cases
[i
].max_rows
, cases
[i
].max_cols
,
776 EXPECT_EQ(cases
[i
].output
, UTF16ToUTF8(output
));
780 TEST(TextEliderTest
, ElideRectangleStringNotStrict
) {
788 { "", 0, 0, false, "" },
789 { "", 1, 1, false, "" },
790 { "Hi, my name_is\nDick", 0, 0, true, "..." },
791 { "Hi, my name_is\nDick", 1, 0, true, "\n..." },
792 { "Hi, my name_is\nDick", 0, 1, true, "..." },
793 { "Hi, my name_is\nDick", 1, 1, true, "H\n..." },
794 { "Hi, my name_is\nDick", 2, 1, true, "H\ni\n..." },
795 { "Hi, my name_is\nDick", 3, 1, true, "H\ni\n,\n..." },
796 { "Hi, my name_is\nDick", 4, 1, true, "H\ni\n,\n \n..." },
797 { "Hi, my name_is\nDick", 5, 1, true, "H\ni\n,\n \nm\n..." },
798 { "Hi, my name_is\nDick", 0, 2, true, "..." },
799 { "Hi, my name_is\nDick", 1, 2, true, "Hi\n..." },
800 { "Hi, my name_is\nDick", 2, 2, true, "Hi\n, \n..." },
801 { "Hi, my name_is\nDick", 3, 2, true, "Hi\n, \nmy\n..." },
802 { "Hi, my name_is\nDick", 4, 2, true, "Hi\n, \nmy\n n\n..." },
803 { "Hi, my name_is\nDick", 5, 2, true, "Hi\n, \nmy\n n\nam\n..." },
804 { "Hi, my name_is\nDick", 0, 3, true, "..." },
805 { "Hi, my name_is\nDick", 1, 3, true, "Hi,\n..." },
806 { "Hi, my name_is\nDick", 2, 3, true, "Hi,\n my\n..." },
807 { "Hi, my name_is\nDick", 3, 3, true, "Hi,\n my\n na\n..." },
808 { "Hi, my name_is\nDick", 4, 3, true, "Hi,\n my\n na\nme_\n..." },
809 { "Hi, my name_is\nDick", 5, 3, true, "Hi,\n my\n na\nme_\nis\n..." },
810 { "Hi, my name_is\nDick", 1, 4, true, "Hi, ..." },
811 { "Hi, my name_is\nDick", 2, 4, true, "Hi, my n\n..." },
812 { "Hi, my name_is\nDick", 3, 4, true, "Hi, my n\name_\n..." },
813 { "Hi, my name_is\nDick", 4, 4, true, "Hi, my n\name_\nis\n..." },
814 { "Hi, my name_is\nDick", 5, 4, false, "Hi, my n\name_\nis\nDick" },
815 { "Hi, my name_is\nDick", 1, 5, true, "Hi, ..." },
816 { "Hi, my name_is\nDick", 2, 5, true, "Hi, my na\n..." },
817 { "Hi, my name_is\nDick", 3, 5, true, "Hi, my na\nme_is\n..." },
818 { "Hi, my name_is\nDick", 4, 5, true, "Hi, my na\nme_is\n\n..." },
819 { "Hi, my name_is\nDick", 5, 5, false, "Hi, my na\nme_is\n\nDick" },
820 { "Hi, my name_is\nDick", 1, 6, true, "Hi, ..." },
821 { "Hi, my name_is\nDick", 2, 6, true, "Hi, my nam\n..." },
822 { "Hi, my name_is\nDick", 3, 6, true, "Hi, my nam\ne_is\n..." },
823 { "Hi, my name_is\nDick", 4, 6, false, "Hi, my nam\ne_is\nDick" },
824 { "Hi, my name_is\nDick", 5, 6, false, "Hi, my nam\ne_is\nDick" },
825 { "Hi, my name_is\nDick", 1, 7, true, "Hi, ..." },
826 { "Hi, my name_is\nDick", 2, 7, true, "Hi, my name\n..." },
827 { "Hi, my name_is\nDick", 3, 7, true, "Hi, my name\n_is\n..." },
828 { "Hi, my name_is\nDick", 4, 7, false, "Hi, my name\n_is\nDick" },
829 { "Hi, my name_is\nDick", 5, 7, false, "Hi, my name\n_is\nDick" },
830 { "Hi, my name_is\nDick", 1, 8, true, "Hi, my n\n..." },
831 { "Hi, my name_is\nDick", 2, 8, true, "Hi, my n\name_is\n..." },
832 { "Hi, my name_is\nDick", 3, 8, false, "Hi, my n\name_is\nDick" },
833 { "Hi, my name_is\nDick", 1, 9, true, "Hi, my ..." },
834 { "Hi, my name_is\nDick", 2, 9, true, "Hi, my name_is\n..." },
835 { "Hi, my name_is\nDick", 3, 9, false, "Hi, my name_is\nDick" },
836 { "Hi, my name_is\nDick", 1, 10, true, "Hi, my ..." },
837 { "Hi, my name_is\nDick", 2, 10, true, "Hi, my name_is\n..." },
838 { "Hi, my name_is\nDick", 3, 10, false, "Hi, my name_is\nDick" },
839 { "Hi, my name_is\nDick", 1, 11, true, "Hi, my ..." },
840 { "Hi, my name_is\nDick", 2, 11, true, "Hi, my name_is\n..." },
841 { "Hi, my name_is\nDick", 3, 11, false, "Hi, my name_is\nDick" },
842 { "Hi, my name_is\nDick", 1, 12, true, "Hi, my ..." },
843 { "Hi, my name_is\nDick", 2, 12, true, "Hi, my name_is\n..." },
844 { "Hi, my name_is\nDick", 3, 12, false, "Hi, my name_is\nDick" },
845 { "Hi, my name_is\nDick", 1, 13, true, "Hi, my ..." },
846 { "Hi, my name_is\nDick", 2, 13, true, "Hi, my name_is\n..." },
847 { "Hi, my name_is\nDick", 3, 13, false, "Hi, my name_is\nDick" },
848 { "Hi, my name_is\nDick", 1, 20, true, "Hi, my name_is\n..." },
849 { "Hi, my name_is\nDick", 2, 20, false, "Hi, my name_is\nDick" },
850 { "Hi, my name_is Dick", 1, 40, false, "Hi, my name_is Dick" },
852 base::string16 output
;
853 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
854 EXPECT_EQ(cases
[i
].result
,
855 ElideRectangleString(UTF8ToUTF16(cases
[i
].input
),
856 cases
[i
].max_rows
, cases
[i
].max_cols
,
858 EXPECT_EQ(cases
[i
].output
, UTF16ToUTF8(output
));
862 TEST(TextEliderTest
, ElideRectangleWide16
) {
863 // Two greek words separated by space.
864 const base::string16
str(WideToUTF16(
865 L
"\x03a0\x03b1\x03b3\x03ba\x03cc\x03c3\x03bc\x03b9"
866 L
"\x03bf\x03c2\x0020\x0399\x03c3\x03c4\x03cc\x03c2"));
867 const base::string16
out1(WideToUTF16(
868 L
"\x03a0\x03b1\x03b3\x03ba\n"
869 L
"\x03cc\x03c3\x03bc\x03b9\n"
871 const base::string16
out2(WideToUTF16(
872 L
"\x03a0\x03b1\x03b3\x03ba\x03cc\x03c3\x03bc\x03b9\x03bf\x03c2\x0020\n"
873 L
"\x0399\x03c3\x03c4\x03cc\x03c2"));
874 base::string16 output
;
875 EXPECT_TRUE(ElideRectangleString(str
, 2, 4, true, &output
));
876 EXPECT_EQ(out1
, output
);
877 EXPECT_FALSE(ElideRectangleString(str
, 2, 12, true, &output
));
878 EXPECT_EQ(out2
, output
);
881 TEST(TextEliderTest
, ElideRectangleWide32
) {
882 // Four U+1D49C MATHEMATICAL SCRIPT CAPITAL A followed by space "aaaaa".
883 const base::string16
str(UTF8ToUTF16(
884 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C"
886 const base::string16
out(UTF8ToUTF16(
887 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\n"
888 "\xF0\x9D\x92\x9C \naaa\n..."));
889 base::string16 output
;
890 EXPECT_TRUE(ElideRectangleString(str
, 3, 3, true, &output
));
891 EXPECT_EQ(out
, output
);
894 TEST(TextEliderTest
, TruncateString
) {
895 base::string16 string
= ASCIIToUTF16("foooooey bxxxar baz");
897 // Tests that apply to both break behaviors:
899 // Make sure it doesn't modify the string if length > string length.
900 EXPECT_EQ(string
, TruncateString(string
, 100, WORD_BREAK
));
901 EXPECT_EQ(string
, TruncateString(string
, 100, CHARACTER_BREAK
));
903 // Test no characters.
904 EXPECT_EQ(L
"", UTF16ToWide(TruncateString(string
, 0, WORD_BREAK
)));
905 EXPECT_EQ(L
"", UTF16ToWide(TruncateString(string
, 0, CHARACTER_BREAK
)));
908 EXPECT_EQ(L
"\x2026", UTF16ToWide(TruncateString(string
, 1, WORD_BREAK
)));
909 EXPECT_EQ(L
"\x2026", UTF16ToWide(TruncateString(string
, 1, CHARACTER_BREAK
)));
911 // Test completely truncates string if break is on initial whitespace.
913 UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2, WORD_BREAK
)));
915 UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2,
918 // Break-only-at-word-boundaries tests:
920 // Test adds ... at right spot when there is enough room to break at a
922 EXPECT_EQ(L
"foooooey\x2026", UTF16ToWide(TruncateString(string
, 14,
925 // Test adds ... at right spot when there is not enough space in first word.
926 EXPECT_EQ(L
"f\x2026", UTF16ToWide(TruncateString(string
, 2, WORD_BREAK
)));
928 // Test adds ... at right spot when there is not enough room to break at a
930 EXPECT_EQ(L
"foooooey\x2026", UTF16ToWide(TruncateString(string
, 11,
933 // Break-anywhere tests:
935 // Test adds ... at right spot within a word.
936 EXPECT_EQ(L
"f\x2026", UTF16ToWide(TruncateString(string
, 2,
939 // Test removes trailing whitespace if break falls between words.
940 EXPECT_EQ(L
"foooooey\x2026", UTF16ToWide(TruncateString(string
, 12,