OLD | NEW |
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 17 matching lines...) Expand all Loading... |
28 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool()); | 28 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool()); |
29 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, | 29 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, |
30 ScrollbarPart(const ScrollbarThemeClient&, float, float)); | 30 ScrollbarPart(const ScrollbarThemeClient&, float, float)); |
31 }; | 31 }; |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 class ScrollableAreaTest : public ScrollbarTestSuite {}; | 35 class ScrollableAreaTest : public ScrollbarTestSuite {}; |
36 | 36 |
37 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) { | 37 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) { |
| 38 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler, |
| 39 const TestingPlatformSupport::Config&> |
| 40 platform(m_config); |
| 41 |
38 MockScrollableArea* scrollableArea = | 42 MockScrollableArea* scrollableArea = |
39 MockScrollableArea::create(ScrollOffset(0, 100)); | 43 MockScrollableArea::create(ScrollOffset(0, 100)); |
40 scrollableArea->setScrollOffset(ScrollOffset(0, 10000), CompositorScroll); | 44 scrollableArea->setScrollOffset(ScrollOffset(0, 10000), CompositorScroll); |
41 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentOffset().height()); | 45 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentOffset().height()); |
42 } | 46 } |
43 | 47 |
44 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint) { | 48 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint) { |
| 49 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler, |
| 50 const TestingPlatformSupport::Config&> |
| 51 platform(m_config); |
| 52 |
45 ScrollbarThemeWithMockInvalidation theme; | 53 ScrollbarThemeWithMockInvalidation theme; |
46 MockScrollableArea* scrollableArea = | 54 MockScrollableArea* scrollableArea = |
47 MockScrollableArea::create(ScrollOffset(0, 100)); | 55 MockScrollableArea::create(ScrollOffset(0, 100)); |
48 Scrollbar* scrollbar = Scrollbar::createForTesting( | 56 Scrollbar* scrollbar = Scrollbar::createForTesting( |
49 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); | 57 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); |
50 | 58 |
51 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()) | 59 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()) |
52 .WillRepeatedly(Return(true)); | 60 .WillRepeatedly(Return(true)); |
53 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); | 61 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); |
54 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); | 62 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); |
(...skipping 19 matching lines...) Expand all Loading... |
74 EXPECT_FALSE(scrollbar->thumbNeedsRepaint()); | 82 EXPECT_FALSE(scrollbar->thumbNeedsRepaint()); |
75 scrollbar->setNeedsPaintInvalidation(ThumbPart); | 83 scrollbar->setNeedsPaintInvalidation(ThumbPart); |
76 EXPECT_FALSE(scrollbar->trackNeedsRepaint()); | 84 EXPECT_FALSE(scrollbar->trackNeedsRepaint()); |
77 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); | 85 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); |
78 | 86 |
79 // Forced GC in order to finalize objects depending on the mock object. | 87 // Forced GC in order to finalize objects depending on the mock object. |
80 ThreadState::current()->collectAllGarbage(); | 88 ThreadState::current()->collectAllGarbage(); |
81 } | 89 } |
82 | 90 |
83 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation) { | 91 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation) { |
| 92 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler, |
| 93 const TestingPlatformSupport::Config&> |
| 94 platform(m_config); |
| 95 |
84 ScrollbarTheme::setMockScrollbarsEnabled(true); | 96 ScrollbarTheme::setMockScrollbarsEnabled(true); |
85 MockScrollableArea* scrollableArea = | 97 MockScrollableArea* scrollableArea = |
86 MockScrollableArea::create(ScrollOffset(0, 100)); | 98 MockScrollableArea::create(ScrollOffset(0, 100)); |
87 FakeGraphicsLayerClient graphicsLayerClient; | 99 FakeGraphicsLayerClient graphicsLayerClient; |
88 graphicsLayerClient.setIsTrackingRasterInvalidations(true); | 100 graphicsLayerClient.setIsTrackingRasterInvalidations(true); |
89 FakeGraphicsLayer graphicsLayer(&graphicsLayerClient); | 101 FakeGraphicsLayer graphicsLayer(&graphicsLayerClient); |
90 graphicsLayer.setDrawsContent(true); | 102 graphicsLayer.setDrawsContent(true); |
91 graphicsLayer.setSize(FloatSize(111, 222)); | 103 graphicsLayer.setSize(FloatSize(111, 222)); |
92 | 104 |
93 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()) | 105 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()) |
94 .WillRepeatedly(Return(&graphicsLayer)); | 106 .WillRepeatedly(Return(&graphicsLayer)); |
95 | 107 |
96 Scrollbar* scrollbar = Scrollbar::create(scrollableArea, HorizontalScrollbar, | 108 Scrollbar* scrollbar = Scrollbar::create(scrollableArea, HorizontalScrollbar, |
97 RegularScrollbar, nullptr); | 109 RegularScrollbar, nullptr); |
98 graphicsLayer.resetTrackedRasterInvalidations(); | 110 graphicsLayer.resetTrackedRasterInvalidations(); |
99 scrollbar->setNeedsPaintInvalidation(NoPart); | 111 scrollbar->setNeedsPaintInvalidation(NoPart); |
100 EXPECT_TRUE(graphicsLayer.hasTrackedRasterInvalidations()); | 112 EXPECT_TRUE(graphicsLayer.hasTrackedRasterInvalidations()); |
101 | 113 |
102 // Forced GC in order to finalize objects depending on the mock object. | 114 // Forced GC in order to finalize objects depending on the mock object. |
103 ThreadState::current()->collectAllGarbage(); | 115 ThreadState::current()->collectAllGarbage(); |
104 } | 116 } |
105 | 117 |
106 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves) { | 118 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves) { |
| 119 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler, |
| 120 const TestingPlatformSupport::Config&> |
| 121 platform(m_config); |
| 122 |
107 ScrollbarThemeWithMockInvalidation theme; | 123 ScrollbarThemeWithMockInvalidation theme; |
108 MockScrollableArea* scrollableArea = | 124 MockScrollableArea* scrollableArea = |
109 MockScrollableArea::create(ScrollOffset(100, 100)); | 125 MockScrollableArea::create(ScrollOffset(100, 100)); |
110 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting( | 126 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting( |
111 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); | 127 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); |
112 Scrollbar* verticalScrollbar = Scrollbar::createForTesting( | 128 Scrollbar* verticalScrollbar = Scrollbar::createForTesting( |
113 scrollableArea, VerticalScrollbar, RegularScrollbar, &theme); | 129 scrollableArea, VerticalScrollbar, RegularScrollbar, &theme); |
114 EXPECT_CALL(*scrollableArea, horizontalScrollbar()) | 130 EXPECT_CALL(*scrollableArea, horizontalScrollbar()) |
115 .WillRepeatedly(Return(horizontalScrollbar)); | 131 .WillRepeatedly(Return(horizontalScrollbar)); |
116 EXPECT_CALL(*scrollableArea, verticalScrollbar()) | 132 EXPECT_CALL(*scrollableArea, verticalScrollbar()) |
(...skipping 20 matching lines...) Expand all Loading... |
137 scrollableArea->setScrollOffset(ScrollOffset(50, 50), ProgrammaticScroll); | 153 scrollableArea->setScrollOffset(ScrollOffset(50, 50), ProgrammaticScroll); |
138 EXPECT_TRUE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation()); | 154 EXPECT_TRUE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation()); |
139 EXPECT_FALSE(scrollableArea->verticalScrollbarNeedsPaintInvalidation()); | 155 EXPECT_FALSE(scrollableArea->verticalScrollbarNeedsPaintInvalidation()); |
140 scrollableArea->clearNeedsPaintInvalidationForScrollControls(); | 156 scrollableArea->clearNeedsPaintInvalidationForScrollControls(); |
141 | 157 |
142 // Forced GC in order to finalize objects depending on the mock object. | 158 // Forced GC in order to finalize objects depending on the mock object. |
143 ThreadState::current()->collectAllGarbage(); | 159 ThreadState::current()->collectAllGarbage(); |
144 } | 160 } |
145 | 161 |
146 TEST_F(ScrollableAreaTest, InvalidatesCompositedScrollbarsIfPartsNeedRepaint) { | 162 TEST_F(ScrollableAreaTest, InvalidatesCompositedScrollbarsIfPartsNeedRepaint) { |
| 163 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler, |
| 164 const TestingPlatformSupport::Config&> |
| 165 platform(m_config); |
| 166 |
147 ScrollbarThemeWithMockInvalidation theme; | 167 ScrollbarThemeWithMockInvalidation theme; |
148 MockScrollableArea* scrollableArea = | 168 MockScrollableArea* scrollableArea = |
149 MockScrollableArea::create(ScrollOffset(100, 100)); | 169 MockScrollableArea::create(ScrollOffset(100, 100)); |
150 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting( | 170 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting( |
151 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); | 171 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); |
152 horizontalScrollbar->clearTrackNeedsRepaint(); | 172 horizontalScrollbar->clearTrackNeedsRepaint(); |
153 horizontalScrollbar->clearThumbNeedsRepaint(); | 173 horizontalScrollbar->clearThumbNeedsRepaint(); |
154 Scrollbar* verticalScrollbar = Scrollbar::createForTesting( | 174 Scrollbar* verticalScrollbar = Scrollbar::createForTesting( |
155 scrollableArea, VerticalScrollbar, RegularScrollbar, &theme); | 175 scrollableArea, VerticalScrollbar, RegularScrollbar, &theme); |
156 verticalScrollbar->clearTrackNeedsRepaint(); | 176 verticalScrollbar->clearTrackNeedsRepaint(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 EXPECT_FALSE(horizontalScrollbar->trackNeedsRepaint()); | 235 EXPECT_FALSE(horizontalScrollbar->trackNeedsRepaint()); |
216 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); | 236 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); |
217 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); | 237 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); |
218 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint()); | 238 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint()); |
219 | 239 |
220 // Forced GC in order to finalize objects depending on the mock object. | 240 // Forced GC in order to finalize objects depending on the mock object. |
221 ThreadState::current()->collectAllGarbage(); | 241 ThreadState::current()->collectAllGarbage(); |
222 } | 242 } |
223 | 243 |
224 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges) { | 244 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges) { |
| 245 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler, |
| 246 const TestingPlatformSupport::Config&> |
| 247 platform(m_config); |
| 248 |
225 MockScrollableArea* scrollableArea = | 249 MockScrollableArea* scrollableArea = |
226 MockScrollableArea::create(ScrollOffset(0, 100)); | 250 MockScrollableArea::create(ScrollOffset(0, 100)); |
227 | 251 |
228 EXPECT_EQ(ScrollbarOverlayColorThemeDark, | 252 EXPECT_EQ(ScrollbarOverlayColorThemeDark, |
229 scrollableArea->getScrollbarOverlayColorTheme()); | 253 scrollableArea->getScrollbarOverlayColorTheme()); |
230 scrollableArea->recalculateScrollbarOverlayColorTheme(Color(34, 85, 51)); | 254 scrollableArea->recalculateScrollbarOverlayColorTheme(Color(34, 85, 51)); |
231 EXPECT_EQ(ScrollbarOverlayColorThemeLight, | 255 EXPECT_EQ(ScrollbarOverlayColorThemeLight, |
232 scrollableArea->getScrollbarOverlayColorTheme()); | 256 scrollableArea->getScrollbarOverlayColorTheme()); |
233 scrollableArea->recalculateScrollbarOverlayColorTheme(Color(236, 143, 185)); | 257 scrollableArea->recalculateScrollbarOverlayColorTheme(Color(236, 143, 185)); |
234 EXPECT_EQ(ScrollbarOverlayColorThemeDark, | 258 EXPECT_EQ(ScrollbarOverlayColorThemeDark, |
235 scrollableArea->getScrollbarOverlayColorTheme()); | 259 scrollableArea->getScrollbarOverlayColorTheme()); |
236 } | 260 } |
237 | 261 |
238 } // namespace blink | 262 } // namespace blink |
OLD | NEW |