Index: ui/gfx/text_elider_unittest.cc |
diff --git a/ui/gfx/text_elider_unittest.cc b/ui/gfx/text_elider_unittest.cc |
index 92c47ce6873076588874d3ef477231f8d5e61667..e4ae4e977799d97eeb60f43f050149e3afa63ece 100644 |
--- a/ui/gfx/text_elider_unittest.cc |
+++ b/ui/gfx/text_elider_unittest.cc |
@@ -876,28 +876,46 @@ TEST(TextEliderTest, ElideRectangleWide32) { |
TEST(TextEliderTest, TruncateString) { |
base::string16 string = ASCIIToUTF16("foooooey bxxxar baz"); |
+ // Tests that apply to both break behaviors: |
+ |
// Make sure it doesn't modify the string if length > string length. |
- EXPECT_EQ(string, TruncateString(string, 100)); |
+ EXPECT_EQ(string, TruncateString(string, 100, true)); |
+ EXPECT_EQ(string, TruncateString(string, 100, false)); |
// Test no characters. |
- EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0))); |
+ EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0, true))); |
+ EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0, false))); |
// Test 1 character. |
- EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1))); |
+ EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1, true))); |
+ EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1, false))); |
+ |
+ // Test completely truncates string if break is on initial whitespace. |
+ EXPECT_EQ(L"\x2026", |
+ UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2, true))); |
+ EXPECT_EQ(L"\x2026", |
+ UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2, false))); |
+ |
+ // Break-only-at-word-boundaries tests: |
// Test adds ... at right spot when there is enough room to break at a |
// word boundary. |
- EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 14))); |
+ EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 14, true))); |
// Test adds ... at right spot when there is not enough space in first word. |
- EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2))); |
+ EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, true))); |
// Test adds ... at right spot when there is not enough room to break at a |
// word boundary. |
- EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); |
+ EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11, true))); |
- // Test completely truncates string if break is on initial whitespace. |
- EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); |
+ // Break-anywhere tests: |
+ |
+ // Test adds ... at right spot within a word. |
+ EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, false))); |
+ |
+ // Test removes trailing whitespace if break falls between words. |
+ EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12, false))); |
} |
} // namespace gfx |