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

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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 // Forced GC in order to finalize objects depending on the mock object. 76 // Forced GC in order to finalize objects depending on the mock object.
77 ThreadState::current()-> collectAllGarbage(); 77 ThreadState::current()-> collectAllGarbage();
78 } 78 }
79 79
80 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation) 80 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation)
81 { 81 {
82 ScrollbarTheme::setMockScrollbarsEnabled(true); 82 ScrollbarTheme::setMockScrollbarsEnabled(true);
83 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0, 100)); 83 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0, 100));
84 FakeGraphicsLayerClient graphicsLayerClient; 84 FakeGraphicsLayerClient graphicsLayerClient;
85 graphicsLayerClient.setIsTrackingPaintInvalidations(true); 85 graphicsLayerClient.setIsTrackingRasterInvalidations(true);
86 FakeGraphicsLayer graphicsLayer(&graphicsLayerClient); 86 FakeGraphicsLayer graphicsLayer(&graphicsLayerClient);
87 graphicsLayer.setDrawsContent(true); 87 graphicsLayer.setDrawsContent(true);
88 graphicsLayer.setSize(FloatSize(111, 222)); 88 graphicsLayer.setSize(FloatSize(111, 222));
89 89
90 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&graphicsLayer)); 90 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&graphicsLayer));
91 91
92 Scrollbar* scrollbar = Scrollbar::create(scrollableArea, HorizontalScrollbar , RegularScrollbar, nullptr); 92 Scrollbar* scrollbar = Scrollbar::create(scrollableArea, HorizontalScrollbar , RegularScrollbar, nullptr);
93 graphicsLayer.resetTrackedPaintInvalidations(); 93 graphicsLayer.resetTrackedRasterInvalidations();
94 scrollbar->setNeedsPaintInvalidation(NoPart); 94 scrollbar->setNeedsPaintInvalidation(NoPart);
95 EXPECT_TRUE(graphicsLayer.hasTrackedPaintInvalidations()); 95 EXPECT_TRUE(graphicsLayer.hasTrackedRasterInvalidations());
96 96
97 // Forced GC in order to finalize objects depending on the mock object. 97 // Forced GC in order to finalize objects depending on the mock object.
98 ThreadState::current()-> collectAllGarbage(); 98 ThreadState::current()-> collectAllGarbage();
99 } 99 }
100 100
101 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves) 101 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves)
102 { 102 {
103 ScrollbarThemeWithMockInvalidation theme; 103 ScrollbarThemeWithMockInvalidation theme;
104 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(100 , 100)); 104 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(100 , 100));
105 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting(scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); 105 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting(scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 horizontalScrollbar->clearThumbNeedsRepaint(); 139 horizontalScrollbar->clearThumbNeedsRepaint();
140 Scrollbar* verticalScrollbar = Scrollbar::createForTesting(scrollableArea, V erticalScrollbar, RegularScrollbar, &theme); 140 Scrollbar* verticalScrollbar = Scrollbar::createForTesting(scrollableArea, V erticalScrollbar, RegularScrollbar, &theme);
141 verticalScrollbar->clearTrackNeedsRepaint(); 141 verticalScrollbar->clearTrackNeedsRepaint();
142 verticalScrollbar->clearThumbNeedsRepaint(); 142 verticalScrollbar->clearThumbNeedsRepaint();
143 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar)); 143 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar));
144 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar)); 144 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar));
145 145
146 // Composited scrollbars only need repainting when parts become invalid 146 // Composited scrollbars only need repainting when parts become invalid
147 // (e.g. if the track changes appearance when the thumb reaches the end). 147 // (e.g. if the track changes appearance when the thumb reaches the end).
148 FakeGraphicsLayerClient graphicsLayerClient; 148 FakeGraphicsLayerClient graphicsLayerClient;
149 graphicsLayerClient.setIsTrackingPaintInvalidations(true); 149 graphicsLayerClient.setIsTrackingRasterInvalidations(true);
150 FakeGraphicsLayer layerForHorizontalScrollbar(&graphicsLayerClient); 150 FakeGraphicsLayer layerForHorizontalScrollbar(&graphicsLayerClient);
151 layerForHorizontalScrollbar.setDrawsContent(true); 151 layerForHorizontalScrollbar.setDrawsContent(true);
152 layerForHorizontalScrollbar.setSize(FloatSize(10, 10)); 152 layerForHorizontalScrollbar.setSize(FloatSize(10, 10));
153 FakeGraphicsLayer layerForVerticalScrollbar(&graphicsLayerClient); 153 FakeGraphicsLayer layerForVerticalScrollbar(&graphicsLayerClient);
154 layerForVerticalScrollbar.setDrawsContent(true); 154 layerForVerticalScrollbar.setDrawsContent(true);
155 layerForVerticalScrollbar.setSize(FloatSize(10, 10)); 155 layerForVerticalScrollbar.setSize(FloatSize(10, 10));
156 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&layerForHorizontalScrollbar)); 156 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&layerForHorizontalScrollbar));
157 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()).WillRepeatedly(Ret urn(&layerForVerticalScrollbar)); 157 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()).WillRepeatedly(Ret urn(&layerForVerticalScrollbar));
158 ASSERT_TRUE(scrollableArea->hasLayerForHorizontalScrollbar()); 158 ASSERT_TRUE(scrollableArea->hasLayerForHorizontalScrollbar());
159 ASSERT_TRUE(scrollableArea->hasLayerForVerticalScrollbar()); 159 ASSERT_TRUE(scrollableArea->hasLayerForVerticalScrollbar());
160 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false)); 160 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false));
161 161
162 // First, we'll scroll horizontally, and the theme will require repainting 162 // First, we'll scroll horizontally, and the theme will require repainting
163 // the back button (i.e. the track). 163 // the back button (i.e. the track).
164 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillOnce(Return (BackButtonStartPart)); 164 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillOnce(Return (BackButtonStartPart));
165 scrollableArea->setScrollPosition(DoublePoint(50, 0), ProgrammaticScroll); 165 scrollableArea->setScrollPosition(DoublePoint(50, 0), ProgrammaticScroll);
166 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedPaintInvalidations()); 166 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations());
167 EXPECT_FALSE(layerForVerticalScrollbar.hasTrackedPaintInvalidations()); 167 EXPECT_FALSE(layerForVerticalScrollbar.hasTrackedRasterInvalidations());
168 EXPECT_TRUE(horizontalScrollbar->trackNeedsRepaint()); 168 EXPECT_TRUE(horizontalScrollbar->trackNeedsRepaint());
169 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); 169 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint());
170 layerForHorizontalScrollbar.resetTrackedPaintInvalidations(); 170 layerForHorizontalScrollbar.resetTrackedRasterInvalidations();
171 horizontalScrollbar->clearTrackNeedsRepaint(); 171 horizontalScrollbar->clearTrackNeedsRepaint();
172 172
173 // Next, we'll scroll vertically, but invalidate the thumb. 173 // Next, we'll scroll vertically, but invalidate the thumb.
174 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillOnce(Return (ThumbPart)); 174 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillOnce(Return (ThumbPart));
175 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll); 175 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll);
176 EXPECT_FALSE(layerForHorizontalScrollbar.hasTrackedPaintInvalidations()); 176 EXPECT_FALSE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations());
177 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedPaintInvalidations()); 177 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedRasterInvalidations());
178 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); 178 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint());
179 EXPECT_TRUE(verticalScrollbar->thumbNeedsRepaint()); 179 EXPECT_TRUE(verticalScrollbar->thumbNeedsRepaint());
180 layerForVerticalScrollbar.resetTrackedPaintInvalidations(); 180 layerForVerticalScrollbar.resetTrackedRasterInvalidations();
181 verticalScrollbar->clearThumbNeedsRepaint(); 181 verticalScrollbar->clearThumbNeedsRepaint();
182 182
183 // Next we'll scroll in both, but the thumb position moving requires no 183 // Next we'll scroll in both, but the thumb position moving requires no
184 // invalidations. Nonetheless the GraphicsLayer should be invalidated, 184 // invalidations. Nonetheless the GraphicsLayer should be invalidated,
185 // because we still need to update the underlying layer (though no 185 // because we still need to update the underlying layer (though no
186 // rasterization will be required). 186 // rasterization will be required).
187 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).Times(2).WillRe peatedly(Return(NoPart)); 187 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).Times(2).WillRe peatedly(Return(NoPart));
188 scrollableArea->setScrollPosition(DoublePoint(70, 70), ProgrammaticScroll); 188 scrollableArea->setScrollPosition(DoublePoint(70, 70), ProgrammaticScroll);
189 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedPaintInvalidations()); 189 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations());
190 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedPaintInvalidations()); 190 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedRasterInvalidations());
191 EXPECT_FALSE(horizontalScrollbar->trackNeedsRepaint()); 191 EXPECT_FALSE(horizontalScrollbar->trackNeedsRepaint());
192 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); 192 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint());
193 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); 193 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint());
194 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint()); 194 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint());
195 195
196 // Forced GC in order to finalize objects depending on the mock object. 196 // Forced GC in order to finalize objects depending on the mock object.
197 ThreadState::current()-> collectAllGarbage(); 197 ThreadState::current()-> collectAllGarbage();
198 } 198 }
199 199
200 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges) 200 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges)
201 { 201 {
202 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0, 100)); 202 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0, 100));
203 203
204 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle()); 204 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle());
205 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51)); 205 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51));
206 EXPECT_EQ(ScrollbarOverlayStyleLight, scrollableArea->getScrollbarOverlaySty le()); 206 EXPECT_EQ(ScrollbarOverlayStyleLight, scrollableArea->getScrollbarOverlaySty le());
207 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185)); 207 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185));
208 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle()); 208 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle());
209 } 209 }
210 210
211 } // namespace blink 211 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698