| 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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 scrollAnimator->updateCompositorAnimations(); | 437 scrollAnimator->updateCompositorAnimations(); |
| 438 scrollAnimator->tickAnimation(getMockedTime()); | 438 scrollAnimator->tickAnimation(getMockedTime()); |
| 439 EXPECT_EQ(scrollAnimator->m_runState, | 439 EXPECT_EQ(scrollAnimator->m_runState, |
| 440 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); | 440 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); |
| 441 | 441 |
| 442 EXPECT_EQ(offsetX + 15 + 10, scrollAnimator->currentPosition().x()); | 442 EXPECT_EQ(offsetX + 15 + 10, scrollAnimator->currentPosition().x()); |
| 443 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 443 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); |
| 444 reset(*scrollAnimator); | 444 reset(*scrollAnimator); |
| 445 } | 445 } |
| 446 | 446 |
| 447 // Test the behavior when in WaitingToCancelOnCompositor and a new user scroll |
| 448 // happens. |
| 449 TEST(ScrollAnimatorTest, CancellingCompositorAnimation) |
| 450 { |
| 451 RawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::create(true)
; |
| 452 RawPtr<TestScrollAnimator> scrollAnimator = adoptPtrWillBeNoop(new TestScrol
lAnimator(scrollableArea.get(), getMockedTime)); |
| 453 |
| 454 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) |
| 455 .WillRepeatedly(Return(IntPoint())); |
| 456 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) |
| 457 .WillRepeatedly(Return(IntPoint(1000, 1000))); |
| 458 // Called when reset, not setting anywhere else. |
| 459 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(1); |
| 460 // Called from first and last user scroll, and first update. |
| 461 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(3); |
| 462 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) |
| 463 .WillRepeatedly(Return(true)); |
| 464 |
| 465 EXPECT_FALSE(scrollAnimator->hasAnimationThatRequiresService()); |
| 466 |
| 467 // First user scroll. |
| 468 ScrollResult result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100
, 0)); |
| 469 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); |
| 470 EXPECT_TRUE(result.didScrollX); |
| 471 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); |
| 472 EXPECT_TRUE(scrollAnimator->hasRunningAnimation()); |
| 473 EXPECT_EQ(100, scrollAnimator->desiredTargetPosition().x()); |
| 474 EXPECT_EQ(0, scrollAnimator->desiredTargetPosition().y()); |
| 475 |
| 476 // Update compositor animation. |
| 477 gMockedTime += 0.05; |
| 478 scrollAnimator->setShouldSendToCompositor(true); |
| 479 scrollAnimator->updateCompositorAnimations(); |
| 480 EXPECT_EQ(scrollAnimator->m_runState, |
| 481 ScrollAnimatorCompositorCoordinator::RunState::RunningOnCompositor); |
| 482 |
| 483 // Cancel |
| 484 scrollAnimator->cancelAnimation(); |
| 485 EXPECT_EQ(scrollAnimator->m_runState, |
| 486 ScrollAnimatorCompositorCoordinator::RunState::WaitingToCancelOnComposit
or); |
| 487 |
| 488 // Second user scroll should not affect the run state. |
| 489 result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); |
| 490 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); |
| 491 EXPECT_TRUE(result.didScrollX); |
| 492 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); |
| 493 EXPECT_EQ(scrollAnimator->m_runState, |
| 494 ScrollAnimatorCompositorCoordinator::RunState::WaitingToCancelOnComposit
or); |
| 495 // Desired target position is what it was before. |
| 496 EXPECT_EQ(100, scrollAnimator->desiredTargetPosition().x()); |
| 497 EXPECT_EQ(0, scrollAnimator->desiredTargetPosition().y()); |
| 498 |
| 499 // Update compositor animation. |
| 500 gMockedTime += 0.05; |
| 501 scrollAnimator->updateCompositorAnimations(); |
| 502 EXPECT_EQ(scrollAnimator->m_runState, |
| 503 ScrollAnimatorCompositorCoordinator::RunState::Idle); |
| 504 |
| 505 // Third user scroll after compositor update is treated like a new scroll. |
| 506 result = scrollAnimator->userScroll(ScrollByLine, FloatSize(100, 0)); |
| 507 EXPECT_TRUE(scrollAnimator->hasAnimationThatRequiresService()); |
| 508 EXPECT_TRUE(result.didScrollX); |
| 509 EXPECT_FLOAT_EQ(0.0, result.unusedScrollDeltaX); |
| 510 EXPECT_EQ(scrollAnimator->m_runState, |
| 511 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor
); |
| 512 EXPECT_EQ(100, scrollAnimator->desiredTargetPosition().x()); |
| 513 EXPECT_EQ(0, scrollAnimator->desiredTargetPosition().y()); |
| 514 reset(*scrollAnimator); |
| 515 |
| 516 // Forced GC in order to finalize objects depending on the mock object. |
| 517 Heap::collectAllGarbage(); |
| 518 } |
| 519 |
| 447 } // namespace blink | 520 } // namespace blink |
| OLD | NEW |