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

Unified 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: rev2 Created 8 years, 10 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
« ui/base/text/text_elider.h ('K') | « ui/base/text/text_elider.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 b342b4c5dbae63b1a67287f75febe0130111471f..2c04138546efcddcdffa11934d09c5b17f138dd0 100644
--- a/ui/base/text/text_elider_unittest.cc
+++ b/ui/base/text/text_elider_unittest.cc
@@ -53,8 +53,68 @@ void RunTest(Testcase* testcases, size_t num_testcases) {
}
}
+void RunEmailTest(Testcase* testcases,
+ size_t num_testcases,
+ size_t max_email_length) {
+ for (size_t i = 0; i < num_testcases; ++i) {
+ EXPECT_EQ(UTF8ToUTF16(testcases[i].output),
+ ElideEmail(UTF8ToUTF16(testcases[i].input), max_email_length));
+ }
+}
+
} // namespace
+TEST(TextEliderTest, SmallestElideEmail) {
+ const std::string kEllipsisStr(kEllipsis);
+
+ // Make sure the ellipsis is of length 1 in UTF16 as all the tests below
+ // assume this to be true.
+ ASSERT_EQ(UTF8ToUTF16(kEllipsisStr).length(), size_t(1));
+
+ // 5 is the smallest max_email_length allowed in ui::ElideEmail
+ const size_t max_email_length = 5;
+
+ Testcase testcases[] = {
+ {"g@g.c", "g@g.c"},
+ {"ga@co", "ga@co"},
+ {"short@small.com", "s" + kEllipsisStr + "@s" + kEllipsisStr},
+ };
+
+ RunEmailTest(testcases, arraysize(testcases), max_email_length);
+}
+
+TEST(TextEliderTest, RegularElideEmail) {
+ const std::string kEllipsisStr(kEllipsis);
+
+ // Make sure the ellipsis is of length 1 in UTF16 as all the tests below
+ // assume this to be true.
+ ASSERT_EQ(UTF8ToUTF16(kEllipsisStr).length(), size_t(1));
+
+ const size_t max_email_length = 20;
+
+ Testcase testcases[] = {
+ {"short@small.com", "short@small.com"},
+ {"justunder@test19.ca", "justunder@test19.ca"},
+ {"exactly@righton20.ca", "exactly@righton20.ca"},
+ {"justover20@test21.com", "justover" + kEllipsisStr + "@test21.com"},
+ {"longusernameshortdomain@short.com", "longusern" + kEllipsisStr +
+ "@short.com"},
+ {"short@verysuperlongdomain.com", "short@verys" + kEllipsisStr + ".com"},
+ {"waytoobigofanemail@somealsoverybigdomain.com", "waytoobi" +
+ kEllipsisStr +
+ "@somea" +
+ kEllipsisStr +
+ ".com"},
+ {"toolongusername@maxsizedomain.com", "t" + kEllipsisStr +
+ "@maxsizedomain.com"},
+ {"toolongusername@justovermaxof17.tv", "toolongu" + kEllipsisStr +
+ "@justo" + kEllipsisStr +
+ "7.tv"},
+ };
+
+ RunEmailTest(testcases, arraysize(testcases), max_email_length);
+}
+
// Test eliding of commonplace URLs.
TEST(TextEliderTest, TestGeneralEliding) {
const std::string kEllipsisStr(kEllipsis);
« ui/base/text/text_elider.h ('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