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

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

Issue 2152773002: Make scroll anchoring adjustment when the bounds of a scroller is changed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix failing 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 unified diff | Download patch
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/dom/ClientRect.h" 7 #include "core/dom/ClientRect.h"
8 #include "core/frame/VisualViewport.h" 8 #include "core/frame/VisualViewport.h"
9 #include "core/layout/LayoutBox.h" 9 #include "core/layout/LayoutBox.h"
10 #include "core/layout/LayoutTestHelper.h" 10 #include "core/layout/LayoutTestHelper.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 setHeight(document().getElementById("outerChanger"), 150); 187 setHeight(document().getElementById("outerChanger"), 150);
188 188
189 EXPECT_EQ(300, scroller->scrollPosition().y()); 189 EXPECT_EQ(300, scroller->scrollPosition().y());
190 EXPECT_EQ(document().getElementById("innerAnchor")->layoutObject(), 190 EXPECT_EQ(document().getElementById("innerAnchor")->layoutObject(),
191 scrollAnchor(scroller).anchorObject()); 191 scrollAnchor(scroller).anchorObject());
192 EXPECT_EQ(500, viewport->scrollPosition().y()); 192 EXPECT_EQ(500, viewport->scrollPosition().y());
193 EXPECT_EQ(document().getElementById("outerAnchor")->layoutObject(), 193 EXPECT_EQ(document().getElementById("outerAnchor")->layoutObject(),
194 scrollAnchor(viewport).anchorObject()); 194 scrollAnchor(viewport).anchorObject());
195 } 195 }
196 196
197 // Test that scroll anchoring causes no visible jump when a layout change
198 // (such as removal of a DOM element) changes the scroll bounds.
199 TEST_F(ScrollAnchorTest, AnchoringWhenContentRemoved)
200 {
201 setBodyInnerHTML(
202 "<style>"
203 " #changer { height: 1500px; }"
204 " #anchor {"
205 " width: 150px; height: 1000px; background-color: pink;"
206 " }"
207 "</style>"
208 "<div id='changer'></div>"
209 "<div id='anchor'></div>");
210
211 ScrollableArea* viewport = layoutViewport();
212 scrollLayoutViewport(DoubleSize(0, 1600));
213
214 setHeight(document().getElementById("changer"), 0);
215
216 EXPECT_EQ(100, viewport->scrollPosition().y());
217 EXPECT_EQ(document().getElementById("anchor")->layoutObject(),
218 scrollAnchor(viewport).anchorObject());
219 }
220
221 // Test that scroll anchoring causes no visible jump when a layout change
222 // (such as removal of a DOM element) changes the scroll bounds of a scrolling
223 // div.
224 TEST_F(ScrollAnchorTest, AnchoringWhenContentRemovedFromScrollingDiv)
225 {
226 setBodyInnerHTML(
227 "<style>"
228 " #scroller { height: 500px; width: 200px; overflow: scroll; }"
229 " #changer { height: 1500px; }"
230 " #anchor {"
231 " width: 150px; height: 1000px; overflow: scroll;"
232 " }"
233 "</style>"
234 "<div id='scroller'>"
235 " <div id='changer'></div>"
236 " <div id='anchor'></div>"
237 "</div>");
238
239 ScrollableArea* scroller = scrollerForElement(document().getElementById("scr oller"));
240
241 document().getElementById("scroller")->setScrollTop(1600);
242
243 setHeight(document().getElementById("changer"), 0);
244
245 EXPECT_EQ(100, scroller->scrollPosition().y());
246 EXPECT_EQ(document().getElementById("anchor")->layoutObject(),
247 scrollAnchor(scroller).anchorObject());
248 }
249
197 TEST_F(ScrollAnchorTest, FractionalOffsetsAreRoundedBeforeComparing) 250 TEST_F(ScrollAnchorTest, FractionalOffsetsAreRoundedBeforeComparing)
198 { 251 {
199 setBodyInnerHTML( 252 setBodyInnerHTML(
200 "<style> body { height: 1000px } </style>" 253 "<style> body { height: 1000px } </style>"
201 "<div id='block1' style='height: 50.4px'>abc</div>" 254 "<div id='block1' style='height: 50.4px'>abc</div>"
202 "<div id='block2' style='height: 100px'>def</div>"); 255 "<div id='block2' style='height: 100px'>def</div>");
203 256
204 ScrollableArea* viewport = layoutViewport(); 257 ScrollableArea* viewport = layoutViewport();
205 scrollLayoutViewport(DoubleSize(0, 100)); 258 scrollLayoutViewport(DoubleSize(0, 100));
206 259
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 "<div id=c></div>" 782 "<div id=c></div>"
730 "<div id=d></div>"); 783 "<div id=d></div>");
731 784
732 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0)) ; 785 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0)) ;
733 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0 )); 786 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0 ));
734 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30 0)); 787 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30 0));
735 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, - 300)); 788 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, - 300));
736 } 789 }
737 790
738 } 791 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.cpp ('k') | third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698