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"
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
,
23 double playback_rate
) {
24 scoped_ptr
<Animation
> to_return(
25 Animation::Create(make_scoped_ptr(new FakeFloatAnimationCurve(duration
)),
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))
47 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
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))
57 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
59 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
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))
68 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
70 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
72 EXPECT_EQ(0.9, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.9))
74 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
76 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
78 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
82 TEST(AnimationTest
, TrimTimeInfiniteIterations
) {
83 scoped_ptr
<Animation
> anim(CreateAnimation(-1));
84 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
86 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
88 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
90 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
94 TEST(AnimationTest
, TrimTimeReverse
) {
95 scoped_ptr
<Animation
> anim(CreateAnimation(-1));
96 anim
->set_direction(Animation::Reverse
);
98 1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
99 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
101 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
103 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
105 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
107 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
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))
116 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
118 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
120 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
122 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
124 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
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))
133 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
135 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
137 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
139 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
141 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
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))
150 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
152 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
154 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
156 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
158 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
160 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
162 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
164 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
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))
173 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
175 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
177 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
179 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
181 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
183 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
185 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
187 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
189 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.50))
191 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.75))
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))
200 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
202 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
204 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
206 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
208 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
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))
217 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
219 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
221 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
223 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
225 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
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))
234 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
236 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
238 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
240 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
242 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
244 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
246 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
248 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
252 TEST(AnimationTest
, TrimTimeStartTime
) {
253 scoped_ptr
<Animation
> anim(CreateAnimation(1));
254 anim
->set_start_time(TicksFromSecondsF(4));
256 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
258 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0)).InSecondsF());
259 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
262 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
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
);
272 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
273 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
275 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
278 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
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));
288 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
289 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
292 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
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))
304 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
307 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
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));
317 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
319 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0)).InSecondsF());
320 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
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
);
332 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
333 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
335 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
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));
345 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
346 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
348 anim
->SetRunState(Animation::Paused
, TicksFromSecondsF(0.5));
349 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
351 anim
->SetRunState(Animation::Running
, TicksFromSecondsF(1024.0));
352 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
354 EXPECT_EQ(1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.5))
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))
364 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
366 anim
->SetRunState(Animation::Paused
, TicksFromSecondsF(0.25));
367 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
369 anim
->SetRunState(Animation::Running
, TicksFromSecondsF(1024.0));
370 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
372 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.75))
376 TEST(AnimationTest
, TrimTimeSuspendResume
) {
377 scoped_ptr
<Animation
> anim(CreateAnimation(1));
378 anim
->SetRunState(Animation::Running
, TicksFromSecondsF(0.0));
380 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
381 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
383 anim
->Suspend(TicksFromSecondsF(0.5));
384 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
386 anim
->Resume(TicksFromSecondsF(1024));
387 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
389 EXPECT_EQ(1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.5))
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))
399 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
401 anim
->Suspend(TicksFromSecondsF(0.75));
402 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
404 anim
->Resume(TicksFromSecondsF(1024));
405 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
407 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.25))
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))
417 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
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))
427 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
429 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
431 anim
->set_time_offset(TimeDelta::FromMilliseconds(2000));
432 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
434 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
436 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
438 anim
->set_start_time(TicksFromSecondsF(1.0));
439 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
441 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
443 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
445 EXPECT_EQ(3.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
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))
455 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
457 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
459 anim
->set_time_offset(TimeDelta::FromMilliseconds(2000));
460 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
462 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
464 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
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))
470 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
472 EXPECT_EQ(3.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
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))
588 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
589 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
592 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
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))
602 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
603 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
605 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
608 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
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))
618 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
620 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
622 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
624 3, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
626 4, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
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))
636 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
637 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
640 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
641 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
644 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
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))
654 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
655 EXPECT_EQ(1.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
657 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
659 EXPECT_EQ(1.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
662 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
663 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
666 0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3)).InSecondsF());
667 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
670 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4)).InSecondsF());
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))
680 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
681 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
684 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
685 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
688 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
690 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
693 TEST(AnimationTest
, TrimTimePlaybackFastInfiniteIterations
) {
694 scoped_ptr
<Animation
> anim(CreateAnimation(-1, 4, 4));
696 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
698 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
700 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
702 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
703 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1000.0))
705 EXPECT_EQ(2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1000.5))
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))
715 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
716 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
719 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
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))
730 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
732 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
734 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
736 3, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
738 4, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
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))
748 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
750 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
752 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
754 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
756 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
758 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
760 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
762 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
764 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
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))
773 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
775 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
777 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
779 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
781 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
783 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
785 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
787 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
789 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
791 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
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))
800 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
802 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
804 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
806 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
808 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
810 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
812 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
814 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
816 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
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))
826 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
828 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
830 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
832 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
834 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
836 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
838 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
840 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
842 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
844 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
846 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.75))
848 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
850 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.25))
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))
860 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
862 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
864 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
866 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
868 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
870 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
872 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
874 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
876 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
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))
885 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
887 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
889 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
891 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
893 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
895 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
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))
905 EXPECT_EQ(0.3, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
907 EXPECT_EQ(0.8, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
909 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.7))
911 EXPECT_EQ(0.7, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
913 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.2))
915 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.7))
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))
925 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
927 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
929 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
931 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
933 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
935 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
937 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
939 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
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))
950 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
952 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
954 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
956 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
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)));