Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(841)

Unified Diff: ui/gfx/text_elider_unittest.cc

Issue 381953002: New avatar button: Consolidate text elision between Mac and Win/Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/text_elider.cc ('k') | ui/message_center/views/notification_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..72630f220c7ddeb9d22cf655e3efed0e4e0e8498 100644
--- a/ui/gfx/text_elider_unittest.cc
+++ b/ui/gfx/text_elider_unittest.cc
@@ -876,28 +876,51 @@ 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, WORD_BREAK));
+ EXPECT_EQ(string, TruncateString(string, 100, CHARACTER_BREAK));
// Test no characters.
- EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0)));
+ EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0, WORD_BREAK)));
+ EXPECT_EQ(L"", UTF16ToWide(TruncateString(string, 0, CHARACTER_BREAK)));
// Test 1 character.
- EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1)));
+ EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1, WORD_BREAK)));
+ EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(string, 1, CHARACTER_BREAK)));
+
+ // Test completely truncates string if break is on initial whitespace.
+ EXPECT_EQ(L"\x2026",
+ UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2, WORD_BREAK)));
+ EXPECT_EQ(L"\x2026",
+ UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2,
+ CHARACTER_BREAK)));
+
+ // 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,
+ WORD_BREAK)));
// 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, WORD_BREAK)));
// 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,
+ WORD_BREAK)));
- // 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,
+ CHARACTER_BREAK)));
+
+ // Test removes trailing whitespace if break falls between words.
+ EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12,
+ CHARACTER_BREAK)));
}
} // namespace gfx
« no previous file with comments | « ui/gfx/text_elider.cc ('k') | ui/message_center/views/notification_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698