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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/ScrollAnchor.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/ScrollAnchor.h" 5 #include "core/layout/ScrollAnchor.h"
6 6
7 #include "core/layout/LayoutBox.h" 7 #include "core/layout/LayoutBox.h"
8 #include "core/layout/LayoutTestHelper.h" 8 #include "core/layout/LayoutTestHelper.h"
9 #include "core/paint/PaintLayerScrollableArea.h" 9 #include "core/paint/PaintLayerScrollableArea.h"
10 #include "platform/testing/HistogramTester.h" 10 #include "platform/testing/HistogramTester.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); 239 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
240 240
241 scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative"); 241 scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative");
242 scroller->scrollBy(DoubleSize(0, 25), UserScroll); 242 scroller->scrollBy(DoubleSize(0, 25), UserScroll);
243 setHeight(relPos, 125); 243 setHeight(relPos, 125);
244 244
245 // When the scroller is position:relative, the anchor may be position:absolu te. 245 // When the scroller is position:relative, the anchor may be position:absolu te.
246 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject()); 246 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject());
247 } 247 }
248 248
249 // See crbug.com/600891 for context as to why we don't adjust the scroll offset
250 // if the anchor node changes.
251 TEST_F(ScrollAnchorTest, NoAdjustmentIfAnchorChanged)
252 {
253 setBodyInnerHTML(
254 "<style>"
255 " body { height: 2000px; }"
256 " #beforeAnchor {"
257 " height: 300px; background-color: #fcc;"
258 " }"
259 " #anchor {"
260 " background-color: #afa; height: 200px; border: 1px solid gray;"
261 " }"
262 "</style>"
263 "<div id=beforeAnchor></div>"
264 "<div id=anchor></div>");
265
266 // Bring div that will be anchored into view and change it's height.
267 scrollLayoutViewport(DoubleSize(0, 350));
268 setHeight(document().getElementById("anchor"), 300);
269 // No adjustment should be made.
270 EXPECT_EQ(DoublePoint(0, 350), layoutViewport()->scrollPositionDouble());
271 }
272
249 class ScrollAnchorCornerTest : public ScrollAnchorTest { 273 class ScrollAnchorCornerTest : public ScrollAnchorTest {
250 protected: 274 protected:
251 void checkCorner(const AtomicString& id, Corner corner, DoublePoint startPos , DoubleSize expectedAdjustment) 275 void checkCorner(const AtomicString& expectedAnchorId, Corner corner, Double Point startPos, DoubleSize expectedAdjustment)
252 { 276 {
253 ScrollableArea* viewport = layoutViewport(); 277 ScrollableArea* viewport = layoutViewport();
254 Element* element = document().getElementById(id); 278 Element* changingElement = document().getElementById("changer");
279 viewport->setScrollPosition(startPos, UserScroll);
255 280
256 viewport->setScrollPosition(startPos, UserScroll); 281 setHeight(changingElement, 200);
257 element->setAttribute(HTMLNames::classAttr, "big");
258 update();
259 282
260 DoublePoint endPos = startPos; 283 DoublePoint endPos = startPos;
261 endPos.move(expectedAdjustment); 284 endPos.move(expectedAdjustment);
262 285
263 EXPECT_EQ(endPos, viewport->scrollPositionDouble()); 286 EXPECT_EQ(endPos, viewport->scrollPositionDouble());
264 EXPECT_EQ(element->layoutObject(), scrollAnchor(viewport).anchorObject() ); 287 EXPECT_EQ(document().getElementById(expectedAnchorId)->layoutObject(),
288 scrollAnchor(viewport).anchorObject());
265 EXPECT_EQ(corner, scrollAnchor(viewport).corner()); 289 EXPECT_EQ(corner, scrollAnchor(viewport).corner());
266 290
267 element->removeAttribute(HTMLNames::classAttr); 291 setHeight(changingElement, 0);
268 update();
269 } 292 }
270 }; 293 };
271 294
272 TEST_F(ScrollAnchorCornerTest, Corners) 295 TEST_F(ScrollAnchorCornerTest, Corners)
273 { 296 {
274 setBodyInnerHTML( 297 setBodyInnerHTML(
275 "<style>" 298 "<style>"
276 " body {" 299 " #container {"
277 " position: absolute; border: 10px solid #ccc;" 300 " position: relative; border: 1px solid black;"
278 " width: 1220px; height: 920px;" 301 " width: 1220px; height: 920px;"
279 " }" 302 " }"
280 " #a, #b, #c, #d {" 303 " #a, #b, #c, #d {"
281 " position: absolute; background-color: #ace;" 304 " position: absolute; background-color: #ace;"
282 " width: 400px; height: 300px;" 305 " width: 400px; height: 300px;"
283 " }" 306 " }"
284 " #a, #b { top: 0; }" 307 " #a, #b { top: 0; }"
285 " #a, #c { left: 0; }" 308 " #a, #c { left: 0; }"
286 " #b, #d { right: 0; }" 309 " #b, #d { right: 0; }"
287 " #c, #d { bottom: 0; }" 310 " #c, #d { bottom: 0; }"
288 " .big { width: 800px !important; height: 600px !important }"
289 "</style>" 311 "</style>"
290 "<div id=a></div>" 312 "<div id=changer></div>"
291 "<div id=b></div>" 313 "<div id=container>"
292 "<div id=c></div>" 314 " <div id=a></div>"
293 "<div id=d></div>"); 315 " <div id=b></div>"
316 " <div id=c></div>"
317 " <div id=d></div>"
318 "</div>");
294 319
295 checkCorner("a", Corner::BottomRight, DoublePoint(20, 20), DoubleSize(+400 , +300)); 320 checkCorner("a", Corner::BottomRight, DoublePoint(20, 20), DoubleSize(0, 2 00));
296 checkCorner("b", Corner::BottomLeft, DoublePoint(420, 20), DoubleSize(-400 , +300)); 321 checkCorner("b", Corner::BottomLeft, DoublePoint(420, 20), DoubleSize(0, 2 00));
297 checkCorner("c", Corner::TopRight, DoublePoint(20, 320), DoubleSize(+400 , -300)); 322 checkCorner("c", Corner::TopRight, DoublePoint(20, 320), DoubleSize(0, 2 00));
298 checkCorner("d", Corner::TopLeft, DoublePoint(420, 320), DoubleSize(-400 , -300)); 323 checkCorner("d", Corner::TopLeft, DoublePoint(420, 320), DoubleSize(0, 2 00));
299 } 324 }
300 325
301 } 326 }
OLDNEW
« 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