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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 1953133002: [WIP: not for review] Reduce re-layout Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/render_text_unittest.cc
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index 91aa96d49e30dfcf904d8c9765a26e4fe8753d5d..2b8b4cc3d5f1e516c7c2c303f1b04ee8460b03ee 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -739,8 +739,57 @@ TEST_F(RenderTextTest, ElidedObscuredText) {
EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text());
EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText());
}
+
#endif // !defined(OS_MACOSX)
+TEST_F(RenderTextTest, MultilineElide) {
+ std::unique_ptr<RenderText> render_text(new RenderTextHarfBuzz);
+ base::string16 input_text;
+ // aim for 3 lines
+ for (int i = 0; i < 20; ++i)
+ input_text.append(ASCIIToUTF16("hello world "));
+ render_text->SetText(input_text);
+ // Apply a style that tweaks the layout to make sure elision is calculated
+ // with these styles. This must be done after |SetText()|.
+ render_text->ApplyStyle(gfx::BOLD, true, gfx::Range(1, 20));
+ render_text->ApplyStyle(gfx::ITALIC, true, gfx::Range(1, 20));
+ render_text->ApplyStyle(gfx::DIAGONAL_STRIKE, true, gfx::Range(1, 20));
+ render_text->SetMultiline(true);
+ render_text->SetElideBehavior(ELIDE_TAIL);
+ render_text->SetMaxLines(3);
+ const gfx::Size size = render_text->GetStringSize();
+ // Fit in 3 lines. (If we knew the width of a word, we could
+ // anticipate word wrap better.)
+ render_text->SetDisplayRect(gfx::Rect((size.width() + 96) / 3, 0));
+ render_text->GetStringSize();
+ EXPECT_EQ(input_text, render_text->GetDisplayText());
+
+ const base::char16 kEllipsisUTF16[] = {0x2026, 0};
+ base::string16 actual_text;
+ // Try widenining the space gradually, one pixel at a time, trying
+ // to trigger a failure in layout.
+ for (int i = (size.width() - 12) / 3; i < (size.width() + 30) / 3; ++i) {
+ render_text->SetDisplayRect(gfx::Rect(i, 0));
+ render_text->GetStringSize();
+ actual_text = render_text->GetDisplayText();
+ EXPECT_TRUE(actual_text.size() < input_text.size());
+ EXPECT_EQ(actual_text, input_text.substr(0, actual_text.size() - 1) +
+ base::string16(kEllipsisUTF16));
+ EXPECT_EQ(3U, render_text->GetNumLines());
+ }
+ // Now remove line restriction.
+ render_text->SetMaxLines(0);
+ render_text->GetStringSize();
+ EXPECT_EQ(input_text, render_text->GetDisplayText());
+
+ // And put it back.
+ render_text->SetMaxLines(3);
+ render_text->GetStringSize();
+ EXPECT_TRUE(actual_text.size() < input_text.size());
+ EXPECT_EQ(actual_text, input_text.substr(0, actual_text.size() - 1) +
+ base::string16(kEllipsisUTF16));
+}
+
TEST_F(RenderTextTest, ElidedEmail) {
std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
render_text->SetText(ASCIIToUTF16("test@example.com"));

Powered by Google App Engine
This is Rietveld 408576698