Chromium Code Reviews| Index: ui/gfx/render_text_unittest.cc |
| diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc |
| index c51ef30315f664206e9501ccc234b411236c93a4..356c395af6c13130f2b3dcef0c49e403b3881d12 100644 |
| --- a/ui/gfx/render_text_unittest.cc |
| +++ b/ui/gfx/render_text_unittest.cc |
| @@ -514,6 +514,13 @@ class RenderTextHarfBuzzTest : public RenderTextTest { |
| return GetRenderTextHarfBuzz()->ShapeRunWithFont(text, font, params, run); |
| } |
| + int GetCursorYForTesting(int line_num = 0) { |
|
msw
2016/12/07 20:20:35
nit: use the line_num param in new tests, or remov
karandeepb
2016/12/12 10:36:19
Added tests using this.
|
| + test_api()->EnsureLayout(); |
| + const internal::Line& line = test_api()->lines()[line_num]; |
| + return GetRenderText()->GetLineOffset(line_num).y() + |
| + line.size.height() / 2; |
|
msw
2016/12/07 20:20:35
optional nit: just add 1 instead of half the line
karandeepb
2016/12/12 10:36:19
Done.
|
| + } |
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzzTest); |
| }; |
| @@ -788,10 +795,14 @@ TEST_P(RenderTextHarfBuzzTest, ObscuredText) { |
| // FindCursorPosition() should not return positions between a surrogate pair. |
| render_text->SetDisplayRect(Rect(0, 0, 20, 20)); |
| - EXPECT_EQ(render_text->FindCursorPosition(Point(0, 0)).caret_pos(), 0U); |
| - EXPECT_EQ(render_text->FindCursorPosition(Point(20, 0)).caret_pos(), 2U); |
| + const int cursor_y = GetCursorYForTesting(); |
| + EXPECT_EQ(render_text->FindCursorPosition(Point(0, cursor_y)).caret_pos(), |
| + 0U); |
| + EXPECT_EQ(render_text->FindCursorPosition(Point(20, cursor_y)).caret_pos(), |
| + 2U); |
| for (int x = -1; x <= 20; ++x) { |
| - SelectionModel selection = render_text->FindCursorPosition(Point(x, 0)); |
| + SelectionModel selection = |
| + render_text->FindCursorPosition(Point(x, cursor_y)); |
| EXPECT_TRUE(selection.caret_pos() == 0U || selection.caret_pos() == 2U); |
| } |
| @@ -1783,7 +1794,9 @@ TEST_P(RenderTextHarfBuzzTest, FindCursorPosition) { |
| const Range range(render_text->GetGlyphBounds(j)); |
| // Test a point just inside the leading edge of the glyph bounds. |
| int x = range.is_reversed() ? range.GetMax() - 1 : range.GetMin() + 1; |
| - EXPECT_EQ(j, render_text->FindCursorPosition(Point(x, 0)).caret_pos()); |
| + EXPECT_EQ( |
| + j, render_text->FindCursorPosition(Point(x, GetCursorYForTesting())) |
| + .caret_pos()); |
| } |
| } |
| } |
| @@ -2863,12 +2876,12 @@ TEST_P(RenderTextHarfBuzzTest, Multiline_Newline) { |
| // Ranges of the characters on each line preceding the newline. |
| const Range line_char_ranges[3]; |
| } kTestStrings[] = { |
| - {L"abc\ndef", 2ul, { Range(0, 3), Range(4, 7), Range::InvalidRange() } }, |
| - {L"a \n b ", 2ul, { Range(0, 2), Range(3, 6), Range::InvalidRange() } }, |
| - {L"ab\n", 2ul, { Range(0, 2), Range(), Range::InvalidRange() } }, |
| - {L"a\n\nb", 3ul, { Range(0, 1), Range(), Range(3, 4) } }, |
| - {L"\nab", 2ul, { Range(), Range(1, 3), Range::InvalidRange() } }, |
| - {L"\n", 2ul, { Range(), Range(), Range::InvalidRange() } }, |
| + {L"abc\ndef", 2ul, {Range(0, 3), Range(4, 7), Range::InvalidRange()}}, |
| + {L"a \n b ", 2ul, {Range(0, 2), Range(3, 6), Range::InvalidRange()}}, |
| + {L"ab\n", 2ul, {Range(0, 2), Range(), Range::InvalidRange()}}, |
| + {L"a\n\nb", 3ul, {Range(0, 1), Range(2, 3), Range(3, 4)}}, |
| + {L"\nab", 2ul, {Range(0, 1), Range(1, 3), Range::InvalidRange()}}, |
| + {L"\n", 2ul, {Range(0, 1), Range(), Range::InvalidRange()}}, |
| }; |
| RenderText* render_text = GetRenderText(); |
| @@ -3898,6 +3911,7 @@ TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_LTR) { |
| render_text->ApplyStyle(ITALIC, true, Range(3, 8)); |
| render_text->ApplyStyle(DIAGONAL_STRIKE, true, Range(5, 7)); |
| render_text->ApplyStyle(STRIKE, true, Range(1, 7)); |
| + const int cursor_y = GetCursorYForTesting(); |
| const std::vector<RenderText::FontSpan> font_spans = |
| render_text->GetFontSpansForTesting(); |
| @@ -3931,14 +3945,14 @@ TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_LTR) { |
| { |
| SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds")); |
| EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( |
| - Point(-5, 5), &decorated_word, &baseline_point)); |
| + Point(-5, cursor_y), &decorated_word, &baseline_point)); |
| VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); |
| EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); |
| } |
| { |
| SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds")); |
| EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( |
| - Point(105, 5), &decorated_word, &baseline_point)); |
| + Point(105, cursor_y), &decorated_word, &baseline_point)); |
| VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); |
| EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); |
| } |
| @@ -3982,6 +3996,7 @@ TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_RTL) { |
| render_text->ApplyStyle(ITALIC, true, Range(0, 3)); |
| render_text->ApplyStyle(DIAGONAL_STRIKE, true, Range(0, 2)); |
| render_text->ApplyStyle(STRIKE, true, Range(2, 5)); |
| + const int cursor_y = GetCursorYForTesting(); |
| const std::vector<RenderText::FontSpan> font_spans = |
| render_text->GetFontSpansForTesting(); |
| @@ -4014,14 +4029,14 @@ TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_RTL) { |
| { |
| SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds")); |
| EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( |
| - Point(-5, 5), &decorated_word, &baseline_point)); |
| + Point(-5, cursor_y), &decorated_word, &baseline_point)); |
| VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); |
| EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); |
| } |
| { |
| SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds")); |
| EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( |
| - Point(105, 5), &decorated_word, &baseline_point)); |
| + Point(105, cursor_y), &decorated_word, &baseline_point)); |
| VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); |
| EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); |
| } |