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

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: fix lint -- missing space 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[] = {
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);
asvitkine_google 2012/03/01 22:10:56 Inline this into the loop.
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
94 TEST(TextEliderTest, ElideEmailMoreSpace) {
95 const int test_width_factors[] = {
96 100,
97 10000,
98 1000000,
99 };
100 const std::string test_emails[] = {
101 "a@c",
102 "test@email.com",
103 "short@verysuperdupperlongdomain.com",
104 "supermegalongusername@withasuperlonnnggggdomain.gouv.qc.ca",
105 };
106
107 const gfx::Font font;
108 const size_t num_test_width_factors = arraysize(test_width_factors);
109 const size_t num_test_emails = arraysize(test_emails);
asvitkine_google 2012/03/01 22:10:56 Don't need these as separate variables, just use a
gab 2012/03/01 23:03:46 Ah ok good to know, thought there would be some re
110 for (size_t i = 0; i < num_test_width_factors; ++i) {
111 const int test_width = test_width_factors[i] *
112 font.GetAverageCharacterWidth();
113 for (size_t j = 0; j < num_test_emails; ++j) {
114 // Extra space is available: the email should not be elided.
115 const string16 test_email = UTF8ToUTF16(test_emails[j]);
116 EXPECT_EQ(test_email, ElideEmail(test_email, font, test_width));
117 }
118 }
119 }
120
58 // Test eliding of commonplace URLs. 121 // Test eliding of commonplace URLs.
59 TEST(TextEliderTest, TestGeneralEliding) { 122 TEST(TextEliderTest, TestGeneralEliding) {
60 const std::string kEllipsisStr(kEllipsis); 123 const std::string kEllipsisStr(kEllipsis);
61 Testcase testcases[] = { 124 Testcase testcases[] = {
62 {"http://www.google.com/intl/en/ads/", 125 {"http://www.google.com/intl/en/ads/",
63 "www.google.com/intl/en/ads/"}, 126 "www.google.com/intl/en/ads/"},
64 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, 127 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
65 {"http://www.google.com/intl/en/ads/", 128 {"http://www.google.com/intl/en/ads/",
66 "google.com/intl/" + kEllipsisStr + "/ads/"}, 129 "google.com/intl/" + kEllipsisStr + "/ads/"},
67 {"http://www.google.com/intl/en/ads/", 130 {"http://www.google.com/intl/en/ads/",
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 843
781 // Test adds ... at right spot when there is not enough room to break at a 844 // Test adds ... at right spot when there is not enough room to break at a
782 // word boundary. 845 // word boundary.
783 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); 846 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11)));
784 847
785 // Test completely truncates string if break is on initial whitespace. 848 // Test completely truncates string if break is on initial whitespace.
786 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); 849 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2)));
787 } 850 }
788 851
789 } // namespace ui 852 } // 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