| 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 214c5e57195ff36402510100de76d59a25a30f5c..33ddb634351724282f9ff075870de4b510b574e8 100644
|
| --- a/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
|
| +++ b/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
|
| @@ -17,7 +17,8 @@ using Corner = ScrollAnchor::Corner;
|
|
|
| class ScrollAnchorTest : public RenderingTest {
|
| public:
|
| - ScrollAnchorTest() {
|
| + explicit ScrollAnchorTest(FrameLoaderClient* frameLoaderClient = nullptr)
|
| + : RenderingTest(frameLoaderClient) {
|
| RuntimeEnabledFeatures::setScrollAnchoringEnabled(true);
|
| }
|
| ~ScrollAnchorTest() {
|
| @@ -64,6 +65,12 @@ class ScrollAnchorTest : public RenderingTest {
|
| }
|
| };
|
|
|
| +class ScrollAnchorFrameTest : public ScrollAnchorTest {
|
| + public:
|
| + ScrollAnchorFrameTest()
|
| + : ScrollAnchorTest(SingleChildFrameLoaderClient::create()) {}
|
| +};
|
| +
|
| // TODO(ymalik): Currently, this should be the first test in the file to avoid
|
| // failure when running with other tests. Dig into this more and fix.
|
| TEST_F(ScrollAnchorTest, UMAMetricUpdated) {
|
| @@ -240,6 +247,63 @@ TEST_F(ScrollAnchorTest, AnchoringWhenContentRemovedFromScrollingDiv) {
|
| scrollAnchor(scroller).anchorObject());
|
| }
|
|
|
| +// Test that a non-anchoring scroll on scroller clears scroll anchors for all
|
| +// parent scrollers.
|
| +TEST_F(ScrollAnchorTest, ClearScrollAnchorsOnAncestors) {
|
| + setBodyInnerHTML(
|
| + "<style>"
|
| + " body { height: 1000px } div { height: 200px }"
|
| + " #scroller { height: 100px; width: 200px; overflow: scroll; }"
|
| + "</style>"
|
| + "<div id='changer'>abc</div>"
|
| + "<div id='anchor'>def</div>"
|
| + "<div id='scroller'><div></div></div>");
|
| +
|
| + ScrollableArea* viewport = layoutViewport();
|
| +
|
| + scrollLayoutViewport(DoubleSize(0, 250));
|
| + setHeight(document().getElementById("changer"), 300);
|
| +
|
| + EXPECT_EQ(350, viewport->scrollPosition().y());
|
| + EXPECT_EQ(document().getElementById("anchor")->layoutObject(),
|
| + scrollAnchor(viewport).anchorObject());
|
| +
|
| + // Scrolling the nested scroller should clear the anchor on the main frame.
|
| + ScrollableArea* scroller =
|
| + scrollerForElement(document().getElementById("scroller"));
|
| + scroller->scrollBy(DoubleSize(0, 100), UserScroll);
|
| + EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject());
|
| +}
|
| +
|
| +TEST_F(ScrollAnchorFrameTest, ClearScrollAnchorsOnAncestorsOfIframe) {
|
| + document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
|
| + setBodyInnerHTML(
|
| + "<style>"
|
| + " body { height: 1000px } div { height: 200px }"
|
| + " #scroller { height: 100px; width: 200px; overflow: scroll; }"
|
| + "</style>"
|
| + "<div id='changer'>abc</div>"
|
| + "<div id='anchor'>def</div>"
|
| + "<iframe id='scroller' src='http://test.com'></iframe>");
|
| +
|
| + Document& frameDocument =
|
| + setupChildIframe("scroller", "<style> body { height: 1000px } </style>");
|
| +
|
| + ScrollableArea* viewport = layoutViewport();
|
| +
|
| + scrollLayoutViewport(DoubleSize(0, 250));
|
| + setHeight(document().getElementById("changer"), 300);
|
| +
|
| + EXPECT_EQ(350, viewport->scrollPosition().y());
|
| + EXPECT_EQ(document().getElementById("anchor")->layoutObject(),
|
| + scrollAnchor(viewport).anchorObject());
|
| +
|
| + // Scrolling the iframe should clear the anchor on the main frame.
|
| + frameDocument.view()->setScrollPosition(DoublePoint(0.0, 1000),
|
| + ProgrammaticScroll);
|
| + EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject());
|
| +}
|
| +
|
| TEST_F(ScrollAnchorTest, FractionalOffsetsAreRoundedBeforeComparing) {
|
| setBodyInnerHTML(
|
| "<style> body { height: 1000px } </style>"
|
|
|