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

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

Issue 2433873003: Fix crash when calling ScrollAnchor::clear from PaintLayer's destructor (Closed)
Patch Set: Created 4 years, 2 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 EXPECT_EQ(250, scroller->scrollOffsetInt().height()); 311 EXPECT_EQ(250, scroller->scrollOffsetInt().height());
312 EXPECT_EQ(block2->layoutObject(), scrollAnchor(scroller).anchorObject()); 312 EXPECT_EQ(block2->layoutObject(), scrollAnchor(scroller).anchorObject());
313 313
314 // Test that the anchor object can be destroyed without affecting the scroll 314 // Test that the anchor object can be destroyed without affecting the scroll
315 // position. 315 // position.
316 block2->remove(); 316 block2->remove();
317 update(); 317 update();
318 EXPECT_EQ(250, scroller->scrollOffsetInt().height()); 318 EXPECT_EQ(250, scroller->scrollOffsetInt().height());
319 } 319 }
320 320
321 // Verify that a nested scroller with a div that has its own PaintLayer can be
322 // removed without causing a crash. This test passes if it doesn't crash.
323 TEST_F(ScrollAnchorTest, RemoveScrollerWithLayerInScrollingDiv) {
324 setBodyInnerHTML(
325 "<style>"
326 " body { height: 2000px }"
327 " #scroller { overflow: scroll; width: 500px; height: 400px}"
328 " #block1 { height: 100px; width: 100px; overflow: hidden}"
329 " #anchor { height: 1000px; }"
330 "</style>"
331 "<div id='changer1'></div>"
332 "<div id='scroller'>"
333 " <div id='changer2'></div>"
334 " <div id='block1'></div>"
335 " <div id='anchor'></div>"
336 "</div>");
337
338 ScrollableArea* viewport = layoutViewport();
339 ScrollableArea* scroller =
340 scrollerForElement(document().getElementById("scroller"));
341 Element* changer1 = document().getElementById("changer1");
342 Element* changer2 = document().getElementById("changer2");
343 Element* anchor = document().getElementById("anchor");
344
345 scroller->scrollBy(ScrollOffset(0, 150), UserScroll);
346 scrollLayoutViewport(ScrollOffset(0, 50));
347
348 // In this layout pass both the inner and outer scroller will anchor to
349 // #anchor.
350 setHeight(changer1, 100);
351 setHeight(changer2, 100);
352 EXPECT_EQ(250, scroller->scrollOffsetInt().height());
353 EXPECT_EQ(anchor->layoutObject(), scrollAnchor(scroller).anchorObject());
354 EXPECT_EQ(anchor->layoutObject(), scrollAnchor(viewport).anchorObject());
355
356 // Test that the inner scroller can be destroyed without crashing.
357 document().getElementById("scroller")->remove();
358 update();
359 }
360
321 TEST_F(ScrollAnchorTest, ExcludeAnonymousCandidates) { 361 TEST_F(ScrollAnchorTest, ExcludeAnonymousCandidates) {
322 setBodyInnerHTML( 362 setBodyInnerHTML(
323 "<style>" 363 "<style>"
324 " body { height: 3500px }" 364 " body { height: 3500px }"
325 " #div {" 365 " #div {"
326 " position: relative; background-color: pink;" 366 " position: relative; background-color: pink;"
327 " top: 5px; left: 5px; width: 100px; height: 3500px;" 367 " top: 5px; left: 5px; width: 100px; height: 3500px;"
328 " }" 368 " }"
329 " #inline { padding-left: 10px }" 369 " #inline { padding-left: 10px }"
330 "</style>" 370 "</style>"
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 1066
1027 scrollLayoutViewport(ScrollOffset(-50, 0)); 1067 scrollLayoutViewport(ScrollOffset(-50, 0));
1028 1068
1029 a->setAttribute(HTMLNames::styleAttr, "width: 200px"); 1069 a->setAttribute(HTMLNames::styleAttr, "width: 200px");
1030 b->setAttribute(HTMLNames::styleAttr, "height: 150px"); 1070 b->setAttribute(HTMLNames::styleAttr, "height: 150px");
1031 update(); 1071 update();
1032 EXPECT_EQ(ScrollOffset(-100, 150), viewport->scrollOffset()); 1072 EXPECT_EQ(ScrollOffset(-100, 150), viewport->scrollOffset());
1033 EXPECT_EQ(c->layoutObject(), scrollAnchor(viewport).anchorObject()); 1073 EXPECT_EQ(c->layoutObject(), scrollAnchor(viewport).anchorObject());
1034 } 1074 }
1035 } 1075 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698