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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/ElementTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/ElementTest.cpp b/third_party/WebKit/Source/core/dom/ElementTest.cpp
index 30064c67ba3ee38b3cfacc842460acaf28119ddd..d1c2f6aac314ecc356d9d84de3ac6d082fe462c4 100644
--- a/third_party/WebKit/Source/core/dom/ElementTest.cpp
+++ b/third_party/WebKit/Source/core/dom/ElementTest.cpp
@@ -23,4 +23,72 @@ TEST(ElementTest, SupportsFocus) {
<< "<html> with designMode=on should be focusable.";
}
+// Verifies that calling getBoundingClientRect cleans compositor inputs.
+// Cleaning the compositor inputs is required so that position:sticky elements
+// and their descendants have the correct location.
+TEST(ElementTest, GetBoundingClientRectUpdatesCompositorInputs) {
+ std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create();
+ Document& document = pageHolder->document();
+
+ document.view()->updateAllLifecyclePhases();
+ EXPECT_EQ(DocumentLifecycle::PaintClean, document.lifecycle().state());
+
+ document.body()->setInnerHTML("<div id='test'></div>");
+ EXPECT_EQ(DocumentLifecycle::VisualUpdatePending,
+ document.lifecycle().state());
+
+ document.body()->getBoundingClientRect();
+ EXPECT_EQ(DocumentLifecycle::CompositingClean, document.lifecycle().state());
+}
+
+// Verifies that calling scrollIntoView* cleans compositor inputs. Cleaning the
+// compositor inputs is required so that position:sticky elements and their
+// descendants have the correct location.
+TEST(ElementTest, ScrollIntoViewUpdatesCompositorInputs) {
+ std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create();
+ Document& document = pageHolder->document();
+
+ document.view()->updateAllLifecyclePhases();
+ EXPECT_EQ(DocumentLifecycle::PaintClean, document.lifecycle().state());
+
+ document.body()->setInnerHTML("<div id='test'></div>");
+ EXPECT_EQ(DocumentLifecycle::VisualUpdatePending,
+ document.lifecycle().state());
+
+ document.body()->scrollIntoView();
+ EXPECT_EQ(DocumentLifecycle::CompositingClean, document.lifecycle().state());
+
+ document.body()->setInnerHTML("<div id='test2'></div>");
+ EXPECT_EQ(DocumentLifecycle::VisualUpdatePending,
+ document.lifecycle().state());
+
+ document.body()->scrollIntoViewIfNeeded();
+ EXPECT_EQ(DocumentLifecycle::CompositingClean, document.lifecycle().state());
+}
+
+// Verifies that calling offsetTop/offsetLeft cleans compositor inputs.
+// Cleaning the compositor inputs is required so that position:sticky elements
+// and their descendants have the correct location.
+TEST(ElementTest, OffsetTopAndLeftUpdateCompositorInputs) {
+ std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create();
+ Document& document = pageHolder->document();
+
+ document.view()->updateAllLifecyclePhases();
+ EXPECT_EQ(DocumentLifecycle::PaintClean, document.lifecycle().state());
+
+ document.body()->setInnerHTML("<div id='test'></div>");
+ EXPECT_EQ(DocumentLifecycle::VisualUpdatePending,
+ document.lifecycle().state());
+
+ document.body()->offsetTop();
+ EXPECT_EQ(DocumentLifecycle::CompositingClean, document.lifecycle().state());
+
+ document.body()->setInnerHTML("<div id='test2'></div>");
+ EXPECT_EQ(DocumentLifecycle::VisualUpdatePending,
+ document.lifecycle().state());
+
+ 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
+ EXPECT_EQ(DocumentLifecycle::CompositingClean, document.lifecycle().state());
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698