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/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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 const std::string input; | 25 const std::string input; |
26 const std::string output; | 26 const std::string output; |
27 }; | 27 }; |
28 | 28 |
29 struct FileTestcase { | 29 struct FileTestcase { |
30 const base::FilePath::StringType input; | 30 const base::FilePath::StringType input; |
31 const std::string output; | 31 const std::string output; |
32 }; | 32 }; |
33 | 33 |
34 struct UTF16Testcase { | 34 struct UTF16Testcase { |
35 const string16 input; | 35 const base::string16 input; |
36 const string16 output; | 36 const base::string16 output; |
37 }; | 37 }; |
38 | 38 |
39 struct TestData { | 39 struct TestData { |
40 const std::string a; | 40 const std::string a; |
41 const std::string b; | 41 const std::string b; |
42 const int compare_result; | 42 const int compare_result; |
43 }; | 43 }; |
44 | 44 |
45 void RunUrlTest(Testcase* testcases, size_t num_testcases) { | 45 void RunUrlTest(Testcase* testcases, size_t num_testcases) { |
46 static const FontList font_list; | 46 static const FontList font_list; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 "at\"@@@@@@@@@...@@.@." + kEllipsisStr + "@madness.com"}, | 104 "at\"@@@@@@@@@...@@.@." + kEllipsisStr + "@madness.com"}, |
105 // Special case: "m..." takes more than half of the available width; thus | 105 // Special case: "m..." takes more than half of the available width; thus |
106 // the domain must elide to "l..." and not "l...l" as it must allow enough | 106 // the domain must elide to "l..." and not "l...l" as it must allow enough |
107 // space for the minimal username elision although its half of the | 107 // space for the minimal username elision although its half of the |
108 // available width would normally allow it to elide to "l...l". | 108 // available width would normally allow it to elide to "l...l". |
109 {"mmmmm@llllllllll", "m" + kEllipsisStr + "@l" + kEllipsisStr}, | 109 {"mmmmm@llllllllll", "m" + kEllipsisStr + "@l" + kEllipsisStr}, |
110 }; | 110 }; |
111 | 111 |
112 const FontList font_list; | 112 const FontList font_list; |
113 for (size_t i = 0; i < arraysize(testcases); ++i) { | 113 for (size_t i = 0; i < arraysize(testcases); ++i) { |
114 const string16 expected_output = UTF8ToUTF16(testcases[i].output); | 114 const base::string16 expected_output = UTF8ToUTF16(testcases[i].output); |
115 EXPECT_EQ(expected_output, | 115 EXPECT_EQ(expected_output, |
116 ElideEmail( | 116 ElideEmail( |
117 UTF8ToUTF16(testcases[i].input), | 117 UTF8ToUTF16(testcases[i].input), |
118 font_list, | 118 font_list, |
119 GetStringWidthF(expected_output, font_list))); | 119 GetStringWidthF(expected_output, font_list))); |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 TEST(TextEliderTest, ElideEmailMoreSpace) { | 123 TEST(TextEliderTest, ElideEmailMoreSpace) { |
124 const int test_width_factors[] = { | 124 const int test_width_factors[] = { |
125 100, | 125 100, |
126 10000, | 126 10000, |
127 1000000, | 127 1000000, |
128 }; | 128 }; |
129 const std::string test_emails[] = { | 129 const std::string test_emails[] = { |
130 "a@c", | 130 "a@c", |
131 "test@email.com", | 131 "test@email.com", |
132 "short@verysuperdupperlongdomain.com", | 132 "short@verysuperdupperlongdomain.com", |
133 "supermegalongusername@withasuperlonnnggggdomain.gouv.qc.ca", | 133 "supermegalongusername@withasuperlonnnggggdomain.gouv.qc.ca", |
134 }; | 134 }; |
135 | 135 |
136 const FontList font_list; | 136 const FontList font_list; |
137 for (size_t i = 0; i < arraysize(test_width_factors); ++i) { | 137 for (size_t i = 0; i < arraysize(test_width_factors); ++i) { |
138 const int test_width = | 138 const int test_width = |
139 font_list.GetExpectedTextWidth(test_width_factors[i]); | 139 font_list.GetExpectedTextWidth(test_width_factors[i]); |
140 for (size_t j = 0; j < arraysize(test_emails); ++j) { | 140 for (size_t j = 0; j < arraysize(test_emails); ++j) { |
141 // Extra space is available: the email should not be elided. | 141 // Extra space is available: the email should not be elided. |
142 const string16 test_email = UTF8ToUTF16(test_emails[j]); | 142 const base::string16 test_email = UTF8ToUTF16(test_emails[j]); |
143 EXPECT_EQ(test_email, ElideEmail(test_email, font_list, test_width)); | 143 EXPECT_EQ(test_email, ElideEmail(test_email, font_list, test_width)); |
144 } | 144 } |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 // Test eliding of commonplace URLs. | 148 // Test eliding of commonplace URLs. |
149 TEST(TextEliderTest, TestGeneralEliding) { | 149 TEST(TextEliderTest, TestGeneralEliding) { |
150 const std::string kEllipsisStr(kEllipsis); | 150 const std::string kEllipsisStr(kEllipsis); |
151 Testcase testcases[] = { | 151 Testcase testcases[] = { |
152 {"http://www.google.com/intl/en/ads/", | 152 {"http://www.google.com/intl/en/ads/", |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 font_list); | 186 font_list); |
187 | 187 |
188 // Create the expected string, after elision. Depending on font size, the | 188 // Create the expected string, after elision. Depending on font size, the |
189 // directory might become /dir... or /di... or/d... - it never should be | 189 // directory might become /dir... or /di... or/d... - it never should be |
190 // shorter than that. (If it is, the font considers d... to be longer | 190 // shorter than that. (If it is, the font considers d... to be longer |
191 // than .../... - that should never happen). | 191 // than .../... - that should never happen). |
192 ASSERT_GT(GetStringWidthF(UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr), | 192 ASSERT_GT(GetStringWidthF(UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr), |
193 font_list), | 193 font_list), |
194 GetStringWidthF(UTF8ToUTF16("d" + kEllipsisStr), font_list)); | 194 GetStringWidthF(UTF8ToUTF16("d" + kEllipsisStr), font_list)); |
195 GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc"); | 195 GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc"); |
196 string16 expected = | 196 base::string16 expected = |
197 ElideUrl(long_url, font_list, available_width, std::string()); | 197 ElideUrl(long_url, font_list, available_width, std::string()); |
198 // Ensure that the expected result still contains part of the directory name. | 198 // Ensure that the expected result still contains part of the directory name. |
199 ASSERT_GT(expected.length(), std::string("battersbox.com/d").length()); | 199 ASSERT_GT(expected.length(), std::string("battersbox.com/d").length()); |
200 EXPECT_EQ(expected, | 200 EXPECT_EQ(expected, |
201 ElideUrl(url, font_list, available_width, std::string())); | 201 ElideUrl(url, font_list, available_width, std::string())); |
202 | 202 |
203 // More space available - elide directories, partially elide filename. | 203 // More space available - elide directories, partially elide filename. |
204 Testcase testcases[] = { | 204 Testcase testcases[] = { |
205 {"http://battersbox.com/directory/foo/peter_paul_and_mary.html", | 205 {"http://battersbox.com/directory/foo/peter_paul_and_mary.html", |
206 "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr}, | 206 "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr}, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 "filename.sup" + kEllipsisStr + "emelylongext"}, | 313 "filename.sup" + kEllipsisStr + "emelylongext"}, |
314 {FILE_PATH_LITERAL("filenamereallylongtext.superduperextremelylongext"), | 314 {FILE_PATH_LITERAL("filenamereallylongtext.superduperextremelylongext"), |
315 "filenamereall" + kEllipsisStr + "emelylongext"}, | 315 "filenamereall" + kEllipsisStr + "emelylongext"}, |
316 {FILE_PATH_LITERAL("file.name.really.long.text.superduperextremelylongext"), | 316 {FILE_PATH_LITERAL("file.name.really.long.text.superduperextremelylongext"), |
317 "file.name.re" + kEllipsisStr + "emelylongext"} | 317 "file.name.re" + kEllipsisStr + "emelylongext"} |
318 }; | 318 }; |
319 | 319 |
320 static const FontList font_list; | 320 static const FontList font_list; |
321 for (size_t i = 0; i < arraysize(testcases); ++i) { | 321 for (size_t i = 0; i < arraysize(testcases); ++i) { |
322 base::FilePath filepath(testcases[i].input); | 322 base::FilePath filepath(testcases[i].input); |
323 string16 expected = UTF8ToUTF16(testcases[i].output); | 323 base::string16 expected = UTF8ToUTF16(testcases[i].output); |
324 expected = base::i18n::GetDisplayStringInLTRDirectionality(expected); | 324 expected = base::i18n::GetDisplayStringInLTRDirectionality(expected); |
325 EXPECT_EQ(expected, ElideFilename(filepath, font_list, | 325 EXPECT_EQ(expected, ElideFilename(filepath, font_list, |
326 GetStringWidthF(UTF8ToUTF16(testcases[i].output), font_list))); | 326 GetStringWidthF(UTF8ToUTF16(testcases[i].output), font_list))); |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 TEST(TextEliderTest, ElideTextTruncate) { | 330 TEST(TextEliderTest, ElideTextTruncate) { |
331 const FontList font_list; | 331 const FontList font_list; |
332 const float kTestWidth = GetStringWidthF(ASCIIToUTF16("Test"), font_list); | 332 const float kTestWidth = GetStringWidthF(ASCIIToUTF16("Test"), font_list); |
333 struct TestData { | 333 struct TestData { |
334 const char* input; | 334 const char* input; |
335 float width; | 335 float width; |
336 const char* output; | 336 const char* output; |
337 } cases[] = { | 337 } cases[] = { |
338 { "", 0, "" }, | 338 { "", 0, "" }, |
339 { "Test", 0, "" }, | 339 { "Test", 0, "" }, |
340 { "", kTestWidth, "" }, | 340 { "", kTestWidth, "" }, |
341 { "Tes", kTestWidth, "Tes" }, | 341 { "Tes", kTestWidth, "Tes" }, |
342 { "Test", kTestWidth, "Test" }, | 342 { "Test", kTestWidth, "Test" }, |
343 { "Tests", kTestWidth, "Test" }, | 343 { "Tests", kTestWidth, "Test" }, |
344 }; | 344 }; |
345 | 345 |
346 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 346 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
347 string16 result = ElideText(UTF8ToUTF16(cases[i].input), font_list, | 347 base::string16 result = ElideText(UTF8ToUTF16(cases[i].input), font_list, |
348 cases[i].width, TRUNCATE_AT_END); | 348 cases[i].width, TRUNCATE_AT_END); |
349 EXPECT_EQ(cases[i].output, UTF16ToUTF8(result)); | 349 EXPECT_EQ(cases[i].output, UTF16ToUTF8(result)); |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 TEST(TextEliderTest, ElideTextEllipsis) { | 353 TEST(TextEliderTest, ElideTextEllipsis) { |
354 const FontList font_list; | 354 const FontList font_list; |
355 const float kTestWidth = GetStringWidthF(ASCIIToUTF16("Test"), font_list); | 355 const float kTestWidth = GetStringWidthF(ASCIIToUTF16("Test"), font_list); |
356 const char* kEllipsis = "\xE2\x80\xA6"; | 356 const char* kEllipsis = "\xE2\x80\xA6"; |
357 const float kEllipsisWidth = | 357 const float kEllipsisWidth = |
358 GetStringWidthF(UTF8ToUTF16(kEllipsis), font_list); | 358 GetStringWidthF(UTF8ToUTF16(kEllipsis), font_list); |
359 struct TestData { | 359 struct TestData { |
360 const char* input; | 360 const char* input; |
361 float width; | 361 float width; |
362 const char* output; | 362 const char* output; |
363 } cases[] = { | 363 } cases[] = { |
364 { "", 0, "" }, | 364 { "", 0, "" }, |
365 { "Test", 0, "" }, | 365 { "Test", 0, "" }, |
366 { "Test", kEllipsisWidth, kEllipsis }, | 366 { "Test", kEllipsisWidth, kEllipsis }, |
367 { "", kTestWidth, "" }, | 367 { "", kTestWidth, "" }, |
368 { "Tes", kTestWidth, "Tes" }, | 368 { "Tes", kTestWidth, "Tes" }, |
369 { "Test", kTestWidth, "Test" }, | 369 { "Test", kTestWidth, "Test" }, |
370 }; | 370 }; |
371 | 371 |
372 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 372 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
373 string16 result = ElideText(UTF8ToUTF16(cases[i].input), font_list, | 373 base::string16 result = ElideText(UTF8ToUTF16(cases[i].input), font_list, |
374 cases[i].width, ELIDE_AT_END); | 374 cases[i].width, ELIDE_AT_END); |
375 EXPECT_EQ(cases[i].output, UTF16ToUTF8(result)); | 375 EXPECT_EQ(cases[i].output, UTF16ToUTF8(result)); |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 // Checks that all occurrences of |first_char| are followed by |second_char| and | 379 // Checks that all occurrences of |first_char| are followed by |second_char| and |
380 // all occurrences of |second_char| are preceded by |first_char| in |text|. | 380 // all occurrences of |second_char| are preceded by |first_char| in |text|. |
381 static void CheckSurrogatePairs(const string16& text, | 381 static void CheckSurrogatePairs(const base::string16& text, |
382 char16 first_char, | 382 char16 first_char, |
383 char16 second_char) { | 383 char16 second_char) { |
384 size_t index = text.find_first_of(first_char); | 384 size_t index = text.find_first_of(first_char); |
385 while (index != string16::npos) { | 385 while (index != base::string16::npos) { |
386 EXPECT_LT(index, text.length() - 1); | 386 EXPECT_LT(index, text.length() - 1); |
387 EXPECT_EQ(second_char, text[index + 1]); | 387 EXPECT_EQ(second_char, text[index + 1]); |
388 index = text.find_first_of(first_char, index + 1); | 388 index = text.find_first_of(first_char, index + 1); |
389 } | 389 } |
390 index = text.find_first_of(second_char); | 390 index = text.find_first_of(second_char); |
391 while (index != string16::npos) { | 391 while (index != base::string16::npos) { |
392 EXPECT_GT(index, 0U); | 392 EXPECT_GT(index, 0U); |
393 EXPECT_EQ(first_char, text[index - 1]); | 393 EXPECT_EQ(first_char, text[index - 1]); |
394 index = text.find_first_of(second_char, index + 1); | 394 index = text.find_first_of(second_char, index + 1); |
395 } | 395 } |
396 } | 396 } |
397 | 397 |
398 TEST(TextEliderTest, ElideTextSurrogatePairs) { | 398 TEST(TextEliderTest, ElideTextSurrogatePairs) { |
399 const FontList font_list; | 399 const FontList font_list; |
400 // The below is 'MUSICAL SYMBOL G CLEF', which is represented in UTF-16 as | 400 // The below is 'MUSICAL SYMBOL G CLEF', which is represented in UTF-16 as |
401 // two characters forming a surrogate pair 0x0001D11E. | 401 // two characters forming a surrogate pair 0x0001D11E. |
402 const std::string kSurrogate = "\xF0\x9D\x84\x9E"; | 402 const std::string kSurrogate = "\xF0\x9D\x84\x9E"; |
403 const string16 kTestString = | 403 const base::string16 kTestString = |
404 UTF8ToUTF16(kSurrogate + "ab" + kSurrogate + kSurrogate + "cd"); | 404 UTF8ToUTF16(kSurrogate + "ab" + kSurrogate + kSurrogate + "cd"); |
405 const float kTestStringWidth = GetStringWidthF(kTestString, font_list); | 405 const float kTestStringWidth = GetStringWidthF(kTestString, font_list); |
406 const char16 kSurrogateFirstChar = kTestString[0]; | 406 const char16 kSurrogateFirstChar = kTestString[0]; |
407 const char16 kSurrogateSecondChar = kTestString[1]; | 407 const char16 kSurrogateSecondChar = kTestString[1]; |
408 string16 result; | 408 base::string16 result; |
409 | 409 |
410 // Elide |kTextString| to all possible widths and check that no instance of | 410 // Elide |kTextString| to all possible widths and check that no instance of |
411 // |kSurrogate| was split in two. | 411 // |kSurrogate| was split in two. |
412 for (float width = 0; width <= kTestStringWidth; width++) { | 412 for (float width = 0; width <= kTestStringWidth; width++) { |
413 result = ElideText(kTestString, font_list, width, TRUNCATE_AT_END); | 413 result = ElideText(kTestString, font_list, width, TRUNCATE_AT_END); |
414 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar); | 414 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar); |
415 | 415 |
416 result = ElideText(kTestString, font_list, width, ELIDE_AT_END); | 416 result = ElideText(kTestString, font_list, width, ELIDE_AT_END); |
417 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar); | 417 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar); |
418 | 418 |
419 result = ElideText(kTestString, font_list, width, ELIDE_IN_MIDDLE); | 419 result = ElideText(kTestString, font_list, width, ELIDE_IN_MIDDLE); |
420 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar); | 420 CheckSurrogatePairs(result, kSurrogateFirstChar, kSurrogateSecondChar); |
421 } | 421 } |
422 } | 422 } |
423 | 423 |
424 TEST(TextEliderTest, ElideTextLongStrings) { | 424 TEST(TextEliderTest, ElideTextLongStrings) { |
425 const string16 kEllipsisStr = UTF8ToUTF16(kEllipsis); | 425 const base::string16 kEllipsisStr = UTF8ToUTF16(kEllipsis); |
426 string16 data_scheme(UTF8ToUTF16("data:text/plain,")); | 426 base::string16 data_scheme(UTF8ToUTF16("data:text/plain,")); |
427 size_t data_scheme_length = data_scheme.length(); | 427 size_t data_scheme_length = data_scheme.length(); |
428 | 428 |
429 string16 ten_a(10, 'a'); | 429 base::string16 ten_a(10, 'a'); |
430 string16 hundred_a(100, 'a'); | 430 base::string16 hundred_a(100, 'a'); |
431 string16 thousand_a(1000, 'a'); | 431 base::string16 thousand_a(1000, 'a'); |
432 string16 ten_thousand_a(10000, 'a'); | 432 base::string16 ten_thousand_a(10000, 'a'); |
433 string16 hundred_thousand_a(100000, 'a'); | 433 base::string16 hundred_thousand_a(100000, 'a'); |
434 string16 million_a(1000000, 'a'); | 434 base::string16 million_a(1000000, 'a'); |
435 | 435 |
436 size_t number_of_as = 156; | 436 size_t number_of_as = 156; |
437 string16 long_string_end( | 437 base::string16 long_string_end( |
438 data_scheme + string16(number_of_as, 'a') + kEllipsisStr); | 438 data_scheme + base::string16(number_of_as, 'a') + kEllipsisStr); |
439 UTF16Testcase testcases_end[] = { | 439 UTF16Testcase testcases_end[] = { |
440 {data_scheme + ten_a, data_scheme + ten_a}, | 440 {data_scheme + ten_a, data_scheme + ten_a}, |
441 {data_scheme + hundred_a, data_scheme + hundred_a}, | 441 {data_scheme + hundred_a, data_scheme + hundred_a}, |
442 {data_scheme + thousand_a, long_string_end}, | 442 {data_scheme + thousand_a, long_string_end}, |
443 {data_scheme + ten_thousand_a, long_string_end}, | 443 {data_scheme + ten_thousand_a, long_string_end}, |
444 {data_scheme + hundred_thousand_a, long_string_end}, | 444 {data_scheme + hundred_thousand_a, long_string_end}, |
445 {data_scheme + million_a, long_string_end}, | 445 {data_scheme + million_a, long_string_end}, |
446 }; | 446 }; |
447 | 447 |
448 const FontList font_list; | 448 const FontList font_list; |
449 float ellipsis_width = GetStringWidthF(kEllipsisStr, font_list); | 449 float ellipsis_width = GetStringWidthF(kEllipsisStr, font_list); |
450 for (size_t i = 0; i < arraysize(testcases_end); ++i) { | 450 for (size_t i = 0; i < arraysize(testcases_end); ++i) { |
451 // Compare sizes rather than actual contents because if the test fails, | 451 // Compare sizes rather than actual contents because if the test fails, |
452 // output is rather long. | 452 // output is rather long. |
453 EXPECT_EQ(testcases_end[i].output.size(), | 453 EXPECT_EQ(testcases_end[i].output.size(), |
454 ElideText( | 454 ElideText( |
455 testcases_end[i].input, | 455 testcases_end[i].input, |
456 font_list, | 456 font_list, |
457 GetStringWidthF(testcases_end[i].output, font_list), | 457 GetStringWidthF(testcases_end[i].output, font_list), |
458 ELIDE_AT_END).size()); | 458 ELIDE_AT_END).size()); |
459 EXPECT_EQ(kEllipsisStr, | 459 EXPECT_EQ(kEllipsisStr, |
460 ElideText(testcases_end[i].input, font_list, ellipsis_width, | 460 ElideText(testcases_end[i].input, font_list, ellipsis_width, |
461 ELIDE_AT_END)); | 461 ELIDE_AT_END)); |
462 } | 462 } |
463 | 463 |
464 size_t number_of_trailing_as = (data_scheme_length + number_of_as) / 2; | 464 size_t number_of_trailing_as = (data_scheme_length + number_of_as) / 2; |
465 string16 long_string_middle(data_scheme + | 465 base::string16 long_string_middle(data_scheme + |
466 string16(number_of_as - number_of_trailing_as, 'a') + kEllipsisStr + | 466 base::string16(number_of_as - number_of_trailing_as, 'a') + kEllipsisStr + |
467 string16(number_of_trailing_as, 'a')); | 467 base::string16(number_of_trailing_as, 'a')); |
468 UTF16Testcase testcases_middle[] = { | 468 UTF16Testcase testcases_middle[] = { |
469 {data_scheme + ten_a, data_scheme + ten_a}, | 469 {data_scheme + ten_a, data_scheme + ten_a}, |
470 {data_scheme + hundred_a, data_scheme + hundred_a}, | 470 {data_scheme + hundred_a, data_scheme + hundred_a}, |
471 {data_scheme + thousand_a, long_string_middle}, | 471 {data_scheme + thousand_a, long_string_middle}, |
472 {data_scheme + ten_thousand_a, long_string_middle}, | 472 {data_scheme + ten_thousand_a, long_string_middle}, |
473 {data_scheme + hundred_thousand_a, long_string_middle}, | 473 {data_scheme + hundred_thousand_a, long_string_middle}, |
474 {data_scheme + million_a, long_string_middle}, | 474 {data_scheme + million_a, long_string_middle}, |
475 }; | 475 }; |
476 | 476 |
477 for (size_t i = 0; i < arraysize(testcases_middle); ++i) { | 477 for (size_t i = 0; i < arraysize(testcases_middle); ++i) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 { "Hello, my name is Tom", 2, true, "He" }, | 546 { "Hello, my name is Tom", 2, true, "He" }, |
547 { "Hello, my name is Tom", 3, true, "H.m" }, | 547 { "Hello, my name is Tom", 3, true, "H.m" }, |
548 { "Hello, my name is Tom", 4, true, "H..m" }, | 548 { "Hello, my name is Tom", 4, true, "H..m" }, |
549 { "Hello, my name is Tom", 5, true, "H...m" }, | 549 { "Hello, my name is Tom", 5, true, "H...m" }, |
550 { "Hello, my name is Tom", 6, true, "He...m" }, | 550 { "Hello, my name is Tom", 6, true, "He...m" }, |
551 { "Hello, my name is Tom", 7, true, "He...om" }, | 551 { "Hello, my name is Tom", 7, true, "He...om" }, |
552 { "Hello, my name is Tom", 10, true, "Hell...Tom" }, | 552 { "Hello, my name is Tom", 10, true, "Hell...Tom" }, |
553 { "Hello, my name is Tom", 100, false, "Hello, my name is Tom" } | 553 { "Hello, my name is Tom", 100, false, "Hello, my name is Tom" } |
554 }; | 554 }; |
555 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 555 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
556 string16 output; | 556 base::string16 output; |
557 EXPECT_EQ(cases[i].result, | 557 EXPECT_EQ(cases[i].result, |
558 ElideString(UTF8ToUTF16(cases[i].input), | 558 ElideString(UTF8ToUTF16(cases[i].input), |
559 cases[i].max_len, &output)); | 559 cases[i].max_len, &output)); |
560 EXPECT_EQ(cases[i].output, UTF16ToUTF8(output)); | 560 EXPECT_EQ(cases[i].output, UTF16ToUTF8(output)); |
561 } | 561 } |
562 } | 562 } |
563 | 563 |
564 TEST(TextEliderTest, ElideRectangleText) { | 564 TEST(TextEliderTest, ElideRectangleText) { |
565 const FontList font_list; | 565 const FontList font_list; |
566 const int line_height = font_list.GetHeight(); | 566 const int line_height = font_list.GetHeight(); |
(...skipping 27 matching lines...) Expand all Loading... |
594 { "Test\n\n", 2 * test_width, line_height * 5, false, "Test||" }, | 594 { "Test\n\n", 2 * test_width, line_height * 5, false, "Test||" }, |
595 { "Test\n\n\n", 2 * test_width, line_height * 5, false, "Test|||" }, | 595 { "Test\n\n\n", 2 * test_width, line_height * 5, false, "Test|||" }, |
596 { "Test\nTest\n\n", 2 * test_width, line_height * 5, false, "Test|Test||" }, | 596 { "Test\nTest\n\n", 2 * test_width, line_height * 5, false, "Test|Test||" }, |
597 { "Test\n\nTest\n", 2 * test_width, line_height * 5, false, "Test||Test|" }, | 597 { "Test\n\nTest\n", 2 * test_width, line_height * 5, false, "Test||Test|" }, |
598 { "Test\n\n\nTest", 2 * test_width, line_height * 5, false, "Test|||Test" }, | 598 { "Test\n\n\nTest", 2 * test_width, line_height * 5, false, "Test|||Test" }, |
599 { "Te ", test_width, line_height, false, "Te" }, | 599 { "Te ", test_width, line_height, false, "Te" }, |
600 { "Te Te Test", test_width, 3 * line_height, false, "Te|Te|Test" }, | 600 { "Te Te Test", test_width, 3 * line_height, false, "Te|Te|Test" }, |
601 }; | 601 }; |
602 | 602 |
603 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 603 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
604 std::vector<string16> lines; | 604 std::vector<base::string16> lines; |
605 EXPECT_EQ(cases[i].truncated_y ? INSUFFICIENT_SPACE_VERTICAL : 0, | 605 EXPECT_EQ(cases[i].truncated_y ? INSUFFICIENT_SPACE_VERTICAL : 0, |
606 ElideRectangleText(UTF8ToUTF16(cases[i].input), | 606 ElideRectangleText(UTF8ToUTF16(cases[i].input), |
607 font_list, | 607 font_list, |
608 cases[i].available_pixel_width, | 608 cases[i].available_pixel_width, |
609 cases[i].available_pixel_height, | 609 cases[i].available_pixel_height, |
610 TRUNCATE_LONG_WORDS, | 610 TRUNCATE_LONG_WORDS, |
611 &lines)); | 611 &lines)); |
612 if (cases[i].output) { | 612 if (cases[i].output) { |
613 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); | 613 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); |
614 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; | 614 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; |
(...skipping 17 matching lines...) Expand all Loading... |
632 bool truncated_x; | 632 bool truncated_x; |
633 const char* output; | 633 const char* output; |
634 } cases[] = { | 634 } cases[] = { |
635 { "Test T.", test_t_width, line_height * 2, false, false, "Test|T." }, | 635 { "Test T.", test_t_width, line_height * 2, false, false, "Test|T." }, |
636 { "Test T ?", test_t_width, line_height * 2, false, false, "Test|T ?" }, | 636 { "Test T ?", test_t_width, line_height * 2, false, false, "Test|T ?" }, |
637 { "Test. Test", test_width, line_height * 3, false, true, "Test|Test" }, | 637 { "Test. Test", test_width, line_height * 3, false, true, "Test|Test" }, |
638 { "Test. Test", test_width, line_height * 3, true, false, "Test|.|Test" }, | 638 { "Test. Test", test_width, line_height * 3, true, false, "Test|.|Test" }, |
639 }; | 639 }; |
640 | 640 |
641 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 641 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
642 std::vector<string16> lines; | 642 std::vector<base::string16> lines; |
643 const WordWrapBehavior wrap_behavior = | 643 const WordWrapBehavior wrap_behavior = |
644 (cases[i].wrap_words ? WRAP_LONG_WORDS : TRUNCATE_LONG_WORDS); | 644 (cases[i].wrap_words ? WRAP_LONG_WORDS : TRUNCATE_LONG_WORDS); |
645 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, | 645 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, |
646 ElideRectangleText(UTF8ToUTF16(cases[i].input), | 646 ElideRectangleText(UTF8ToUTF16(cases[i].input), |
647 font_list, | 647 font_list, |
648 cases[i].available_pixel_width, | 648 cases[i].available_pixel_width, |
649 cases[i].available_pixel_height, | 649 cases[i].available_pixel_height, |
650 wrap_behavior, | 650 wrap_behavior, |
651 &lines)); | 651 &lines)); |
652 if (cases[i].output) { | 652 if (cases[i].output) { |
653 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); | 653 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); |
654 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; | 654 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; |
655 } else { | 655 } else { |
656 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!"; | 656 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!"; |
657 } | 657 } |
658 } | 658 } |
659 } | 659 } |
660 | 660 |
661 TEST(TextEliderTest, ElideRectangleTextLongWords) { | 661 TEST(TextEliderTest, ElideRectangleTextLongWords) { |
662 const FontList font_list; | 662 const FontList font_list; |
663 const int kAvailableHeight = 1000; | 663 const int kAvailableHeight = 1000; |
664 const string16 kElidedTesting = UTF8ToUTF16(std::string("Tes") + kEllipsis); | 664 const base::string16 kElidedTesting = |
| 665 UTF8ToUTF16(std::string("Tes") + kEllipsis); |
665 const float elided_width = GetStringWidthF(kElidedTesting, font_list); | 666 const float elided_width = GetStringWidthF(kElidedTesting, font_list); |
666 const float test_width = GetStringWidthF(ASCIIToUTF16("Test"), font_list); | 667 const float test_width = GetStringWidthF(ASCIIToUTF16("Test"), font_list); |
667 | 668 |
668 struct TestData { | 669 struct TestData { |
669 const char* input; | 670 const char* input; |
670 float available_pixel_width; | 671 float available_pixel_width; |
671 WordWrapBehavior wrap_behavior; | 672 WordWrapBehavior wrap_behavior; |
672 bool truncated_x; | 673 bool truncated_x; |
673 const char* output; | 674 const char* output; |
674 } cases[] = { | 675 } cases[] = { |
(...skipping 20 matching lines...) Expand all Loading... |
695 { "X Testing", test_width, WRAP_LONG_WORDS, false, "X|Test|ing" }, | 696 { "X Testing", test_width, WRAP_LONG_WORDS, false, "X|Test|ing" }, |
696 { "Test Testing", test_width, WRAP_LONG_WORDS, false, "Test|Test|ing" }, | 697 { "Test Testing", test_width, WRAP_LONG_WORDS, false, "Test|Test|ing" }, |
697 { "Test\nTesting", test_width, WRAP_LONG_WORDS, false, "Test|Test|ing" }, | 698 { "Test\nTesting", test_width, WRAP_LONG_WORDS, false, "Test|Test|ing" }, |
698 { "Test Tests ", test_width, WRAP_LONG_WORDS, false, "Test|Test|s" }, | 699 { "Test Tests ", test_width, WRAP_LONG_WORDS, false, "Test|Test|s" }, |
699 { "Test Tests T", test_width, WRAP_LONG_WORDS, false, "Test|Test|s T" }, | 700 { "Test Tests T", test_width, WRAP_LONG_WORDS, false, "Test|Test|s T" }, |
700 { "TestTestTest", test_width, WRAP_LONG_WORDS, false, "Test|Test|Test" }, | 701 { "TestTestTest", test_width, WRAP_LONG_WORDS, false, "Test|Test|Test" }, |
701 { "TestTestTestT", test_width, WRAP_LONG_WORDS, false, "Test|Test|Test|T" }, | 702 { "TestTestTestT", test_width, WRAP_LONG_WORDS, false, "Test|Test|Test|T" }, |
702 }; | 703 }; |
703 | 704 |
704 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 705 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
705 std::vector<string16> lines; | 706 std::vector<base::string16> lines; |
706 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, | 707 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, |
707 ElideRectangleText(UTF8ToUTF16(cases[i].input), | 708 ElideRectangleText(UTF8ToUTF16(cases[i].input), |
708 font_list, | 709 font_list, |
709 cases[i].available_pixel_width, | 710 cases[i].available_pixel_width, |
710 kAvailableHeight, | 711 kAvailableHeight, |
711 cases[i].wrap_behavior, | 712 cases[i].wrap_behavior, |
712 &lines)); | 713 &lines)); |
713 std::string expected_output(cases[i].output); | 714 std::string expected_output(cases[i].output); |
714 ReplaceSubstringsAfterOffset(&expected_output, 0, "...", kEllipsis); | 715 ReplaceSubstringsAfterOffset(&expected_output, 0, "...", kEllipsis); |
715 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); | 716 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); |
716 EXPECT_EQ(expected_output, result) << "Case " << i << " failed!"; | 717 EXPECT_EQ(expected_output, result) << "Case " << i << " failed!"; |
717 } | 718 } |
718 } | 719 } |
719 | 720 |
720 // This test is to make sure that the width of each wrapped line does not | 721 // This test is to make sure that the width of each wrapped line does not |
721 // exceed the available width. On some platform like Mac, this test used to | 722 // exceed the available width. On some platform like Mac, this test used to |
722 // fail because the truncated integer width is returned for the string | 723 // fail because the truncated integer width is returned for the string |
723 // and the accumulation of the truncated values causes the elide function | 724 // and the accumulation of the truncated values causes the elide function |
724 // to wrap incorrectly. | 725 // to wrap incorrectly. |
725 TEST(TextEliderTest, ElideRectangleTextCheckLineWidth) { | 726 TEST(TextEliderTest, ElideRectangleTextCheckLineWidth) { |
726 FontList font_list; | 727 FontList font_list; |
727 #if defined(OS_MACOSX) && !defined(OS_IOS) | 728 #if defined(OS_MACOSX) && !defined(OS_IOS) |
728 // Use a specific font to expose the line width exceeding problem. | 729 // Use a specific font to expose the line width exceeding problem. |
729 font_list = FontList(Font("LucidaGrande", 12)); | 730 font_list = FontList(Font("LucidaGrande", 12)); |
730 #endif | 731 #endif |
731 const float kAvailableWidth = 235; | 732 const float kAvailableWidth = 235; |
732 const int kAvailableHeight = 1000; | 733 const int kAvailableHeight = 1000; |
733 const char text[] = "that Russian place we used to go to after fencing"; | 734 const char text[] = "that Russian place we used to go to after fencing"; |
734 std::vector<string16> lines; | 735 std::vector<base::string16> lines; |
735 EXPECT_EQ(0, ElideRectangleText(UTF8ToUTF16(text), | 736 EXPECT_EQ(0, ElideRectangleText(UTF8ToUTF16(text), |
736 font_list, | 737 font_list, |
737 kAvailableWidth, | 738 kAvailableWidth, |
738 kAvailableHeight, | 739 kAvailableHeight, |
739 WRAP_LONG_WORDS, | 740 WRAP_LONG_WORDS, |
740 &lines)); | 741 &lines)); |
741 ASSERT_EQ(2u, lines.size()); | 742 ASSERT_EQ(2u, lines.size()); |
742 EXPECT_LE(GetStringWidthF(lines[0], font_list), kAvailableWidth); | 743 EXPECT_LE(GetStringWidthF(lines[0], font_list), kAvailableWidth); |
743 EXPECT_LE(GetStringWidthF(lines[1], font_list), kAvailableWidth); | 744 EXPECT_LE(GetStringWidthF(lines[1], font_list), kAvailableWidth); |
744 } | 745 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 { "Hi, my name is\nTom", 1, 12, true, "Hi, my \n..." }, | 810 { "Hi, my name is\nTom", 1, 12, true, "Hi, my \n..." }, |
810 { "Hi, my name is\nTom", 2, 12, true, "Hi, my \nname is\n..." }, | 811 { "Hi, my name is\nTom", 2, 12, true, "Hi, my \nname is\n..." }, |
811 { "Hi, my name is\nTom", 3, 12, false, "Hi, my \nname is\nTom" }, | 812 { "Hi, my name is\nTom", 3, 12, false, "Hi, my \nname is\nTom" }, |
812 { "Hi, my name is\nTom", 1, 13, true, "Hi, my name \n..." }, | 813 { "Hi, my name is\nTom", 1, 13, true, "Hi, my name \n..." }, |
813 { "Hi, my name is\nTom", 2, 13, true, "Hi, my name \nis\n..." }, | 814 { "Hi, my name is\nTom", 2, 13, true, "Hi, my name \nis\n..." }, |
814 { "Hi, my name is\nTom", 3, 13, false, "Hi, my name \nis\nTom" }, | 815 { "Hi, my name is\nTom", 3, 13, false, "Hi, my name \nis\nTom" }, |
815 { "Hi, my name is\nTom", 1, 20, true, "Hi, my name is\n..." }, | 816 { "Hi, my name is\nTom", 1, 20, true, "Hi, my name is\n..." }, |
816 { "Hi, my name is\nTom", 2, 20, false, "Hi, my name is\nTom" }, | 817 { "Hi, my name is\nTom", 2, 20, false, "Hi, my name is\nTom" }, |
817 { "Hi, my name is Tom", 1, 40, false, "Hi, my name is Tom" }, | 818 { "Hi, my name is Tom", 1, 40, false, "Hi, my name is Tom" }, |
818 }; | 819 }; |
819 string16 output; | 820 base::string16 output; |
820 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 821 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
821 EXPECT_EQ(cases[i].result, | 822 EXPECT_EQ(cases[i].result, |
822 ElideRectangleString(UTF8ToUTF16(cases[i].input), | 823 ElideRectangleString(UTF8ToUTF16(cases[i].input), |
823 cases[i].max_rows, cases[i].max_cols, | 824 cases[i].max_rows, cases[i].max_cols, |
824 true, &output)); | 825 true, &output)); |
825 EXPECT_EQ(cases[i].output, UTF16ToUTF8(output)); | 826 EXPECT_EQ(cases[i].output, UTF16ToUTF8(output)); |
826 } | 827 } |
827 } | 828 } |
828 | 829 |
829 TEST(TextEliderTest, ElideRectangleStringNotStrict) { | 830 TEST(TextEliderTest, ElideRectangleStringNotStrict) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 { "Hi, my name_is\nDick", 1, 12, true, "Hi, my ..." }, | 892 { "Hi, my name_is\nDick", 1, 12, true, "Hi, my ..." }, |
892 { "Hi, my name_is\nDick", 2, 12, true, "Hi, my name_is\n..." }, | 893 { "Hi, my name_is\nDick", 2, 12, true, "Hi, my name_is\n..." }, |
893 { "Hi, my name_is\nDick", 3, 12, false, "Hi, my name_is\nDick" }, | 894 { "Hi, my name_is\nDick", 3, 12, false, "Hi, my name_is\nDick" }, |
894 { "Hi, my name_is\nDick", 1, 13, true, "Hi, my ..." }, | 895 { "Hi, my name_is\nDick", 1, 13, true, "Hi, my ..." }, |
895 { "Hi, my name_is\nDick", 2, 13, true, "Hi, my name_is\n..." }, | 896 { "Hi, my name_is\nDick", 2, 13, true, "Hi, my name_is\n..." }, |
896 { "Hi, my name_is\nDick", 3, 13, false, "Hi, my name_is\nDick" }, | 897 { "Hi, my name_is\nDick", 3, 13, false, "Hi, my name_is\nDick" }, |
897 { "Hi, my name_is\nDick", 1, 20, true, "Hi, my name_is\n..." }, | 898 { "Hi, my name_is\nDick", 1, 20, true, "Hi, my name_is\n..." }, |
898 { "Hi, my name_is\nDick", 2, 20, false, "Hi, my name_is\nDick" }, | 899 { "Hi, my name_is\nDick", 2, 20, false, "Hi, my name_is\nDick" }, |
899 { "Hi, my name_is Dick", 1, 40, false, "Hi, my name_is Dick" }, | 900 { "Hi, my name_is Dick", 1, 40, false, "Hi, my name_is Dick" }, |
900 }; | 901 }; |
901 string16 output; | 902 base::string16 output; |
902 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 903 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
903 EXPECT_EQ(cases[i].result, | 904 EXPECT_EQ(cases[i].result, |
904 ElideRectangleString(UTF8ToUTF16(cases[i].input), | 905 ElideRectangleString(UTF8ToUTF16(cases[i].input), |
905 cases[i].max_rows, cases[i].max_cols, | 906 cases[i].max_rows, cases[i].max_cols, |
906 false, &output)); | 907 false, &output)); |
907 EXPECT_EQ(cases[i].output, UTF16ToUTF8(output)); | 908 EXPECT_EQ(cases[i].output, UTF16ToUTF8(output)); |
908 } | 909 } |
909 } | 910 } |
910 | 911 |
911 TEST(TextEliderTest, ElideRectangleWide16) { | 912 TEST(TextEliderTest, ElideRectangleWide16) { |
912 // Two greek words separated by space. | 913 // Two greek words separated by space. |
913 const string16 str(WideToUTF16( | 914 const base::string16 str(WideToUTF16( |
914 L"\x03a0\x03b1\x03b3\x03ba\x03cc\x03c3\x03bc\x03b9" | 915 L"\x03a0\x03b1\x03b3\x03ba\x03cc\x03c3\x03bc\x03b9" |
915 L"\x03bf\x03c2\x0020\x0399\x03c3\x03c4\x03cc\x03c2")); | 916 L"\x03bf\x03c2\x0020\x0399\x03c3\x03c4\x03cc\x03c2")); |
916 const string16 out1(WideToUTF16( | 917 const base::string16 out1(WideToUTF16( |
917 L"\x03a0\x03b1\x03b3\x03ba\n" | 918 L"\x03a0\x03b1\x03b3\x03ba\n" |
918 L"\x03cc\x03c3\x03bc\x03b9\n" | 919 L"\x03cc\x03c3\x03bc\x03b9\n" |
919 L"...")); | 920 L"...")); |
920 const string16 out2(WideToUTF16( | 921 const base::string16 out2(WideToUTF16( |
921 L"\x03a0\x03b1\x03b3\x03ba\x03cc\x03c3\x03bc\x03b9\x03bf\x03c2\x0020\n" | 922 L"\x03a0\x03b1\x03b3\x03ba\x03cc\x03c3\x03bc\x03b9\x03bf\x03c2\x0020\n" |
922 L"\x0399\x03c3\x03c4\x03cc\x03c2")); | 923 L"\x0399\x03c3\x03c4\x03cc\x03c2")); |
923 string16 output; | 924 base::string16 output; |
924 EXPECT_TRUE(ElideRectangleString(str, 2, 4, true, &output)); | 925 EXPECT_TRUE(ElideRectangleString(str, 2, 4, true, &output)); |
925 EXPECT_EQ(out1, output); | 926 EXPECT_EQ(out1, output); |
926 EXPECT_FALSE(ElideRectangleString(str, 2, 12, true, &output)); | 927 EXPECT_FALSE(ElideRectangleString(str, 2, 12, true, &output)); |
927 EXPECT_EQ(out2, output); | 928 EXPECT_EQ(out2, output); |
928 } | 929 } |
929 | 930 |
930 TEST(TextEliderTest, ElideRectangleWide32) { | 931 TEST(TextEliderTest, ElideRectangleWide32) { |
931 // Four U+1D49C MATHEMATICAL SCRIPT CAPITAL A followed by space "aaaaa". | 932 // Four U+1D49C MATHEMATICAL SCRIPT CAPITAL A followed by space "aaaaa". |
932 const string16 str(UTF8ToUTF16( | 933 const base::string16 str(UTF8ToUTF16( |
933 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C" | 934 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C" |
934 " aaaaa")); | 935 " aaaaa")); |
935 const string16 out(UTF8ToUTF16( | 936 const base::string16 out(UTF8ToUTF16( |
936 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\n" | 937 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\n" |
937 "\xF0\x9D\x92\x9C \naaa\n...")); | 938 "\xF0\x9D\x92\x9C \naaa\n...")); |
938 string16 output; | 939 base::string16 output; |
939 EXPECT_TRUE(ElideRectangleString(str, 3, 3, true, &output)); | 940 EXPECT_TRUE(ElideRectangleString(str, 3, 3, true, &output)); |
940 EXPECT_EQ(out, output); | 941 EXPECT_EQ(out, output); |
941 } | 942 } |
942 | 943 |
943 TEST(TextEliderTest, TruncateString) { | 944 TEST(TextEliderTest, TruncateString) { |
944 string16 string = ASCIIToUTF16("foooooey bxxxar baz"); | 945 base::string16 string = ASCIIToUTF16("foooooey bxxxar baz"); |
945 | 946 |
946 // Make sure it doesn't modify the string if length > string length. | 947 // Make sure it doesn't modify the string if length > string length. |
947 EXPECT_EQ(string, TruncateString(string, 100)); | 948 EXPECT_EQ(string, TruncateString(string, 100)); |
948 | 949 |
949 // Test no characters. | 950 // Test no characters. |
950 EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0))); | 951 EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0))); |
951 | 952 |
952 // Test 1 character. | 953 // Test 1 character. |
953 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1))); | 954 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1))); |
954 | 955 |
955 // Test adds ... at right spot when there is enough room to break at a | 956 // Test adds ... at right spot when there is enough room to break at a |
956 // word boundary. | 957 // word boundary. |
957 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 14))); | 958 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 14))); |
958 | 959 |
959 // Test adds ... at right spot when there is not enough space in first word. | 960 // Test adds ... at right spot when there is not enough space in first word. |
960 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2))); | 961 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2))); |
961 | 962 |
962 // Test adds ... at right spot when there is not enough room to break at a | 963 // Test adds ... at right spot when there is not enough room to break at a |
963 // word boundary. | 964 // word boundary. |
964 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); | 965 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); |
965 | 966 |
966 // Test completely truncates string if break is on initial whitespace. | 967 // Test completely truncates string if break is on initial whitespace. |
967 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); | 968 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); |
968 } | 969 } |
969 | 970 |
970 } // namespace gfx | 971 } // namespace gfx |
OLD | NEW |