| 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 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 TEST(ScrollAnimatorTest, MainThreadAnimationTargetAdjustment) | 594 TEST(ScrollAnimatorTest, MainThreadAnimationTargetAdjustment) |
| 595 { | 595 { |
| 596 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); | 596 MockScrollableArea* scrollableArea = MockScrollableArea::create(true); |
| 597 ScrollAnimator* animator = new ScrollAnimator(scrollableArea, getMockedTime)
; | 597 ScrollAnimator* animator = new ScrollAnimator(scrollableArea, getMockedTime)
; |
| 598 scrollableArea->setScrollAnimator(animator); | 598 scrollableArea->setScrollAnimator(animator); |
| 599 | 599 |
| 600 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) | 600 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) |
| 601 .WillRepeatedly(Return(IntPoint(-100, -100))); | 601 .WillRepeatedly(Return(IntPoint(-100, -100))); |
| 602 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) | 602 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) |
| 603 .WillRepeatedly(Return(IntPoint(1000, 1000))); | 603 .WillRepeatedly(Return(IntPoint(1000, 1000))); |
| 604 // Twice from tickAnimation, once from reset, and once from | 604 // Twice from tickAnimation, once from reset, and twice from |
| 605 // adjustAnimationAndSetScrollPosition. | 605 // adjustAnimationAndSetScrollPosition. |
| 606 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(4); | 606 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(5); |
| 607 // One from call to userScroll and one from updateCompositorAnimations. | 607 // One from call to userScroll and one from updateCompositorAnimations. |
| 608 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); | 608 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(2); |
| 609 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) | 609 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) |
| 610 .WillRepeatedly(Return(true)); | 610 .WillRepeatedly(Return(true)); |
| 611 | 611 |
| 612 // Idle | 612 // Idle |
| 613 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); | 613 EXPECT_FALSE(animator->hasAnimationThatRequiresService()); |
| 614 EXPECT_EQ(FloatPoint(), animator->currentPosition()); | 614 EXPECT_EQ(FloatPoint(), animator->currentPosition()); |
| 615 | 615 |
| 616 // WaitingToSendToCompositor | 616 // WaitingToSendToCompositor |
| 617 animator->userScroll(ScrollByLine, FloatSize(100, 100)); | 617 animator->userScroll(ScrollByLine, FloatSize(100, 100)); |
| 618 | 618 |
| 619 // RunningOnMainThread | 619 // RunningOnMainThread |
| 620 gMockedTime += 0.05; | 620 gMockedTime += 0.05; |
| 621 animator->updateCompositorAnimations(); | 621 animator->updateCompositorAnimations(); |
| 622 animator->tickAnimation(getMockedTime()); | 622 animator->tickAnimation(getMockedTime()); |
| 623 FloatPoint pos = animator->currentPosition(); | 623 FloatPoint pos = animator->currentPosition(); |
| 624 EXPECT_EQ(FloatPoint(100, 100), animator->desiredTargetPosition()); | 624 EXPECT_EQ(FloatPoint(100, 100), animator->desiredTargetPosition()); |
| 625 EXPECT_GT(pos.x(), 0); | 625 EXPECT_GT(pos.x(), 0); |
| 626 EXPECT_GT(pos.y(), 0); | 626 EXPECT_GT(pos.y(), 0); |
| 627 | 627 |
| 628 // Adjustment | 628 // Adjustment |
| 629 FloatPoint newPos = pos + FloatSize(10, -10); | 629 FloatPoint newPos = pos + FloatSize(10, -10); |
| 630 animator->adjustAnimationAndSetScrollPosition(newPos, AnchoringScroll); | 630 animator->adjustAnimationAndSetScrollPosition(newPos, AnchoringScroll); |
| 631 EXPECT_EQ(FloatPoint(110, 90), animator->desiredTargetPosition()); | 631 EXPECT_EQ(FloatPoint(110, 90), animator->desiredTargetPosition()); |
| 632 | 632 |
| 633 // Animation finished | 633 // Adjusting after finished animation should do nothing. |
| 634 gMockedTime += 1.0; | 634 gMockedTime += 1.0; |
| 635 animator->updateCompositorAnimations(); | 635 animator->updateCompositorAnimations(); |
| 636 animator->tickAnimation(getMockedTime()); | 636 animator->tickAnimation(getMockedTime()); |
| 637 EXPECT_EQ(FloatPoint(110, 90), animator->currentPosition()); | 637 EXPECT_EQ(animator->runStateForTesting(), |
| 638 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); |
| 639 newPos = animator->currentPosition() + FloatSize(10, -10); |
| 640 animator->adjustAnimationAndSetScrollPosition(newPos, AnchoringScroll); |
| 641 EXPECT_EQ(animator->runStateForTesting(), |
| 642 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); |
| 643 EXPECT_EQ(FloatPoint(110, 90), animator->desiredTargetPosition()); |
| 644 |
| 638 reset(*animator); | 645 reset(*animator); |
| 639 | 646 |
| 640 // Forced GC in order to finalize objects depending on the mock object. | 647 // Forced GC in order to finalize objects depending on the mock object. |
| 641 ThreadState::current()-> collectAllGarbage(); | 648 ThreadState::current()-> collectAllGarbage(); |
| 642 } | 649 } |
| 643 | 650 |
| 644 } // namespace blink | 651 } // namespace blink |
| OLD | NEW |