Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / animation / AnimationPlayerTest.cpp
index f846dd8..017f6d8 100644 (file)
@@ -58,13 +58,13 @@ protected:
         document->animationClock().resetTimeForTesting();
         timeline = AnimationTimeline::create(document.get());
         player = timeline->createAnimationPlayer(0);
-        player->setStartTimeInternal(0);
+        player->setStartTime(0);
         player->setSource(makeAnimation().get());
     }
 
     void startTimeline()
     {
-        updateTimeline(0);
+        simulateFrame(0);
     }
 
     PassRefPtrWillBeRawPtr<Animation> makeAnimation(double duration = 30, double playbackRate = 1)
@@ -75,11 +75,12 @@ protected:
         return Animation::create(0, nullptr, timing);
     }
 
-    bool updateTimeline(double time)
+    bool simulateFrame(double time)
     {
         document->animationClock().updateTime(time);
+        document->compositorPendingAnimations().update(false);
         // The timeline does not know about our player, so we have to explicitly call update().
-        return player->update(TimingUpdateOnDemand);
+        return player->update(TimingUpdateForAnimationFrame);
     }
 
     RefPtrWillBePersistent<Document> document;
@@ -92,6 +93,7 @@ TEST_F(AnimationAnimationPlayerTest, InitialState)
 {
     setUpWithoutStartingTimeline();
     player = timeline->createAnimationPlayer(0);
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
     EXPECT_EQ(0, player->currentTimeInternal());
     EXPECT_FALSE(player->paused());
     EXPECT_EQ(1, player->playbackRate());
@@ -99,7 +101,7 @@ TEST_F(AnimationAnimationPlayerTest, InitialState)
     EXPECT_TRUE(isNull(player->startTimeInternal()));
 
     startTimeline();
-    player->setStartTimeInternal(0);
+    EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
     EXPECT_EQ(0, timeline->currentTimeInternal());
     EXPECT_EQ(0, player->currentTimeInternal());
     EXPECT_FALSE(player->paused());
@@ -114,7 +116,7 @@ TEST_F(AnimationAnimationPlayerTest, CurrentTimeDoesNotSetOutdated)
     EXPECT_FALSE(player->outdated());
     EXPECT_EQ(0, player->currentTimeInternal());
     EXPECT_FALSE(player->outdated());
-    // FIXME: We should split updateTimeline into a version that doesn't update
+    // FIXME: We should split simulateFrame into a version that doesn't update
     // the player and one that does, as most of the tests don't require update()
     // to be called.
     document->animationClock().updateTime(10);
@@ -124,37 +126,62 @@ TEST_F(AnimationAnimationPlayerTest, CurrentTimeDoesNotSetOutdated)
 
 TEST_F(AnimationAnimationPlayerTest, SetCurrentTime)
 {
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
     player->setCurrentTimeInternal(10);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
     EXPECT_EQ(10, player->currentTimeInternal());
-    updateTimeline(10);
+    simulateFrame(10);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
     EXPECT_EQ(20, player->currentTimeInternal());
 }
 
 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeNegative)
 {
     player->setCurrentTimeInternal(-10);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
     EXPECT_EQ(-10, player->currentTimeInternal());
-    updateTimeline(20);
+    simulateFrame(20);
     EXPECT_EQ(10, player->currentTimeInternal());
 
     player->setPlaybackRate(-2);
     player->setCurrentTimeInternal(-10);
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
     EXPECT_EQ(-10, player->currentTimeInternal());
-    updateTimeline(40);
+    simulateFrame(40);
+    EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
     EXPECT_EQ(-10, player->currentTimeInternal());
 }
 
+TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeNegativeWithoutSimultaneousPlaybackRateChange)
+{
+    simulateFrame(20);
+    EXPECT_EQ(20, player->currentTimeInternal());
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
+    player->setPlaybackRate(-1);
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    simulateFrame(30);
+    EXPECT_EQ(20, player->currentTimeInternal());
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
+    player->setCurrentTimeInternal(-10);
+    EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
+}
+
 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimePastContentEnd)
 {
     player->setCurrentTimeInternal(50);
+    EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
     EXPECT_EQ(50, player->currentTimeInternal());
-    updateTimeline(20);
+    simulateFrame(20);
+    EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
     EXPECT_EQ(50, player->currentTimeInternal());
 
     player->setPlaybackRate(-2);
     player->setCurrentTimeInternal(50);
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
     EXPECT_EQ(50, player->currentTimeInternal());
-    updateTimeline(40);
+    simulateFrame(20);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
+    simulateFrame(40);
     EXPECT_EQ(10, player->currentTimeInternal());
 }
 
@@ -164,7 +191,7 @@ TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeBeforeTimelineStarted)
     player->setCurrentTimeInternal(5);
     EXPECT_EQ(5, player->currentTimeInternal());
     startTimeline();
-    updateTimeline(10);
+    simulateFrame(10);
     EXPECT_EQ(15, player->currentTimeInternal());
 }
 
@@ -174,7 +201,7 @@ TEST_F(AnimationAnimationPlayerTest, SetCurrentTimePastContentEndBeforeTimelineS
     player->setCurrentTimeInternal(250);
     EXPECT_EQ(250, player->currentTimeInternal());
     startTimeline();
-    updateTimeline(10);
+    simulateFrame(10);
     EXPECT_EQ(250, player->currentTimeInternal());
 }
 
@@ -182,13 +209,13 @@ TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeMax)
 {
     player->setCurrentTimeInternal(std::numeric_limits<double>::max());
     EXPECT_EQ(std::numeric_limits<double>::max(), player->currentTimeInternal());
-    updateTimeline(100);
+    simulateFrame(100);
     EXPECT_EQ(std::numeric_limits<double>::max(), player->currentTimeInternal());
 }
 
 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeUnrestrictedDouble)
 {
-    updateTimeline(10);
+    simulateFrame(10);
     player->setCurrentTime(nullValue());
     EXPECT_EQ(10, player->currentTimeInternal());
     player->setCurrentTime(std::numeric_limits<double>::infinity());
@@ -203,58 +230,78 @@ TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeSetsStartTime)
     EXPECT_EQ(0, player->startTime());
     player->setCurrentTime(1000);
     EXPECT_EQ(-1000, player->startTime());
-    updateTimeline(1);
+    simulateFrame(1);
     EXPECT_EQ(-1000, player->startTime());
     EXPECT_EQ(2000, player->currentTime());
 }
 
 TEST_F(AnimationAnimationPlayerTest, SetStartTime)
 {
-    updateTimeline(20);
+    simulateFrame(20);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
     EXPECT_EQ(0, player->startTimeInternal());
     EXPECT_EQ(20, player->currentTimeInternal());
-    player->setStartTimeInternal(10);
+    player->setStartTime(10 * 1000);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
     EXPECT_EQ(10, player->startTimeInternal());
     EXPECT_EQ(10, player->currentTimeInternal());
-    updateTimeline(30);
+    simulateFrame(30);
     EXPECT_EQ(10, player->startTimeInternal());
     EXPECT_EQ(20, player->currentTimeInternal());
+    player->setStartTime(-20 * 1000);
+    EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
 }
 
 TEST_F(AnimationAnimationPlayerTest, SetStartTimeLimitsAnimationPlayer)
 {
-    player->setStartTimeInternal(-50);
+    player->setStartTime(-50 * 1000);
+    EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
     EXPECT_EQ(30, player->currentTimeInternal());
     player->setPlaybackRate(-1);
-    player->setStartTimeInternal(-100);
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    player->setStartTime(-100 * 1000);
+    EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
     EXPECT_EQ(0, player->currentTimeInternal());
     EXPECT_TRUE(player->finished());
 }
 
 TEST_F(AnimationAnimationPlayerTest, SetStartTimeOnLimitedAnimationPlayer)
 {
-    updateTimeline(30);
-    player->setStartTimeInternal(-10);
+    simulateFrame(30);
+    player->setStartTime(-10 * 1000);
+    EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
     EXPECT_EQ(30, player->currentTimeInternal());
     player->setCurrentTimeInternal(50);
-    player->setStartTimeInternal(-40);
-    EXPECT_EQ(50, player->currentTimeInternal());
+    player->setStartTime(-40 * 1000);
+    EXPECT_EQ(30, player->currentTimeInternal());
+    EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
     EXPECT_TRUE(player->finished());
 }
 
 TEST_F(AnimationAnimationPlayerTest, StartTimePauseFinish)
 {
     player->pause();
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
     EXPECT_TRUE(std::isnan(player->startTime()));
     player->finish(exceptionState);
+    EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal());
     EXPECT_TRUE(std::isnan(player->startTime()));
 }
 
