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