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