| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/animation/TimedItem.h" | 32 #include "core/animation/TimedItem.h" |
| 33 | 33 |
| 34 #include <gtest/gtest.h> | 34 #include <gtest/gtest.h> |
| 35 | 35 |
| 36 using namespace WebCore; | 36 using namespace WebCore; |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 class TestTimedItemEventDelegate : public TimedItemEventDelegate { | 40 class TestTimedItemEventDelegate : public TimedItem::EventDelegate { |
| 41 public: | 41 public: |
| 42 void onEventCondition(bool wasInPlay, bool isInPlay, double previousIteratio
n, double currentIteration) OVERRIDE | 42 void onEventCondition(bool isFirstSample, TimedItem::Phase previousPhase, Ti
medItem::Phase phase, double previousIteration, double currentIteration) OVERRID
E |
| 43 { | 43 { |
| 44 m_eventTriggered = true; | 44 m_eventTriggered = true; |
| 45 m_playStateChanged = wasInPlay != isInPlay; | 45 m_phaseChanged = previousPhase != phase; |
| 46 m_iterationChanged = isInPlay && previousIteration != currentIteration; | 46 m_iterationChanged = previousIteration != currentIteration; |
| 47 if (isInPlay) | |
| 48 ASSERT(!isNull(currentIteration)); | |
| 49 | 47 |
| 50 } | 48 } |
| 51 void reset() | 49 void reset() |
| 52 { | 50 { |
| 53 m_eventTriggered = false; | 51 m_eventTriggered = false; |
| 54 m_playStateChanged = false; | 52 m_phaseChanged = false; |
| 55 m_iterationChanged = false; | 53 m_iterationChanged = false; |
| 56 } | 54 } |
| 57 bool eventTriggered() { return m_eventTriggered; } | 55 bool eventTriggered() { return m_eventTriggered; } |
| 58 bool playStateChanged() { return m_playStateChanged; } | 56 bool phaseChanged() { return m_phaseChanged; } |
| 59 bool iterationChanged() { return m_iterationChanged; } | 57 bool iterationChanged() { return m_iterationChanged; } |
| 60 | 58 |
| 61 private: | 59 private: |
| 62 bool m_eventTriggered; | 60 bool m_eventTriggered; |
| 63 bool m_playStateChanged; | 61 bool m_phaseChanged; |
| 64 bool m_iterationChanged; | 62 bool m_iterationChanged; |
| 65 }; | 63 }; |
| 66 | 64 |
| 67 class TestTimedItem : public TimedItem { | 65 class TestTimedItem : public TimedItem { |
| 68 public: | 66 public: |
| 69 static PassRefPtr<TestTimedItem> create(const Timing& specified) | 67 static PassRefPtr<TestTimedItem> create(const Timing& specified) |
| 70 { | 68 { |
| 71 return adoptRef(new TestTimedItem(specified, new TestTimedItemEventDeleg
ate())); | 69 return adoptRef(new TestTimedItem(specified, new TestTimedItemEventDeleg
ate())); |
| 72 } | 70 } |
| 73 | 71 |
| 74 void updateInheritedTime(double time) | 72 void updateInheritedTime(double time) |
| 75 { | 73 { |
| 76 m_eventDelegate->reset(); | 74 m_eventDelegate->reset(); |
| 77 TimedItem::updateInheritedTime(time); | 75 TimedItem::updateInheritedTime(time); |
| 78 } | 76 } |
| 79 | 77 |
| 80 void updateChildrenAndEffects(bool wasActiveOrInEffect) const FINAL OVERRIDE
{ | 78 void updateChildrenAndEffects(bool wasActiveOrInEffect) const FINAL OVERRIDE
{ } |
| 81 } | |
| 82 | |
| 83 void willDetach() { } | 79 void willDetach() { } |
| 84 | |
| 85 TestTimedItemEventDelegate* eventDelegate() { return m_eventDelegate; } | 80 TestTimedItemEventDelegate* eventDelegate() { return m_eventDelegate; } |
| 86 | 81 |
| 87 private: | 82 private: |
| 88 TestTimedItem(const Timing& specified, TestTimedItemEventDelegate* eventDele
gate) | 83 TestTimedItem(const Timing& specified, TestTimedItemEventDelegate* eventDele
gate) |
| 89 : TimedItem(specified, adoptPtr(eventDelegate)) | 84 : TimedItem(specified, adoptPtr(eventDelegate)) |
| 90 , m_eventDelegate(eventDelegate) | 85 , m_eventDelegate(eventDelegate) |
| 91 { | 86 { |
| 92 } | 87 } |
| 93 | 88 |
| 94 TestTimedItemEventDelegate* m_eventDelegate; | 89 TestTimedItemEventDelegate* m_eventDelegate; |
| 95 }; | 90 }; |
| 96 | 91 |
| 97 TEST(TimedItem, Sanity) | 92 TEST(TimedItem, Sanity) |
| 98 { | 93 { |
| 99 Timing timing; | 94 Timing timing; |
| 100 timing.hasIterationDuration = true; | 95 timing.hasIterationDuration = true; |
| 101 timing.iterationDuration = 2; | 96 timing.iterationDuration = 2; |
| 102 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); | 97 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); |
| 103 | 98 |
| 104 ASSERT_FALSE(timedItem->isCurrent()); | |
| 105 ASSERT_FALSE(timedItem->isInEffect()); | |
| 106 ASSERT_FALSE(timedItem->isInPlay()); | |
| 107 ASSERT_TRUE(isNull(timedItem->currentIteration())); | |
| 108 ASSERT_EQ(0, timedItem->startTime()); | 99 ASSERT_EQ(0, timedItem->startTime()); |
| 109 ASSERT_TRUE(isNull(timedItem->activeDuration())); | |
| 110 ASSERT_TRUE(isNull(timedItem->timeFraction())); | |
| 111 | 100 |
| 112 timedItem->updateInheritedTime(0); | 101 timedItem->updateInheritedTime(0); |
| 113 | 102 |
| 103 ASSERT_EQ(TimedItem::PhaseActive, timedItem->phase()); |
| 114 ASSERT_TRUE(timedItem->isInPlay()); | 104 ASSERT_TRUE(timedItem->isInPlay()); |
| 115 ASSERT_TRUE(timedItem->isCurrent()); | 105 ASSERT_TRUE(timedItem->isCurrent()); |
| 116 ASSERT_TRUE(timedItem->isInEffect()); | 106 ASSERT_TRUE(timedItem->isInEffect()); |
| 117 ASSERT_EQ(0, timedItem->currentIteration()); | 107 ASSERT_EQ(0, timedItem->currentIteration()); |
| 118 ASSERT_EQ(0, timedItem->startTime()); | 108 ASSERT_EQ(0, timedItem->startTime()); |
| 119 ASSERT_EQ(2, timedItem->activeDuration()); | 109 ASSERT_EQ(2, timedItem->activeDuration()); |
| 120 ASSERT_EQ(0, timedItem->timeFraction()); | 110 ASSERT_EQ(0, timedItem->timeFraction()); |
| 121 | 111 |
| 122 timedItem->updateInheritedTime(1); | 112 timedItem->updateInheritedTime(1); |
| 123 | 113 |
| 114 ASSERT_EQ(TimedItem::PhaseActive, timedItem->phase()); |
| 124 ASSERT_TRUE(timedItem->isInPlay()); | 115 ASSERT_TRUE(timedItem->isInPlay()); |
| 125 ASSERT_TRUE(timedItem->isCurrent()); | 116 ASSERT_TRUE(timedItem->isCurrent()); |
| 126 ASSERT_TRUE(timedItem->isInEffect()); | 117 ASSERT_TRUE(timedItem->isInEffect()); |
| 127 ASSERT_EQ(0, timedItem->currentIteration()); | 118 ASSERT_EQ(0, timedItem->currentIteration()); |
| 128 ASSERT_EQ(0, timedItem->startTime()); | 119 ASSERT_EQ(0, timedItem->startTime()); |
| 129 ASSERT_EQ(2, timedItem->activeDuration()); | 120 ASSERT_EQ(2, timedItem->activeDuration()); |
| 130 ASSERT_EQ(0.5, timedItem->timeFraction()); | 121 ASSERT_EQ(0.5, timedItem->timeFraction()); |
| 131 | 122 |
| 132 timedItem->updateInheritedTime(2); | 123 timedItem->updateInheritedTime(2); |
| 133 | 124 |
| 125 ASSERT_EQ(TimedItem::PhaseAfter, timedItem->phase()); |
| 134 ASSERT_FALSE(timedItem->isInPlay()); | 126 ASSERT_FALSE(timedItem->isInPlay()); |
| 135 ASSERT_FALSE(timedItem->isCurrent()); | 127 ASSERT_FALSE(timedItem->isCurrent()); |
| 136 ASSERT_TRUE(timedItem->isInEffect()); | 128 ASSERT_TRUE(timedItem->isInEffect()); |
| 137 ASSERT_EQ(0, timedItem->currentIteration()); | 129 ASSERT_EQ(0, timedItem->currentIteration()); |
| 138 ASSERT_EQ(0, timedItem->startTime()); | 130 ASSERT_EQ(0, timedItem->startTime()); |
| 139 ASSERT_EQ(2, timedItem->activeDuration()); | 131 ASSERT_EQ(2, timedItem->activeDuration()); |
| 140 ASSERT_EQ(1, timedItem->timeFraction()); | 132 ASSERT_EQ(1, timedItem->timeFraction()); |
| 141 | 133 |
| 142 timedItem->updateInheritedTime(3); | 134 timedItem->updateInheritedTime(3); |
| 143 | 135 |
| 136 ASSERT_EQ(TimedItem::PhaseAfter, timedItem->phase()); |
| 144 ASSERT_FALSE(timedItem->isInPlay()); | 137 ASSERT_FALSE(timedItem->isInPlay()); |
| 145 ASSERT_FALSE(timedItem->isCurrent()); | 138 ASSERT_FALSE(timedItem->isCurrent()); |
| 146 ASSERT_TRUE(timedItem->isInEffect()); | 139 ASSERT_TRUE(timedItem->isInEffect()); |
| 147 ASSERT_EQ(0, timedItem->currentIteration()); | 140 ASSERT_EQ(0, timedItem->currentIteration()); |
| 148 ASSERT_EQ(0, timedItem->startTime()); | 141 ASSERT_EQ(0, timedItem->startTime()); |
| 149 ASSERT_EQ(2, timedItem->activeDuration()); | 142 ASSERT_EQ(2, timedItem->activeDuration()); |
| 150 ASSERT_EQ(1, timedItem->timeFraction()); | 143 ASSERT_EQ(1, timedItem->timeFraction()); |
| 151 } | 144 } |
| 152 | 145 |
| 153 TEST(TimedItem, FillForwards) | 146 TEST(TimedItem, FillForwards) |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 timedItem->updateInheritedTime(2.75); | 318 timedItem->updateInheritedTime(2.75); |
| 326 ASSERT_EQ(2, timedItem->currentIteration()); | 319 ASSERT_EQ(2, timedItem->currentIteration()); |
| 327 ASSERT_EQ(0.25, timedItem->timeFraction()); | 320 ASSERT_EQ(0.25, timedItem->timeFraction()); |
| 328 } | 321 } |
| 329 | 322 |
| 330 TEST(TimedItem, ZeroDurationSanity) | 323 TEST(TimedItem, ZeroDurationSanity) |
| 331 { | 324 { |
| 332 Timing timing; | 325 Timing timing; |
| 333 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); | 326 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); |
| 334 | 327 |
| 335 ASSERT_FALSE(timedItem->isInPlay()); | |
| 336 ASSERT_FALSE(timedItem->isCurrent()); | |
| 337 ASSERT_FALSE(timedItem->isInEffect()); | |
| 338 ASSERT_TRUE(isNull(timedItem->currentIteration())); | |
| 339 ASSERT_EQ(0, timedItem->startTime()); | 328 ASSERT_EQ(0, timedItem->startTime()); |
| 340 ASSERT_TRUE(isNull(timedItem->activeDuration())); | |
| 341 ASSERT_TRUE(isNull(timedItem->timeFraction())); | |
| 342 | 329 |
| 343 timedItem->updateInheritedTime(0); | 330 timedItem->updateInheritedTime(0); |
| 344 | 331 |
| 332 ASSERT_EQ(TimedItem::PhaseAfter, timedItem->phase()); |
| 345 ASSERT_FALSE(timedItem->isInPlay()); | 333 ASSERT_FALSE(timedItem->isInPlay()); |
| 346 ASSERT_FALSE(timedItem->isCurrent()); | 334 ASSERT_FALSE(timedItem->isCurrent()); |
| 347 ASSERT_TRUE(timedItem->isInEffect()); | 335 ASSERT_TRUE(timedItem->isInEffect()); |
| 348 ASSERT_EQ(0, timedItem->currentIteration()); | 336 ASSERT_EQ(0, timedItem->currentIteration()); |
| 349 ASSERT_EQ(0, timedItem->startTime()); | 337 ASSERT_EQ(0, timedItem->startTime()); |
| 350 ASSERT_EQ(0, timedItem->activeDuration()); | 338 ASSERT_EQ(0, timedItem->activeDuration()); |
| 351 ASSERT_EQ(1, timedItem->timeFraction()); | 339 ASSERT_EQ(1, timedItem->timeFraction()); |
| 352 | 340 |
| 353 timedItem->updateInheritedTime(1); | 341 timedItem->updateInheritedTime(1); |
| 354 | 342 |
| 343 ASSERT_EQ(TimedItem::PhaseAfter, timedItem->phase()); |
| 355 ASSERT_FALSE(timedItem->isInPlay()); | 344 ASSERT_FALSE(timedItem->isInPlay()); |
| 356 ASSERT_FALSE(timedItem->isCurrent()); | 345 ASSERT_FALSE(timedItem->isCurrent()); |
| 357 ASSERT_TRUE(timedItem->isInEffect()); | 346 ASSERT_TRUE(timedItem->isInEffect()); |
| 358 ASSERT_EQ(0, timedItem->currentIteration()); | 347 ASSERT_EQ(0, timedItem->currentIteration()); |
| 359 ASSERT_EQ(0, timedItem->startTime()); | 348 ASSERT_EQ(0, timedItem->startTime()); |
| 360 ASSERT_EQ(0, timedItem->activeDuration()); | 349 ASSERT_EQ(0, timedItem->activeDuration()); |
| 361 ASSERT_EQ(1, timedItem->timeFraction()); | 350 ASSERT_EQ(1, timedItem->timeFraction()); |
| 362 } | 351 } |
| 363 | 352 |
| 364 TEST(TimedItem, ZeroDurationFillForwards) | 353 TEST(TimedItem, ZeroDurationFillForwards) |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 ASSERT_EQ(1, timedItem->currentIteration()); | 528 ASSERT_EQ(1, timedItem->currentIteration()); |
| 540 ASSERT_EQ(1, timedItem->timeFraction()); | 529 ASSERT_EQ(1, timedItem->timeFraction()); |
| 541 } | 530 } |
| 542 | 531 |
| 543 TEST(TimedItem, Events) | 532 TEST(TimedItem, Events) |
| 544 { | 533 { |
| 545 Timing timing; | 534 Timing timing; |
| 546 timing.hasIterationDuration = true; | 535 timing.hasIterationDuration = true; |
| 547 timing.iterationDuration = 1; | 536 timing.iterationDuration = 1; |
| 548 timing.iterationCount = 2; | 537 timing.iterationCount = 2; |
| 538 timing.startDelay = 1; |
| 549 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); | 539 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); |
| 550 | 540 |
| 551 timedItem->updateInheritedTime(0.3); | 541 // First sample |
| 542 timedItem->updateInheritedTime(0.0); |
| 552 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 543 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); |
| 553 EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 544 |
| 545 // Before start |
| 546 timedItem->updateInheritedTime(0.5); |
| 547 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 548 |
| 549 // First iteration |
| 550 timedItem->updateInheritedTime(1.5); |
| 551 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); |
| 552 EXPECT_TRUE(timedItem->eventDelegate()->phaseChanged()); |
| 554 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); | 553 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); |
| 555 | 554 |
| 556 timedItem->updateInheritedTime(0.6); | 555 timedItem->updateInheritedTime(1.6); |
| 557 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); | 556 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 558 | 557 |
| 559 timedItem->updateInheritedTime(1.5); | 558 // Second iteration |
| 560 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | |
| 561 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); | |
| 562 EXPECT_FALSE(timedItem->eventDelegate()->playStateChanged()); | |
| 563 | |
| 564 timedItem->updateInheritedTime(2.5); | 559 timedItem->updateInheritedTime(2.5); |
| 565 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 560 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); |
| 566 EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); | 561 EXPECT_FALSE(timedItem->eventDelegate()->phaseChanged()); |
| 567 EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 562 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); |
| 568 | 563 |
| 569 timedItem->updateInheritedTime(3); | 564 timedItem->updateInheritedTime(2.6); |
| 570 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); | 565 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 571 | 566 |
| 572 timedItem->updateInheritedTime(1.5); | 567 // After end |
| 568 timedItem->updateInheritedTime(3.5); |
| 573 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 569 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); |
| 570 EXPECT_TRUE(timedItem->eventDelegate()->phaseChanged()); |
| 574 EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); | 571 EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); |
| 575 EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 572 |
| 573 timedItem->updateInheritedTime(3.6); |
| 574 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 576 } | 575 } |
| 577 } | 576 } |
| OLD | NEW |