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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\n" | 869 "\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\xF0\x9D\x92\x9C\n" |
870 "\xF0\x9D\x92\x9C \naaa\n...")); | 870 "\xF0\x9D\x92\x9C \naaa\n...")); |
871 base::string16 output; | 871 base::string16 output; |
872 EXPECT_TRUE(ElideRectangleString(str, 3, 3, true, &output)); | 872 EXPECT_TRUE(ElideRectangleString(str, 3, 3, true, &output)); |
873 EXPECT_EQ(out, output); | 873 EXPECT_EQ(out, output); |
874 } | 874 } |
875 | 875 |
876 TEST(TextEliderTest, TruncateString) { | 876 TEST(TextEliderTest, TruncateString) { |
877 base::string16 string = ASCIIToUTF16("foooooey bxxxar baz"); | 877 base::string16 string = ASCIIToUTF16("foooooey bxxxar baz"); |
878 | 878 |
| 879 // Tests that apply to both break behaviors: |
| 880 |
879 // Make sure it doesn't modify the string if length > string length. | 881 // Make sure it doesn't modify the string if length > string length. |
880 EXPECT_EQ(string, TruncateString(string, 100)); | 882 EXPECT_EQ(string, TruncateString(string, 100, WORD_BREAK)); |
| 883 EXPECT_EQ(string, TruncateString(string, 100, CHARACTER_BREAK)); |
881 | 884 |
882 // Test no characters. | 885 // Test no characters. |
883 EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0))); | 886 EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0, WORD_BREAK))); |
| 887 EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0, CHARACTER_BREAK))); |
884 | 888 |
885 // Test 1 character. | 889 // Test 1 character. |
886 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1))); | 890 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1, WORD_BREAK))); |
| 891 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1, CHARACTER_BREAK))); |
| 892 |
| 893 // Test completely truncates string if break is on initial whitespace. |
| 894 EXPECT_EQ(L"\x2026", |
| 895 UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2, WORD_BREAK))); |
| 896 EXPECT_EQ(L"\x2026", |
| 897 UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2, |
| 898 CHARACTER_BREAK))); |
| 899 |
| 900 // Break-only-at-word-boundaries tests: |
887 | 901 |
888 // Test adds ... at right spot when there is enough room to break at a | 902 // Test adds ... at right spot when there is enough room to break at a |
889 // word boundary. | 903 // word boundary. |
890 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 14))); | 904 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 14, |
| 905 WORD_BREAK))); |
891 | 906 |
892 // Test adds ... at right spot when there is not enough space in first word. | 907 // Test adds ... at right spot when there is not enough space in first word. |
893 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2))); | 908 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, WORD_BREAK))); |
894 | 909 |
895 // Test adds ... at right spot when there is not enough room to break at a | 910 // Test adds ... at right spot when there is not enough room to break at a |
896 // word boundary. | 911 // word boundary. |
897 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); | 912 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11, |
| 913 WORD_BREAK))); |
898 | 914 |
899 // Test completely truncates string if break is on initial whitespace. | 915 // Break-anywhere tests: |
900 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); | 916 |
| 917 // Test adds ... at right spot within a word. |
| 918 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, |
| 919 CHARACTER_BREAK))); |
| 920 |
| 921 // Test removes trailing whitespace if break falls between words. |
| 922 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12, |
| 923 CHARACTER_BREAK))); |
901 } | 924 } |
902 | 925 |
903 } // namespace gfx | 926 } // namespace gfx |
OLD | NEW |