+TEST_F(AnimationAnimationPlayerTest, PauseBeatsFinish)
+{
+    player->pause();
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    simulateFrame(10);
+    EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal());
+    player->finish(exceptionState);
+    EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal());
+}
+
 TEST_F(AnimationAnimationPlayerTest, StartTimeFinishPause)
 {
-    double startTime = player->startTime();
     player->finish(exceptionState);
-    EXPECT_EQ(startTime, player->startTime());
+    EXPECT_EQ(-30 * 1000, player->startTime());
     player->pause();
     EXPECT_TRUE(std::isnan(player->startTime()));
 }
@@ -262,31 +309,28 @@ TEST_F(AnimationAnimationPlayerTest, StartTimeFinishPause)
 TEST_F(AnimationAnimationPlayerTest, StartTimeWithZeroPlaybackRate)
 {
     player->setPlaybackRate(0);
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
     EXPECT_TRUE(std::isnan(player->startTime()));
-}
-
-TEST_F(AnimationAnimationPlayerTest, SetStartTimeWhilePaused)
-{
-    updateTimeline(10);
-    player->pause();
-    player->setStartTimeInternal(-40);
-    EXPECT_EQ(10, player->currentTimeInternal());
-    updateTimeline(50);
-    player->setStartTimeInternal(60);
-    EXPECT_EQ(10, player->currentTimeInternal());
+    simulateFrame(10);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
 }
 
 TEST_F(AnimationAnimationPlayerTest, PausePlay)
 {
-    updateTimeline(10);
+    simulateFrame(10);
     player->pause();
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
     EXPECT_TRUE(player->paused());
     EXPECT_EQ(10, player->currentTimeInternal());
-    updateTimeline(20);
+    simulateFrame(20);
+    EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal());
     player->play();
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    simulateFrame(20);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
     EXPECT_FALSE(player->paused());
     EXPECT_EQ(10, player->currentTimeInternal());
-    updateTimeline(30);
+    simulateFrame(30);
     EXPECT_EQ(20, player->currentTimeInternal());
 }
 
@@ -300,26 +344,11 @@ TEST_F(AnimationAnimationPlayerTest, PauseBeforeTimelineStarted)
 
     player->pause();
     startTimeline();
-    updateTimeline(100);
+    simulateFrame(100);
     EXPECT_TRUE(player->paused());
     EXPECT_EQ(0, player->currentTimeInternal());
 }
 
-TEST_F(AnimationAnimationPlayerTest, PauseBeforeStartTimeSet)
-{
-    player = timeline->createAnimationPlayer(makeAnimation().get());
-    updateTimeline(100);
-    player->pause();
-    updateTimeline(200);
-    EXPECT_EQ(0, player->currentTimeInternal());
-
-    player->setStartTimeInternal(150);
-    player->play();
-    EXPECT_EQ(0, player->currentTimeInternal());
-    updateTimeline(220);
-    EXPECT_EQ(20, player->currentTimeInternal());
-}
-
 TEST_F(AnimationAnimationPlayerTest, PlayRewindsToStart)
 {
     player->setCurrentTimeInternal(30);
@@ -329,10 +358,15 @@ TEST_F(AnimationAnimationPlayerTest, PlayRewindsToStart)
     player->setCurrentTimeInternal(40);
     player->play();
     EXPECT_EQ(0, player->currentTimeInternal());
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    simulateFrame(10);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
 
     player->setCurrentTimeInternal(-10);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
     player->play();
     EXPECT_EQ(0, player->currentTimeInternal());
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
 }
 
 TEST_F(AnimationAnimationPlayerTest, PlayRewindsToEnd)
