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

Unified Diff: ui/gfx/text_elider_unittest.cc

Issue 24883002: Uses and returns the fractional width in text eliding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix trybots Created 7 years, 2 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
Index: ui/gfx/text_elider_unittest.cc
diff --git a/ui/gfx/text_elider_unittest.cc b/ui/gfx/text_elider_unittest.cc
index 2a90e5d73cbcca9366f4fa2eeab1a8246fb97284..0f1404761929bb8e230c6fdc5e8668dcec291187 100644
--- a/ui/gfx/text_elider_unittest.cc
+++ b/ui/gfx/text_elider_unittest.cc
@@ -69,8 +69,8 @@ gfx::Font GetTestingFont() {
} // namespace
-// TODO(ios): Complex eliding is off by one for some of those tests on iOS.
-// See crbug.com/154019
+// TODO(ios): This test fails on iOS because iOS version of gfx::GetStringWidth
+// that calls [NSString sizeWithFont] returns the rounded string width.
#if defined(OS_IOS)
#define MAYBE_ElideEmail DISABLED_ElideEmail
#else
@@ -121,22 +121,13 @@ TEST(TextEliderTest, MAYBE_ElideEmail) {
{"mmmmm@llllllllll", "m" + kEllipsisStr + "@l" + kEllipsisStr},
};
- const gfx::Font font = GetTestingFont();
+ const gfx::Font font;
for (size_t i = 0; i < arraysize(testcases); ++i) {
const string16 expected_output = UTF8ToUTF16(testcases[i].output);
- int available_width = font.GetStringWidth(expected_output);
-#if defined(OS_MACOSX)
- // Give two extra pixels to offset the ceiling width returned by
- // GetStringWidth on Mac. This workaround will no longer be needed once
- // the floating point width is adopted (http://crbug.com/288987).
- // Note that we need one more pixel than TestFilenameEliding because
- // multiple strings are elided and we need to offset more.
- available_width += 2;
-#endif
EXPECT_EQ(expected_output,
ElideEmail(UTF8ToUTF16(testcases[i].input),
font,
- available_width));
+ font.GetStringWidth(expected_output)));
}
}
@@ -288,8 +279,8 @@ TEST(TextEliderTest, TestFileURLEliding) {
RunUrlTest(testcases, arraysize(testcases));
}
-// TODO(ios): Complex eliding is off by one for some of those tests on iOS.
-// See crbug.com/154019
+// TODO(ios): This test fails on iOS because iOS version of gfx::GetStringWidth
+// that calls [NSString sizeWithFont] returns the rounded string width.
#if defined(OS_IOS)
#define MAYBE_TestFilenameEliding DISABLED_TestFilenameEliding
#else
@@ -334,19 +325,13 @@ TEST(TextEliderTest, MAYBE_TestFilenameEliding) {
"file.name.re" + kEllipsisStr + "emelylongext"}
};
- static const gfx::Font font = GetTestingFont();
+ static const gfx::Font font;
for (size_t i = 0; i < arraysize(testcases); ++i) {
base::FilePath filepath(testcases[i].input);
string16 expected = UTF8ToUTF16(testcases[i].output);
expected = base::i18n::GetDisplayStringInLTRDirectionality(expected);
- int available_width = font.GetStringWidth(UTF8ToUTF16(testcases[i].output));
-#if defined(OS_MACOSX)
- // Give one extra pixel to offset the ceiling width returned by
- // GetStringWidth on Mac. This workaround will no longer be needed once
- // the floating point width is adopted (http://crbug.com/288987).
- available_width += 1;
-#endif
- EXPECT_EQ(expected, ElideFilename(filepath, font, available_width));
+ EXPECT_EQ(expected, ElideFilename(filepath, font,
+ font.GetStringWidth(UTF8ToUTF16(testcases[i].output))));
}
}
@@ -735,23 +720,18 @@ TEST(TextEliderTest, ElideRectangleTextLongWords) {
}
}
-// TODO(ios): Complex eliding is off by one for some of those tests on iOS.
-// See crbug.com/154019
-#if defined(OS_IOS)
-#define MAYBE_ElideRectangleTextCheckLineWidth \
- DISABLED_ElideRectangleTextCheckLineWidth
-#else
-#define MAYBE_ElideRectangleTextCheckLineWidth ElideRectangleTextCheckLineWidth
-#endif
-
// This test is to make sure that the width of each wrapped line does not
// exceed the available width. On some platform like Mac, this test used to
// fail because the truncated integer width is returned for the string
// and the accumulation of the truncated values causes the elide function
// to wrap incorrectly.
-TEST(TextEliderTest, MAYBE_ElideRectangleTextCheckLineWidth) {
- gfx::Font font = GetTestingFont();
- const int kAvailableWidth = 235;
+TEST(TextEliderTest, ElideRectangleTextCheckLineWidth) {
+ gfx::Font font;
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+ // Use a specific font to expose the line width exceeding problem.
+ font = gfx::Font("LucidaGrande", 12);
+#endif
+ const float kAvailableWidth = 235;
const int kAvailableHeight = 1000;
const char text[] = "that Russian place we used to go to after fencing";
std::vector<string16> lines;

Powered by Google App Engine
This is Rietveld 408576698