Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layer_animation_controller.h" | 5 #include "cc/layer_animation_controller.h" |
| 6 | 6 |
| 7 #include "cc/animation.h" | 7 #include "cc/animation.h" |
| 8 #include "cc/animation_curve.h" | 8 #include "cc/animation_curve.h" |
| 9 #include "cc/test/animation_test_common.h" | 9 #include "cc/test/animation_test_common.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 | 60 |
| 61 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 61 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 62 | 62 |
| 63 EXPECT_TRUE(controllerImpl->getAnimation(0, Animation::Opacity)); | 63 EXPECT_TRUE(controllerImpl->getAnimation(0, Animation::Opacity)); |
| 64 EXPECT_EQ(Animation::WaitingForTargetAvailability, controllerImpl->getAnimat ion(0, Animation::Opacity)->runState()); | 64 EXPECT_EQ(Animation::WaitingForTargetAvailability, controllerImpl->getAnimat ion(0, Animation::Opacity)->runState()); |
| 65 | 65 |
| 66 AnimationEventsVector events; | 66 AnimationEventsVector events; |
| 67 controllerImpl->animate(1); | 67 controllerImpl->animate(1); |
| 68 controllerImpl->updateState(&events); | 68 controllerImpl->updateState(&events); |
| 69 | 69 |
| 70 // Synchronize the start times. | 70 // Synchronize the start times. This will also have a property update |
| 71 EXPECT_EQ(1u, events.size()); | 71 // event for opacity. |
| 72 EXPECT_EQ(2u, events.size()); | |
| 72 controller->OnAnimationStarted(events[0]); | 73 controller->OnAnimationStarted(events[0]); |
| 73 EXPECT_EQ(controller->getAnimation(0, Animation::Opacity)->startTime(), cont rollerImpl->getAnimation(0, Animation::Opacity)->startTime()); | 74 EXPECT_EQ(controller->getAnimation(0, Animation::Opacity)->startTime(), cont rollerImpl->getAnimation(0, Animation::Opacity)->startTime()); |
| 74 | 75 |
| 75 // Start the animation on the main thread. Should not affect the start time. | 76 // Start the animation on the main thread. Should not affect the start time. |
| 76 controller->animate(1.5); | 77 controller->animate(1.5); |
| 77 controller->updateState(0); | 78 controller->updateState(0); |
| 78 EXPECT_EQ(controller->getAnimation(0, Animation::Opacity)->startTime(), cont rollerImpl->getAnimation(0, Animation::Opacity)->startTime()); | 79 EXPECT_EQ(controller->getAnimation(0, Animation::Opacity)->startTime(), cont rollerImpl->getAnimation(0, Animation::Opacity)->startTime()); |
| 79 } | 80 } |
| 80 | 81 |
| 81 TEST(LayerAnimationControllerTest, syncPauseAndResume) | 82 TEST(LayerAnimationControllerTest, syncPauseAndResume) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 150 |
| 150 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); | 151 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); |
| 151 | 152 |
| 152 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 153 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 153 | 154 |
| 154 // Even though the main thread has a 'new' animation, it should not be pushe d because the animation has already completed on the impl thread. | 155 // Even though the main thread has a 'new' animation, it should not be pushe d because the animation has already completed on the impl thread. |
| 155 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); | 156 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); |
| 156 } | 157 } |
| 157 | 158 |
| 158 // Tests that transitioning opacity from 0 to 1 works as expected. | 159 // Tests that transitioning opacity from 0 to 1 works as expected. |
| 160 | |
| 161 static const AnimationEvent* getLastPropertyUpdateOpacityEvent(const AnimationEv entsVector* events) | |
| 162 { | |
| 163 const AnimationEvent* event = 0; | |
| 164 for (size_t i = 0; i < events->size(); ++i) | |
| 165 if ((*events)[i].type == AnimationEvent::PropertyUpdate && | |
| 166 (*events)[i].targetProperty == Animation::Opacity) | |
| 167 event = &(*events)[i]; | |
| 168 | |
| 169 return event; | |
| 170 } | |
| 171 | |
|
Ian Vollick
2013/03/06 01:00:57
I would like 3 new tests rather than these tweaks
wjmaclean
2013/03/06 17:03:13
Now that non implOnly animations do not send back
| |
| 159 TEST(LayerAnimationControllerTest, TrivialTransition) | 172 TEST(LayerAnimationControllerTest, TrivialTransition) |
| 160 { | 173 { |
| 161 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 174 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); |
| 162 FakeLayerAnimationValueObserver dummy; | 175 FakeLayerAnimationValueObserver dummy; |
| 163 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 176 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); |
| 164 controller->addObserver(&dummy); | 177 controller->addObserver(&dummy); |
| 165 | 178 |
| 166 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 179 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
| 167 | 180 |
| 168 controller->addAnimation(toAdd.Pass()); | 181 controller->addAnimation(toAdd.Pass()); |
| 169 controller->animate(0); | 182 controller->animate(0); |
| 170 controller->updateState(events.get()); | 183 controller->updateState(events.get()); |
| 171 EXPECT_TRUE(controller->hasActiveAnimation()); | 184 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 172 EXPECT_EQ(0, dummy.opacity()); | 185 EXPECT_EQ(0, dummy.opacity()); |
| 186 EXPECT_EQ(2, events->size()); | |
| 187 const AnimationEvent* startOpacityEvent = getLastPropertyUpdateOpacityEvent( events.get()); | |
| 188 ASSERT_TRUE(startOpacityEvent); | |
| 189 EXPECT_EQ(0, startOpacityEvent->value); | |
| 173 controller->animate(1); | 190 controller->animate(1); |
| 174 controller->updateState(events.get()); | 191 controller->updateState(events.get()); |
| 175 EXPECT_EQ(1, dummy.opacity()); | 192 EXPECT_EQ(1, dummy.opacity()); |
| 176 EXPECT_FALSE(controller->hasActiveAnimation()); | 193 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 194 EXPECT_EQ(4, events->size()); | |
| 195 const AnimationEvent* endOpacityEvent = getLastPropertyUpdateOpacityEvent(ev ents.get()); | |
| 196 ASSERT_TRUE(endOpacityEvent); | |
| 197 EXPECT_EQ(1, endOpacityEvent->value); | |
| 177 } | 198 } |
| 178 | 199 |
| 179 // Tests animations that are waiting for a synchronized start time do not finish . | 200 // Tests animations that are waiting for a synchronized start time do not finish . |
| 180 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe yWaitLongerToStartThanTheirDuration) | 201 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe yWaitLongerToStartThanTheirDuration) |
| 181 { | 202 { |
| 182 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 203 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); |
| 183 FakeLayerAnimationValueObserver dummy; | 204 FakeLayerAnimationValueObserver dummy; |
| 184 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 205 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); |
| 185 controller->addObserver(&dummy); | 206 controller->addObserver(&dummy); |
| 186 | 207 |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 | 654 |
| 634 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 0, 1)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); | 655 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 0, 1)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); |
| 635 | 656 |
| 636 // Animate but don't updateState. | 657 // Animate but don't updateState. |
| 637 controller->animate(1); | 658 controller->animate(1); |
| 638 | 659 |
| 639 controller->animate(2); | 660 controller->animate(2); |
| 640 events.reset(new AnimationEventsVector); | 661 events.reset(new AnimationEventsVector); |
| 641 controller->updateState(events.get()); | 662 controller->updateState(events.get()); |
| 642 | 663 |
| 643 // Should have one Started event and one Finished event. | 664 // Should have one Started event, one Finished event, and one |
| 644 EXPECT_EQ(2, events->size()); | 665 // opacity property update event. |
| 666 EXPECT_EQ(3, events->size()); | |
| 645 EXPECT_NE((*events)[0].type, (*events)[1].type); | 667 EXPECT_NE((*events)[0].type, (*events)[1].type); |
| 668 EXPECT_NE((*events)[0].type, (*events)[2].type); | |
| 669 EXPECT_NE((*events)[1].type, (*events)[2].type); | |
| 646 | 670 |
| 647 // The float transition should still be at its starting point. | 671 // The float transition should still be at its starting point. |
| 648 EXPECT_TRUE(controller->hasActiveAnimation()); | 672 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 649 EXPECT_EQ(0, dummy.opacity()); | 673 EXPECT_EQ(0, dummy.opacity()); |
| 650 | 674 |
| 651 controller->animate(3); | 675 controller->animate(3); |
| 652 controller->updateState(events.get()); | 676 controller->updateState(events.get()); |
| 653 | 677 |
| 654 // The float tranisition should now be done. | 678 // The float tranisition should now be done. |
| 655 EXPECT_EQ(1, dummy.opacity()); | 679 EXPECT_EQ(1, dummy.opacity()); |
| 656 EXPECT_FALSE(controller->hasActiveAnimation()); | 680 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 657 } | 681 } |
| 658 | 682 |
| 659 } // namespace | 683 } // namespace |
| 660 } // namespace cc | 684 } // namespace cc |
| OLD | NEW |