@@ -342,12 +376,19 @@ TEST_F(AnimationAnimationPlayerTest, PlayRewindsToEnd)
     EXPECT_EQ(30, player->currentTimeInternal());
 
     player->setCurrentTimeInternal(40);
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
     player->play();
     EXPECT_EQ(30, player->currentTimeInternal());
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    simulateFrame(10);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
 
     player->setCurrentTimeInternal(-10);
     player->play();
     EXPECT_EQ(30, player->currentTimeInternal());
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    simulateFrame(20);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
 }
 
 TEST_F(AnimationAnimationPlayerTest, PlayWithPlaybackRateZeroDoesNotSeek)
@@ -365,6 +406,15 @@ TEST_F(AnimationAnimationPlayerTest, PlayWithPlaybackRateZeroDoesNotSeek)
     EXPECT_EQ(-10, player->currentTimeInternal());
 }
 
+TEST_F(AnimationAnimationPlayerTest, PlayAfterPauseWithPlaybackRateZeroUpdatesPlayState)
+{
+    player->pause();
+    player->setPlaybackRate(0);
+    simulateFrame(1);
+    EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal());
+    player->play();
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
+}
 
 TEST_F(AnimationAnimationPlayerTest, Reverse)
 {
@@ -410,18 +460,18 @@ TEST_F(AnimationAnimationPlayerTest, ReverseSeeksToEnd)
     EXPECT_EQ(30, player->currentTimeInternal());
 }
 
-TEST_F(AnimationAnimationPlayerTest, ReverseLimitsAnimationPlayer)
+TEST_F(AnimationAnimationPlayerTest, ReverseBeyondLimit)
 {
     player->setCurrentTimeInternal(40);
     player->setPlaybackRate(-1);
     player->reverse();
-    EXPECT_TRUE(player->finished());
-    EXPECT_EQ(40, player->currentTimeInternal());
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    EXPECT_EQ(0, player->currentTimeInternal());
 
     player->setCurrentTimeInternal(-10);
     player->reverse();
-    EXPECT_TRUE(player->finished());
-    EXPECT_EQ(-10, player->currentTimeInternal());
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    EXPECT_EQ(30, player->currentTimeInternal());
 }
 
 
@@ -479,22 +529,23 @@ TEST_F(AnimationAnimationPlayerTest, FinishRaisesException)
 
 TEST_F(AnimationAnimationPlayerTest, LimitingAtSourceEnd)
 {
-    updateTimeline(30);
+    simulateFrame(30);
     EXPECT_EQ(30, player->currentTimeInternal());
     EXPECT_TRUE(player->finished());
-    updateTimeline(40);
+    simulateFrame(40);
     EXPECT_EQ(30, player->currentTimeInternal());
     EXPECT_FALSE(player->paused());
 }
 
 TEST_F(AnimationAnimationPlayerTest, LimitingAtStart)
 {
-    updateTimeline(30);
+    simulateFrame(30);
     player->setPlaybackRate(-2);
-    updateTimeline(45);
+    simulateFrame(30);
+    simulateFrame(45);
     EXPECT_EQ(0, player->currentTimeInternal());
     EXPECT_TRUE(player->finished());
-    updateTimeline(60);
+    simulateFrame(60);
     EXPECT_EQ(0, player->currentTimeInternal());
     EXPECT_FALSE(player->paused());
 }
@@ -503,7 +554,7 @@ TEST_F(AnimationAnimationPlayerTest, LimitingWithNoSource)
 {
     player->setSource(0);
     EXPECT_TRUE(player->finished());
-    updateTimeline(30);
+    simulateFrame(30);
     EXPECT_EQ(0, player->currentTimeInternal());
 }
 
