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

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: fixed lint 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const GURL url(testcases[i].input); 46 const GURL url(testcases[i].input);
47 // Should we test with non-empty language list? 47 // Should we test with non-empty language list?
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 void RunEmailTest(Testcase* testcases, size_t num_testcases,
Alexei Svitkine (slow) 2012/02/28 15:46:22 Nit: Put "num_testcases" on its own line.
57 size_t max_email_length) {
58 for (size_t i = 0; i < num_testcases; ++i) {
59 EXPECT_EQ(UTF8ToUTF16(testcases[i].output),
60 ElideEmail(UTF8ToUTF16(testcases[i].input), max_email_length));
61 }
62 }
63
56 } // namespace 64 } // namespace
57 65
66 TEST(TextEliderTest, SmallestElideEmail) {
67 const std::string kEllipsisStr(kEllipsis);
68
69 // all expected values in this test assume the UTF16 ellipsis is a single char
70 ASSERT_EQ(UTF8ToUTF16(kEllipsisStr).length(), size_t(1));
71
72 // 5 is the smallest max_email_length allowed in ui::ElideEmail
73 const size_t max_email_length = 5;
74
75 Testcase testcases[] = {
76 {"g@g.c", "g@g.c"},
77 {"ga@co", "ga@co"},
78 {"short@small.com", "s" + kEllipsisStr + "@s" +kEllipsisStr},
Alexei Svitkine (slow) 2012/02/28 15:46:22 Add a space between + and kEllipsisStr.
79 };
80
81 RunEmailTest(testcases, arraysize(testcases), max_email_length);
82 }
83
84 TEST(TextEliderTest, RegularElideEmail) {
85 const std::string kEllipsisStr(kEllipsis);
86
87 // all expected values in this test assume the UTF16 ellipsis is a single char
Alexei Svitkine (slow) 2012/02/28 15:46:22 Comments should be complete sentences: starting wi
88 ASSERT_EQ(UTF8ToUTF16(kEllipsisStr).length(), size_t(1));
89
90 const size_t max_email_length = 20;
91
92 Testcase testcases[] = {
93 {"short@small.com", "short@small.com"},
94 {"justunder@test19.ca", "justunder@test19.ca"},
95 {"exactly@righton20.ca", "exactly@righton20.ca"},
96 {"justover20@test21.com", "justover" + kEllipsisStr + "@test21.com"},
97 {"longusernameshortdomain@short.com", "longusern" + kEllipsisStr +
98 "@short.com"},
99 {"short@verysuperlongdomain.com", "short@verys" + kEllipsisStr + ".com"},
100 {"waytoobigofanemail@somealsoverybigdomain.com", "waytoobi" +
101 kEllipsisStr +
102 "@somea" +
103 kEllipsisStr +
104 ".com"},
105 {"toolongusername@maxsizedomain.com", "t" + kEllipsisStr +
106 "@maxsizedomain.com"},
107 {"toolongusername@justovermaxof17.tv", "toolongu" + kEllipsisStr +
108 "@justo" + kEllipsisStr +
109 "7.tv"},
110 };
111
112 RunEmailTest(testcases, arraysize(testcases), max_email_length);
113 }
114
58 // Test eliding of commonplace URLs. 115 // Test eliding of commonplace URLs.
59 TEST(TextEliderTest, TestGeneralEliding) { 116 TEST(TextEliderTest, TestGeneralEliding) {
60 const std::string kEllipsisStr(kEllipsis); 117 const std::string kEllipsisStr(kEllipsis);
61 Testcase testcases[] = { 118 Testcase testcases[] = {
62 {"http://www.google.com/intl/en/ads/", 119 {"http://www.google.com/intl/en/ads/",
63 "www.google.com/intl/en/ads/"}, 120 "www.google.com/intl/en/ads/"},
64 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, 121 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
65 {"http://www.google.com/intl/en/ads/", 122 {"http://www.google.com/intl/en/ads/",
66 "google.com/intl/" + kEllipsisStr + "/ads/"}, 123 "google.com/intl/" + kEllipsisStr + "/ads/"},
67 {"http://www.google.com/intl/en/ads/", 124 {"http://www.google.com/intl/en/ads/",
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 837
781 // Test adds ... at right spot when there is not enough room to break at a 838 // Test adds ... at right spot when there is not enough room to break at a
782 // word boundary. 839 // word boundary.
783 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); 840 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11)));
784 841
785 // Test completely truncates string if break is on initial whitespace. 842 // Test completely truncates string if break is on initial whitespace.
786 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); 843 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2)));
787 } 844 }
788 845
789 } // namespace ui 846 } // 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