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