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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/ScrollbarTheme.h" 9 #include "platform/scroll/ScrollbarTheme.h"
10 #include "platform/scroll/ScrollbarThemeMock.h" 10 #include "platform/scroll/ScrollbarThemeMock.h"
11 #include "platform/testing/TestingPlatformSupport.h" 11 #include "platform/testing/TestingPlatformSupport.h"
12 #include "public/platform/Platform.h" 12 #include "public/platform/Platform.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 namespace { 18 namespace {
19 19
20 using testing::_; 20 using testing::_;
21 using testing::Return; 21 using testing::Return;
22 22
23 class MockScrollableArea : public NoBaseWillBeGarbageCollectedFinalized<MockScro llableArea>, public ScrollableArea { 23 class MockScrollableArea : public GarbageCollectedFinalized<MockScrollableArea>, public ScrollableArea {
24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); 24 USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea);
25 public: 25 public:
26 static PassOwnPtrWillBeRawPtr<MockScrollableArea> create(const IntPoint& max imumScrollPosition) 26 static RawPtr<MockScrollableArea> create(const IntPoint& maximumScrollPositi on)
27 { 27 {
28 return adoptPtrWillBeNoop(new MockScrollableArea(maximumScrollPosition)) ; 28 return new MockScrollableArea(maximumScrollPosition);
29 } 29 }
30 30
31 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect()); 31 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect());
32 MOCK_CONST_METHOD0(isActive, bool()); 32 MOCK_CONST_METHOD0(isActive, bool());
33 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); 33 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation));
34 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); 34 MOCK_CONST_METHOD0(isScrollCornerVisible, bool());
35 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); 35 MOCK_CONST_METHOD0(scrollCornerRect, IntRect());
36 MOCK_CONST_METHOD0(horizontalScrollbar, Scrollbar*()); 36 MOCK_CONST_METHOD0(horizontalScrollbar, Scrollbar*());
37 MOCK_CONST_METHOD0(verticalScrollbar, Scrollbar*()); 37 MOCK_CONST_METHOD0(verticalScrollbar, Scrollbar*());
38 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void()); 38 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 { 89 {
90 m_fakePlatform = nullptr; 90 m_fakePlatform = nullptr;
91 } 91 }
92 92
93 private: 93 private:
94 OwnPtr<TestingPlatformSupportWithMockScheduler> m_fakePlatform; 94 OwnPtr<TestingPlatformSupportWithMockScheduler> m_fakePlatform;
95 }; 95 };
96 96
97 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) 97 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync)
98 { 98 {
99 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100)); 99 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(0, 100));
100 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll); 100 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll);
101 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y()); 101 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y());
102 } 102 }
103 103
104 namespace { 104 namespace {
105 105
106 class ScrollbarThemeWithMockInvalidation : public ScrollbarThemeMock { 106 class ScrollbarThemeWithMockInvalidation : public ScrollbarThemeMock {
107 public: 107 public:
108 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool()); 108 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool());
109 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, ScrollbarPart(const Scro llbarThemeClient&, float, float)); 109 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, ScrollbarPart(const Scro llbarThemeClient&, float, float));
110 }; 110 };
111 111
112 } // namespace 112 } // namespace
113 113
114 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint) 114 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint)
115 { 115 {
116 ScrollbarThemeWithMockInvalidation theme; 116 ScrollbarThemeWithMockInvalidation theme;
117 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100)); 117 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(0, 100));
118 RefPtrWillBeRawPtr<Scrollbar> scrollbar = Scrollbar::createForTesting(scroll ableArea.get(), HorizontalScrollbar, RegularScrollbar, &theme); 118 RawPtr<Scrollbar> scrollbar = Scrollbar::createForTesting(scrollableArea.get (), HorizontalScrollbar, RegularScrollbar, &theme);
119 119
120 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(true)); 120 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(true));
121 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); 121 EXPECT_TRUE(scrollbar->trackNeedsRepaint());
122 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 122 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
123 scrollbar->setNeedsPaintInvalidation(NoPart); 123 scrollbar->setNeedsPaintInvalidation(NoPart);
124 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); 124 EXPECT_TRUE(scrollbar->trackNeedsRepaint());
125 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 125 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
126 126
127 scrollbar->clearTrackNeedsRepaint(); 127 scrollbar->clearTrackNeedsRepaint();
128 scrollbar->clearThumbNeedsRepaint(); 128 scrollbar->clearThumbNeedsRepaint();
(...skipping 28 matching lines...) Expand all
157 }; 157 };
158 158
159 class MockGraphicsLayer : public GraphicsLayer { 159 class MockGraphicsLayer : public GraphicsLayer {
160 public: 160 public:
161 explicit MockGraphicsLayer(GraphicsLayerClient* client) : GraphicsLayer(clie nt) { } 161 explicit MockGraphicsLayer(GraphicsLayerClient* client) : GraphicsLayer(clie nt) { }
162 }; 162 };
163 163
164 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation) 164 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation)
165 { 165 {
166 ScrollbarTheme::setMockScrollbarsEnabled(true); 166 ScrollbarTheme::setMockScrollbarsEnabled(true);
167 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100)); 167 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(0, 100));
168 MockGraphicsLayerClient graphicsLayerClient; 168 MockGraphicsLayerClient graphicsLayerClient;
169 MockGraphicsLayer graphicsLayer(&graphicsLayerClient); 169 MockGraphicsLayer graphicsLayer(&graphicsLayerClient);
170 graphicsLayer.setDrawsContent(true); 170 graphicsLayer.setDrawsContent(true);
171 graphicsLayer.setSize(FloatSize(111, 222)); 171 graphicsLayer.setSize(FloatSize(111, 222));
172 172
173 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&graphicsLayer)); 173 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&graphicsLayer));
174 174
175 RefPtrWillBeRawPtr<Scrollbar> scrollbar = Scrollbar::create(scrollableArea.g et(), HorizontalScrollbar, RegularScrollbar, nullptr); 175 RawPtr<Scrollbar> scrollbar = Scrollbar::create(scrollableArea.get(), Horizo ntalScrollbar, RegularScrollbar, nullptr);
176 graphicsLayer.resetTrackedPaintInvalidations(); 176 graphicsLayer.resetTrackedPaintInvalidations();
177 scrollbar->setNeedsPaintInvalidation(NoPart); 177 scrollbar->setNeedsPaintInvalidation(NoPart);
178 EXPECT_TRUE(graphicsLayer.hasTrackedPaintInvalidations()); 178 EXPECT_TRUE(graphicsLayer.hasTrackedPaintInvalidations());
179 179
180 // Forced GC in order to finalize objects depending on the mock object. 180 // Forced GC in order to finalize objects depending on the mock object.
181 Heap::collectAllGarbage(); 181 Heap::collectAllGarbage();
182 } 182 }
183 183
184 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves) 184 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves)
185 { 185 {
186 ScrollbarThemeWithMockInvalidation theme; 186 ScrollbarThemeWithMockInvalidation theme;
187 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(100, 100)); 187 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(100, 100));
188 RefPtrWillBeRawPtr<Scrollbar> horizontalScrollbar = Scrollbar::createForTest ing(scrollableArea.get(), HorizontalScrollbar, RegularScrollbar, &theme); 188 RawPtr<Scrollbar> horizontalScrollbar = Scrollbar::createForTesting(scrollab leArea.get(), HorizontalScrollbar, RegularScrollbar, &theme);
189 RefPtrWillBeRawPtr<Scrollbar> verticalScrollbar = Scrollbar::createForTestin g(scrollableArea.get(), VerticalScrollbar, RegularScrollbar, &theme); 189 RawPtr<Scrollbar> verticalScrollbar = Scrollbar::createForTesting(scrollable Area.get(), VerticalScrollbar, RegularScrollbar, &theme);
190 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar.get())); 190 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar.get()));
191 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar.get())); 191 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar.get()));
192 192
193 // Regardless of whether the theme invalidates any parts, non-composited 193 // Regardless of whether the theme invalidates any parts, non-composited
194 // scrollbars have to be repainted if the thumb moves. 194 // scrollbars have to be repainted if the thumb moves.
195 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(nullptr)); 195 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(nullptr));
196 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()).WillRepeatedly(Ret urn(nullptr)); 196 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()).WillRepeatedly(Ret urn(nullptr));
197 ASSERT_FALSE(scrollableArea->hasLayerForVerticalScrollbar()); 197 ASSERT_FALSE(scrollableArea->hasLayerForVerticalScrollbar());
198 ASSERT_FALSE(scrollableArea->hasLayerForHorizontalScrollbar()); 198 ASSERT_FALSE(scrollableArea->hasLayerForHorizontalScrollbar());
199 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false)); 199 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false));
200 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillRepeatedly( Return(NoPart)); 200 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillRepeatedly( Return(NoPart));
201 201
202 // A scroll in each direction should only invalidate one scrollbar. 202 // A scroll in each direction should only invalidate one scrollbar.
203 scrollableArea->setScrollPosition(DoublePoint(0, 50), ProgrammaticScroll); 203 scrollableArea->setScrollPosition(DoublePoint(0, 50), ProgrammaticScroll);
204 EXPECT_FALSE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation()); 204 EXPECT_FALSE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation());
205 EXPECT_TRUE(scrollableArea->verticalScrollbarNeedsPaintInvalidation()); 205 EXPECT_TRUE(scrollableArea->verticalScrollbarNeedsPaintInvalidation());
206 scrollableArea->clearNeedsPaintInvalidationForScrollControls(); 206 scrollableArea->clearNeedsPaintInvalidationForScrollControls();
207 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll); 207 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll);
208 EXPECT_TRUE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation()); 208 EXPECT_TRUE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation());
209 EXPECT_FALSE(scrollableArea->verticalScrollbarNeedsPaintInvalidation()); 209 EXPECT_FALSE(scrollableArea->verticalScrollbarNeedsPaintInvalidation());
210 scrollableArea->clearNeedsPaintInvalidationForScrollControls(); 210 scrollableArea->clearNeedsPaintInvalidationForScrollControls();
211 211
212 // Forced GC in order to finalize objects depending on the mock object. 212 // Forced GC in order to finalize objects depending on the mock object.
213 Heap::collectAllGarbage(); 213 Heap::collectAllGarbage();
214 } 214 }
215 215
216 TEST_F(ScrollableAreaTest, InvalidatesCompositedScrollbarsIfPartsNeedRepaint) 216 TEST_F(ScrollableAreaTest, InvalidatesCompositedScrollbarsIfPartsNeedRepaint)
217 { 217 {
218 ScrollbarThemeWithMockInvalidation theme; 218 ScrollbarThemeWithMockInvalidation theme;
219 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(100, 100)); 219 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(100, 100));
220 RefPtrWillBeRawPtr<Scrollbar> horizontalScrollbar = Scrollbar::createForTest ing(scrollableArea.get(), HorizontalScrollbar, RegularScrollbar, &theme); 220 RawPtr<Scrollbar> horizontalScrollbar = Scrollbar::createForTesting(scrollab leArea.get(), HorizontalScrollbar, RegularScrollbar, &theme);
221 horizontalScrollbar->clearTrackNeedsRepaint(); 221 horizontalScrollbar->clearTrackNeedsRepaint();
222 horizontalScrollbar->clearThumbNeedsRepaint(); 222 horizontalScrollbar->clearThumbNeedsRepaint();
223 RefPtrWillBeRawPtr<Scrollbar> verticalScrollbar = Scrollbar::createForTestin g(scrollableArea.get(), VerticalScrollbar, RegularScrollbar, &theme); 223 RawPtr<Scrollbar> verticalScrollbar = Scrollbar::createForTesting(scrollable Area.get(), VerticalScrollbar, RegularScrollbar, &theme);
224 verticalScrollbar->clearTrackNeedsRepaint(); 224 verticalScrollbar->clearTrackNeedsRepaint();
225 verticalScrollbar->clearThumbNeedsRepaint(); 225 verticalScrollbar->clearThumbNeedsRepaint();
226 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar.get())); 226 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar.get()));
227 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar.get())); 227 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar.get()));
228 228
229 // Composited scrollbars only need repainting when parts become invalid 229 // Composited scrollbars only need repainting when parts become invalid
230 // (e.g. if the track changes appearance when the thumb reaches the end). 230 // (e.g. if the track changes appearance when the thumb reaches the end).
231 MockGraphicsLayerClient graphicsLayerClient; 231 MockGraphicsLayerClient graphicsLayerClient;
232 MockGraphicsLayer layerForHorizontalScrollbar(&graphicsLayerClient); 232 MockGraphicsLayer layerForHorizontalScrollbar(&graphicsLayerClient);
233 layerForHorizontalScrollbar.setDrawsContent(true); 233 layerForHorizontalScrollbar.setDrawsContent(true);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); 274 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint());
275 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); 275 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint());
276 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint()); 276 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint());
277 277
278 // Forced GC in order to finalize objects depending on the mock object. 278 // Forced GC in order to finalize objects depending on the mock object.
279 Heap::collectAllGarbage(); 279 Heap::collectAllGarbage();
280 } 280 }
281 281
282 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges) 282 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges)
283 { 283 {
284 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100)); 284 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(0, 100));
285 285
286 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle()); 286 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle());
287 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51)); 287 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51));
288 EXPECT_EQ(ScrollbarOverlayStyleLight, scrollableArea->getScrollbarOverlaySty le()); 288 EXPECT_EQ(ScrollbarOverlayStyleLight, scrollableArea->getScrollbarOverlaySty le());
289 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185)); 289 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185));
290 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle()); 290 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle());
291 } 291 }
292 292
293 } // namespace blink 293 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollableArea.cpp ('k') | third_party/WebKit/Source/platform/scroll/Scrollbar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698