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

Side by Side Diff: third_party/WebKit/Source/core/editing/CaretDisplayItemClientTest.cpp

Issue 2748563002: Fix another caret paint invalidation issue (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/CaretDisplayItemClient.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/HTMLNames.h" 5 #include "core/HTMLNames.h"
6 #include "core/editing/FrameSelection.h" 6 #include "core/editing/FrameSelection.h"
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/layout/LayoutTestHelper.h" 8 #include "core/layout/LayoutTestHelper.h"
9 #include "core/layout/LayoutView.h" 9 #include "core/layout/LayoutView.h"
10 #include "core/page/FocusController.h" 10 #include "core/page/FocusController.h"
11 #include "core/paint/PaintLayer.h" 11 #include "core/paint/PaintLayer.h"
12 #include "platform/graphics/GraphicsLayer.h" 12 #include "platform/graphics/GraphicsLayer.h"
13 #include "platform/graphics/paint/RasterInvalidationTracking.h" 13 #include "platform/graphics/paint/RasterInvalidationTracking.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 class CaretDisplayItemClientTest : public RenderingTest { 17 class CaretDisplayItemClientTest : public RenderingTest {
18 protected: 18 protected:
19 void SetUp() override { 19 void SetUp() override {
20 RenderingTest::SetUp(); 20 RenderingTest::SetUp();
21 enableCompositing(); 21 enableCompositing();
22 selection().setCaretBlinkingSuspended(true);
22 } 23 }
23 24
24 const RasterInvalidationTracking* getRasterInvalidationTracking() const { 25 const RasterInvalidationTracking* getRasterInvalidationTracking() const {
25 // TODO(wangxianzhu): Test SPv2. 26 // TODO(wangxianzhu): Test SPv2.
26 return layoutView() 27 return layoutView()
27 .layer() 28 .layer()
28 ->graphicsLayerBacking() 29 ->graphicsLayerBacking()
29 ->getRasterInvalidationTracking(); 30 ->getRasterInvalidationTracking();
30 } 31 }
31 32
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 EXPECT_EQ(enclosingIntRect(caretVisualRect2), (*rasterInvalidations)[1].rect); 216 EXPECT_EQ(enclosingIntRect(caretVisualRect2), (*rasterInvalidations)[1].rect);
216 EXPECT_EQ(block2, (*rasterInvalidations)[1].client); 217 EXPECT_EQ(block2, (*rasterInvalidations)[1].client);
217 EXPECT_EQ(PaintInvalidationCaret, (*rasterInvalidations)[1].reason); 218 EXPECT_EQ(PaintInvalidationCaret, (*rasterInvalidations)[1].reason);
218 219
219 objectInvalidations = 220 objectInvalidations =
220 document().view()->trackedObjectPaintInvalidationsAsJSON(); 221 document().view()->trackedObjectPaintInvalidationsAsJSON();
221 ASSERT_EQ(2u, objectInvalidations->size()); 222 ASSERT_EQ(2u, objectInvalidations->size());
222 document().view()->setTracksPaintInvalidations(false); 223 document().view()->setTracksPaintInvalidations(false);
223 } 224 }
224 225
226 TEST_F(CaretDisplayItemClientTest, CaretHideMoveAndShow) {
227 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION);
228 document().page()->focusController().setActive(true);
229 document().page()->focusController().setFocused(true);
230
231 Text* text = appendTextNode("Hello, World!");
232 document().body()->focus();
233 updateAllLifecyclePhases();
234 const auto* block = toLayoutBlock(document().body()->layoutObject());
235
236 LayoutRect caretVisualRect = caretDisplayItemClient().visualRect();
237 EXPECT_EQ(1, caretVisualRect.width());
238 EXPECT_EQ(block->location(), caretVisualRect.location());
239
240 // Simulate that the blinking cursor becomes invisible.
241 selection().setCaretVisible(false);
242 // Move the caret to the end of the text.
243 document().view()->setTracksPaintInvalidations(true);
244 selection().setSelection(
245 SelectionInDOMTree::Builder().collapse(Position(text, 5)).build());
246 // Simulate that the cursor blinking is restarted.
247 selection().setCaretVisible(true);
248 updateAllLifecyclePhases();
249
250 LayoutRect newCaretVisualRect = caretDisplayItemClient().visualRect();
251 EXPECT_EQ(caretVisualRect.size(), newCaretVisualRect.size());
252 EXPECT_EQ(caretVisualRect.y(), newCaretVisualRect.y());
253 EXPECT_LT(caretVisualRect.x(), newCaretVisualRect.x());
254
255 const auto& rasterInvalidations =
256 getRasterInvalidationTracking()->trackedRasterInvalidations;
257 ASSERT_EQ(2u, rasterInvalidations.size());
258 EXPECT_EQ(enclosingIntRect(caretVisualRect), rasterInvalidations[0].rect);
259 EXPECT_EQ(block, rasterInvalidations[0].client);
260 EXPECT_EQ(PaintInvalidationCaret, rasterInvalidations[0].reason);
261 EXPECT_EQ(enclosingIntRect(newCaretVisualRect), rasterInvalidations[1].rect);
262 EXPECT_EQ(block, rasterInvalidations[1].client);
263 EXPECT_EQ(PaintInvalidationCaret, rasterInvalidations[1].reason);
264
265 auto objectInvalidations =
266 document().view()->trackedObjectPaintInvalidationsAsJSON();
267 ASSERT_EQ(1u, objectInvalidations->size());
268 String s;
269 JSONObject::cast(objectInvalidations->at(0))->get("object")->asString(&s);
270 EXPECT_EQ("Caret", s);
271 document().view()->setTracksPaintInvalidations(false);
272 }
273
225 } // namespace blink 274 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/CaretDisplayItemClient.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698