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