| Index: third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp b/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
|
| index 9035f2f6c664cf0abdae702a48052769609cef39..dab713a8c396568cd5bdd2b2113362ed71009e76 100644
|
| --- a/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
|
| +++ b/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
|
| @@ -309,7 +309,8 @@ TEST_F(ScrollAnchorTest, ExcludeAnonymousCandidates)
|
| "<div id='div'>"
|
| " <a id='inline'>text</a>"
|
| " <p id='block'>Some text</p>"
|
| - "</div>");
|
| + "</div>"
|
| + "<div id=a>after</div>");
|
|
|
| ScrollableArea* viewport = layoutViewport();
|
| Element* inlineElem = document().getElementById("inline");
|
| @@ -319,8 +320,7 @@ TEST_F(ScrollAnchorTest, ExcludeAnonymousCandidates)
|
| document().getElementById("div")->scrollIntoView();
|
|
|
| // Trigger layout and verify that we don't anchor to the anonymous block.
|
| - document().getElementById("div")->setAttribute(HTMLNames::styleAttr,
|
| - AtomicString("top: 6px"));
|
| + setHeight(document().getElementById("a"), 100);
|
| update();
|
| EXPECT_EQ(inlineElem->layoutObject()->slowFirstChild(),
|
| scrollAnchor(viewport).anchorObject());
|
| @@ -347,10 +347,11 @@ TEST_F(ScrollAnchorTest, FullyContainedInlineBlock)
|
|
|
| scrollLayoutViewport(DoubleSize(0, 150));
|
|
|
| - Element* ib2 = document().getElementById("ib2");
|
| - ib2->setAttribute(HTMLNames::styleAttr, "line-height: 150px");
|
| + Element* ib1 = document().getElementById("ib1");
|
| + ib1->setAttribute(HTMLNames::styleAttr, "line-height: 150px");
|
| update();
|
| - EXPECT_EQ(ib2->layoutObject(), scrollAnchor(layoutViewport()).anchorObject());
|
| + EXPECT_EQ(document().getElementById("ib2")->layoutObject(),
|
| + scrollAnchor(layoutViewport()).anchorObject());
|
| }
|
|
|
| TEST_F(ScrollAnchorTest, TextBounds)
|
| @@ -365,11 +366,12 @@ TEST_F(ScrollAnchorTest, TextBounds)
|
| " line-height: 100px;"
|
| " }"
|
| "</style>"
|
| - "abc <b id=b>def</b> ghi");
|
| + "abc <b id=b>def</b> ghi"
|
| + "<div id=a>after</div>");
|
|
|
| scrollLayoutViewport(DoubleSize(0, 150));
|
|
|
| - setHeight(document().body(), 1100);
|
| + setHeight(document().getElementById("a"), 100);
|
| EXPECT_EQ(document().getElementById("b")->layoutObject()->slowFirstChild(),
|
| scrollAnchor(layoutViewport()).anchorObject());
|
| }
|
| @@ -383,11 +385,12 @@ TEST_F(ScrollAnchorTest, ExcludeFixedPosition)
|
| " #f { position: fixed }"
|
| "</style>"
|
| "<div id=f>fixed</div>"
|
| - "<div id=c>content</div>");
|
| + "<div id=c>content</div>"
|
| + "<div id=a>after</div>");
|
|
|
| scrollLayoutViewport(DoubleSize(0, 50));
|
|
|
| - setHeight(document().body(), 1100);
|
| + setHeight(document().getElementById("a"), 100);
|
| EXPECT_EQ(document().getElementById("c")->layoutObject(),
|
| scrollAnchor(layoutViewport()).anchorObject());
|
| }
|
| @@ -413,6 +416,7 @@ TEST_F(ScrollAnchorTest, ExcludeAbsolutePositionThatSticksToViewport)
|
| "<div id='scroller'><div id='space'>"
|
| " <div id='abs'></div>"
|
| " <div id='rel'></div>"
|
| + " <div id=a>after</div>"
|
| "</div></div>");
|
|
|
| Element* scrollerElement = document().getElementById("scroller");
|
| @@ -421,84 +425,20 @@ TEST_F(ScrollAnchorTest, ExcludeAbsolutePositionThatSticksToViewport)
|
| Element* relPos = document().getElementById("rel");
|
|
|
| scroller->scrollBy(DoubleSize(0, 25), UserScroll);
|
| - setHeight(relPos, 100);
|
| + setHeight(document().getElementById("a"), 100);
|
|
|
| // When the scroller is position:static, the anchor cannot be position:absolute.
|
| EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
|
|
|
| scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative");
|
| + update();
|
| scroller->scrollBy(DoubleSize(0, 25), UserScroll);
|
| - setHeight(relPos, 125);
|
| + setHeight(document().getElementById("a"), 125);
|
|
|
| // When the scroller is position:relative, the anchor may be position:absolute.
|
| EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject());
|
| }
|
|
|
| -// This test verifies that position:absolute elements with top/right/bottom/left
|
| -// set are not selected as anchors.
|
| -TEST_F(ScrollAnchorTest, ExcludeOffsettedAbsolutePosition)
|
| -{
|
| - setBodyInnerHTML(
|
| - "<style>"
|
| - " body { margin: 0; }"
|
| - " #scroller { overflow: scroll; width: 500px; height: 400px; position:relative; }"
|
| - " #space { height: 1000px; }"
|
| - " #abs {"
|
| - " position: absolute; background-color: red;"
|
| - " width: 100px; height: 100px;"
|
| - " }"
|
| - " #rel {"
|
| - " position: relative; background-color: green;"
|
| - " left: 50px; top: 100px; width: 100px; height: 75px;"
|
| - " }"
|
| - " .top { top: 10px }"
|
| - " .left { left: 10px }"
|
| - " .right { right: 10px }"
|
| - " .bottom { bottom: 10px }"
|
| - "</style>"
|
| - "<div id='scroller'><div id='space'>"
|
| - " <div id='abs'></div>"
|
| - " <div id='rel'></div>"
|
| - "</div></div>");
|
| -
|
| - Element* scrollerElement = document().getElementById("scroller");
|
| - ScrollableArea* scroller = scrollerForElement(scrollerElement);
|
| - Element* relPos = document().getElementById("rel");
|
| - Element* absPos = document().getElementById("abs");
|
| -
|
| - scroller->scrollBy(DoubleSize(0, 25), UserScroll);
|
| - setHeight(relPos, 100);
|
| - // Pick absolute anchor.
|
| - EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject());
|
| -
|
| - absPos->setAttribute(HTMLNames::classAttr, "top");
|
| - scroller->scrollBy(DoubleSize(0, 25), UserScroll);
|
| - setHeight(relPos, 125);
|
| - // Don't pick absolute anchor since top is set.
|
| - EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
|
| -
|
| - absPos->removeAttribute(HTMLNames::classAttr);
|
| - absPos->setAttribute(HTMLNames::classAttr, "right");
|
| - scroller->scrollBy(DoubleSize(0, 25), UserScroll);
|
| - setHeight(relPos, 150);
|
| - // Don't pick absolute anchor since right is set.
|
| - EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
|
| -
|
| - absPos->removeAttribute(HTMLNames::classAttr);
|
| - absPos->setAttribute(HTMLNames::classAttr, "bottom");
|
| - scroller->scrollBy(DoubleSize(0, 25), UserScroll);
|
| - setHeight(relPos, 175);
|
| - // Don't pick absolute anchor since bottom is set.
|
| - EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
|
| -
|
| - absPos->removeAttribute(HTMLNames::classAttr);
|
| - absPos->setAttribute(HTMLNames::classAttr, "left");
|
| - scroller->scrollBy(DoubleSize(0, 25), UserScroll);
|
| - setHeight(relPos, 200);
|
| - // Don't pick absolute anchor since left is set.
|
| - EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
|
| -}
|
| -
|
| // Test that we descend into zero-height containers that have overflowing content.
|
| TEST_F(ScrollAnchorTest, DescendsIntoContainerWithOverflow)
|
| {
|
| @@ -547,14 +487,15 @@ TEST_F(ScrollAnchorTest, DescendsIntoContainerWithFloat)
|
| " <div id='inner'></div>"
|
| " </div>"
|
| " </div>"
|
| - "</div>");
|
| + "</div>"
|
| + "<div id=a>after</div>");
|
|
|
| EXPECT_EQ(0, toLayoutBox(document().getElementById("zeroheight")->layoutObject())->size().height());
|
|
|
| ScrollableArea* viewport = layoutViewport();
|
|
|
| scrollLayoutViewport(DoubleSize(0, 200));
|
| - setHeight(document().getElementById("float"), 600);
|
| + setHeight(document().getElementById("a"), 100);
|
|
|
| EXPECT_EQ(200, viewport->scrollPosition().y());
|
| EXPECT_EQ(document().getElementById("float")->layoutObject(),
|
| @@ -634,6 +575,66 @@ TEST_F(ScrollAnchorTest, OptOutElement)
|
| scrollAnchor(viewport).anchorObject());
|
| }
|
|
|
| +TEST_F(ScrollAnchorTest, SuppressAnchorNodeAncestorChangingLayoutAffectingProperty)
|
| +{
|
| + setBodyInnerHTML(
|
| + "<style> body { height: 1000px } div { height: 100px } </style>"
|
| + "<div id='block1'>abc</div>");
|
| +
|
| + ScrollableArea* viewport = layoutViewport();
|
| +
|
| + scrollLayoutViewport(DoubleSize(0, 50));
|
| + document().body()->setAttribute(HTMLNames::styleAttr, "padding-top: 20px");
|
| + update();
|
| +
|
| + EXPECT_EQ(50, viewport->scrollPosition().y());
|
| + EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject());
|
| +}
|
| +
|
| +TEST_F(ScrollAnchorTest, AnchorNodeAncestorChangingNonLayoutAffectingProperty)
|
| +{
|
| + setBodyInnerHTML(
|
| + "<style> body { height: 1000px } div { height: 100px } </style>"
|
| + "<div id='block1'>abc</div>"
|
| + "<div id='block2'>def</div>");
|
| +
|
| + ScrollableArea* viewport = layoutViewport();
|
| + scrollLayoutViewport(DoubleSize(0, 150));
|
| +
|
| + document().body()->setAttribute(HTMLNames::styleAttr, "color: red");
|
| + setHeight(document().getElementById("block1"), 200);
|
| +
|
| + EXPECT_EQ(250, viewport->scrollPosition().y());
|
| + EXPECT_EQ(document().getElementById("block2")->layoutObject(),
|
| + scrollAnchor(viewport).anchorObject());
|
| +}
|
| +
|
| +TEST_F(ScrollAnchorTest, TransformIsLayoutAffecting)
|
| +{
|
| + setBodyInnerHTML(
|
| + "<style>"
|
| + " body { height: 1000px }"
|
| + " #block1 { height: 100px }"
|
| + "</style>"
|
| + "<div id='block1'>abc</div>"
|
| + "<div id=a>after</div>");
|
| +
|
| + ScrollableArea* viewport = layoutViewport();
|
| +
|
| + scrollLayoutViewport(DoubleSize(0, 50));
|
| + document().getElementById("block1")->setAttribute(
|
| + HTMLNames::styleAttr, "transform: matrix(1, 0, 0, 1, 25, 25);");
|
| + update();
|
| +
|
| + document().getElementById("block1")->setAttribute(
|
| + HTMLNames::styleAttr, "transform: matrix(1, 0, 0, 1, 50, 50);");
|
| + setHeight(document().getElementById("a"), 100);
|
| + update();
|
| +
|
| + EXPECT_EQ(50, viewport->scrollPosition().y());
|
| + EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject());
|
| +}
|
| +
|
| TEST_F(ScrollAnchorTest, OptOutBody)
|
| {
|
| setBodyInnerHTML(
|
|
|