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

Side by Side Diff: third_party/WebKit/Source/core/paint/BlockPaintInvalidatorTest.cpp

Issue 2665823002: Invalidate caret during paint invalidation (Closed)
Patch Set: Rebaseline Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/HTMLNames.h"
6 #include "core/editing/FrameSelection.h"
7 #include "core/editing/SelectionTemplate.h"
8 #include "core/frame/FrameView.h"
9 #include "core/layout/LayoutTestHelper.h"
10 #include "core/layout/LayoutView.h"
11 #include "core/paint/PaintLayer.h"
12 #include "platform/graphics/GraphicsLayer.h"
13 #include "platform/graphics/paint/RasterInvalidationTracking.h"
14
15 namespace blink {
16
17 class BlockPaintInvalidatorTest : public RenderingTest {
18 protected:
19 void SetUp() override {
20 RenderingTest::SetUp();
21 enableCompositing();
22 }
23
24 const RasterInvalidationTracking* getRasterInvalidationTracking() const {
25 // TODO(wangxianzhu): Test SPv2.
26 return layoutView()
27 .layer()
28 ->graphicsLayerBacking()
29 ->getRasterInvalidationTracking();
30 }
31
32 FrameSelection& selection() const {
33 return document().view()->frame().selection();
34 }
35
36 Text* appendTextNode(const String& data) {
37 Text* text = document().createTextNode(data);
38 document().body()->appendChild(text);
39 return text;
40 }
41 };
42
43 TEST_F(BlockPaintInvalidatorTest, CaretPaintInvalidation) {
44 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION);
45 Text* text = appendTextNode("Hello, World!");
46 document().view()->updateAllLifecyclePhases();
47
48 // Focus the body. Should invalidate the new caret.
49 document().view()->setTracksPaintInvalidations(true);
50 document().body()->focus();
51 LayoutBlock* caretLayoutBlock = selection().caretLayoutBlock();
52 EXPECT_EQ(document().body()->layoutObject(), caretLayoutBlock);
53 EXPECT_TRUE(caretLayoutBlock->hasCursorCaret());
54 EXPECT_TRUE(caretLayoutBlock->mayNeedPaintInvalidation());
55
56 document().view()->updateAllLifecyclePhases();
57 EXPECT_EQ(caretLayoutBlock, selection().caretLayoutBlock());
58 EXPECT_FALSE(caretLayoutBlock->mayNeedPaintInvalidation());
59
60 LayoutRect caretRect = selection().caretLocalRect();
61 caretRect.moveBy(caretLayoutBlock->location());
62 EXPECT_EQ(caretRect, selection().getCaretDisplayItemClient().visualRect());
63
64 const auto* rasterInvalidations =
65 &getRasterInvalidationTracking()->trackedRasterInvalidations;
66 ASSERT_EQ(1u, rasterInvalidations->size());
67 EXPECT_EQ(enclosingIntRect(caretRect), (*rasterInvalidations)[0].rect);
68 EXPECT_EQ(caretLayoutBlock, (*rasterInvalidations)[0].client);
69 EXPECT_EQ(PaintInvalidationCaret, (*rasterInvalidations)[0].reason);
70
71 std::unique_ptr<JSONArray> objectInvalidations =
72 document().view()->trackedObjectPaintInvalidationsAsJSON();
73 ASSERT_EQ(1u, objectInvalidations->size());
74 String s;
75 JSONObject::cast(objectInvalidations->at(0))->get("object")->asString(&s);
76 EXPECT_EQ("Caret", s);
77 document().view()->setTracksPaintInvalidations(false);
78
79 // Move the caret to the end of the text. Should invalidate both the old and
80 // new carets.
81 document().view()->setTracksPaintInvalidations(true);
82 selection().setSelection(
83 SelectionInDOMTree::Builder().collapse(Position(text, 5)).build());
84 caretLayoutBlock = selection().caretLayoutBlock();
85 EXPECT_EQ(document().body()->layoutObject(), caretLayoutBlock);
86 EXPECT_TRUE(caretLayoutBlock->hasCursorCaret());
87 EXPECT_TRUE(caretLayoutBlock->mayNeedPaintInvalidation());
88
89 document().view()->updateAllLifecyclePhases();
90 EXPECT_EQ(caretLayoutBlock, selection().caretLayoutBlock());
91 EXPECT_FALSE(caretLayoutBlock->mayNeedPaintInvalidation());
92
93 LayoutRect newCaretRect = selection().caretLocalRect();
94 newCaretRect.moveBy(caretLayoutBlock->location());
95 EXPECT_EQ(newCaretRect, selection().getCaretDisplayItemClient().visualRect());
96
97 rasterInvalidations =
98 &getRasterInvalidationTracking()->trackedRasterInvalidations;
99 ASSERT_EQ(2u, rasterInvalidations->size());
100 EXPECT_EQ(enclosingIntRect(caretRect), (*rasterInvalidations)[0].rect);
101 EXPECT_EQ(caretLayoutBlock, (*rasterInvalidations)[0].client);
102 EXPECT_EQ(PaintInvalidationCaret, (*rasterInvalidations)[0].reason);
103 EXPECT_EQ(enclosingIntRect(newCaretRect), (*rasterInvalidations)[1].rect);
104 EXPECT_EQ(caretLayoutBlock, (*rasterInvalidations)[1].client);
105 EXPECT_EQ(PaintInvalidationCaret, (*rasterInvalidations)[1].reason);
106
107 objectInvalidations =
108 document().view()->trackedObjectPaintInvalidationsAsJSON();
109 ASSERT_EQ(1u, objectInvalidations->size());
110 JSONObject::cast(objectInvalidations->at(0))->get("object")->asString(&s);
111 EXPECT_EQ("Caret", s);
112 document().view()->setTracksPaintInvalidations(false);
113
114 // Remove selection. Should invalidate the old caret.
115 LayoutRect oldCaretRect = newCaretRect;
116 LayoutBlock* oldCaretLayoutBlock = caretLayoutBlock;
117 document().view()->setTracksPaintInvalidations(true);
118 selection().setSelection(SelectionInDOMTree());
119 EXPECT_FALSE(selection().caretLayoutBlock());
120
121 document().view()->updateAllLifecyclePhases();
122 EXPECT_FALSE(selection().caretLayoutBlock());
123
124 rasterInvalidations =
125 &getRasterInvalidationTracking()->trackedRasterInvalidations;
126 ASSERT_EQ(1u, rasterInvalidations->size());
127 EXPECT_EQ(enclosingIntRect(oldCaretRect), (*rasterInvalidations)[0].rect);
128 EXPECT_EQ(oldCaretLayoutBlock, (*rasterInvalidations)[0].client);
129
130 objectInvalidations =
131 document().view()->trackedObjectPaintInvalidationsAsJSON();
132 ASSERT_EQ(1u, objectInvalidations->size());
133 JSONObject::cast(objectInvalidations->at(0))->get("object")->asString(&s);
134 EXPECT_EQ("Caret", s);
135 document().view()->setTracksPaintInvalidations(false);
136 }
137
138 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698