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

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

Issue 2145823002: Implement the overflow-anchor CSS property as an opt-out for ScrollAnchoring (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Put opt-out behind RuntimeEnabledFeature and update tests Created 4 years, 5 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/ScrollAnchorTest.cpp
diff --git a/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp b/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
index 2fb1618e812e260690b26b83dba7947b51760d1b..452c3ef66ab9437fe6693854d07684c05b146e19 100644
--- a/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
+++ b/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
@@ -469,6 +469,85 @@ TEST_F(ScrollAnchorTest, DescendsIntoContainerWithFloat)
scrollAnchor(viewport).anchorObject());
}
+TEST_F(ScrollAnchorTest, OptOutBody)
+{
+ setBodyInnerHTML(
+ "<style>"
+ " body { height: 2000px; overflow-anchor: none; }"
+ " #scroller { overflow: scroll; width: 500px; height: 300px; }"
+ " .anchor {"
+ " position:relative; height: 100px; width: 150px;"
+ " background-color: #afa; border: 1px solid gray;"
+ " }"
+ " #forceScrolling { height: 500px; background-color: #fcc; }"
+ "</style>"
+ "<div id='outerChanger'></div>"
+ "<div id='outerAnchor' class='anchor'></div>"
+ "<div id='scroller'>"
+ " <div id='innerChanger'></div>"
+ " <div id='innerAnchor' class='anchor'></div>"
+ " <div id='forceScrolling'></div>"
+ "</div>");
+
+ ScrollableArea* scroller = scrollerForElement(document().getElementById("scroller"));
+ ScrollableArea* viewport = layoutViewport();
+
+ document().getElementById("scroller")->setScrollTop(100);
+ scrollLayoutViewport(DoubleSize(0, 100));
+
+ setHeight(document().getElementById("innerChanger"), 200);
+ setHeight(document().getElementById("outerChanger"), 150);
+
+ // Scroll anchoring should apply within #scroller.
+ EXPECT_EQ(300, scroller->scrollPosition().y());
+ EXPECT_EQ(document().getElementById("innerAnchor")->layoutObject(),
+ scrollAnchor(scroller).anchorObject());
+ // Scroll anchoring should not apply within main frame.
+ EXPECT_EQ(100, viewport->scrollPosition().y());
+ EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject());
+}
+
+TEST_F(ScrollAnchorTest, OptOutScrollingDiv)
+{
+ setBodyInnerHTML(
+ "<style>"
+ " body { height: 2000px; }"
+ " #scroller {"
+ " overflow: scroll; width: 500px; height: 300px;"
+ " overflow-anchor: none;"
+ " }"
+ " .anchor {"
+ " position:relative; height: 100px; width: 150px;"
+ " background-color: #afa; border: 1px solid gray;"
+ " }"
+ " #forceScrolling { height: 500px; background-color: #fcc; }"
+ "</style>"
+ "<div id='outerChanger'></div>"
+ "<div id='outerAnchor' class='anchor'></div>"
+ "<div id='scroller'>"
+ " <div id='innerChanger'></div>"
+ " <div id='innerAnchor' class='anchor'></div>"
+ " <div id='forceScrolling'></div>"
+ "</div>");
+
+ ScrollableArea* scroller = scrollerForElement(document().getElementById("scroller"));
+ ScrollableArea* viewport = layoutViewport();
+
+ document().getElementById("scroller")->setScrollTop(100);
+ scrollLayoutViewport(DoubleSize(0, 100));
+
+ setHeight(document().getElementById("innerChanger"), 200);
+ setHeight(document().getElementById("outerChanger"), 150);
+
+ // Scroll anchoring should not apply within #scroller.
+ EXPECT_EQ(100, scroller->scrollPosition().y());
+ EXPECT_EQ(nullptr, scrollAnchor(scroller).anchorObject());
+ // Scroll anchoring should apply within main frame.
+ EXPECT_EQ(250, viewport->scrollPosition().y());
+ EXPECT_EQ(document().getElementById("outerAnchor")->layoutObject(),
+ scrollAnchor(viewport).anchorObject());
+}
+
class ScrollAnchorCornerTest : public ScrollAnchorTest {
protected:
void checkCorner(const AtomicString& id, Corner corner, DoublePoint startPos, DoubleSize expectedAdjustment)

Powered by Google App Engine
This is Rietveld 408576698