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

Side by Side Diff: third_party/WebKit/Source/core/dom/ElementTest.cpp

Issue 2647533002: Force compositing inputs to be clean for getBoundingClientRect (Closed)
Patch Set: Add LayoutTests to validate post-layout behavior Created 3 years, 11 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/dom/Element.h" 5 #include "core/dom/Element.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/frame/FrameView.h" 8 #include "core/frame/FrameView.h"
9 #include "core/html/HTMLHtmlElement.h" 9 #include "core/html/HTMLHtmlElement.h"
10 #include "core/testing/DummyPageHolder.h" 10 #include "core/testing/DummyPageHolder.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include <memory> 12 #include <memory>
13 13
14 namespace blink { 14 namespace blink {
15 15
16 TEST(ElementTest, SupportsFocus) { 16 TEST(ElementTest, SupportsFocus) {
17 std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create(); 17 std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create();
18 Document& document = pageHolder->document(); 18 Document& document = pageHolder->document();
19 DCHECK(isHTMLHtmlElement(document.documentElement())); 19 DCHECK(isHTMLHtmlElement(document.documentElement()));
20 document.setDesignMode("on"); 20 document.setDesignMode("on");
21 document.view()->updateAllLifecyclePhases(); 21 document.view()->updateAllLifecyclePhases();
22 EXPECT_TRUE(document.documentElement()->supportsFocus()) 22 EXPECT_TRUE(document.documentElement()->supportsFocus())
23 << "<html> with designMode=on should be focusable."; 23 << "<html> with designMode=on should be focusable.";
24 } 24 }
25 25
26 // Verifies that calling getBoundingClientRect cleans compositor inputs.
27 // Cleaning the compositor inputs is required so that position:sticky elements
28 // and their descendants have the correct location.
29 TEST(ElementTest, GetBoundingClientRectUpdatesCompositorInputs) {
30 std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create();
31 Document& document = pageHolder->document();
32
33 document.view()->updateAllLifecyclePhases();
34 EXPECT_EQ(DocumentLifecycle::PaintClean, document.lifecycle().state());
35
36 document.body()->setInnerHTML("<div id='test'></div>");
37 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending,
38 document.lifecycle().state());
39
40 document.body()->getBoundingClientRect();
41 EXPECT_EQ(DocumentLifecycle::CompositingClean, document.lifecycle().state());
42 }
43
44 // Verifies that calling scrollIntoView* cleans compositor inputs. Cleaning the
45 // compositor inputs is required so that position:sticky elements and their
46 // descendants have the correct location.
47 TEST(ElementTest, ScrollIntoViewUpdatesCompositorInputs) {
48 std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create();
49 Document& document = pageHolder->document();
50
51 document.view()->updateAllLifecyclePhases();
52 EXPECT_EQ(DocumentLifecycle::PaintClean, document.lifecycle().state());
53
54 document.body()->setInnerHTML("<div id='test'></div>");
55 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending,
56 document.lifecycle().state());
57
58 document.body()->scrollIntoView();
59 EXPECT_EQ(DocumentLifecycle::CompositingClean, document.lifecycle().state());
60
61 document.body()->setInnerHTML("<div id='test2'></div>");
62 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending,
63 document.lifecycle().state());
64
65 document.body()->scrollIntoViewIfNeeded();
66 EXPECT_EQ(DocumentLifecycle::CompositingClean, document.lifecycle().state());
67 }
68
69 // Verifies that calling offsetTop/offsetLeft cleans compositor inputs.
70 // Cleaning the compositor inputs is required so that position:sticky elements
71 // and their descendants have the correct location.
72 TEST(ElementTest, OffsetTopAndLeftUpdateCompositorInputs) {
73 std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create();
74 Document& document = pageHolder->document();
75
76 document.view()->updateAllLifecyclePhases();
77 EXPECT_EQ(DocumentLifecycle::PaintClean, document.lifecycle().state());
78
79 document.body()->setInnerHTML("<div id='test'></div>");
80 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending,
81 document.lifecycle().state());
82
83 document.body()->offsetTop();
84 EXPECT_EQ(DocumentLifecycle::CompositingClean, document.lifecycle().state());
85
86 document.body()->setInnerHTML("<div id='test2'></div>");
87 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending,
88 document.lifecycle().state());
89
90 document.body()->offsetLeft();
flackr 2017/01/23 16:43:50 It might be worth unit testing that the correct of
smcgruer 2017/01/24 15:26:30 Tried this, however for reasons I don't yet unders
flackr 2017/01/24 17:00:21 I think I know what's happening. This normally get
flackr 2017/01/24 18:20:54 I guess remove the assertion that compositing inpu
smcgruer 2017/01/24 20:09:42 Added a partially-complete test to make sure that
flackr 2017/01/24 20:22:28 Acknowledged. That's exactly what I was suggesting
91 EXPECT_EQ(DocumentLifecycle::CompositingClean, document.lifecycle().state());
92 }
93
26 } // namespace blink 94 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698