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, true)); |
| 883 EXPECT_EQ(string, TruncateString(string, 100, false)); |
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, true))); |
| 887 EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0, false))); |
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, true))); |
| 891 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1, false))); |
| 892 |
| 893 // Test completely truncates string if break is on initial whitespace. |
| 894 EXPECT_EQ(L"\x2026", |
| 895 UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2, true))); |
| 896 EXPECT_EQ(L"\x2026", |
| 897 UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2, false))); |
| 898 |
| 899 // Break-only-at-word-boundaries tests: |
887 | 900 |
888 // Test adds ... at right spot when there is enough room to break at a | 901 // Test adds ... at right spot when there is enough room to break at a |
889 // word boundary. | 902 // word boundary. |
890 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 14))); | 903 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 14, true))); |
891 | 904 |
892 // Test adds ... at right spot when there is not enough space in first word. | 905 // Test adds ... at right spot when there is not enough space in first word. |
893 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2))); | 906 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, true))); |
894 | 907 |
895 // Test adds ... at right spot when there is not enough room to break at a | 908 // Test adds ... at right spot when there is not enough room to break at a |
896 // word boundary. | 909 // word boundary. |
897 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); | 910 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11, true))); |
898 | 911 |
899 // Test completely truncates string if break is on initial whitespace. | 912 // Break-anywhere tests: |
900 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); | 913 |
| 914 // Test adds ... at right spot within a word. |
| 915 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, false))); |
| 916 |
| 917 // Test removes trailing whitespace if break falls between words. |
| 918 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12, false))); |
901 } | 919 } |
902 | 920 |
903 } // namespace gfx | 921 } // namespace gfx |
OLD | NEW |