Index: ui/base/text/text_elider_unittest.cc |
diff --git a/ui/base/text/text_elider_unittest.cc b/ui/base/text/text_elider_unittest.cc |
index 0ff70e4bba845f6f5e00a8ec2d638cebb00573d5..60ab1f743ed11d135f0a0a3a6749608a005c7da1 100644 |
--- a/ui/base/text/text_elider_unittest.cc |
+++ b/ui/base/text/text_elider_unittest.cc |
@@ -547,4 +547,31 @@ TEST(TextEliderTest, ElideRectangleWide32) { |
EXPECT_EQ(out, output); |
} |
+TEST(TextEliderTest, TruncateString) { |
+ string16 string = ASCIIToUTF16("foooooey bxxxar baz"); |
+ |
+ // Make sure it doesn't modify the string if length > string length. |
+ EXPECT_EQ(string, ui::TruncateString(string, 100)); |
+ |
+ // Test no characters. |
+ EXPECT_EQ(L"", UTF16ToWide(ui::TruncateString(string, 0))); |
+ |
+ // Test 1 character. |
+ EXPECT_EQ(L"\x2026", UTF16ToWide(ui::TruncateString(string, 1))); |
+ |
+ // Test adds ... at right spot when there is enough room to break at a |
+ // word boundary. |
+ EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(ui::TruncateString(string, 14))); |
+ |
+ // Test adds ... at right spot when there is not enough space in first word. |
+ EXPECT_EQ(L"f\x2026", UTF16ToWide(ui::TruncateString(string, 2))); |
+ |
+ // Test adds ... at right spot when there is not enough room to break at a |
+ // word boundary. |
+ EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(ui::TruncateString(string, 11))); |
+ |
+ // Test completely truncates string if break is on initial whitespace. |
+ EXPECT_EQ(L"\x2026", UTF16ToWide(ui::TruncateString(ASCIIToUTF16(" "), 2))); |
+} |
+ |
} // namespace ui |