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

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

Issue 2123053002: Improve scroll anchoring's interactions with the visual viewport (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix broken 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 3f2d730240abfeb1b8ddf97cccf688c4f0395ac9..2fb1618e812e260690b26b83dba7947b51760d1b 100644
--- a/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
+++ b/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
@@ -4,6 +4,8 @@
#include "core/layout/ScrollAnchor.h"
+#include "core/dom/ClientRect.h"
+#include "core/frame/VisualViewport.h"
#include "core/layout/LayoutBox.h"
#include "core/layout/LayoutTestHelper.h"
#include "core/paint/PaintLayerScrollableArea.h"
@@ -30,6 +32,11 @@ protected:
return document().view()->layoutViewportScrollableArea();
}
+ VisualViewport& visualViewport()
+ {
+ return document().view()->page()->frameHost().visualViewport();
+ }
+
ScrollableArea* scrollerForElement(Element* element)
{
return toLayoutBox(element->layoutObject())->getScrollableArea();
@@ -111,6 +118,43 @@ TEST_F(ScrollAnchorTest, Basic)
EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject());
}
+TEST_F(ScrollAnchorTest, VisualViewportAnchors)
+{
+ setBodyInnerHTML(
+ "<style>"
+ " * { font-size: 1.2em; font-family: sans-serif; }"
+ " div { height: 100px; width: 20px; background-color: pink; }"
+ "</style>"
+ "<div id='div'></div>"
+ "<div id='text'><b>This is a scroll anchoring test</div>");
+
+ ScrollableArea* lViewport = layoutViewport();
+ VisualViewport& vViewport = visualViewport();
+
+ vViewport.setScale(2.0);
+
+ // No anchor at origin (0,0).
+ EXPECT_EQ(nullptr, scrollAnchor(lViewport).anchorObject());
+
+ // Scroll the visual viewport to bring #text to the top.
+ int top = document().getElementById("text")->getBoundingClientRect()->top();
+ vViewport.setLocation(FloatPoint(0, top));
+
+ setHeight(document().getElementById("div"), 10);
+ EXPECT_EQ(document().getElementById("text")->layoutObject(),
+ scrollAnchor(lViewport).anchorObject());
+ EXPECT_EQ(top - 90, vViewport.scrollPosition().y());
+
+ setHeight(document().getElementById("div"), 100);
+ EXPECT_EQ(document().getElementById("text")->layoutObject(),
+ scrollAnchor(lViewport).anchorObject());
+ EXPECT_EQ(top, vViewport.scrollPosition().y());
+
+ // Scrolling the visual viewport should clear the anchor.
+ vViewport.setLocation(FloatPoint(0, 0));
+ EXPECT_EQ(nullptr, scrollAnchor(lViewport).anchorObject());
+}
+
TEST_F(ScrollAnchorTest, FractionalOffsetsAreRoundedBeforeComparing)
{
setBodyInnerHTML(

Powered by Google App Engine
This is Rietveld 408576698