Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: Source/core/animation/AnimationPlayerTest.cpp

Issue 534193002: Web-Animations: Implement idle state for AnimationPlayers. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/animation/AnimationPlayer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 player->pause(); 747 player->pause();
748 player->update(TimingUpdateOnDemand); 748 player->update(TimingUpdateOnDemand);
749 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e()); 749 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
750 } 750 }
751 751
752 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStart) 752 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStart)
753 { 753 {
754 EXPECT_EQ(0, player->timeToEffectChange()); 754 EXPECT_EQ(0, player->timeToEffectChange());
755 player->setCurrentTimeInternal(-8); 755 player->setCurrentTimeInternal(-8);
756 player->setPlaybackRate(2); 756 player->setPlaybackRate(2);
757 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
757 player->cancel(); 758 player->cancel();
759 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
758 player->update(TimingUpdateOnDemand); 760 player->update(TimingUpdateOnDemand);
761 // This frame will fire the finish event event though no start time has been
762 // received from the compositor yet, as cancel() nukes start times.
759 simulateFrame(0); 763 simulateFrame(0);
760 EXPECT_EQ(4, player->timeToEffectChange()); 764 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
761 } 765 }
762 766
763 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStartRev erse) 767 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStartRev erse)
764 { 768 {
765 EXPECT_EQ(0, player->timeToEffectChange()); 769 EXPECT_EQ(0, player->timeToEffectChange());
766 player->setCurrentTimeInternal(9); 770 player->setCurrentTimeInternal(9);
767 player->setPlaybackRate(-3); 771 player->setPlaybackRate(-3);
772 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
773 player->cancel();
774 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
775 player->update(TimingUpdateOnDemand);
776 // This frame will fire the finish event event though no start time has been
777 // received from the compositor yet, as cancel() nukes start times.
778 simulateFrame(0);
779 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
780 }
781
782 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectSimpleCancelledBeforeStart)
783 {
784 EXPECT_EQ(0, player->timeToEffectChange());
785 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
768 player->cancel(); 786 player->cancel();
769 player->update(TimingUpdateOnDemand); 787 player->update(TimingUpdateOnDemand);
788 // This frame will fire the finish event event though no start time has been
789 // received from the compositor yet, as cancel() nukes start times.
770 simulateFrame(0); 790 simulateFrame(0);
771 EXPECT_EQ(3, player->timeToEffectChange()); 791 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
772 } 792 }
773 793
774 TEST_F(AnimationAnimationPlayerTest, AttachedAnimationPlayers) 794 TEST_F(AnimationAnimationPlayerTest, AttachedAnimationPlayers)
775 { 795 {
776 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS ERT_NO_EXCEPTION); 796 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS ERT_NO_EXCEPTION);
777 797
778 Timing timing; 798 Timing timing;
779 RefPtrWillBeRawPtr<Animation> animation = Animation::create(element.get(), n ullptr, timing); 799 RefPtrWillBeRawPtr<Animation> animation = Animation::create(element.get(), n ullptr, timing);
780 RefPtrWillBeRawPtr<AnimationPlayer> player = timeline->createAnimationPlayer (animation.get()); 800 RefPtrWillBeRawPtr<AnimationPlayer> player = timeline->createAnimationPlayer (animation.get());
781 simulateFrame(0); 801 simulateFrame(0);
782 timeline->serviceAnimations(TimingUpdateForAnimationFrame); 802 timeline->serviceAnimations(TimingUpdateForAnimationFrame);
783 EXPECT_EQ(1U, element->activeAnimations()->players().find(player.get())->val ue); 803 EXPECT_EQ(1U, element->activeAnimations()->players().find(player.get())->val ue);
784 804
785 player.release(); 805 player.release();
786 Heap::collectAllGarbage(); 806 Heap::collectAllGarbage();
787 EXPECT_TRUE(element->activeAnimations()->players().isEmpty()); 807 EXPECT_TRUE(element->activeAnimations()->players().isEmpty());
788 } 808 }
789 809
790 TEST_F(AnimationAnimationPlayerTest, HasLowerPriority) 810 TEST_F(AnimationAnimationPlayerTest, HasLowerPriority)
791 { 811 {
792 RefPtrWillBeRawPtr<AnimationPlayer> player1 = timeline->createAnimationPlaye r(0); 812 RefPtrWillBeRawPtr<AnimationPlayer> player1 = timeline->createAnimationPlaye r(0);
793 RefPtrWillBeRawPtr<AnimationPlayer> player2 = timeline->createAnimationPlaye r(0); 813 RefPtrWillBeRawPtr<AnimationPlayer> player2 = timeline->createAnimationPlaye r(0);
794 EXPECT_TRUE(AnimationPlayer::hasLowerPriority(player1.get(), player2.get())) ; 814 EXPECT_TRUE(AnimationPlayer::hasLowerPriority(player1.get(), player2.get())) ;
795 } 815 }
796 816
817 TEST_F(AnimationAnimationPlayerTest, PlayAfterCancel)
818 {
819 player->cancel();
820 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
821 EXPECT_TRUE(std::isnan(player->currentTime()));
822 EXPECT_TRUE(std::isnan(player->startTime()));
823 player->play();
824 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
825 EXPECT_EQ(0, player->currentTime());
826 EXPECT_TRUE(std::isnan(player->startTime()));
827 simulateFrame(10);
828 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
829 EXPECT_EQ(0, player->currentTime());
830 EXPECT_EQ(10 * 1000, player->startTime());
797 } 831 }
832
833 TEST_F(AnimationAnimationPlayerTest, PlayBackwardsAfterCancel)
834 {
835 player->setPlaybackRate(-1);
836 player->setCurrentTime(15 * 1000);
837 simulateFrame(0);
838 player->cancel();
839 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
840 EXPECT_TRUE(std::isnan(player->currentTime()));
841 EXPECT_TRUE(std::isnan(player->startTime()));
842 player->play();
843 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
844 EXPECT_EQ(30 * 1000, player->currentTime());
845 EXPECT_TRUE(std::isnan(player->startTime()));
846 simulateFrame(10);
847 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
848 EXPECT_EQ(30 * 1000, player->currentTime());
849 EXPECT_EQ(40 * 1000, player->startTime());
850 }
851
852 // FIXME: crbug.com/410229, when fixed, will reuqire the expected results of
853 // this test to change (currentTime -> 30 * 1000).
854 TEST_F(AnimationAnimationPlayerTest, ReverseAfterCancel)
855 {
856 player->cancel();
857 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
858 EXPECT_TRUE(std::isnan(player->currentTime()));
859 EXPECT_TRUE(std::isnan(player->startTime()));
860 player->reverse();
861 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
862 EXPECT_TRUE(std::isnan(player->currentTime()));
863 EXPECT_TRUE(std::isnan(player->startTime()));
864 simulateFrame(10);
865 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
866 EXPECT_EQ(0 * 1000, player->currentTime());
867 EXPECT_EQ(10 * 1000, player->startTime());
868 }
869
870 TEST_F(AnimationAnimationPlayerTest, FinishAfterCancel)
871 {
872 player->cancel();
873 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
874 EXPECT_TRUE(std::isnan(player->currentTime()));
875 EXPECT_TRUE(std::isnan(player->startTime()));
876 player->finish(exceptionState);
877 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
878 EXPECT_EQ(30 * 1000, player->currentTime());
879 EXPECT_EQ(0, player->startTime());
880 }
881
882 TEST_F(AnimationAnimationPlayerTest, PauseAfterCancel)
883 {
884 player->cancel();
885 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
886 EXPECT_TRUE(std::isnan(player->currentTime()));
887 EXPECT_TRUE(std::isnan(player->startTime()));
888 player->pause();
889 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
890 EXPECT_TRUE(std::isnan(player->currentTime()));
891 EXPECT_TRUE(std::isnan(player->startTime()));
892 }
893
894 }
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationPlayer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698