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

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

Issue 2022853002: Fix scroll anchoring crash from removing an anonymous block anchor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: skip anonymous LayoutObjects 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 setHeight(block1, 200); 152 setHeight(block1, 200);
153 EXPECT_EQ(250, scroller->scrollPosition().y()); 153 EXPECT_EQ(250, scroller->scrollPosition().y());
154 EXPECT_EQ(block2->layoutObject(), scrollAnchor(scroller).anchorObject()); 154 EXPECT_EQ(block2->layoutObject(), scrollAnchor(scroller).anchorObject());
155 155
156 // Test that the anchor object can be destroyed without affecting the scroll position. 156 // Test that the anchor object can be destroyed without affecting the scroll position.
157 block2->remove(); 157 block2->remove();
158 update(); 158 update();
159 EXPECT_EQ(250, scroller->scrollPosition().y()); 159 EXPECT_EQ(250, scroller->scrollPosition().y());
160 } 160 }
161 161
162 TEST_F(ScrollAnchorTest, ExcludeAnonymousCandidates)
163 {
164 setBodyInnerHTML(
165 "<style>"
166 " body { height: 3500px }"
167 " #div {"
168 " position: relative; background-color: pink;"
169 " top: 5px; left: 5px; width: 100px; height: 3500px;"
170 " }"
171 " #inline { padding-left: 10px }"
172 "</style>"
173 "<div id='div'>"
174 " <a id='inline'>text</a>"
175 " <p id='block'>Some text</p>"
176 "</div>");
177
178 ScrollableArea* viewport = layoutViewport();
179 Element* inlineElem = document().getElementById("inline");
180 EXPECT_TRUE(inlineElem->layoutObject()->parent()->isAnonymous());
181
182 // Scroll #div into view, making anonymous block a viable candidate.
183 document().getElementById("div")->scrollIntoView();
184
185 // Trigger layout and verify that we don't anchor to the anonymous block.
186 document().getElementById("div")->setAttribute(HTMLNames::styleAttr,
187 AtomicString("top: 6px"));
188 update();
189 EXPECT_EQ(inlineElem->layoutObject()->slowFirstChild(),
190 scrollAnchor(viewport).anchorObject());
191 }
192
162 TEST_F(ScrollAnchorTest, FullyContainedInlineBlock) 193 TEST_F(ScrollAnchorTest, FullyContainedInlineBlock)
163 { 194 {
164 // Exercises every WalkStatus value: 195 // Exercises every WalkStatus value:
165 // html, body -> Constrain 196 // html, body -> Constrain
166 // #outer -> Continue 197 // #outer -> Continue
167 // #ib1, br -> Skip 198 // #ib1, br -> Skip
168 // #ib2 -> Return 199 // #ib2 -> Return
169 setBodyInnerHTML( 200 setBodyInnerHTML(
170 "<style>" 201 "<style>"
171 " body { height: 1000px }" 202 " body { height: 1000px }"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 235
205 setHeight(document().body(), 1100); 236 setHeight(document().body(), 1100);
206 EXPECT_EQ(document().getElementById("b")->layoutObject()->slowFirstChild(), 237 EXPECT_EQ(document().getElementById("b")->layoutObject()->slowFirstChild(),
207 scrollAnchor(layoutViewport()).anchorObject()); 238 scrollAnchor(layoutViewport()).anchorObject());
208 } 239 }
209 240
210 TEST_F(ScrollAnchorTest, ExcludeFixedPosition) 241 TEST_F(ScrollAnchorTest, ExcludeFixedPosition)
211 { 242 {
212 setBodyInnerHTML( 243 setBodyInnerHTML(
213 "<style>" 244 "<style>"
214 " body { height: 1000px; padding: 20px }" 245 " body { height: 1000px; padding: 20px; }"
215 " div { position: relative; top: 100px; }" 246 " div { position: relative; top: 100px; }"
216 " #f { position: fixed }" 247 " #f { position: fixed }"
217 "</style>" 248 "</style>"
218 "<div id=f>fixed</div>" 249 "<div id=f>fixed</div>"
219 "<div id=c>content</div>"); 250 "<div id=c>content</div>");
220 251
221 scrollLayoutViewport(DoubleSize(0, 50)); 252 scrollLayoutViewport(DoubleSize(0, 50));
222 253
223 setHeight(document().body(), 1100); 254 setHeight(document().body(), 1100);
224 EXPECT_EQ(document().getElementById("c")->layoutObject(), 255 EXPECT_EQ(document().getElementById("c")->layoutObject(),
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 "<div id=c></div>" 500 "<div id=c></div>"
470 "<div id=d></div>"); 501 "<div id=d></div>");
471 502
472 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0)) ; 503 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0)) ;
473 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0 )); 504 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0 ));
474 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30 0)); 505 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30 0));
475 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, - 300)); 506 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, - 300));
476 } 507 }
477 508
478 } 509 }
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