blob: 2e7a959e4b9a1aa5bd3caf023df373e009c47da9 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// Copyright 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]aa0a9d32012-10-24 01:58:105#include "cc/active_animation.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]101441ce2012-10-16 01:45:037#include "cc/test/animation_test_common.h"
[email protected]7f0c53db2012-10-02 00:23:188#include "testing/gmock/include/gmock/gmock.h"
9#include "testing/gtest/include/gtest/gtest.h"
[email protected]94f206c12012-08-25 00:09:1410
11using namespace WebKitTests;
[email protected]94f206c12012-08-25 00:09:1412
[email protected]ba565742012-11-10 09:29:4813namespace cc {
[email protected]94f206c12012-08-25 00:09:1414namespace {
15
[email protected]96baf3e2012-10-22 23:09:5516scoped_ptr<ActiveAnimation> createActiveAnimation(int iterations, double duration)
[email protected]94f206c12012-08-25 00:09:1417{
[email protected]96baf3e2012-10-22 23:09:5518 scoped_ptr<ActiveAnimation> toReturn(ActiveAnimation::create(make_scoped_ptr(new FakeFloatAnimationCurve(duration)).PassAs<AnimationCurve>(), 0, 1, ActiveAnimation::Opacity));
[email protected]94f206c12012-08-25 00:09:1419 toReturn->setIterations(iterations);
[email protected]9aca3592012-10-12 15:57:0920 return toReturn.Pass();
[email protected]94f206c12012-08-25 00:09:1421}
22
[email protected]96baf3e2012-10-22 23:09:5523scoped_ptr<ActiveAnimation> createActiveAnimation(int iterations)
[email protected]4dad47e2012-09-21 22:08:4724{
25 return createActiveAnimation(iterations, 1);
26}
27
[email protected]96baf3e2012-10-22 23:09:5528TEST(ActiveAnimationTest, TrimTimeZeroIterations)
[email protected]94f206c12012-08-25 00:09:1429{
[email protected]96baf3e2012-10-22 23:09:5530 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(0));
[email protected]94f206c12012-08-25 00:09:1431 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(-1));
32 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
33 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(1));
34}
35
[email protected]96baf3e2012-10-22 23:09:5536TEST(ActiveAnimationTest, TrimTimeOneIteration)
[email protected]94f206c12012-08-25 00:09:1437{
[email protected]96baf3e2012-10-22 23:09:5538 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(1));
[email protected]94f206c12012-08-25 00:09:1439 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(-1));
40 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
41 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1));
42 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(2));
43}
44
[email protected]96baf3e2012-10-22 23:09:5545TEST(ActiveAnimationTest, TrimTimeInfiniteIterations)
[email protected]94f206c12012-08-25 00:09:1446{
[email protected]96baf3e2012-10-22 23:09:5547 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(-1));
[email protected]94f206c12012-08-25 00:09:1448 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
49 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5));
50 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(1));
51 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1.5));
52}
53
[email protected]96baf3e2012-10-22 23:09:5554TEST(ActiveAnimationTest, TrimTimeAlternating)
[email protected]94f206c12012-08-25 00:09:1455{
[email protected]96baf3e2012-10-22 23:09:5556 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(-1));
[email protected]94f206c12012-08-25 00:09:1457 anim->setAlternatesDirection(true);
58 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
59 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5));
60 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1));
61 EXPECT_EQ(0.75, anim->trimTimeToCurrentIteration(1.25));
62}
63
[email protected]96baf3e2012-10-22 23:09:5564TEST(ActiveAnimationTest, TrimTimeStartTime)
[email protected]94f206c12012-08-25 00:09:1465{
[email protected]96baf3e2012-10-22 23:09:5566 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(1));
[email protected]94f206c12012-08-25 00:09:1467 anim->setStartTime(4);
68 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
69 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(4));
70 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(4.5));
71 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(5));
72 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(6));
73}
74
[email protected]96baf3e2012-10-22 23:09:5575TEST(ActiveAnimationTest, TrimTimeTimeOffset)
[email protected]94f206c12012-08-25 00:09:1476{
[email protected]96baf3e2012-10-22 23:09:5577 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(1));
[email protected]94f206c12012-08-25 00:09:1478 anim->setTimeOffset(4);
79 anim->setStartTime(4);
80 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
81 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5));
82 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1));
83 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1));
84}
85
[email protected]96baf3e2012-10-22 23:09:5586TEST(ActiveAnimationTest, TrimTimePauseResume)
[email protected]94f206c12012-08-25 00:09:1487{
[email protected]96baf3e2012-10-22 23:09:5588 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(1));
89 anim->setRunState(ActiveAnimation::Running, 0);
[email protected]94f206c12012-08-25 00:09:1490 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
91 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5));
[email protected]96baf3e2012-10-22 23:09:5592 anim->setRunState(ActiveAnimation::Paused, 0.5);
[email protected]94f206c12012-08-25 00:09:1493 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1024));
[email protected]96baf3e2012-10-22 23:09:5594 anim->setRunState(ActiveAnimation::Running, 1024);
[email protected]94f206c12012-08-25 00:09:1495 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1024));
96 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1024.5));
97}
98
[email protected]96baf3e2012-10-22 23:09:5599TEST(ActiveAnimationTest, TrimTimeSuspendResume)
[email protected]94f206c12012-08-25 00:09:14100{
[email protected]96baf3e2012-10-22 23:09:55101 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(1));
102 anim->setRunState(ActiveAnimation::Running, 0);
[email protected]94f206c12012-08-25 00:09:14103 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
104 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5));
105 anim->suspend(0.5);
106 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1024));
107 anim->resume(1024);
108 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1024));
109 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1024.5));
110}
111
[email protected]96baf3e2012-10-22 23:09:55112TEST(ActiveAnimationTest, TrimTimeZeroDuration)
[email protected]4dad47e2012-09-21 22:08:47113{
[email protected]96baf3e2012-10-22 23:09:55114 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(0, 0));
115 anim->setRunState(ActiveAnimation::Running, 0);
[email protected]4dad47e2012-09-21 22:08:47116 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(-1));
117 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
118 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(1));
119}
120
[email protected]96baf3e2012-10-22 23:09:55121TEST(ActiveAnimationTest, IsFinishedAtZeroIterations)
[email protected]94f206c12012-08-25 00:09:14122{
[email protected]96baf3e2012-10-22 23:09:55123 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(0));
124 anim->setRunState(ActiveAnimation::Running, 0);
[email protected]94f206c12012-08-25 00:09:14125 EXPECT_FALSE(anim->isFinishedAt(-1));
126 EXPECT_TRUE(anim->isFinishedAt(0));
127 EXPECT_TRUE(anim->isFinishedAt(1));
128}
129
[email protected]96baf3e2012-10-22 23:09:55130TEST(ActiveAnimationTest, IsFinishedAtOneIteration)
[email protected]94f206c12012-08-25 00:09:14131{
[email protected]96baf3e2012-10-22 23:09:55132 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(1));
133 anim->setRunState(ActiveAnimation::Running, 0);
[email protected]94f206c12012-08-25 00:09:14134 EXPECT_FALSE(anim->isFinishedAt(-1));
135 EXPECT_FALSE(anim->isFinishedAt(0));
136 EXPECT_TRUE(anim->isFinishedAt(1));
137 EXPECT_TRUE(anim->isFinishedAt(2));
138}
139
[email protected]96baf3e2012-10-22 23:09:55140TEST(ActiveAnimationTest, IsFinishedAtInfiniteIterations)
[email protected]94f206c12012-08-25 00:09:14141{
[email protected]96baf3e2012-10-22 23:09:55142 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(-1));
143 anim->setRunState(ActiveAnimation::Running, 0);
[email protected]94f206c12012-08-25 00:09:14144 EXPECT_FALSE(anim->isFinishedAt(0));
145 EXPECT_FALSE(anim->isFinishedAt(0.5));
146 EXPECT_FALSE(anim->isFinishedAt(1));
147 EXPECT_FALSE(anim->isFinishedAt(1.5));
148}
149
[email protected]96baf3e2012-10-22 23:09:55150TEST(ActiveAnimationTest, IsFinishedAtNotRunning)
[email protected]94f206c12012-08-25 00:09:14151{
[email protected]96baf3e2012-10-22 23:09:55152 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(0));
153 anim->setRunState(ActiveAnimation::Running, 0);
[email protected]94f206c12012-08-25 00:09:14154 EXPECT_TRUE(anim->isFinishedAt(0));
[email protected]96baf3e2012-10-22 23:09:55155 anim->setRunState(ActiveAnimation::Paused, 0);
[email protected]94f206c12012-08-25 00:09:14156 EXPECT_FALSE(anim->isFinishedAt(0));
[email protected]96baf3e2012-10-22 23:09:55157 anim->setRunState(ActiveAnimation::WaitingForNextTick, 0);
[email protected]94f206c12012-08-25 00:09:14158 EXPECT_FALSE(anim->isFinishedAt(0));
[email protected]96baf3e2012-10-22 23:09:55159 anim->setRunState(ActiveAnimation::WaitingForTargetAvailability, 0);
[email protected]94f206c12012-08-25 00:09:14160 EXPECT_FALSE(anim->isFinishedAt(0));
[email protected]96baf3e2012-10-22 23:09:55161 anim->setRunState(ActiveAnimation::WaitingForStartTime, 0);
[email protected]94f206c12012-08-25 00:09:14162 EXPECT_FALSE(anim->isFinishedAt(0));
[email protected]96baf3e2012-10-22 23:09:55163 anim->setRunState(ActiveAnimation::Finished, 0);
[email protected]94f206c12012-08-25 00:09:14164 EXPECT_TRUE(anim->isFinishedAt(0));
[email protected]96baf3e2012-10-22 23:09:55165 anim->setRunState(ActiveAnimation::Aborted, 0);
[email protected]94f206c12012-08-25 00:09:14166 EXPECT_TRUE(anim->isFinishedAt(0));
167}
168
[email protected]96baf3e2012-10-22 23:09:55169TEST(ActiveAnimationTest, IsFinished)
[email protected]94f206c12012-08-25 00:09:14170{
[email protected]96baf3e2012-10-22 23:09:55171 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(1));
172 anim->setRunState(ActiveAnimation::Running, 0);
[email protected]94f206c12012-08-25 00:09:14173 EXPECT_FALSE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55174 anim->setRunState(ActiveAnimation::Paused, 0);
[email protected]94f206c12012-08-25 00:09:14175 EXPECT_FALSE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55176 anim->setRunState(ActiveAnimation::WaitingForNextTick, 0);
[email protected]94f206c12012-08-25 00:09:14177 EXPECT_FALSE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55178 anim->setRunState(ActiveAnimation::WaitingForTargetAvailability, 0);
[email protected]94f206c12012-08-25 00:09:14179 EXPECT_FALSE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55180 anim->setRunState(ActiveAnimation::WaitingForStartTime, 0);
[email protected]94f206c12012-08-25 00:09:14181 EXPECT_FALSE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55182 anim->setRunState(ActiveAnimation::Finished, 0);
[email protected]94f206c12012-08-25 00:09:14183 EXPECT_TRUE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55184 anim->setRunState(ActiveAnimation::Aborted, 0);
[email protected]94f206c12012-08-25 00:09:14185 EXPECT_TRUE(anim->isFinished());
186}
187
[email protected]96baf3e2012-10-22 23:09:55188TEST(ActiveAnimationTest, IsFinishedNeedsSynchronizedStartTime)
[email protected]94f206c12012-08-25 00:09:14189{
[email protected]96baf3e2012-10-22 23:09:55190 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(1));
191 anim->setRunState(ActiveAnimation::Running, 2);
[email protected]94f206c12012-08-25 00:09:14192 EXPECT_FALSE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55193 anim->setRunState(ActiveAnimation::Paused, 2);
[email protected]94f206c12012-08-25 00:09:14194 EXPECT_FALSE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55195 anim->setRunState(ActiveAnimation::WaitingForNextTick, 2);
[email protected]94f206c12012-08-25 00:09:14196 EXPECT_FALSE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55197 anim->setRunState(ActiveAnimation::WaitingForTargetAvailability, 2);
[email protected]94f206c12012-08-25 00:09:14198 EXPECT_FALSE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55199 anim->setRunState(ActiveAnimation::WaitingForStartTime, 2);
[email protected]94f206c12012-08-25 00:09:14200 EXPECT_FALSE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55201 anim->setRunState(ActiveAnimation::Finished, 0);
[email protected]94f206c12012-08-25 00:09:14202 EXPECT_TRUE(anim->isFinished());
[email protected]96baf3e2012-10-22 23:09:55203 anim->setRunState(ActiveAnimation::Aborted, 0);
[email protected]94f206c12012-08-25 00:09:14204 EXPECT_TRUE(anim->isFinished());
205}
206
[email protected]96baf3e2012-10-22 23:09:55207TEST(ActiveAnimationTest, RunStateChangesIgnoredWhileSuspended)
[email protected]94f206c12012-08-25 00:09:14208{
[email protected]96baf3e2012-10-22 23:09:55209 scoped_ptr<ActiveAnimation> anim(createActiveAnimation(1));
[email protected]94f206c12012-08-25 00:09:14210 anim->suspend(0);
[email protected]96baf3e2012-10-22 23:09:55211 EXPECT_EQ(ActiveAnimation::Paused, anim->runState());
212 anim->setRunState(ActiveAnimation::Running, 0);
213 EXPECT_EQ(ActiveAnimation::Paused, anim->runState());
[email protected]94f206c12012-08-25 00:09:14214 anim->resume(0);
[email protected]96baf3e2012-10-22 23:09:55215 anim->setRunState(ActiveAnimation::Running, 0);
216 EXPECT_EQ(ActiveAnimation::Running, anim->runState());
[email protected]94f206c12012-08-25 00:09:14217}
218
[email protected]ba565742012-11-10 09:29:48219} // namespace
220} // namespace cc