Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: cc/layer_animation_controller_unittest.cc

Issue 11348256: Use an auxiliary list of animation controllers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_animation_controller.cc ('k') | cc/layer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
236 controller->setOpacity(0);
253 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans formTransition(1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Transform)); 237 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)); 238 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)); 239 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 1)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity));
256 240
257 controller->animate(0, events.get()); 241 controller->animate(0, events.get());
258 EXPECT_EQ(0, dummy.opacity()); 242 EXPECT_EQ(0, controller->opacity());
259 EXPECT_TRUE(controller->hasActiveAnimation()); 243 EXPECT_TRUE(controller->hasActiveAnimation());
260 controller->animate(1, events.get()); 244 controller->animate(1, events.get());
261 // Should not have started the float transition yet. 245 // Should not have started the float transition yet.
262 EXPECT_TRUE(controller->hasActiveAnimation()); 246 EXPECT_TRUE(controller->hasActiveAnimation());
263 EXPECT_EQ(0, dummy.opacity()); 247 EXPECT_EQ(0, controller->opacity());
264 // The float animation should have started at time 1 and should be done. 248 // The float animation should have started at time 1 and should be done.
265 controller->animate(2, events.get()); 249 controller->animate(2, events.get());
266 EXPECT_EQ(1, dummy.opacity()); 250 EXPECT_EQ(1, controller->opacity());
267 EXPECT_FALSE(controller->hasActiveAnimation()); 251 EXPECT_FALSE(controller->hasActiveAnimation());
268 } 252 }
269 253
270 // Tests scheduling two animations to run together with different lengths and an other 254 // 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 255 // animation queued to start when the shorter animation finishes (should wait
272 // for both to finish). 256 // for both to finish).
273 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) 257 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting)
274 { 258 {
275 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 259 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
276 FakeLayerAnimationControllerClient dummy; 260 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create());
277 scoped_ptr<LayerAnimationController> controller(
278 LayerAnimationController::create(&dummy));
279 261
280 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans formTransition(2)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Transform)); 262 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)); 263 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)); 264 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity));
283 265
284 // Animations with id 1 should both start now. 266 // Animations with id 1 should both start now.
285 controller->animate(0, events.get()); 267 controller->animate(0, events.get());
286 EXPECT_TRUE(controller->hasActiveAnimation()); 268 EXPECT_TRUE(controller->hasActiveAnimation());
287 EXPECT_EQ(0, dummy.opacity()); 269 EXPECT_EQ(0, controller->opacity());
288 // The opacity animation should have finished at time 1, but the group 270 // 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 271 // of animations with id 1 don't finish until time 2 because of the length
290 // of the transform animation. 272 // of the transform animation.
291 controller->animate(2, events.get()); 273 controller->animate(2, events.get());
292 // Should not have started the float transition yet. 274 // Should not have started the float transition yet.
293 EXPECT_TRUE(controller->hasActiveAnimation()); 275 EXPECT_TRUE(controller->hasActiveAnimation());
294 EXPECT_EQ(1, dummy.opacity()); 276 EXPECT_EQ(1, controller->opacity());
295 277
296 // The second opacity animation should start at time 2 and should be done by time 3 278 // The second opacity animation should start at time 2 and should be done by time 3
297 controller->animate(3, events.get()); 279 controller->animate(3, events.get());
298 EXPECT_EQ(0.5, dummy.opacity()); 280 EXPECT_EQ(0.5, controller->opacity());
299 EXPECT_FALSE(controller->hasActiveAnimation()); 281 EXPECT_FALSE(controller->hasActiveAnimation());
300 } 282 }
301 283
302 // Tests scheduling an animation to start in the future. 284 // Tests scheduling an animation to start in the future.
303 TEST(LayerAnimationControllerTest, ScheduleAnimation) 285 TEST(LayerAnimationControllerTest, ScheduleAnimation)
304 { 286 {
305 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 287 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
306 FakeLayerAnimationControllerClient dummy; 288 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create());
307 scoped_ptr<LayerAnimationController> controller(
308 LayerAnimationController::create(&dummy));
309 289
290 controller->setOpacity(0);
310 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac ity)); 291 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); 292 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0);
312 toAdd->setStartTime(1); 293 toAdd->setStartTime(1);
313 controller->addAnimation(toAdd.Pass()); 294 controller->addAnimation(toAdd.Pass());
314 295
315 controller->animate(0, events.get()); 296 controller->animate(0, events.get());
316 EXPECT_TRUE(controller->hasActiveAnimation()); 297 EXPECT_TRUE(controller->hasActiveAnimation());
317 EXPECT_EQ(0, dummy.opacity()); 298 EXPECT_EQ(0, controller->opacity());
318 controller->animate(1, events.get()); 299 controller->animate(1, events.get());
319 EXPECT_TRUE(controller->hasActiveAnimation()); 300 EXPECT_TRUE(controller->hasActiveAnimation());
320 EXPECT_EQ(0, dummy.opacity()); 301 EXPECT_EQ(0, controller->opacity());
321 controller->animate(2, events.get()); 302 controller->animate(2, events.get());
322 EXPECT_EQ(1, dummy.opacity()); 303 EXPECT_EQ(1, controller->opacity());
323 EXPECT_FALSE(controller->hasActiveAnimation()); 304 EXPECT_FALSE(controller->hasActiveAnimation());
324 } 305 }
325 306
326 // Tests scheduling an animation to start in the future that's interrupting a ru nning animation. 307 // Tests scheduling an animation to start in the future that's interrupting a ru nning animation.
327 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimation) 308 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimation)
328 { 309 {
329 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 310 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
330 FakeLayerAnimationControllerClient dummy; 311 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create());
331 scoped_ptr<LayerAnimationController> controller(
332 LayerAnimationController::create(&dummy));
333 312
334 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(2, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); 313 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(2, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity));
335 314
336 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new FakeFloatTransition(1, 0.5, 0)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op acity)); 315 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); 316 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0);
338 toAdd->setStartTime(1); 317 toAdd->setStartTime(1);
339 controller->addAnimation(toAdd.Pass()); 318 controller->addAnimation(toAdd.Pass());
340 319
341 // First 2s opacity transition should start immediately. 320 // First 2s opacity transition should start immediately.
342 controller->animate(0, events.get()); 321 controller->animate(0, events.get());
343 EXPECT_TRUE(controller->hasActiveAnimation()); 322 EXPECT_TRUE(controller->hasActiveAnimation());
344 EXPECT_EQ(0, dummy.opacity()); 323 EXPECT_EQ(0, controller->opacity());
345 controller->animate(0.5, events.get()); 324 controller->animate(0.5, events.get());
346 EXPECT_TRUE(controller->hasActiveAnimation()); 325 EXPECT_TRUE(controller->hasActiveAnimation());
347 EXPECT_EQ(0.25, dummy.opacity()); 326 EXPECT_EQ(0.25, controller->opacity());
348 controller->animate(1, events.get()); 327 controller->animate(1, events.get());
349 EXPECT_TRUE(controller->hasActiveAnimation()); 328 EXPECT_TRUE(controller->hasActiveAnimation());
350 EXPECT_EQ(0.5, dummy.opacity()); 329 EXPECT_EQ(0.5, controller->opacity());
351 controller->animate(2, events.get()); 330 controller->animate(2, events.get());
352 EXPECT_EQ(0, dummy.opacity()); 331 EXPECT_EQ(0, controller->opacity());
353 EXPECT_FALSE(controller->hasActiveAnimation()); 332 EXPECT_FALSE(controller->hasActiveAnimation());
354 } 333 }
355 334
356 // Tests scheduling an animation to start in the future that interrupts a runnin g animation 335 // 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. 336 // and there is yet another animation queued to start later.
358 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimationW ithAnimInQueue) 337 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimationW ithAnimInQueue)
359 { 338 {
360 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 339 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
361 FakeLayerAnimationControllerClient dummy; 340 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create());
362 scoped_ptr<LayerAnimationController> controller(
363 LayerAnimationController::create(&dummy));
364 341
365 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(2, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); 342 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(2, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity));
366 343
367 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new FakeFloatTransition(2, 0.5, 0)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op acity)); 344 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); 345 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0);
369 toAdd->setStartTime(1); 346 toAdd->setStartTime(1);
370 controller->addAnimation(toAdd.Pass()); 347 controller->addAnimation(toAdd.Pass());
371 348
372 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 0.75)).PassAs<AnimationCurve>(), 3, ActiveAnimation::Opacity)); 349 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 0.75)).PassAs<AnimationCurve>(), 3, ActiveAnimation::Opacity));
373 350
374 // First 2s opacity transition should start immediately. 351 // First 2s opacity transition should start immediately.
375 controller->animate(0, events.get()); 352 controller->animate(0, events.get());
376 EXPECT_TRUE(controller->hasActiveAnimation()); 353 EXPECT_TRUE(controller->hasActiveAnimation());
377 EXPECT_EQ(0, dummy.opacity()); 354 EXPECT_EQ(0, controller->opacity());
378 controller->animate(0.5, events.get()); 355 controller->animate(0.5, events.get());
379 EXPECT_TRUE(controller->hasActiveAnimation()); 356 EXPECT_TRUE(controller->hasActiveAnimation());
380 EXPECT_EQ(0.25, dummy.opacity()); 357 EXPECT_EQ(0.25, controller->opacity());
381 EXPECT_TRUE(controller->hasActiveAnimation()); 358 EXPECT_TRUE(controller->hasActiveAnimation());
382 controller->animate(1, events.get()); 359 controller->animate(1, events.get());
383 EXPECT_TRUE(controller->hasActiveAnimation()); 360 EXPECT_TRUE(controller->hasActiveAnimation());
384 EXPECT_EQ(0.5, dummy.opacity()); 361 EXPECT_EQ(0.5, controller->opacity());
385 controller->animate(3, events.get()); 362 controller->animate(3, events.get());
386 EXPECT_TRUE(controller->hasActiveAnimation()); 363 EXPECT_TRUE(controller->hasActiveAnimation());
387 EXPECT_EQ(0, dummy.opacity()); 364 EXPECT_EQ(0, controller->opacity());
388 controller->animate(4, events.get()); 365 controller->animate(4, events.get());
389 EXPECT_EQ(0.75, dummy.opacity()); 366 EXPECT_EQ(0.75, controller->opacity());
390 EXPECT_FALSE(controller->hasActiveAnimation()); 367 EXPECT_FALSE(controller->hasActiveAnimation());
391 } 368 }
392 369
393 // Test that a looping animation loops and for the correct number of iterations. 370 // Test that a looping animation loops and for the correct number of iterations.
394 TEST(LayerAnimationControllerTest, TrivialLooping) 371 TEST(LayerAnimationControllerTest, TrivialLooping)
395 { 372 {
396 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 373 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
397 FakeLayerAnimationControllerClient dummy; 374 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create());
398 scoped_ptr<LayerAnimationController> controller(
399 LayerAnimationController::create(&dummy));
400 375
401 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac ity)); 376 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac ity));
402 toAdd->setIterations(3); 377 toAdd->setIterations(3);
403 controller->addAnimation(toAdd.Pass()); 378 controller->addAnimation(toAdd.Pass());
404 379
405 controller->animate(0, events.get()); 380 controller->animate(0, events.get());
406 EXPECT_TRUE(controller->hasActiveAnimation()); 381 EXPECT_TRUE(controller->hasActiveAnimation());
407 EXPECT_EQ(0, dummy.opacity()); 382 EXPECT_EQ(0, controller->opacity());
408 controller->animate(1.25, events.get()); 383 controller->animate(1.25, events.get());
409 EXPECT_TRUE(controller->hasActiveAnimation()); 384 EXPECT_TRUE(controller->hasActiveAnimation());
410 EXPECT_EQ(0.25, dummy.opacity()); 385 EXPECT_EQ(0.25, controller->opacity());
411 controller->animate(1.75, events.get()); 386 controller->animate(1.75, events.get());
412 EXPECT_TRUE(controller->hasActiveAnimation()); 387 EXPECT_TRUE(controller->hasActiveAnimation());
413 EXPECT_EQ(0.75, dummy.opacity()); 388 EXPECT_EQ(0.75, controller->opacity());
414 controller->animate(2.25, events.get()); 389 controller->animate(2.25, events.get());
415 EXPECT_TRUE(controller->hasActiveAnimation()); 390 EXPECT_TRUE(controller->hasActiveAnimation());
416 EXPECT_EQ(0.25, dummy.opacity()); 391 EXPECT_EQ(0.25, controller->opacity());
417 controller->animate(2.75, events.get()); 392 controller->animate(2.75, events.get());
418 EXPECT_TRUE(controller->hasActiveAnimation()); 393 EXPECT_TRUE(controller->hasActiveAnimation());
419 EXPECT_EQ(0.75, dummy.opacity()); 394 EXPECT_EQ(0.75, controller->opacity());
420 controller->animate(3, events.get()); 395 controller->animate(3, events.get());
421 EXPECT_FALSE(controller->hasActiveAnimation()); 396 EXPECT_FALSE(controller->hasActiveAnimation());
422 EXPECT_EQ(1, dummy.opacity()); 397 EXPECT_EQ(1, controller->opacity());
423 398
424 // Just be extra sure. 399 // Just be extra sure.
425 controller->animate(4, events.get()); 400 controller->animate(4, events.get());
426 EXPECT_EQ(1, dummy.opacity()); 401 EXPECT_EQ(1, controller->opacity());
427 } 402 }
428 403
429 // Test that an infinitely looping animation does indeed go until aborted. 404 // Test that an infinitely looping animation does indeed go until aborted.
430 TEST(LayerAnimationControllerTest, InfiniteLooping) 405 TEST(LayerAnimationControllerTest, InfiniteLooping)
431 { 406 {
432 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 407 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
433 FakeLayerAnimationControllerClient dummy; 408 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create());
434 scoped_ptr<LayerAnimationController> controller(
435 LayerAnimationController::create(&dummy));
436 409
437 const int id = 1; 410 const int id = 1;
438 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opa city)); 411 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opa city));
439 toAdd->setIterations(-1); 412 toAdd->setIterations(-1);
440 controller->addAnimation(toAdd.Pass()); 413 controller->addAnimation(toAdd.Pass());
441 414
442 controller->animate(0, events.get()); 415 controller->animate(0, events.get());
443 EXPECT_TRUE(controller->hasActiveAnimation()); 416 EXPECT_TRUE(controller->hasActiveAnimation());
444 EXPECT_EQ(0, dummy.opacity()); 417 EXPECT_EQ(0, controller->opacity());
445 controller->animate(1.25, events.get()); 418 controller->animate(1.25, events.get());
446 EXPECT_TRUE(controller->hasActiveAnimation()); 419 EXPECT_TRUE(controller->hasActiveAnimation());
447 EXPECT_EQ(0.25, dummy.opacity()); 420 EXPECT_EQ(0.25, controller->opacity());
448 controller->animate(1.75, events.get()); 421 controller->animate(1.75, events.get());
449 EXPECT_TRUE(controller->hasActiveAnimation()); 422 EXPECT_TRUE(controller->hasActiveAnimation());
450 EXPECT_EQ(0.75, dummy.opacity()); 423 EXPECT_EQ(0.75, controller->opacity());
451 424
452 controller->animate(1073741824.25, events.get()); 425 controller->animate(1073741824.25, events.get());
453 EXPECT_TRUE(controller->hasActiveAnimation()); 426 EXPECT_TRUE(controller->hasActiveAnimation());
454 EXPECT_EQ(0.25, dummy.opacity()); 427 EXPECT_EQ(0.25, controller->opacity());
455 controller->animate(1073741824.75, events.get()); 428 controller->animate(1073741824.75, events.get());
456 EXPECT_TRUE(controller->hasActiveAnimation()); 429 EXPECT_TRUE(controller->hasActiveAnimation());
457 EXPECT_EQ(0.75, dummy.opacity()); 430 EXPECT_EQ(0.75, controller->opacity());
458 431
459 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); 432 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity));
460 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac tiveAnimation::Aborted, 0.75); 433 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac tiveAnimation::Aborted, 0.75);
461 EXPECT_FALSE(controller->hasActiveAnimation()); 434 EXPECT_FALSE(controller->hasActiveAnimation());
462 EXPECT_EQ(0.75, dummy.opacity()); 435 EXPECT_EQ(0.75, controller->opacity());
463 } 436 }
464 437
465 // Test that pausing and resuming work as expected. 438 // Test that pausing and resuming work as expected.
466 TEST(LayerAnimationControllerTest, PauseResume) 439 TEST(LayerAnimationControllerTest, PauseResume)
467 { 440 {
468 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 441 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
469 FakeLayerAnimationControllerClient dummy; 442 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create());
470 scoped_ptr<LayerAnimationController> controller(
471 LayerAnimationController::create(&dummy));
472 443
473 const int id = 1; 444 const int id = 1;
474 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opacity)); 445 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opacity));
475 446
476 controller->animate(0, events.get()); 447 controller->animate(0, events.get());
477 EXPECT_TRUE(controller->hasActiveAnimation()); 448 EXPECT_TRUE(controller->hasActiveAnimation());
478 EXPECT_EQ(0, dummy.opacity()); 449 EXPECT_EQ(0, controller->opacity());
479 controller->animate(0.5, events.get()); 450 controller->animate(0.5, events.get());
480 EXPECT_TRUE(controller->hasActiveAnimation()); 451 EXPECT_TRUE(controller->hasActiveAnimation());
481 EXPECT_EQ(0.5, dummy.opacity()); 452 EXPECT_EQ(0.5, controller->opacity());
482 453
483 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); 454 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity));
484 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac tiveAnimation::Paused, 0.5); 455 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac tiveAnimation::Paused, 0.5);
485 456
486 controller->animate(1024, events.get()); 457 controller->animate(1024, events.get());
487 EXPECT_TRUE(controller->hasActiveAnimation()); 458 EXPECT_TRUE(controller->hasActiveAnimation());
488 EXPECT_EQ(0.5, dummy.opacity()); 459 EXPECT_EQ(0.5, controller->opacity());
489 460
490 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); 461 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity));
491 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac tiveAnimation::Running, 1024); 462 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac tiveAnimation::Running, 1024);
492 463
493 controller->animate(1024.25, events.get()); 464 controller->animate(1024.25, events.get());
494 EXPECT_TRUE(controller->hasActiveAnimation()); 465 EXPECT_TRUE(controller->hasActiveAnimation());
495 EXPECT_EQ(0.75, dummy.opacity()); 466 EXPECT_EQ(0.75, controller->opacity());
496 controller->animate(1024.5, events.get()); 467 controller->animate(1024.5, events.get());
497 EXPECT_FALSE(controller->hasActiveAnimation()); 468 EXPECT_FALSE(controller->hasActiveAnimation());
498 EXPECT_EQ(1, dummy.opacity()); 469 EXPECT_EQ(1, controller->opacity());
499 } 470 }
500 471
501 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) 472 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation)
502 { 473 {
503 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 474 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
504 FakeLayerAnimationControllerClient dummy; 475 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create());
505 scoped_ptr<LayerAnimationController> controller(
506 LayerAnimationController::create(&dummy));
507 476
508 const int id = 1; 477 const int id = 1;
509 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans formTransition(1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Transform)); 478 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)); 479 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)); 480 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 1, 0.75)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity));
512 481
513 controller->animate(0, events.get()); 482 controller->animate(0, events.get());
514 EXPECT_TRUE(controller->hasActiveAnimation()); 483 EXPECT_TRUE(controller->hasActiveAnimation());
515 EXPECT_EQ(0, dummy.opacity()); 484 EXPECT_EQ(0, controller->opacity());
516 controller->animate(1, events.get()); 485 controller->animate(1, events.get());
517 EXPECT_TRUE(controller->hasActiveAnimation()); 486 EXPECT_TRUE(controller->hasActiveAnimation());
518 EXPECT_EQ(0.5, dummy.opacity()); 487 EXPECT_EQ(0.5, controller->opacity());
519 488
520 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); 489 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity));
521 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac tiveAnimation::Aborted, 1); 490 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac tiveAnimation::Aborted, 1);
522 controller->animate(1, events.get()); 491 controller->animate(1, events.get());
523 EXPECT_TRUE(controller->hasActiveAnimation()); 492 EXPECT_TRUE(controller->hasActiveAnimation());
524 EXPECT_EQ(1, dummy.opacity()); 493 EXPECT_EQ(1, controller->opacity());
525 controller->animate(2, events.get()); 494 controller->animate(2, events.get());
526 EXPECT_TRUE(!controller->hasActiveAnimation()); 495 EXPECT_TRUE(!controller->hasActiveAnimation());
527 EXPECT_EQ(0.75, dummy.opacity()); 496 EXPECT_EQ(0.75, controller->opacity());
528 } 497 }
529 498
530 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) 499 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded)
531 { 500 {
532 FakeLayerAnimationControllerClient dummyImpl; 501 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl ler::create());
533 scoped_ptr<LayerAnimationController> controllerImpl(LayerAnimationController ::create(&dummyImpl)); 502 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 503
539 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new FakeFloatTransition(2, 0, 1)).PassAs<AnimationCurve>(), 0, ActiveAnimation::Opac ity)); 504 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new FakeFloatTransition(2, 0, 1)).PassAs<AnimationCurve>(), 0, ActiveAnimation::Opac ity));
540 toAdd->setNeedsSynchronizedStartTime(true); 505 toAdd->setNeedsSynchronizedStartTime(true);
541 controller->addAnimation(toAdd.Pass()); 506 controller->addAnimation(toAdd.Pass());
542 507
543 controller->animate(0, 0); 508 controller->animate(0, 0);
544 EXPECT_TRUE(controller->hasActiveAnimation()); 509 EXPECT_TRUE(controller->hasActiveAnimation());
545 ActiveAnimation* activeAnimation = controller->getActiveAnimation(0, ActiveA nimation::Opacity); 510 ActiveAnimation* activeAnimation = controller->getActiveAnimation(0, ActiveA nimation::Opacity);
546 EXPECT_TRUE(activeAnimation); 511 EXPECT_TRUE(activeAnimation);
547 EXPECT_TRUE(activeAnimation->needsSynchronizedStartTime()); 512 EXPECT_TRUE(activeAnimation->needsSynchronizedStartTime());
548 513
549 controller->setForceSync(); 514 controller->setForceSync();
550 515
551 controller->pushAnimationUpdatesTo(controllerImpl.get()); 516 controller->pushAnimationUpdatesTo(controllerImpl.get());
552 517
553 activeAnimation = controllerImpl->getActiveAnimation(0, ActiveAnimation::Opa city); 518 activeAnimation = controllerImpl->getActiveAnimation(0, ActiveAnimation::Opa city);
554 EXPECT_TRUE(activeAnimation); 519 EXPECT_TRUE(activeAnimation);
555 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, activeAnimation->ru nState()); 520 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, activeAnimation->ru nState());
556 } 521 }
557 522
558 } // namespace 523 } // namespace
559 } // namespace cc 524 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_animation_controller.cc ('k') | cc/layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698