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

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: more chars in last test 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « 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 217170c812c0ab22813390f61dec2b9b660e8e2a..2fe99812a3dac85de650779ca39279d547691054 100644
--- a/ui/base/text/text_elider_unittest.cc
+++ b/ui/base/text/text_elider_unittest.cc
@@ -55,6 +55,86 @@ void RunUrlTest(Testcase* testcases, size_t num_testcases) {
} // namespace
+TEST(TextEliderTest, ElideEmail) {
+ const std::string kEllipsisStr(kEllipsis);
+
+ // Test emails and their expected elided forms (which the available widths
Alexei Svitkine (slow) 2012/03/13 15:36:54 Nit: "from which the available widths will be deri
gab 2012/03/13 15:49:54 Fixed
+ // will be derived from).
+ // For elided forms in which both the username and domain must be elided:
+ // the result (how many characters are left on each side) can be font
+ // dependent. To avoid this, the username is prefixed with the characters
+ // expected to remain in the domain.
+ Testcase testcases[] = {
+ {"g@g.c", "g@g.c"},
+ {"g@g.c", kEllipsisStr},
+ {"ga@co.ca", "ga@c" + kEllipsisStr + "a"},
+ {"short@small.com", "s" + kEllipsisStr + "@s" + kEllipsisStr},
+ {"short@small.com", "s" + kEllipsisStr + "@small.com"},
+ {"short@longbutlotsofspace.com", "short@longbutlotsofspace.com"},
+ {"short@longbutnotverymuchspace.com",
+ "short@long" + kEllipsisStr + ".com"},
+ {"la_short@longbutverytightspace.ca",
+ "la" + kEllipsisStr + "@l" + kEllipsisStr + "a"},
+ {"longusername@gmail.com", "long" + kEllipsisStr + "@gmail.com"},
+ {"elidetothemax@justfits.com", "e" + kEllipsisStr + "@justfits.com"},
+ {"thatom_somelongemail@thatdoesntfit.com",
+ "thatom" + kEllipsisStr + "@tha" + kEllipsisStr + "om"},
+ {"namefits@butthedomaindoesnt.com",
+ "namefits@butthedo" + kEllipsisStr + "snt.com"},
+ {"widthtootight@nospace.com", kEllipsisStr},
+ {"nospaceforusername@l", kEllipsisStr},
+ {"little@littlespace.com", "l" + kEllipsisStr + "@l" + kEllipsisStr},
+ {"l@lllllllll.com", "l@lllll" + kEllipsisStr + ".com"},
+ {"messed\"up@whyanat\"++@notgoogley.com",
+ "messed\"up@whyanat\"++@notgoogley.com"},
+ {"messed\"up@whyanat\"++@notgoogley.com",
+ "messed\"up@why" + kEllipsisStr + "@notgoogley.com"},
+ {"noca_messed\"up@whyanat\"++@notgoogley.ca",
+ "noca" + kEllipsisStr + "@no" + kEllipsisStr + "ca"},
+ {"at\"@@@@@@@@@...@@.@.@.@@@\"@madness.com",
+ "at\"@@@@@@@@@...@@.@." + kEllipsisStr + "@madness.com"},
+ // Special case: "m..." takes more than half of the available width; thus
+ // the domain must elide to "l..." and not "l...l" as it must allow enough
+ // space for the minimal username elision although its half of the
+ // available width would normally allow it to elide to "l...l".
+ {"mmmmm@llllllllll", "m" + kEllipsisStr + "@l" + kEllipsisStr},
+ };
+
+ const gfx::Font font;
+ for (size_t i = 0; i < arraysize(testcases); ++i) {
+ const string16 expected_output = UTF8ToUTF16(testcases[i].output);
+ EXPECT_EQ(expected_output,
+ ElideEmail(UTF8ToUTF16(testcases[i].input),
+ font,
+ font.GetStringWidth(expected_output)));
+ }
+}
+
+TEST(TextEliderTest, ElideEmailMoreSpace) {
+ const int test_width_factors[] = {
+ 100,
+ 10000,
+ 1000000,
+ };
+ const std::string test_emails[] = {
+ "a@c",
+ "test@email.com",
+ "short@verysuperdupperlongdomain.com",
+ "supermegalongusername@withasuperlonnnggggdomain.gouv.qc.ca",
+ };
+
+ const gfx::Font font;
+ for (size_t i = 0; i < arraysize(test_width_factors); ++i) {
+ const int test_width = test_width_factors[i] *
+ font.GetAverageCharacterWidth();
+ for (size_t j = 0; j < arraysize(test_emails); ++j) {
+ // Extra space is available: the email should not be elided.
+ const string16 test_email = UTF8ToUTF16(test_emails[j]);
+ EXPECT_EQ(test_email, ElideEmail(test_email, font, test_width));
+ }
+ }
+}
+
// Test eliding of commonplace URLs.
TEST(TextEliderTest, TestGeneralEliding) {
const std::string kEllipsisStr(kEllipsis);
« no previous file with comments | « ui/base/text/text_elider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698