| 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 21 matching lines...) Expand all Loading... |
| 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 TimedItemEventDelegate { |
| 41 public: | 41 public: |
| 42 void onEventCondition(bool wasInPlay, bool isInPlay, double previousIteratio
n, double currentIteration) OVERRIDE | 42 void onEventCondition(bool wasInPlay, bool isInPlay, bool wasCurrent, bool i
sCurrent, double previousIteration, double currentIteration) OVERRIDE |
| 43 { | 43 { |
| 44 m_eventTriggered = true; | 44 m_eventTriggered = true; |
| 45 m_playStateChanged = wasInPlay != isInPlay; | 45 m_inPlayStateChanged = wasInPlay != isInPlay; |
| 46 m_currentStateChanged = wasCurrent != isCurrent; |
| 46 m_iterationChanged = isInPlay && previousIteration != currentIteration; | 47 m_iterationChanged = isInPlay && previousIteration != currentIteration; |
| 47 if (isInPlay) | 48 if (isInPlay) |
| 48 ASSERT(!isNull(currentIteration)); | 49 ASSERT(!isNull(currentIteration)); |
| 49 | 50 |
| 50 } | 51 } |
| 51 void reset() | 52 void reset() |
| 52 { | 53 { |
| 53 m_eventTriggered = false; | 54 m_eventTriggered = false; |
| 54 m_playStateChanged = false; | 55 m_inPlayStateChanged = false; |
| 56 m_currentStateChanged = false; |
| 55 m_iterationChanged = false; | 57 m_iterationChanged = false; |
| 56 } | 58 } |
| 57 bool eventTriggered() { return m_eventTriggered; } | 59 bool eventTriggered() { return m_eventTriggered; } |
| 58 bool playStateChanged() { return m_playStateChanged; } | 60 bool inPlayStateChanged() { return m_inPlayStateChanged; } |
| 61 bool currentStateChanged() { return m_currentStateChanged; } |
| 59 bool iterationChanged() { return m_iterationChanged; } | 62 bool iterationChanged() { return m_iterationChanged; } |
| 60 | 63 |
| 61 private: | 64 private: |
| 62 bool m_eventTriggered; | 65 bool m_eventTriggered; |
| 63 bool m_playStateChanged; | 66 bool m_inPlayStateChanged; |
| 67 bool m_currentStateChanged; |
| 64 bool m_iterationChanged; | 68 bool m_iterationChanged; |
| 65 }; | 69 }; |
| 66 | 70 |
| 67 class TestTimedItem : public TimedItem { | 71 class TestTimedItem : public TimedItem { |
| 68 public: | 72 public: |
| 69 static PassRefPtr<TestTimedItem> create(const Timing& specified) | 73 static PassRefPtr<TestTimedItem> create(const Timing& specified) |
| 70 { | 74 { |
| 71 return adoptRef(new TestTimedItem(specified, new TestTimedItemEventDeleg
ate())); | 75 return adoptRef(new TestTimedItem(specified, new TestTimedItemEventDeleg
ate())); |
| 72 } | 76 } |
| 73 | 77 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 94 TestTimedItemEventDelegate* m_eventDelegate; | 98 TestTimedItemEventDelegate* m_eventDelegate; |
| 95 }; | 99 }; |
| 96 | 100 |
| 97 TEST(TimedItem, Sanity) | 101 TEST(TimedItem, Sanity) |
| 98 { | 102 { |
| 99 Timing timing; | 103 Timing timing; |
| 100 timing.hasIterationDuration = true; | 104 timing.hasIterationDuration = true; |
| 101 timing.iterationDuration = 2; | 105 timing.iterationDuration = 2; |
| 102 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); | 106 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); |
| 103 | 107 |
| 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()); | 108 ASSERT_EQ(0, timedItem->startTime()); |
| 109 ASSERT_TRUE(isNull(timedItem->activeDuration())); | |
| 110 ASSERT_TRUE(isNull(timedItem->timeFraction())); | |
| 111 | 109 |
| 112 timedItem->updateInheritedTime(0); | 110 timedItem->updateInheritedTime(0); |
| 113 | 111 |
| 114 ASSERT_TRUE(timedItem->isInPlay()); | 112 ASSERT_TRUE(timedItem->isInPlay()); |
| 115 ASSERT_TRUE(timedItem->isCurrent()); | 113 ASSERT_TRUE(timedItem->isCurrent()); |
| 116 ASSERT_TRUE(timedItem->isInEffect()); | 114 ASSERT_TRUE(timedItem->isInEffect()); |
| 117 ASSERT_EQ(0, timedItem->currentIteration()); | 115 ASSERT_EQ(0, timedItem->currentIteration()); |
| 118 ASSERT_EQ(0, timedItem->startTime()); | 116 ASSERT_EQ(0, timedItem->startTime()); |
| 119 ASSERT_EQ(2, timedItem->activeDuration()); | 117 ASSERT_EQ(2, timedItem->activeDuration()); |
| 120 ASSERT_EQ(0, timedItem->timeFraction()); | 118 ASSERT_EQ(0, timedItem->timeFraction()); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 timedItem->updateInheritedTime(2.75); | 323 timedItem->updateInheritedTime(2.75); |
| 326 ASSERT_EQ(2, timedItem->currentIteration()); | 324 ASSERT_EQ(2, timedItem->currentIteration()); |
| 327 ASSERT_EQ(0.25, timedItem->timeFraction()); | 325 ASSERT_EQ(0.25, timedItem->timeFraction()); |
| 328 } | 326 } |
| 329 | 327 |
| 330 TEST(TimedItem, ZeroDurationSanity) | 328 TEST(TimedItem, ZeroDurationSanity) |
| 331 { | 329 { |
| 332 Timing timing; | 330 Timing timing; |
| 333 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); | 331 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); |
| 334 | 332 |
| 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()); | 333 ASSERT_EQ(0, timedItem->startTime()); |
| 340 ASSERT_TRUE(isNull(timedItem->activeDuration())); | |
| 341 ASSERT_TRUE(isNull(timedItem->timeFraction())); | |
| 342 | 334 |
| 343 timedItem->updateInheritedTime(0); | 335 timedItem->updateInheritedTime(0); |
| 344 | 336 |
| 345 ASSERT_FALSE(timedItem->isInPlay()); | 337 ASSERT_FALSE(timedItem->isInPlay()); |
| 346 ASSERT_FALSE(timedItem->isCurrent()); | 338 ASSERT_FALSE(timedItem->isCurrent()); |
| 347 ASSERT_TRUE(timedItem->isInEffect()); | 339 ASSERT_TRUE(timedItem->isInEffect()); |
| 348 ASSERT_EQ(0, timedItem->currentIteration()); | 340 ASSERT_EQ(0, timedItem->currentIteration()); |
| 349 ASSERT_EQ(0, timedItem->startTime()); | 341 ASSERT_EQ(0, timedItem->startTime()); |
| 350 ASSERT_EQ(0, timedItem->activeDuration()); | 342 ASSERT_EQ(0, timedItem->activeDuration()); |
| 351 ASSERT_EQ(1, timedItem->timeFraction()); | 343 ASSERT_EQ(1, timedItem->timeFraction()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 ASSERT_EQ(1, timedItem->currentIteration()); | 531 ASSERT_EQ(1, timedItem->currentIteration()); |
| 540 ASSERT_EQ(1, timedItem->timeFraction()); | 532 ASSERT_EQ(1, timedItem->timeFraction()); |
| 541 } | 533 } |
| 542 | 534 |
| 543 TEST(TimedItem, Events) | 535 TEST(TimedItem, Events) |
| 544 { | 536 { |
| 545 Timing timing; | 537 Timing timing; |
| 546 timing.hasIterationDuration = true; | 538 timing.hasIterationDuration = true; |
| 547 timing.iterationDuration = 1; | 539 timing.iterationDuration = 1; |
| 548 timing.iterationCount = 2; | 540 timing.iterationCount = 2; |
| 541 timing.startDelay = 1; |
| 549 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); | 542 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); |
| 550 | 543 |
| 551 timedItem->updateInheritedTime(0.3); | 544 // Before start |
| 545 timedItem->updateInheritedTime(0.0); |
| 546 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 547 |
| 548 timedItem->updateInheritedTime(0.5); |
| 549 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 550 |
| 551 // First iteration |
| 552 timedItem->updateInheritedTime(1.5); |
| 552 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 553 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); |
| 553 EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 554 EXPECT_TRUE(timedItem->eventDelegate()->inPlayStateChanged()); |
| 555 EXPECT_FALSE(timedItem->eventDelegate()->currentStateChanged()); |
| 554 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); | 556 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); |
| 555 | 557 |
| 556 timedItem->updateInheritedTime(0.6); | 558 timedItem->updateInheritedTime(1.6); |
| 557 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); | 559 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 558 | 560 |
| 559 timedItem->updateInheritedTime(1.5); | 561 // 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); | 562 timedItem->updateInheritedTime(2.5); |
| 565 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 563 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); |
| 566 EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); | 564 EXPECT_FALSE(timedItem->eventDelegate()->inPlayStateChanged()); |
| 567 EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 565 EXPECT_FALSE(timedItem->eventDelegate()->currentStateChanged()); |
| 566 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); |
| 568 | 567 |
| 569 timedItem->updateInheritedTime(3); | 568 timedItem->updateInheritedTime(2.6); |
| 570 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); | 569 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 571 | 570 |
| 572 timedItem->updateInheritedTime(1.5); | 571 // After end |
| 572 timedItem->updateInheritedTime(3.5); |
| 573 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 573 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); |
| 574 EXPECT_TRUE(timedItem->eventDelegate()->inPlayStateChanged()); |
| 575 EXPECT_TRUE(timedItem->eventDelegate()->currentStateChanged()); |
| 574 EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); | 576 EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); |
| 575 EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 577 |
| 578 timedItem->updateInheritedTime(3.6); |
| 579 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 576 } | 580 } |
| 577 } | 581 } |
| OLD | NEW |