| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 return gMockedTime; | 46 return gMockedTime; |
| 47 } | 47 } |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 class MockScrollableArea : public GarbageCollectedFinalized<MockScrollableArea>, | 51 class MockScrollableArea : public GarbageCollectedFinalized<MockScrollableArea>, |
| 52 public ScrollableArea { | 52 public ScrollableArea { |
| 53 USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); | 53 USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); |
| 54 | 54 |
| 55 public: | 55 public: |
| 56 static MockScrollableArea* create(bool scrollAnimatorEnabled) { | 56 static MockScrollableArea* create(bool scrollAnimatorEnabled, |
| 57 return new MockScrollableArea(scrollAnimatorEnabled); | 57 const ScrollOffset& minOffset, |
| 58 const ScrollOffset& maxOffset) { |
| 59 return new MockScrollableArea(scrollAnimatorEnabled, minOffset, maxOffset); |
| 58 } | 60 } |
| 59 | 61 |
| 60 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect()); | 62 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect()); |
| 61 MOCK_CONST_METHOD0(isActive, bool()); | 63 MOCK_CONST_METHOD0(isActive, bool()); |
| 62 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); | 64 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); |
| 63 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); | 65 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); |
| 64 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); | 66 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); |
| 65 MOCK_METHOD2(setScrollOffset, void(const DoublePoint&, ScrollType)); | 67 MOCK_METHOD2(updateScrollOffset, void(const ScrollOffset&, ScrollType)); |
| 66 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void()); | 68 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void()); |
| 67 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); | 69 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); |
| 68 MOCK_CONST_METHOD0(minimumScrollPosition, IntPoint()); | |
| 69 MOCK_CONST_METHOD0(maximumScrollPosition, IntPoint()); | |
| 70 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); | 70 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); |
| 71 MOCK_CONST_METHOD0(contentsSize, IntSize()); | 71 MOCK_CONST_METHOD0(contentsSize, IntSize()); |
| 72 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); | 72 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); |
| 73 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); | 73 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); |
| 74 MOCK_METHOD0(registerForAnimation, void()); | 74 MOCK_METHOD0(registerForAnimation, void()); |
| 75 MOCK_METHOD0(scheduleAnimation, bool()); | 75 MOCK_METHOD0(scheduleAnimation, bool()); |
| 76 | 76 |
| 77 bool userInputScrollable(ScrollbarOrientation) const override { return true; } | 77 bool userInputScrollable(ScrollbarOrientation) const override { return true; } |
| 78 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } | 78 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } |
| 79 IntPoint scrollPosition() const override { return IntPoint(); } | 79 IntSize scrollOffsetInt() const override { return IntSize(); } |
| 80 int visibleHeight() const override { return 768; } | 80 int visibleHeight() const override { return 768; } |
| 81 int visibleWidth() const override { return 1024; } | 81 int visibleWidth() const override { return 1024; } |
| 82 bool scrollAnimatorEnabled() const override { | 82 bool scrollAnimatorEnabled() const override { |
| 83 return m_scrollAnimatorEnabled; | 83 return m_scrollAnimatorEnabled; |
| 84 } | 84 } |
| 85 int pageStep(ScrollbarOrientation) const override { return 0; } | 85 int pageStep(ScrollbarOrientation) const override { return 0; } |
| 86 IntSize minimumScrollOffsetInt() const override { |
| 87 return flooredIntSize(m_minOffset); |
| 88 } |
| 89 IntSize maximumScrollOffsetInt() const override { |
| 90 return flooredIntSize(m_maxOffset); |
| 91 } |
| 86 | 92 |
| 87 void setScrollAnimator(ScrollAnimator* scrollAnimator) { | 93 void setScrollAnimator(ScrollAnimator* scrollAnimator) { |
| 88 animator = scrollAnimator; | 94 animator = scrollAnimator; |
| 89 } | 95 } |
| 90 | 96 |
| 91 DoublePoint scrollPositionDouble() const override { | 97 ScrollOffset scrollOffset() const override { |
| 92 if (animator) | 98 if (animator) |
| 93 return animator->currentPosition(); | 99 return animator->currentOffset(); |
| 94 return ScrollableArea::scrollPositionDouble(); | 100 return ScrollableArea::scrollOffset(); |
| 95 } | 101 } |
| 96 | 102 |
| 97 void setScrollPosition(const DoublePoint& position, | 103 void setScrollOffset(const ScrollOffset& offset, |
| 98 ScrollType type, | 104 ScrollType type, |
| 99 ScrollBehavior behavior = ScrollBehaviorInstant) { | 105 ScrollBehavior behavior = ScrollBehaviorInstant) { |
| 100 if (animator) | 106 if (animator) |
| 101 animator->setCurrentPosition(toFloatPoint(position)); | 107 animator->setCurrentOffset(offset); |
| 102 ScrollableArea::setScrollPosition(position, type, behavior); | 108 ScrollableArea::setScrollOffset(offset, type, behavior); |
| 103 } | 109 } |
| 104 | 110 |
| 105 DEFINE_INLINE_VIRTUAL_TRACE() { | 111 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 106 visitor->trace(animator); | 112 visitor->trace(animator); |
| 107 ScrollableArea::trace(visitor); | 113 ScrollableArea::trace(visitor); |
| 108 } | 114 } |
| 109 | 115 |
| 110 private: | 116 private: |
| 111 explicit MockScrollableArea(bool scrollAnimatorEnabled) | 117 explicit MockScrollableArea(bool scrollAnimatorEnabled, |
| 112 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) {} | 118 const ScrollOffset& minOffset, |
| 119 const ScrollOffset& maxOffset) |
| 120 : m_scrollAnimatorEnabled(scrollAnimatorEnabled), |
| 121 m_minOffset(minOffset), |
| 122 m_maxOffset(maxOffset) {} |
| 113 | 123 |
| 114 bool m_scrollAnimatorEnabled; | 124 bool m_scrollAnimatorEnabled; |
| 125 ScrollOffset m_minOffset; |
| 126 ScrollOffset m_maxOffset; |
| 115 Member<ScrollAnimator> animator; | 127 Member<ScrollAnimator> animator; |
| 116 }; | 128 }; |
| 117 | 129 |
| 118 class TestScrollAnimator : public ScrollAnimator { | 130 class TestScrollAnimator : public ScrollAnimator { |
| 119 public: | 131 public: |
| 120 TestScrollAnimator(ScrollableArea* scrollableArea, | 132 TestScrollAnimator(ScrollableArea* scrollableArea, |
| 121 WTF::TimeFunction timingFunction) | 133 WTF::TimeFunction timingFunction) |
| 122 : ScrollAnimator(scrollableArea, timingFunction){}; | 134 : ScrollAnimator(scrollableArea, timingFunction){}; |
| 123 ~TestScrollAnimator() override{}; | 135 ~TestScrollAnimator() override{}; |
| 124 | 136 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 137 protected: | 149 protected: |
| 138 void abortAnimation() override {} | 150 void abortAnimation() override {} |
| 139 | 151 |
| 140 private: | 152 private: |
| 141 bool m_shouldSendToCompositor = false; | 153 bool m_shouldSendToCompositor = false; |
| 142 }; | 154 }; |
| 143 | 155 |
| 144 } // namespace | 156 } // namespace |
| 145 | 157 |
| 146 static void reset(ScrollAnimator& scrollAnimator) { | 158 static void reset(ScrollAnimator& scrollAnimator) { |
| 147 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint()); | 159 scrollAnimator.scrollToOffsetWithoutAnimation(ScrollOffset()); |
| 148 } | 160 } |
| 149 | 161 |
| 150 // TODO(skobes): Add unit tests for composited scrolling paths. | 162 // TODO(skobes): Add unit tests for composited scrolling paths. |
| 151 | 163 |
| 152 TEST(ScrollAnimatorTest, MainThreadStates) { | 164 TEST(ScrollAnimatorTest, MainThreadStates) { |
| 153 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 165 MockScrollableArea* scrollableArea = MockScrollableArea::create( |
| 166 true, ScrollOffset(), ScrollOffset(1000, 1000)); |
| 154 ScrollAnimator* scrollAnimator = | 167 ScrollAnimator* scrollAnimator = |
| 155 new ScrollAnimator(scrollableArea, getMockedTime); | 168 new ScrollAnimator(scrollableArea, getMockedTime); |
| 156 | 169 |
| 157 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) | 170 EXPECT_CALL(*scrollableArea, updateScrollOffset(_, _)).Times(2); |
| 158 .Times(AtLeast(1)) | |
| 159 .WillRepeatedly(Return(IntPoint())); | |
| 160 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) | |
| 161 .Times(AtLeast(1)) | |
| 162 .WillRepeatedly(Return(IntPoint(1000, 1000))); | |
| 163 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); | |
| 164 // Once from userScroll, once from updateCompositorAnimations. | 171 // Once from userScroll, once from updateCompositorAnimations. |
| 165 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); | 172 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); |
| 166 EXPECT_CALL(*scrollableArea, scheduleAnimation()) | 173 EXPECT_CALL(*scrollableArea, scheduleAnimation()) |
| 167 .Times(AtLeast(1)) | 174 .Times(AtLeast(1)) |
| 168 .WillRepeatedly(Return(true)); | 175 .WillRepeatedly(Return(true)); |
| 169 | 176 |
| 170 // Idle | 177 // Idle |
| 171 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | 178 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
| 172 EXPECT_EQ(scrollAnimator->m_runState, | 179 EXPECT_EQ(scrollAnimator->m_runState, |
| 173 ScrollAnimatorCompositorCoordinator::RunState::Idle); | 180 ScrollAnimatorCompositorCoordinator::RunState::Idle); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 199 EXPECT_EQ(scrollAnimator->m_runState, | 206 EXPECT_EQ(scrollAnimator->m_runState, |
| 200 ScrollAnimatorCompositorCoordinator::RunState::Idle); | 207 ScrollAnimatorCompositorCoordinator::RunState::Idle); |
| 201 | 208 |
| 202 reset(*scrollAnimator); | 209 reset(*scrollAnimator); |
| 203 | 210 |
| 204 // Forced GC in order to finalize objects depending on the mock object. | 211 // Forced GC in order to finalize objects depending on the mock object. |
| 205 ThreadState::current()->collectAllGarbage(); | 212 ThreadState::current()->collectAllGarbage(); |
| 206 } | 213 } |
| 207 | 214 |
| 208 TEST(ScrollAnimatorTest, MainThreadEnabled) { | 215 TEST(ScrollAnimatorTest, MainThreadEnabled) { |
| 209 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 216 MockScrollableArea* scrollableArea = MockScrollableArea::create( |
| 217 true, ScrollOffset(), ScrollOffset(1000, 1000)); |
| 210 ScrollAnimator* scrollAnimator = | 218 ScrollAnimator* scrollAnimator = |
| 211 new ScrollAnimator(scrollableArea, getMockedTime); | 219 new ScrollAnimator(scrollableArea, getMockedTime); |
| 212 | 220 |
| 213 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) | 221 EXPECT_CALL(*scrollableArea, updateScrollOffset(_, _)).Times(9); |
| 214 .Times(AtLeast(1)) | |
| 215 .WillRepeatedly(Return(IntPoint())); | |
| 216 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) | |
| 217 .Times(AtLeast(1)) | |
| 218 .WillRepeatedly(Return(IntPoint(1000, 1000))); | |
| 219 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(9); | |
| 220 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(6); | 222 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(6); |
| 221 EXPECT_CALL(*scrollableArea, scheduleAnimation()) | 223 EXPECT_CALL(*scrollableArea, scheduleAnimation()) |
| 222 .Times(AtLeast(1)) | 224 .Times(AtLeast(1)) |
| 223 .WillRepeatedly(Return(true)); | 225 .WillRepeatedly(Return(true)); |
| 224 | 226 |
| 225 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | 227 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
| 226 | 228 |
| 227 ScrollResult result = | 229 ScrollResult result = |
| 228 scrollAnimator->userScroll(ScrollByLine, FloatSize(-100, 0)); | 230 scrollAnimator->userScroll(ScrollByLine, FloatSize(-100, 0)); |
| 229 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | 231 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
| 230 EXPECT_FALSE(result.didScrollX); | 232 EXPECT_FALSE(result.didScrollX); |
| 231 EXPECT_FLOAT_EQ(-100.0f, result.unusedScrollDeltaX); | 233 EXPECT_FLOAT_EQ(-100.0f, result.unusedScrollDeltaX); |
| 232 | 234 |
| 233 result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); | 235 result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); |
| 234 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); | 236 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); |
| 235 EXPECT_TRUE(result.didScrollX); | 237 EXPECT_TRUE(result.didScrollX); |
| 236 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); | 238 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); |
| 237 | 239 |
| 238 gMockedTime += 0.05; | 240 gMockedTime += 0.05; |
| 239 scrollAnimator->updateCompositorAnimations(); | 241 scrollAnimator->updateCompositorAnimations(); |
| 240 scrollAnimator->tickAnimation(getMockedTime()); | 242 scrollAnimator->tickAnimation(getMockedTime()); |
| 241 | 243 |
| 242 EXPECT_NE(100, scrollAnimator->currentPosition().x()); | 244 EXPECT_NE(100, scrollAnimator->currentOffset().width()); |
| 243 EXPECT_NE(0, scrollAnimator->currentPosition().x()); | 245 EXPECT_NE(0, scrollAnimator->currentOffset().width()); |
| 244 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 246 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 245 reset(*scrollAnimator); | 247 reset(*scrollAnimator); |
| 246 | 248 |
| 247 scrollAnimator->userScroll(ScrollByPage, FloatSize(100, 0)); | 249 scrollAnimator->userScroll(ScrollByPage, FloatSize(100, 0)); |
| 248 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); | 250 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); |
| 249 | 251 |
| 250 gMockedTime += 0.05; | 252 gMockedTime += 0.05; |
| 251 scrollAnimator->updateCompositorAnimations(); | 253 scrollAnimator->updateCompositorAnimations(); |
| 252 scrollAnimator->tickAnimation(getMockedTime()); | 254 scrollAnimator->tickAnimation(getMockedTime()); |
| 253 | 255 |
| 254 EXPECT_NE(100, scrollAnimator->currentPosition().x()); | 256 EXPECT_NE(100, scrollAnimator->currentOffset().width()); |
| 255 EXPECT_NE(0, scrollAnimator->currentPosition().x()); | 257 EXPECT_NE(0, scrollAnimator->currentOffset().width()); |
| 256 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 258 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 257 reset(*scrollAnimator); | 259 reset(*scrollAnimator); |
| 258 | 260 |
| 259 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0)); | 261 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0)); |
| 260 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); | 262 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); |
| 261 | 263 |
| 262 gMockedTime += 0.05; | 264 gMockedTime += 0.05; |
| 263 scrollAnimator->updateCompositorAnimations(); | 265 scrollAnimator->updateCompositorAnimations(); |
| 264 scrollAnimator->tickAnimation(getMockedTime()); | 266 scrollAnimator->tickAnimation(getMockedTime()); |
| 265 | 267 |
| 266 EXPECT_NE(100, scrollAnimator->currentPosition().x()); | 268 EXPECT_NE(100, scrollAnimator->currentOffset().width()); |
| 267 EXPECT_NE(0, scrollAnimator->currentPosition().x()); | 269 EXPECT_NE(0, scrollAnimator->currentOffset().width()); |
| 268 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 270 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 269 | 271 |
| 270 gMockedTime += 1.0; | 272 gMockedTime += 1.0; |
| 271 scrollAnimator->updateCompositorAnimations(); | 273 scrollAnimator->updateCompositorAnimations(); |
| 272 scrollAnimator->tickAnimation(getMockedTime()); | 274 scrollAnimator->tickAnimation(getMockedTime()); |
| 273 | 275 |
| 274 gMockedTime += 0.05; | 276 gMockedTime += 0.05; |
| 275 scrollAnimator->updateCompositorAnimations(); | 277 scrollAnimator->updateCompositorAnimations(); |
| 276 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | 278 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
| 277 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); | 279 EXPECT_EQ(100, scrollAnimator->currentOffset().width()); |
| 278 | 280 |
| 279 reset(*scrollAnimator); | 281 reset(*scrollAnimator); |
| 280 | 282 |
| 281 scrollAnimator->userScroll(ScrollByPrecisePixel, FloatSize(100, 0)); | 283 scrollAnimator->userScroll(ScrollByPrecisePixel, FloatSize(100, 0)); |
| 282 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | 284 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
| 283 | 285 |
| 284 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); | 286 EXPECT_EQ(100, scrollAnimator->currentOffset().width()); |
| 285 EXPECT_NE(0, scrollAnimator->currentPosition().x()); | 287 EXPECT_NE(0, scrollAnimator->currentOffset().width()); |
| 286 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 288 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 287 reset(*scrollAnimator); | 289 reset(*scrollAnimator); |
| 288 } | 290 } |
| 289 | 291 |
| 290 // Test that a smooth scroll offset animation is aborted when followed by a | 292 // Test that a smooth scroll offset animation is aborted when followed by a |
| 291 // non-smooth scroll offset animation. | 293 // non-smooth scroll offset animation. |
| 292 TEST(ScrollAnimatorTest, AnimatedScrollAborted) { | 294 TEST(ScrollAnimatorTest, AnimatedScrollAborted) { |
| 293 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 295 MockScrollableArea* scrollableArea = MockScrollableArea::create( |
| 296 true, ScrollOffset(), ScrollOffset(1000, 1000)); |
| 294 ScrollAnimator* scrollAnimator = | 297 ScrollAnimator* scrollAnimator = |
| 295 new ScrollAnimator(scrollableArea, getMockedTime); | 298 new ScrollAnimator(scrollableArea, getMockedTime); |
| 296 | 299 |
| 297 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) | 300 EXPECT_CALL(*scrollableArea, updateScrollOffset(_, _)).Times(3); |
| 298 .Times(AtLeast(1)) | |
| 299 .WillRepeatedly(Return(IntPoint())); | |
| 300 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) | |
| 301 .Times(AtLeast(1)) | |
| 302 .WillRepeatedly(Return(IntPoint(1000, 1000))); | |
| 303 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3); | |
| 304 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); | 301 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); |
| 305 EXPECT_CALL(*scrollableArea, scheduleAnimation()) | 302 EXPECT_CALL(*scrollableArea, scheduleAnimation()) |
| 306 .Times(AtLeast(1)) | 303 .Times(AtLeast(1)) |
| 307 .WillRepeatedly(Return(true)); | 304 .WillRepeatedly(Return(true)); |
| 308 | 305 |
| 309 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | 306 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
| 310 | 307 |
| 311 // Smooth scroll. | 308 // Smooth scroll. |
| 312 ScrollResult result = | 309 ScrollResult result = |
| 313 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); | 310 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); |
| 314 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); | 311 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); |
| 315 EXPECT_TRUE(result.didScrollX); | 312 EXPECT_TRUE(result.didScrollX); |
| 316 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); | 313 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); |
| 317 EXPECT_TRUE(scrollAnimator->hasRunningAnimation()); | 314 EXPECT_TRUE(scrollAnimator->hasRunningAnimation()); |
| 318 | 315 |
| 319 gMockedTime += 0.05; | 316 gMockedTime += 0.05; |
| 320 scrollAnimator->updateCompositorAnimations(); | 317 scrollAnimator->updateCompositorAnimations(); |
| 321 scrollAnimator->tickAnimation(getMockedTime()); | 318 scrollAnimator->tickAnimation(getMockedTime()); |
| 322 | 319 |
| 323 EXPECT_NE(100, scrollAnimator->currentPosition().x()); | 320 EXPECT_NE(100, scrollAnimator->currentOffset().width()); |
| 324 EXPECT_NE(0, scrollAnimator->currentPosition().x()); | 321 EXPECT_NE(0, scrollAnimator->currentOffset().width()); |
| 325 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 322 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 326 | 323 |
| 327 float x = scrollAnimator->currentPosition().x(); | 324 float x = scrollAnimator->currentOffset().width(); |
| 328 | 325 |
| 329 // Instant scroll. | 326 // Instant scroll. |
| 330 result = scrollAnimator->userScroll(ScrollByPrecisePixel, FloatSize(100, 0)); | 327 result = scrollAnimator->userScroll(ScrollByPrecisePixel, FloatSize(100, 0)); |
| 331 EXPECT_TRUE(result.didScrollX); | 328 EXPECT_TRUE(result.didScrollX); |
| 332 gMockedTime += 0.05; | 329 gMockedTime += 0.05; |
| 333 scrollAnimator->updateCompositorAnimations(); | 330 scrollAnimator->updateCompositorAnimations(); |
| 334 EXPECT_FALSE(scrollAnimator->hasRunningAnimation()); | 331 EXPECT_FALSE(scrollAnimator->hasRunningAnimation()); |
| 335 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x()); | 332 EXPECT_EQ(x + 100, scrollAnimator->currentOffset().width()); |
| 336 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 333 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 337 | 334 |
| 338 reset(*scrollAnimator); | 335 reset(*scrollAnimator); |
| 339 } | 336 } |
| 340 | 337 |
| 341 // Test that a smooth scroll offset animation running on the compositor is | 338 // Test that a smooth scroll offset animation running on the compositor is |
| 342 // completed on the main thread. | 339 // completed on the main thread. |
| 343 TEST(ScrollAnimatorTest, AnimatedScrollTakeover) { | 340 TEST(ScrollAnimatorTest, AnimatedScrollTakeover) { |
| 344 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 341 MockScrollableArea* scrollableArea = MockScrollableArea::create( |
| 342 true, ScrollOffset(), ScrollOffset(1000, 1000)); |
| 345 TestScrollAnimator* scrollAnimator = | 343 TestScrollAnimator* scrollAnimator = |
| 346 new TestScrollAnimator(scrollableArea, getMockedTime); | 344 new TestScrollAnimator(scrollableArea, getMockedTime); |
| 347 | 345 |
| 348 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) | 346 EXPECT_CALL(*scrollableArea, updateScrollOffset(_, _)).Times(2); |
| 349 .Times(AtLeast(1)) | |
| 350 .WillRepeatedly(Return(IntPoint())); | |
| 351 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) | |
| 352 .Times(AtLeast(1)) | |
| 353 .WillRepeatedly(Return(IntPoint(1000, 1000))); | |
| 354 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); | |
| 355 // Called from userScroll, updateCompositorAnimations, then | 347 // Called from userScroll, updateCompositorAnimations, then |
| 356 // takeOverCompositorAnimation (to re-register after RunningOnCompositor). | 348 // takeOverCompositorAnimation (to re-register after RunningOnCompositor). |
| 357 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); | 349 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); |
| 358 EXPECT_CALL(*scrollableArea, scheduleAnimation()) | 350 EXPECT_CALL(*scrollableArea, scheduleAnimation()) |
| 359 .Times(AtLeast(1)) | 351 .Times(AtLeast(1)) |
| 360 .WillRepeatedly(Return(true)); | 352 .WillRepeatedly(Return(true)); |
| 361 | 353 |
| 362 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | 354 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
| 363 | 355 |
| 364 // Smooth scroll. | 356 // Smooth scroll. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 381 EXPECT_EQ(scrollAnimator->m_runState, | 373 EXPECT_EQ(scrollAnimator->m_runState, |
| 382 ScrollAnimatorCompositorCoordinator::RunState:: | 374 ScrollAnimatorCompositorCoordinator::RunState:: |
| 383 RunningOnCompositorButNeedsTakeover); | 375 RunningOnCompositorButNeedsTakeover); |
| 384 | 376 |
| 385 // Animation should now be running on the main thread. | 377 // Animation should now be running on the main thread. |
| 386 scrollAnimator->setShouldSendToCompositor(false); | 378 scrollAnimator->setShouldSendToCompositor(false); |
| 387 scrollAnimator->updateCompositorAnimations(); | 379 scrollAnimator->updateCompositorAnimations(); |
| 388 EXPECT_EQ(scrollAnimator->m_runState, | 380 EXPECT_EQ(scrollAnimator->m_runState, |
| 389 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); | 381 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); |
| 390 scrollAnimator->tickAnimation(getMockedTime()); | 382 scrollAnimator->tickAnimation(getMockedTime()); |
| 391 EXPECT_NE(100, scrollAnimator->currentPosition().x()); | 383 EXPECT_NE(100, scrollAnimator->currentOffset().width()); |
| 392 EXPECT_NE(0, scrollAnimator->currentPosition().x()); | 384 EXPECT_NE(0, scrollAnimator->currentOffset().width()); |
| 393 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 385 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 394 reset(*scrollAnimator); | 386 reset(*scrollAnimator); |
| 395 } | 387 } |
| 396 | 388 |
| 397 TEST(ScrollAnimatorTest, Disabled) { | 389 TEST(ScrollAnimatorTest, Disabled) { |
| 398 MockScrollableArea* scrollableArea = MockScrollableArea::create(false); | 390 MockScrollableArea* scrollableArea = MockScrollableArea::create( |
| 391 false, ScrollOffset(), ScrollOffset(1000, 1000)); |
| 399 ScrollAnimator* scrollAnimator = | 392 ScrollAnimator* scrollAnimator = |
| 400 new ScrollAnimator(scrollableArea, getMockedTime); | 393 new ScrollAnimator(scrollableArea, getMockedTime); |
| 401 | 394 |
| 402 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) | 395 EXPECT_CALL(*scrollableArea, updateScrollOffset(_, _)).Times(8); |
| 403 .Times(AtLeast(1)) | |
| 404 .WillRepeatedly(Return(IntPoint())); | |
| 405 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) | |
| 406 .Times(AtLeast(1)) | |
| 407 .WillRepeatedly(Return(IntPoint(1000, 1000))); | |
| 408 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8); | |
| 409 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0); | 396 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0); |
| 410 | 397 |
| 411 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); | 398 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); |
| 412 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); | 399 EXPECT_EQ(100, scrollAnimator->currentOffset().width()); |
| 413 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 400 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 414 reset(*scrollAnimator); | 401 reset(*scrollAnimator); |
| 415 | 402 |
| 416 scrollAnimator->userScroll(ScrollByPage, FloatSize(100, 0)); | 403 scrollAnimator->userScroll(ScrollByPage, FloatSize(100, 0)); |
| 417 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); | 404 EXPECT_EQ(100, scrollAnimator->currentOffset().width()); |
| 418 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 405 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 419 reset(*scrollAnimator); | 406 reset(*scrollAnimator); |
| 420 | 407 |
| 421 scrollAnimator->userScroll(ScrollByDocument, FloatSize(100, 0)); | 408 scrollAnimator->userScroll(ScrollByDocument, FloatSize(100, 0)); |
| 422 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); | 409 EXPECT_EQ(100, scrollAnimator->currentOffset().width()); |
| 423 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 410 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 424 reset(*scrollAnimator); | 411 reset(*scrollAnimator); |
| 425 | 412 |
| 426 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0)); | 413 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0)); |
| 427 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); | 414 EXPECT_EQ(100, scrollAnimator->currentOffset().width()); |
| 428 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 415 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 429 reset(*scrollAnimator); | 416 reset(*scrollAnimator); |
| 430 } | 417 } |
| 431 | 418 |
| 432 // Test that cancelling an animation resets the animation state. | 419 // Test that cancelling an animation resets the animation state. |
| 433 // See crbug.com/598548. | 420 // See crbug.com/598548. |
| 434 TEST(ScrollAnimatorTest, CancellingAnimationResetsState) { | 421 TEST(ScrollAnimatorTest, CancellingAnimationResetsState) { |
| 435 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 422 MockScrollableArea* scrollableArea = MockScrollableArea::create( |
| 423 true, ScrollOffset(), ScrollOffset(1000, 1000)); |
| 436 ScrollAnimator* scrollAnimator = | 424 ScrollAnimator* scrollAnimator = |
| 437 new ScrollAnimator(scrollableArea, getMockedTime); | 425 new ScrollAnimator(scrollableArea, getMockedTime); |
| 438 | 426 |
| 439 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) | 427 // Called from first userScroll, setCurrentOffset, and second userScroll. |
| 440 .Times(AtLeast(1)) | 428 EXPECT_CALL(*scrollableArea, updateScrollOffset(_, _)).Times(3); |
| 441 .WillRepeatedly(Return(IntPoint())); | |
| 442 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) | |
| 443 .Times(AtLeast(1)) | |
| 444 .WillRepeatedly(Return(IntPoint(1000, 1000))); | |
| 445 // Called from first userScroll, setCurrentPosition, and second userScroll. | |
| 446 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3); | |
| 447 // Called from userScroll, updateCompositorAnimations. | 429 // Called from userScroll, updateCompositorAnimations. |
| 448 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4); | 430 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4); |
| 449 EXPECT_CALL(*scrollableArea, scheduleAnimation()) | 431 EXPECT_CALL(*scrollableArea, scheduleAnimation()) |
| 450 .Times(AtLeast(1)) | 432 .Times(AtLeast(1)) |
| 451 .WillRepeatedly(Return(true)); | 433 .WillRepeatedly(Return(true)); |
| 452 | 434 |
| 453 EXPECT_EQ(0, scrollAnimator->currentPosition().x()); | 435 EXPECT_EQ(0, scrollAnimator->currentOffset().width()); |
| 454 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 436 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 455 | 437 |
| 456 // WaitingToSendToCompositor | 438 // WaitingToSendToCompositor |
| 457 scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0)); | 439 scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0)); |
| 458 EXPECT_EQ( | 440 EXPECT_EQ( |
| 459 scrollAnimator->m_runState, | 441 scrollAnimator->m_runState, |
| 460 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor); | 442 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor); |
| 461 | 443 |
| 462 // RunningOnMainThread | 444 // RunningOnMainThread |
| 463 gMockedTime += 0.05; | 445 gMockedTime += 0.05; |
| 464 scrollAnimator->updateCompositorAnimations(); | 446 scrollAnimator->updateCompositorAnimations(); |
| 465 EXPECT_EQ(scrollAnimator->m_runState, | 447 EXPECT_EQ(scrollAnimator->m_runState, |
| 466 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); | 448 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); |
| 467 scrollAnimator->tickAnimation(getMockedTime()); | 449 scrollAnimator->tickAnimation(getMockedTime()); |
| 468 EXPECT_EQ(scrollAnimator->m_runState, | 450 EXPECT_EQ(scrollAnimator->m_runState, |
| 469 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); | 451 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); |
| 470 | 452 |
| 471 // Amount scrolled so far. | 453 // Amount scrolled so far. |
| 472 float offsetX = scrollAnimator->currentPosition().x(); | 454 float offsetX = scrollAnimator->currentOffset().width(); |
| 473 | 455 |
| 474 // Interrupt user scroll. | 456 // Interrupt user scroll. |
| 475 scrollAnimator->cancelAnimation(); | 457 scrollAnimator->cancelAnimation(); |
| 476 EXPECT_EQ( | 458 EXPECT_EQ( |
| 477 scrollAnimator->m_runState, | 459 scrollAnimator->m_runState, |
| 478 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); | 460 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); |
| 479 | 461 |
| 480 // Another userScroll after modified scroll offset. | 462 // Another userScroll after modified scroll offset. |
| 481 scrollAnimator->setCurrentPosition(FloatPoint(offsetX + 15, 0)); | 463 scrollAnimator->setCurrentOffset(ScrollOffset(offsetX + 15, 0)); |
| 482 scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0)); | 464 scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0)); |
| 483 EXPECT_EQ( | 465 EXPECT_EQ( |
| 484 scrollAnimator->m_runState, | 466 scrollAnimator->m_runState, |
| 485 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor); | 467 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor); |
| 486 | 468 |
| 487 // Finish scroll animation. | 469 // Finish scroll animation. |
| 488 gMockedTime += 1.0; | 470 gMockedTime += 1.0; |
| 489 scrollAnimator->updateCompositorAnimations(); | 471 scrollAnimator->updateCompositorAnimations(); |
| 490 scrollAnimator->tickAnimation(getMockedTime()); | 472 scrollAnimator->tickAnimation(getMockedTime()); |
| 491 EXPECT_EQ( | 473 EXPECT_EQ( |
| 492 scrollAnimator->m_runState, | 474 scrollAnimator->m_runState, |
| 493 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); | 475 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); |
| 494 | 476 |
| 495 EXPECT_EQ(offsetX + 15 + 10, scrollAnimator->currentPosition().x()); | 477 EXPECT_EQ(offsetX + 15 + 10, scrollAnimator->currentOffset().width()); |
| 496 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 478 EXPECT_EQ(0, scrollAnimator->currentOffset().height()); |
| 497 reset(*scrollAnimator); | 479 reset(*scrollAnimator); |
| 498 } | 480 } |
| 499 | 481 |
| 500 // Test the behavior when in WaitingToCancelOnCompositor and a new user scroll | 482 // Test the behavior when in WaitingToCancelOnCompositor and a new user scroll |
| 501 // happens. | 483 // happens. |
| 502 TEST(ScrollAnimatorTest, CancellingCompositorAnimation) { | 484 TEST(ScrollAnimatorTest, CancellingCompositorAnimation) { |
| 503 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 485 MockScrollableArea* scrollableArea = MockScrollableArea::create( |
| 486 true, ScrollOffset(), ScrollOffset(1000, 1000)); |
| 504 TestScrollAnimator* scrollAnimator = | 487 TestScrollAnimator* scrollAnimator = |
| 505 new TestScrollAnimator(scrollableArea, getMockedTime); | 488 new TestScrollAnimator(scrollableArea, getMockedTime); |
| 506 | 489 |
| 507 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) | |
| 508 .Times(AtLeast(1)) | |
| 509 .WillRepeatedly(Return(IntPoint())); | |
| 510 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) | |
| 511 .Times(AtLeast(1)) | |
| 512 .WillRepeatedly(Return(IntPoint(1000, 1000))); | |
| 513 // Called when reset, not setting anywhere else. | 490 // Called when reset, not setting anywhere else. |
| 514 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(1); | 491 EXPECT_CALL(*scrollableArea, updateScrollOffset(_, _)).Times(1); |
| 515 // Called from userScroll, and first update. | 492 // Called from userScroll, and first update. |
| 516 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4); | 493 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4); |
| 517 EXPECT_CALL(*scrollableArea, scheduleAnimation()) | 494 EXPECT_CALL(*scrollableArea, scheduleAnimation()) |
| 518 .Times(AtLeast(1)) | 495 .Times(AtLeast(1)) |
| 519 .WillRepeatedly(Return(true)); | 496 .WillRepeatedly(Return(true)); |
| 520 | 497 |
| 521 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | 498 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
| 522 | 499 |
| 523 // First user scroll. | 500 // First user scroll. |
| 524 ScrollResult result = | 501 ScrollResult result = |
| 525 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); | 502 scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); |
| 526 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); | 503 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); |
| 527 EXPECT_TRUE(result.didScrollX); | 504 EXPECT_TRUE(result.didScrollX); |
| 528 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); | 505 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); |
| 529 EXPECT_TRUE(scrollAnimator->hasRunningAnimation()); | 506 EXPECT_TRUE(scrollAnimator->hasRunningAnimation()); |
| 530 EXPECT_EQ(100, scrollAnimator->desiredTargetPosition().x()); | 507 EXPECT_EQ(100, scrollAnimator->desiredTargetOffset().width()); |
| 531 EXPECT_EQ(0, scrollAnimator->desiredTargetPosition().y()); | 508 EXPECT_EQ(0, scrollAnimator->desiredTargetOffset().height()); |
| 532 | 509 |
| 533 // Update compositor animation. | 510 // Update compositor animation. |
| 534 gMockedTime += 0.05; | 511 gMockedTime += 0.05; |
| 535 scrollAnimator->setShouldSendToCompositor(true); | 512 scrollAnimator->setShouldSendToCompositor(true); |
| 536 scrollAnimator->updateCompositorAnimations(); | 513 scrollAnimator->updateCompositorAnimations(); |
| 537 EXPECT_EQ(scrollAnimator->m_runState, | 514 EXPECT_EQ(scrollAnimator->m_runState, |
| 538 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositor); | 515 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositor); |
| 539 | 516 |
| 540 // Cancel | 517 // Cancel |
| 541 scrollAnimator->cancelAnimation(); | 518 scrollAnimator->cancelAnimation(); |
| 542 EXPECT_EQ(scrollAnimator->m_runState, | 519 EXPECT_EQ(scrollAnimator->m_runState, |
| 543 ScrollAnimatorCompositorCoordinator::RunState:: | 520 ScrollAnimatorCompositorCoordinator::RunState:: |
| 544 WaitingToCancelOnCompositor); | 521 WaitingToCancelOnCompositor); |
| 545 | 522 |
| 546 // Unrelated scroll position update. | 523 // Unrelated scroll offset update. |
| 547 scrollAnimator->setCurrentPosition(FloatPoint(50, 0)); | 524 scrollAnimator->setCurrentOffset(ScrollOffset(50, 0)); |
| 548 | 525 |
| 549 // Desired target position should be that of the second scroll. | 526 // Desired target offset should be that of the second scroll. |
| 550 result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); | 527 result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); |
| 551 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); | 528 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); |
| 552 EXPECT_TRUE(result.didScrollX); | 529 EXPECT_TRUE(result.didScrollX); |
| 553 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); | 530 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); |
| 554 EXPECT_EQ(scrollAnimator->m_runState, | 531 EXPECT_EQ(scrollAnimator->m_runState, |
| 555 ScrollAnimatorCompositorCoordinator::RunState:: | 532 ScrollAnimatorCompositorCoordinator::RunState:: |
| 556 WaitingToCancelOnCompositorButNewScroll); | 533 WaitingToCancelOnCompositorButNewScroll); |
| 557 EXPECT_EQ(150, scrollAnimator->desiredTargetPosition().x()); | 534 EXPECT_EQ(150, scrollAnimator->desiredTargetOffset().width()); |
| 558 EXPECT_EQ(0, scrollAnimator->desiredTargetPosition().y()); | 535 EXPECT_EQ(0, scrollAnimator->desiredTargetOffset().height()); |
| 559 | 536 |
| 560 // Update compositor animation. | 537 // Update compositor animation. |
| 561 gMockedTime += 0.05; | 538 gMockedTime += 0.05; |
| 562 scrollAnimator->updateCompositorAnimations(); | 539 scrollAnimator->updateCompositorAnimations(); |
| 563 EXPECT_EQ(scrollAnimator->m_runState, | 540 EXPECT_EQ(scrollAnimator->m_runState, |
| 564 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositor); | 541 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositor); |
| 565 | 542 |
| 566 // Third user scroll after compositor update updates the target. | 543 // Third user scroll after compositor update updates the target. |
| 567 result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); | 544 result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); |
| 568 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); | 545 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); |
| 569 EXPECT_TRUE(result.didScrollX); | 546 EXPECT_TRUE(result.didScrollX); |
| 570 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); | 547 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); |
| 571 EXPECT_EQ(scrollAnimator->m_runState, | 548 EXPECT_EQ(scrollAnimator->m_runState, |
| 572 ScrollAnimatorCompositorCoordinator::RunState:: | 549 ScrollAnimatorCompositorCoordinator::RunState:: |
| 573 RunningOnCompositorButNeedsUpdate); | 550 RunningOnCompositorButNeedsUpdate); |
| 574 EXPECT_EQ(250, scrollAnimator->desiredTargetPosition().x()); | 551 EXPECT_EQ(250, scrollAnimator->desiredTargetOffset().width()); |
| 575 EXPECT_EQ(0, scrollAnimator->desiredTargetPosition().y()); | 552 EXPECT_EQ(0, scrollAnimator->desiredTargetOffset().height()); |
| 576 reset(*scrollAnimator); | 553 reset(*scrollAnimator); |
| 577 | 554 |
| 578 // Forced GC in order to finalize objects depending on the mock object. | 555 // Forced GC in order to finalize objects depending on the mock object. |
| 579 ThreadState::current()->collectAllGarbage(); | 556 ThreadState::current()->collectAllGarbage(); |
| 580 } | 557 } |
| 581 | 558 |
| 582 // This test verifies that impl only animation updates get cleared once they | 559 // This test verifies that impl only animation updates get cleared once they |
| 583 // are pushed to compositor animation host. | 560 // are pushed to compositor animation host. |
| 584 TEST(ScrollAnimatorTest, ImplOnlyAnimationUpdatesCleared) { | 561 TEST(ScrollAnimatorTest, ImplOnlyAnimationUpdatesCleared) { |
| 585 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 562 MockScrollableArea* scrollableArea = MockScrollableArea::create( |
| 563 true, ScrollOffset(), ScrollOffset(1000, 1000)); |
| 586 TestScrollAnimator* animator = | 564 TestScrollAnimator* animator = |
| 587 new TestScrollAnimator(scrollableArea, getMockedTime); | 565 new TestScrollAnimator(scrollableArea, getMockedTime); |
| 588 | 566 |
| 589 // From calls to adjust/takeoverImplOnlyScrollOffsetAnimation. | 567 // From calls to adjust/takeoverImplOnlyScrollOffsetAnimation. |
| 590 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); | 568 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); |
| 591 | 569 |
| 592 // Verify that the adjustment update is cleared. | 570 // Verify that the adjustment update is cleared. |
| 593 EXPECT_EQ(animator->m_runState, | 571 EXPECT_EQ(animator->m_runState, |
| 594 ScrollAnimatorCompositorCoordinator::RunState::Idle); | 572 ScrollAnimatorCompositorCoordinator::RunState::Idle); |
| 595 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); | 573 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 611 | 589 |
| 612 // Verify that the takeover update is cleared. | 590 // Verify that the takeover update is cleared. |
| 613 animator->takeOverImplOnlyScrollOffsetAnimation(); | 591 animator->takeOverImplOnlyScrollOffsetAnimation(); |
| 614 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); | 592 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); |
| 615 | 593 |
| 616 // Forced GC in order to finalize objects depending on the mock object. | 594 // Forced GC in order to finalize objects depending on the mock object. |
| 617 ThreadState::current()->collectAllGarbage(); | 595 ThreadState::current()->collectAllGarbage(); |
| 618 } | 596 } |
| 619 | 597 |
| 620 TEST(ScrollAnimatorTest, MainThreadAnimationTargetAdjustment) { | 598 TEST(ScrollAnimatorTest, MainThreadAnimationTargetAdjustment) { |
| 621 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 599 MockScrollableArea* scrollableArea = MockScrollableArea::create( |
| 600 true, ScrollOffset(-100, -100), ScrollOffset(1000, 1000)); |
| 622 ScrollAnimator* animator = new ScrollAnimator(scrollableArea, getMockedTime); | 601 ScrollAnimator* animator = new ScrollAnimator(scrollableArea, getMockedTime); |
| 623 scrollableArea->setScrollAnimator(animator); | 602 scrollableArea->setScrollAnimator(animator); |
| 624 | 603 |
| 625 EXPECT_CALL(*scrollableArea, minimumScrollPosition()) | |
| 626 .Times(AtLeast(1)) | |
| 627 .WillRepeatedly(Return(IntPoint(-100, -100))); | |
| 628 EXPECT_CALL(*scrollableArea, maximumScrollPosition()) | |
| 629 .Times(AtLeast(1)) | |
| 630 .WillRepeatedly(Return(IntPoint(1000, 1000))); | |
| 631 // Twice from tickAnimation, once from reset, and twice from | 604 // Twice from tickAnimation, once from reset, and twice from |
| 632 // adjustAnimationAndSetScrollPosition. | 605 // adjustAnimationAndSetScrollOffset. |
| 633 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(5); | 606 EXPECT_CALL(*scrollableArea, updateScrollOffset(_, _)).Times(5); |
| 634 // One from call to userScroll and one from updateCompositorAnimations. | 607 // One from call to userScroll and one from updateCompositorAnimations. |
| 635 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); | 608 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); |
| 636 EXPECT_CALL(*scrollableArea, scheduleAnimation()) | 609 EXPECT_CALL(*scrollableArea, scheduleAnimation()) |
| 637 .Times(AtLeast(1)) | 610 .Times(AtLeast(1)) |
| 638 .WillRepeatedly(Return(true)); | 611 .WillRepeatedly(Return(true)); |
| 639 | 612 |
| 640 // Idle | 613 // Idle |
| 641 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); | 614 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); |
| 642 EXPECT_EQ(FloatPoint(), animator->currentPosition()); | 615 EXPECT_EQ(ScrollOffset(), animator->currentOffset()); |
| 643 | 616 |
| 644 // WaitingToSendToCompositor | 617 // WaitingToSendToCompositor |
| 645 animator->userScroll(ScrollByLine, FloatSize(100, 100)); | 618 animator->userScroll(ScrollByLine, ScrollOffset(100, 100)); |
| 646 | 619 |
| 647 // RunningOnMainThread | 620 // RunningOnMainThread |
| 648 gMockedTime += 0.05; | 621 gMockedTime += 0.05; |
| 649 animator->updateCompositorAnimations(); | 622 animator->updateCompositorAnimations(); |
| 650 animator->tickAnimation(getMockedTime()); | 623 animator->tickAnimation(getMockedTime()); |
| 651 FloatPoint pos = animator->currentPosition(); | 624 ScrollOffset offset = animator->currentOffset(); |
| 652 EXPECT_EQ(FloatPoint(100, 100), animator->desiredTargetPosition()); | 625 EXPECT_EQ(ScrollOffset(100, 100), animator->desiredTargetOffset()); |
| 653 EXPECT_GT(pos.x(), 0); | 626 EXPECT_GT(offset.width(), 0); |
| 654 EXPECT_GT(pos.y(), 0); | 627 EXPECT_GT(offset.height(), 0); |
| 655 | 628 |
| 656 // Adjustment | 629 // Adjustment |
| 657 FloatPoint newPos = pos + FloatSize(10, -10); | 630 ScrollOffset newOffset = offset + ScrollOffset(10, -10); |
| 658 animator->adjustAnimationAndSetScrollPosition(newPos, AnchoringScroll); | 631 animator->adjustAnimationAndSetScrollOffset(newOffset, AnchoringScroll); |
| 659 EXPECT_EQ(FloatPoint(110, 90), animator->desiredTargetPosition()); | 632 EXPECT_EQ(ScrollOffset(110, 90), animator->desiredTargetOffset()); |
| 660 | 633 |
| 661 // Adjusting after finished animation should do nothing. | 634 // Adjusting after finished animation should do nothing. |
| 662 gMockedTime += 1.0; | 635 gMockedTime += 1.0; |
| 663 animator->updateCompositorAnimations(); | 636 animator->updateCompositorAnimations(); |
| 664 animator->tickAnimation(getMockedTime()); | 637 animator->tickAnimation(getMockedTime()); |
| 665 EXPECT_EQ( | 638 EXPECT_EQ( |
| 666 animator->runStateForTesting(), | 639 animator->runStateForTesting(), |
| 667 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); | 640 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); |
| 668 newPos = animator->currentPosition() + FloatSize(10, -10); | 641 newOffset = animator->currentOffset() + ScrollOffset(10, -10); |
| 669 animator->adjustAnimationAndSetScrollPosition(newPos, AnchoringScroll); | 642 animator->adjustAnimationAndSetScrollOffset(newOffset, AnchoringScroll); |
| 670 EXPECT_EQ( | 643 EXPECT_EQ( |
| 671 animator->runStateForTesting(), | 644 animator->runStateForTesting(), |
| 672 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); | 645 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); |
| 673 EXPECT_EQ(FloatPoint(110, 90), animator->desiredTargetPosition()); | 646 EXPECT_EQ(ScrollOffset(110, 90), animator->desiredTargetOffset()); |
| 674 | 647 |
| 675 reset(*animator); | 648 reset(*animator); |
| 676 | 649 |
| 677 // Forced GC in order to finalize objects depending on the mock object. | 650 // Forced GC in order to finalize objects depending on the mock object. |
| 678 ThreadState::current()->collectAllGarbage(); | 651 ThreadState::current()->collectAllGarbage(); |
| 679 } | 652 } |
| 680 | 653 |
| 681 } // namespace blink | 654 } // namespace blink |
| OLD | NEW |