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

Unified Diff: third_party/WebKit/Source/core/layout/LayoutBoxModelObjectTest.cpp

Issue 2020103002: Fix sticky constraints and update sticky layer positions recursively after scroll. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bugs with overflow scrollers in sticky position constraints, add unit tests, and test clipped b… Created 4 years, 7 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/layout/LayoutBoxModelObjectTest.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutBoxModelObjectTest.cpp b/third_party/WebKit/Source/core/layout/LayoutBoxModelObjectTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..09a19f51a93d6d0b716459c59f4c9b7dafe53793
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/LayoutBoxModelObjectTest.cpp
@@ -0,0 +1,84 @@
+// Copyright 2016 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 "core/layout/LayoutBoxModelObject.h"
+
+#include "core/html/HTMLElement.h"
+#include "core/layout/ImageQualityController.h"
+#include "core/layout/LayoutTestHelper.h"
+#include "core/page/scrolling/StickyPositionScrollingConstraints.h"
+#include "core/paint/PaintLayer.h"
+#include "core/paint/PaintLayerScrollableArea.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+class LayoutBoxModelObjectTest : public RenderingTest {
+};
+
+// Verifies that the sticky constraints are correctly computed.
+TEST_F(LayoutBoxModelObjectTest, StickyPositionConstraints)
+{
+ setBodyInnerHTML("<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; }"
+ "#container { box-sizing: border-box; position: relative; top: 100px; height: 400px; width: 200px; padding: 10px; border: 5px solid black; }"
+ "#scroller { height: 100px; overflow: auto; position: relative; top: 200px; }"
+ ".spacer { height: 1000px; }</style>"
+ "<div id='scroller'><div id='container'><div id='sticky'></div></div><div class='spacer'></div></div>");
+ LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByElementId("scroller"));
+ scroller->getScrollableArea()->scrollToYOffset(50);
+ ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset());
+ LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByElementId("sticky"));
+ sticky->updateStickyPositionConstraints();
+ ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer());
+
+ const StickyPositionScrollingConstraints& constraints = scroller->getScrollableArea()->stickyConstraintsMap().get(sticky->layer());
+ ASSERT_EQ(0.f, constraints.topOffset());
+
+ // The coordinates of the constraint rects should all be with respect to the unscrolled scroller.
+ ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(constraints.scrollContainerRelativeContainingBlockRect()));
chrishtr 2016/06/06 22:18:40 Why 115 and not 15?
flackr 2016/06/09 17:13:33 Because it's 115 from the top of the scrollable ar
+ ASSERT_EQ(IntRect(15, 115, 100, 100), enclosingIntRect(constraints.scrollContainerRelativeStickyBoxRect()));
+}
+
+// Verifies that the sticky constraints are correct when the sticky position container is also
+// the ancestor scroller.
+TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller)
+{
+ setBodyInnerHTML("<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; }"
+ "#scroller { height: 100px; width: 400px; overflow: auto; position: relative; top: 200px; }"
+ ".spacer { height: 1000px; }</style>"
+ "<div id='scroller'><div id='sticky'></div><div class='spacer'></div></div>");
+ LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByElementId("scroller"));
+ scroller->getScrollableArea()->scrollToYOffset(50);
+ ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset());
+ LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByElementId("sticky"));
+ sticky->updateStickyPositionConstraints();
+ ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer());
+
+ const StickyPositionScrollingConstraints& constraints = scroller->getScrollableArea()->stickyConstraintsMap().get(sticky->layer());
+ ASSERT_EQ(IntRect(0, 0, 400, 1100), enclosingIntRect(constraints.scrollContainerRelativeContainingBlockRect()));
chrishtr 2016/06/06 22:18:39 Why should it include the overflow (and hence heig
flackr 2016/06/09 17:13:33 Because the #sticky element is constrained to the
+ ASSERT_EQ(IntRect(0, 0, 100, 100), enclosingIntRect(constraints.scrollContainerRelativeStickyBoxRect()));
+}
+
+// Verifies that the sticky constraints are correct when the sticky position object has an
+// anonymous containing block.
+TEST_F(LayoutBoxModelObjectTest, StickyPositionAnonymousContainer)
+{
+ setBodyInnerHTML("<style>#sticky { display: inline-block; position: sticky; top: 0; width: 100px; height: 100px; }"
+ "#container { box-sizing: border-box; position: relative; top: 100px; height: 400px; width: 200px; padding: 10px; border: 5px solid black; }"
chrishtr 2016/06/06 22:18:40 Where is the anonymous containing block in this ex
flackr 2016/06/09 17:13:33 Inside .container, .header is a block and #sticky
+ "#scroller { height: 100px; overflow: auto; position: relative; top: 200px; }"
+ ".header { height: 50px; }"
+ ".spacer { height: 1000px; }</style>"
+ "<div id='scroller'><div id='container'><div class='header'></div><div id='sticky'></div></div><div class='spacer'></div></div>");
+ LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByElementId("scroller"));
+ scroller->getScrollableArea()->scrollToYOffset(50);
+ ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset());
+ LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByElementId("sticky"));
+ sticky->updateStickyPositionConstraints();
+ ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer());
+
+ const StickyPositionScrollingConstraints& constraints = scroller->getScrollableArea()->stickyConstraintsMap().get(sticky->layer());
+ ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(constraints.scrollContainerRelativeContainingBlockRect()));
+ ASSERT_EQ(IntRect(15, 165, 100, 100), enclosingIntRect(constraints.scrollContainerRelativeStickyBoxRect()));
+}
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698