| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 startTimeline(); | 53 startTimeline(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void setUpWithoutStartingTimeline() | 56 void setUpWithoutStartingTimeline() |
| 57 { | 57 { |
| 58 document = Document::create(); | 58 document = Document::create(); |
| 59 document->animationClock().resetTimeForTesting(); | 59 document->animationClock().resetTimeForTesting(); |
| 60 timeline = AnimationTimeline::create(document.get()); | 60 timeline = AnimationTimeline::create(document.get()); |
| 61 player = timeline->play(0); | 61 player = timeline->play(0); |
| 62 player->setStartTime(0); | 62 player->setStartTime(0); |
| 63 player->setSource(makeAnimation().get()); | 63 player->setSource(makeAnimation()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void startTimeline() | 66 void startTimeline() |
| 67 { | 67 { |
| 68 simulateFrame(0); | 68 simulateFrame(0); |
| 69 } | 69 } |
| 70 | 70 |
| 71 PassRefPtrWillBeRawPtr<Animation> makeAnimation(double duration = 30, double
playbackRate = 1) | 71 Animation* makeAnimation(double duration = 30, double playbackRate = 1) |
| 72 { | 72 { |
| 73 Timing timing; | 73 Timing timing; |
| 74 timing.iterationDuration = duration; | 74 timing.iterationDuration = duration; |
| 75 timing.playbackRate = playbackRate; | 75 timing.playbackRate = playbackRate; |
| 76 return Animation::create(0, nullptr, timing); | 76 return Animation::create(0, nullptr, timing); |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool simulateFrame(double time) | 79 bool simulateFrame(double time) |
| 80 { | 80 { |
| 81 document->animationClock().updateTime(time); | 81 document->animationClock().updateTime(time); |
| 82 document->compositorPendingAnimations().update(false); | 82 document->compositorPendingAnimations().update(false); |
| 83 // The timeline does not know about our player, so we have to explicitly
call update(). | 83 // The timeline does not know about our player, so we have to explicitly
call update(). |
| 84 return player->update(TimingUpdateForAnimationFrame); | 84 return player->update(TimingUpdateForAnimationFrame); |
| 85 } | 85 } |
| 86 | 86 |
| 87 RefPtrWillBePersistent<Document> document; | 87 RefPtrWillBePersistent<Document> document; |
| 88 RefPtrWillBePersistent<AnimationTimeline> timeline; | 88 Persistent<AnimationTimeline> timeline; |
| 89 RefPtrWillBePersistent<AnimationPlayer> player; | 89 RefPtrWillBePersistent<AnimationPlayer> player; |
| 90 TrackExceptionState exceptionState; | 90 TrackExceptionState exceptionState; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 TEST_F(AnimationAnimationPlayerTest, InitialState) | 93 TEST_F(AnimationAnimationPlayerTest, InitialState) |
| 94 { | 94 { |
| 95 setUpWithoutStartingTimeline(); | 95 setUpWithoutStartingTimeline(); |
| 96 player = timeline->play(0); | 96 player = timeline->play(0); |
| 97 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | 97 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); |
| 98 EXPECT_EQ(0, player->currentTimeInternal()); | 98 EXPECT_EQ(0, player->currentTimeInternal()); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 player->setPlaybackRate(0); | 501 player->setPlaybackRate(0); |
| 502 player->finish(exceptionState); | 502 player->finish(exceptionState); |
| 503 EXPECT_EQ(10, player->currentTimeInternal()); | 503 EXPECT_EQ(10, player->currentTimeInternal()); |
| 504 } | 504 } |
| 505 | 505 |
| 506 TEST_F(AnimationAnimationPlayerTest, FinishRaisesException) | 506 TEST_F(AnimationAnimationPlayerTest, FinishRaisesException) |
| 507 { | 507 { |
| 508 Timing timing; | 508 Timing timing; |
| 509 timing.iterationDuration = 1; | 509 timing.iterationDuration = 1; |
| 510 timing.iterationCount = std::numeric_limits<double>::infinity(); | 510 timing.iterationCount = std::numeric_limits<double>::infinity(); |
| 511 player->setSource(Animation::create(0, nullptr, timing).get()); | 511 player->setSource(Animation::create(0, nullptr, timing)); |
| 512 player->setCurrentTimeInternal(10); | 512 player->setCurrentTimeInternal(10); |
| 513 | 513 |
| 514 player->finish(exceptionState); | 514 player->finish(exceptionState); |
| 515 EXPECT_EQ(10, player->currentTimeInternal()); | 515 EXPECT_EQ(10, player->currentTimeInternal()); |
| 516 EXPECT_TRUE(exceptionState.hadException()); | 516 EXPECT_TRUE(exceptionState.hadException()); |
| 517 EXPECT_EQ(InvalidStateError, exceptionState.code()); | 517 EXPECT_EQ(InvalidStateError, exceptionState.code()); |
| 518 } | 518 } |
| 519 | 519 |
| 520 | 520 |
| 521 TEST_F(AnimationAnimationPlayerTest, LimitingAtSourceEnd) | 521 TEST_F(AnimationAnimationPlayerTest, LimitingAtSourceEnd) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 EXPECT_EQ(0, player->currentTimeInternal()); | 619 EXPECT_EQ(0, player->currentTimeInternal()); |
| 620 simulateFrame(1); | 620 simulateFrame(1); |
| 621 EXPECT_EQ(30, player->currentTimeInternal()); | 621 EXPECT_EQ(30, player->currentTimeInternal()); |
| 622 } | 622 } |
| 623 | 623 |
| 624 | 624 |
| 625 TEST_F(AnimationAnimationPlayerTest, SetSource) | 625 TEST_F(AnimationAnimationPlayerTest, SetSource) |
| 626 { | 626 { |
| 627 player = timeline->play(0); | 627 player = timeline->play(0); |
| 628 player->setStartTime(0); | 628 player->setStartTime(0); |
| 629 RefPtrWillBeRawPtr<AnimationNode> source1 = makeAnimation(); | 629 AnimationNode* source1 = makeAnimation(); |
| 630 RefPtrWillBeRawPtr<AnimationNode> source2 = makeAnimation(); | 630 AnimationNode* source2 = makeAnimation(); |
| 631 player->setSource(source1.get()); | 631 player->setSource(source1); |
| 632 EXPECT_EQ(source1, player->source()); | 632 EXPECT_EQ(source1, player->source()); |
| 633 EXPECT_EQ(0, player->currentTimeInternal()); | 633 EXPECT_EQ(0, player->currentTimeInternal()); |
| 634 player->setCurrentTimeInternal(15); | 634 player->setCurrentTimeInternal(15); |
| 635 player->setSource(source2.get()); | 635 player->setSource(source2); |
| 636 EXPECT_EQ(15, player->currentTimeInternal()); | 636 EXPECT_EQ(15, player->currentTimeInternal()); |
| 637 EXPECT_EQ(0, source1->player()); | 637 EXPECT_EQ(0, source1->player()); |
| 638 EXPECT_EQ(player.get(), source2->player()); | 638 EXPECT_EQ(player.get(), source2->player()); |
| 639 EXPECT_EQ(source2, player->source()); | 639 EXPECT_EQ(source2, player->source()); |
| 640 } | 640 } |
| 641 | 641 |
| 642 TEST_F(AnimationAnimationPlayerTest, SetSourceLimitsAnimationPlayer) | 642 TEST_F(AnimationAnimationPlayerTest, SetSourceLimitsAnimationPlayer) |
| 643 { | 643 { |
| 644 player->setCurrentTimeInternal(20); | 644 player->setCurrentTimeInternal(20); |
| 645 player->setSource(makeAnimation(10).get()); | 645 player->setSource(makeAnimation(10)); |
| 646 EXPECT_EQ(20, player->currentTimeInternal()); | 646 EXPECT_EQ(20, player->currentTimeInternal()); |
| 647 EXPECT_TRUE(player->limited()); | 647 EXPECT_TRUE(player->limited()); |
| 648 simulateFrame(10); | 648 simulateFrame(10); |
| 649 EXPECT_EQ(20, player->currentTimeInternal()); | 649 EXPECT_EQ(20, player->currentTimeInternal()); |
| 650 } | 650 } |
| 651 | 651 |
| 652 TEST_F(AnimationAnimationPlayerTest, SetSourceUnlimitsAnimationPlayer) | 652 TEST_F(AnimationAnimationPlayerTest, SetSourceUnlimitsAnimationPlayer) |
| 653 { | 653 { |
| 654 player->setCurrentTimeInternal(40); | 654 player->setCurrentTimeInternal(40); |
| 655 player->setSource(makeAnimation(60).get()); | 655 player->setSource(makeAnimation(60)); |
| 656 EXPECT_FALSE(player->limited()); | 656 EXPECT_FALSE(player->limited()); |
| 657 EXPECT_EQ(40, player->currentTimeInternal()); | 657 EXPECT_EQ(40, player->currentTimeInternal()); |
| 658 simulateFrame(10); | 658 simulateFrame(10); |
| 659 EXPECT_EQ(50, player->currentTimeInternal()); | 659 EXPECT_EQ(50, player->currentTimeInternal()); |
| 660 } | 660 } |
| 661 | 661 |
| 662 | 662 |
| 663 TEST_F(AnimationAnimationPlayerTest, EmptyAnimationPlayersDontUpdateEffects) | 663 TEST_F(AnimationAnimationPlayerTest, EmptyAnimationPlayersDontUpdateEffects) |
| 664 { | 664 { |
| 665 player = timeline->play(0); | 665 player = timeline->play(0); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 678 player->setSource(animationNode); | 678 player->setSource(animationNode); |
| 679 EXPECT_EQ(0, player2->source()); | 679 EXPECT_EQ(0, player2->source()); |
| 680 } | 680 } |
| 681 | 681 |
| 682 TEST_F(AnimationAnimationPlayerTest, AnimationPlayersReturnTimeToNextEffect) | 682 TEST_F(AnimationAnimationPlayerTest, AnimationPlayersReturnTimeToNextEffect) |
| 683 { | 683 { |
| 684 Timing timing; | 684 Timing timing; |
| 685 timing.startDelay = 1; | 685 timing.startDelay = 1; |
| 686 timing.iterationDuration = 1; | 686 timing.iterationDuration = 1; |
| 687 timing.endDelay = 1; | 687 timing.endDelay = 1; |
| 688 RefPtrWillBeRawPtr<Animation> animation = Animation::create(0, nullptr, timi
ng); | 688 Animation* animation = Animation::create(0, nullptr, timing); |
| 689 player = timeline->play(animation.get()); | 689 player = timeline->play(animation); |
| 690 player->setStartTime(0); | 690 player->setStartTime(0); |
| 691 | 691 |
| 692 simulateFrame(0); | 692 simulateFrame(0); |
| 693 EXPECT_EQ(1, player->timeToEffectChange()); | 693 EXPECT_EQ(1, player->timeToEffectChange()); |
| 694 | 694 |
| 695 simulateFrame(0.5); | 695 simulateFrame(0.5); |
| 696 EXPECT_EQ(0.5, player->timeToEffectChange()); | 696 EXPECT_EQ(0.5, player->timeToEffectChange()); |
| 697 | 697 |
| 698 simulateFrame(1); | 698 simulateFrame(1); |
| 699 EXPECT_EQ(0, player->timeToEffectChange()); | 699 EXPECT_EQ(0, player->timeToEffectChange()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 // received from the compositor yet, as cancel() nukes start times. | 779 // received from the compositor yet, as cancel() nukes start times. |
| 780 simulateFrame(0); | 780 simulateFrame(0); |
| 781 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang
e()); | 781 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang
e()); |
| 782 } | 782 } |
| 783 | 783 |
| 784 TEST_F(AnimationAnimationPlayerTest, AttachedAnimationPlayers) | 784 TEST_F(AnimationAnimationPlayerTest, AttachedAnimationPlayers) |
| 785 { | 785 { |
| 786 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS
ERT_NO_EXCEPTION); | 786 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS
ERT_NO_EXCEPTION); |
| 787 | 787 |
| 788 Timing timing; | 788 Timing timing; |
| 789 RefPtrWillBeRawPtr<Animation> animation = Animation::create(element.get(), n
ullptr, timing); | 789 Animation* animation = Animation::create(element.get(), nullptr, timing); |
| 790 RefPtrWillBeRawPtr<AnimationPlayer> player = timeline->play(animation.get())
; | 790 RefPtrWillBeRawPtr<AnimationPlayer> player = timeline->play(animation); |
| 791 simulateFrame(0); | 791 simulateFrame(0); |
| 792 timeline->serviceAnimations(TimingUpdateForAnimationFrame); | 792 timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
| 793 EXPECT_EQ(1U, element->elementAnimations()->players().find(player.get())->va
lue); | 793 EXPECT_EQ(1U, element->elementAnimations()->players().find(player.get())->va
lue); |
| 794 | 794 |
| 795 player.release(); | 795 player.release(); |
| 796 Heap::collectAllGarbage(); | 796 Heap::collectAllGarbage(); |
| 797 EXPECT_TRUE(element->elementAnimations()->players().isEmpty()); | 797 EXPECT_TRUE(element->elementAnimations()->players().isEmpty()); |
| 798 } | 798 } |
| 799 | 799 |
| 800 TEST_F(AnimationAnimationPlayerTest, HasLowerPriority) | 800 TEST_F(AnimationAnimationPlayerTest, HasLowerPriority) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal()); | 873 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal()); |
| 874 EXPECT_TRUE(std::isnan(player->currentTime())); | 874 EXPECT_TRUE(std::isnan(player->currentTime())); |
| 875 EXPECT_TRUE(std::isnan(player->startTime())); | 875 EXPECT_TRUE(std::isnan(player->startTime())); |
| 876 player->pause(); | 876 player->pause(); |
| 877 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal()); | 877 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal()); |
| 878 EXPECT_TRUE(std::isnan(player->currentTime())); | 878 EXPECT_TRUE(std::isnan(player->currentTime())); |
| 879 EXPECT_TRUE(std::isnan(player->startTime())); | 879 EXPECT_TRUE(std::isnan(player->startTime())); |
| 880 } | 880 } |
| 881 | 881 |
| 882 } | 882 } |
| OLD | NEW |