OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 int visibleHeight() const override { return 768; } | 81 int visibleHeight() const override { return 768; } |
82 int visibleWidth() const override { return 1024; } | 82 int visibleWidth() const override { return 1024; } |
83 bool scrollAnimatorEnabled() const override { return m_scrollAnimatorEnabled
; } | 83 bool scrollAnimatorEnabled() const override { return m_scrollAnimatorEnabled
; } |
84 int pageStep(ScrollbarOrientation) const override { return 0; } | 84 int pageStep(ScrollbarOrientation) const override { return 0; } |
85 | 85 |
86 void setScrollAnimator(ScrollAnimator* scrollAnimator) | 86 void setScrollAnimator(ScrollAnimator* scrollAnimator) |
87 { | 87 { |
88 animator = scrollAnimator; | 88 animator = scrollAnimator; |
89 } | 89 } |
90 | 90 |
| 91 bool shouldScrollOnMainThread() const override |
| 92 { |
| 93 return m_scrollOnMainThread; |
| 94 } |
| 95 |
| 96 void setScrollOnMainThread(bool scrollOnMainThread) |
| 97 { |
| 98 m_scrollOnMainThread = scrollOnMainThread; |
| 99 } |
| 100 |
91 DoublePoint scrollPositionDouble() const override | 101 DoublePoint scrollPositionDouble() const override |
92 { | 102 { |
93 if (animator) | 103 if (animator) |
94 return animator->currentPosition(); | 104 return animator->currentPosition(); |
95 return ScrollableArea::scrollPositionDouble(); | 105 return ScrollableArea::scrollPositionDouble(); |
96 } | 106 } |
97 | 107 |
98 void setScrollPosition(const DoublePoint& position, ScrollType type, | 108 void setScrollPosition(const DoublePoint& position, ScrollType type, |
99 ScrollBehavior behavior = ScrollBehaviorInstant) | 109 ScrollBehavior behavior = ScrollBehaviorInstant) |
100 { | 110 { |
101 if (animator) | 111 if (animator) |
102 animator->setCurrentPosition(toFloatPoint(position)); | 112 animator->setCurrentPosition(toFloatPoint(position)); |
103 ScrollableArea::setScrollPosition(position, type, behavior); | 113 ScrollableArea::setScrollPosition(position, type, behavior); |
104 } | 114 } |
105 | 115 |
106 DEFINE_INLINE_VIRTUAL_TRACE() | 116 DEFINE_INLINE_VIRTUAL_TRACE() |
107 { | 117 { |
108 visitor->trace(animator); | 118 visitor->trace(animator); |
109 ScrollableArea::trace(visitor); | 119 ScrollableArea::trace(visitor); |
110 } | 120 } |
111 | 121 |
112 private: | 122 private: |
113 explicit MockScrollableArea(bool scrollAnimatorEnabled) | 123 explicit MockScrollableArea(bool scrollAnimatorEnabled) |
114 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } | 124 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } |
115 | 125 |
116 bool m_scrollAnimatorEnabled; | 126 bool m_scrollAnimatorEnabled; |
| 127 bool m_scrollOnMainThread = false; |
117 Member<ScrollAnimator> animator; | 128 Member<ScrollAnimator> animator; |
118 }; | 129 }; |
119 | 130 |
120 class TestScrollAnimator : public ScrollAnimator { | 131 class TestScrollAnimator : public ScrollAnimator { |
121 public: | 132 public: |
122 TestScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timingF
unction) | 133 TestScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timingF
unction) |
123 : ScrollAnimator(scrollableArea, timingFunction) {}; | 134 : ScrollAnimator(scrollableArea, timingFunction) {}; |
124 ~TestScrollAnimator() override {}; | 135 ~TestScrollAnimator() override {}; |
125 | 136 |
126 void setShouldSendToCompositor(bool send) | 137 void setShouldSendToCompositor(bool send) |
(...skipping 23 matching lines...) Expand all Loading... |
150 static void reset(ScrollAnimator& scrollAnimator) | 161 static void reset(ScrollAnimator& scrollAnimator) |
151 { | 162 { |
152 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint()); | 163 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint()); |
153 } | 164 } |
154 | 165 |
155 // TODO(skobes): Add unit tests for composited scrolling paths. | 166 // TODO(skobes): Add unit tests for composited scrolling paths. |
156 | 167 |
157 TEST(ScrollAnimatorTest, MainThreadStates) | 168 TEST(ScrollAnimatorTest, MainThreadStates) |
158 { | 169 { |
159 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 170 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); |
| 171 scrollableArea->setScrollOnMainThread(true); |
160 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke
dTime); | 172 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke
dTime); |
161 | 173 |
162 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) | 174 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) |
163 .WillRepeatedly(Return(IntPoint())); | 175 .WillRepeatedly(Return(IntPoint())); |
164 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) | 176 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) |
165 .WillRepeatedly(Return(IntPoint(1000, 1000))); | 177 .WillRepeatedly(Return(IntPoint(1000, 1000))); |
166 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); | 178 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); |
167 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); | 179 // Once from userScroll. |
| 180 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(1); |
168 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) | 181 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) |
169 .WillRepeatedly(Return(true)); | 182 .WillRepeatedly(Return(true)); |
170 | 183 |
171 // Idle | 184 // Idle |
172 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | 185 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
173 EXPECT_EQ(scrollAnimator->m_runState, | 186 EXPECT_EQ(scrollAnimator->m_runState, |
174 ScrollAnimatorCompositorCoordinator::RunState::Idle); | 187 ScrollAnimatorCompositorCoordinator::RunState::Idle); |
175 | 188 |
176 // WaitingToSendToCompositor | 189 // WaitingToSendToCompositor |
177 scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0)); | 190 scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0)); |
178 EXPECT_EQ(scrollAnimator->m_runState, | 191 EXPECT_EQ(scrollAnimator->m_runState, |
179 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor
); | 192 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); |
180 | 193 |
181 // RunningOnMainThread | 194 // RunningOnMainThread |
182 gMockedTime += 0.05; | 195 gMockedTime += 0.05; |
183 scrollAnimator->updateCompositorAnimations(); | 196 scrollAnimator->updateCompositorAnimations(); |
184 EXPECT_EQ(scrollAnimator->m_runState, | 197 EXPECT_EQ(scrollAnimator->m_runState, |
185 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); | 198 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); |
186 scrollAnimator->tickAnimation(getMockedTime()); | 199 scrollAnimator->tickAnimation(getMockedTime()); |
187 EXPECT_EQ(scrollAnimator->m_runState, | 200 EXPECT_EQ(scrollAnimator->m_runState, |
188 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); | 201 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); |
189 | 202 |
190 // PostAnimationCleanup | 203 // PostAnimationCleanup |
191 scrollAnimator->cancelAnimation(); | 204 scrollAnimator->cancelAnimation(); |
192 EXPECT_EQ(scrollAnimator->m_runState, | 205 EXPECT_EQ(scrollAnimator->m_runState, |
193 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); | 206 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); |
194 | 207 |
195 // Idle | 208 // Idle |
196 scrollAnimator->updateCompositorAnimations(); | 209 scrollAnimator->updateCompositorAnimations(); |
197 scrollAnimator->tickAnimation(getMockedTime()); | 210 scrollAnimator->tickAnimation(getMockedTime()); |
198 EXPECT_EQ(scrollAnimator->m_runState, | 211 EXPECT_EQ(scrollAnimator->m_runState, |
199 ScrollAnimatorCompositorCoordinator::RunState::Idle); | 212 ScrollAnimatorCompositorCoordinator::RunState::Idle); |
200 | 213 |
201 reset(*scrollAnimator); | 214 reset(*scrollAnimator); |
| 215 |
| 216 // Forced GC in order to finalize objects depending on the mock object. |
| 217 ThreadHeap::collectAllGarbage(); |
202 } | 218 } |
203 | 219 |
204 TEST(ScrollAnimatorTest, MainThreadEnabled) | 220 TEST(ScrollAnimatorTest, MainThreadEnabled) |
205 { | 221 { |
206 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 222 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); |
207 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke
dTime); | 223 ScrollAnimator* scrollAnimator = new ScrollAnimator(scrollableArea, getMocke
dTime); |
208 | 224 |
209 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint())); | 225 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint())); |
210 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint(1000, 1000))); | 226 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint(1000, 1000))); |
211 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(9); | 227 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(9); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 animator->updateCompositorAnimations(); | 639 animator->updateCompositorAnimations(); |
624 animator->tickAnimation(getMockedTime()); | 640 animator->tickAnimation(getMockedTime()); |
625 EXPECT_EQ(FloatPoint(110, 90), animator->currentPosition()); | 641 EXPECT_EQ(FloatPoint(110, 90), animator->currentPosition()); |
626 reset(*animator); | 642 reset(*animator); |
627 | 643 |
628 // Forced GC in order to finalize objects depending on the mock object. | 644 // Forced GC in order to finalize objects depending on the mock object. |
629 ThreadHeap::collectAllGarbage(); | 645 ThreadHeap::collectAllGarbage(); |
630 } | 646 } |
631 | 647 |
632 } // namespace blink | 648 } // namespace blink |
OLD | NEW |