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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 1015533016: Move allow_character_break property to RenderText. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 5 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/gfx/render_text_harfbuzz.cc ('k') | ui/gfx/text_constants.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_unittest.cc
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index fa10e542cfca27e22674cd67d7187a1fc06b4f74..2a04d7996590dd0ee374e6dc2a89396ec2966864 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -2076,6 +2076,7 @@ TEST_F(RenderTextTest, Multiline_MinWidth) {
RenderTextHarfBuzz render_text;
render_text.SetDisplayRect(Rect(1, 1000));
render_text.SetMultiline(true);
+ render_text.SetWordWrapBehavior(WRAP_LONG_WORDS);
Canvas canvas;
for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
@@ -2109,6 +2110,7 @@ TEST_F(RenderTextTest, Multiline_NormalWidth) {
render_text.set_glyph_width_for_test(5);
render_text.SetDisplayRect(Rect(50, 1000));
render_text.SetMultiline(true);
+ render_text.SetWordWrapBehavior(WRAP_LONG_WORDS);
render_text.SetHorizontalAlignment(ALIGN_TO_HEAD);
Canvas canvas;
@@ -2295,6 +2297,44 @@ TEST_F(RenderTextTest, Multiline_HorizontalAlignment) {
}
}
+TEST_F(RenderTextTest, Multiline_WordWrapBehavior) {
+ const int kGlyphSize = 5;
+ const struct {
+ const WordWrapBehavior behavior;
+ const size_t num_lines;
+ const Range char_ranges[4];
+ } kTestScenarios[] = {
+ { IGNORE_LONG_WORDS, 3u,
+ { Range(0, 4), Range(4, 11), Range(11, 14), Range::InvalidRange() } },
+ { TRUNCATE_LONG_WORDS, 3u,
+ { Range(0, 4), Range(4, 8), Range(11, 14), Range::InvalidRange() } },
+ { WRAP_LONG_WORDS, 4u,
+ { Range(0, 4), Range(4, 8), Range(8, 11), Range(11, 14) } },
+ // TODO(mukai): implement ELIDE_LONG_WORDS. It's not used right now.
+ };
+ RenderTextHarfBuzz render_text;
+ render_text.SetMultiline(true);
+ render_text.SetText(ASCIIToUTF16("foo fooooo foo"));
+ render_text.set_glyph_width_for_test(kGlyphSize);
+ render_text.SetDisplayRect(Rect(0, 0, kGlyphSize * 4, 0));
+
+ Canvas canvas;
+
+ for (size_t i = 0; i < arraysize(kTestScenarios); ++i) {
+ SCOPED_TRACE(base::StringPrintf(
+ "kTestStrings[%" PRIuS "] %d", i, kTestScenarios[i].behavior));
msw 2015/03/26 23:05:55 nit: kTestScenarios
Jun Mukai 2015/03/27 00:31:58 Done.
+ render_text.SetWordWrapBehavior(kTestScenarios[i].behavior);
+ render_text.Draw(&canvas);
+
+ ASSERT_EQ(kTestScenarios[i].num_lines, render_text.lines().size());
+ for (size_t j = 0; j < render_text.lines().size(); ++j) {
+ SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j));
+ EXPECT_EQ(kTestScenarios[i].char_ranges[j],
+ render_text.lines()[j].segments[0].char_range);
+ }
+ }
+}
+
TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) {
const wchar_t* kTestStrings[] = {
L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n",
« no previous file with comments | « ui/gfx/render_text_harfbuzz.cc ('k') | ui/gfx/text_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698