| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/layout/LayoutBoxModelObject.h" |
| 6 |
| 7 #include "core/html/HTMLElement.h" |
| 8 #include "core/layout/ImageQualityController.h" |
| 9 #include "core/layout/LayoutTestHelper.h" |
| 10 #include "core/page/scrolling/StickyPositionScrollingConstraints.h" |
| 11 #include "core/paint/PaintLayer.h" |
| 12 #include "core/paint/PaintLayerScrollableArea.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 class LayoutBoxModelObjectTest : public RenderingTest { |
| 18 }; |
| 19 |
| 20 // Verifies that the sticky constraints are correctly computed. |
| 21 TEST_F(LayoutBoxModelObjectTest, StickyPositionConstraints) |
| 22 { |
| 23 setBodyInnerHTML("<style>#sticky { position: sticky; top: 0; width: 100px; h
eight: 100px; }" |
| 24 "#container { box-sizing: border-box; position: relative; top: 100px; he
ight: 400px; width: 200px; padding: 10px; border: 5px solid black; }" |
| 25 "#scroller { height: 100px; overflow: auto; position: relative; top: 200
px; }" |
| 26 ".spacer { height: 1000px; }</style>" |
| 27 "<div id='scroller'><div id='container'><div id='sticky'></div></div><di
v class='spacer'></div></div>"); |
| 28 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle
mentId("scroller")); |
| 29 scroller->getScrollableArea()->scrollToYOffset(50); |
| 30 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); |
| 31 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme
ntId("sticky")); |
| 32 sticky->updateStickyPositionConstraints(); |
| 33 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 34 |
| 35 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); |
| 36 ASSERT_EQ(0.f, constraints.topOffset()); |
| 37 |
| 38 // The coordinates of the constraint rects should all be with respect to the
unscrolled scroller. |
| 39 ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(constraints.scrollCon
tainerRelativeContainingBlockRect())); |
| 40 ASSERT_EQ(IntRect(15, 115, 100, 100), enclosingIntRect(constraints.scrollCon
tainerRelativeStickyBoxRect())); |
| 41 } |
| 42 |
| 43 // Verifies that the sticky constraints are correctly computed. |
| 44 TEST_F(LayoutBoxModelObjectTest, StickyPositionPercentageStyles) |
| 45 { |
| 46 setBodyInnerHTML("<style>#sticky { position: sticky; margin-top: 10%; top: 0
; width: 100px; height: 100px; }" |
| 47 "#container { box-sizing: border-box; position: relative; top: 100px; he
ight: 400px; width: 250px; padding: 5%; border: 5px solid black; }" |
| 48 "#scroller { width: 400px; height: 100px; overflow: auto; position: rela
tive; top: 200px; }" |
| 49 ".spacer { height: 1000px; }</style>" |
| 50 "<div id='scroller'><div id='container'><div id='sticky'></div></div><di
v class='spacer'></div></div>"); |
| 51 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle
mentId("scroller")); |
| 52 scroller->getScrollableArea()->scrollToYOffset(50); |
| 53 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); |
| 54 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme
ntId("sticky")); |
| 55 sticky->updateStickyPositionConstraints(); |
| 56 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 57 |
| 58 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); |
| 59 ASSERT_EQ(0.f, constraints.topOffset()); |
| 60 |
| 61 ASSERT_EQ(IntRect(25, 145, 200, 330), enclosingIntRect(constraints.scrollCon
tainerRelativeContainingBlockRect())); |
| 62 ASSERT_EQ(IntRect(25, 145, 100, 100), enclosingIntRect(constraints.scrollCon
tainerRelativeStickyBoxRect())); |
| 63 } |
| 64 |
| 65 // Verifies that the sticky constraints are correct when the sticky position con
tainer is also |
| 66 // the ancestor scroller. |
| 67 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller) |
| 68 { |
| 69 setBodyInnerHTML("<style>#sticky { position: sticky; top: 0; width: 100px; h
eight: 100px; }" |
| 70 "#scroller { height: 100px; width: 400px; overflow: auto; position: rela
tive; top: 200px; }" |
| 71 ".spacer { height: 1000px; }</style>" |
| 72 "<div id='scroller'><div id='sticky'></div><div class='spacer'></div></d
iv>"); |
| 73 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle
mentId("scroller")); |
| 74 scroller->getScrollableArea()->scrollToYOffset(50); |
| 75 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); |
| 76 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme
ntId("sticky")); |
| 77 sticky->updateStickyPositionConstraints(); |
| 78 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 79 |
| 80 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); |
| 81 ASSERT_EQ(IntRect(0, 0, 400, 1100), enclosingIntRect(constraints.scrollConta
inerRelativeContainingBlockRect())); |
| 82 ASSERT_EQ(IntRect(0, 0, 100, 100), enclosingIntRect(constraints.scrollContai
nerRelativeStickyBoxRect())); |
| 83 } |
| 84 |
| 85 // Verifies that the sticky constraints are correct when the sticky position obj
ect has an |
| 86 // anonymous containing block. |
| 87 TEST_F(LayoutBoxModelObjectTest, StickyPositionAnonymousContainer) |
| 88 { |
| 89 setBodyInnerHTML("<style>#sticky { display: inline-block; position: sticky;
top: 0; width: 100px; height: 100px; }" |
| 90 "#container { box-sizing: border-box; position: relative; top: 100px; he
ight: 400px; width: 200px; padding: 10px; border: 5px solid black; }" |
| 91 "#scroller { height: 100px; overflow: auto; position: relative; top: 200
px; }" |
| 92 ".header { height: 50px; }" |
| 93 ".spacer { height: 1000px; }</style>" |
| 94 "<div id='scroller'><div id='container'><div class='header'></div><div i
d='sticky'></div></div><div class='spacer'></div></div>"); |
| 95 LayoutBoxModelObject* scroller = toLayoutBoxModelObject(getLayoutObjectByEle
mentId("scroller")); |
| 96 scroller->getScrollableArea()->scrollToYOffset(50); |
| 97 ASSERT_EQ(50.0, scroller->getScrollableArea()->scrollYOffset()); |
| 98 LayoutBoxModelObject* sticky = toLayoutBoxModelObject(getLayoutObjectByEleme
ntId("sticky")); |
| 99 sticky->updateStickyPositionConstraints(); |
| 100 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); |
| 101 |
| 102 const StickyPositionScrollingConstraints& constraints = scroller->getScrolla
bleArea()->stickyConstraintsMap().get(sticky->layer()); |
| 103 ASSERT_EQ(IntRect(15, 115, 170, 370), enclosingIntRect(constraints.scrollCon
tainerRelativeContainingBlockRect())); |
| 104 ASSERT_EQ(IntRect(15, 165, 100, 100), enclosingIntRect(constraints.scrollCon
tainerRelativeStickyBoxRect())); |
| 105 } |
| 106 } // namespace blink |
| OLD | NEW |