summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/paint/inline_text_box_painter_test.cc
blob: 1b505e57d1ef3e9a382a7837f3396f5a82f65d81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/paint/inline_text_box_painter.h"

#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/editing/testing/selection_sample.h"
#include "third_party/blink/renderer/core/paint/paint_controller_paint_test.h"

using testing::ElementsAre;

namespace blink {

using InlineTextBoxPainterTest = PaintControllerPaintTest;

INSTANTIATE_PAINT_TEST_SUITE_P(InlineTextBoxPainterTest);

TEST_P(InlineTextBoxPainterTest, LineBreak) {
  SetBodyInnerHTML("<span style='font-size: 20px'>A<br>B<br>C</span>");
  // 0: view background, 1: A, 2: B, 3: C
  EXPECT_EQ(4u, ContentDisplayItems().size());

  GetDocument().GetFrame()->Selection().SelectAll();
  UpdateAllLifecyclePhasesForTest();
  // 0: view background, 1: A, 2: <br>, 3: B, 4: <br>, 5: C
  EXPECT_EQ(6u, ContentDisplayItems().size());
}

class InlineTextBoxPainterNonNGTest : public PaintControllerPaintTest,
                                      public ScopedLayoutNGForTest {
 public:
  InlineTextBoxPainterNonNGTest() : ScopedLayoutNGForTest(false) {}
};

INSTANTIATE_PAINT_TEST_SUITE_P(InlineTextBoxPainterNonNGTest);

TEST_P(InlineTextBoxPainterNonNGTest, RecordedSelectionAll) {
  if (!RuntimeEnabledFeatures::CompositeAfterPaintEnabled())
    return;
  SetBodyInnerHTML("<span>A<br>B<br>C</span>");

  GetDocument().GetFrame()->Selection().SetHandleVisibleForTesting();
  GetDocument().GetFrame()->Selection().SelectAll();
  UpdateAllLifecyclePhasesForTest();

  auto chunks = ContentPaintChunks();
  EXPECT_EQ(chunks.size(), 1u);
  EXPECT_TRUE(chunks.begin()->layer_selection_data->start.has_value());
  EXPECT_TRUE(chunks.begin()->layer_selection_data->end.has_value());
  PaintedSelectionBound start =
      chunks.begin()->layer_selection_data->start.value();
  EXPECT_EQ(start.type, gfx::SelectionBound::LEFT);
  EXPECT_EQ(start.edge_start, IntPoint(8, 8));
  EXPECT_EQ(start.edge_end, IntPoint(8, 9));

  PaintedSelectionBound end = chunks.begin()->layer_selection_data->end.value();
  EXPECT_EQ(end.type, gfx::SelectionBound::RIGHT);
  EXPECT_EQ(end.edge_start, IntPoint(9, 10));
  EXPECT_EQ(end.edge_end, IntPoint(9, 11));
}

TEST_P(InlineTextBoxPainterNonNGTest, RecordedSelectionMultiline) {
  if (!RuntimeEnabledFeatures::CompositeAfterPaintEnabled())
    return;

  GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping(
      SelectionSample::SetSelectionText(
          GetDocument().body(),
          "<div style='white-space:pre'>f^oo\nbar\nb|az</div>"));
  GetDocument().GetFrame()->Selection().SetHandleVisibleForTesting();
  UpdateAllLifecyclePhasesForTest();

  auto chunks = ContentPaintChunks();
  EXPECT_EQ(chunks.size(), 1u);
  EXPECT_TRUE(chunks.begin()->layer_selection_data->start.has_value());
  EXPECT_TRUE(chunks.begin()->layer_selection_data->end.has_value());
  PaintedSelectionBound start =
      chunks.begin()->layer_selection_data->start.value();
  EXPECT_EQ(start.type, gfx::SelectionBound::LEFT);
  EXPECT_EQ(start.edge_start, IntPoint(8, 8));
  EXPECT_EQ(start.edge_end, IntPoint(8, 9));

  PaintedSelectionBound end = chunks.begin()->layer_selection_data->end.value();
  EXPECT_EQ(end.type, gfx::SelectionBound::RIGHT);
  EXPECT_EQ(end.edge_start, IntPoint(9, 10));
  EXPECT_EQ(end.edge_end, IntPoint(9, 11));
}

}  // namespace blink