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

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollableAreaTest.cpp

Issue 2380683006: SPv2: Add support for tracking raster paint invalidations in testing. (Closed)
Patch Set: none 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 "platform/scroll/ScrollableArea.h" 5 #include "platform/scroll/ScrollableArea.h"
6 6
7 #include "platform/graphics/Color.h" 7 #include "platform/graphics/Color.h"
8 #include "platform/graphics/GraphicsLayer.h" 8 #include "platform/graphics/GraphicsLayer.h"
9 #include "platform/scroll/ScrollbarTestSuite.h" 9 #include "platform/scroll/ScrollbarTestSuite.h"
10 #include "platform/scroll/ScrollbarTheme.h" 10 #include "platform/scroll/ScrollbarTheme.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 // Forced GC in order to finalize objects depending on the mock object. 79 // Forced GC in order to finalize objects depending on the mock object.
80 ThreadState::current()->collectAllGarbage(); 80 ThreadState::current()->collectAllGarbage();
81 } 81 }
82 82
83 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation) { 83 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation) {
84 ScrollbarTheme::setMockScrollbarsEnabled(true); 84 ScrollbarTheme::setMockScrollbarsEnabled(true);
85 MockScrollableArea* scrollableArea = 85 MockScrollableArea* scrollableArea =
86 MockScrollableArea::create(IntPoint(0, 100)); 86 MockScrollableArea::create(IntPoint(0, 100));
87 FakeGraphicsLayerClient graphicsLayerClient; 87 FakeGraphicsLayerClient graphicsLayerClient;
88 graphicsLayerClient.setIsTrackingPaintInvalidations(true); 88 graphicsLayerClient.setIsTrackingRasterInvalidations(true);
89 FakeGraphicsLayer graphicsLayer(&graphicsLayerClient); 89 FakeGraphicsLayer graphicsLayer(&graphicsLayerClient);
90 graphicsLayer.setDrawsContent(true); 90 graphicsLayer.setDrawsContent(true);
91 graphicsLayer.setSize(FloatSize(111, 222)); 91 graphicsLayer.setSize(FloatSize(111, 222));
92 92
93 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()) 93 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar())
94 .WillRepeatedly(Return(&graphicsLayer)); 94 .WillRepeatedly(Return(&graphicsLayer));
95 95
96 Scrollbar* scrollbar = Scrollbar::create(scrollableArea, HorizontalScrollbar, 96 Scrollbar* scrollbar = Scrollbar::create(scrollableArea, HorizontalScrollbar,
97 RegularScrollbar, nullptr); 97 RegularScrollbar, nullptr);
98 graphicsLayer.resetTrackedPaintInvalidations(); 98 graphicsLayer.resetTrackedRasterInvalidations();
99 scrollbar->setNeedsPaintInvalidation(NoPart); 99 scrollbar->setNeedsPaintInvalidation(NoPart);
100 EXPECT_TRUE(graphicsLayer.hasTrackedPaintInvalidations()); 100 EXPECT_TRUE(graphicsLayer.hasTrackedRasterInvalidations());
101 101
102 // Forced GC in order to finalize objects depending on the mock object. 102 // Forced GC in order to finalize objects depending on the mock object.
103 ThreadState::current()->collectAllGarbage(); 103 ThreadState::current()->collectAllGarbage();
104 } 104 }
105 105
106 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves) { 106 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves) {
107 ScrollbarThemeWithMockInvalidation theme; 107 ScrollbarThemeWithMockInvalidation theme;
108 MockScrollableArea* scrollableArea = 108 MockScrollableArea* scrollableArea =
109 MockScrollableArea::create(IntPoint(100, 100)); 109 MockScrollableArea::create(IntPoint(100, 100));
110 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting( 110 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 verticalScrollbar->clearTrackNeedsRepaint(); 156 verticalScrollbar->clearTrackNeedsRepaint();
157 verticalScrollbar->clearThumbNeedsRepaint(); 157 verticalScrollbar->clearThumbNeedsRepaint();
158 EXPECT_CALL(*scrollableArea, horizontalScrollbar()) 158 EXPECT_CALL(*scrollableArea, horizontalScrollbar())
159 .WillRepeatedly(Return(horizontalScrollbar)); 159 .WillRepeatedly(Return(horizontalScrollbar));
160 EXPECT_CALL(*scrollableArea, verticalScrollbar()) 160 EXPECT_CALL(*scrollableArea, verticalScrollbar())
161 .WillRepeatedly(Return(verticalScrollbar)); 161 .WillRepeatedly(Return(verticalScrollbar));
162 162
163 // Composited scrollbars only need repainting when parts become invalid 163 // Composited scrollbars only need repainting when parts become invalid
164 // (e.g. if the track changes appearance when the thumb reaches the end). 164 // (e.g. if the track changes appearance when the thumb reaches the end).
165 FakeGraphicsLayerClient graphicsLayerClient; 165 FakeGraphicsLayerClient graphicsLayerClient;
166 graphicsLayerClient.setIsTrackingPaintInvalidations(true); 166 graphicsLayerClient.setIsTrackingRasterInvalidations(true);
167 FakeGraphicsLayer layerForHorizontalScrollbar(&graphicsLayerClient); 167 FakeGraphicsLayer layerForHorizontalScrollbar(&graphicsLayerClient);
168 layerForHorizontalScrollbar.setDrawsContent(true); 168 layerForHorizontalScrollbar.setDrawsContent(true);
169 layerForHorizontalScrollbar.setSize(FloatSize(10, 10)); 169 layerForHorizontalScrollbar.setSize(FloatSize(10, 10));
170 FakeGraphicsLayer layerForVerticalScrollbar(&graphicsLayerClient); 170 FakeGraphicsLayer layerForVerticalScrollbar(&graphicsLayerClient);
171 layerForVerticalScrollbar.setDrawsContent(true); 171 layerForVerticalScrollbar.setDrawsContent(true);
172 layerForVerticalScrollbar.setSize(FloatSize(10, 10)); 172 layerForVerticalScrollbar.setSize(FloatSize(10, 10));
173 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()) 173 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar())
174 .WillRepeatedly(Return(&layerForHorizontalScrollbar)); 174 .WillRepeatedly(Return(&layerForHorizontalScrollbar));
175 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()) 175 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar())
176 .WillRepeatedly(Return(&layerForVerticalScrollbar)); 176 .WillRepeatedly(Return(&layerForVerticalScrollbar));
177 ASSERT_TRUE(scrollableArea->hasLayerForHorizontalScrollbar()); 177 ASSERT_TRUE(scrollableArea->hasLayerForHorizontalScrollbar());
178 ASSERT_TRUE(scrollableArea->hasLayerForVerticalScrollbar()); 178 ASSERT_TRUE(scrollableArea->hasLayerForVerticalScrollbar());
179 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()) 179 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation())
180 .WillRepeatedly(Return(false)); 180 .WillRepeatedly(Return(false));
181 181
182 // First, we'll scroll horizontally, and the theme will require repainting 182 // First, we'll scroll horizontally, and the theme will require repainting
183 // the back button (i.e. the track). 183 // the back button (i.e. the track).
184 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) 184 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _))
185 .WillOnce(Return(BackButtonStartPart)); 185 .WillOnce(Return(BackButtonStartPart));
186 scrollableArea->setScrollPosition(DoublePoint(50, 0), ProgrammaticScroll); 186 scrollableArea->setScrollPosition(DoublePoint(50, 0), ProgrammaticScroll);
187 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedPaintInvalidations()); 187 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations());
188 EXPECT_FALSE(layerForVerticalScrollbar.hasTrackedPaintInvalidations()); 188 EXPECT_FALSE(layerForVerticalScrollbar.hasTrackedRasterInvalidations());
189 EXPECT_TRUE(horizontalScrollbar->trackNeedsRepaint()); 189 EXPECT_TRUE(horizontalScrollbar->trackNeedsRepaint());
190 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); 190 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint());
191 layerForHorizontalScrollbar.resetTrackedPaintInvalidations(); 191 layerForHorizontalScrollbar.resetTrackedRasterInvalidations();
192 horizontalScrollbar->clearTrackNeedsRepaint(); 192 horizontalScrollbar->clearTrackNeedsRepaint();
193 193
194 // Next, we'll scroll vertically, but invalidate the thumb. 194 // Next, we'll scroll vertically, but invalidate the thumb.
195 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) 195 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _))
196 .WillOnce(Return(ThumbPart)); 196 .WillOnce(Return(ThumbPart));
197 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll); 197 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll);
198 EXPECT_FALSE(layerForHorizontalScrollbar.hasTrackedPaintInvalidations()); 198 EXPECT_FALSE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations());
199 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedPaintInvalidations()); 199 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedRasterInvalidations());
200 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); 200 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint());
201 EXPECT_TRUE(verticalScrollbar->thumbNeedsRepaint()); 201 EXPECT_TRUE(verticalScrollbar->thumbNeedsRepaint());
202 layerForVerticalScrollbar.resetTrackedPaintInvalidations(); 202 layerForVerticalScrollbar.resetTrackedRasterInvalidations();
203 verticalScrollbar->clearThumbNeedsRepaint(); 203 verticalScrollbar->clearThumbNeedsRepaint();
204 204
205 // Next we'll scroll in both, but the thumb position moving requires no 205 // Next we'll scroll in both, but the thumb position moving requires no
206 // invalidations. Nonetheless the GraphicsLayer should be invalidated, 206 // invalidations. Nonetheless the GraphicsLayer should be invalidated,
207 // because we still need to update the underlying layer (though no 207 // because we still need to update the underlying layer (though no
208 // rasterization will be required). 208 // rasterization will be required).
209 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) 209 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _))
210 .Times(2) 210 .Times(2)
211 .WillRepeatedly(Return(NoPart)); 211 .WillRepeatedly(Return(NoPart));
212 scrollableArea->setScrollPosition(DoublePoint(70, 70), ProgrammaticScroll); 212 scrollableArea->setScrollPosition(DoublePoint(70, 70), ProgrammaticScroll);
213 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedPaintInvalidations()); 213 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations());
214 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedPaintInvalidations()); 214 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedRasterInvalidations());
215 EXPECT_FALSE(horizontalScrollbar->trackNeedsRepaint()); 215 EXPECT_FALSE(horizontalScrollbar->trackNeedsRepaint());
216 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); 216 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint());
217 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); 217 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint());
218 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint()); 218 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint());
219 219
220 // Forced GC in order to finalize objects depending on the mock object. 220 // Forced GC in order to finalize objects depending on the mock object.
221 ThreadState::current()->collectAllGarbage(); 221 ThreadState::current()->collectAllGarbage();
222 } 222 }
223 223
224 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges) { 224 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges) {
225 MockScrollableArea* scrollableArea = 225 MockScrollableArea* scrollableArea =
226 MockScrollableArea::create(IntPoint(0, 100)); 226 MockScrollableArea::create(IntPoint(0, 100));
227 227
228 EXPECT_EQ(ScrollbarOverlayStyleDefault, 228 EXPECT_EQ(ScrollbarOverlayStyleDefault,
229 scrollableArea->getScrollbarOverlayStyle()); 229 scrollableArea->getScrollbarOverlayStyle());
230 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51)); 230 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51));
231 EXPECT_EQ(ScrollbarOverlayStyleLight, 231 EXPECT_EQ(ScrollbarOverlayStyleLight,
232 scrollableArea->getScrollbarOverlayStyle()); 232 scrollableArea->getScrollbarOverlayStyle());
233 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185)); 233 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185));
234 EXPECT_EQ(ScrollbarOverlayStyleDefault, 234 EXPECT_EQ(ScrollbarOverlayStyleDefault,
235 scrollableArea->getScrollbarOverlayStyle()); 235 scrollableArea->getScrollbarOverlayStyle());
236 } 236 }
237 237
238 } // namespace blink 238 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698