| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 ScrollableArea::trace(visitor); | 87 ScrollableArea::trace(visitor); |
| 88 } | 88 } |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 explicit MockScrollableArea(bool scrollAnimatorEnabled) | 91 explicit MockScrollableArea(bool scrollAnimatorEnabled) |
| 92 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } | 92 : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } |
| 93 | 93 |
| 94 bool m_scrollAnimatorEnabled; | 94 bool m_scrollAnimatorEnabled; |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 class TestScrollAnimator : public ScrollAnimator { | |
| 98 public: | |
| 99 TestScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction timingF
unction) | |
| 100 : ScrollAnimator(scrollableArea, timingFunction) {}; | |
| 101 ~TestScrollAnimator() override {}; | |
| 102 | |
| 103 void setShouldSendToCompositor(bool send) | |
| 104 { | |
| 105 m_shouldSendToCompositor = send; | |
| 106 } | |
| 107 | |
| 108 bool sendAnimationToCompositor() override | |
| 109 { | |
| 110 if (m_shouldSendToCompositor) { | |
| 111 m_runState = ScrollAnimatorCompositorCoordinator::RunState::RunningO
nCompositor; | |
| 112 m_compositorAnimationId = 1; | |
| 113 return true; | |
| 114 } | |
| 115 return false; | |
| 116 } | |
| 117 | |
| 118 protected: | |
| 119 void abortAnimation() override {} | |
| 120 | |
| 121 private: | |
| 122 bool m_shouldSendToCompositor = false; | |
| 123 }; | |
| 124 | |
| 125 } // namespace | 97 } // namespace |
| 126 | 98 |
| 127 static void reset(ScrollAnimator& scrollAnimator) | 99 static void reset(ScrollAnimator& scrollAnimator) |
| 128 { | 100 { |
| 129 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint()); | 101 scrollAnimator.scrollToOffsetWithoutAnimation(FloatPoint()); |
| 130 } | 102 } |
| 131 | 103 |
| 132 // TODO(skobes): Add unit tests for composited scrolling paths. | 104 // TODO(skobes): Add unit tests for composited scrolling paths. |
| 133 | 105 |
| 134 TEST(ScrollAnimatorTest, MainThreadStates) | 106 TEST(ScrollAnimatorTest, MainThreadStates) |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 EXPECT_TRUE(result.didScroll); | 271 EXPECT_TRUE(result.didScroll); |
| 300 gMockedTime += 0.05; | 272 gMockedTime += 0.05; |
| 301 scrollAnimator->updateCompositorAnimations(); | 273 scrollAnimator->updateCompositorAnimations(); |
| 302 EXPECT_FALSE(scrollAnimator->hasRunningAnimation()); | 274 EXPECT_FALSE(scrollAnimator->hasRunningAnimation()); |
| 303 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x()); | 275 EXPECT_EQ(x + 100, scrollAnimator->currentPosition().x()); |
| 304 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 276 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); |
| 305 | 277 |
| 306 reset(*scrollAnimator); | 278 reset(*scrollAnimator); |
| 307 } | 279 } |
| 308 | 280 |
| 309 // Test that a smooth scroll offset animation running on the compositor is | |
| 310 // completed on the main thread. | |
| 311 TEST(ScrollAnimatorTest, AnimatedScrollTakeover) | |
| 312 { | |
| 313 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = | |
| 314 MockScrollableArea::create(true); | |
| 315 OwnPtrWillBeRawPtr<TestScrollAnimator> scrollAnimator = adoptPtrWillBeNoop( | |
| 316 new TestScrollAnimator(scrollableArea.get(), getMockedTime)); | |
| 317 | |
| 318 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) | |
| 319 .WillRepeatedly(Return(IntPoint())); | |
| 320 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) | |
| 321 .WillRepeatedly(Return(IntPoint(1000, 1000))); | |
| 322 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(2); | |
| 323 // Called from userScroll, updateCompositorAnimations, then | |
| 324 // takeoverCompositorAnimation (to re-register after RunningOnCompositor). | |
| 325 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); | |
| 326 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) | |
| 327 .WillRepeatedly(Return(true)); | |
| 328 | |
| 329 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); | |
| 330 | |
| 331 // Smooth scroll. | |
| 332 ScrollResult result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100
, 0)); | |
| 333 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); | |
| 334 EXPECT_TRUE(result.didScrollX); | |
| 335 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); | |
| 336 EXPECT_TRUE(scrollAnimator->hasRunningAnimation()); | |
| 337 | |
| 338 // Update compositor animation. | |
| 339 gMockedTime += 0.05; | |
| 340 scrollAnimator->setShouldSendToCompositor(true); | |
| 341 scrollAnimator->updateCompositorAnimations(); | |
| 342 EXPECT_EQ(scrollAnimator->m_runState, | |
| 343 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositor); | |
| 344 | |
| 345 // Takeover. | |
| 346 scrollAnimator->takeoverCompositorAnimation(); | |
| 347 EXPECT_EQ(scrollAnimator->m_runState, | |
| 348 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositorButNee
dsTakeover); | |
| 349 | |
| 350 // Animation should now be running on the main thread. | |
| 351 scrollAnimator->setShouldSendToCompositor(false); | |
| 352 scrollAnimator->updateCompositorAnimations(); | |
| 353 EXPECT_EQ(scrollAnimator->m_runState, | |
| 354 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); | |
| 355 scrollAnimator->tickAnimation(getMockedTime()); | |
| 356 EXPECT_NE(100, scrollAnimator->currentPosition().x()); | |
| 357 EXPECT_NE(0, scrollAnimator->currentPosition().x()); | |
| 358 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | |
| 359 reset(*scrollAnimator); | |
| 360 } | |
| 361 | |
| 362 TEST(ScrollAnimatorTest, Disabled) | 281 TEST(ScrollAnimatorTest, Disabled) |
| 363 { | 282 { |
| 364 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::
create(false); | 283 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::
create(false); |
| 365 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S
crollAnimator(scrollableArea.get(), getMockedTime)); | 284 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new S
crollAnimator(scrollableArea.get(), getMockedTime)); |
| 366 | 285 |
| 367 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint())); | 286 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint())); |
| 368 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint(1000, 1000))); | 287 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)).Will
Repeatedly(Return(IntPoint(1000, 1000))); |
| 369 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8); | 288 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(8); |
| 370 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0); | 289 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(0); |
| 371 | 290 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 384 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 303 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); |
| 385 reset(*scrollAnimator); | 304 reset(*scrollAnimator); |
| 386 | 305 |
| 387 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPixel, 100, 1); | 306 scrollAnimator->userScroll(HorizontalScrollbar, ScrollByPixel, 100, 1); |
| 388 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); | 307 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); |
| 389 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 308 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); |
| 390 reset(*scrollAnimator); | 309 reset(*scrollAnimator); |
| 391 } | 310 } |
| 392 | 311 |
| 393 } // namespace blink | 312 } // namespace blink |
| OLD | NEW |