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