@@ -511,9 +562,10 @@ TEST_F(AnimationAnimationPlayerTest, LimitingWithNoSource)
 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRate)
 {
     player->setPlaybackRate(2);
+    simulateFrame(0);
     EXPECT_EQ(2, player->playbackRate());
     EXPECT_EQ(0, player->currentTimeInternal());
-    updateTimeline(10);
+    simulateFrame(10);
     EXPECT_EQ(20, player->currentTimeInternal());
 }
 
@@ -524,41 +576,45 @@ TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateBeforeTimelineStarted)
     EXPECT_EQ(2, player->playbackRate());
     EXPECT_EQ(0, player->currentTimeInternal());
     startTimeline();
-    updateTimeline(10);
+    simulateFrame(10);
     EXPECT_EQ(20, player->currentTimeInternal());
 }
 
 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateWhilePaused)
 {
-    updateTimeline(10);
+    simulateFrame(10);
     player->pause();
     player->setPlaybackRate(2);
-    updateTimeline(20);
+    simulateFrame(20);
     player->play();
     EXPECT_EQ(10, player->currentTimeInternal());
-    updateTimeline(25);
+    simulateFrame(20);
+    simulateFrame(25);
     EXPECT_EQ(20, player->currentTimeInternal());
 }
 
 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateWhileLimited)
 {
-    updateTimeline(40);
+    simulateFrame(40);
     EXPECT_EQ(30, player->currentTimeInternal());
     player->setPlaybackRate(2);
-    updateTimeline(50);
+    simulateFrame(50);
     EXPECT_EQ(30, player->currentTimeInternal());
     player->setPlaybackRate(-2);
+    simulateFrame(50);
+    simulateFrame(60);
     EXPECT_FALSE(player->finished());
-    updateTimeline(60);
     EXPECT_EQ(10, player->currentTimeInternal());
 }
 
 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateZero)
 {
-    updateTimeline(10);
+    simulateFrame(0);
+    simulateFrame(10);
     player->setPlaybackRate(0);
+    simulateFrame(10);
     EXPECT_EQ(10, player->currentTimeInternal());
-    updateTimeline(20);
+    simulateFrame(20);
     EXPECT_EQ(10, player->currentTimeInternal());
     player->setCurrentTimeInternal(20);
     EXPECT_EQ(20, player->currentTimeInternal());
@@ -567,9 +623,10 @@ TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateZero)
 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateMax)
 {
     player->setPlaybackRate(std::numeric_limits<double>::max());
+    simulateFrame(0);
     EXPECT_EQ(std::numeric_limits<double>::max(), player->playbackRate());
     EXPECT_EQ(0, player->currentTimeInternal());
-    updateTimeline(1);
+    simulateFrame(1);
     EXPECT_EQ(30, player->currentTimeInternal());
 }
 
@@ -577,7 +634,7 @@ TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateMax)
 TEST_F(AnimationAnimationPlayerTest, SetSource)
 {
     player = timeline->createAnimationPlayer(0);
-    player->setStartTimeInternal(0);
+    player->setStartTime(0);
     RefPtrWillBeRawPtr<AnimationNode> source1 = makeAnimation();
     RefPtrWillBeRawPtr<AnimationNode> source2 = makeAnimation();
     player->setSource(source1.get());
@@ -597,7 +654,7 @@ TEST_F(AnimationAnimationPlayerTest, SetSourceLimitsAnimationPlayer)
     player->setSource(makeAnimation(10).get());
     EXPECT_EQ(20, player->currentTimeInternal());
     EXPECT_TRUE(player->finished());
-    updateTimeline(10);
+    simulateFrame(10);
     EXPECT_EQ(20, player->currentTimeInternal());
 }
 
@@ -607,7 +664,7 @@ TEST_F(AnimationAnimationPlayerTest, SetSourceUnlimitsAnimationPlayer)
     player->setSource(makeAnimation(60).get());
     EXPECT_FALSE(player->finished());
     EXPECT_EQ(40, player->currentTimeInternal());
