Chromium Code Reviews| 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 |
| 114 ASSERT_TRUE(timedItem->isInPlay()); | 103 ASSERT_TRUE(timedItem->isInPlay()); |
| 115 ASSERT_TRUE(timedItem->isCurrent()); | 104 ASSERT_TRUE(timedItem->isCurrent()); |
| 116 ASSERT_TRUE(timedItem->isInEffect()); | 105 ASSERT_TRUE(timedItem->isInEffect()); |
| 117 ASSERT_EQ(0, timedItem->currentIteration()); | 106 ASSERT_EQ(0, timedItem->currentIteration()); |
| 118 ASSERT_EQ(0, timedItem->startTime()); | 107 ASSERT_EQ(0, timedItem->startTime()); |
| 119 ASSERT_EQ(2, timedItem->activeDuration()); | 108 ASSERT_EQ(2, timedItem->activeDuration()); |
| 120 ASSERT_EQ(0, timedItem->timeFraction()); | 109 ASSERT_EQ(0, timedItem->timeFraction()); |
|
dstockwell
2013/08/21 06:18:02
test phase()
| |
| 121 | 110 |
| 122 timedItem->updateInheritedTime(1); | 111 timedItem->updateInheritedTime(1); |
| 123 | 112 |
| 124 ASSERT_TRUE(timedItem->isInPlay()); | 113 ASSERT_TRUE(timedItem->isInPlay()); |
| 125 ASSERT_TRUE(timedItem->isCurrent()); | 114 ASSERT_TRUE(timedItem->isCurrent()); |
| 126 ASSERT_TRUE(timedItem->isInEffect()); | 115 ASSERT_TRUE(timedItem->isInEffect()); |
| 127 ASSERT_EQ(0, timedItem->currentIteration()); | 116 ASSERT_EQ(0, timedItem->currentIteration()); |
| 128 ASSERT_EQ(0, timedItem->startTime()); | 117 ASSERT_EQ(0, timedItem->startTime()); |
| 129 ASSERT_EQ(2, timedItem->activeDuration()); | 118 ASSERT_EQ(2, timedItem->activeDuration()); |
| 130 ASSERT_EQ(0.5, timedItem->timeFraction()); | 119 ASSERT_EQ(0.5, timedItem->timeFraction()); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 timedItem->updateInheritedTime(2.75); | 314 timedItem->updateInheritedTime(2.75); |
| 326 ASSERT_EQ(2, timedItem->currentIteration()); | 315 ASSERT_EQ(2, timedItem->currentIteration()); |
| 327 ASSERT_EQ(0.25, timedItem->timeFraction()); | 316 ASSERT_EQ(0.25, timedItem->timeFraction()); |
| 328 } | 317 } |
| 329 | 318 |
| 330 TEST(TimedItem, ZeroDurationSanity) | 319 TEST(TimedItem, ZeroDurationSanity) |
| 331 { | 320 { |
| 332 Timing timing; | 321 Timing timing; |
| 333 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); | 322 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); |
| 334 | 323 |
| 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()); | 324 ASSERT_EQ(0, timedItem->startTime()); |
| 340 ASSERT_TRUE(isNull(timedItem->activeDuration())); | |
| 341 ASSERT_TRUE(isNull(timedItem->timeFraction())); | |
| 342 | 325 |
| 343 timedItem->updateInheritedTime(0); | 326 timedItem->updateInheritedTime(0); |
| 344 | 327 |
| 345 ASSERT_FALSE(timedItem->isInPlay()); | 328 ASSERT_FALSE(timedItem->isInPlay()); |
| 346 ASSERT_FALSE(timedItem->isCurrent()); | 329 ASSERT_FALSE(timedItem->isCurrent()); |
| 347 ASSERT_TRUE(timedItem->isInEffect()); | 330 ASSERT_TRUE(timedItem->isInEffect()); |
| 348 ASSERT_EQ(0, timedItem->currentIteration()); | 331 ASSERT_EQ(0, timedItem->currentIteration()); |
| 349 ASSERT_EQ(0, timedItem->startTime()); | 332 ASSERT_EQ(0, timedItem->startTime()); |
| 350 ASSERT_EQ(0, timedItem->activeDuration()); | 333 ASSERT_EQ(0, timedItem->activeDuration()); |
| 351 ASSERT_EQ(1, timedItem->timeFraction()); | 334 ASSERT_EQ(1, timedItem->timeFraction()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 ASSERT_EQ(1, timedItem->currentIteration()); | 522 ASSERT_EQ(1, timedItem->currentIteration()); |
| 540 ASSERT_EQ(1, timedItem->timeFraction()); | 523 ASSERT_EQ(1, timedItem->timeFraction()); |
| 541 } | 524 } |
| 542 | 525 |
| 543 TEST(TimedItem, Events) | 526 TEST(TimedItem, Events) |
| 544 { | 527 { |
| 545 Timing timing; | 528 Timing timing; |
| 546 timing.hasIterationDuration = true; | 529 timing.hasIterationDuration = true; |
| 547 timing.iterationDuration = 1; | 530 timing.iterationDuration = 1; |
| 548 timing.iterationCount = 2; | 531 timing.iterationCount = 2; |
| 532 timing.startDelay = 1; | |
| 549 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); | 533 RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); |
| 550 | 534 |
| 551 timedItem->updateInheritedTime(0.3); | 535 // First sample |
| 536 timedItem->updateInheritedTime(0.0); | |
| 552 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 537 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); |
| 553 EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 538 |
| 539 // Before start | |
| 540 timedItem->updateInheritedTime(0.5); | |
| 541 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); | |
| 542 | |
| 543 // First iteration | |
| 544 timedItem->updateInheritedTime(1.5); | |
| 545 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | |
| 546 EXPECT_TRUE(timedItem->eventDelegate()->phaseChanged()); | |
| 554 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); | 547 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); |
| 555 | 548 |
| 556 timedItem->updateInheritedTime(0.6); | 549 timedItem->updateInheritedTime(1.6); |
| 557 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); | 550 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 558 | 551 |
| 559 timedItem->updateInheritedTime(1.5); | 552 // 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); | 553 timedItem->updateInheritedTime(2.5); |
| 565 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 554 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); |
| 566 EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); | 555 EXPECT_FALSE(timedItem->eventDelegate()->phaseChanged()); |
| 567 EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 556 EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); |
| 568 | 557 |
| 569 timedItem->updateInheritedTime(3); | 558 timedItem->updateInheritedTime(2.6); |
| 570 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); | 559 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); |
| 571 | 560 |
| 572 timedItem->updateInheritedTime(1.5); | 561 // After end |
| 562 timedItem->updateInheritedTime(3.5); | |
| 573 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 563 ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); |
| 564 EXPECT_TRUE(timedItem->eventDelegate()->phaseChanged()); | |
| 574 EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); | 565 EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); |
| 575 EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 566 |
| 567 timedItem->updateInheritedTime(3.6); | |
| 568 ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); | |
| 576 } | 569 } |
| 577 } | 570 } |
| OLD | NEW |