Index: ui/gfx/render_text_unittest.cc |
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc |
index 44aaa1a43b5772eefff567e04d4a8f802b97a011..e6ccdb3e2368a129e419ad54f08014b6a3979ea0 100644 |
--- a/ui/gfx/render_text_unittest.cc |
+++ b/ui/gfx/render_text_unittest.cc |
@@ -2003,6 +2003,45 @@ TEST_F(RenderTextTest, Multiline_Newline) { |
} |
} |
+// Ensure RTL alignment works. |
+TEST_F(RenderTextTest, Multiline_HorizontalAlignment) { |
+ const struct { |
+ const wchar_t* const text; |
+ gfx::HorizontalAlignment alignment; |
+ } kTestStrings[] = { |
+ { L"abcdefghij\nhijkl", gfx::ALIGN_LEFT }, |
+ // hebrew |
+ { L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7\n\x5d0\x5d1\x5d2\x5d3", |
+ gfx::ALIGN_RIGHT }, |
+ // arabic |
+ { L"\x62a\x62b\x62c\x62d\x62e\x62f\x630\n\x660\x661\x662\x663\x664", |
+ gfx::ALIGN_RIGHT }, |
+ }; |
+ RenderTextHarfBuzz render_text; |
+ render_text.SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); |
+ render_text.set_glyph_width_for_test(5); |
+ render_text.SetDisplayRect(Rect(100, 1000)); |
+ render_text.SetMultiline(true); |
+ |
+ Canvas canvas; |
+ for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
+ SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "] %ls", i, |
+ kTestStrings[i].text)); |
+ render_text.SetText(WideToUTF16(kTestStrings[i].text)); |
+ render_text.Draw(&canvas); |
+ ASSERT_LE(2u, render_text.lines().size()); |
+ if (kTestStrings[i].alignment == gfx::ALIGN_LEFT) { |
+ EXPECT_EQ(0, render_text.GetAlignmentOffset(0).x()); |
+ EXPECT_EQ(0, render_text.GetAlignmentOffset(1).x()); |
+ } else { |
+ // Second string should be always shorter, thus |
msw
2015/02/19 01:13:50
nit: consider: "The second line in the test string
|
+ // the seond line has longer alignment. |
msw
2015/02/19 01:13:50
nit: "second"
|
+ EXPECT_LT(render_text.GetAlignmentOffset(0).x(), |
+ render_text.GetAlignmentOffset(1).x()); |
+ } |
+ } |
+} |
+ |
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", |