-    updateTimeline(10);
+    simulateFrame(10);
     EXPECT_EQ(50, player->currentTimeInternal());
 }
 
@@ -618,7 +675,7 @@ TEST_F(AnimationAnimationPlayerTest, EmptyAnimationPlayersDontUpdateEffects)
     player->update(TimingUpdateOnDemand);
     EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChange());
 
-    updateTimeline(1234);
+    simulateFrame(1234);
     EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChange());
 }
 
@@ -639,32 +696,32 @@ TEST_F(AnimationAnimationPlayerTest, AnimationPlayersReturnTimeToNextEffect)
     timing.endDelay = 1;
     RefPtrWillBeRawPtr<Animation> animation = Animation::create(0, nullptr, timing);
     player = timeline->createAnimationPlayer(animation.get());
-    player->setStartTimeInternal(0);
+    player->setStartTime(0);
 
-    updateTimeline(0);
+    simulateFrame(0);
     EXPECT_EQ(1, player->timeToEffectChange());
 
-    updateTimeline(0.5);
+    simulateFrame(0.5);
     EXPECT_EQ(0.5, player->timeToEffectChange());
 
-    updateTimeline(1);
+    simulateFrame(1);
     EXPECT_EQ(0, player->timeToEffectChange());
 
-    updateTimeline(1.5);
+    simulateFrame(1.5);
     EXPECT_EQ(0, player->timeToEffectChange());
 
-    updateTimeline(2);
+    simulateFrame(2);
     EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChange());
 
-    updateTimeline(3);
+    simulateFrame(3);
     EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChange());
 
     player->setCurrentTimeInternal(0);
-    player->update(TimingUpdateOnDemand);
+    simulateFrame(3);
     EXPECT_EQ(1, player->timeToEffectChange());
 
     player->setPlaybackRate(2);
-    player->update(TimingUpdateOnDemand);
+    simulateFrame(3);
     EXPECT_EQ(0.5, player->timeToEffectChange());
 
     player->setPlaybackRate(0);
@@ -674,10 +731,12 @@ TEST_F(AnimationAnimationPlayerTest, AnimationPlayersReturnTimeToNextEffect)
     player->setCurrentTimeInternal(3);
     player->setPlaybackRate(-1);
     player->update(TimingUpdateOnDemand);
+    simulateFrame(3);
     EXPECT_EQ(1, player->timeToEffectChange());
 
     player->setPlaybackRate(-2);
     player->update(TimingUpdateOnDemand);
+    simulateFrame(3);
     EXPECT_EQ(0.5, player->timeToEffectChange());
 }
 
@@ -694,9 +753,14 @@ TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStart)
     EXPECT_EQ(0, player->timeToEffectChange());
     player->setCurrentTimeInternal(-8);
     player->setPlaybackRate(2);
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
     player->cancel();
+    EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
     player->update(TimingUpdateOnDemand);
-    EXPECT_EQ(4, player->timeToEffectChange());
+    // This frame will fire the finish event event though no start time has been
+    // received from the compositor yet, as cancel() nukes start times.
+    simulateFrame(0);
+    EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChange());
 }
 
 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStartReverse)
@@ -704,9 +768,26 @@ TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStartRev
     EXPECT_EQ(0, player->timeToEffectChange());
     player->setCurrentTimeInternal(9);
     player->setPlaybackRate(-3);
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
     player->cancel();
+    EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
     player->update(TimingUpdateOnDemand);
-    EXPECT_EQ(3, player->timeToEffectChange());
+    // This frame will fire the finish event event though no start time has been
+    // received from the compositor yet, as cancel() nukes start times.
+    simulateFrame(0);
+    EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChange());
+}
+
+TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectSimpleCancelledBeforeStart)
+{
+    EXPECT_EQ(0, player->timeToEffectChange());
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
+    player->cancel();
+    player->update(TimingUpdateOnDemand);
+    // This frame will fire the finish event event though no start time has been
+    // received from the compositor yet, as cancel() nukes start times.
+    simulateFrame(0);
+    EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChange());
 }
 
 TEST_F(AnimationAnimationPlayerTest, AttachedAnimationPlayers)
