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

Side by Side Diff: third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp

Issue 2002623003: Exclude position:absolute elements when picking an anchor for ScrollAnchoring (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit + rebase Created 4 years, 6 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 "<div id=f>fixed</div>" 249 "<div id=f>fixed</div>"
250 "<div id=c>content</div>"); 250 "<div id=c>content</div>");
251 251
252 scrollLayoutViewport(DoubleSize(0, 50)); 252 scrollLayoutViewport(DoubleSize(0, 50));
253 253
254 setHeight(document().body(), 1100); 254 setHeight(document().body(), 1100);
255 EXPECT_EQ(document().getElementById("c")->layoutObject(), 255 EXPECT_EQ(document().getElementById("c")->layoutObject(),
256 scrollAnchor(layoutViewport()).anchorObject()); 256 scrollAnchor(layoutViewport()).anchorObject());
257 } 257 }
258 258
259 TEST_F(ScrollAnchorTest, ExcludeAbsolutePosition) 259 // This test verifies that position:absolute elements that stick to the viewport
260 // are not selected as anchors.
261 TEST_F(ScrollAnchorTest, ExcludeAbsolutePositionThatSticksToViewport)
260 { 262 {
261 setBodyInnerHTML( 263 setBodyInnerHTML(
262 "<style>" 264 "<style>"
263 " body { margin: 0; }" 265 " body { margin: 0; }"
264 " #scroller { overflow: scroll; width: 500px; height: 400px; }" 266 " #scroller { overflow: scroll; width: 500px; height: 400px; }"
265 " #space { height: 1000px; }" 267 " #space { height: 1000px; }"
266 " #abs {" 268 " #abs {"
267 " position: absolute; background-color: red;" 269 " position: absolute; background-color: red;"
268 " left: 200px; top: 100px; width: 100px; height: 100px;" 270 " width: 100px; height: 100px;"
269 " }" 271 " }"
270 " #rel {" 272 " #rel {"
271 " position: relative; background-color: green;" 273 " position: relative; background-color: green;"
272 " left: 50px; top: 100px; width: 100px; height: 75px;" 274 " left: 50px; top: 100px; width: 100px; height: 75px;"
273 " }" 275 " }"
274 "</style>" 276 "</style>"
275 "<div id='scroller'><div id='space'>" 277 "<div id='scroller'><div id='space'>"
276 " <div id='abs'></div>" 278 " <div id='abs'></div>"
277 " <div id='rel'></div>" 279 " <div id='rel'></div>"
278 "</div></div>"); 280 "</div></div>");
(...skipping 10 matching lines...) Expand all
289 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject()); 291 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
290 292
291 scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative"); 293 scrollerElement->setAttribute(HTMLNames::styleAttr, "position: relative");
292 scroller->scrollBy(DoubleSize(0, 25), UserScroll); 294 scroller->scrollBy(DoubleSize(0, 25), UserScroll);
293 setHeight(relPos, 125); 295 setHeight(relPos, 125);
294 296
295 // When the scroller is position:relative, the anchor may be position:absolu te. 297 // When the scroller is position:relative, the anchor may be position:absolu te.
296 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject()); 298 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject());
297 } 299 }
298 300
301 // This test verifies that position:absolute elements with top/right/bottom/left
302 // set are not selected as anchors.
303 TEST_F(ScrollAnchorTest, ExcludeOffsettedAbsolutePosition)
304 {
305 setBodyInnerHTML(
306 "<style>"
307 " body { margin: 0; }"
308 " #scroller { overflow: scroll; width: 500px; height: 400px; position :relative; }"
309 " #space { height: 1000px; }"
310 " #abs {"
311 " position: absolute; background-color: red;"
312 " width: 100px; height: 100px;"
313 " }"
314 " #rel {"
315 " position: relative; background-color: green;"
316 " left: 50px; top: 100px; width: 100px; height: 75px;"
317 " }"
318 " .top { top: 10px }"
319 " .left { left: 10px }"
320 " .right { right: 10px }"
321 " .bottom { bottom: 10px }"
322 "</style>"
323 "<div id='scroller'><div id='space'>"
324 " <div id='abs'></div>"
325 " <div id='rel'></div>"
326 "</div></div>");
327
328 Element* scrollerElement = document().getElementById("scroller");
329 ScrollableArea* scroller = scrollerForElement(scrollerElement);
330 Element* relPos = document().getElementById("rel");
331 Element* absPos = document().getElementById("abs");
332
333 scroller->scrollBy(DoubleSize(0, 25), UserScroll);
334 setHeight(relPos, 100);
335 // Pick absolute anchor.
336 EXPECT_EQ(absPos->layoutObject(), scrollAnchor(scroller).anchorObject());
337
338 absPos->setAttribute(HTMLNames::classAttr, "top");
339 scroller->scrollBy(DoubleSize(0, 25), UserScroll);
340 setHeight(relPos, 125);
341 // Don't pick absolute anchor since top is set.
342 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
343
344 absPos->removeAttribute(HTMLNames::classAttr);
345 absPos->setAttribute(HTMLNames::classAttr, "right");
346 scroller->scrollBy(DoubleSize(0, 25), UserScroll);
347 setHeight(relPos, 150);
348 // Don't pick absolute anchor since right is set.
349 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
350
351 absPos->removeAttribute(HTMLNames::classAttr);
352 absPos->setAttribute(HTMLNames::classAttr, "bottom");
353 scroller->scrollBy(DoubleSize(0, 25), UserScroll);
354 setHeight(relPos, 175);
355 // Don't pick absolute anchor since bottom is set.
356 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
357
358 absPos->removeAttribute(HTMLNames::classAttr);
359 absPos->setAttribute(HTMLNames::classAttr, "left");
360 scroller->scrollBy(DoubleSize(0, 25), UserScroll);
361 setHeight(relPos, 200);
362 // Don't pick absolute anchor since left is set.
363 EXPECT_EQ(relPos->layoutObject(), scrollAnchor(scroller).anchorObject());
364 }
365
299 // Test that we descend into zero-height containers that have overflowing conten t. 366 // Test that we descend into zero-height containers that have overflowing conten t.
300 TEST_F(ScrollAnchorTest, DescendsIntoContainerWithOverflow) 367 TEST_F(ScrollAnchorTest, DescendsIntoContainerWithOverflow)
301 { 368 {
302 setBodyInnerHTML( 369 setBodyInnerHTML(
303 "<style>" 370 "<style>"
304 " body { height: 1000; }" 371 " body { height: 1000; }"
305 " #outer { width: 300px; }" 372 " #outer { width: 300px; }"
306 " #zeroheight { height: 0px; }" 373 " #zeroheight { height: 0px; }"
307 " #changer { height: 100px; background-color: red; }" 374 " #changer { height: 100px; background-color: red; }"
308 " #bottom { margin-top: 600px; }" 375 " #bottom { margin-top: 600px; }"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 "<div id=c></div>" 567 "<div id=c></div>"
501 "<div id=d></div>"); 568 "<div id=d></div>");
502 569
503 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0)) ; 570 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0)) ;
504 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0 )); 571 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0 ));
505 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30 0)); 572 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30 0));
506 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, - 300)); 573 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, - 300));
507 } 574 }
508 575
509 } 576 }
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