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 3657ef0353f9d09393b13f488032fa535cefc30a..c8e7c884a562900035d5e55267da8c0c45772e90 100644 |
| --- a/ui/gfx/render_text_unittest.cc |
| +++ b/ui/gfx/render_text_unittest.cc |
| @@ -473,12 +473,16 @@ class RenderTextTest : public testing::Test, |
| } |
| #endif |
| - Rect GetSelectionBoundsUnion() { |
| + Rect GetSubstringBoundsUnionForRange(const Range& range) { |
|
msw
2017/01/20 16:45:32
optional nit: drop |ForRange|
karandeepb
2017/01/23 00:20:25
Done.
|
| const std::vector<Rect> bounds = |
| - render_text_->GetSubstringBoundsForTesting(render_text_->selection()); |
| + render_text_->GetSubstringBoundsForTesting(range); |
| return std::accumulate(bounds.begin(), bounds.end(), Rect(), UnionRects); |
| } |
| + Rect GetSelectionBoundsUnion() { |
| + return GetSubstringBoundsUnionForRange(render_text_->selection()); |
| + } |
| + |
| Canvas* canvas() { return &canvas_; } |
| TestSkiaTextRenderer* renderer() { return &renderer_; } |
| test::RenderTextTestApi* test_api() { return test_api_.get(); }; |
| @@ -4160,6 +4164,82 @@ TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_RTL) { |
| } |
| } |
| +// Test that GetDecoratedWordAtPoint behaves correctly for multiline text. |
| +TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_Multiline) { |
| + const base::string16 text = ASCIIToUTF16("a b\n..\nc."); |
|
msw
2017/01/20 16:45:32
nit: make at least one of these words multi-charac
karandeepb
2017/01/23 00:20:25
Done.
|
| + const size_t kWordOneIndex = 0; // Index of character 'a'. |
| + const size_t kWordTwoIndex = 2; // Index of character 'b'. |
| + const size_t kWordThreeIndex = 7; // Index of character 'c'. |
| + |
| + // Set up render text. |
| + RenderText* render_text = GetRenderText(); |
| + render_text->SetMultiline(true); |
| + render_text->SetDisplayRect(Rect(500, 500)); |
| + render_text->SetText(text); |
| + render_text->ApplyWeight(Font::Weight::SEMIBOLD, Range(0, 3)); |
| + render_text->ApplyStyle(UNDERLINE, true, Range(1, 7)); |
| + render_text->ApplyStyle(STRIKE, true, Range(1, 8)); |
| + render_text->ApplyStyle(ITALIC, true, Range(5, 8)); |
| + |
| + // Set up test expectations. |
| + const std::vector<RenderText::FontSpan> font_spans = |
| + render_text->GetFontSpansForTesting(); |
| + |
| + DecoratedText expected_word_1; |
| + expected_word_1.text = ASCIIToUTF16("a"); |
| + expected_word_1.attributes.push_back(CreateRangedAttribute( |
| + font_spans, 0, kWordOneIndex, Font::Weight::SEMIBOLD, 0)); |
| + const Rect left_glyph_word_1 = |
| + GetSubstringBoundsUnionForRange(Range(kWordOneIndex, kWordOneIndex + 1)); |
| + |
| + DecoratedText expected_word_2; |
| + expected_word_2.text = ASCIIToUTF16("b"); |
| + expected_word_2.attributes.push_back(CreateRangedAttribute( |
| + font_spans, 0, kWordTwoIndex, Font::Weight::SEMIBOLD, |
| + UNDERLINE_MASK | STRIKE_MASK)); |
| + const Rect left_glyph_word_2 = |
| + GetSubstringBoundsUnionForRange(Range(kWordTwoIndex, kWordTwoIndex + 1)); |
| + |
| + DecoratedText expected_word_3; |
| + expected_word_3.text = ASCIIToUTF16("c"); |
| + expected_word_3.attributes.push_back( |
| + CreateRangedAttribute(font_spans, 0, kWordThreeIndex, |
| + Font::Weight::NORMAL, STRIKE_MASK | ITALIC_MASK)); |
| + const Rect left_glyph_word_3 = GetSubstringBoundsUnionForRange( |
| + Range(kWordThreeIndex, kWordThreeIndex + 1)); |
| + |
| + DecoratedText decorated_word; |
| + Point baseline_point; |
| + { |
| + // Query to the left of the first line. |
| + EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( |
| + Point(-5, GetCursorYForTesting(0)), &decorated_word, &baseline_point)); |
| + VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); |
| + EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); |
| + } |
| + { |
| + // Query on the second line. |
| + EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( |
| + Point(5, GetCursorYForTesting(1)), &decorated_word, &baseline_point)); |
| + VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); |
| + EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); |
| + } |
| + { |
| + // Query at the center point of the character 'c'. |
| + EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( |
| + left_glyph_word_3.CenterPoint(), &decorated_word, &baseline_point)); |
| + VerifyDecoratedWordsAreEqual(expected_word_3, decorated_word); |
| + EXPECT_TRUE(left_glyph_word_3.Contains(baseline_point)); |
| + } |
| + { |
| + // Query to the right of the third line. |
| + EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( |
| + Point(505, GetCursorYForTesting(2)), &decorated_word, &baseline_point)); |
| + VerifyDecoratedWordsAreEqual(expected_word_3, decorated_word); |
| + EXPECT_TRUE(left_glyph_word_3.Contains(baseline_point)); |
| + } |
| +} |
| + |
| // Verify the boolean return value of GetDecoratedWordAtPoint. |
| TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_Return) { |
| RenderText* render_text = GetRenderText(); |