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

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

Issue 1875943004: [DNS] Don't adjust the scroll position if the anchor element changes in size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/ScrollAnchor.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 194ae5e604e12b76cd094bed82b273253e8e7973..300be36e9f4c51d1f250a77ea0fe72a5a1df4c1f 100644
--- a/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
+++ b/third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp
@@ -246,26 +246,49 @@ TEST_F(ScrollAnchorTest, ExcludeAbsolutePosition)
EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject());
}
+// See crbug.com/600891 for context as to why we don't adjust the scroll offset
+// if the anchor node changes.
+TEST_F(ScrollAnchorTest, NoAdjustmentIfAnchorChanged)
+{
+ setBodyInnerHTML(
+ "<style>"
+ " body { height: 2000px; }"
+ " #beforeAnchor {"
+ " height: 300px; background-color: #fcc;"
+ " }"
+ " #anchor {"
+ " background-color: #afa; height: 200px; border: 1px solid gray;"
+ " }"
+ "</style>"
+ "<div id=beforeAnchor></div>"
+ "<div id=anchor></div>");
+
+ // Bring div that will be anchored into view and change it's height.
+ scrollLayoutViewport(DoubleSize(0, 350));
+ setHeight(document().getElementById("anchor"), 300);
+ // No adjustment should be made.
+ EXPECT_EQ(DoublePoint(0, 350), layoutViewport()->scrollPositionDouble());
+}
+
class ScrollAnchorCornerTest : public ScrollAnchorTest {
protected:
- void checkCorner(const AtomicString& id, Corner corner, DoublePoint startPos, DoubleSize expectedAdjustment)
+ void checkCorner(const AtomicString& expectedAnchorId, Corner corner, DoublePoint startPos, DoubleSize expectedAdjustment)
{
ScrollableArea* viewport = layoutViewport();
- Element* element = document().getElementById(id);
-
+ Element* changingElement = document().getElementById("changer");
viewport->setScrollPosition(startPos, UserScroll);
- element->setAttribute(HTMLNames::classAttr, "big");
- update();
+
+ setHeight(changingElement, 200);
DoublePoint endPos = startPos;
endPos.move(expectedAdjustment);
EXPECT_EQ(endPos, viewport->scrollPositionDouble());
- EXPECT_EQ(element->layoutObject(), scrollAnchor(viewport).anchorObject());
+ EXPECT_EQ(document().getElementById(expectedAnchorId)->layoutObject(),
+ scrollAnchor(viewport).anchorObject());
EXPECT_EQ(corner, scrollAnchor(viewport).corner());
- element->removeAttribute(HTMLNames::classAttr);
- update();
+ setHeight(changingElement, 0);
}
};
@@ -273,8 +296,8 @@ TEST_F(ScrollAnchorCornerTest, Corners)
{
setBodyInnerHTML(
"<style>"
- " body {"
- " position: absolute; border: 10px solid #ccc;"
+ " #container {"
+ " position: relative; border: 1px solid black;"
" width: 1220px; height: 920px;"
" }"
" #a, #b, #c, #d {"
@@ -285,17 +308,19 @@ TEST_F(ScrollAnchorCornerTest, Corners)
" #a, #c { left: 0; }"
" #b, #d { right: 0; }"
" #c, #d { bottom: 0; }"
- " .big { width: 800px !important; height: 600px !important }"
"</style>"
- "<div id=a></div>"
- "<div id=b></div>"
- "<div id=c></div>"
- "<div id=d></div>");
-
- checkCorner("a", Corner::BottomRight, DoublePoint(20, 20), DoubleSize(+400, +300));
- checkCorner("b", Corner::BottomLeft, DoublePoint(420, 20), DoubleSize(-400, +300));
- checkCorner("c", Corner::TopRight, DoublePoint(20, 320), DoubleSize(+400, -300));
- checkCorner("d", Corner::TopLeft, DoublePoint(420, 320), DoubleSize(-400, -300));
+ "<div id=changer></div>"
+ "<div id=container>"
+ " <div id=a></div>"
+ " <div id=b></div>"
+ " <div id=c></div>"
+ " <div id=d></div>"
+ "</div>");
+
+ checkCorner("a", Corner::BottomRight, DoublePoint(20, 20), DoubleSize(0, 200));
+ checkCorner("b", Corner::BottomLeft, DoublePoint(420, 20), DoubleSize(0, 200));
+ checkCorner("c", Corner::TopRight, DoublePoint(20, 320), DoubleSize(0, 200));
+ checkCorner("d", Corner::TopLeft, DoublePoint(420, 320), DoubleSize(0, 200));
}
}
« no previous file with comments | « third_party/WebKit/Source/core/layout/ScrollAnchor.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698