2 * Copyright (c) 2013, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/animation/TimedItem.h"
34 #include <gtest/gtest.h>
36 using namespace WebCore;
40 class TestTimedItemEventDelegate : public TimedItem::EventDelegate {
42 virtual void onEventCondition(const TimedItem* timedItem, bool isFirstSample, TimedItem::Phase previousPhase, double previousIteration) OVERRIDE
44 m_eventTriggered = true;
45 m_phaseChanged = previousPhase != timedItem->phase();
46 m_iterationChanged = previousIteration != timedItem->currentIteration();
51 m_eventTriggered = false;
52 m_phaseChanged = false;
53 m_iterationChanged = false;
55 bool eventTriggered() { return m_eventTriggered; }
56 bool phaseChanged() { return m_phaseChanged; }
57 bool iterationChanged() { return m_iterationChanged; }
60 bool m_eventTriggered;
62 bool m_iterationChanged;
65 class TestTimedItem : public TimedItem {
67 static PassRefPtr<TestTimedItem> create(const Timing& specified)
69 return adoptRef(new TestTimedItem(specified, new TestTimedItemEventDelegate()));
72 void updateInheritedTime(double time)
74 m_eventDelegate->reset();
75 TimedItem::updateInheritedTime(time);
78 virtual bool updateChildrenAndEffects() const OVERRIDE { return false; }
80 TestTimedItemEventDelegate* eventDelegate() { return m_eventDelegate; }
81 virtual double calculateTimeToEffectChange(double localTime, double timeToNextIteration) const OVERRIDE
83 m_localTime = localTime;
84 m_timeToNextIteration = timeToNextIteration;
88 double takeLocalTime()
90 const double result = m_localTime;
91 m_localTime = nullValue();
95 double takeTimeToNextIteration()
97 const double result = m_timeToNextIteration;
98 m_timeToNextIteration = nullValue();
103 TestTimedItem(const Timing& specified, TestTimedItemEventDelegate* eventDelegate)
104 : TimedItem(specified, adoptPtr(eventDelegate))
105 , m_eventDelegate(eventDelegate)
109 TestTimedItemEventDelegate* m_eventDelegate;
110 mutable double m_localTime;
111 mutable double m_timeToNextIteration;
114 TEST(AnimationTimedItemTest, Sanity)
117 timing.hasIterationDuration = true;
118 timing.iterationDuration = 2;
119 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
121 EXPECT_EQ(0, timedItem->startTime());
123 timedItem->updateInheritedTime(0);
125 EXPECT_EQ(TimedItem::PhaseActive, timedItem->phase());
126 EXPECT_TRUE(timedItem->isInPlay());
127 EXPECT_TRUE(timedItem->isCurrent());
128 EXPECT_TRUE(timedItem->isInEffect());
129 EXPECT_EQ(0, timedItem->currentIteration());
130 EXPECT_EQ(0, timedItem->startTime());
131 EXPECT_EQ(2, timedItem->activeDuration());
132 EXPECT_EQ(0, timedItem->timeFraction());
134 timedItem->updateInheritedTime(1);
136 EXPECT_EQ(TimedItem::PhaseActive, timedItem->phase());
137 EXPECT_TRUE(timedItem->isInPlay());
138 EXPECT_TRUE(timedItem->isCurrent());
139 EXPECT_TRUE(timedItem->isInEffect());
140 EXPECT_EQ(0, timedItem->currentIteration());
141 EXPECT_EQ(0, timedItem->startTime());
142 EXPECT_EQ(2, timedItem->activeDuration());
143 EXPECT_EQ(0.5, timedItem->timeFraction());
145 timedItem->updateInheritedTime(2);
147 EXPECT_EQ(TimedItem::PhaseAfter, timedItem->phase());
148 EXPECT_FALSE(timedItem->isInPlay());
149 EXPECT_FALSE(timedItem->isCurrent());
150 EXPECT_TRUE(timedItem->isInEffect());
151 EXPECT_EQ(0, timedItem->currentIteration());
152 EXPECT_EQ(0, timedItem->startTime());
153 EXPECT_EQ(2, timedItem->activeDuration());
154 EXPECT_EQ(1, timedItem->timeFraction());
156 timedItem->updateInheritedTime(3);
158 EXPECT_EQ(TimedItem::PhaseAfter, timedItem->phase());
159 EXPECT_FALSE(timedItem->isInPlay());
160 EXPECT_FALSE(timedItem->isCurrent());
161 EXPECT_TRUE(timedItem->isInEffect());
162 EXPECT_EQ(0, timedItem->currentIteration());
163 EXPECT_EQ(0, timedItem->startTime());
164 EXPECT_EQ(2, timedItem->activeDuration());
165 EXPECT_EQ(1, timedItem->timeFraction());
168 TEST(AnimationTimedItemTest, FillForwards)
171 timing.hasIterationDuration = true;
172 timing.iterationDuration = 1;
173 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
175 timedItem->updateInheritedTime(-1);
176 EXPECT_TRUE(isNull(timedItem->timeFraction()));
178 timedItem->updateInheritedTime(2);
179 EXPECT_EQ(1, timedItem->timeFraction());
182 TEST(AnimationTimedItemTest, FillBackwards)
185 timing.hasIterationDuration = true;
186 timing.iterationDuration = 1;
187 timing.fillMode = Timing::FillModeBackwards;
188 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
190 timedItem->updateInheritedTime(-1);
191 EXPECT_EQ(0, timedItem->timeFraction());
193 timedItem->updateInheritedTime(2);
194 EXPECT_TRUE(isNull(timedItem->timeFraction()));
197 TEST(AnimationTimedItemTest, FillBoth)
200 timing.hasIterationDuration = true;
201 timing.iterationDuration = 1;
202 timing.fillMode = Timing::FillModeBoth;
203 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
205 timedItem->updateInheritedTime(-1);
206 EXPECT_EQ(0, timedItem->timeFraction());
208 timedItem->updateInheritedTime(2);
209 EXPECT_EQ(1, timedItem->timeFraction());
212 TEST(AnimationTimedItemTest, StartDelay)
215 timing.hasIterationDuration = true;
216 timing.iterationDuration = 1;
217 timing.startDelay = 0.5;
218 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
220 timedItem->updateInheritedTime(0);
221 EXPECT_TRUE(isNull(timedItem->timeFraction()));
223 timedItem->updateInheritedTime(0.5);
224 EXPECT_EQ(0, timedItem->timeFraction());
226 timedItem->updateInheritedTime(1.5);
227 EXPECT_EQ(1, timedItem->timeFraction());
230 TEST(AnimationTimedItemTest, ZeroIteration)
233 timing.hasIterationDuration = true;
234 timing.iterationDuration = 1;
235 timing.iterationCount = 0;
236 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
238 timedItem->updateInheritedTime(-1);
239 EXPECT_EQ(0, timedItem->activeDuration());
240 EXPECT_TRUE(isNull(timedItem->currentIteration()));
241 EXPECT_TRUE(isNull(timedItem->timeFraction()));
243 timedItem->updateInheritedTime(0);
244 EXPECT_EQ(0, timedItem->activeDuration());
245 EXPECT_EQ(0, timedItem->currentIteration());
246 EXPECT_EQ(0, timedItem->timeFraction());
249 TEST(AnimationTimedItemTest, InfiniteIteration)
252 timing.hasIterationDuration = true;
253 timing.iterationDuration = 1;
254 timing.iterationCount = std::numeric_limits<double>::infinity();
255 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
257 timedItem->updateInheritedTime(-1);
258 EXPECT_TRUE(isNull(timedItem->currentIteration()));
259 EXPECT_TRUE(isNull(timedItem->timeFraction()));
261 EXPECT_EQ(std::numeric_limits<double>::infinity(), timedItem->activeDuration());
263 timedItem->updateInheritedTime(0);
264 EXPECT_EQ(0, timedItem->currentIteration());
265 EXPECT_EQ(0, timedItem->timeFraction());
268 TEST(AnimationTimedItemTest, Iteration)
271 timing.iterationCount = 2;
272 timing.hasIterationDuration = true;
273 timing.iterationDuration = 2;
274 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
276 timedItem->updateInheritedTime(0);
277 EXPECT_EQ(0, timedItem->currentIteration());
278 EXPECT_EQ(0, timedItem->timeFraction());
280 timedItem->updateInheritedTime(1);
281 EXPECT_EQ(0, timedItem->currentIteration());
282 EXPECT_EQ(0.5, timedItem->timeFraction());
284 timedItem->updateInheritedTime(2);
285 EXPECT_EQ(1, timedItem->currentIteration());
286 EXPECT_EQ(0, timedItem->timeFraction());
288 timedItem->updateInheritedTime(2);
289 EXPECT_EQ(1, timedItem->currentIteration());
290 EXPECT_EQ(0, timedItem->timeFraction());
292 timedItem->updateInheritedTime(5);
293 EXPECT_EQ(1, timedItem->currentIteration());
294 EXPECT_EQ(1, timedItem->timeFraction());
297 TEST(AnimationTimedItemTest, IterationStart)
300 timing.iterationStart = 1.2;
301 timing.iterationCount = 2.2;
302 timing.hasIterationDuration = true;
303 timing.iterationDuration = 1;
304 timing.fillMode = Timing::FillModeBoth;
305 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
307 timedItem->updateInheritedTime(-1);
308 EXPECT_EQ(1, timedItem->currentIteration());
309 EXPECT_NEAR(0.2, timedItem->timeFraction(), 0.000000000000001);
311 timedItem->updateInheritedTime(0);
312 EXPECT_EQ(1, timedItem->currentIteration());
313 EXPECT_NEAR(0.2, timedItem->timeFraction(), 0.000000000000001);
315 timedItem->updateInheritedTime(10);
316 EXPECT_EQ(3, timedItem->currentIteration());
317 EXPECT_NEAR(0.4, timedItem->timeFraction(), 0.000000000000001);
320 TEST(AnimationTimedItemTest, IterationAlternate)
323 timing.iterationCount = 10;
324 timing.hasIterationDuration = true;
325 timing.iterationDuration = 1;
326 timing.direction = Timing::PlaybackDirectionAlternate;
327 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
329 timedItem->updateInheritedTime(0.75);
330 EXPECT_EQ(0, timedItem->currentIteration());
331 EXPECT_EQ(0.75, timedItem->timeFraction());
333 timedItem->updateInheritedTime(1.75);
334 EXPECT_EQ(1, timedItem->currentIteration());
335 EXPECT_EQ(0.25, timedItem->timeFraction());
337 timedItem->updateInheritedTime(2.75);
338 EXPECT_EQ(2, timedItem->currentIteration());
339 EXPECT_EQ(0.75, timedItem->timeFraction());
342 TEST(AnimationTimedItemTest, IterationAlternateReverse)
345 timing.iterationCount = 10;
346 timing.hasIterationDuration = true;
347 timing.iterationDuration = 1;
348 timing.direction = Timing::PlaybackDirectionAlternateReverse;
349 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
351 timedItem->updateInheritedTime(0.75);
352 EXPECT_EQ(0, timedItem->currentIteration());
353 EXPECT_EQ(0.25, timedItem->timeFraction());
355 timedItem->updateInheritedTime(1.75);
356 EXPECT_EQ(1, timedItem->currentIteration());
357 EXPECT_EQ(0.75, timedItem->timeFraction());
359 timedItem->updateInheritedTime(2.75);
360 EXPECT_EQ(2, timedItem->currentIteration());
361 EXPECT_EQ(0.25, timedItem->timeFraction());
364 TEST(AnimationTimedItemTest, ZeroDurationSanity)
367 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
369 EXPECT_EQ(0, timedItem->startTime());
371 timedItem->updateInheritedTime(0);
373 EXPECT_EQ(TimedItem::PhaseAfter, timedItem->phase());
374 EXPECT_FALSE(timedItem->isInPlay());
375 EXPECT_FALSE(timedItem->isCurrent());
376 EXPECT_TRUE(timedItem->isInEffect());
377 EXPECT_EQ(0, timedItem->currentIteration());
378 EXPECT_EQ(0, timedItem->startTime());
379 EXPECT_EQ(0, timedItem->activeDuration());
380 EXPECT_EQ(1, timedItem->timeFraction());
382 timedItem->updateInheritedTime(1);
384 EXPECT_EQ(TimedItem::PhaseAfter, timedItem->phase());
385 EXPECT_FALSE(timedItem->isInPlay());
386 EXPECT_FALSE(timedItem->isCurrent());
387 EXPECT_TRUE(timedItem->isInEffect());
388 EXPECT_EQ(0, timedItem->currentIteration());
389 EXPECT_EQ(0, timedItem->startTime());
390 EXPECT_EQ(0, timedItem->activeDuration());
391 EXPECT_EQ(1, timedItem->timeFraction());
394 TEST(AnimationTimedItemTest, ZeroDurationFillForwards)
397 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
399 timedItem->updateInheritedTime(-1);
400 EXPECT_TRUE(isNull(timedItem->timeFraction()));
402 timedItem->updateInheritedTime(0);
403 EXPECT_EQ(1, timedItem->timeFraction());
405 timedItem->updateInheritedTime(1);
406 EXPECT_EQ(1, timedItem->timeFraction());
409 TEST(AnimationTimedItemTest, ZeroDurationFillBackwards)
412 timing.fillMode = Timing::FillModeBackwards;
413 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
415 timedItem->updateInheritedTime(-1);
416 EXPECT_EQ(0, timedItem->timeFraction());
418 timedItem->updateInheritedTime(0);
419 EXPECT_TRUE(isNull(timedItem->timeFraction()));
421 timedItem->updateInheritedTime(1);
422 EXPECT_TRUE(isNull(timedItem->timeFraction()));
425 TEST(AnimationTimedItemTest, ZeroDurationFillBoth)
428 timing.fillMode = Timing::FillModeBoth;
429 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
431 timedItem->updateInheritedTime(-1);
432 EXPECT_EQ(0, timedItem->timeFraction());
434 timedItem->updateInheritedTime(0);
435 EXPECT_EQ(1, timedItem->timeFraction());
437 timedItem->updateInheritedTime(1);
438 EXPECT_EQ(1, timedItem->timeFraction());
441 TEST(AnimationTimedItemTest, ZeroDurationStartDelay)
444 timing.startDelay = 0.5;
445 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
447 timedItem->updateInheritedTime(0);
448 EXPECT_TRUE(isNull(timedItem->timeFraction()));
450 timedItem->updateInheritedTime(0.5);
451 EXPECT_EQ(1, timedItem->timeFraction());
453 timedItem->updateInheritedTime(1.5);
454 EXPECT_EQ(1, timedItem->timeFraction());
457 TEST(AnimationTimedItemTest, ZeroDurationIterationStartAndCount)
460 timing.iterationStart = 0.1;
461 timing.iterationCount = 0.2;
462 timing.fillMode = Timing::FillModeBoth;
463 timing.startDelay = 0.3;
464 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
466 timedItem->updateInheritedTime(0);
467 EXPECT_EQ(0.1, timedItem->timeFraction());
469 timedItem->updateInheritedTime(0.3);
470 EXPECT_DOUBLE_EQ(0.3, timedItem->timeFraction());
472 timedItem->updateInheritedTime(1);
473 EXPECT_DOUBLE_EQ(0.3, timedItem->timeFraction());
476 // FIXME: Needs specification work.
477 TEST(AnimationTimedItemTest, ZeroDurationInfiniteIteration)
480 timing.iterationCount = std::numeric_limits<double>::infinity();
481 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
483 timedItem->updateInheritedTime(-1);
484 EXPECT_EQ(0, timedItem->activeDuration());
485 EXPECT_TRUE(isNull(timedItem->currentIteration()));
486 EXPECT_TRUE(isNull(timedItem->timeFraction()));
488 timedItem->updateInheritedTime(0);
489 EXPECT_EQ(0, timedItem->activeDuration());
490 EXPECT_EQ(std::numeric_limits<double>::infinity(), timedItem->currentIteration());
491 EXPECT_EQ(1, timedItem->timeFraction());
494 TEST(AnimationTimedItemTest, ZeroDurationIteration)
497 timing.iterationCount = 2;
498 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
500 timedItem->updateInheritedTime(-1);
501 EXPECT_TRUE(isNull(timedItem->currentIteration()));
502 EXPECT_TRUE(isNull(timedItem->timeFraction()));
504 timedItem->updateInheritedTime(0);
505 EXPECT_EQ(1, timedItem->currentIteration());
506 EXPECT_EQ(1, timedItem->timeFraction());
508 timedItem->updateInheritedTime(1);
509 EXPECT_EQ(1, timedItem->currentIteration());
510 EXPECT_EQ(1, timedItem->timeFraction());
513 TEST(AnimationTimedItemTest, ZeroDurationIterationStart)
516 timing.iterationStart = 1.2;
517 timing.iterationCount = 2.2;
518 timing.fillMode = Timing::FillModeBoth;
519 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
521 timedItem->updateInheritedTime(-1);
522 EXPECT_EQ(1, timedItem->currentIteration());
523 EXPECT_NEAR(0.2, timedItem->timeFraction(), 0.000000000000001);
525 timedItem->updateInheritedTime(0);
526 EXPECT_EQ(3, timedItem->currentIteration());
527 EXPECT_NEAR(0.4, timedItem->timeFraction(), 0.000000000000001);
529 timedItem->updateInheritedTime(10);
530 EXPECT_EQ(3, timedItem->currentIteration());
531 EXPECT_NEAR(0.4, timedItem->timeFraction(), 0.000000000000001);
534 TEST(AnimationTimedItemTest, ZeroDurationIterationAlternate)
537 timing.iterationCount = 2;
538 timing.direction = Timing::PlaybackDirectionAlternate;
539 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
541 timedItem->updateInheritedTime(-1);
542 EXPECT_TRUE(isNull(timedItem->currentIteration()));
543 EXPECT_TRUE(isNull(timedItem->timeFraction()));
545 timedItem->updateInheritedTime(0);
546 EXPECT_EQ(1, timedItem->currentIteration());
547 EXPECT_EQ(0, timedItem->timeFraction());
549 timedItem->updateInheritedTime(1);
550 EXPECT_EQ(1, timedItem->currentIteration());
551 EXPECT_EQ(0, timedItem->timeFraction());
554 TEST(AnimationTimedItemTest, ZeroDurationIterationAlternateReverse)
557 timing.iterationCount = 2;
558 timing.direction = Timing::PlaybackDirectionAlternateReverse;
559 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
561 timedItem->updateInheritedTime(-1);
562 EXPECT_TRUE(isNull(timedItem->currentIteration()));
563 EXPECT_TRUE(isNull(timedItem->timeFraction()));
565 timedItem->updateInheritedTime(0);
566 EXPECT_EQ(1, timedItem->currentIteration());
567 EXPECT_EQ(1, timedItem->timeFraction());
569 timedItem->updateInheritedTime(1);
570 EXPECT_EQ(1, timedItem->currentIteration());
571 EXPECT_EQ(1, timedItem->timeFraction());
574 TEST(AnimationTimedItemTest, InfiniteDurationSanity)
577 timing.hasIterationDuration = true;
578 timing.iterationDuration = std::numeric_limits<double>::infinity();
579 timing.iterationCount = 1;
580 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
582 EXPECT_EQ(0, timedItem->startTime());
584 timedItem->updateInheritedTime(0);
586 EXPECT_EQ(std::numeric_limits<double>::infinity(), timedItem->activeDuration());
587 EXPECT_EQ(TimedItem::PhaseActive, timedItem->phase());
588 EXPECT_TRUE(timedItem->isInPlay());
589 EXPECT_TRUE(timedItem->isCurrent());
590 EXPECT_TRUE(timedItem->isInEffect());
591 EXPECT_EQ(0, timedItem->currentIteration());
592 EXPECT_EQ(0, timedItem->timeFraction());
594 timedItem->updateInheritedTime(1);
596 EXPECT_EQ(std::numeric_limits<double>::infinity(), timedItem->activeDuration());
597 EXPECT_EQ(TimedItem::PhaseActive, timedItem->phase());
598 EXPECT_TRUE(timedItem->isInPlay());
599 EXPECT_TRUE(timedItem->isCurrent());
600 EXPECT_TRUE(timedItem->isInEffect());
601 EXPECT_EQ(0, timedItem->currentIteration());
602 EXPECT_EQ(0, timedItem->timeFraction());
605 // FIXME: Needs specification work.
606 TEST(AnimationTimedItemTest, InfiniteDurationZeroIterations)
609 timing.hasIterationDuration = true;
610 timing.iterationDuration = std::numeric_limits<double>::infinity();
611 timing.iterationCount = 0;
612 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
614 EXPECT_EQ(0, timedItem->startTime());
616 timedItem->updateInheritedTime(0);
618 EXPECT_EQ(0, timedItem->activeDuration());
619 EXPECT_EQ(TimedItem::PhaseAfter, timedItem->phase());
620 EXPECT_FALSE(timedItem->isInPlay());
621 EXPECT_FALSE(timedItem->isCurrent());
622 EXPECT_TRUE(timedItem->isInEffect());
623 EXPECT_EQ(0, timedItem->currentIteration());
624 EXPECT_EQ(0, timedItem->timeFraction());
626 timedItem->updateInheritedTime(1);
628 EXPECT_EQ(TimedItem::PhaseAfter, timedItem->phase());
629 EXPECT_EQ(TimedItem::PhaseAfter, timedItem->phase());
630 EXPECT_FALSE(timedItem->isInPlay());
631 EXPECT_FALSE(timedItem->isCurrent());
632 EXPECT_TRUE(timedItem->isInEffect());
633 EXPECT_EQ(0, timedItem->currentIteration());
634 EXPECT_EQ(0, timedItem->timeFraction());
637 TEST(AnimationTimedItemTest, InfiniteDurationInfiniteIterations)
640 timing.hasIterationDuration = true;
641 timing.iterationDuration = std::numeric_limits<double>::infinity();
642 timing.iterationCount = std::numeric_limits<double>::infinity();
643 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
645 EXPECT_EQ(0, timedItem->startTime());
647 timedItem->updateInheritedTime(0);
649 EXPECT_EQ(std::numeric_limits<double>::infinity(), timedItem->activeDuration());
650 EXPECT_EQ(TimedItem::PhaseActive, timedItem->phase());
651 EXPECT_TRUE(timedItem->isInPlay());
652 EXPECT_TRUE(timedItem->isCurrent());
653 EXPECT_TRUE(timedItem->isInEffect());
654 EXPECT_EQ(0, timedItem->currentIteration());
655 EXPECT_EQ(0, timedItem->timeFraction());
657 timedItem->updateInheritedTime(1);
659 EXPECT_EQ(std::numeric_limits<double>::infinity(), timedItem->activeDuration());
660 EXPECT_EQ(TimedItem::PhaseActive, timedItem->phase());
661 EXPECT_TRUE(timedItem->isInPlay());
662 EXPECT_TRUE(timedItem->isCurrent());
663 EXPECT_TRUE(timedItem->isInEffect());
664 EXPECT_EQ(0, timedItem->currentIteration());
665 EXPECT_EQ(0, timedItem->timeFraction());
668 TEST(AnimationTimedItemTest, InfiniteDurationZeroPlaybackRate)
671 timing.hasIterationDuration = true;
672 timing.iterationDuration = std::numeric_limits<double>::infinity();
673 timing.playbackRate = 0;
674 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
676 EXPECT_EQ(0, timedItem->startTime());
678 timedItem->updateInheritedTime(0);
680 EXPECT_EQ(std::numeric_limits<double>::infinity(), timedItem->activeDuration());
681 EXPECT_EQ(TimedItem::PhaseActive, timedItem->phase());
682 EXPECT_TRUE(timedItem->isInPlay());
683 EXPECT_TRUE(timedItem->isCurrent());
684 EXPECT_TRUE(timedItem->isInEffect());
685 EXPECT_EQ(0, timedItem->currentIteration());
686 EXPECT_EQ(0, timedItem->timeFraction());
688 timedItem->updateInheritedTime(std::numeric_limits<double>::infinity());
690 EXPECT_EQ(std::numeric_limits<double>::infinity(), timedItem->activeDuration());
691 EXPECT_EQ(TimedItem::PhaseAfter, timedItem->phase());
692 EXPECT_FALSE(timedItem->isInPlay());
693 EXPECT_FALSE(timedItem->isCurrent());
694 EXPECT_TRUE(timedItem->isInEffect());
695 EXPECT_EQ(0, timedItem->currentIteration());
696 EXPECT_EQ(0, timedItem->timeFraction());
699 TEST(AnimationTimedItemTest, Events)
702 timing.hasIterationDuration = true;
703 timing.iterationDuration = 1;
704 timing.iterationCount = 2;
705 timing.startDelay = 1;
706 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
709 timedItem->updateInheritedTime(0.0);
710 EXPECT_TRUE(timedItem->eventDelegate()->eventTriggered());
713 timedItem->updateInheritedTime(0.5);
714 EXPECT_FALSE(timedItem->eventDelegate()->eventTriggered());
717 timedItem->updateInheritedTime(1.5);
718 EXPECT_TRUE(timedItem->eventDelegate()->eventTriggered());
719 EXPECT_TRUE(timedItem->eventDelegate()->phaseChanged());
720 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged());
722 timedItem->updateInheritedTime(1.6);
723 EXPECT_FALSE(timedItem->eventDelegate()->eventTriggered());
726 timedItem->updateInheritedTime(2.5);
727 EXPECT_TRUE(timedItem->eventDelegate()->eventTriggered());
728 EXPECT_FALSE(timedItem->eventDelegate()->phaseChanged());
729 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged());
731 timedItem->updateInheritedTime(2.6);
732 EXPECT_FALSE(timedItem->eventDelegate()->eventTriggered());
735 timedItem->updateInheritedTime(3.5);
736 EXPECT_TRUE(timedItem->eventDelegate()->eventTriggered());
737 EXPECT_TRUE(timedItem->eventDelegate()->phaseChanged());
738 EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged());
740 timedItem->updateInheritedTime(3.6);
741 EXPECT_FALSE(timedItem->eventDelegate()->eventTriggered());
744 TEST(AnimationTimedItemTest, TimeToEffectChange)
747 timing.hasIterationDuration = true;
748 timing.iterationDuration = 1;
749 timing.iterationStart = 0.2;
750 timing.iterationCount = 2.5;
751 timing.startDelay = 1;
752 timing.direction = Timing::PlaybackDirectionAlternate;
753 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing);
755 timedItem->updateInheritedTime(0);
756 EXPECT_EQ(0, timedItem->takeLocalTime());
757 EXPECT_TRUE(std::isinf(timedItem->takeTimeToNextIteration()));
760 timedItem->updateInheritedTime(1.75);
761 EXPECT_EQ(1.75, timedItem->takeLocalTime());
762 EXPECT_NEAR(0.05, timedItem->takeTimeToNextIteration(), 0.000000000000001);
764 // Reverse iteration.
765 timedItem->updateInheritedTime(2.75);
766 EXPECT_EQ(2.75, timedItem->takeLocalTime());
767 EXPECT_NEAR(0.05, timedItem->takeTimeToNextIteration(), 0.000000000000001);
769 // Item ends before iteration finishes.
770 timedItem->updateInheritedTime(3.4);
771 EXPECT_EQ(TimedItem::PhaseActive, timedItem->phase());
772 EXPECT_EQ(3.4, timedItem->takeLocalTime());
773 EXPECT_TRUE(std::isinf(timedItem->takeTimeToNextIteration()));
775 // Item has finished.
776 timedItem->updateInheritedTime(3.5);
777 EXPECT_EQ(TimedItem::PhaseAfter, timedItem->phase());
778 EXPECT_EQ(3.5, timedItem->takeLocalTime());
779 EXPECT_TRUE(std::isinf(timedItem->takeTimeToNextIteration()));