OLD | NEW |
| (Empty) |
1 // 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 | |
5 #include "config.h" | |
6 | |
7 #include "CCActiveAnimation.h" | |
8 | |
9 #include "CCAnimationTestCommon.h" | |
10 #include "testing/gmock/include/gmock/gmock.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 using namespace WebKitTests; | |
14 using namespace cc; | |
15 | |
16 namespace { | |
17 | |
18 scoped_ptr<CCActiveAnimation> createActiveAnimation(int iterations, double durat
ion) | |
19 { | |
20 scoped_ptr<CCActiveAnimation> toReturn(CCActiveAnimation::create(make_scoped
_ptr(new FakeFloatAnimationCurve(duration)).PassAs<CCAnimationCurve>(), 0, 1, CC
ActiveAnimation::Opacity)); | |
21 toReturn->setIterations(iterations); | |
22 return toReturn.Pass(); | |
23 } | |
24 | |
25 scoped_ptr<CCActiveAnimation> createActiveAnimation(int iterations) | |
26 { | |
27 return createActiveAnimation(iterations, 1); | |
28 } | |
29 | |
30 TEST(CCActiveAnimationTest, TrimTimeZeroIterations) | |
31 { | |
32 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(0)); | |
33 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(-1)); | |
34 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0)); | |
35 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(1)); | |
36 } | |
37 | |
38 TEST(CCActiveAnimationTest, TrimTimeOneIteration) | |
39 { | |
40 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(1)); | |
41 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(-1)); | |
42 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0)); | |
43 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1)); | |
44 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(2)); | |
45 } | |
46 | |
47 TEST(CCActiveAnimationTest, TrimTimeInfiniteIterations) | |
48 { | |
49 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(-1)); | |
50 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0)); | |
51 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5)); | |
52 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(1)); | |
53 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1.5)); | |
54 } | |
55 | |
56 TEST(CCActiveAnimationTest, TrimTimeAlternating) | |
57 { | |
58 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(-1)); | |
59 anim->setAlternatesDirection(true); | |
60 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0)); | |
61 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5)); | |
62 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1)); | |
63 EXPECT_EQ(0.75, anim->trimTimeToCurrentIteration(1.25)); | |
64 } | |
65 | |
66 TEST(CCActiveAnimationTest, TrimTimeStartTime) | |
67 { | |
68 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(1)); | |
69 anim->setStartTime(4); | |
70 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0)); | |
71 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(4)); | |
72 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(4.5)); | |
73 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(5)); | |
74 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(6)); | |
75 } | |
76 | |
77 TEST(CCActiveAnimationTest, TrimTimeTimeOffset) | |
78 { | |
79 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(1)); | |
80 anim->setTimeOffset(4); | |
81 anim->setStartTime(4); | |
82 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0)); | |
83 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5)); | |
84 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1)); | |
85 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1)); | |
86 } | |
87 | |
88 TEST(CCActiveAnimationTest, TrimTimePauseResume) | |
89 { | |
90 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(1)); | |
91 anim->setRunState(CCActiveAnimation::Running, 0); | |
92 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0)); | |
93 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5)); | |
94 anim->setRunState(CCActiveAnimation::Paused, 0.5); | |
95 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1024)); | |
96 anim->setRunState(CCActiveAnimation::Running, 1024); | |
97 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1024)); | |
98 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1024.5)); | |
99 } | |
100 | |
101 TEST(CCActiveAnimationTest, TrimTimeSuspendResume) | |
102 { | |
103 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(1)); | |
104 anim->setRunState(CCActiveAnimation::Running, 0); | |
105 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0)); | |
106 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5)); | |
107 anim->suspend(0.5); | |
108 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1024)); | |
109 anim->resume(1024); | |
110 EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(1024)); | |
111 EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1024.5)); | |
112 } | |
113 | |
114 TEST(CCActiveAnimationTest, TrimTimeZeroDuration) | |
115 { | |
116 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(0, 0)); | |
117 anim->setRunState(CCActiveAnimation::Running, 0); | |
118 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(-1)); | |
119 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0)); | |
120 EXPECT_EQ(0, anim->trimTimeToCurrentIteration(1)); | |
121 } | |
122 | |
123 TEST(CCActiveAnimationTest, IsFinishedAtZeroIterations) | |
124 { | |
125 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(0)); | |
126 anim->setRunState(CCActiveAnimation::Running, 0); | |
127 EXPECT_FALSE(anim->isFinishedAt(-1)); | |
128 EXPECT_TRUE(anim->isFinishedAt(0)); | |
129 EXPECT_TRUE(anim->isFinishedAt(1)); | |
130 } | |
131 | |
132 TEST(CCActiveAnimationTest, IsFinishedAtOneIteration) | |
133 { | |
134 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(1)); | |
135 anim->setRunState(CCActiveAnimation::Running, 0); | |
136 EXPECT_FALSE(anim->isFinishedAt(-1)); | |
137 EXPECT_FALSE(anim->isFinishedAt(0)); | |
138 EXPECT_TRUE(anim->isFinishedAt(1)); | |
139 EXPECT_TRUE(anim->isFinishedAt(2)); | |
140 } | |
141 | |
142 TEST(CCActiveAnimationTest, IsFinishedAtInfiniteIterations) | |
143 { | |
144 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(-1)); | |
145 anim->setRunState(CCActiveAnimation::Running, 0); | |
146 EXPECT_FALSE(anim->isFinishedAt(0)); | |
147 EXPECT_FALSE(anim->isFinishedAt(0.5)); | |
148 EXPECT_FALSE(anim->isFinishedAt(1)); | |
149 EXPECT_FALSE(anim->isFinishedAt(1.5)); | |
150 } | |
151 | |
152 TEST(CCActiveAnimationTest, IsFinishedAtNotRunning) | |
153 { | |
154 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(0)); | |
155 anim->setRunState(CCActiveAnimation::Running, 0); | |
156 EXPECT_TRUE(anim->isFinishedAt(0)); | |
157 anim->setRunState(CCActiveAnimation::Paused, 0); | |
158 EXPECT_FALSE(anim->isFinishedAt(0)); | |
159 anim->setRunState(CCActiveAnimation::WaitingForNextTick, 0); | |
160 EXPECT_FALSE(anim->isFinishedAt(0)); | |
161 anim->setRunState(CCActiveAnimation::WaitingForTargetAvailability, 0); | |
162 EXPECT_FALSE(anim->isFinishedAt(0)); | |
163 anim->setRunState(CCActiveAnimation::WaitingForStartTime, 0); | |
164 EXPECT_FALSE(anim->isFinishedAt(0)); | |
165 anim->setRunState(CCActiveAnimation::Finished, 0); | |
166 EXPECT_TRUE(anim->isFinishedAt(0)); | |
167 anim->setRunState(CCActiveAnimation::Aborted, 0); | |
168 EXPECT_TRUE(anim->isFinishedAt(0)); | |
169 } | |
170 | |
171 TEST(CCActiveAnimationTest, IsFinished) | |
172 { | |
173 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(1)); | |
174 anim->setRunState(CCActiveAnimation::Running, 0); | |
175 EXPECT_FALSE(anim->isFinished()); | |
176 anim->setRunState(CCActiveAnimation::Paused, 0); | |
177 EXPECT_FALSE(anim->isFinished()); | |
178 anim->setRunState(CCActiveAnimation::WaitingForNextTick, 0); | |
179 EXPECT_FALSE(anim->isFinished()); | |
180 anim->setRunState(CCActiveAnimation::WaitingForTargetAvailability, 0); | |
181 EXPECT_FALSE(anim->isFinished()); | |
182 anim->setRunState(CCActiveAnimation::WaitingForStartTime, 0); | |
183 EXPECT_FALSE(anim->isFinished()); | |
184 anim->setRunState(CCActiveAnimation::Finished, 0); | |
185 EXPECT_TRUE(anim->isFinished()); | |
186 anim->setRunState(CCActiveAnimation::Aborted, 0); | |
187 EXPECT_TRUE(anim->isFinished()); | |
188 } | |
189 | |
190 TEST(CCActiveAnimationTest, IsFinishedNeedsSynchronizedStartTime) | |
191 { | |
192 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(1)); | |
193 anim->setRunState(CCActiveAnimation::Running, 2); | |
194 EXPECT_FALSE(anim->isFinished()); | |
195 anim->setRunState(CCActiveAnimation::Paused, 2); | |
196 EXPECT_FALSE(anim->isFinished()); | |
197 anim->setRunState(CCActiveAnimation::WaitingForNextTick, 2); | |
198 EXPECT_FALSE(anim->isFinished()); | |
199 anim->setRunState(CCActiveAnimation::WaitingForTargetAvailability, 2); | |
200 EXPECT_FALSE(anim->isFinished()); | |
201 anim->setRunState(CCActiveAnimation::WaitingForStartTime, 2); | |
202 EXPECT_FALSE(anim->isFinished()); | |
203 anim->setRunState(CCActiveAnimation::Finished, 0); | |
204 EXPECT_TRUE(anim->isFinished()); | |
205 anim->setRunState(CCActiveAnimation::Aborted, 0); | |
206 EXPECT_TRUE(anim->isFinished()); | |
207 } | |
208 | |
209 TEST(CCActiveAnimationTest, RunStateChangesIgnoredWhileSuspended) | |
210 { | |
211 scoped_ptr<CCActiveAnimation> anim(createActiveAnimation(1)); | |
212 anim->suspend(0); | |
213 EXPECT_EQ(CCActiveAnimation::Paused, anim->runState()); | |
214 anim->setRunState(CCActiveAnimation::Running, 0); | |
215 EXPECT_EQ(CCActiveAnimation::Paused, anim->runState()); | |
216 anim->resume(0); | |
217 anim->setRunState(CCActiveAnimation::Running, 0); | |
218 EXPECT_EQ(CCActiveAnimation::Running, anim->runState()); | |
219 } | |
220 | |
221 } // namespace | |
OLD | NEW |