| 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 { | 
 |   41 public: | 
 |   42     void onEventCondition(bool wasInPlay, bool isInPlay, double previousIteratio
     n, double currentIteration) OVERRIDE | 
 |   43     { | 
 |   44         m_eventTriggered = true; | 
 |   45         m_playStateChanged = wasInPlay != isInPlay; | 
 |   46         m_iterationChanged = isInPlay && previousIteration != currentIteration; | 
 |   47         if (isInPlay) | 
 |   48             ASSERT(!isNull(currentIteration)); | 
 |   49  | 
 |   50     } | 
 |   51     void reset() | 
 |   52     { | 
 |   53         m_eventTriggered = false; | 
 |   54         m_playStateChanged = false; | 
 |   55         m_iterationChanged = false; | 
 |   56     } | 
 |   57     bool eventTriggered() { return m_eventTriggered; } | 
 |   58     bool playStateChanged() { return m_playStateChanged; } | 
 |   59     bool iterationChanged() { return m_iterationChanged; } | 
 |   60  | 
 |   61 private: | 
 |   62     bool m_eventTriggered; | 
 |   63     bool m_playStateChanged; | 
 |   64     bool m_iterationChanged; | 
 |   65 }; | 
 |   66  | 
|   40 class TestTimedItem : public TimedItem { |   67 class TestTimedItem : public TimedItem { | 
|   41 public: |   68 public: | 
|   42     static PassRefPtr<TestTimedItem> create(const Timing& specified) |   69     static PassRefPtr<TestTimedItem> create(const Timing& specified) | 
|   43     { |   70     { | 
|   44         return adoptRef(new TestTimedItem(specified)); |   71         return adoptRef(new TestTimedItem(specified, new TestTimedItemEventDeleg
     ate())); | 
|   45     } |   72     } | 
|   46  |   73  | 
|   47     void updateInheritedTime(double time) |   74     void updateInheritedTime(double time) | 
|   48     { |   75     { | 
 |   76         m_eventDelegate->reset(); | 
|   49         TimedItem::updateInheritedTime(time); |   77         TimedItem::updateInheritedTime(time); | 
|   50     } |   78     } | 
|   51  |   79  | 
|   52     void updateChildrenAndEffects(bool wasActiveOrInEffect) const FINAL OVERRIDE
      { |   80     void updateChildrenAndEffects(bool wasActiveOrInEffect) const FINAL OVERRIDE
      { | 
|   53     } |   81     } | 
|   54  |   82  | 
|   55     void willDetach() { } |   83     void willDetach() { } | 
|   56  |   84  | 
 |   85     TestTimedItemEventDelegate* eventDelegate() { return m_eventDelegate; } | 
 |   86  | 
|   57 private: |   87 private: | 
|   58     TestTimedItem(const Timing& specified) |   88     TestTimedItem(const Timing& specified, TestTimedItemEventDelegate* eventDele
     gate) | 
|   59         : TimedItem(specified) |   89         : TimedItem(specified, adoptPtr(eventDelegate)) | 
 |   90         , m_eventDelegate(eventDelegate) | 
|   60     { |   91     { | 
|   61     } |   92     } | 
 |   93  | 
 |   94     TestTimedItemEventDelegate* m_eventDelegate; | 
|   62 }; |   95 }; | 
|   63  |   96  | 
|   64 TEST(TimedItem, Sanity) |   97 TEST(TimedItem, Sanity) | 
|   65 { |   98 { | 
|   66     Timing timing; |   99     Timing timing; | 
|   67     timing.hasIterationDuration = true; |  100     timing.hasIterationDuration = true; | 
|   68     timing.iterationDuration = 2; |  101     timing.iterationDuration = 2; | 
|   69     RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); |  102     RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); | 
|   70  |  103  | 
|   71     ASSERT_FALSE(timedItem->isCurrent()); |  104     ASSERT_FALSE(timedItem->isCurrent()); | 
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  499     ASSERT_TRUE(isNull(timedItem->timeFraction())); |  532     ASSERT_TRUE(isNull(timedItem->timeFraction())); | 
|  500  |  533  | 
|  501     timedItem->updateInheritedTime(0); |  534     timedItem->updateInheritedTime(0); | 
|  502     ASSERT_EQ(1, timedItem->currentIteration()); |  535     ASSERT_EQ(1, timedItem->currentIteration()); | 
|  503     ASSERT_EQ(1, timedItem->timeFraction()); |  536     ASSERT_EQ(1, timedItem->timeFraction()); | 
|  504  |  537  | 
|  505     timedItem->updateInheritedTime(1); |  538     timedItem->updateInheritedTime(1); | 
|  506     ASSERT_EQ(1, timedItem->currentIteration()); |  539     ASSERT_EQ(1, timedItem->currentIteration()); | 
|  507     ASSERT_EQ(1, timedItem->timeFraction()); |  540     ASSERT_EQ(1, timedItem->timeFraction()); | 
|  508 } |  541 } | 
 |  542  | 
 |  543 TEST(TimedItem, Events) | 
 |  544 { | 
 |  545     Timing timing; | 
 |  546     timing.hasIterationDuration = true; | 
 |  547     timing.iterationDuration = 1; | 
 |  548     timing.iterationCount = 2; | 
 |  549     RefPtr<TestTimedItem> timedItem = TestTimedItem::create(timing); | 
 |  550  | 
 |  551     timedItem->updateInheritedTime(0.3); | 
 |  552     ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 
 |  553     EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 
 |  554     EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); | 
 |  555  | 
 |  556     timedItem->updateInheritedTime(0.6); | 
 |  557     ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); | 
 |  558  | 
 |  559     timedItem->updateInheritedTime(1.5); | 
 |  560     ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 
 |  561     EXPECT_TRUE(timedItem->eventDelegate()->iterationChanged()); | 
 |  562     EXPECT_FALSE(timedItem->eventDelegate()->playStateChanged()); | 
 |  563  | 
 |  564     timedItem->updateInheritedTime(2.5); | 
 |  565     ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 
 |  566     EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); | 
 |  567     EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 
 |  568  | 
 |  569     timedItem->updateInheritedTime(3); | 
 |  570     ASSERT_FALSE(timedItem->eventDelegate()->eventTriggered()); | 
 |  571  | 
 |  572     timedItem->updateInheritedTime(1.5); | 
 |  573     ASSERT_TRUE(timedItem->eventDelegate()->eventTriggered()); | 
 |  574     EXPECT_FALSE(timedItem->eventDelegate()->iterationChanged()); | 
 |  575     EXPECT_TRUE(timedItem->eventDelegate()->playStateChanged()); | 
|  509 } |  576 } | 
 |  577 } | 
| OLD | NEW |