OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/i18n/rtl.h" | 6 #include "base/i18n/rtl.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C" | 540 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C" |
541 " aaaaa")); | 541 " aaaaa")); |
542 const string16 out(UTF8ToUTF16( | 542 const string16 out(UTF8ToUTF16( |
543 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\n" | 543 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\n" |
544 "\xF0\x9D\x92\x9C \naaa\n...")); | 544 "\xF0\x9D\x92\x9C \naaa\n...")); |
545 string16 output; | 545 string16 output; |
546 EXPECT_TRUE(ui::ElideRectangleString(str, 3, 3, true, &output)); | 546 EXPECT_TRUE(ui::ElideRectangleString(str, 3, 3, true, &output)); |
547 EXPECT_EQ(out, output); | 547 EXPECT_EQ(out, output); |
548 } | 548 } |
549 | 549 |
| 550 TEST(TextEliderTest, TruncateString) { |
| 551 string16 string = ASCIIToUTF16("foooooey bxxxar baz"); |
| 552 |
| 553 // Make sure it doesn't modify the string if length > string length. |
| 554 EXPECT_EQ(string, ui::TruncateString(string, 100)); |
| 555 |
| 556 // Test no characters. |
| 557 EXPECT_EQ(L"", UTF16ToWide(ui::TruncateString(string, 0))); |
| 558 |
| 559 // Test 1 character. |
| 560 EXPECT_EQ(L"\x2026", UTF16ToWide(ui::TruncateString(string, 1))); |
| 561 |
| 562 // Test adds ... at right spot when there is enough room to break at a |
| 563 // word boundary. |
| 564 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(ui::TruncateString(string, 14))); |
| 565 |
| 566 // Test adds ... at right spot when there is not enough space in first word. |
| 567 EXPECT_EQ(L"f\x2026", UTF16ToWide(ui::TruncateString(string, 2))); |
| 568 |
| 569 // Test adds ... at right spot when there is not enough room to break at a |
| 570 // word boundary. |
| 571 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(ui::TruncateString(string, 11))); |
| 572 |
| 573 // Test completely truncates string if break is on initial whitespace. |
| 574 EXPECT_EQ(L"\x2026", UTF16ToWide(ui::TruncateString(ASCIIToUTF16(" "), 2))); |
| 575 } |
| 576 |
550 } // namespace ui | 577 } // namespace ui |
OLD | NEW |