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

Side by Side Diff: ui/base/text/text_elider_unittest.cc

Issue 9489011: Elide long emails in the wrench and profile menus. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: lint - fix comment spacing Created 8 years, 9 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 unified diff | Download patch
« ui/base/text/text_elider.cc ('K') | « ui/base/text/text_elider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base/text/text_elider.h" 7 #include "ui/base/text/text_elider.h"
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // That's kinda redundant with net_util_unittests. 48 // That's kinda redundant with net_util_unittests.
49 EXPECT_EQ(UTF8ToUTF16(testcases[i].output), 49 EXPECT_EQ(UTF8ToUTF16(testcases[i].output),
50 ElideUrl(url, font, 50 ElideUrl(url, font,
51 font.GetStringWidth(UTF8ToUTF16(testcases[i].output)), 51 font.GetStringWidth(UTF8ToUTF16(testcases[i].output)),
52 std::string())); 52 std::string()));
53 } 53 }
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 TEST(TextEliderTest, ElideEmail) {
59 const std::string kEllipsisStr(kEllipsis);
60
61 Testcase testcases[] = {
asvitkine_google 2012/03/01 20:13:29 Please add some tests that check no eliding takes
62 {"g@g.c", "g@g.c"},
63 {"g@g.c", kEllipsisStr},
64 {"ga@co.ca", "ga@c" + kEllipsisStr + "a"},
65 {"short@small.com", "s" + kEllipsisStr + "@s" + kEllipsisStr},
66 {"short@small.com", "s" + kEllipsisStr + "@small.com"},
67 {"short@longbutlotsofspace.com", "short@longbutlotsofspace.com"},
68 {"short@longbutnotverymuchspace.com",
69 "short@long" + kEllipsisStr + ".com"},
70 {"short@longbutverytightspace.ca",
71 "sh" + kEllipsisStr + "@l" + kEllipsisStr + "a"},
72 {"longusername@gmail.com", "long" + kEllipsisStr + "@gmail.com"},
73 {"elidetothemax@justfits.com", "e" + kEllipsisStr + "@justfits.com"},
74 {"somelongemail@thatdoesntfit.com",
75 "somelo" + kEllipsisStr + "@tha" + kEllipsisStr + "om"},
76 {"namefits@butthedomaindoesnt.com",
77 "namefits@butthedo" + kEllipsisStr + "snt.com"},
78 {"widthtootight@nospace.com", kEllipsisStr},
79 {"nospaceforusername@l", kEllipsisStr},
80 {"little@littlespace.com", "l" + kEllipsisStr + "@l" + kEllipsisStr},
81 };
82
83 const gfx::Font font;
84 const size_t num_testcases = arraysize(testcases);
85 for (size_t i = 0; i < num_testcases; ++i) {
86 const string16 expected_output = UTF8ToUTF16(testcases[i].output);
87 EXPECT_EQ(expected_output,
88 ElideEmail(UTF8ToUTF16(testcases[i].input),
89 font,
90 font.GetStringWidth(expected_output)));
91 }
92 }
93
58 // Test eliding of commonplace URLs. 94 // Test eliding of commonplace URLs.
59 TEST(TextEliderTest, TestGeneralEliding) { 95 TEST(TextEliderTest, TestGeneralEliding) {
60 const std::string kEllipsisStr(kEllipsis); 96 const std::string kEllipsisStr(kEllipsis);
61 Testcase testcases[] = { 97 Testcase testcases[] = {
62 {"http://www.google.com/intl/en/ads/", 98 {"http://www.google.com/intl/en/ads/",
63 "www.google.com/intl/en/ads/"}, 99 "www.google.com/intl/en/ads/"},
64 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, 100 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
65 {"http://www.google.com/intl/en/ads/", 101 {"http://www.google.com/intl/en/ads/",
66 "google.com/intl/" + kEllipsisStr + "/ads/"}, 102 "google.com/intl/" + kEllipsisStr + "/ads/"},
67 {"http://www.google.com/intl/en/ads/", 103 {"http://www.google.com/intl/en/ads/",
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 816
781 // Test adds ... at right spot when there is not enough room to break at a 817 // Test adds ... at right spot when there is not enough room to break at a
782 // word boundary. 818 // word boundary.
783 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); 819 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11)));
784 820
785 // Test completely truncates string if break is on initial whitespace. 821 // Test completely truncates string if break is on initial whitespace.
786 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); 822 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2)));
787 } 823 }
788 824
789 } // namespace ui 825 } // namespace ui
OLDNEW
« ui/base/text/text_elider.cc ('K') | « ui/base/text/text_elider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698