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

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

Issue 1977703002: Lightening fix for UMA metric test failure locally. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comment 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
« no previous file with comments | « no previous file | 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 void scrollLayoutViewport(DoubleSize delta) 53 void scrollLayoutViewport(DoubleSize delta)
54 { 54 {
55 Element* scrollingElement = document().scrollingElement(); 55 Element* scrollingElement = document().scrollingElement();
56 if (delta.width()) 56 if (delta.width())
57 scrollingElement->setScrollTop(scrollingElement->scrollLeft() + delt a.width()); 57 scrollingElement->setScrollTop(scrollingElement->scrollLeft() + delt a.width());
58 if (delta.height()) 58 if (delta.height())
59 scrollingElement->setScrollTop(scrollingElement->scrollTop() + delta .height()); 59 scrollingElement->setScrollTop(scrollingElement->scrollTop() + delta .height());
60 } 60 }
61 }; 61 };
62 62
63 // TODO(ymalik): Currently, this should be the first test in the file to avoid
64 // failure when running with other tests. Dig into this more and fix.
65 TEST_F(ScrollAnchorTest, UMAMetricUpdated)
66 {
67 HistogramTester histogramTester;
68 setBodyInnerHTML(
69 "<style> body { height: 1000px } div { height: 100px } </style>"
70 "<div id='block1'>abc</div>"
71 "<div id='block2'>def</div>");
72
73 ScrollableArea* viewport = layoutViewport();
74
75 // Scroll position not adjusted, metric not updated.
76 scrollLayoutViewport(DoubleSize(0, 150));
77 histogramTester.expectTotalCount(
78 "Layout.ScrollAnchor.AdjustedScrollOffset", 0);
79
80 // Height changed, verify metric updated once.
81 setHeight(document().getElementById("block1"), 200);
82 histogramTester.expectUniqueSample(
83 "Layout.ScrollAnchor.AdjustedScrollOffset", 1, 1);
84
85 EXPECT_EQ(250, viewport->scrollPosition().y());
86 EXPECT_EQ(document().getElementById("block2")->layoutObject(),
87 scrollAnchor(viewport).anchorObject());
88 }
89
63 TEST_F(ScrollAnchorTest, Basic) 90 TEST_F(ScrollAnchorTest, Basic)
64 { 91 {
65 setBodyInnerHTML( 92 setBodyInnerHTML(
66 "<style> body { height: 1000px } div { height: 100px } </style>" 93 "<style> body { height: 1000px } div { height: 100px } </style>"
67 "<div id='block1'>abc</div>" 94 "<div id='block1'>abc</div>"
68 "<div id='block2'>def</div>"); 95 "<div id='block2'>def</div>");
69 96
70 ScrollableArea* viewport = layoutViewport(); 97 ScrollableArea* viewport = layoutViewport();
71 98
72 // No anchor at origin (0,0). 99 // No anchor at origin (0,0).
(...skipping 21 matching lines...) Expand all
94 ScrollableArea* viewport = layoutViewport(); 121 ScrollableArea* viewport = layoutViewport();
95 scrollLayoutViewport(DoubleSize(0, 100)); 122 scrollLayoutViewport(DoubleSize(0, 100));
96 123
97 document().getElementById("block1")->setAttribute( 124 document().getElementById("block1")->setAttribute(
98 HTMLNames::styleAttr, "height: 50.6px"); 125 HTMLNames::styleAttr, "height: 50.6px");
99 update(); 126 update();
100 127
101 EXPECT_EQ(101, viewport->scrollPosition().y()); 128 EXPECT_EQ(101, viewport->scrollPosition().y());
102 } 129 }
103 130
104 TEST_F(ScrollAnchorTest, UMAMetricUpdated)
105 {
106 HistogramTester histogramTester;
107 setBodyInnerHTML(
108 "<style> body { height: 1000px } div { height: 100px } </style>"
109 "<div id='block1'>abc</div>"
110 "<div id='block2'>def</div>");
111
112 ScrollableArea* viewport = layoutViewport();
113
114 // Scroll position not adjusted, metric not updated.
115 scrollLayoutViewport(DoubleSize(0, 150));
116 histogramTester.expectTotalCount(
117 "Layout.ScrollAnchor.AdjustedScrollOffset", 0);
118
119 // Height changed, verify metric updated once.
120 setHeight(document().getElementById("block1"), 200);
121 histogramTester.expectUniqueSample(
122 "Layout.ScrollAnchor.AdjustedScrollOffset", 1, 1);
123
124 EXPECT_EQ(250, viewport->scrollPosition().y());
125 EXPECT_EQ(document().getElementById("block2")->layoutObject(),
126 scrollAnchor(viewport).anchorObject());
127 }
128
129 TEST_F(ScrollAnchorTest, AnchorWithLayerInScrollingDiv) 131 TEST_F(ScrollAnchorTest, AnchorWithLayerInScrollingDiv)
130 { 132 {
131 setBodyInnerHTML( 133 setBodyInnerHTML(
132 "<style>" 134 "<style>"
133 " #scroller { overflow: scroll; width: 500px; height: 400px; }" 135 " #scroller { overflow: scroll; width: 500px; height: 400px; }"
134 " div { height: 100px }" 136 " div { height: 100px }"
135 " #block2 { overflow: hidden }" 137 " #block2 { overflow: hidden }"
136 " #space { height: 1000px; }" 138 " #space { height: 1000px; }"
137 "</style>" 139 "</style>"
138 "<div id='scroller'><div id='space'>" 140 "<div id='scroller'><div id='space'>"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 "<div id=c></div>" 407 "<div id=c></div>"
406 "<div id=d></div>"); 408 "<div id=d></div>");
407 409
408 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0)) ; 410 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0)) ;
409 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0 )); 411 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0 ));
410 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30 0)); 412 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30 0));
411 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, - 300)); 413 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, - 300));
412 } 414 }
413 415
414 } 416 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698