Do not clear ephemeral device permissions when an app is suspended.
[chromium-blink-merge.git] / cc / animation / animation_unittest.cc
blob9345c6b1fc57569d59d8ae7548209376f755c97e
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)),
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))
43 .InSecondsF());
44 EXPECT_EQ(
45 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
46 EXPECT_EQ(
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))
53 .InSecondsF());
54 EXPECT_EQ(
55 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
56 EXPECT_EQ(
57 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
58 EXPECT_EQ(
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))
65 .InSecondsF());
66 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
67 .InSecondsF());
68 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
69 .InSecondsF());
70 EXPECT_EQ(0.9, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.9))
71 .InSecondsF());
72 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
73 .InSecondsF());
74 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
75 .InSecondsF());
76 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
77 .InSecondsF());
80 TEST(AnimationTest, TrimTimeInfiniteIterations) {
81 scoped_ptr<Animation> anim(CreateAnimation(-1));
82 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
83 .InSecondsF());
84 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
85 .InSecondsF());
86 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
87 .InSecondsF());
88 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
89 .InSecondsF());
92 TEST(AnimationTest, TrimTimeReverse) {
93 scoped_ptr<Animation> anim(CreateAnimation(-1));
94 anim->set_direction(Animation::DIRECTION_REVERSE);
95 EXPECT_EQ(
96 1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
97 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
98 .InSecondsF());
99 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
100 .InSecondsF());
101 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
102 .InSecondsF());
103 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
104 .InSecondsF());
105 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
106 .InSecondsF());
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))
113 .InSecondsF());
114 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
115 .InSecondsF());
116 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
117 .InSecondsF());
118 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
119 .InSecondsF());
120 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
121 .InSecondsF());
122 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
123 .InSecondsF());
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))
130 .InSecondsF());
131 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
132 .InSecondsF());
133 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
134 .InSecondsF());
135 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
136 .InSecondsF());
137 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
138 .InSecondsF());
139 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
140 .InSecondsF());
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))
147 .InSecondsF());
148 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
149 .InSecondsF());
150 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
151 .InSecondsF());
152 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
153 .InSecondsF());
154 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
155 .InSecondsF());
156 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
157 .InSecondsF());
158 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
159 .InSecondsF());
160 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
161 .InSecondsF());
162 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
163 .InSecondsF());
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))
170 .InSecondsF());
171 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
172 .InSecondsF());
173 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
174 .InSecondsF());
175 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
176 .InSecondsF());
177 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
178 .InSecondsF());
179 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
180 .InSecondsF());
181 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
182 .InSecondsF());
183 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
184 .InSecondsF());
185 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
186 .InSecondsF());
187 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.50))
188 .InSecondsF());
189 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.75))
190 .InSecondsF());
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))
197 .InSecondsF());
198 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
199 .InSecondsF());
200 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
201 .InSecondsF());
202 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
203 .InSecondsF());
204 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
205 .InSecondsF());
206 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
207 .InSecondsF());
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))
214 .InSecondsF());
215 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
216 .InSecondsF());
217 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
218 .InSecondsF());
219 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
220 .InSecondsF());
221 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
222 .InSecondsF());
223 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
224 .InSecondsF());
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))
231 .InSecondsF());
232 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
233 .InSecondsF());
234 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
235 .InSecondsF());
236 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
237 .InSecondsF());
238 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
239 .InSecondsF());
240 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
241 .InSecondsF());
242 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
243 .InSecondsF());
244 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
245 .InSecondsF());
246 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
247 .InSecondsF());
250 TEST(AnimationTest, TrimTimeStartTime) {
251 scoped_ptr<Animation> anim(CreateAnimation(1));
252 anim->set_start_time(TicksFromSecondsF(4));
253 EXPECT_EQ(
254 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
255 EXPECT_EQ(
256 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0)).InSecondsF());
257 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
258 .InSecondsF());
259 EXPECT_EQ(
260 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
261 EXPECT_EQ(
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);
269 EXPECT_EQ(
270 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
271 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
272 .InSecondsF());
273 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
274 .InSecondsF());
275 EXPECT_EQ(
276 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(5.0)).InSecondsF());
277 EXPECT_EQ(
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));
285 EXPECT_EQ(
286 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
287 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
288 .InSecondsF());
289 EXPECT_EQ(
290 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
291 EXPECT_EQ(
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))
301 .InSecondsF());
302 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
303 .InSecondsF());
304 EXPECT_EQ(
305 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
306 EXPECT_EQ(
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));
314 EXPECT_EQ(
315 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
316 EXPECT_EQ(
317 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0)).InSecondsF());
318 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
319 .InSecondsF());
320 EXPECT_EQ(
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);
329 EXPECT_EQ(
330 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
331 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
332 .InSecondsF());
333 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
334 .InSecondsF());
335 EXPECT_EQ(
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));
342 EXPECT_EQ(
343 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
344 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
345 .InSecondsF());
346 anim->SetRunState(Animation::PAUSED, TicksFromSecondsF(0.5));
347 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
348 .InSecondsF());
349 anim->SetRunState(Animation::RUNNING, TicksFromSecondsF(1024.0));
350 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
351 .InSecondsF());
352 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.5))
353 .InSecondsF());
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))
361 .InSecondsF());
362 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
363 .InSecondsF());
364 anim->SetRunState(Animation::PAUSED, TicksFromSecondsF(0.25));
365 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
366 .InSecondsF());
367 anim->SetRunState(Animation::RUNNING, TicksFromSecondsF(1024.0));
368 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
369 .InSecondsF());
370 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.75))
371 .InSecondsF());
374 TEST(AnimationTest, TrimTimeSuspendResume) {
375 scoped_ptr<Animation> anim(CreateAnimation(1));
376 anim->SetRunState(Animation::RUNNING, TicksFromSecondsF(0.0));
377 EXPECT_EQ(
378 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
379 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
380 .InSecondsF());
381 anim->Suspend(TicksFromSecondsF(0.5));
382 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
383 .InSecondsF());
384 anim->Resume(TicksFromSecondsF(1024));
385 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
386 .InSecondsF());
387 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.5))
388 .InSecondsF());
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))
396 .InSecondsF());
397 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
398 .InSecondsF());
399 anim->Suspend(TicksFromSecondsF(0.75));
400 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
401 .InSecondsF());
402 anim->Resume(TicksFromSecondsF(1024));
403 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.0))
404 .InSecondsF());
405 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1024.25))
406 .InSecondsF());
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))
413 .InSecondsF());
414 EXPECT_EQ(
415 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
416 EXPECT_EQ(
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))
424 .InSecondsF());
425 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
426 .InSecondsF());
427 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
428 .InSecondsF());
429 anim->set_time_offset(TimeDelta::FromMilliseconds(2000));
430 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
431 .InSecondsF());
432 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
433 .InSecondsF());
434 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
435 .InSecondsF());
436 anim->set_start_time(TicksFromSecondsF(1.0));
437 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
438 .InSecondsF());
439 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
440 .InSecondsF());
441 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
442 .InSecondsF());
443 EXPECT_EQ(3.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
444 .InSecondsF());
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))
452 .InSecondsF());
453 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
454 .InSecondsF());
455 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
456 .InSecondsF());
457 anim->set_time_offset(TimeDelta::FromMilliseconds(2000));
458 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(-1.0))
459 .InSecondsF());
460 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
461 .InSecondsF());
462 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
463 .InSecondsF());
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))
467 .InSecondsF());
468 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
469 .InSecondsF());
470 EXPECT_EQ(3.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
471 .InSecondsF());
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))
584 .InSecondsF());
585 EXPECT_EQ(
586 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
587 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
588 .InSecondsF());
589 EXPECT_EQ(
590 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
591 EXPECT_EQ(
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))
598 .InSecondsF());
599 EXPECT_EQ(
600 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
601 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
602 .InSecondsF());
603 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
604 .InSecondsF());
605 EXPECT_EQ(
606 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
607 EXPECT_EQ(
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))
614 .InSecondsF());
615 EXPECT_EQ(
616 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
617 EXPECT_EQ(
618 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
619 EXPECT_EQ(
620 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
621 EXPECT_EQ(
622 3, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
623 EXPECT_EQ(
624 4, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
625 EXPECT_EQ(
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))
632 .InSecondsF());
633 EXPECT_EQ(
634 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
635 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
636 .InSecondsF());
637 EXPECT_EQ(
638 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
639 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
640 .InSecondsF());
641 EXPECT_EQ(
642 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
643 EXPECT_EQ(
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))
650 .InSecondsF());
651 EXPECT_EQ(
652 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
653 EXPECT_EQ(1.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
654 .InSecondsF());
655 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
656 .InSecondsF());
657 EXPECT_EQ(1.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
658 .InSecondsF());
659 EXPECT_EQ(
660 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
661 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
662 .InSecondsF());
663 EXPECT_EQ(
664 0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3)).InSecondsF());
665 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
666 .InSecondsF());
667 EXPECT_EQ(
668 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4)).InSecondsF());
669 EXPECT_EQ(
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))
676 .InSecondsF());
677 EXPECT_EQ(
678 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0)).InSecondsF());
679 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
680 .InSecondsF());
681 EXPECT_EQ(
682 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
683 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
684 .InSecondsF());
685 EXPECT_EQ(
686 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
687 EXPECT_EQ(
688 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
691 TEST(AnimationTest, TrimTimePlaybackFastInfiniteIterations) {
692 scoped_ptr<Animation> anim(CreateAnimation(-1, 4, 4));
693 EXPECT_EQ(
694 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
695 EXPECT_EQ(
696 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
697 EXPECT_EQ(
698 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
699 EXPECT_EQ(
700 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
701 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1000.0))
702 .InSecondsF());
703 EXPECT_EQ(2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1000.5))
704 .InSecondsF());
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))
711 .InSecondsF());
712 EXPECT_EQ(
713 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
714 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
715 .InSecondsF());
716 EXPECT_EQ(
717 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
718 EXPECT_EQ(
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))
726 .InSecondsF());
727 EXPECT_EQ(
728 0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0)).InSecondsF());
729 EXPECT_EQ(
730 1, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5)).InSecondsF());
731 EXPECT_EQ(
732 2, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0)).InSecondsF());
733 EXPECT_EQ(
734 3, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5)).InSecondsF());
735 EXPECT_EQ(
736 4, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0)).InSecondsF());
737 EXPECT_EQ(
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))
745 .InSecondsF());
746 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
747 .InSecondsF());
748 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
749 .InSecondsF());
750 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
751 .InSecondsF());
752 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
753 .InSecondsF());
754 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
755 .InSecondsF());
756 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
757 .InSecondsF());
758 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
759 .InSecondsF());
760 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
761 .InSecondsF());
762 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
763 .InSecondsF());
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))
770 .InSecondsF());
771 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
772 .InSecondsF());
773 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
774 .InSecondsF());
775 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
776 .InSecondsF());
777 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
778 .InSecondsF());
779 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
780 .InSecondsF());
781 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
782 .InSecondsF());
783 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
784 .InSecondsF());
785 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
786 .InSecondsF());
787 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
788 .InSecondsF());
789 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
790 .InSecondsF());
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))
797 .InSecondsF());
798 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
799 .InSecondsF());
800 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
801 .InSecondsF());
802 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
803 .InSecondsF());
804 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
805 .InSecondsF());
806 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
807 .InSecondsF());
808 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
809 .InSecondsF());
810 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
811 .InSecondsF());
812 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
813 .InSecondsF());
814 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
815 .InSecondsF());
818 TEST(AnimationTest,
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))
823 .InSecondsF());
824 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.25))
825 .InSecondsF());
826 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
827 .InSecondsF());
828 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.75))
829 .InSecondsF());
830 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
831 .InSecondsF());
832 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.25))
833 .InSecondsF());
834 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
835 .InSecondsF());
836 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.75))
837 .InSecondsF());
838 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
839 .InSecondsF());
840 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.25))
841 .InSecondsF());
842 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
843 .InSecondsF());
844 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.75))
845 .InSecondsF());
846 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
847 .InSecondsF());
848 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.25))
849 .InSecondsF());
852 TEST(AnimationTest,
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))
857 .InSecondsF());
858 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
859 .InSecondsF());
860 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
861 .InSecondsF());
862 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
863 .InSecondsF());
864 EXPECT_EQ(2.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
865 .InSecondsF());
866 EXPECT_EQ(1.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
867 .InSecondsF());
868 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
869 .InSecondsF());
870 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
871 .InSecondsF());
872 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.0))
873 .InSecondsF());
874 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(4.5))
875 .InSecondsF());
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))
882 .InSecondsF());
883 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
884 .InSecondsF());
885 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
886 .InSecondsF());
887 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
888 .InSecondsF());
889 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
890 .InSecondsF());
891 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
892 .InSecondsF());
893 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
894 .InSecondsF());
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))
902 .InSecondsF());
903 EXPECT_EQ(0.3, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
904 .InSecondsF());
905 EXPECT_EQ(0.8, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
906 .InSecondsF());
907 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.7))
908 .InSecondsF());
909 EXPECT_EQ(0.7, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
910 .InSecondsF());
911 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.2))
912 .InSecondsF());
913 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.7))
914 .InSecondsF());
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))
922 .InSecondsF());
923 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.0))
924 .InSecondsF());
925 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(0.5))
926 .InSecondsF());
927 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
928 .InSecondsF());
929 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.5))
930 .InSecondsF());
931 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
932 .InSecondsF());
933 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.5))
934 .InSecondsF());
935 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
936 .InSecondsF());
937 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
938 .InSecondsF());
941 TEST(AnimationTest,
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))
947 .InSecondsF());
948 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(1.0))
949 .InSecondsF());
950 EXPECT_EQ(0.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(2.0))
951 .InSecondsF());
952 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.0))
953 .InSecondsF());
954 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(TicksFromSecondsF(3.5))
955 .InSecondsF());
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)));
1004 } // namespace
1005 } // namespace cc