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

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

Powered by Google App Engine
This is Rietveld 408576698