| 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/active_animation.h" | 7 #include "cc/active_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" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gfx/transform.h" | 12 #include "ui/gfx/transform.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 void expectTranslateX(double translateX, const gfx::Transform& matrix) | 17 void expectTranslateX(double translateX, const gfx::Transform& matrix) |
| 18 { | 18 { |
| 19 EXPECT_FLOAT_EQ(translateX, matrix.matrix().getDouble(0, 3)); | 19 EXPECT_FLOAT_EQ(translateX, matrix.matrix().getDouble(0, 3)); |
| 20 } | 20 } |
| 21 | 21 |
| 22 scoped_ptr<ActiveAnimation> createActiveAnimation(scoped_ptr<AnimationCurve> cur
ve, int id, ActiveAnimation::TargetProperty property) | 22 scoped_ptr<ActiveAnimation> createActiveAnimation(scoped_ptr<AnimationCurve> cur
ve, int id, ActiveAnimation::TargetProperty property) |
| 23 { | 23 { |
| 24 return ActiveAnimation::create(curve.Pass(), 0, id, property); | 24 return ActiveAnimation::create(curve.Pass(), 0, id, property); |
| 25 } | 25 } |
| 26 | 26 |
| 27 TEST(LayerAnimationControllerTest, syncNewAnimation) | 27 TEST(LayerAnimationControllerTest, syncNewAnimation) |
| 28 { | 28 { |
| 29 FakeLayerAnimationControllerClient dummyImpl; | 29 FakeLayerAnimationValueObserver dummyImpl; |
| 30 scoped_ptr<LayerAnimationController> controllerImpl(LayerAnimationController
::create(&dummyImpl)); | 30 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
| 31 FakeLayerAnimationControllerClient dummy; | 31 controllerImpl->addObserver(&dummyImpl); |
| 32 scoped_ptr<LayerAnimationController> controller(LayerAnimationController::cr
eate(&dummy)); | 32 FakeLayerAnimationValueObserver dummy; |
| 33 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 34 controller->addObserver(&dummy); |
| 33 | 35 |
| 34 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); | 36 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); |
| 35 | 37 |
| 36 addOpacityTransitionToController(*controller, 1, 0, 1, false); | 38 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
| 37 | 39 |
| 38 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 40 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 39 | 41 |
| 40 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; | 42 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; |
| 41 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); | 43 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); |
| 42 } | 44 } |
| 43 | 45 |
| 44 // If an animation is started on the impl thread before it is ticked on the main | 46 // If an animation is started on the impl thread before it is ticked on the main |
| 45 // thread, we must be sure to respect the synchronized start time. | 47 // thread, we must be sure to respect the synchronized start time. |
| 46 TEST(LayerAnimationControllerTest, doNotClobberStartTimes) | 48 TEST(LayerAnimationControllerTest, doNotClobberStartTimes) |
| 47 { | 49 { |
| 48 FakeLayerAnimationControllerClient dummyImpl; | 50 FakeLayerAnimationValueObserver dummyImpl; |
| 49 scoped_ptr<LayerAnimationController> controllerImpl(LayerAnimationController
::create(&dummyImpl)); | 51 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
| 50 FakeLayerAnimationControllerClient dummy; | 52 controllerImpl->addObserver(&dummyImpl); |
| 51 scoped_ptr<LayerAnimationController> controller(LayerAnimationController::cr
eate(&dummy)); | 53 FakeLayerAnimationValueObserver dummy; |
| 54 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 55 controller->addObserver(&dummy); |
| 52 | 56 |
| 53 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); | 57 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); |
| 54 | 58 |
| 55 addOpacityTransitionToController(*controller, 1, 0, 1, false); | 59 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
| 56 | 60 |
| 57 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 61 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 58 | 62 |
| 59 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; | 63 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; |
| 60 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); | 64 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); |
| 61 | 65 |
| 62 AnimationEventsVector events; | 66 AnimationEventsVector events; |
| 63 controllerImpl->animate(1, &events); | 67 controllerImpl->animate(1, &events); |
| 64 | 68 |
| 65 // Synchronize the start times. | 69 // Synchronize the start times. |
| 66 EXPECT_EQ(1u, events.size()); | 70 EXPECT_EQ(1u, events.size()); |
| 67 controller->OnAnimationStarted(events[0]); | 71 controller->OnAnimationStarted(events[0]); |
| 68 EXPECT_EQ(controller->getActiveAnimation(0, ActiveAnimation::Opacity)->start
Time(), controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)->startTi
me()); | 72 EXPECT_EQ(controller->getActiveAnimation(0, ActiveAnimation::Opacity)->start
Time(), controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)->startTi
me()); |
| 69 | 73 |
| 70 // Start the animation on the main thread. Should not affect the start time. | 74 // Start the animation on the main thread. Should not affect the start time. |
| 71 controller->animate(1.5, 0); | 75 controller->animate(1.5, 0); |
| 72 EXPECT_EQ(controller->getActiveAnimation(0, ActiveAnimation::Opacity)->start
Time(), controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)->startTi
me()); | 76 EXPECT_EQ(controller->getActiveAnimation(0, ActiveAnimation::Opacity)->start
Time(), controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)->startTi
me()); |
| 73 } | 77 } |
| 74 | 78 |
| 75 TEST(LayerAnimationControllerTest, syncPauseAndResume) | 79 TEST(LayerAnimationControllerTest, syncPauseAndResume) |
| 76 { | 80 { |
| 77 FakeLayerAnimationControllerClient dummyImpl; | 81 FakeLayerAnimationValueObserver dummyImpl; |
| 78 scoped_ptr<LayerAnimationController> controllerImpl(LayerAnimationController
::create(&dummyImpl)); | 82 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
| 79 FakeLayerAnimationControllerClient dummy; | 83 controllerImpl->addObserver(&dummyImpl); |
| 80 scoped_ptr<LayerAnimationController> controller(LayerAnimationController::cr
eate(&dummy)); | 84 FakeLayerAnimationValueObserver dummy; |
| 85 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 86 controller->addObserver(&dummy); |
| 81 | 87 |
| 82 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); | 88 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); |
| 83 | 89 |
| 84 addOpacityTransitionToController(*controller, 1, 0, 1, false); | 90 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
| 85 | 91 |
| 86 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 92 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 87 | 93 |
| 88 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; | 94 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; |
| 89 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); | 95 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); |
| 90 | 96 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 107 controller->resumeAnimations(2); | 113 controller->resumeAnimations(2); |
| 108 EXPECT_EQ(ActiveAnimation::Running, controller->getActiveAnimation(0, Active
Animation::Opacity)->runState()); | 114 EXPECT_EQ(ActiveAnimation::Running, controller->getActiveAnimation(0, Active
Animation::Opacity)->runState()); |
| 109 | 115 |
| 110 // The pause run state change should make it to the impl thread controller. | 116 // The pause run state change should make it to the impl thread controller. |
| 111 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 117 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 112 EXPECT_EQ(ActiveAnimation::Running, controllerImpl->getActiveAnimation(0, Ac
tiveAnimation::Opacity)->runState()); | 118 EXPECT_EQ(ActiveAnimation::Running, controllerImpl->getActiveAnimation(0, Ac
tiveAnimation::Opacity)->runState()); |
| 113 } | 119 } |
| 114 | 120 |
| 115 TEST(LayerAnimationControllerTest, doNotSyncFinishedAnimation) | 121 TEST(LayerAnimationControllerTest, doNotSyncFinishedAnimation) |
| 116 { | 122 { |
| 117 FakeLayerAnimationControllerClient dummyImpl; | 123 FakeLayerAnimationValueObserver dummyImpl; |
| 118 scoped_ptr<LayerAnimationController> controllerImpl(LayerAnimationController
::create(&dummyImpl)); | 124 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
| 119 FakeLayerAnimationControllerClient dummy; | 125 controllerImpl->addObserver(&dummyImpl); |
| 120 scoped_ptr<LayerAnimationController> controller(LayerAnimationController::cr
eate(&dummy)); | 126 FakeLayerAnimationValueObserver dummy; |
| 127 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 128 controller->addObserver(&dummy); |
| 121 | 129 |
| 122 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); | 130 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); |
| 123 | 131 |
| 124 int animationId = addOpacityTransitionToController(*controller, 1, 0, 1, fal
se); | 132 int animationId = addOpacityTransitionToController(*controller, 1, 0, 1, fal
se); |
| 125 | 133 |
| 126 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 134 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 127 | 135 |
| 128 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; | 136 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; |
| 129 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); | 137 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); |
| 130 | 138 |
| 131 // Notify main thread controller that the animation has started. | 139 // Notify main thread controller that the animation has started. |
| 132 AnimationEvent animationStartedEvent(AnimationEvent::Started, 0, 0, ActiveAn
imation::Opacity, 0); | 140 AnimationEvent animationStartedEvent(AnimationEvent::Started, 0, 0, ActiveAn
imation::Opacity, 0); |
| 133 controller->OnAnimationStarted(animationStartedEvent); | 141 controller->OnAnimationStarted(animationStartedEvent); |
| 134 | 142 |
| 135 // Force animation to complete on impl thread. | 143 // Force animation to complete on impl thread. |
| 136 controllerImpl->removeAnimation(animationId); | 144 controllerImpl->removeAnimation(animationId); |
| 137 | 145 |
| 138 EXPECT_FALSE(controllerImpl->getActiveAnimation(animationId, ActiveAnimation
::Opacity)); | 146 EXPECT_FALSE(controllerImpl->getActiveAnimation(animationId, ActiveAnimation
::Opacity)); |
| 139 | 147 |
| 140 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 148 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 141 | 149 |
| 142 // 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. | 150 // 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. |
| 143 EXPECT_FALSE(controllerImpl->getActiveAnimation(animationId, ActiveAnimation
::Opacity)); | 151 EXPECT_FALSE(controllerImpl->getActiveAnimation(animationId, ActiveAnimation
::Opacity)); |
| 144 } | 152 } |
| 145 | 153 |
| 146 // Tests that transitioning opacity from 0 to 1 works as expected. | 154 // Tests that transitioning opacity from 0 to 1 works as expected. |
| 147 TEST(LayerAnimationControllerTest, TrivialTransition) | 155 TEST(LayerAnimationControllerTest, TrivialTransition) |
| 148 { | 156 { |
| 149 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 157 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 150 FakeLayerAnimationControllerClient dummy; | 158 FakeLayerAnimationValueObserver dummy; |
| 151 scoped_ptr<LayerAnimationController> controller( | 159 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 152 LayerAnimationController::create(&dummy)); | 160 controller->addObserver(&dummy); |
| 153 | 161 |
| 154 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); | 162 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); |
| 155 | 163 |
| 156 controller->addAnimation(toAdd.Pass()); | 164 controller->addAnimation(toAdd.Pass()); |
| 157 controller->animate(0, events.get()); | 165 controller->animate(0, events.get()); |
| 158 EXPECT_TRUE(controller->hasActiveAnimation()); | 166 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 159 EXPECT_EQ(0, dummy.opacity()); | 167 EXPECT_EQ(0, dummy.opacity()); |
| 160 controller->animate(1, events.get()); | 168 controller->animate(1, events.get()); |
| 161 EXPECT_EQ(1, dummy.opacity()); | 169 EXPECT_EQ(1, dummy.opacity()); |
| 162 EXPECT_FALSE(controller->hasActiveAnimation()); | 170 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 163 } | 171 } |
| 164 | 172 |
| 165 // Tests animations that are waiting for a synchronized start time do not finish
. | 173 // Tests animations that are waiting for a synchronized start time do not finish
. |
| 166 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe
yWaitLongerToStartThanTheirDuration) | 174 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe
yWaitLongerToStartThanTheirDuration) |
| 167 { | 175 { |
| 168 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 176 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 169 FakeLayerAnimationControllerClient dummy; | 177 FakeLayerAnimationValueObserver dummy; |
| 170 scoped_ptr<LayerAnimationController> controller( | 178 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 171 LayerAnimationController::create(&dummy)); | 179 controller->addObserver(&dummy); |
| 172 | 180 |
| 173 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); | 181 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); |
| 174 toAdd->setNeedsSynchronizedStartTime(true); | 182 toAdd->setNeedsSynchronizedStartTime(true); |
| 175 | 183 |
| 176 // We should pause at the first keyframe indefinitely waiting for that anima
tion to start. | 184 // We should pause at the first keyframe indefinitely waiting for that anima
tion to start. |
| 177 controller->addAnimation(toAdd.Pass()); | 185 controller->addAnimation(toAdd.Pass()); |
| 178 controller->animate(0, events.get()); | 186 controller->animate(0, events.get()); |
| 179 EXPECT_TRUE(controller->hasActiveAnimation()); | 187 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 180 EXPECT_EQ(0, dummy.opacity()); | 188 EXPECT_EQ(0, dummy.opacity()); |
| 181 controller->animate(1, events.get()); | 189 controller->animate(1, events.get()); |
| 182 EXPECT_TRUE(controller->hasActiveAnimation()); | 190 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 183 EXPECT_EQ(0, dummy.opacity()); | 191 EXPECT_EQ(0, dummy.opacity()); |
| 184 controller->animate(2, events.get()); | 192 controller->animate(2, events.get()); |
| 185 EXPECT_TRUE(controller->hasActiveAnimation()); | 193 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 186 EXPECT_EQ(0, dummy.opacity()); | 194 EXPECT_EQ(0, dummy.opacity()); |
| 187 | 195 |
| 188 // Send the synchronized start time. | 196 // Send the synchronized start time. |
| 189 controller->OnAnimationStarted(AnimationEvent(AnimationEvent::Started, 0, 1,
ActiveAnimation::Opacity, 2)); | 197 controller->OnAnimationStarted(AnimationEvent(AnimationEvent::Started, 0, 1,
ActiveAnimation::Opacity, 2)); |
| 190 controller->animate(5, events.get()); | 198 controller->animate(5, events.get()); |
| 191 EXPECT_EQ(1, dummy.opacity()); | 199 EXPECT_EQ(1, dummy.opacity()); |
| 192 EXPECT_FALSE(controller->hasActiveAnimation()); | 200 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 193 } | 201 } |
| 194 | 202 |
| 195 // Tests that two queued animations affecting the same property run in sequence. | 203 // Tests that two queued animations affecting the same property run in sequence. |
| 196 TEST(LayerAnimationControllerTest, TrivialQueuing) | 204 TEST(LayerAnimationControllerTest, TrivialQueuing) |
| 197 { | 205 { |
| 198 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 206 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 199 FakeLayerAnimationControllerClient dummy; | 207 FakeLayerAnimationValueObserver dummy; |
| 200 scoped_ptr<LayerAnimationController> controller( | 208 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 201 LayerAnimationController::create(&dummy)); | 209 controller->addObserver(&dummy); |
| 202 | 210 |
| 203 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); | 211 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); |
| 204 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); | 212 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); |
| 205 | 213 |
| 206 controller->animate(0, events.get()); | 214 controller->animate(0, events.get()); |
| 207 EXPECT_TRUE(controller->hasActiveAnimation()); | 215 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 208 EXPECT_EQ(0, dummy.opacity()); | 216 EXPECT_EQ(0, dummy.opacity()); |
| 209 controller->animate(1, events.get()); | 217 controller->animate(1, events.get()); |
| 210 EXPECT_TRUE(controller->hasActiveAnimation()); | 218 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 211 EXPECT_EQ(1, dummy.opacity()); | 219 EXPECT_EQ(1, dummy.opacity()); |
| 212 controller->animate(2, events.get()); | 220 controller->animate(2, events.get()); |
| 213 EXPECT_EQ(0.5, dummy.opacity()); | 221 EXPECT_EQ(0.5, dummy.opacity()); |
| 214 EXPECT_FALSE(controller->hasActiveAnimation()); | 222 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 215 } | 223 } |
| 216 | 224 |
| 217 // Tests interrupting a transition with another transition. | 225 // Tests interrupting a transition with another transition. |
| 218 TEST(LayerAnimationControllerTest, Interrupt) | 226 TEST(LayerAnimationControllerTest, Interrupt) |
| 219 { | 227 { |
| 220 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 228 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 221 FakeLayerAnimationControllerClient dummy; | 229 FakeLayerAnimationValueObserver dummy; |
| 222 scoped_ptr<LayerAnimationController> controller( | 230 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 223 LayerAnimationController::create(&dummy)); | 231 controller->addObserver(&dummy); |
| 224 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); | 232 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); |
| 225 controller->animate(0, events.get()); | 233 controller->animate(0, events.get()); |
| 226 EXPECT_TRUE(controller->hasActiveAnimation()); | 234 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 227 EXPECT_EQ(0, dummy.opacity()); | 235 EXPECT_EQ(0, dummy.opacity()); |
| 228 | 236 |
| 229 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op
acity)); | 237 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op
acity)); |
| 230 toAdd->setRunState(ActiveAnimation::WaitingForNextTick, 0); | 238 toAdd->setRunState(ActiveAnimation::WaitingForNextTick, 0); |
| 231 controller->addAnimation(toAdd.Pass()); | 239 controller->addAnimation(toAdd.Pass()); |
| 232 | 240 |
| 233 // Since the animation was in the WaitingForNextTick state, it should start
right in | 241 // Since the animation was in the WaitingForNextTick state, it should start
right in |
| 234 // this call to animate. | 242 // this call to animate. |
| 235 controller->animate(0.5, events.get()); | 243 controller->animate(0.5, events.get()); |
| 236 EXPECT_TRUE(controller->hasActiveAnimation()); | 244 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 237 EXPECT_EQ(1, dummy.opacity()); | 245 EXPECT_EQ(1, dummy.opacity()); |
| 238 controller->animate(1.5, events.get()); | 246 controller->animate(1.5, events.get()); |
| 239 EXPECT_EQ(0.5, dummy.opacity()); | 247 EXPECT_EQ(0.5, dummy.opacity()); |
| 240 EXPECT_FALSE(controller->hasActiveAnimation()); | 248 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 241 } | 249 } |
| 242 | 250 |
| 243 // Tests scheduling two animations to run together when only one property is fre
e. | 251 // Tests scheduling two animations to run together when only one property is fre
e. |
| 244 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) | 252 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) |
| 245 { | 253 { |
| 246 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 254 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 247 FakeLayerAnimationControllerClient dummy; | 255 FakeLayerAnimationValueObserver dummy; |
| 248 scoped_ptr<LayerAnimationController> controller( | 256 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 249 LayerAnimationController::create(&dummy)); | 257 controller->addObserver(&dummy); |
| 250 | 258 |
| 251 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Transform)); | 259 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Transform)); |
| 252 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(1)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Transform)); | 260 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(1)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Transform)); |
| 253 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); | 261 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); |
| 254 | 262 |
| 255 controller->animate(0, events.get()); | 263 controller->animate(0, events.get()); |
| 256 EXPECT_EQ(0, dummy.opacity()); | 264 EXPECT_EQ(0, dummy.opacity()); |
| 257 EXPECT_TRUE(controller->hasActiveAnimation()); | 265 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 258 controller->animate(1, events.get()); | 266 controller->animate(1, events.get()); |
| 259 // Should not have started the float transition yet. | 267 // Should not have started the float transition yet. |
| 260 EXPECT_TRUE(controller->hasActiveAnimation()); | 268 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 261 EXPECT_EQ(0, dummy.opacity()); | 269 EXPECT_EQ(0, dummy.opacity()); |
| 262 // The float animation should have started at time 1 and should be done. | 270 // The float animation should have started at time 1 and should be done. |
| 263 controller->animate(2, events.get()); | 271 controller->animate(2, events.get()); |
| 264 EXPECT_EQ(1, dummy.opacity()); | 272 EXPECT_EQ(1, dummy.opacity()); |
| 265 EXPECT_FALSE(controller->hasActiveAnimation()); | 273 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 266 } | 274 } |
| 267 | 275 |
| 268 // Tests scheduling two animations to run together with different lengths and an
other | 276 // Tests scheduling two animations to run together with different lengths and an
other |
| 269 // animation queued to start when the shorter animation finishes (should wait | 277 // animation queued to start when the shorter animation finishes (should wait |
| 270 // for both to finish). | 278 // for both to finish). |
| 271 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) | 279 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) |
| 272 { | 280 { |
| 273 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 281 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 274 FakeLayerAnimationControllerClient dummy; | 282 FakeLayerAnimationValueObserver dummy; |
| 275 scoped_ptr<LayerAnimationController> controller( | 283 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 276 LayerAnimationController::create(&dummy)); | 284 controller->addObserver(&dummy); |
| 277 | 285 |
| 278 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(2)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Transform)); | 286 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(2)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Transform)); |
| 279 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); | 287 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); |
| 280 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); | 288 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); |
| 281 | 289 |
| 282 // Animations with id 1 should both start now. | 290 // Animations with id 1 should both start now. |
| 283 controller->animate(0, events.get()); | 291 controller->animate(0, events.get()); |
| 284 EXPECT_TRUE(controller->hasActiveAnimation()); | 292 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 285 EXPECT_EQ(0, dummy.opacity()); | 293 EXPECT_EQ(0, dummy.opacity()); |
| 286 // The opacity animation should have finished at time 1, but the group | 294 // The opacity animation should have finished at time 1, but the group |
| 287 // of animations with id 1 don't finish until time 2 because of the length | 295 // of animations with id 1 don't finish until time 2 because of the length |
| 288 // of the transform animation. | 296 // of the transform animation. |
| 289 controller->animate(2, events.get()); | 297 controller->animate(2, events.get()); |
| 290 // Should not have started the float transition yet. | 298 // Should not have started the float transition yet. |
| 291 EXPECT_TRUE(controller->hasActiveAnimation()); | 299 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 292 EXPECT_EQ(1, dummy.opacity()); | 300 EXPECT_EQ(1, dummy.opacity()); |
| 293 | 301 |
| 294 // The second opacity animation should start at time 2 and should be done by
time 3 | 302 // The second opacity animation should start at time 2 and should be done by
time 3 |
| 295 controller->animate(3, events.get()); | 303 controller->animate(3, events.get()); |
| 296 EXPECT_EQ(0.5, dummy.opacity()); | 304 EXPECT_EQ(0.5, dummy.opacity()); |
| 297 EXPECT_FALSE(controller->hasActiveAnimation()); | 305 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 298 } | 306 } |
| 299 | 307 |
| 300 // Tests scheduling an animation to start in the future. | 308 // Tests scheduling an animation to start in the future. |
| 301 TEST(LayerAnimationControllerTest, ScheduleAnimation) | 309 TEST(LayerAnimationControllerTest, ScheduleAnimation) |
| 302 { | 310 { |
| 303 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 311 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 304 FakeLayerAnimationControllerClient dummy; | 312 FakeLayerAnimationValueObserver dummy; |
| 305 scoped_ptr<LayerAnimationController> controller( | 313 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 306 LayerAnimationController::create(&dummy)); | 314 controller->addObserver(&dummy); |
| 307 | 315 |
| 308 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); | 316 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); |
| 309 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0); | 317 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0); |
| 310 toAdd->setStartTime(1); | 318 toAdd->setStartTime(1); |
| 311 controller->addAnimation(toAdd.Pass()); | 319 controller->addAnimation(toAdd.Pass()); |
| 312 | 320 |
| 313 controller->animate(0, events.get()); | 321 controller->animate(0, events.get()); |
| 314 EXPECT_TRUE(controller->hasActiveAnimation()); | 322 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 315 EXPECT_EQ(0, dummy.opacity()); | 323 EXPECT_EQ(0, dummy.opacity()); |
| 316 controller->animate(1, events.get()); | 324 controller->animate(1, events.get()); |
| 317 EXPECT_TRUE(controller->hasActiveAnimation()); | 325 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 318 EXPECT_EQ(0, dummy.opacity()); | 326 EXPECT_EQ(0, dummy.opacity()); |
| 319 controller->animate(2, events.get()); | 327 controller->animate(2, events.get()); |
| 320 EXPECT_EQ(1, dummy.opacity()); | 328 EXPECT_EQ(1, dummy.opacity()); |
| 321 EXPECT_FALSE(controller->hasActiveAnimation()); | 329 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 322 } | 330 } |
| 323 | 331 |
| 324 // Tests scheduling an animation to start in the future that's interrupting a ru
nning animation. | 332 // Tests scheduling an animation to start in the future that's interrupting a ru
nning animation. |
| 325 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimation) | 333 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimation) |
| 326 { | 334 { |
| 327 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 335 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 328 FakeLayerAnimationControllerClient dummy; | 336 FakeLayerAnimationValueObserver dummy; |
| 329 scoped_ptr<LayerAnimationController> controller( | 337 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 330 LayerAnimationController::create(&dummy)); | 338 controller->addObserver(&dummy); |
| 331 | 339 |
| 332 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(2, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); | 340 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(2, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); |
| 333 | 341 |
| 334 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0.5, 0)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op
acity)); | 342 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0.5, 0)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op
acity)); |
| 335 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0); | 343 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0); |
| 336 toAdd->setStartTime(1); | 344 toAdd->setStartTime(1); |
| 337 controller->addAnimation(toAdd.Pass()); | 345 controller->addAnimation(toAdd.Pass()); |
| 338 | 346 |
| 339 // First 2s opacity transition should start immediately. | 347 // First 2s opacity transition should start immediately. |
| 340 controller->animate(0, events.get()); | 348 controller->animate(0, events.get()); |
| 341 EXPECT_TRUE(controller->hasActiveAnimation()); | 349 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 342 EXPECT_EQ(0, dummy.opacity()); | 350 EXPECT_EQ(0, dummy.opacity()); |
| 343 controller->animate(0.5, events.get()); | 351 controller->animate(0.5, events.get()); |
| 344 EXPECT_TRUE(controller->hasActiveAnimation()); | 352 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 345 EXPECT_EQ(0.25, dummy.opacity()); | 353 EXPECT_EQ(0.25, dummy.opacity()); |
| 346 controller->animate(1, events.get()); | 354 controller->animate(1, events.get()); |
| 347 EXPECT_TRUE(controller->hasActiveAnimation()); | 355 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 348 EXPECT_EQ(0.5, dummy.opacity()); | 356 EXPECT_EQ(0.5, dummy.opacity()); |
| 349 controller->animate(2, events.get()); | 357 controller->animate(2, events.get()); |
| 350 EXPECT_EQ(0, dummy.opacity()); | 358 EXPECT_EQ(0, dummy.opacity()); |
| 351 EXPECT_FALSE(controller->hasActiveAnimation()); | 359 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 352 } | 360 } |
| 353 | 361 |
| 354 // Tests scheduling an animation to start in the future that interrupts a runnin
g animation | 362 // Tests scheduling an animation to start in the future that interrupts a runnin
g animation |
| 355 // and there is yet another animation queued to start later. | 363 // and there is yet another animation queued to start later. |
| 356 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimationW
ithAnimInQueue) | 364 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimationW
ithAnimInQueue) |
| 357 { | 365 { |
| 358 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 366 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 359 FakeLayerAnimationControllerClient dummy; | 367 FakeLayerAnimationValueObserver dummy; |
| 360 scoped_ptr<LayerAnimationController> controller( | 368 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 361 LayerAnimationController::create(&dummy)); | 369 controller->addObserver(&dummy); |
| 362 | 370 |
| 363 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(2, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); | 371 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(2, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); |
| 364 | 372 |
| 365 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(2, 0.5, 0)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op
acity)); | 373 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(2, 0.5, 0)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op
acity)); |
| 366 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0); | 374 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0); |
| 367 toAdd->setStartTime(1); | 375 toAdd->setStartTime(1); |
| 368 controller->addAnimation(toAdd.Pass()); | 376 controller->addAnimation(toAdd.Pass()); |
| 369 | 377 |
| 370 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 0.75)).PassAs<AnimationCurve>(), 3, ActiveAnimation::Opacity)); | 378 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 0.75)).PassAs<AnimationCurve>(), 3, ActiveAnimation::Opacity)); |
| 371 | 379 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 385 EXPECT_EQ(0, dummy.opacity()); | 393 EXPECT_EQ(0, dummy.opacity()); |
| 386 controller->animate(4, events.get()); | 394 controller->animate(4, events.get()); |
| 387 EXPECT_EQ(0.75, dummy.opacity()); | 395 EXPECT_EQ(0.75, dummy.opacity()); |
| 388 EXPECT_FALSE(controller->hasActiveAnimation()); | 396 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 389 } | 397 } |
| 390 | 398 |
| 391 // Test that a looping animation loops and for the correct number of iterations. | 399 // Test that a looping animation loops and for the correct number of iterations. |
| 392 TEST(LayerAnimationControllerTest, TrivialLooping) | 400 TEST(LayerAnimationControllerTest, TrivialLooping) |
| 393 { | 401 { |
| 394 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 402 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 395 FakeLayerAnimationControllerClient dummy; | 403 FakeLayerAnimationValueObserver dummy; |
| 396 scoped_ptr<LayerAnimationController> controller( | 404 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 397 LayerAnimationController::create(&dummy)); | 405 controller->addObserver(&dummy); |
| 398 | 406 |
| 399 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); | 407 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); |
| 400 toAdd->setIterations(3); | 408 toAdd->setIterations(3); |
| 401 controller->addAnimation(toAdd.Pass()); | 409 controller->addAnimation(toAdd.Pass()); |
| 402 | 410 |
| 403 controller->animate(0, events.get()); | 411 controller->animate(0, events.get()); |
| 404 EXPECT_TRUE(controller->hasActiveAnimation()); | 412 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 405 EXPECT_EQ(0, dummy.opacity()); | 413 EXPECT_EQ(0, dummy.opacity()); |
| 406 controller->animate(1.25, events.get()); | 414 controller->animate(1.25, events.get()); |
| 407 EXPECT_TRUE(controller->hasActiveAnimation()); | 415 EXPECT_TRUE(controller->hasActiveAnimation()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 421 | 429 |
| 422 // Just be extra sure. | 430 // Just be extra sure. |
| 423 controller->animate(4, events.get()); | 431 controller->animate(4, events.get()); |
| 424 EXPECT_EQ(1, dummy.opacity()); | 432 EXPECT_EQ(1, dummy.opacity()); |
| 425 } | 433 } |
| 426 | 434 |
| 427 // Test that an infinitely looping animation does indeed go until aborted. | 435 // Test that an infinitely looping animation does indeed go until aborted. |
| 428 TEST(LayerAnimationControllerTest, InfiniteLooping) | 436 TEST(LayerAnimationControllerTest, InfiniteLooping) |
| 429 { | 437 { |
| 430 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 438 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 431 FakeLayerAnimationControllerClient dummy; | 439 FakeLayerAnimationValueObserver dummy; |
| 432 scoped_ptr<LayerAnimationController> controller( | 440 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 433 LayerAnimationController::create(&dummy)); | 441 controller->addObserver(&dummy); |
| 434 | 442 |
| 435 const int id = 1; | 443 const int id = 1; |
| 436 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opa
city)); | 444 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opa
city)); |
| 437 toAdd->setIterations(-1); | 445 toAdd->setIterations(-1); |
| 438 controller->addAnimation(toAdd.Pass()); | 446 controller->addAnimation(toAdd.Pass()); |
| 439 | 447 |
| 440 controller->animate(0, events.get()); | 448 controller->animate(0, events.get()); |
| 441 EXPECT_TRUE(controller->hasActiveAnimation()); | 449 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 442 EXPECT_EQ(0, dummy.opacity()); | 450 EXPECT_EQ(0, dummy.opacity()); |
| 443 controller->animate(1.25, events.get()); | 451 controller->animate(1.25, events.get()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 457 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); | 465 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); |
| 458 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac
tiveAnimation::Aborted, 0.75); | 466 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac
tiveAnimation::Aborted, 0.75); |
| 459 EXPECT_FALSE(controller->hasActiveAnimation()); | 467 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 460 EXPECT_EQ(0.75, dummy.opacity()); | 468 EXPECT_EQ(0.75, dummy.opacity()); |
| 461 } | 469 } |
| 462 | 470 |
| 463 // Test that pausing and resuming work as expected. | 471 // Test that pausing and resuming work as expected. |
| 464 TEST(LayerAnimationControllerTest, PauseResume) | 472 TEST(LayerAnimationControllerTest, PauseResume) |
| 465 { | 473 { |
| 466 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 474 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 467 FakeLayerAnimationControllerClient dummy; | 475 FakeLayerAnimationValueObserver dummy; |
| 468 scoped_ptr<LayerAnimationController> controller( | 476 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 469 LayerAnimationController::create(&dummy)); | 477 controller->addObserver(&dummy); |
| 470 | 478 |
| 471 const int id = 1; | 479 const int id = 1; |
| 472 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opacity)); | 480 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opacity)); |
| 473 | 481 |
| 474 controller->animate(0, events.get()); | 482 controller->animate(0, events.get()); |
| 475 EXPECT_TRUE(controller->hasActiveAnimation()); | 483 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 476 EXPECT_EQ(0, dummy.opacity()); | 484 EXPECT_EQ(0, dummy.opacity()); |
| 477 controller->animate(0.5, events.get()); | 485 controller->animate(0.5, events.get()); |
| 478 EXPECT_TRUE(controller->hasActiveAnimation()); | 486 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 479 EXPECT_EQ(0.5, dummy.opacity()); | 487 EXPECT_EQ(0.5, dummy.opacity()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 492 EXPECT_TRUE(controller->hasActiveAnimation()); | 500 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 493 EXPECT_EQ(0.75, dummy.opacity()); | 501 EXPECT_EQ(0.75, dummy.opacity()); |
| 494 controller->animate(1024.5, events.get()); | 502 controller->animate(1024.5, events.get()); |
| 495 EXPECT_FALSE(controller->hasActiveAnimation()); | 503 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 496 EXPECT_EQ(1, dummy.opacity()); | 504 EXPECT_EQ(1, dummy.opacity()); |
| 497 } | 505 } |
| 498 | 506 |
| 499 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) | 507 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) |
| 500 { | 508 { |
| 501 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 509 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 502 FakeLayerAnimationControllerClient dummy; | 510 FakeLayerAnimationValueObserver dummy; |
| 503 scoped_ptr<LayerAnimationController> controller( | 511 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 504 LayerAnimationController::create(&dummy)); | 512 controller->addObserver(&dummy); |
| 505 | 513 |
| 506 const int id = 1; | 514 const int id = 1; |
| 507 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Transform)); | 515 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Transform)); |
| 508 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(2, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opacity)); | 516 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(2, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opacity)); |
| 509 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 1, 0.75)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); | 517 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 1, 0.75)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); |
| 510 | 518 |
| 511 controller->animate(0, events.get()); | 519 controller->animate(0, events.get()); |
| 512 EXPECT_TRUE(controller->hasActiveAnimation()); | 520 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 513 EXPECT_EQ(0, dummy.opacity()); | 521 EXPECT_EQ(0, dummy.opacity()); |
| 514 controller->animate(1, events.get()); | 522 controller->animate(1, events.get()); |
| 515 EXPECT_TRUE(controller->hasActiveAnimation()); | 523 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 516 EXPECT_EQ(0.5, dummy.opacity()); | 524 EXPECT_EQ(0.5, dummy.opacity()); |
| 517 | 525 |
| 518 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); | 526 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); |
| 519 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac
tiveAnimation::Aborted, 1); | 527 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac
tiveAnimation::Aborted, 1); |
| 520 controller->animate(1, events.get()); | 528 controller->animate(1, events.get()); |
| 521 EXPECT_TRUE(controller->hasActiveAnimation()); | 529 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 522 EXPECT_EQ(1, dummy.opacity()); | 530 EXPECT_EQ(1, dummy.opacity()); |
| 523 controller->animate(2, events.get()); | 531 controller->animate(2, events.get()); |
| 524 EXPECT_TRUE(!controller->hasActiveAnimation()); | 532 EXPECT_TRUE(!controller->hasActiveAnimation()); |
| 525 EXPECT_EQ(0.75, dummy.opacity()); | 533 EXPECT_EQ(0.75, dummy.opacity()); |
| 526 } | 534 } |
| 527 | 535 |
| 528 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) | 536 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) |
| 529 { | 537 { |
| 530 FakeLayerAnimationControllerClient dummyImpl; | 538 FakeLayerAnimationValueObserver dummyImpl; |
| 531 scoped_ptr<LayerAnimationController> controllerImpl(LayerAnimationController
::create(&dummyImpl)); | 539 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
| 540 controllerImpl->addObserver(&dummyImpl); |
| 532 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 541 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 533 FakeLayerAnimationControllerClient dummy; | 542 FakeLayerAnimationValueObserver dummy; |
| 534 scoped_ptr<LayerAnimationController> controller( | 543 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 535 LayerAnimationController::create(&dummy)); | 544 controller->addObserver(&dummy); |
| 536 | 545 |
| 537 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(2, 0, 1)).PassAs<AnimationCurve>(), 0, ActiveAnimation::Opac
ity)); | 546 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(2, 0, 1)).PassAs<AnimationCurve>(), 0, ActiveAnimation::Opac
ity)); |
| 538 toAdd->setNeedsSynchronizedStartTime(true); | 547 toAdd->setNeedsSynchronizedStartTime(true); |
| 539 controller->addAnimation(toAdd.Pass()); | 548 controller->addAnimation(toAdd.Pass()); |
| 540 | 549 |
| 541 controller->animate(0, 0); | 550 controller->animate(0, 0); |
| 542 EXPECT_TRUE(controller->hasActiveAnimation()); | 551 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 543 ActiveAnimation* activeAnimation = controller->getActiveAnimation(0, ActiveA
nimation::Opacity); | 552 ActiveAnimation* activeAnimation = controller->getActiveAnimation(0, ActiveA
nimation::Opacity); |
| 544 EXPECT_TRUE(activeAnimation); | 553 EXPECT_TRUE(activeAnimation); |
| 545 EXPECT_TRUE(activeAnimation->needsSynchronizedStartTime()); | 554 EXPECT_TRUE(activeAnimation->needsSynchronizedStartTime()); |
| 546 | 555 |
| 547 controller->setForceSync(); | 556 controller->setForceSync(); |
| 548 | 557 |
| 549 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 558 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 550 | 559 |
| 551 activeAnimation = controllerImpl->getActiveAnimation(0, ActiveAnimation::Opa
city); | 560 activeAnimation = controllerImpl->getActiveAnimation(0, ActiveAnimation::Opa
city); |
| 552 EXPECT_TRUE(activeAnimation); | 561 EXPECT_TRUE(activeAnimation); |
| 553 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, activeAnimation->ru
nState()); | 562 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, activeAnimation->ru
nState()); |
| 554 } | 563 } |
| 555 | 564 |
| 556 } // namespace | 565 } // namespace |
| 557 } // namespace cc | 566 } // namespace cc |
| OLD | NEW |