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

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

Issue 1961243002: Round anchor offsets to DIPs in ScrollAnchor::restore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweak and add comments Created 4 years, 7 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/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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 EXPECT_EQ(250, viewport->scrollPosition().y()); 78 EXPECT_EQ(250, viewport->scrollPosition().y());
79 EXPECT_EQ(document().getElementById("block2")->layoutObject(), 79 EXPECT_EQ(document().getElementById("block2")->layoutObject(),
80 scrollAnchor(viewport).anchorObject()); 80 scrollAnchor(viewport).anchorObject());
81 81
82 // ScrollableArea::userScroll should clear the anchor. 82 // ScrollableArea::userScroll should clear the anchor.
83 viewport->userScroll(ScrollByPrecisePixel, FloatSize(0, 100)); 83 viewport->userScroll(ScrollByPrecisePixel, FloatSize(0, 100));
84 EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject()); 84 EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject());
85 } 85 }
86 86
87 TEST_F(ScrollAnchorTest, FractionalOffsetsAreRoundedBeforeComparing)
88 {
89 setBodyInnerHTML(
90 "<style> body { height: 1000px } </style>"
91 "<div id='block1' style='height: 50.4px'>abc</div>"
92 "<div id='block2' style='height: 100px'>def</div>");
93
94 ScrollableArea* viewport = layoutViewport();
95 scrollLayoutViewport(DoubleSize(0, 100));
96
97 document().getElementById("block1")->setAttribute(
98 HTMLNames::styleAttr, "height: 50.6px");
99 update();
100
101 EXPECT_EQ(101, viewport->scrollPosition().y());
102 }
103
87 TEST_F(ScrollAnchorTest, UMAMetricUpdated) 104 TEST_F(ScrollAnchorTest, UMAMetricUpdated)
88 { 105 {
89 HistogramTester histogramTester; 106 HistogramTester histogramTester;
90 setBodyInnerHTML( 107 setBodyInnerHTML(
91 "<style> body { height: 1000px } div { height: 100px } </style>" 108 "<style> body { height: 1000px } div { height: 100px } </style>"
92 "<div id='block1'>abc</div>" 109 "<div id='block1'>abc</div>"
93 "<div id='block2'>def</div>"); 110 "<div id='block2'>def</div>");
94 111
95 ScrollableArea* viewport = layoutViewport(); 112 ScrollableArea* viewport = layoutViewport();
96 113
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 "<div id=c></div>" 309 "<div id=c></div>"
293 "<div id=d></div>"); 310 "<div id=d></div>");
294 311
295 checkCorner("a", Corner::BottomRight, DoublePoint(20, 20), DoubleSize(+400 , +300)); 312 checkCorner("a", Corner::BottomRight, DoublePoint(20, 20), DoubleSize(+400 , +300));
296 checkCorner("b", Corner::BottomLeft, DoublePoint(420, 20), DoubleSize(-400 , +300)); 313 checkCorner("b", Corner::BottomLeft, DoublePoint(420, 20), DoubleSize(-400 , +300));
297 checkCorner("c", Corner::TopRight, DoublePoint(20, 320), DoubleSize(+400 , -300)); 314 checkCorner("c", Corner::TopRight, DoublePoint(20, 320), DoubleSize(+400 , -300));
298 checkCorner("d", Corner::TopLeft, DoublePoint(420, 320), DoubleSize(-400 , -300)); 315 checkCorner("d", Corner::TopLeft, DoublePoint(420, 320), DoubleSize(-400 , -300));
299 } 316 }
300 317
301 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698