Suppress UBSan's false positives for virtual base classes.
[chromium-blink-merge.git] / cc / animation / animation_unittest.cc
blob2522f19ee645d3d2b8137b4729b50d187a090b6b
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.
5 #include "cc/animation/animation.h"
7 #include "cc/test/animation_test_common.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace cc {
12 namespace {
14 using base::TimeDelta;
16 static base::TimeTicks TicksFromSecondsF(double seconds) {
17 return base::TimeTicks::FromInternalValue(seconds *
18 base::Time::kMicrosecondsPerSecond);
21 scoped_ptr<Animation> CreateAnimation(double iterations,
22 double duration,
23 double playback_rate) {
24 scoped_ptr<Animation> to_return(
25 Animation::Create(make_scoped_ptr(new FakeFloatAnimationCurve(duration)),
28 Animation::Opacity));
29 to_return->set_iterations(iterations);
30 to_return->set_playback_rate(playback_rate);
31 return to_return.Pass();
34 scoped_ptr<Animation> CreateAnimation(double iterations, double duration) {
35 return CreateAnimation(iterations, duration, 1);
38 scoped_ptr<Animation> CreateAnimation(double iterations) {
39 return CreateAnimation(iterations, 1, 1);
42 TEST(AnimationTest, TrimTimeZeroIterations) {
43 scoped_ptr<Animation> anim(CreateAnimation(0));
44 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
45 .InSecondsF());
46 EXPECT_EQ(
47 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
48 EXPECT_EQ(
49 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
52 TEST(AnimationTest, TrimTimeOneIteration) {
53 scoped_ptr<Animation> anim(CreateAnimation(1));
54 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
55 .InSecondsF());
56 EXPECT_EQ(
57 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
58 EXPECT_EQ(
59 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
60 EXPECT_EQ(
61 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
64 TEST(AnimationTest, TrimTimeOneHalfIteration) {
65 scoped_ptr<Animation> anim(CreateAnimation(1.5));
66 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
67 .InSecondsF());
68 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
69 .InSecondsF());
70 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
71 .InSecondsF());
72 EXPECT_EQ(0.9, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.9))
73 .InSecondsF());
74 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
75 .InSecondsF());
76 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
77 .InSecondsF());
78 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
79 .InSecondsF());
82 TEST(AnimationTest, TrimTimeInfiniteIterations) {
83 scoped_ptr<Animation> anim(CreateAnimation(-1));
84 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
85 .InSecondsF());
86 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
87 .InSecondsF());
88 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
89 .InSecondsF());
90 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
91 .InSecondsF());
94 TEST(AnimationTest, TrimTimeReverse) {
95 scoped_ptr<Animation> anim(CreateAnimation(-1));
96 anim->set_direction(Animation::Reverse);
97 EXPECT_EQ(
98 1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
99 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
100 .InSecondsF());
101 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
102 .InSecondsF());
103 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
104 .InSecondsF());
105 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
106 .InSecondsF());
107 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
108 .InSecondsF());
111 TEST(AnimationTest, TrimTimeAlternateInfiniteIterations) {
112 scoped_ptr<Animation> anim(CreateAnimation(-1));
113 anim->set_direction(Animation::Alternate);
114 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
115 .InSecondsF());
116 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
117 .InSecondsF());
118 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
119 .InSecondsF());
120 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
121 .InSecondsF());
122 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
123 .InSecondsF());
124 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
125 .InSecondsF());
128 TEST(AnimationTest, TrimTimeAlternateOneIteration) {
129 scoped_ptr<Animation> anim(CreateAnimation(1));
130 anim->set_direction(Animation::Alternate);
131 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
132 .InSecondsF());
133 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
134 .InSecondsF());
135 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
136 .InSecondsF());
137 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
138 .InSecondsF());
139 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
140 .InSecondsF());
141 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
142 .InSecondsF());
145 TEST(AnimationTest, TrimTimeAlternateTwoIterations) {
146 scoped_ptr<Animation> anim(CreateAnimation(2));
147 anim->set_direction(Animation::Alternate);
148 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
149 .InSecondsF());
150 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
151 .InSecondsF());
152 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
153 .InSecondsF());
154 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
155 .InSecondsF());
156 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
157 .InSecondsF());
158 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
159 .InSecondsF());
160 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
161 .InSecondsF());
162 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
163 .InSecondsF());
164 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
165 .InSecondsF());
168 TEST(AnimationTest, TrimTimeAlternateTwoHalfIterations) {
169 scoped_ptr<Animation> anim(CreateAnimation(2.5));
170 anim->set_direction(Animation::Alternate);
171 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
172 .InSecondsF());
173 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
174 .InSecondsF());
175 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
176 .InSecondsF());
177 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
178 .InSecondsF());
179 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
180 .InSecondsF());
181 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
182 .InSecondsF());
183 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
184 .InSecondsF());
185 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
186 .InSecondsF());
187 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
188 .InSecondsF());
189 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.50))
190 .InSecondsF());
191 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.75))
192 .InSecondsF());
195 TEST(AnimationTest, TrimTimeAlternateReverseInfiniteIterations) {
196 scoped_ptr<Animation> anim(CreateAnimation(-1));
197 anim->set_direction(Animation::AlternateReverse);
198 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
199 .InSecondsF());
200 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
201 .InSecondsF());
202 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
203 .InSecondsF());
204 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
205 .InSecondsF());
206 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
207 .InSecondsF());
208 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
209 .InSecondsF());
212 TEST(AnimationTest, TrimTimeAlternateReverseOneIteration) {
213 scoped_ptr<Animation> anim(CreateAnimation(1));
214 anim->set_direction(Animation::AlternateReverse);
215 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
216 .InSecondsF());
217 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
218 .InSecondsF());
219 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
220 .InSecondsF());
221 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
222 .InSecondsF());
223 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
224 .InSecondsF());
225 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
226 .InSecondsF());
229 TEST(AnimationTest, TrimTimeAlternateReverseTwoIterations) {
230 scoped_ptr<Animation> anim(CreateAnimation(2));
231 anim->set_direction(Animation::AlternateReverse);
232 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
233 .InSecondsF());
234 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
235 .InSecondsF());
236 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
237 .InSecondsF());
238 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
239 .InSecondsF());
240 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
241 .InSecondsF());
242 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
243 .InSecondsF());
244 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
245 .InSecondsF());
246 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
247 .InSecondsF());
248 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
249 .InSecondsF());
252 TEST(AnimationTest, TrimTimeStartTime) {
253 scoped_ptr<Animation> anim(CreateAnimation(1));
254 anim->set_start_time(TicksFromSecondsF(4));
255 EXPECT_EQ(
256 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
257 EXPECT_EQ(
258 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0)).InSecondsF());
259 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
260 .InSecondsF());
261 EXPECT_EQ(
262 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
263 EXPECT_EQ(
264 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(6.0)).InSecondsF());
267 TEST(AnimationTest, TrimTimeStartTimeReverse) {
268 scoped_ptr<Animation> anim(CreateAnimation(1));
269 anim->set_start_time(TicksFromSecondsF(4));
270 anim->set_direction(Animation::Reverse);
271 EXPECT_EQ(
272 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
273 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
274 .InSecondsF());
275 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
276 .InSecondsF());
277 EXPECT_EQ(
278 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
279 EXPECT_EQ(
280 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(6.0)).InSecondsF());
283 TEST(AnimationTest, TrimTimeTimeOffset) {
284 scoped_ptr<Animation> anim(CreateAnimation(1));
285 anim->set_time_offset(TimeDelta::FromMilliseconds(4000));
286 anim->set_start_time(TicksFromSecondsF(4));
287 EXPECT_EQ(
288 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
289 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
290 .InSecondsF());
291 EXPECT_EQ(
292 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
293 EXPECT_EQ(
294 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
297 TEST(AnimationTest, TrimTimeTimeOffsetReverse) {
298 scoped_ptr<Animation> anim(CreateAnimation(1));
299 anim->set_time_offset(TimeDelta::FromMilliseconds(4000));
300 anim->set_start_time(TicksFromSecondsF(4));
301 anim->set_direction(Animation::Reverse);
302 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
303 .InSecondsF());
304 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
305 .InSecondsF());
306 EXPECT_EQ(
307 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
308 EXPECT_EQ(
309 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
312 TEST(AnimationTest, TrimTimeNegativeTimeOffset) {
313 scoped_ptr<Animation> anim(CreateAnimation(1));
314 anim->set_time_offset(TimeDelta::FromMilliseconds(-4000));
316 EXPECT_EQ(
317 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
318 EXPECT_EQ(
319 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0)).InSecondsF());
320 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
321 .InSecondsF());
322 EXPECT_EQ(
323 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
326 TEST(AnimationTest, TrimTimeNegativeTimeOffsetReverse) {
327 scoped_ptr<Animation> anim(CreateAnimation(1));
328 anim->set_time_offset(TimeDelta::FromMilliseconds(-4000));
329 anim->set_direction(Animation::Reverse);
331 EXPECT_EQ(
332 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
333 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
334 .InSecondsF());
335 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
336 .InSecondsF());
337 EXPECT_EQ(
338 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
341 TEST(AnimationTest, TrimTimePauseResume) {
342 scoped_ptr<Animation> anim(CreateAnimation(1));
343 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
344 EXPECT_EQ(
345 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
346 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
347 .InSecondsF());
348 anim->SetRunState(Animation::Paused, TicksFromSecondsF(0.5));
349 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
350 .InSecondsF());
351 anim->SetRunState(Animation::Running, TicksFromSecondsF(1024.0));
352 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
353 .InSecondsF());
354 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.5))
355 .InSecondsF());
358 TEST(AnimationTest, TrimTimePauseResumeReverse) {
359 scoped_ptr<Animation> anim(CreateAnimation(1));
360 anim->set_direction(Animation::Reverse);
361 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
362 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
363 .InSecondsF());
364 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
365 .InSecondsF());
366 anim->SetRunState(Animation::Paused, TicksFromSecondsF(0.25));
367 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
368 .InSecondsF());
369 anim->SetRunState(Animation::Running, TicksFromSecondsF(1024.0));
370 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
371 .InSecondsF());
372 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.75))
373 .InSecondsF());
376 TEST(AnimationTest, TrimTimeSuspendResume) {
377 scoped_ptr<Animation> anim(CreateAnimation(1));
378 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
379 EXPECT_EQ(
380 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
381 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
382 .InSecondsF());
383 anim->Suspend(TicksFromSecondsF(0.5));
384 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
385 .InSecondsF());
386 anim->Resume(TicksFromSecondsF(1024));
387 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
388 .InSecondsF());
389 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.5))
390 .InSecondsF());
393 TEST(AnimationTest, TrimTimeSuspendResumeReverse) {
394 scoped_ptr<Animation> anim(CreateAnimation(1));
395 anim->set_direction(Animation::Reverse);
396 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
397 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
398 .InSecondsF());
399 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
400 .InSecondsF());
401 anim->Suspend(TicksFromSecondsF(0.75));
402 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
403 .InSecondsF());
404 anim->Resume(TicksFromSecondsF(1024));
405 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
406 .InSecondsF());
407 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.25))
408 .InSecondsF());
411 TEST(AnimationTest, TrimTimeZeroDuration) {
412 scoped_ptr<Animation> anim(CreateAnimation(0, 0));
413 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
414 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
415 .InSecondsF());
416 EXPECT_EQ(
417 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
418 EXPECT_EQ(
419 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
422 TEST(AnimationTest, TrimTimeStarting) {
423 scoped_ptr<Animation> anim(CreateAnimation(1, 5.0));
424 anim->SetRunState(Animation::Starting, TicksFromSecondsF(0.0));
425 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
426 .InSecondsF());
427 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
428 .InSecondsF());
429 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
430 .InSecondsF());
431 anim->set_time_offset(TimeDelta::FromMilliseconds(2000));
432 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
433 .InSecondsF());
434 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
435 .InSecondsF());
436 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
437 .InSecondsF());
438 anim->set_start_time(TicksFromSecondsF(1.0));
439 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
440 .InSecondsF());
441 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
442 .InSecondsF());
443 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
444 .InSecondsF());
445 EXPECT_EQ(3.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
446 .InSecondsF());
449 TEST(AnimationTest, TrimTimeNeedsSynchronizedStartTime) {
450 scoped_ptr<Animation> anim(CreateAnimation(1, 5.0));
451 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
452 anim->set_needs_synchronized_start_time(true);
453 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
454 .InSecondsF());
455 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
456 .InSecondsF());
457 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
458 .InSecondsF());
459 anim->set_time_offset(TimeDelta::FromMilliseconds(2000));
460 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
461 .InSecondsF());
462 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
463 .InSecondsF());
464 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
465 .InSecondsF());
466 anim->set_start_time(TicksFromSecondsF(1.0));
467 anim->set_needs_synchronized_start_time(false);
468 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
469 .InSecondsF());
470 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
471 .InSecondsF());
472 EXPECT_EQ(3.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
473 .InSecondsF());
476 TEST(AnimationTest, IsFinishedAtZeroIterations) {
477 scoped_ptr<Animation> anim(CreateAnimation(0));
478 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
479 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(-1.0)));
480 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(0.0)));
481 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(1.0)));
484 TEST(AnimationTest, IsFinishedAtOneIteration) {
485 scoped_ptr<Animation> anim(CreateAnimation(1));
486 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
487 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(-1.0)));
488 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(0.0)));
489 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(1.0)));
490 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(2.0)));
493 TEST(AnimationTest, IsFinishedAtInfiniteIterations) {
494 scoped_ptr<Animation> anim(CreateAnimation(-1));
495 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
496 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(0.0)));
497 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(0.5)));
498 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(1.0)));
499 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(1.5)));
502 TEST(AnimationTest, IsFinishedNegativeTimeOffset) {
503 scoped_ptr<Animation> anim(CreateAnimation(1));
504 anim->set_time_offset(TimeDelta::FromMilliseconds(-500));
505 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
507 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(-1.0)));
508 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(0.0)));
509 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(0.5)));
510 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(1.0)));
511 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(1.5)));
512 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(2.0)));
513 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(2.5)));
516 TEST(AnimationTest, IsFinishedPositiveTimeOffset) {
517 scoped_ptr<Animation> anim(CreateAnimation(1));
518 anim->set_time_offset(TimeDelta::FromMilliseconds(500));
519 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
521 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(-1.0)));
522 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(0.0)));
523 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(0.5)));
524 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(1.0)));
527 TEST(AnimationTest, IsFinishedAtNotRunning) {
528 scoped_ptr<Animation> anim(CreateAnimation(0));
529 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
530 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(0.0)));
531 anim->SetRunState(Animation::Paused, TicksFromSecondsF(0.0));
532 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(0.0)));
533 anim->SetRunState(Animation::WaitingForTargetAvailability,
534 TicksFromSecondsF(0.0));
535 EXPECT_FALSE(anim->IsFinishedAt(TicksFromSecondsF(0.0)));
536 anim->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
537 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(0.0)));
538 anim->SetRunState(Animation::Aborted, TicksFromSecondsF(0.0));
539 EXPECT_TRUE(anim->IsFinishedAt(TicksFromSecondsF(0.0)));
542 TEST(AnimationTest, IsFinished) {
543 scoped_ptr<Animation> anim(CreateAnimation(1));
544 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
545 EXPECT_FALSE(anim->is_finished());
546 anim->SetRunState(Animation::Paused, TicksFromSecondsF(0.0));
547 EXPECT_FALSE(anim->is_finished());
548 anim->SetRunState(Animation::WaitingForTargetAvailability,
549 TicksFromSecondsF(0.0));
550 EXPECT_FALSE(anim->is_finished());
551 anim->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
552 EXPECT_TRUE(anim->is_finished());
553 anim->SetRunState(Animation::Aborted, TicksFromSecondsF(0.0));
554 EXPECT_TRUE(anim->is_finished());
557 TEST(AnimationTest, IsFinishedNeedsSynchronizedStartTime) {
558 scoped_ptr<Animation> anim(CreateAnimation(1));
559 anim->SetRunState(Animation::Running, TicksFromSecondsF(2.0));
560 EXPECT_FALSE(anim->is_finished());
561 anim->SetRunState(Animation::Paused, TicksFromSecondsF(2.0));
562 EXPECT_FALSE(anim->is_finished());
563 anim->SetRunState(Animation::WaitingForTargetAvailability,
564 TicksFromSecondsF(2.0));
565 EXPECT_FALSE(anim->is_finished());
566 anim->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
567 EXPECT_TRUE(anim->is_finished());
568 anim->SetRunState(Animation::Aborted, TicksFromSecondsF(0.0));
569 EXPECT_TRUE(anim->is_finished());
572 TEST(AnimationTest, RunStateChangesIgnoredWhileSuspended) {
573 scoped_ptr<Animation> anim(CreateAnimation(1));
574 anim->Suspend(TicksFromSecondsF(0));
575 EXPECT_EQ(Animation::Paused, anim->run_state());
576 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
577 EXPECT_EQ(Animation::Paused, anim->run_state());
578 anim->Resume(TicksFromSecondsF(0));
579 anim->SetRunState(Animation::Running, TicksFromSecondsF(0.0));
580 EXPECT_EQ(Animation::Running, anim->run_state());
583 TEST(AnimationTest, TrimTimePlaybackNormal) {
584 scoped_ptr<Animation> anim(CreateAnimation(1, 1, 1));
585 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
586 .InSecondsF());
587 EXPECT_EQ(
588 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
589 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
590 .InSecondsF());
591 EXPECT_EQ(
592 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
593 EXPECT_EQ(
594 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
597 TEST(AnimationTest, TrimTimePlaybackSlow) {
598 scoped_ptr<Animation> anim(CreateAnimation(1, 1, 0.5));
599 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
600 .InSecondsF());
601 EXPECT_EQ(
602 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
603 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
604 .InSecondsF());
605 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
606 .InSecondsF());
607 EXPECT_EQ(
608 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
609 EXPECT_EQ(
610 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0)).InSecondsF());
613 TEST(AnimationTest, TrimTimePlaybackFast) {
614 scoped_ptr<Animation> anim(CreateAnimation(1, 4, 2));
615 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
616 .InSecondsF());
617 EXPECT_EQ(
618 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
619 EXPECT_EQ(
620 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
621 EXPECT_EQ(
622 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
623 EXPECT_EQ(
624 3, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
625 EXPECT_EQ(
626 4, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
627 EXPECT_EQ(
628 4, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5)).InSecondsF());
631 TEST(AnimationTest, TrimTimePlaybackNormalReverse) {
632 scoped_ptr<Animation> anim(CreateAnimation(1, 2, -1));
633 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
634 .InSecondsF());
635 EXPECT_EQ(
636 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
637 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
638 .InSecondsF());
639 EXPECT_EQ(
640 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
641 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
642 .InSecondsF());
643 EXPECT_EQ(
644 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
645 EXPECT_EQ(
646 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5)).InSecondsF());
649 TEST(AnimationTest, TrimTimePlaybackSlowReverse) {
650 scoped_ptr<Animation> anim(CreateAnimation(1, 2, -0.5));
651 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
652 .InSecondsF());
653 EXPECT_EQ(
654 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
655 EXPECT_EQ(1.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
656 .InSecondsF());
657 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
658 .InSecondsF());
659 EXPECT_EQ(1.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
660 .InSecondsF());
661 EXPECT_EQ(
662 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
663 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
664 .InSecondsF());
665 EXPECT_EQ(
666 0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3)).InSecondsF());
667 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
668 .InSecondsF());
669 EXPECT_EQ(
670 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4)).InSecondsF());
671 EXPECT_EQ(
672 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5)).InSecondsF());
675 TEST(AnimationTest, TrimTimePlaybackFastReverse) {
676 scoped_ptr<Animation> anim(CreateAnimation(1, 2, -2));
677 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
678 .InSecondsF());
679 EXPECT_EQ(
680 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
681 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
682 .InSecondsF());
683 EXPECT_EQ(
684 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
685 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
686 .InSecondsF());
687 EXPECT_EQ(
688 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
689 EXPECT_EQ(
690 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
693 TEST(AnimationTest, TrimTimePlaybackFastInfiniteIterations) {
694 scoped_ptr<Animation> anim(CreateAnimation(-1, 4, 4));
695 EXPECT_EQ(
696 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
697 EXPECT_EQ(
698 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
699 EXPECT_EQ(
700 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
701 EXPECT_EQ(
702 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
703 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1000.0))
704 .InSecondsF());
705 EXPECT_EQ(2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1000.5))
706 .InSecondsF());
709 TEST(AnimationTest, TrimTimePlaybackNormalDoubleReverse) {
710 scoped_ptr<Animation> anim(CreateAnimation(1, 1, -1));
711 anim->set_direction(Animation::Reverse);
712 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
713 .InSecondsF());
714 EXPECT_EQ(
715 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
716 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
717 .InSecondsF());
718 EXPECT_EQ(
719 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
720 EXPECT_EQ(
721 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
724 TEST(AnimationTest, TrimTimePlaybackFastDoubleReverse) {
725 scoped_ptr<Animation> anim(CreateAnimation(1, 4, -2));
726 anim->set_direction(Animation::Reverse);
727 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
728 .InSecondsF());
729 EXPECT_EQ(
730 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
731 EXPECT_EQ(
732 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
733 EXPECT_EQ(
734 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
735 EXPECT_EQ(
736 3, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
737 EXPECT_EQ(
738 4, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
739 EXPECT_EQ(
740 4, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5)).InSecondsF());
743 TEST(AnimationTest, TrimTimeAlternateTwoIterationsPlaybackFast) {
744 scoped_ptr<Animation> anim(CreateAnimation(2, 2, 2));
745 anim->set_direction(Animation::Alternate);
746 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
747 .InSecondsF());
748 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
749 .InSecondsF());
750 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
751 .InSecondsF());
752 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
753 .InSecondsF());
754 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
755 .InSecondsF());
756 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
757 .InSecondsF());
758 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
759 .InSecondsF());
760 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
761 .InSecondsF());
762 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
763 .InSecondsF());
764 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
765 .InSecondsF());
768 TEST(AnimationTest, TrimTimeAlternateTwoIterationsPlaybackFastReverse) {
769 scoped_ptr<Animation> anim(CreateAnimation(2, 2, 2));
770 anim->set_direction(Animation::AlternateReverse);
771 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
772 .InSecondsF());
773 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
774 .InSecondsF());
775 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
776 .InSecondsF());
777 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
778 .InSecondsF());
779 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
780 .InSecondsF());
781 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
782 .InSecondsF());
783 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
784 .InSecondsF());
785 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
786 .InSecondsF());
787 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
788 .InSecondsF());
789 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
790 .InSecondsF());
791 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
792 .InSecondsF());
795 TEST(AnimationTest, TrimTimeAlternateTwoIterationsPlaybackFastDoubleReverse) {
796 scoped_ptr<Animation> anim(CreateAnimation(2, 2, -2));
797 anim->set_direction(Animation::AlternateReverse);
798 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
799 .InSecondsF());
800 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
801 .InSecondsF());
802 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
803 .InSecondsF());
804 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
805 .InSecondsF());
806 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
807 .InSecondsF());
808 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
809 .InSecondsF());
810 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
811 .InSecondsF());
812 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
813 .InSecondsF());
814 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
815 .InSecondsF());
816 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
817 .InSecondsF());
820 TEST(AnimationTest,
821 TrimTimeAlternateReverseThreeIterationsPlaybackFastAlternateReverse) {
822 scoped_ptr<Animation> anim(CreateAnimation(3, 2, -2));
823 anim->set_direction(Animation::AlternateReverse);
824 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
825 .InSecondsF());
826 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
827 .InSecondsF());
828 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
829 .InSecondsF());
830 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
831 .InSecondsF());
832 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
833 .InSecondsF());
834 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
835 .InSecondsF());
836 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
837 .InSecondsF());
838 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
839 .InSecondsF());
840 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
841 .InSecondsF());
842 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
843 .InSecondsF());
844 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
845 .InSecondsF());
846 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.75))
847 .InSecondsF());
848 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
849 .InSecondsF());
850 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.25))
851 .InSecondsF());
854 TEST(AnimationTest,
855 TrimTimeAlternateReverseTwoIterationsPlaybackNormalAlternate) {
856 scoped_ptr<Animation> anim(CreateAnimation(2, 2, -1));
857 anim->set_direction(Animation::Alternate);
858 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
859 .InSecondsF());
860 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
861 .InSecondsF());
862 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
863 .InSecondsF());
864 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
865 .InSecondsF());
866 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
867 .InSecondsF());
868 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
869 .InSecondsF());
870 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
871 .InSecondsF());
872 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
873 .InSecondsF());
874 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
875 .InSecondsF());
876 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
877 .InSecondsF());
880 TEST(AnimationTest, TrimTimeIterationStart) {
881 scoped_ptr<Animation> anim(CreateAnimation(2, 1, 1));
882 anim->set_iteration_start(0.5);
883 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
884 .InSecondsF());
885 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
886 .InSecondsF());
887 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
888 .InSecondsF());
889 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
890 .InSecondsF());
891 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
892 .InSecondsF());
893 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
894 .InSecondsF());
895 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
896 .InSecondsF());
899 TEST(AnimationTest, TrimTimeIterationStartAlternate) {
900 scoped_ptr<Animation> anim(CreateAnimation(2, 1, 1));
901 anim->set_direction(Animation::Alternate);
902 anim->set_iteration_start(0.3);
903 EXPECT_EQ(0.3, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
904 .InSecondsF());
905 EXPECT_EQ(0.3, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
906 .InSecondsF());
907 EXPECT_EQ(0.8, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
908 .InSecondsF());
909 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.7))
910 .InSecondsF());
911 EXPECT_EQ(0.7, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
912 .InSecondsF());
913 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.2))
914 .InSecondsF());
915 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.7))
916 .InSecondsF());
919 TEST(AnimationTest, TrimTimeIterationStartAlternateThreeIterations) {
920 scoped_ptr<Animation> anim(CreateAnimation(3, 1, 1));
921 anim->set_direction(Animation::Alternate);
922 anim->set_iteration_start(1);
923 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
924 .InSecondsF());
925 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
926 .InSecondsF());
927 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
928 .InSecondsF());
929 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
930 .InSecondsF());
931 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
932 .InSecondsF());
933 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
934 .InSecondsF());
935 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
936 .InSecondsF());
937 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
938 .InSecondsF());
939 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
940 .InSecondsF());
943 TEST(AnimationTest,
944 TrimTimeIterationStartAlternateThreeIterationsPlaybackReverse) {
945 scoped_ptr<Animation> anim(CreateAnimation(3, 1, -1));
946 anim->set_direction(Animation::Alternate);
947 anim->set_iteration_start(1);
948 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
949 .InSecondsF());
950 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
951 .InSecondsF());
952 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
953 .InSecondsF());
954 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
955 .InSecondsF());
956 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
957 .InSecondsF());
960 TEST(AnimationTest, InEffectFillMode) {
961 scoped_ptr<Animation> anim(CreateAnimation(1));
962 anim->set_fill_mode(Animation::FillModeNone);
963 EXPECT_FALSE(anim->InEffect(TicksFromSecondsF(-1.0)));
964 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(0.0)));
965 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(1.0)));
967 anim->set_fill_mode(Animation::FillModeForwards);
968 EXPECT_FALSE(anim->InEffect(TicksFromSecondsF(-1.0)));
969 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(0.0)));
970 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(1.0)));
972 anim->set_fill_mode(Animation::FillModeBackwards);
973 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(-1.0)));
974 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(0.0)));
975 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(1.0)));
977 anim->set_fill_mode(Animation::FillModeBoth);
978 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(-1.0)));
979 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(0.0)));
980 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(1.0)));
983 TEST(AnimationTest, InEffectFillModePlayback) {
984 scoped_ptr<Animation> anim(CreateAnimation(1, 1, -1));
985 anim->set_fill_mode(Animation::FillModeNone);
986 EXPECT_FALSE(anim->InEffect(TicksFromSecondsF(-1.0)));
987 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(0.0)));
988 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(1.0)));
990 anim->set_fill_mode(Animation::FillModeForwards);
991 EXPECT_FALSE(anim->InEffect(TicksFromSecondsF(-1.0)));
992 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(0.0)));
993 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(1.0)));
995 anim->set_fill_mode(Animation::FillModeBackwards);
996 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(-1.0)));
997 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(0.0)));
998 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(1.0)));
1000 anim->set_fill_mode(Animation::FillModeBoth);
1001 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(-1.0)));
1002 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(0.0)));
1003 EXPECT_TRUE(anim->InEffect(TicksFromSecondsF(1.0)));
1006 } // namespace
1007 } // namespace cc