@@ -716,7 +797,7 @@ TEST_F(AnimationAnimationPlayerTest, AttachedAnimationPlayers)
     Timing timing;
     RefPtrWillBeRawPtr<Animation> animation = Animation::create(element.get(), nullptr, timing);
     RefPtrWillBeRawPtr<AnimationPlayer> player = timeline->createAnimationPlayer(animation.get());
-    player->setStartTime(0);
+    simulateFrame(0);
     timeline->serviceAnimations(TimingUpdateForAnimationFrame);
     EXPECT_EQ(1U, element->activeAnimations()->players().find(player.get())->value);
 
@@ -732,4 +813,79 @@ TEST_F(AnimationAnimationPlayerTest, HasLowerPriority)
     EXPECT_TRUE(AnimationPlayer::hasLowerPriority(player1.get(), player2.get()));
 }
 
+TEST_F(AnimationAnimationPlayerTest, PlayAfterCancel)
+{
+    player->cancel();
+    EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
+    EXPECT_TRUE(std::isnan(player->currentTime()));
+    EXPECT_TRUE(std::isnan(player->startTime()));
+    player->play();
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    EXPECT_EQ(0, player->currentTime());
+    EXPECT_TRUE(std::isnan(player->startTime()));
+    simulateFrame(10);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
+    EXPECT_EQ(0, player->currentTime());
+    EXPECT_EQ(10 * 1000, player->startTime());
+}
+
+TEST_F(AnimationAnimationPlayerTest, PlayBackwardsAfterCancel)
+{
+    player->setPlaybackRate(-1);
+    player->setCurrentTime(15 * 1000);
+    simulateFrame(0);
+    player->cancel();
+    EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
+    EXPECT_TRUE(std::isnan(player->currentTime()));
+    EXPECT_TRUE(std::isnan(player->startTime()));
+    player->play();
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    EXPECT_EQ(30 * 1000, player->currentTime());
+    EXPECT_TRUE(std::isnan(player->startTime()));
+    simulateFrame(10);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
+    EXPECT_EQ(30 * 1000, player->currentTime());
+    EXPECT_EQ(40 * 1000, player->startTime());
+}
+
+TEST_F(AnimationAnimationPlayerTest, ReverseAfterCancel)
+{
+    player->cancel();
+    EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
+    EXPECT_TRUE(std::isnan(player->currentTime()));
+    EXPECT_TRUE(std::isnan(player->startTime()));
+    player->reverse();
+    EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
+    EXPECT_EQ(30 * 1000, player->currentTime());
+    EXPECT_TRUE(std::isnan(player->startTime()));
+    simulateFrame(10);
+    EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
+    EXPECT_EQ(30 * 1000, player->currentTime());
+    EXPECT_EQ(40 * 1000, player->startTime());
+}
+
+TEST_F(AnimationAnimationPlayerTest, FinishAfterCancel)
+{
+    player->cancel();
+    EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
+    EXPECT_TRUE(std::isnan(player->currentTime()));
+    EXPECT_TRUE(std::isnan(player->startTime()));
+    player->finish(exceptionState);
+    EXPECT_TRUE(std::isnan(player->currentTime()));
+    EXPECT_TRUE(std::isnan(player->startTime()));
+    EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
+}
+
+TEST_F(AnimationAnimationPlayerTest, PauseAfterCancel)
+{
+    player->cancel();
+    EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
+    EXPECT_TRUE(std::isnan(player->currentTime()));
+    EXPECT_TRUE(std::isnan(player->startTime()));
+    player->pause();
+    EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
+    EXPECT_TRUE(std::isnan(player->currentTime()));
+    EXPECT_TRUE(std::isnan(player->startTime()));
+}
+
 }