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

Side by Side Diff: ui/gfx/text_elider_unittest.cc

Issue 24883002: Uses and returns the fractional width in text eliding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix per feedbacks Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
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/gfx/text_elider.h" 7 #include "ui/gfx/text_elider.h"
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/font.h" 15 #include "ui/gfx/font.h"
16 #include "ui/gfx/font_list.h"
17 #include "ui/gfx/text_utils.h"
16 #include "url/gurl.h" 18 #include "url/gurl.h"
17 19
18 namespace gfx { 20 namespace gfx {
19 21
20 namespace { 22 namespace {
21 23
22 struct Testcase { 24 struct Testcase {
23 const std::string input; 25 const std::string input;
24 const std::string output; 26 const std::string output;
25 }; 27 };
26 28
27 struct FileTestcase { 29 struct FileTestcase {
28 const base::FilePath::StringType input; 30 const base::FilePath::StringType input;
29 const std::string output; 31 const std::string output;
30 }; 32 };
31 33
32 struct UTF16Testcase { 34 struct UTF16Testcase {
33 const string16 input; 35 const string16 input;
34 const string16 output; 36 const string16 output;
35 }; 37 };
36 38
37 struct TestData { 39 struct TestData {
38 const std::string a; 40 const std::string a;
39 const std::string b; 41 const std::string b;
40 const int compare_result; 42 const int compare_result;
41 }; 43 };
42 44
43 void RunUrlTest(Testcase* testcases, size_t num_testcases) { 45 void RunUrlTest(Testcase* testcases, size_t num_testcases) {
44 static const gfx::Font font; 46 static const gfx::FontList font_list;
45 for (size_t i = 0; i < num_testcases; ++i) { 47 for (size_t i = 0; i < num_testcases; ++i) {
46 const GURL url(testcases[i].input); 48 const GURL url(testcases[i].input);
47 // Should we test with non-empty language list? 49 // Should we test with non-empty language list?
48 // That's kinda redundant with net_util_unittests. 50 // That's kinda redundant with net_util_unittests.
49 EXPECT_EQ(UTF8ToUTF16(testcases[i].output), 51 EXPECT_EQ(
50 ElideUrl(url, font, 52 UTF8ToUTF16(testcases[i].output),
51 font.GetStringWidth(UTF8ToUTF16(testcases[i].output)), 53 ElideUrl(
52 std::string())); 54 url,
55 font_list,
56 GetStringWidthF(UTF8ToUTF16(testcases[i].output), font_list),
Alexei Svitkine (slow) 2013/10/07 23:33:28 Nit: Move this to a local variable, so that the EX
jianli 2013/10/08 00:01:18 Done.
57 std::string()));
53 } 58 }
54 } 59 }
55 60
56 gfx::Font GetTestingFont() {
57 gfx::Font font;
58 #if defined(OS_MACOSX)
59 // Use a specific font for certain tests on Mac.
60 // 1) Different Mac machines might be configured with different default font.
61 // The number of extra pixels needed to make ElideEmail/TestFilenameEliding
62 // tests work might vary per the default font.
63 // 2) This specific font helps expose the line width exceeding problem as in
64 // ElideRectangleTextCheckLineWidth.
65 font = gfx::Font("LucidaGrande", 12);
66 #endif
67 return font;
68 }
69
70 } // namespace 61 } // namespace
71 62
72 // TODO(ios): Complex eliding is off by one for some of those tests on iOS. 63 // TODO(ios): This test fails on iOS because iOS version of gfx::GetStringWidthF
73 // See crbug.com/154019 64 // that calls [NSString sizeWithFont] returns the rounded string width.
74 #if defined(OS_IOS) 65 #if defined(OS_IOS)
75 #define MAYBE_ElideEmail DISABLED_ElideEmail 66 #define MAYBE_ElideEmail DISABLED_ElideEmail
76 #else 67 #else
77 #define MAYBE_ElideEmail ElideEmail 68 #define MAYBE_ElideEmail ElideEmail
78 #endif 69 #endif
79 TEST(TextEliderTest, MAYBE_ElideEmail) { 70 TEST(TextEliderTest, MAYBE_ElideEmail) {
80 const std::string kEllipsisStr(kEllipsis); 71 const std::string kEllipsisStr(kEllipsis);
81 72
82 // Test emails and their expected elided forms (from which the available 73 // Test emails and their expected elided forms (from which the available
83 // widths will be derived). 74 // widths will be derived).
(...skipping 30 matching lines...) Expand all
114 "noca" + kEllipsisStr + "@no" + kEllipsisStr + "ca"}, 105 "noca" + kEllipsisStr + "@no" + kEllipsisStr + "ca"},
115 {"at\"@@@@@@@@@...@@.@.@.@@@\"@madness.com", 106 {"at\"@@@@@@@@@...@@.@.@.@@@\"@madness.com",
116 "at\"@@@@@@@@@...@@.@." + kEllipsisStr + "@madness.com"}, 107 "at\"@@@@@@@@@...@@.@." + kEllipsisStr + "@madness.com"},
117 // Special case: "m..." takes more than half of the available width; thus 108 // Special case: "m..." takes more than half of the available width; thus
118 // the domain must elide to "l..." and not "l...l" as it must allow enough 109 // the domain must elide to "l..." and not "l...l" as it must allow enough
119 // space for the minimal username elision although its half of the 110 // space for the minimal username elision although its half of the
120 // available width would normally allow it to elide to "l...l". 111 // available width would normally allow it to elide to "l...l".
121 {"mmmmm@llllllllll", "m" + kEllipsisStr + "@l" + kEllipsisStr}, 112 {"mmmmm@llllllllll", "m" + kEllipsisStr + "@l" + kEllipsisStr},
122 }; 113 };
123 114
124 const gfx::Font font = GetTestingFont(); 115 const gfx::FontList font_list;
125 for (size_t i = 0; i < arraysize(testcases); ++i) { 116 for (size_t i = 0; i < arraysize(testcases); ++i) {
126 const string16 expected_output = UTF8ToUTF16(testcases[i].output); 117 const string16 expected_output = UTF8ToUTF16(testcases[i].output);
127 int available_width = font.GetStringWidth(expected_output);
128 #if defined(OS_MACOSX)
129 // Give two extra pixels to offset the ceiling width returned by
130 // GetStringWidth on Mac. This workaround will no longer be needed once
131 // the floating point width is adopted (http://crbug.com/288987).
132 // Note that we need one more pixel than TestFilenameEliding because
133 // multiple strings are elided and we need to offset more.
134 available_width += 2;
135 #endif
136 EXPECT_EQ(expected_output, 118 EXPECT_EQ(expected_output,
137 ElideEmail(UTF8ToUTF16(testcases[i].input), 119 ElideEmail(
138 font, 120 UTF8ToUTF16(testcases[i].input),
139 available_width)); 121 font_list,
122 gfx::GetStringWidthF(expected_output, font_list)));
Alexei Svitkine (slow) 2013/10/07 23:33:28 Nit: No need for gfx::. Please fix throughout this
jianli 2013/10/08 00:01:18 Done.
140 } 123 }
141 } 124 }
142 125
143 TEST(TextEliderTest, ElideEmailMoreSpace) { 126 TEST(TextEliderTest, ElideEmailMoreSpace) {
144 const int test_width_factors[] = { 127 const int test_width_factors[] = {
145 100, 128 100,
146 10000, 129 10000,
147 1000000, 130 1000000,
148 }; 131 };
149 const std::string test_emails[] = { 132 const std::string test_emails[] = {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 175 }
193 176
194 // When there is very little space available, the elision code will shorten 177 // When there is very little space available, the elision code will shorten
195 // both path AND file name to an ellipsis - ".../...". To avoid this result, 178 // both path AND file name to an ellipsis - ".../...". To avoid this result,
196 // there is a hack in place that simply treats them as one string in this 179 // there is a hack in place that simply treats them as one string in this
197 // case. 180 // case.
198 TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) { 181 TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) {
199 const std::string kEllipsisStr(kEllipsis); 182 const std::string kEllipsisStr(kEllipsis);
200 183
201 // Very little space, would cause double ellipsis. 184 // Very little space, would cause double ellipsis.
202 gfx::Font font; 185 gfx::FontList font_list;
203 GURL url("http://battersbox.com/directory/foo/peter_paul_and_mary.html"); 186 GURL url("http://battersbox.com/directory/foo/peter_paul_and_mary.html");
204 int available_width = font.GetStringWidth( 187 float available_width = gfx::GetStringWidthF(
205 UTF8ToUTF16("battersbox.com/" + kEllipsisStr + "/" + kEllipsisStr)); 188 UTF8ToUTF16("battersbox.com/" + kEllipsisStr + "/" + kEllipsisStr),
189 font_list);
206 190
207 // Create the expected string, after elision. Depending on font size, the 191 // Create the expected string, after elision. Depending on font size, the
208 // directory might become /dir... or /di... or/d... - it never should be 192 // directory might become /dir... or /di... or/d... - it never should be
209 // shorter than that. (If it is, the font considers d... to be longer 193 // shorter than that. (If it is, the font considers d... to be longer
210 // than .../... - that should never happen). 194 // than .../... - that should never happen).
211 ASSERT_GT(font.GetStringWidth(UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr)), 195 ASSERT_GT(
212 font.GetStringWidth(UTF8ToUTF16("d" + kEllipsisStr))); 196 gfx::GetStringWidthF(UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr),
197 font_list),
198 gfx::GetStringWidthF(UTF8ToUTF16("d" + kEllipsisStr), font_list));
213 GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc"); 199 GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc");
214 string16 expected = ElideUrl(long_url, font, available_width, std::string()); 200 string16 expected =
201 ElideUrl(long_url, font_list, available_width, std::string());
215 // Ensure that the expected result still contains part of the directory name. 202 // Ensure that the expected result still contains part of the directory name.
216 ASSERT_GT(expected.length(), std::string("battersbox.com/d").length()); 203 ASSERT_GT(expected.length(), std::string("battersbox.com/d").length());
217 EXPECT_EQ(expected, 204 EXPECT_EQ(expected,
218 ElideUrl(url, font, available_width, std::string())); 205 ElideUrl(url, font_list, available_width, std::string()));
219 206
220 // More space available - elide directories, partially elide filename. 207 // More space available - elide directories, partially elide filename.
221 Testcase testcases[] = { 208 Testcase testcases[] = {
222 {"http://battersbox.com/directory/foo/peter_paul_and_mary.html", 209 {"http://battersbox.com/directory/foo/peter_paul_and_mary.html",
223 "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr}, 210 "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr},
224 }; 211 };
225 RunUrlTest(testcases, arraysize(testcases)); 212 RunUrlTest(testcases, arraysize(testcases));
226 } 213 }
227 214
228 // Test eliding of empty strings, URLs with ports, passwords, queries, etc. 215 // Test eliding of empty strings, URLs with ports, passwords, queries, etc.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 "C:/" + kEllipsisStr + "/filename"}, 268 "C:/" + kEllipsisStr + "/filename"},
282 #endif 269 #endif
283 {"file://filer/foo/bar/file", "filer/foo/bar/file"}, 270 {"file://filer/foo/bar/file", "filer/foo/bar/file"},
284 {"file://filer/foo/bar/file", "filer/foo/" + kEllipsisStr + "/file"}, 271 {"file://filer/foo/bar/file", "filer/foo/" + kEllipsisStr + "/file"},
285 {"file://filer/foo/bar/file", "filer/" + kEllipsisStr + "/file"}, 272 {"file://filer/foo/bar/file", "filer/" + kEllipsisStr + "/file"},
286 }; 273 };
287 274
288 RunUrlTest(testcases, arraysize(testcases)); 275 RunUrlTest(testcases, arraysize(testcases));
289 } 276 }
290 277
291 // TODO(ios): Complex eliding is off by one for some of those tests on iOS. 278 // TODO(ios): This test fails on iOS because iOS version of gfx::GetStringWidthF
292 // See crbug.com/154019 279 // that calls [NSString sizeWithFont] returns the rounded string width.
293 #if defined(OS_IOS) 280 #if defined(OS_IOS)
294 #define MAYBE_TestFilenameEliding DISABLED_TestFilenameEliding 281 #define MAYBE_TestFilenameEliding DISABLED_TestFilenameEliding
295 #else 282 #else
296 #define MAYBE_TestFilenameEliding TestFilenameEliding 283 #define MAYBE_TestFilenameEliding TestFilenameEliding
297 #endif 284 #endif
298 TEST(TextEliderTest, MAYBE_TestFilenameEliding) { 285 TEST(TextEliderTest, MAYBE_TestFilenameEliding) {
299 const std::string kEllipsisStr(kEllipsis); 286 const std::string kEllipsisStr(kEllipsis);
300 const base::FilePath::StringType kPathSeparator = 287 const base::FilePath::StringType kPathSeparator =
301 base::FilePath::StringType().append(1, base::FilePath::kSeparators[0]); 288 base::FilePath::StringType().append(1, base::FilePath::kSeparators[0]);
302 289
(...skipping 24 matching lines...) Expand all
327 {FILE_PATH_LITERAL("filename.middleext.longext"), 314 {FILE_PATH_LITERAL("filename.middleext.longext"),
328 "filename.mid" + kEllipsisStr + ".longext"}, 315 "filename.mid" + kEllipsisStr + ".longext"},
329 {FILE_PATH_LITERAL("filename.superduperextremelylongext"), 316 {FILE_PATH_LITERAL("filename.superduperextremelylongext"),
330 "filename.sup" + kEllipsisStr + "emelylongext"}, 317 "filename.sup" + kEllipsisStr + "emelylongext"},
331 {FILE_PATH_LITERAL("filenamereallylongtext.superduperextremelylongext"), 318 {FILE_PATH_LITERAL("filenamereallylongtext.superduperextremelylongext"),
332 "filenamereall" + kEllipsisStr + "emelylongext"}, 319 "filenamereall" + kEllipsisStr + "emelylongext"},
333 {FILE_PATH_LITERAL("file.name.really.long.text.superduperextremelylongext"), 320 {FILE_PATH_LITERAL("file.name.really.long.text.superduperextremelylongext"),
334 "file.name.re" + kEllipsisStr + "emelylongext"} 321 "file.name.re" + kEllipsisStr + "emelylongext"}
335 }; 322 };
336 323
337 static const gfx::Font font = GetTestingFont(); 324 static const gfx::FontList font_list;
338 for (size_t i = 0; i < arraysize(testcases); ++i) { 325 for (size_t i = 0; i < arraysize(testcases); ++i) {
339 base::FilePath filepath(testcases[i].input); 326 base::FilePath filepath(testcases[i].input);
340 string16 expected = UTF8ToUTF16(testcases[i].output); 327 string16 expected = UTF8ToUTF16(testcases[i].output);
341 expected = base::i18n::GetDisplayStringInLTRDirectionality(expected); 328 expected = base::i18n::GetDisplayStringInLTRDirectionality(expected);
342 int available_width = font.GetStringWidth(UTF8ToUTF16(testcases[i].output)); 329 EXPECT_EQ(expected, ElideFilename(filepath, font_list,
343 #if defined(OS_MACOSX) 330 gfx::GetStringWidthF(UTF8ToUTF16(testcases[i].output), font_list)));
344 // Give one extra pixel to offset the ceiling width returned by
345 // GetStringWidth on Mac. This workaround will no longer be needed once
346 // the floating point width is adopted (http://crbug.com/288987).
347 available_width += 1;
348 #endif
349 EXPECT_EQ(expected, ElideFilename(filepath, font, available_width));
350 } 331 }
351 } 332 }
352 333
353 TEST(TextEliderTest, ElideTextTruncate) { 334 TEST(TextEliderTest, ElideTextTruncate) {
354 const gfx::Font font; 335 const gfx::FontList font_list;
355 const int kTestWidth = font.GetStringWidth(ASCIIToUTF16("Test")); 336 const float kTestWidth =
337 gfx::GetStringWidthF(ASCIIToUTF16("Test"), font_list);
356 struct TestData { 338 struct TestData {
357 const char* input; 339 const char* input;
358 int width; 340 float width;
359 const char* output; 341 const char* output;
360 } cases[] = { 342 } cases[] = {
361 { "", 0, "" }, 343 { "", 0, "" },
362 { "Test", 0, "" }, 344 { "Test", 0, "" },
363 { "", kTestWidth, "" }, 345 { "", kTestWidth, "" },
364 { "Tes", kTestWidth, "Tes" }, 346 { "Tes", kTestWidth, "Tes" },
365 { "Test", kTestWidth, "Test" }, 347 { "Test", kTestWidth, "Test" },
366 { "Tests", kTestWidth, "Test" }, 348 { "Tests", kTestWidth, "Test" },
367 }; 349 };
368 350
369 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 351 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
370 string16 result = ElideText(UTF8ToUTF16(cases[i].input), font, 352 string16 result = ElideText(UTF8ToUTF16(cases[i].input), font_list,
371 cases[i].width, TRUNCATE_AT_END); 353 cases[i].width, TRUNCATE_AT_END);
372 EXPECT_EQ(cases[i].output, UTF16ToUTF8(result)); 354 EXPECT_EQ(cases[i].output, UTF16ToUTF8(result));
373 } 355 }
374 } 356 }
375 357
376 TEST(TextEliderTest, ElideTextEllipsis) { 358 TEST(TextEliderTest, ElideTextEllipsis) {
377 const gfx::Font font; 359 const gfx::FontList font_list;
378 const int kTestWidth = font.GetStringWidth(ASCIIToUTF16("Test")); 360 const float kTestWidth =
361 gfx::GetStringWidthF(ASCIIToUTF16("Test"), font_list);
379 const char* kEllipsis = "\xE2\x80\xA6"; 362 const char* kEllipsis = "\xE2\x80\xA6";
380 const int kEllipsisWidth = font.GetStringWidth(UTF8ToUTF16(kEllipsis)); 363 const float kEllipsisWidth =
364 gfx::GetStringWidthF(UTF8ToUTF16(kEllipsis), font_list);
381 struct TestData { 365 struct TestData {
382 const char* input; 366 const char* input;
383 int width; 367 float width;
384 const char* output; 368 const char* output;
385 } cases[] = { 369 } cases[] = {
386 { "", 0, "" }, 370 { "", 0, "" },
387 { "Test", 0, "" }, 371 { "Test", 0, "" },
388 { "Test", kEllipsisWidth, kEllipsis }, 372 { "Test", kEllipsisWidth, kEllipsis },
389 { "", kTestWidth, "" }, 373 { "", kTestWidth, "" },
390 { "Tes", kTestWidth, "Tes" }, 374 { "Tes", kTestWidth, "Tes" },
391 { "Test", kTestWidth, "Test" }, 375 { "Test", kTestWidth, "Test" },
392 }; 376 };
393 377
394 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 378 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
395 string16 result = ElideText(UTF8ToUTF16(cases[i].input), font, 379 string16 result = ElideText(UTF8ToUTF16(cases[i].input), font_list,
396 cases[i].width, ELIDE_AT_END); 380 cases[i].width, ELIDE_AT_END);
397 EXPECT_EQ(cases[i].output, UTF16ToUTF8(result)); 381 EXPECT_EQ(cases[i].output, UTF16ToUTF8(result));
398 } 382 }
399 } 383 }
400 384
401 // Checks that all occurrences of |first_char| are followed by |second_char| and 385 // Checks that all occurrences of |first_char| are followed by |second_char| and
402 // all occurrences of |second_char| are preceded by |first_char| in |text|. 386 // all occurrences of |second_char| are preceded by |first_char| in |text|.
403 static void CheckSurrogatePairs(const string16& text, 387 static void CheckSurrogatePairs(const string16& text,
404 char16 first_char, 388 char16 first_char,
405 char16 second_char) { 389 char16 second_char) {
406 size_t index = text.find_first_of(first_char); 390 size_t index = text.find_first_of(first_char);
407 while (index != string16::npos) { 391 while (index != string16::npos) {
408 EXPECT_LT(index, text.length() - 1); 392 EXPECT_LT(index, text.length() - 1);
409 EXPECT_EQ(second_char, text[index + 1]); 393 EXPECT_EQ(second_char, text[index + 1]);
410 index = text.find_first_of(first_char, index + 1); 394 index = text.find_first_of(first_char, index + 1);
411 } 395 }
412 index = text.find_first_of(second_char); 396 index = text.find_first_of(second_char);
413 while (index != string16::npos) { 397 while (index != string16::npos) {
414 EXPECT_GT(index, 0U); 398 EXPECT_GT(index, 0U);
415 EXPECT_EQ(first_char, text[index - 1]); 399 EXPECT_EQ(first_char, text[index - 1]);
416 index = text.find_first_of(second_char, index + 1); 400 index = text.find_first_of(second_char, index + 1);
417 } 401 }
418 } 402 }
419 403
420 TEST(TextEliderTest, ElideTextSurrogatePairs) { 404 TEST(TextEliderTest, ElideTextSurrogatePairs) {
421 const gfx::Font font; 405 const gfx::FontList font_list;
422 // The below is 'MUSICAL SYMBOL G CLEF', which is represented in UTF-16 as 406 // The below is 'MUSICAL SYMBOL G CLEF', which is represented in UTF-16 as
423 // two characters forming a surrogate pair 0x0001D11E. 407 // two characters forming a surrogate pair 0x0001D11E.
424 const std::string kSurrogate = "\xF0\x9D\x84\x9E"; 408 const std::string kSurrogate = "\xF0\x9D\x84\x9E";
425 const string16 kTestString = 409 const string16 kTestString =
426 UTF8ToUTF16(kSurrogate + "ab" + kSurrogate + kSurrogate + "cd"); 410 UTF8ToUTF16(kSurrogate + "ab" + kSurrogate + kSurrogate + "cd");
427 const int kTestStringWidth = font.GetStringWidth(kTestString); 411 const float kTestStringWidth = gfx::GetStringWidthF(kTestString, font_list);
428 const char16 kSurrogateFirstChar = kTestString[0]; 412 const char16 kSurrogateFirstChar = kTestString[0];
429 const char16 kSurrogateSecondChar = kTestString[1]; 413 const char16 kSurrogateSecondChar = kTestString[1];
430 string16 result; 414 string16 result;
431 415
432 // Elide |kTextString| to all possible widths and check that no instance of 416 // Elide |kTextString| to all possible widths and check that no instance of
433 // |kSurrogate| was split in two. 417 // |kSurrogate| was split in two.
434 for (int width = 0; width <= kTestStringWidth; width++) { 418 for (float width = 0; width <= kTestStringWidth; width++) {
435 result = ElideText(kTestString, font, width, TRUNCATE_AT_END); 419 result = ElideText(kTestString, font_list, width, TRUNCATE_AT_END);
436 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar); 420 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar);
437 421
438 result = ElideText(kTestString, font, width, ELIDE_AT_END); 422 result = ElideText(kTestString, font_list, width, ELIDE_AT_END);
439 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar); 423 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar);
440 424
441 result = ElideText(kTestString, font, width, ELIDE_IN_MIDDLE); 425 result = ElideText(kTestString, font_list, width, ELIDE_IN_MIDDLE);
442 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar); 426 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar);
443 } 427 }
444 } 428 }
445 429
446 TEST(TextEliderTest, ElideTextLongStrings) { 430 TEST(TextEliderTest, ElideTextLongStrings) {
447 const string16 kEllipsisStr = UTF8ToUTF16(kEllipsis); 431 const string16 kEllipsisStr = UTF8ToUTF16(kEllipsis);
448 string16 data_scheme(UTF8ToUTF16("data:text/plain,")); 432 string16 data_scheme(UTF8ToUTF16("data:text/plain,"));
449 size_t data_scheme_length = data_scheme.length(); 433 size_t data_scheme_length = data_scheme.length();
450 434
451 string16 ten_a(10, 'a'); 435 string16 ten_a(10, 'a');
452 string16 hundred_a(100, 'a'); 436 string16 hundred_a(100, 'a');
453 string16 thousand_a(1000, 'a'); 437 string16 thousand_a(1000, 'a');
454 string16 ten_thousand_a(10000, 'a'); 438 string16 ten_thousand_a(10000, 'a');
455 string16 hundred_thousand_a(100000, 'a'); 439 string16 hundred_thousand_a(100000, 'a');
456 string16 million_a(1000000, 'a'); 440 string16 million_a(1000000, 'a');
457 441
458 size_t number_of_as = 156; 442 size_t number_of_as = 156;
459 string16 long_string_end( 443 string16 long_string_end(
460 data_scheme + string16(number_of_as, 'a') + kEllipsisStr); 444 data_scheme + string16(number_of_as, 'a') + kEllipsisStr);
461 UTF16Testcase testcases_end[] = { 445 UTF16Testcase testcases_end[] = {
462 {data_scheme + ten_a, data_scheme + ten_a}, 446 {data_scheme + ten_a, data_scheme + ten_a},
463 {data_scheme + hundred_a, data_scheme + hundred_a}, 447 {data_scheme + hundred_a, data_scheme + hundred_a},
464 {data_scheme + thousand_a, long_string_end}, 448 {data_scheme + thousand_a, long_string_end},
465 {data_scheme + ten_thousand_a, long_string_end}, 449 {data_scheme + ten_thousand_a, long_string_end},
466 {data_scheme + hundred_thousand_a, long_string_end}, 450 {data_scheme + hundred_thousand_a, long_string_end},
467 {data_scheme + million_a, long_string_end}, 451 {data_scheme + million_a, long_string_end},
468 }; 452 };
469 453
470 const gfx::Font font; 454 const gfx::FontList font_list;
471 int ellipsis_width = font.GetStringWidth(kEllipsisStr); 455 float ellipsis_width = gfx::GetStringWidthF(kEllipsisStr, font_list);
472 for (size_t i = 0; i < arraysize(testcases_end); ++i) { 456 for (size_t i = 0; i < arraysize(testcases_end); ++i) {
473 // Compare sizes rather than actual contents because if the test fails, 457 // Compare sizes rather than actual contents because if the test fails,
474 // output is rather long. 458 // output is rather long.
475 EXPECT_EQ(testcases_end[i].output.size(), 459 EXPECT_EQ(testcases_end[i].output.size(),
476 ElideText(testcases_end[i].input, font, 460 ElideText(
477 font.GetStringWidth(testcases_end[i].output), 461 testcases_end[i].input,
478 ELIDE_AT_END).size()); 462 font_list,
463 gfx::GetStringWidthF(testcases_end[i].output, font_list),
464 ELIDE_AT_END).size());
479 EXPECT_EQ(kEllipsisStr, 465 EXPECT_EQ(kEllipsisStr,
480 ElideText(testcases_end[i].input, font, ellipsis_width, 466 ElideText(testcases_end[i].input, font_list, ellipsis_width,
481 ELIDE_AT_END)); 467 ELIDE_AT_END));
482 } 468 }
483 469
484 size_t number_of_trailing_as = (data_scheme_length + number_of_as) / 2; 470 size_t number_of_trailing_as = (data_scheme_length + number_of_as) / 2;
485 string16 long_string_middle(data_scheme + 471 string16 long_string_middle(data_scheme +
486 string16(number_of_as - number_of_trailing_as, 'a') + kEllipsisStr + 472 string16(number_of_as - number_of_trailing_as, 'a') + kEllipsisStr +
487 string16(number_of_trailing_as, 'a')); 473 string16(number_of_trailing_as, 'a'));
488 UTF16Testcase testcases_middle[] = { 474 UTF16Testcase testcases_middle[] = {
489 {data_scheme + ten_a, data_scheme + ten_a}, 475 {data_scheme + ten_a, data_scheme + ten_a},
490 {data_scheme + hundred_a, data_scheme + hundred_a}, 476 {data_scheme + hundred_a, data_scheme + hundred_a},
491 {data_scheme + thousand_a, long_string_middle}, 477 {data_scheme + thousand_a, long_string_middle},
492 {data_scheme + ten_thousand_a, long_string_middle}, 478 {data_scheme + ten_thousand_a, long_string_middle},
493 {data_scheme + hundred_thousand_a, long_string_middle}, 479 {data_scheme + hundred_thousand_a, long_string_middle},
494 {data_scheme + million_a, long_string_middle}, 480 {data_scheme + million_a, long_string_middle},
495 }; 481 };
496 482
497 for (size_t i = 0; i < arraysize(testcases_middle); ++i) { 483 for (size_t i = 0; i < arraysize(testcases_middle); ++i) {
498 // Compare sizes rather than actual contents because if the test fails, 484 // Compare sizes rather than actual contents because if the test fails,
499 // output is rather long. 485 // output is rather long.
500 EXPECT_EQ(testcases_middle[i].output.size(), 486 EXPECT_EQ(testcases_middle[i].output.size(),
501 ElideText(testcases_middle[i].input, font, 487 ElideText(
502 font.GetStringWidth(testcases_middle[i].output), 488 testcases_middle[i].input,
503 ELIDE_AT_END).size()); 489 font_list,
490 gfx::GetStringWidthF(testcases_middle[i].output, font_list),
491 ELIDE_AT_END).size());
504 EXPECT_EQ(kEllipsisStr, 492 EXPECT_EQ(kEllipsisStr,
505 ElideText(testcases_middle[i].input, font, ellipsis_width, 493 ElideText(testcases_middle[i].input, font_list, ellipsis_width,
506 ELIDE_AT_END)); 494 ELIDE_AT_END));
507 } 495 }
508 } 496 }
509 497
510 // Verifies display_url is set correctly. 498 // Verifies display_url is set correctly.
511 TEST(TextEliderTest, SortedDisplayURL) { 499 TEST(TextEliderTest, SortedDisplayURL) {
512 SortedDisplayURL d_url(GURL("http://www.google.com"), std::string()); 500 SortedDisplayURL d_url(GURL("http://www.google.com"), std::string());
513 EXPECT_EQ("www.google.com", UTF16ToASCII(d_url.display_url())); 501 EXPECT_EQ("www.google.com", UTF16ToASCII(d_url.display_url()));
514 } 502 }
515 503
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 561 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
574 string16 output; 562 string16 output;
575 EXPECT_EQ(cases[i].result, 563 EXPECT_EQ(cases[i].result,
576 ElideString(UTF8ToUTF16(cases[i].input), 564 ElideString(UTF8ToUTF16(cases[i].input),
577 cases[i].max_len, &output)); 565 cases[i].max_len, &output));
578 EXPECT_EQ(cases[i].output, UTF16ToUTF8(output)); 566 EXPECT_EQ(cases[i].output, UTF16ToUTF8(output));
579 } 567 }
580 } 568 }
581 569
582 TEST(TextEliderTest, ElideRectangleText) { 570 TEST(TextEliderTest, ElideRectangleText) {
583 const gfx::Font font; 571 const gfx::FontList font_list;
584 const int line_height = font.GetHeight(); 572 const int line_height = font_list.GetHeight();
585 const int test_width = font.GetStringWidth(ASCIIToUTF16("Test")); 573 const float test_width =
574 gfx::GetStringWidthF(ASCIIToUTF16("Test"), font_list);
586 575
587 struct TestData { 576 struct TestData {
588 const char* input; 577 const char* input;
589 int available_pixel_width; 578 float available_pixel_width;
590 int available_pixel_height; 579 int available_pixel_height;
591 bool truncated_y; 580 bool truncated_y;
592 const char* output; 581 const char* output;
593 } cases[] = { 582 } cases[] = {
594 { "", 0, 0, false, NULL }, 583 { "", 0, 0, false, NULL },
595 { "", 1, 1, false, NULL }, 584 { "", 1, 1, false, NULL },
596 { "Test", test_width, 0, true, NULL }, 585 { "Test", test_width, 0, true, NULL },
597 { "Test", test_width, 1, false, "Test" }, 586 { "Test", test_width, 1, false, "Test" },
598 { "Test", test_width, line_height, false, "Test" }, 587 { "Test", test_width, line_height, false, "Test" },
599 { "Test Test", test_width, line_height, true, "Test" }, 588 { "Test Test", test_width, line_height, true, "Test" },
(...skipping 15 matching lines...) Expand all
615 { "Test\n\nTest\n", 2 * test_width, line_height * 5, false, "Test||Test|" }, 604 { "Test\n\nTest\n", 2 * test_width, line_height * 5, false, "Test||Test|" },
616 { "Test\n\n\nTest", 2 * test_width, line_height * 5, false, "Test|||Test" }, 605 { "Test\n\n\nTest", 2 * test_width, line_height * 5, false, "Test|||Test" },
617 { "Te ", test_width, line_height, false, "Te" }, 606 { "Te ", test_width, line_height, false, "Te" },
618 { "Te Te Test", test_width, 3 * line_height, false, "Te|Te|Test" }, 607 { "Te Te Test", test_width, 3 * line_height, false, "Te|Te|Test" },
619 }; 608 };
620 609
621 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 610 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
622 std::vector<string16> lines; 611 std::vector<string16> lines;
623 EXPECT_EQ(cases[i].truncated_y ? INSUFFICIENT_SPACE_VERTICAL : 0, 612 EXPECT_EQ(cases[i].truncated_y ? INSUFFICIENT_SPACE_VERTICAL : 0,
624 ElideRectangleText(UTF8ToUTF16(cases[i].input), 613 ElideRectangleText(UTF8ToUTF16(cases[i].input),
625 font, 614 font_list,
626 cases[i].available_pixel_width, 615 cases[i].available_pixel_width,
627 cases[i].available_pixel_height, 616 cases[i].available_pixel_height,
628 TRUNCATE_LONG_WORDS, 617 TRUNCATE_LONG_WORDS,
629 &lines)); 618 &lines));
630 if (cases[i].output) { 619 if (cases[i].output) {
631 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); 620 const std::string result = UTF16ToUTF8(JoinString(lines, '|'));
632 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; 621 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!";
633 } else { 622 } else {
634 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!"; 623 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!";
635 } 624 }
636 } 625 }
637 } 626 }
638 627
639 TEST(TextEliderTest, ElideRectangleTextPunctuation) { 628 TEST(TextEliderTest, ElideRectangleTextPunctuation) {
640 const gfx::Font font; 629 const gfx::FontList font_list;
641 const int line_height = font.GetHeight(); 630 const int line_height = font_list.GetHeight();
642 const int test_width = font.GetStringWidth(ASCIIToUTF16("Test")); 631 const float test_width =
643 const int test_t_width = font.GetStringWidth(ASCIIToUTF16("Test T")); 632 gfx::GetStringWidthF(ASCIIToUTF16("Test"), font_list);
633 const float test_t_width =
634 gfx::GetStringWidthF(ASCIIToUTF16("Test T"), font_list);
644 635
645 struct TestData { 636 struct TestData {
646 const char* input; 637 const char* input;
647 int available_pixel_width; 638 float available_pixel_width;
648 int available_pixel_height; 639 int available_pixel_height;
649 bool wrap_words; 640 bool wrap_words;
650 bool truncated_x; 641 bool truncated_x;
651 const char* output; 642 const char* output;
652 } cases[] = { 643 } cases[] = {
653 { "Test T.", test_t_width, line_height * 2, false, false, "Test|T." }, 644 { "Test T.", test_t_width, line_height * 2, false, false, "Test|T." },
654 { "Test T ?", test_t_width, line_height * 2, false, false, "Test|T ?" }, 645 { "Test T ?", test_t_width, line_height * 2, false, false, "Test|T ?" },
655 { "Test. Test", test_width, line_height * 3, false, true, "Test|Test" }, 646 { "Test. Test", test_width, line_height * 3, false, true, "Test|Test" },
656 { "Test. Test", test_width, line_height * 3, true, false, "Test|.|Test" }, 647 { "Test. Test", test_width, line_height * 3, true, false, "Test|.|Test" },
657 }; 648 };
658 649
659 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 650 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
660 std::vector<string16> lines; 651 std::vector<string16> lines;
661 const WordWrapBehavior wrap_behavior = 652 const WordWrapBehavior wrap_behavior =
662 (cases[i].wrap_words ? WRAP_LONG_WORDS : TRUNCATE_LONG_WORDS); 653 (cases[i].wrap_words ? WRAP_LONG_WORDS : TRUNCATE_LONG_WORDS);
663 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, 654 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0,
664 ElideRectangleText(UTF8ToUTF16(cases[i].input), 655 ElideRectangleText(UTF8ToUTF16(cases[i].input),
665 font, 656 font_list,
666 cases[i].available_pixel_width, 657 cases[i].available_pixel_width,
667 cases[i].available_pixel_height, 658 cases[i].available_pixel_height,
668 wrap_behavior, 659 wrap_behavior,
669 &lines)); 660 &lines));
670 if (cases[i].output) { 661 if (cases[i].output) {
671 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); 662 const std::string result = UTF16ToUTF8(JoinString(lines, '|'));
672 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; 663 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!";
673 } else { 664 } else {
674 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!"; 665 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!";
675 } 666 }
676 } 667 }
677 } 668 }
678 669
679 TEST(TextEliderTest, ElideRectangleTextLongWords) { 670 TEST(TextEliderTest, ElideRectangleTextLongWords) {
680 const gfx::Font font; 671 const gfx::FontList font_list;
681 const int kAvailableHeight = 1000; 672 const int kAvailableHeight = 1000;
682 const string16 kElidedTesting = UTF8ToUTF16(std::string("Tes") + kEllipsis); 673 const string16 kElidedTesting = UTF8ToUTF16(std::string("Tes") + kEllipsis);
683 const int elided_width = font.GetStringWidth(kElidedTesting); 674 const float elided_width = gfx::GetStringWidthF(kElidedTesting, font_list);
684 const int test_width = font.GetStringWidth(ASCIIToUTF16("Test")); 675 const float test_width =
676 gfx::GetStringWidthF(ASCIIToUTF16("Test"), font_list);
685 677
686 struct TestData { 678 struct TestData {
687 const char* input; 679 const char* input;
688 int available_pixel_width; 680 float available_pixel_width;
689 WordWrapBehavior wrap_behavior; 681 WordWrapBehavior wrap_behavior;
690 bool truncated_x; 682 bool truncated_x;
691 const char* output; 683 const char* output;
692 } cases[] = { 684 } cases[] = {
693 { "Testing", test_width, IGNORE_LONG_WORDS, false, "Testing" }, 685 { "Testing", test_width, IGNORE_LONG_WORDS, false, "Testing" },
694 { "X Testing", test_width, IGNORE_LONG_WORDS, false, "X|Testing" }, 686 { "X Testing", test_width, IGNORE_LONG_WORDS, false, "X|Testing" },
695 { "Test Testing", test_width, IGNORE_LONG_WORDS, false, "Test|Testing" }, 687 { "Test Testing", test_width, IGNORE_LONG_WORDS, false, "Test|Testing" },
696 { "Test\nTesting", test_width, IGNORE_LONG_WORDS, false, "Test|Testing" }, 688 { "Test\nTesting", test_width, IGNORE_LONG_WORDS, false, "Test|Testing" },
697 { "Test Tests ", test_width, IGNORE_LONG_WORDS, false, "Test|Tests" }, 689 { "Test Tests ", test_width, IGNORE_LONG_WORDS, false, "Test|Tests" },
698 { "Test Tests T", test_width, IGNORE_LONG_WORDS, false, "Test|Tests|T" }, 690 { "Test Tests T", test_width, IGNORE_LONG_WORDS, false, "Test|Tests|T" },
(...skipping 17 matching lines...) Expand all
716 { "Test Tests ", test_width, WRAP_LONG_WORDS, false, "Test|Test|s" }, 708 { "Test Tests ", test_width, WRAP_LONG_WORDS, false, "Test|Test|s" },
717 { "Test Tests T", test_width, WRAP_LONG_WORDS, false, "Test|Test|s T" }, 709 { "Test Tests T", test_width, WRAP_LONG_WORDS, false, "Test|Test|s T" },
718 { "TestTestTest", test_width, WRAP_LONG_WORDS, false, "Test|Test|Test" }, 710 { "TestTestTest", test_width, WRAP_LONG_WORDS, false, "Test|Test|Test" },
719 { "TestTestTestT", test_width, WRAP_LONG_WORDS, false, "Test|Test|Test|T" }, 711 { "TestTestTestT", test_width, WRAP_LONG_WORDS, false, "Test|Test|Test|T" },
720 }; 712 };
721 713
722 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 714 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
723 std::vector<string16> lines; 715 std::vector<string16> lines;
724 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, 716 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0,
725 ElideRectangleText(UTF8ToUTF16(cases[i].input), 717 ElideRectangleText(UTF8ToUTF16(cases[i].input),
726 font, 718 font_list,
727 cases[i].available_pixel_width, 719 cases[i].available_pixel_width,
728 kAvailableHeight, 720 kAvailableHeight,
729 cases[i].wrap_behavior, 721 cases[i].wrap_behavior,
730 &lines)); 722 &lines));
731 std::string expected_output(cases[i].output); 723 std::string expected_output(cases[i].output);
732 ReplaceSubstringsAfterOffset(&expected_output, 0, "...", kEllipsis); 724 ReplaceSubstringsAfterOffset(&expected_output, 0, "...", kEllipsis);
733 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); 725 const std::string result = UTF16ToUTF8(JoinString(lines, '|'));
734 EXPECT_EQ(expected_output, result) << "Case " << i << " failed!"; 726 EXPECT_EQ(expected_output, result) << "Case " << i << " failed!";
735 } 727 }
736 } 728 }
737 729
738 // TODO(ios): Complex eliding is off by one for some of those tests on iOS.
739 // See crbug.com/154019
740 #if defined(OS_IOS)
741 #define MAYBE_ElideRectangleTextCheckLineWidth \
742 DISABLED_ElideRectangleTextCheckLineWidth
743 #else
744 #define MAYBE_ElideRectangleTextCheckLineWidth ElideRectangleTextCheckLineWidth
745 #endif
746
747 // This test is to make sure that the width of each wrapped line does not 730 // This test is to make sure that the width of each wrapped line does not
748 // exceed the available width. On some platform like Mac, this test used to 731 // exceed the available width. On some platform like Mac, this test used to
749 // fail because the truncated integer width is returned for the string 732 // fail because the truncated integer width is returned for the string
750 // and the accumulation of the truncated values causes the elide function 733 // and the accumulation of the truncated values causes the elide function
751 // to wrap incorrectly. 734 // to wrap incorrectly.
752 TEST(TextEliderTest, MAYBE_ElideRectangleTextCheckLineWidth) { 735 TEST(TextEliderTest, ElideRectangleTextCheckLineWidth) {
753 gfx::Font font = GetTestingFont(); 736 gfx::FontList font_list;
754 const int kAvailableWidth = 235; 737 #if defined(OS_MACOSX) && !defined(OS_IOS)
738 // Use a specific font to expose the line width exceeding problem.
739 font_list = gfx::FontList(gfx::Font("LucidaGrande", 12));
740 #endif
741 const float kAvailableWidth = 235;
755 const int kAvailableHeight = 1000; 742 const int kAvailableHeight = 1000;
756 const char text[] = "that Russian place we used to go to after fencing"; 743 const char text[] = "that Russian place we used to go to after fencing";
757 std::vector<string16> lines; 744 std::vector<string16> lines;
758 EXPECT_EQ(0, ElideRectangleText(UTF8ToUTF16(text), 745 EXPECT_EQ(0, ElideRectangleText(UTF8ToUTF16(text),
759 font, 746 font_list,
760 kAvailableWidth, 747 kAvailableWidth,
761 kAvailableHeight, 748 kAvailableHeight,
762 WRAP_LONG_WORDS, 749 WRAP_LONG_WORDS,
763 &lines)); 750 &lines));
764 ASSERT_EQ(2u, lines.size()); 751 ASSERT_EQ(2u, lines.size());
765 EXPECT_LE(font.GetStringWidth(lines[0]), kAvailableWidth); 752 EXPECT_LE(gfx::GetStringWidthF(lines[0], font_list), kAvailableWidth);
766 EXPECT_LE(font.GetStringWidth(lines[1]), kAvailableWidth); 753 EXPECT_LE(gfx::GetStringWidthF(lines[1], font_list), kAvailableWidth);
767 } 754 }
768 755
769 TEST(TextEliderTest, ElideRectangleString) { 756 TEST(TextEliderTest, ElideRectangleString) {
770 struct TestData { 757 struct TestData {
771 const char* input; 758 const char* input;
772 int max_rows; 759 int max_rows;
773 int max_cols; 760 int max_cols;
774 bool result; 761 bool result;
775 const char* output; 762 const char* output;
776 } cases[] = { 763 } cases[] = {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 971
985 // Test adds ... at right spot when there is not enough room to break at a 972 // Test adds ... at right spot when there is not enough room to break at a
986 // word boundary. 973 // word boundary.
987 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); 974 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11)));
988 975
989 // Test completely truncates string if break is on initial whitespace. 976 // Test completely truncates string if break is on initial whitespace.
990 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); 977 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2)));
991 } 978 }
992 979
993 } // namespace gfx 980 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698