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
)),
26 0, 1, Animation::OPACITY
));
27 to_return
->set_iterations(iterations
);
28 to_return
->set_playback_rate(playback_rate
);
29 return to_return
.Pass();
32 scoped_ptr
<Animation
> CreateAnimation(double iterations
, double duration
) {
33 return CreateAnimation(iterations
, duration
, 1);
36 scoped_ptr
<Animation
> CreateAnimation(double iterations
) {
37 return CreateAnimation(iterations
, 1, 1);
40 TEST(AnimationTest
, TrimTimeZeroIterations
) {
41 scoped_ptr
<Animation
> anim(CreateAnimation(0));
42 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
45 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
47 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
50 TEST(AnimationTest
, TrimTimeOneIteration
) {
51 scoped_ptr
<Animation
> anim(CreateAnimation(1));
52 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
55 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
57 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
59 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
62 TEST(AnimationTest
, TrimTimeOneHalfIteration
) {
63 scoped_ptr
<Animation
> anim(CreateAnimation(1.5));
64 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
66 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
68 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
70 EXPECT_EQ(0.9, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.9))
72 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
74 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
76 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
80 TEST(AnimationTest
, TrimTimeInfiniteIterations
) {
81 scoped_ptr
<Animation
> anim(CreateAnimation(-1));
82 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
84 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
86 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
88 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
92 TEST(AnimationTest
, TrimTimeReverse
) {
93 scoped_ptr
<Animation
> anim(CreateAnimation(-1));
94 anim
->set_direction(Animation::DIRECTION_REVERSE
);
96 1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
97 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
99 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
101 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
103 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
105 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
109 TEST(AnimationTest
, TrimTimeAlternateInfiniteIterations
) {
110 scoped_ptr
<Animation
> anim(CreateAnimation(-1));
111 anim
->set_direction(Animation::DIRECTION_ALTERNATE
);
112 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
114 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
116 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
118 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
120 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
122 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
126 TEST(AnimationTest
, TrimTimeAlternateOneIteration
) {
127 scoped_ptr
<Animation
> anim(CreateAnimation(1));
128 anim
->set_direction(Animation::DIRECTION_ALTERNATE
);
129 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
131 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
133 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
135 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
137 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
139 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
143 TEST(AnimationTest
, TrimTimeAlternateTwoIterations
) {
144 scoped_ptr
<Animation
> anim(CreateAnimation(2));
145 anim
->set_direction(Animation::DIRECTION_ALTERNATE
);
146 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
148 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
150 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
152 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
154 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
156 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
158 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
160 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
162 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
166 TEST(AnimationTest
, TrimTimeAlternateTwoHalfIterations
) {
167 scoped_ptr
<Animation
> anim(CreateAnimation(2.5));
168 anim
->set_direction(Animation::DIRECTION_ALTERNATE
);
169 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
171 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
173 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
175 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
177 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
179 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
181 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
183 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
185 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
187 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.50))
189 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.75))
193 TEST(AnimationTest
, TrimTimeAlternateReverseInfiniteIterations
) {
194 scoped_ptr
<Animation
> anim(CreateAnimation(-1));
195 anim
->set_direction(Animation::DIRECTION_ALTERNATE_REVERSE
);
196 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
198 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
200 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
202 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
204 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
206 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
210 TEST(AnimationTest
, TrimTimeAlternateReverseOneIteration
) {
211 scoped_ptr
<Animation
> anim(CreateAnimation(1));
212 anim
->set_direction(Animation::DIRECTION_ALTERNATE_REVERSE
);
213 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
215 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
217 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
219 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
221 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
223 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
227 TEST(AnimationTest
, TrimTimeAlternateReverseTwoIterations
) {
228 scoped_ptr
<Animation
> anim(CreateAnimation(2));
229 anim
->set_direction(Animation::DIRECTION_ALTERNATE_REVERSE
);
230 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
232 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
234 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
236 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
238 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
240 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
242 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
244 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
246 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
250 TEST(AnimationTest
, TrimTimeStartTime
) {
251 scoped_ptr
<Animation
> anim(CreateAnimation(1));
252 anim
->set_start_time(TicksFromSecondsF(4));
254 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
256 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0)).InSecondsF());
257 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
260 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
262 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(6.0)).InSecondsF());
265 TEST(AnimationTest
, TrimTimeStartTimeReverse
) {
266 scoped_ptr
<Animation
> anim(CreateAnimation(1));
267 anim
->set_start_time(TicksFromSecondsF(4));
268 anim
->set_direction(Animation::DIRECTION_REVERSE
);
270 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
271 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
273 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
276 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
278 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(6.0)).InSecondsF());
281 TEST(AnimationTest
, TrimTimeTimeOffset
) {
282 scoped_ptr
<Animation
> anim(CreateAnimation(1));
283 anim
->set_time_offset(TimeDelta::FromMilliseconds(4000));
284 anim
->set_start_time(TicksFromSecondsF(4));
286 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
287 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
290 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
292 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
295 TEST(AnimationTest
, TrimTimeTimeOffsetReverse
) {
296 scoped_ptr
<Animation
> anim(CreateAnimation(1));
297 anim
->set_time_offset(TimeDelta::FromMilliseconds(4000));
298 anim
->set_start_time(TicksFromSecondsF(4));
299 anim
->set_direction(Animation::DIRECTION_REVERSE
);
300 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
302 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
305 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
307 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
310 TEST(AnimationTest
, TrimTimeNegativeTimeOffset
) {
311 scoped_ptr
<Animation
> anim(CreateAnimation(1));
312 anim
->set_time_offset(TimeDelta::FromMilliseconds(-4000));
315 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
317 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0)).InSecondsF());
318 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
321 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
324 TEST(AnimationTest
, TrimTimeNegativeTimeOffsetReverse
) {
325 scoped_ptr
<Animation
> anim(CreateAnimation(1));
326 anim
->set_time_offset(TimeDelta::FromMilliseconds(-4000));
327 anim
->set_direction(Animation::DIRECTION_REVERSE
);
330 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
331 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
333 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
336 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
339 TEST(AnimationTest
, TrimTimePauseResume
) {
340 scoped_ptr
<Animation
> anim(CreateAnimation(1));
341 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
343 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
344 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
346 anim
->SetRunState(Animation::PAUSED
, TicksFromSecondsF(0.5));
347 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
349 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(1024.0));
350 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
352 EXPECT_EQ(1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.5))
356 TEST(AnimationTest
, TrimTimePauseResumeReverse
) {
357 scoped_ptr
<Animation
> anim(CreateAnimation(1));
358 anim
->set_direction(Animation::DIRECTION_REVERSE
);
359 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
360 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
362 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
364 anim
->SetRunState(Animation::PAUSED
, TicksFromSecondsF(0.25));
365 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
367 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(1024.0));
368 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
370 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.75))
374 TEST(AnimationTest
, TrimTimeSuspendResume
) {
375 scoped_ptr
<Animation
> anim(CreateAnimation(1));
376 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
378 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
379 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
381 anim
->Suspend(TicksFromSecondsF(0.5));
382 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
384 anim
->Resume(TicksFromSecondsF(1024));
385 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
387 EXPECT_EQ(1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.5))
391 TEST(AnimationTest
, TrimTimeSuspendResumeReverse
) {
392 scoped_ptr
<Animation
> anim(CreateAnimation(1));
393 anim
->set_direction(Animation::DIRECTION_REVERSE
);
394 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
395 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
397 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
399 anim
->Suspend(TicksFromSecondsF(0.75));
400 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
402 anim
->Resume(TicksFromSecondsF(1024));
403 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
405 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.25))
409 TEST(AnimationTest
, TrimTimeZeroDuration
) {
410 scoped_ptr
<Animation
> anim(CreateAnimation(0, 0));
411 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
412 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
415 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
417 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
420 TEST(AnimationTest
, TrimTimeStarting
) {
421 scoped_ptr
<Animation
> anim(CreateAnimation(1, 5.0));
422 anim
->SetRunState(Animation::STARTING
, TicksFromSecondsF(0.0));
423 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
425 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
427 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
429 anim
->set_time_offset(TimeDelta::FromMilliseconds(2000));
430 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
432 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
434 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
436 anim
->set_start_time(TicksFromSecondsF(1.0));
437 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
439 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
441 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
443 EXPECT_EQ(3.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
447 TEST(AnimationTest
, TrimTimeNeedsSynchronizedStartTime
) {
448 scoped_ptr
<Animation
> anim(CreateAnimation(1, 5.0));
449 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
450 anim
->set_needs_synchronized_start_time(true);
451 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
453 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
455 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
457 anim
->set_time_offset(TimeDelta::FromMilliseconds(2000));
458 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
460 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
462 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
464 anim
->set_start_time(TicksFromSecondsF(1.0));
465 anim
->set_needs_synchronized_start_time(false);
466 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
468 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
470 EXPECT_EQ(3.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
474 TEST(AnimationTest
, IsFinishedAtZeroIterations
) {
475 scoped_ptr
<Animation
> anim(CreateAnimation(0));
476 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
477 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(-1.0)));
478 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(0.0)));
479 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(1.0)));
482 TEST(AnimationTest
, IsFinishedAtOneIteration
) {
483 scoped_ptr
<Animation
> anim(CreateAnimation(1));
484 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
485 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(-1.0)));
486 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(0.0)));
487 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(1.0)));
488 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(2.0)));
491 TEST(AnimationTest
, IsFinishedAtInfiniteIterations
) {
492 scoped_ptr
<Animation
> anim(CreateAnimation(-1));
493 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
494 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(0.0)));
495 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(0.5)));
496 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(1.0)));
497 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(1.5)));
500 TEST(AnimationTest
, IsFinishedNegativeTimeOffset
) {
501 scoped_ptr
<Animation
> anim(CreateAnimation(1));
502 anim
->set_time_offset(TimeDelta::FromMilliseconds(-500));
503 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
505 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(-1.0)));
506 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(0.0)));
507 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(0.5)));
508 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(1.0)));
509 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(1.5)));
510 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(2.0)));
511 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(2.5)));
514 TEST(AnimationTest
, IsFinishedPositiveTimeOffset
) {
515 scoped_ptr
<Animation
> anim(CreateAnimation(1));
516 anim
->set_time_offset(TimeDelta::FromMilliseconds(500));
517 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
519 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(-1.0)));
520 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(0.0)));
521 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(0.5)));
522 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(1.0)));
525 TEST(AnimationTest
, IsFinishedAtNotRunning
) {
526 scoped_ptr
<Animation
> anim(CreateAnimation(0));
527 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
528 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(0.0)));
529 anim
->SetRunState(Animation::PAUSED
, TicksFromSecondsF(0.0));
530 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(0.0)));
531 anim
->SetRunState(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
532 TicksFromSecondsF(0.0));
533 EXPECT_FALSE(anim
->IsFinishedAt(TicksFromSecondsF(0.0)));
534 anim
->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
535 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(0.0)));
536 anim
->SetRunState(Animation::ABORTED
, TicksFromSecondsF(0.0));
537 EXPECT_TRUE(anim
->IsFinishedAt(TicksFromSecondsF(0.0)));
540 TEST(AnimationTest
, IsFinished
) {
541 scoped_ptr
<Animation
> anim(CreateAnimation(1));
542 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
543 EXPECT_FALSE(anim
->is_finished());
544 anim
->SetRunState(Animation::PAUSED
, TicksFromSecondsF(0.0));
545 EXPECT_FALSE(anim
->is_finished());
546 anim
->SetRunState(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
547 TicksFromSecondsF(0.0));
548 EXPECT_FALSE(anim
->is_finished());
549 anim
->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
550 EXPECT_TRUE(anim
->is_finished());
551 anim
->SetRunState(Animation::ABORTED
, TicksFromSecondsF(0.0));
552 EXPECT_TRUE(anim
->is_finished());
555 TEST(AnimationTest
, IsFinishedNeedsSynchronizedStartTime
) {
556 scoped_ptr
<Animation
> anim(CreateAnimation(1));
557 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(2.0));
558 EXPECT_FALSE(anim
->is_finished());
559 anim
->SetRunState(Animation::PAUSED
, TicksFromSecondsF(2.0));
560 EXPECT_FALSE(anim
->is_finished());
561 anim
->SetRunState(Animation::WAITING_FOR_TARGET_AVAILABILITY
,
562 TicksFromSecondsF(2.0));
563 EXPECT_FALSE(anim
->is_finished());
564 anim
->SetRunState(Animation::FINISHED
, TicksFromSecondsF(0.0));
565 EXPECT_TRUE(anim
->is_finished());
566 anim
->SetRunState(Animation::ABORTED
, TicksFromSecondsF(0.0));
567 EXPECT_TRUE(anim
->is_finished());
570 TEST(AnimationTest
, RunStateChangesIgnoredWhileSuspended
) {
571 scoped_ptr
<Animation
> anim(CreateAnimation(1));
572 anim
->Suspend(TicksFromSecondsF(0));
573 EXPECT_EQ(Animation::PAUSED
, anim
->run_state());
574 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
575 EXPECT_EQ(Animation::PAUSED
, anim
->run_state());
576 anim
->Resume(TicksFromSecondsF(0));
577 anim
->SetRunState(Animation::RUNNING
, TicksFromSecondsF(0.0));
578 EXPECT_EQ(Animation::RUNNING
, anim
->run_state());
581 TEST(AnimationTest
, TrimTimePlaybackNormal
) {
582 scoped_ptr
<Animation
> anim(CreateAnimation(1, 1, 1));
583 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
586 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
587 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
590 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
592 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
595 TEST(AnimationTest
, TrimTimePlaybackSlow
) {
596 scoped_ptr
<Animation
> anim(CreateAnimation(1, 1, 0.5));
597 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
600 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
601 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
603 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
606 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
608 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0)).InSecondsF());
611 TEST(AnimationTest
, TrimTimePlaybackFast
) {
612 scoped_ptr
<Animation
> anim(CreateAnimation(1, 4, 2));
613 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
616 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
618 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
620 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
622 3, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
624 4, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
626 4, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5)).InSecondsF());
629 TEST(AnimationTest
, TrimTimePlaybackNormalReverse
) {
630 scoped_ptr
<Animation
> anim(CreateAnimation(1, 2, -1));
631 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
634 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
635 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
638 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
639 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
642 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
644 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5)).InSecondsF());
647 TEST(AnimationTest
, TrimTimePlaybackSlowReverse
) {
648 scoped_ptr
<Animation
> anim(CreateAnimation(1, 2, -0.5));
649 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
652 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
653 EXPECT_EQ(1.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
655 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
657 EXPECT_EQ(1.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
660 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
661 EXPECT_EQ(0.75, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
664 0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3)).InSecondsF());
665 EXPECT_EQ(0.25, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
668 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4)).InSecondsF());
670 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5)).InSecondsF());
673 TEST(AnimationTest
, TrimTimePlaybackFastReverse
) {
674 scoped_ptr
<Animation
> anim(CreateAnimation(1, 2, -2));
675 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
678 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
679 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
682 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
683 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
686 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
688 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
691 TEST(AnimationTest
, TrimTimePlaybackFastInfiniteIterations
) {
692 scoped_ptr
<Animation
> anim(CreateAnimation(-1, 4, 4));
694 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
696 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
698 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
700 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
701 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1000.0))
703 EXPECT_EQ(2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1000.5))
707 TEST(AnimationTest
, TrimTimePlaybackNormalDoubleReverse
) {
708 scoped_ptr
<Animation
> anim(CreateAnimation(1, 1, -1));
709 anim
->set_direction(Animation::DIRECTION_REVERSE
);
710 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
713 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
714 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
717 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
719 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
722 TEST(AnimationTest
, TrimTimePlaybackFastDoubleReverse
) {
723 scoped_ptr
<Animation
> anim(CreateAnimation(1, 4, -2));
724 anim
->set_direction(Animation::DIRECTION_REVERSE
);
725 EXPECT_EQ(0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
728 0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
730 1, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
732 2, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
734 3, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
736 4, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
738 4, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5)).InSecondsF());
741 TEST(AnimationTest
, TrimTimeAlternateTwoIterationsPlaybackFast
) {
742 scoped_ptr
<Animation
> anim(CreateAnimation(2, 2, 2));
743 anim
->set_direction(Animation::DIRECTION_ALTERNATE
);
744 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
746 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
748 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
750 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
752 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
754 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
756 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
758 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
760 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
762 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
766 TEST(AnimationTest
, TrimTimeAlternateTwoIterationsPlaybackFastReverse
) {
767 scoped_ptr
<Animation
> anim(CreateAnimation(2, 2, 2));
768 anim
->set_direction(Animation::DIRECTION_ALTERNATE_REVERSE
);
769 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
771 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
773 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
775 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
777 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
779 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
781 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
783 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
785 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
787 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
789 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
793 TEST(AnimationTest
, TrimTimeAlternateTwoIterationsPlaybackFastDoubleReverse
) {
794 scoped_ptr
<Animation
> anim(CreateAnimation(2, 2, -2));
795 anim
->set_direction(Animation::DIRECTION_ALTERNATE_REVERSE
);
796 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
798 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
800 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
802 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
804 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
806 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
808 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
810 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
812 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
814 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
819 TrimTimeAlternateReverseThreeIterationsPlaybackFastAlternateReverse
) {
820 scoped_ptr
<Animation
> anim(CreateAnimation(3, 2, -2));
821 anim
->set_direction(Animation::DIRECTION_ALTERNATE_REVERSE
);
822 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
824 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
826 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
828 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
830 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
832 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
834 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
836 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
838 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
840 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
842 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
844 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.75))
846 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
848 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.25))
853 TrimTimeAlternateReverseTwoIterationsPlaybackNormalAlternate
) {
854 scoped_ptr
<Animation
> anim(CreateAnimation(2, 2, -1));
855 anim
->set_direction(Animation::DIRECTION_ALTERNATE
);
856 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
858 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
860 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
862 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
864 EXPECT_EQ(2.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
866 EXPECT_EQ(1.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
868 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
870 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
872 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
874 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
878 TEST(AnimationTest
, TrimTimeIterationStart
) {
879 scoped_ptr
<Animation
> anim(CreateAnimation(2, 1, 1));
880 anim
->set_iteration_start(0.5);
881 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
883 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
885 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
887 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
889 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
891 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
893 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
897 TEST(AnimationTest
, TrimTimeIterationStartAlternate
) {
898 scoped_ptr
<Animation
> anim(CreateAnimation(2, 1, 1));
899 anim
->set_direction(Animation::DIRECTION_ALTERNATE
);
900 anim
->set_iteration_start(0.3);
901 EXPECT_EQ(0.3, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
903 EXPECT_EQ(0.3, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
905 EXPECT_EQ(0.8, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
907 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.7))
909 EXPECT_EQ(0.7, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
911 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.2))
913 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.7))
917 TEST(AnimationTest
, TrimTimeIterationStartAlternateThreeIterations
) {
918 scoped_ptr
<Animation
> anim(CreateAnimation(3, 1, 1));
919 anim
->set_direction(Animation::DIRECTION_ALTERNATE
);
920 anim
->set_iteration_start(1);
921 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
923 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
925 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
927 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
929 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
931 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
933 EXPECT_EQ(0.5, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
935 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
937 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
942 TrimTimeIterationStartAlternateThreeIterationsPlaybackReverse
) {
943 scoped_ptr
<Animation
> anim(CreateAnimation(3, 1, -1));
944 anim
->set_direction(Animation::DIRECTION_ALTERNATE
);
945 anim
->set_iteration_start(1);
946 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
948 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
950 EXPECT_EQ(0.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
952 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
954 EXPECT_EQ(1.0, anim
->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
958 TEST(AnimationTest
, InEffectFillMode
) {
959 scoped_ptr
<Animation
> anim(CreateAnimation(1));
960 anim
->set_fill_mode(Animation::FILL_MODE_NONE
);
961 EXPECT_FALSE(anim
->InEffect(TicksFromSecondsF(-1.0)));
962 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(0.0)));
963 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(1.0)));
965 anim
->set_fill_mode(Animation::FILL_MODE_FORWARDS
);
966 EXPECT_FALSE(anim
->InEffect(TicksFromSecondsF(-1.0)));
967 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(0.0)));
968 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(1.0)));
970 anim
->set_fill_mode(Animation::FILL_MODE_BACKWARDS
);
971 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(-1.0)));
972 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(0.0)));
973 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(1.0)));
975 anim
->set_fill_mode(Animation::FILL_MODE_BOTH
);
976 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(-1.0)));
977 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(0.0)));
978 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(1.0)));
981 TEST(AnimationTest
, InEffectFillModePlayback
) {
982 scoped_ptr
<Animation
> anim(CreateAnimation(1, 1, -1));
983 anim
->set_fill_mode(Animation::FILL_MODE_NONE
);
984 EXPECT_FALSE(anim
->InEffect(TicksFromSecondsF(-1.0)));
985 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(0.0)));
986 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(1.0)));
988 anim
->set_fill_mode(Animation::FILL_MODE_FORWARDS
);
989 EXPECT_FALSE(anim
->InEffect(TicksFromSecondsF(-1.0)));
990 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(0.0)));
991 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(1.0)));
993 anim
->set_fill_mode(Animation::FILL_MODE_BACKWARDS
);
994 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(-1.0)));
995 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(0.0)));
996 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(1.0)));
998 anim
->set_fill_mode(Animation::FILL_MODE_BOTH
);
999 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(-1.0)));
1000 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(0.0)));
1001 EXPECT_TRUE(anim
->InEffect(TicksFromSecondsF(1.0)));