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

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

Issue 1860903002: Update Source/platform/ to assume Oilpan only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: back out ScrollAnimatorMac() accidental change 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/FakeGraphicsLayer.h" 11 #include "platform/testing/FakeGraphicsLayer.h"
12 #include "platform/testing/TestingPlatformSupport.h" 12 #include "platform/testing/TestingPlatformSupport.h"
13 #include "public/platform/Platform.h" 13 #include "public/platform/Platform.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace blink { 17 namespace blink {
18 18
19 namespace { 19 namespace {
20 20
21 using testing::_; 21 using testing::_;
22 using testing::Return; 22 using testing::Return;
23 23
24 class MockScrollableArea : public GarbageCollectedFinalized<MockScrollableArea>, public ScrollableArea { 24 class MockScrollableArea : public GarbageCollectedFinalized<MockScrollableArea>, public ScrollableArea {
25 USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); 25 USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea);
26 public: 26 public:
27 static RawPtr<MockScrollableArea> create(const IntPoint& maximumScrollPositi on) 27 static MockScrollableArea* create(const IntPoint& maximumScrollPosition)
28 { 28 {
29 return new MockScrollableArea(maximumScrollPosition); 29 return new MockScrollableArea(maximumScrollPosition);
30 } 30 }
31 31
32 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect()); 32 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect());
33 MOCK_CONST_METHOD0(isActive, bool()); 33 MOCK_CONST_METHOD0(isActive, bool());
34 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); 34 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation));
35 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); 35 MOCK_CONST_METHOD0(isScrollCornerVisible, bool());
36 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); 36 MOCK_CONST_METHOD0(scrollCornerRect, IntRect());
37 MOCK_CONST_METHOD0(horizontalScrollbar, Scrollbar*()); 37 MOCK_CONST_METHOD0(horizontalScrollbar, Scrollbar*());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 { 90 {
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 }; 96 };
97 97
98 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) 98 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync)
99 { 99 {
100 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(0, 100)); 100 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0, 100));
101 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll); 101 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll);
102 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y()); 102 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y());
103 } 103 }
104 104
105 namespace { 105 namespace {
106 106
107 class ScrollbarThemeWithMockInvalidation : public ScrollbarThemeMock { 107 class ScrollbarThemeWithMockInvalidation : public ScrollbarThemeMock {
108 public: 108 public:
109 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool()); 109 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool());
110 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, ScrollbarPart(const Scro llbarThemeClient&, float, float)); 110 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, ScrollbarPart(const Scro llbarThemeClient&, float, float));
111 }; 111 };
112 112
113 } // namespace 113 } // namespace
114 114
115 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint) 115 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint)
116 { 116 {
117 ScrollbarThemeWithMockInvalidation theme; 117 ScrollbarThemeWithMockInvalidation theme;
118 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(0, 100)); 118 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0, 100));
119 RawPtr<Scrollbar> scrollbar = Scrollbar::createForTesting(scrollableArea.get (), HorizontalScrollbar, RegularScrollbar, &theme); 119 Scrollbar* scrollbar = Scrollbar::createForTesting(scrollableArea, Horizonta lScrollbar, RegularScrollbar, &theme);
120 120
121 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(true)); 121 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(true));
122 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); 122 EXPECT_TRUE(scrollbar->trackNeedsRepaint());
123 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 123 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
124 scrollbar->setNeedsPaintInvalidation(NoPart); 124 scrollbar->setNeedsPaintInvalidation(NoPart);
125 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); 125 EXPECT_TRUE(scrollbar->trackNeedsRepaint());
126 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 126 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
127 127
128 scrollbar->clearTrackNeedsRepaint(); 128 scrollbar->clearTrackNeedsRepaint();
129 scrollbar->clearThumbNeedsRepaint(); 129 scrollbar->clearThumbNeedsRepaint();
(...skipping 23 matching lines...) Expand all
153 bool needsRepaint(const GraphicsLayer&) const { return true; } 153 bool needsRepaint(const GraphicsLayer&) const { return true; }
154 IntRect computeInterestRect(const GraphicsLayer*, const IntRect&) const { re turn IntRect(); } 154 IntRect computeInterestRect(const GraphicsLayer*, const IntRect&) const { re turn IntRect(); }
155 void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPain tingPhase, const IntRect&) const override { } 155 void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPain tingPhase, const IntRect&) const override { }
156 String debugName(const GraphicsLayer*) const override { return String(); } 156 String debugName(const GraphicsLayer*) const override { return String(); }
157 bool isTrackingPaintInvalidations() const override { return true; } 157 bool isTrackingPaintInvalidations() const override { return true; }
158 }; 158 };
159 159
160 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation) 160 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation)
161 { 161 {
162 ScrollbarTheme::setMockScrollbarsEnabled(true); 162 ScrollbarTheme::setMockScrollbarsEnabled(true);
163 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(0, 100)); 163 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0, 100));
164 MockGraphicsLayerClient graphicsLayerClient; 164 MockGraphicsLayerClient graphicsLayerClient;
165 FakeGraphicsLayer graphicsLayer(&graphicsLayerClient); 165 FakeGraphicsLayer graphicsLayer(&graphicsLayerClient);
166 graphicsLayer.setDrawsContent(true); 166 graphicsLayer.setDrawsContent(true);
167 graphicsLayer.setSize(FloatSize(111, 222)); 167 graphicsLayer.setSize(FloatSize(111, 222));
168 168
169 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&graphicsLayer)); 169 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&graphicsLayer));
170 170
171 RawPtr<Scrollbar> scrollbar = Scrollbar::create(scrollableArea.get(), Horizo ntalScrollbar, RegularScrollbar, nullptr); 171 Scrollbar* scrollbar = Scrollbar::create(scrollableArea, HorizontalScrollbar , RegularScrollbar, nullptr);
172 graphicsLayer.resetTrackedPaintInvalidations(); 172 graphicsLayer.resetTrackedPaintInvalidations();
173 scrollbar->setNeedsPaintInvalidation(NoPart); 173 scrollbar->setNeedsPaintInvalidation(NoPart);
174 EXPECT_TRUE(graphicsLayer.hasTrackedPaintInvalidations()); 174 EXPECT_TRUE(graphicsLayer.hasTrackedPaintInvalidations());
175 175
176 // Forced GC in order to finalize objects depending on the mock object. 176 // Forced GC in order to finalize objects depending on the mock object.
177 Heap::collectAllGarbage(); 177 Heap::collectAllGarbage();
178 } 178 }
179 179
180 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves) 180 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves)
181 { 181 {
182 ScrollbarThemeWithMockInvalidation theme; 182 ScrollbarThemeWithMockInvalidation theme;
183 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(100, 100)); 183 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(100 , 100));
184 RawPtr<Scrollbar> horizontalScrollbar = Scrollbar::createForTesting(scrollab leArea.get(), HorizontalScrollbar, RegularScrollbar, &theme); 184 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting(scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme);
185 RawPtr<Scrollbar> verticalScrollbar = Scrollbar::createForTesting(scrollable Area.get(), VerticalScrollbar, RegularScrollbar, &theme); 185 Scrollbar* verticalScrollbar = Scrollbar::createForTesting(scrollableArea, V erticalScrollbar, RegularScrollbar, &theme);
186 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar.get())); 186 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar));
187 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar.get())); 187 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar));
188 188
189 // Regardless of whether the theme invalidates any parts, non-composited 189 // Regardless of whether the theme invalidates any parts, non-composited
190 // scrollbars have to be repainted if the thumb moves. 190 // scrollbars have to be repainted if the thumb moves.
191 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(nullptr)); 191 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(nullptr));
192 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()).WillRepeatedly(Ret urn(nullptr)); 192 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()).WillRepeatedly(Ret urn(nullptr));
193 ASSERT_FALSE(scrollableArea->hasLayerForVerticalScrollbar()); 193 ASSERT_FALSE(scrollableArea->hasLayerForVerticalScrollbar());
194 ASSERT_FALSE(scrollableArea->hasLayerForHorizontalScrollbar()); 194 ASSERT_FALSE(scrollableArea->hasLayerForHorizontalScrollbar());
195 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false)); 195 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false));
196 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillRepeatedly( Return(NoPart)); 196 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillRepeatedly( Return(NoPart));
197 197
198 // A scroll in each direction should only invalidate one scrollbar. 198 // A scroll in each direction should only invalidate one scrollbar.
199 scrollableArea->setScrollPosition(DoublePoint(0, 50), ProgrammaticScroll); 199 scrollableArea->setScrollPosition(DoublePoint(0, 50), ProgrammaticScroll);
200 EXPECT_FALSE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation()); 200 EXPECT_FALSE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation());
201 EXPECT_TRUE(scrollableArea->verticalScrollbarNeedsPaintInvalidation()); 201 EXPECT_TRUE(scrollableArea->verticalScrollbarNeedsPaintInvalidation());
202 scrollableArea->clearNeedsPaintInvalidationForScrollControls(); 202 scrollableArea->clearNeedsPaintInvalidationForScrollControls();
203 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll); 203 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll);
204 EXPECT_TRUE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation()); 204 EXPECT_TRUE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation());
205 EXPECT_FALSE(scrollableArea->verticalScrollbarNeedsPaintInvalidation()); 205 EXPECT_FALSE(scrollableArea->verticalScrollbarNeedsPaintInvalidation());
206 scrollableArea->clearNeedsPaintInvalidationForScrollControls(); 206 scrollableArea->clearNeedsPaintInvalidationForScrollControls();
207 207
208 // Forced GC in order to finalize objects depending on the mock object. 208 // Forced GC in order to finalize objects depending on the mock object.
209 Heap::collectAllGarbage(); 209 Heap::collectAllGarbage();
210 } 210 }
211 211
212 TEST_F(ScrollableAreaTest, InvalidatesCompositedScrollbarsIfPartsNeedRepaint) 212 TEST_F(ScrollableAreaTest, InvalidatesCompositedScrollbarsIfPartsNeedRepaint)
213 { 213 {
214 ScrollbarThemeWithMockInvalidation theme; 214 ScrollbarThemeWithMockInvalidation theme;
215 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(100, 100)); 215 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(100 , 100));
216 RawPtr<Scrollbar> horizontalScrollbar = Scrollbar::createForTesting(scrollab leArea.get(), HorizontalScrollbar, RegularScrollbar, &theme); 216 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting(scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme);
217 horizontalScrollbar->clearTrackNeedsRepaint(); 217 horizontalScrollbar->clearTrackNeedsRepaint();
218 horizontalScrollbar->clearThumbNeedsRepaint(); 218 horizontalScrollbar->clearThumbNeedsRepaint();
219 RawPtr<Scrollbar> verticalScrollbar = Scrollbar::createForTesting(scrollable Area.get(), VerticalScrollbar, RegularScrollbar, &theme); 219 Scrollbar* verticalScrollbar = Scrollbar::createForTesting(scrollableArea, V erticalScrollbar, RegularScrollbar, &theme);
220 verticalScrollbar->clearTrackNeedsRepaint(); 220 verticalScrollbar->clearTrackNeedsRepaint();
221 verticalScrollbar->clearThumbNeedsRepaint(); 221 verticalScrollbar->clearThumbNeedsRepaint();
222 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar.get())); 222 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar));
223 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar.get())); 223 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar));
224 224
225 // Composited scrollbars only need repainting when parts become invalid 225 // Composited scrollbars only need repainting when parts become invalid
226 // (e.g. if the track changes appearance when the thumb reaches the end). 226 // (e.g. if the track changes appearance when the thumb reaches the end).
227 MockGraphicsLayerClient graphicsLayerClient; 227 MockGraphicsLayerClient graphicsLayerClient;
228 FakeGraphicsLayer layerForHorizontalScrollbar(&graphicsLayerClient); 228 FakeGraphicsLayer layerForHorizontalScrollbar(&graphicsLayerClient);
229 layerForHorizontalScrollbar.setDrawsContent(true); 229 layerForHorizontalScrollbar.setDrawsContent(true);
230 layerForHorizontalScrollbar.setSize(FloatSize(10, 10)); 230 layerForHorizontalScrollbar.setSize(FloatSize(10, 10));
231 FakeGraphicsLayer layerForVerticalScrollbar(&graphicsLayerClient); 231 FakeGraphicsLayer layerForVerticalScrollbar(&graphicsLayerClient);
232 layerForVerticalScrollbar.setDrawsContent(true); 232 layerForVerticalScrollbar.setDrawsContent(true);
233 layerForVerticalScrollbar.setSize(FloatSize(10, 10)); 233 layerForVerticalScrollbar.setSize(FloatSize(10, 10));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); 270 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint());
271 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); 271 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint());
272 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint()); 272 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint());
273 273
274 // Forced GC in order to finalize objects depending on the mock object. 274 // Forced GC in order to finalize objects depending on the mock object.
275 Heap::collectAllGarbage(); 275 Heap::collectAllGarbage();
276 } 276 }
277 277
278 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges) 278 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges)
279 { 279 {
280 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(IntPo int(0, 100)); 280 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0, 100));
281 281
282 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle()); 282 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle());
283 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51)); 283 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51));
284 EXPECT_EQ(ScrollbarOverlayStyleLight, scrollableArea->getScrollbarOverlaySty le()); 284 EXPECT_EQ(ScrollbarOverlayStyleLight, scrollableArea->getScrollbarOverlaySty le());
285 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185)); 285 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185));
286 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle()); 286 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS tyle());
287 } 287 }
288 288
289 } // namespace blink 289 } // 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