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/animation/layer_animation_controller.h" | 5 #include "cc/animation/layer_animation_controller.h" |
6 | 6 |
7 #include "cc/animation/animation.h" | 7 #include "cc/animation/animation.h" |
8 #include "cc/animation/animation_curve.h" | 8 #include "cc/animation/animation_curve.h" |
9 #include "cc/animation/animation_delegate.h" | 9 #include "cc/animation/animation_delegate.h" |
10 #include "cc/animation/animation_registrar.h" | 10 #include "cc/animation/animation_registrar.h" |
11 #include "cc/animation/keyframed_animation_curve.h" | 11 #include "cc/animation/keyframed_animation_curve.h" |
12 #include "cc/animation/scroll_offset_animation_curve.h" | 12 #include "cc/animation/scroll_offset_animation_curve.h" |
13 #include "cc/animation/transform_operations.h" | 13 #include "cc/animation/transform_operations.h" |
14 #include "cc/test/animation_test_common.h" | 14 #include "cc/test/animation_test_common.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "ui/gfx/box_f.h" | 17 #include "ui/gfx/box_f.h" |
18 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 namespace { | 21 namespace { |
22 | 22 |
23 // A LayerAnimationController cannot be ticked at 0.0, since an animation | 23 // A LayerAnimationController cannot be ticked at 0.0, since an animation |
24 // with start time 0.0 is treated as an animation whose start time has | 24 // with start time 0.0 is treated as an animation whose start time has |
25 // not yet been set. | 25 // not yet been set. |
26 const double kInitialTickTime = 1.0; | 26 const double kInitialTickTime = 1.0; |
danakj
2014/04/09 16:33:03
why not change this to a TimeTicks?
we should avo
ajuma
2014/04/09 17:37:39
+1, please change this to TimeTicks. Note that we
Sikugu_
2014/04/10 14:04:57
Done.
Sikugu_
2014/04/10 14:04:57
Few calls of animation functions still use double.
| |
27 base::TimeTicks GetTimeTicks(double time) { | |
danakj
2014/04/09 16:33:03
blank line above method definition.
Sikugu_
2014/04/10 14:04:57
Done.
| |
28 return base::TimeTicks::FromInternalValue(time * | |
29 base::Time::kMicrosecondsPerSecond); | |
30 } | |
27 | 31 |
28 scoped_ptr<Animation> CreateAnimation(scoped_ptr<AnimationCurve> curve, | 32 scoped_ptr<Animation> CreateAnimation(scoped_ptr<AnimationCurve> curve, |
29 int id, | 33 int id, |
30 Animation::TargetProperty property) { | 34 Animation::TargetProperty property) { |
31 return Animation::Create(curve.Pass(), 0, id, property); | 35 return Animation::Create(curve.Pass(), 0, id, property); |
32 } | 36 } |
33 | 37 |
34 TEST(LayerAnimationControllerTest, SyncNewAnimation) { | 38 TEST(LayerAnimationControllerTest, SyncNewAnimation) { |
35 FakeLayerAnimationValueObserver dummy_impl; | 39 FakeLayerAnimationValueObserver dummy_impl; |
36 scoped_refptr<LayerAnimationController> controller_impl( | 40 scoped_refptr<LayerAnimationController> controller_impl( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 int group_id = controller->GetAnimation(Animation::Opacity)->group(); | 76 int group_id = controller->GetAnimation(Animation::Opacity)->group(); |
73 | 77 |
74 controller->PushAnimationUpdatesTo(controller_impl.get()); | 78 controller->PushAnimationUpdatesTo(controller_impl.get()); |
75 | 79 |
76 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); | 80 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); |
77 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 81 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
78 controller_impl->GetAnimation(group_id, | 82 controller_impl->GetAnimation(group_id, |
79 Animation::Opacity)->run_state()); | 83 Animation::Opacity)->run_state()); |
80 | 84 |
81 AnimationEventsVector events; | 85 AnimationEventsVector events; |
82 controller_impl->Animate(kInitialTickTime); | 86 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
83 controller_impl->UpdateState(true, &events); | 87 controller_impl->UpdateState(true, &events); |
84 | 88 |
85 // Synchronize the start times. | 89 // Synchronize the start times. |
86 EXPECT_EQ(1u, events.size()); | 90 EXPECT_EQ(1u, events.size()); |
87 controller->NotifyAnimationStarted(events[0]); | 91 controller->NotifyAnimationStarted(events[0]); |
88 EXPECT_EQ(controller->GetAnimation(group_id, | 92 EXPECT_EQ(controller->GetAnimation(group_id, |
89 Animation::Opacity)->start_time(), | 93 Animation::Opacity)->start_time(), |
90 controller_impl->GetAnimation(group_id, | 94 controller_impl->GetAnimation(group_id, |
91 Animation::Opacity)->start_time()); | 95 Animation::Opacity)->start_time()); |
92 | 96 |
93 // Start the animation on the main thread. Should not affect the start time. | 97 // Start the animation on the main thread. Should not affect the start time. |
94 controller->Animate(kInitialTickTime + 0.5); | 98 controller->Animate(GetTimeTicks(kInitialTickTime + 0.5)); |
95 controller->UpdateState(true, NULL); | 99 controller->UpdateState(true, NULL); |
96 EXPECT_EQ(controller->GetAnimation(group_id, | 100 EXPECT_EQ(controller->GetAnimation(group_id, |
97 Animation::Opacity)->start_time(), | 101 Animation::Opacity)->start_time(), |
98 controller_impl->GetAnimation(group_id, | 102 controller_impl->GetAnimation(group_id, |
99 Animation::Opacity)->start_time()); | 103 Animation::Opacity)->start_time()); |
100 } | 104 } |
101 | 105 |
102 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) { | 106 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) { |
103 FakeLayerAnimationValueObserver dummy_impl; | 107 FakeLayerAnimationValueObserver dummy_impl; |
104 scoped_refptr<LayerAnimationController> controller_impl( | 108 scoped_refptr<LayerAnimationController> controller_impl( |
(...skipping 11 matching lines...) Expand all Loading... | |
116 controller->GetAnimation(Animation::Opacity)->set_start_time(start_time); | 120 controller->GetAnimation(Animation::Opacity)->set_start_time(start_time); |
117 | 121 |
118 controller->PushAnimationUpdatesTo(controller_impl.get()); | 122 controller->PushAnimationUpdatesTo(controller_impl.get()); |
119 | 123 |
120 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); | 124 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); |
121 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 125 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
122 controller_impl->GetAnimation(group_id, | 126 controller_impl->GetAnimation(group_id, |
123 Animation::Opacity)->run_state()); | 127 Animation::Opacity)->run_state()); |
124 | 128 |
125 AnimationEventsVector events; | 129 AnimationEventsVector events; |
126 controller_impl->Animate(kInitialTickTime); | 130 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
127 controller_impl->UpdateState(true, &events); | 131 controller_impl->UpdateState(true, &events); |
128 | 132 |
129 // Synchronize the start times. | 133 // Synchronize the start times. |
130 EXPECT_EQ(1u, events.size()); | 134 EXPECT_EQ(1u, events.size()); |
131 controller->NotifyAnimationStarted(events[0]); | 135 controller->NotifyAnimationStarted(events[0]); |
132 | 136 |
133 EXPECT_EQ(start_time, | 137 EXPECT_EQ(start_time, |
134 controller->GetAnimation(group_id, | 138 controller->GetAnimation(group_id, |
135 Animation::Opacity)->start_time()); | 139 Animation::Opacity)->start_time()); |
136 EXPECT_EQ(controller->GetAnimation(group_id, | 140 EXPECT_EQ(controller->GetAnimation(group_id, |
137 Animation::Opacity)->start_time(), | 141 Animation::Opacity)->start_time(), |
138 controller_impl->GetAnimation(group_id, | 142 controller_impl->GetAnimation(group_id, |
139 Animation::Opacity)->start_time()); | 143 Animation::Opacity)->start_time()); |
140 | 144 |
141 // Start the animation on the main thread. Should not affect the start time. | 145 // Start the animation on the main thread. Should not affect the start time. |
142 controller->Animate(kInitialTickTime + 0.5); | 146 controller->Animate(GetTimeTicks(kInitialTickTime + 0.5)); |
ajuma
2014/04/09 17:37:39
Offsets (like 0.5 above) should be TimeDeltas.
Sikugu_
2014/04/10 14:04:57
Done.
| |
143 controller->UpdateState(true, NULL); | 147 controller->UpdateState(true, NULL); |
144 EXPECT_EQ(start_time, | 148 EXPECT_EQ(start_time, |
145 controller->GetAnimation(group_id, | 149 controller->GetAnimation(group_id, |
146 Animation::Opacity)->start_time()); | 150 Animation::Opacity)->start_time()); |
147 EXPECT_EQ(controller->GetAnimation(group_id, | 151 EXPECT_EQ(controller->GetAnimation(group_id, |
148 Animation::Opacity)->start_time(), | 152 Animation::Opacity)->start_time(), |
149 controller_impl->GetAnimation(group_id, | 153 controller_impl->GetAnimation(group_id, |
150 Animation::Opacity)->start_time()); | 154 Animation::Opacity)->start_time()); |
151 } | 155 } |
152 | 156 |
(...skipping 24 matching lines...) Expand all Loading... | |
177 | 181 |
178 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 182 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
179 // The main thread controller should now be active. | 183 // The main thread controller should now be active. |
180 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 184 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
181 | 185 |
182 controller->PushAnimationUpdatesTo(controller_impl.get()); | 186 controller->PushAnimationUpdatesTo(controller_impl.get()); |
183 // Both controllers should now be active. | 187 // Both controllers should now be active. |
184 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 188 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
185 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); | 189 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); |
186 | 190 |
187 controller_impl->Animate(kInitialTickTime); | 191 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
188 controller_impl->UpdateState(true, events.get()); | 192 controller_impl->UpdateState(true, events.get()); |
189 EXPECT_EQ(1u, events->size()); | 193 EXPECT_EQ(1u, events->size()); |
190 controller->NotifyAnimationStarted((*events)[0]); | 194 controller->NotifyAnimationStarted((*events)[0]); |
191 | 195 |
192 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 196 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
193 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); | 197 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); |
194 | 198 |
195 controller->Animate(kInitialTickTime + 0.5); | 199 controller->Animate(GetTimeTicks(kInitialTickTime + 0.5)); |
196 controller->UpdateState(true, NULL); | 200 controller->UpdateState(true, NULL); |
197 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 201 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
198 | 202 |
199 controller->Animate(kInitialTickTime + 1.0); | 203 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
200 controller->UpdateState(true, NULL); | 204 controller->UpdateState(true, NULL); |
201 EXPECT_EQ(Animation::Finished, | 205 EXPECT_EQ(Animation::Finished, |
202 controller->GetAnimation(Animation::Opacity)->run_state()); | 206 controller->GetAnimation(Animation::Opacity)->run_state()); |
203 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 207 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
204 | 208 |
205 events.reset(new AnimationEventsVector); | 209 events.reset(new AnimationEventsVector); |
206 controller_impl->Animate(kInitialTickTime + 1.5); | 210 controller_impl->Animate(GetTimeTicks(kInitialTickTime + 1.5)); |
207 controller_impl->UpdateState(true, events.get()); | 211 controller_impl->UpdateState(true, events.get()); |
208 | 212 |
209 EXPECT_EQ(Animation::WaitingForDeletion, | 213 EXPECT_EQ(Animation::WaitingForDeletion, |
210 controller_impl->GetAnimation(Animation::Opacity)->run_state()); | 214 controller_impl->GetAnimation(Animation::Opacity)->run_state()); |
211 // The impl thread controller should have de-activated. | 215 // The impl thread controller should have de-activated. |
212 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size()); | 216 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size()); |
213 | 217 |
214 EXPECT_EQ(1u, events->size()); | 218 EXPECT_EQ(1u, events->size()); |
215 controller->NotifyAnimationFinished((*events)[0]); | 219 controller->NotifyAnimationFinished((*events)[0]); |
216 controller->Animate(kInitialTickTime + 1.5); | 220 controller->Animate(GetTimeTicks(kInitialTickTime + 1.5)); |
217 controller->UpdateState(true, NULL); | 221 controller->UpdateState(true, NULL); |
218 | 222 |
219 EXPECT_EQ(Animation::WaitingForDeletion, | 223 EXPECT_EQ(Animation::WaitingForDeletion, |
220 controller->GetAnimation(Animation::Opacity)->run_state()); | 224 controller->GetAnimation(Animation::Opacity)->run_state()); |
221 // The main thread controller should have de-activated. | 225 // The main thread controller should have de-activated. |
222 EXPECT_EQ(0u, registrar->active_animation_controllers().size()); | 226 EXPECT_EQ(0u, registrar->active_animation_controllers().size()); |
223 | 227 |
224 controller->PushAnimationUpdatesTo(controller_impl.get()); | 228 controller->PushAnimationUpdatesTo(controller_impl.get()); |
225 EXPECT_FALSE(controller->has_any_animation()); | 229 EXPECT_FALSE(controller->has_any_animation()); |
226 EXPECT_FALSE(controller_impl->has_any_animation()); | 230 EXPECT_FALSE(controller_impl->has_any_animation()); |
(...skipping 22 matching lines...) Expand all Loading... | |
249 | 253 |
250 controller->PushAnimationUpdatesTo(controller_impl.get()); | 254 controller->PushAnimationUpdatesTo(controller_impl.get()); |
251 | 255 |
252 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); | 256 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); |
253 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 257 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
254 controller_impl->GetAnimation(group_id, | 258 controller_impl->GetAnimation(group_id, |
255 Animation::Opacity)->run_state()); | 259 Animation::Opacity)->run_state()); |
256 | 260 |
257 // Start the animations on each controller. | 261 // Start the animations on each controller. |
258 AnimationEventsVector events; | 262 AnimationEventsVector events; |
259 controller_impl->Animate(kInitialTickTime); | 263 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
260 controller_impl->UpdateState(true, &events); | 264 controller_impl->UpdateState(true, &events); |
261 controller->Animate(kInitialTickTime); | 265 controller->Animate(GetTimeTicks(kInitialTickTime)); |
262 controller->UpdateState(true, NULL); | 266 controller->UpdateState(true, NULL); |
263 EXPECT_EQ(Animation::Running, | 267 EXPECT_EQ(Animation::Running, |
264 controller_impl->GetAnimation(group_id, | 268 controller_impl->GetAnimation(group_id, |
265 Animation::Opacity)->run_state()); | 269 Animation::Opacity)->run_state()); |
266 EXPECT_EQ(Animation::Running, | 270 EXPECT_EQ(Animation::Running, |
267 controller->GetAnimation(group_id, | 271 controller->GetAnimation(group_id, |
268 Animation::Opacity)->run_state()); | 272 Animation::Opacity)->run_state()); |
269 | 273 |
270 // Pause the main-thread animation. | 274 // Pause the main-thread animation. |
271 controller->PauseAnimation(animation_id, kInitialTickTime + 1.0); | 275 controller->PauseAnimation(animation_id, |
276 GetTimeTicks(kInitialTickTime + 1.0)); | |
272 EXPECT_EQ(Animation::Paused, | 277 EXPECT_EQ(Animation::Paused, |
273 controller->GetAnimation(group_id, | 278 controller->GetAnimation(group_id, |
274 Animation::Opacity)->run_state()); | 279 Animation::Opacity)->run_state()); |
275 | 280 |
276 // The pause run state change should make it to the impl thread controller. | 281 // The pause run state change should make it to the impl thread controller. |
277 controller->PushAnimationUpdatesTo(controller_impl.get()); | 282 controller->PushAnimationUpdatesTo(controller_impl.get()); |
278 EXPECT_EQ(Animation::Paused, | 283 EXPECT_EQ(Animation::Paused, |
279 controller_impl->GetAnimation(group_id, | 284 controller_impl->GetAnimation(group_id, |
280 Animation::Opacity)->run_state()); | 285 Animation::Opacity)->run_state()); |
281 } | 286 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 scoped_ptr<AnimationEventsVector> events( | 336 scoped_ptr<AnimationEventsVector> events( |
332 make_scoped_ptr(new AnimationEventsVector)); | 337 make_scoped_ptr(new AnimationEventsVector)); |
333 scoped_refptr<LayerAnimationController> controller( | 338 scoped_refptr<LayerAnimationController> controller( |
334 LayerAnimationController::Create(0)); | 339 LayerAnimationController::Create(0)); |
335 scoped_refptr<LayerAnimationController> controller_impl( | 340 scoped_refptr<LayerAnimationController> controller_impl( |
336 LayerAnimationController::Create(0)); | 341 LayerAnimationController::Create(0)); |
337 controller->AddValueObserver(&dummy); | 342 controller->AddValueObserver(&dummy); |
338 controller_impl->AddValueObserver(&dummy_impl); | 343 controller_impl->AddValueObserver(&dummy_impl); |
339 | 344 |
340 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); | 345 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); |
341 controller->Animate(kInitialTickTime); | 346 controller->Animate(GetTimeTicks(kInitialTickTime)); |
342 controller->UpdateState(true, NULL); | 347 controller->UpdateState(true, NULL); |
343 controller->PushAnimationUpdatesTo(controller_impl.get()); | 348 controller->PushAnimationUpdatesTo(controller_impl.get()); |
344 | 349 |
345 controller_impl->Animate(kInitialTickTime + 0.5); | 350 controller_impl->Animate(GetTimeTicks(kInitialTickTime + 0.5)); |
346 controller_impl->UpdateState(true, events.get()); | 351 controller_impl->UpdateState(true, events.get()); |
347 | 352 |
348 // There should be a Started event for the animation. | 353 // There should be a Started event for the animation. |
349 EXPECT_EQ(1u, events->size()); | 354 EXPECT_EQ(1u, events->size()); |
350 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); | 355 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); |
351 controller->NotifyAnimationStarted((*events)[0]); | 356 controller->NotifyAnimationStarted((*events)[0]); |
352 | 357 |
353 controller->Animate(kInitialTickTime + 1.0); | 358 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
354 controller->UpdateState(true, NULL); | 359 controller->UpdateState(true, NULL); |
355 | 360 |
356 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | 361 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); |
357 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | 362 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); |
358 | 363 |
359 events.reset(new AnimationEventsVector); | 364 events.reset(new AnimationEventsVector); |
360 controller_impl->Animate(kInitialTickTime + 2.0); | 365 controller_impl->Animate(GetTimeTicks(kInitialTickTime + 2.0)); |
361 controller_impl->UpdateState(true, events.get()); | 366 controller_impl->UpdateState(true, events.get()); |
362 | 367 |
363 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | 368 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); |
364 | 369 |
365 // There should be a Finished event for the animation. | 370 // There should be a Finished event for the animation. |
366 EXPECT_EQ(1u, events->size()); | 371 EXPECT_EQ(1u, events->size()); |
367 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 372 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); |
368 | 373 |
369 // Neither controller should have deleted the animation yet. | 374 // Neither controller should have deleted the animation yet. |
370 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity)); | 375 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity)); |
371 EXPECT_TRUE(controller_impl->GetAnimation(Animation::Opacity)); | 376 EXPECT_TRUE(controller_impl->GetAnimation(Animation::Opacity)); |
372 | 377 |
373 controller->NotifyAnimationFinished((*events)[0]); | 378 controller->NotifyAnimationFinished((*events)[0]); |
374 | 379 |
375 controller->Animate(kInitialTickTime + 3.0); | 380 controller->Animate(GetTimeTicks(kInitialTickTime + 3.0)); |
376 controller->UpdateState(true, NULL); | 381 controller->UpdateState(true, NULL); |
377 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 382 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
378 | 383 |
379 controller->PushAnimationUpdatesTo(controller_impl.get()); | 384 controller->PushAnimationUpdatesTo(controller_impl.get()); |
380 | 385 |
381 // Both controllers should now have deleted the animation. | 386 // Both controllers should now have deleted the animation. |
382 EXPECT_FALSE(controller->has_any_animation()); | 387 EXPECT_FALSE(controller->has_any_animation()); |
383 EXPECT_FALSE(controller_impl->has_any_animation()); | 388 EXPECT_FALSE(controller_impl->has_any_animation()); |
384 } | 389 } |
385 | 390 |
(...skipping 16 matching lines...) Expand all Loading... | |
402 scoped_refptr<LayerAnimationController> controller( | 407 scoped_refptr<LayerAnimationController> controller( |
403 LayerAnimationController::Create(0)); | 408 LayerAnimationController::Create(0)); |
404 controller->AddValueObserver(&dummy); | 409 controller->AddValueObserver(&dummy); |
405 | 410 |
406 scoped_ptr<Animation> to_add(CreateAnimation( | 411 scoped_ptr<Animation> to_add(CreateAnimation( |
407 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 412 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
408 1, | 413 1, |
409 Animation::Opacity)); | 414 Animation::Opacity)); |
410 | 415 |
411 controller->AddAnimation(to_add.Pass()); | 416 controller->AddAnimation(to_add.Pass()); |
412 controller->Animate(kInitialTickTime); | 417 controller->Animate(GetTimeTicks(kInitialTickTime)); |
413 controller->UpdateState(true, events.get()); | 418 controller->UpdateState(true, events.get()); |
414 EXPECT_TRUE(controller->HasActiveAnimation()); | 419 EXPECT_TRUE(controller->HasActiveAnimation()); |
415 EXPECT_EQ(0.f, dummy.opacity()); | 420 EXPECT_EQ(0.f, dummy.opacity()); |
416 // A non-impl-only animation should not generate property updates. | 421 // A non-impl-only animation should not generate property updates. |
417 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 422 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
418 EXPECT_FALSE(event); | 423 EXPECT_FALSE(event); |
419 controller->Animate(kInitialTickTime + 1.0); | 424 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
420 controller->UpdateState(true, events.get()); | 425 controller->UpdateState(true, events.get()); |
421 EXPECT_EQ(1.f, dummy.opacity()); | 426 EXPECT_EQ(1.f, dummy.opacity()); |
422 EXPECT_FALSE(controller->HasActiveAnimation()); | 427 EXPECT_FALSE(controller->HasActiveAnimation()); |
423 event = GetMostRecentPropertyUpdateEvent(events.get()); | 428 event = GetMostRecentPropertyUpdateEvent(events.get()); |
424 EXPECT_FALSE(event); | 429 EXPECT_FALSE(event); |
425 } | 430 } |
426 | 431 |
427 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { | 432 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { |
428 scoped_ptr<AnimationEventsVector> events( | 433 scoped_ptr<AnimationEventsVector> events( |
429 make_scoped_ptr(new AnimationEventsVector)); | 434 make_scoped_ptr(new AnimationEventsVector)); |
430 FakeLayerAnimationValueObserver dummy_impl; | 435 FakeLayerAnimationValueObserver dummy_impl; |
431 scoped_refptr<LayerAnimationController> controller_impl( | 436 scoped_refptr<LayerAnimationController> controller_impl( |
432 LayerAnimationController::Create(0)); | 437 LayerAnimationController::Create(0)); |
433 controller_impl->AddValueObserver(&dummy_impl); | 438 controller_impl->AddValueObserver(&dummy_impl); |
434 | 439 |
435 scoped_ptr<Animation> to_add(CreateAnimation( | 440 scoped_ptr<Animation> to_add(CreateAnimation( |
436 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 441 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
437 1, | 442 1, |
438 Animation::Opacity)); | 443 Animation::Opacity)); |
439 to_add->set_is_impl_only(true); | 444 to_add->set_is_impl_only(true); |
440 | 445 |
441 controller_impl->AddAnimation(to_add.Pass()); | 446 controller_impl->AddAnimation(to_add.Pass()); |
442 controller_impl->Animate(kInitialTickTime); | 447 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
443 controller_impl->UpdateState(true, events.get()); | 448 controller_impl->UpdateState(true, events.get()); |
444 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 449 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
445 EXPECT_EQ(0.f, dummy_impl.opacity()); | 450 EXPECT_EQ(0.f, dummy_impl.opacity()); |
446 EXPECT_EQ(2u, events->size()); | 451 EXPECT_EQ(2u, events->size()); |
447 const AnimationEvent* start_opacity_event = | 452 const AnimationEvent* start_opacity_event = |
448 GetMostRecentPropertyUpdateEvent(events.get()); | 453 GetMostRecentPropertyUpdateEvent(events.get()); |
449 EXPECT_EQ(0.f, start_opacity_event->opacity); | 454 EXPECT_EQ(0.f, start_opacity_event->opacity); |
450 | 455 |
451 controller_impl->Animate(kInitialTickTime + 1.0); | 456 controller_impl->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
452 controller_impl->UpdateState(true, events.get()); | 457 controller_impl->UpdateState(true, events.get()); |
453 EXPECT_EQ(1.f, dummy_impl.opacity()); | 458 EXPECT_EQ(1.f, dummy_impl.opacity()); |
454 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 459 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
455 EXPECT_EQ(4u, events->size()); | 460 EXPECT_EQ(4u, events->size()); |
456 const AnimationEvent* end_opacity_event = | 461 const AnimationEvent* end_opacity_event = |
457 GetMostRecentPropertyUpdateEvent(events.get()); | 462 GetMostRecentPropertyUpdateEvent(events.get()); |
458 EXPECT_EQ(1.f, end_opacity_event->opacity); | 463 EXPECT_EQ(1.f, end_opacity_event->opacity); |
459 } | 464 } |
460 | 465 |
461 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { | 466 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { |
(...skipping 19 matching lines...) Expand all Loading... | |
481 operations.AppendTranslate(delta_x, delta_y, 0); | 486 operations.AppendTranslate(delta_x, delta_y, 0); |
482 curve->AddKeyframe( | 487 curve->AddKeyframe( |
483 TransformKeyframe::Create(1, operations, scoped_ptr<TimingFunction>())); | 488 TransformKeyframe::Create(1, operations, scoped_ptr<TimingFunction>())); |
484 | 489 |
485 scoped_ptr<Animation> animation(Animation::Create( | 490 scoped_ptr<Animation> animation(Animation::Create( |
486 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Transform)); | 491 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Transform)); |
487 animation->set_is_impl_only(true); | 492 animation->set_is_impl_only(true); |
488 controller_impl->AddAnimation(animation.Pass()); | 493 controller_impl->AddAnimation(animation.Pass()); |
489 | 494 |
490 // Run animation. | 495 // Run animation. |
491 controller_impl->Animate(kInitialTickTime); | 496 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
492 controller_impl->UpdateState(true, events.get()); | 497 controller_impl->UpdateState(true, events.get()); |
493 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 498 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
494 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); | 499 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); |
495 EXPECT_EQ(2u, events->size()); | 500 EXPECT_EQ(2u, events->size()); |
496 const AnimationEvent* start_transform_event = | 501 const AnimationEvent* start_transform_event = |
497 GetMostRecentPropertyUpdateEvent(events.get()); | 502 GetMostRecentPropertyUpdateEvent(events.get()); |
498 ASSERT_TRUE(start_transform_event); | 503 ASSERT_TRUE(start_transform_event); |
499 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); | 504 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); |
500 EXPECT_TRUE(start_transform_event->is_impl_only); | 505 EXPECT_TRUE(start_transform_event->is_impl_only); |
501 | 506 |
502 gfx::Transform expected_transform; | 507 gfx::Transform expected_transform; |
503 expected_transform.Translate(delta_x, delta_y); | 508 expected_transform.Translate(delta_x, delta_y); |
504 | 509 |
505 controller_impl->Animate(kInitialTickTime + 1.0); | 510 controller_impl->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
506 controller_impl->UpdateState(true, events.get()); | 511 controller_impl->UpdateState(true, events.get()); |
507 EXPECT_EQ(expected_transform, dummy_impl.transform()); | 512 EXPECT_EQ(expected_transform, dummy_impl.transform()); |
508 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 513 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
509 EXPECT_EQ(4u, events->size()); | 514 EXPECT_EQ(4u, events->size()); |
510 const AnimationEvent* end_transform_event = | 515 const AnimationEvent* end_transform_event = |
511 GetMostRecentPropertyUpdateEvent(events.get()); | 516 GetMostRecentPropertyUpdateEvent(events.get()); |
512 EXPECT_EQ(expected_transform, end_transform_event->transform); | 517 EXPECT_EQ(expected_transform, end_transform_event->transform); |
513 EXPECT_TRUE(end_transform_event->is_impl_only); | 518 EXPECT_TRUE(end_transform_event->is_impl_only); |
514 } | 519 } |
515 | 520 |
(...skipping 14 matching lines...) Expand all Loading... | |
530 FilterKeyframe::Create(0, start_filters, scoped_ptr<TimingFunction>())); | 535 FilterKeyframe::Create(0, start_filters, scoped_ptr<TimingFunction>())); |
531 FilterOperations end_filters; | 536 FilterOperations end_filters; |
532 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 537 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
533 curve->AddKeyframe( | 538 curve->AddKeyframe( |
534 FilterKeyframe::Create(1, end_filters, scoped_ptr<TimingFunction>())); | 539 FilterKeyframe::Create(1, end_filters, scoped_ptr<TimingFunction>())); |
535 | 540 |
536 scoped_ptr<Animation> animation(Animation::Create( | 541 scoped_ptr<Animation> animation(Animation::Create( |
537 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Filter)); | 542 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Filter)); |
538 controller->AddAnimation(animation.Pass()); | 543 controller->AddAnimation(animation.Pass()); |
539 | 544 |
540 controller->Animate(kInitialTickTime); | 545 controller->Animate(GetTimeTicks(kInitialTickTime)); |
541 controller->UpdateState(true, events.get()); | 546 controller->UpdateState(true, events.get()); |
542 EXPECT_TRUE(controller->HasActiveAnimation()); | 547 EXPECT_TRUE(controller->HasActiveAnimation()); |
543 EXPECT_EQ(start_filters, dummy.filters()); | 548 EXPECT_EQ(start_filters, dummy.filters()); |
544 // A non-impl-only animation should not generate property updates. | 549 // A non-impl-only animation should not generate property updates. |
545 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 550 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
546 EXPECT_FALSE(event); | 551 EXPECT_FALSE(event); |
547 | 552 |
548 controller->Animate(kInitialTickTime + 0.5); | 553 controller->Animate(GetTimeTicks(kInitialTickTime + 0.5)); |
549 controller->UpdateState(true, events.get()); | 554 controller->UpdateState(true, events.get()); |
550 EXPECT_EQ(1u, dummy.filters().size()); | 555 EXPECT_EQ(1u, dummy.filters().size()); |
551 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), | 556 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), |
552 dummy.filters().at(0)); | 557 dummy.filters().at(0)); |
553 event = GetMostRecentPropertyUpdateEvent(events.get()); | 558 event = GetMostRecentPropertyUpdateEvent(events.get()); |
554 EXPECT_FALSE(event); | 559 EXPECT_FALSE(event); |
555 | 560 |
556 controller->Animate(kInitialTickTime + 1.0); | 561 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
557 controller->UpdateState(true, events.get()); | 562 controller->UpdateState(true, events.get()); |
558 EXPECT_EQ(end_filters, dummy.filters()); | 563 EXPECT_EQ(end_filters, dummy.filters()); |
559 EXPECT_FALSE(controller->HasActiveAnimation()); | 564 EXPECT_FALSE(controller->HasActiveAnimation()); |
560 event = GetMostRecentPropertyUpdateEvent(events.get()); | 565 event = GetMostRecentPropertyUpdateEvent(events.get()); |
561 EXPECT_FALSE(event); | 566 EXPECT_FALSE(event); |
562 } | 567 } |
563 | 568 |
564 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) { | 569 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) { |
565 scoped_ptr<AnimationEventsVector> events( | 570 scoped_ptr<AnimationEventsVector> events( |
566 make_scoped_ptr(new AnimationEventsVector)); | 571 make_scoped_ptr(new AnimationEventsVector)); |
(...skipping 14 matching lines...) Expand all Loading... | |
581 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 586 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
582 curve->AddKeyframe( | 587 curve->AddKeyframe( |
583 FilterKeyframe::Create(1, end_filters, scoped_ptr<TimingFunction>())); | 588 FilterKeyframe::Create(1, end_filters, scoped_ptr<TimingFunction>())); |
584 | 589 |
585 scoped_ptr<Animation> animation(Animation::Create( | 590 scoped_ptr<Animation> animation(Animation::Create( |
586 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Filter)); | 591 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Filter)); |
587 animation->set_is_impl_only(true); | 592 animation->set_is_impl_only(true); |
588 controller_impl->AddAnimation(animation.Pass()); | 593 controller_impl->AddAnimation(animation.Pass()); |
589 | 594 |
590 // Run animation. | 595 // Run animation. |
591 controller_impl->Animate(kInitialTickTime); | 596 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
592 controller_impl->UpdateState(true, events.get()); | 597 controller_impl->UpdateState(true, events.get()); |
593 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 598 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
594 EXPECT_EQ(start_filters, dummy_impl.filters()); | 599 EXPECT_EQ(start_filters, dummy_impl.filters()); |
595 EXPECT_EQ(2u, events->size()); | 600 EXPECT_EQ(2u, events->size()); |
596 const AnimationEvent* start_filter_event = | 601 const AnimationEvent* start_filter_event = |
597 GetMostRecentPropertyUpdateEvent(events.get()); | 602 GetMostRecentPropertyUpdateEvent(events.get()); |
598 EXPECT_TRUE(start_filter_event); | 603 EXPECT_TRUE(start_filter_event); |
599 EXPECT_EQ(start_filters, start_filter_event->filters); | 604 EXPECT_EQ(start_filters, start_filter_event->filters); |
600 EXPECT_TRUE(start_filter_event->is_impl_only); | 605 EXPECT_TRUE(start_filter_event->is_impl_only); |
601 | 606 |
602 controller_impl->Animate(kInitialTickTime + 1.0); | 607 controller_impl->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
603 controller_impl->UpdateState(true, events.get()); | 608 controller_impl->UpdateState(true, events.get()); |
604 EXPECT_EQ(end_filters, dummy_impl.filters()); | 609 EXPECT_EQ(end_filters, dummy_impl.filters()); |
605 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 610 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
606 EXPECT_EQ(4u, events->size()); | 611 EXPECT_EQ(4u, events->size()); |
607 const AnimationEvent* end_filter_event = | 612 const AnimationEvent* end_filter_event = |
608 GetMostRecentPropertyUpdateEvent(events.get()); | 613 GetMostRecentPropertyUpdateEvent(events.get()); |
609 EXPECT_TRUE(end_filter_event); | 614 EXPECT_TRUE(end_filter_event); |
610 EXPECT_EQ(end_filters, end_filter_event->filters); | 615 EXPECT_EQ(end_filters, end_filter_event->filters); |
611 EXPECT_TRUE(end_filter_event->is_impl_only); | 616 EXPECT_TRUE(end_filter_event->is_impl_only); |
612 } | 617 } |
(...skipping 29 matching lines...) Expand all Loading... | |
642 dummy_provider_impl.set_scroll_offset(initial_value); | 647 dummy_provider_impl.set_scroll_offset(initial_value); |
643 controller->PushAnimationUpdatesTo(controller_impl.get()); | 648 controller->PushAnimationUpdatesTo(controller_impl.get()); |
644 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); | 649 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); |
645 double duration = controller_impl->GetAnimation( | 650 double duration = controller_impl->GetAnimation( |
646 Animation::ScrollOffset)->curve()->Duration(); | 651 Animation::ScrollOffset)->curve()->Duration(); |
647 | 652 |
648 EXPECT_EQ( | 653 EXPECT_EQ( |
649 duration, | 654 duration, |
650 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); | 655 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); |
651 | 656 |
652 controller->Animate(kInitialTickTime); | 657 controller->Animate(GetTimeTicks(kInitialTickTime)); |
653 controller->UpdateState(true, NULL); | 658 controller->UpdateState(true, NULL); |
654 EXPECT_TRUE(controller->HasActiveAnimation()); | 659 EXPECT_TRUE(controller->HasActiveAnimation()); |
655 EXPECT_EQ(initial_value, dummy.scroll_offset()); | 660 EXPECT_EQ(initial_value, dummy.scroll_offset()); |
656 | 661 |
657 controller_impl->Animate(kInitialTickTime); | 662 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
658 controller_impl->UpdateState(true, events.get()); | 663 controller_impl->UpdateState(true, events.get()); |
659 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 664 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
660 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 665 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
661 // Scroll offset animations should not generate property updates. | 666 // Scroll offset animations should not generate property updates. |
662 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 667 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
663 EXPECT_FALSE(event); | 668 EXPECT_FALSE(event); |
664 | 669 |
665 controller->NotifyAnimationStarted((*events)[0]); | 670 controller->NotifyAnimationStarted((*events)[0]); |
666 controller->Animate(kInitialTickTime + duration/2.0); | 671 controller->Animate(GetTimeTicks(kInitialTickTime + duration / 2.0)); |
667 controller->UpdateState(true, NULL); | 672 controller->UpdateState(true, NULL); |
668 EXPECT_TRUE(controller->HasActiveAnimation()); | 673 EXPECT_TRUE(controller->HasActiveAnimation()); |
669 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset()); | 674 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset()); |
670 | 675 |
671 controller_impl->Animate(kInitialTickTime + duration/2.0); | 676 controller_impl->Animate(GetTimeTicks(kInitialTickTime + duration / 2.0)); |
672 controller_impl->UpdateState(true, events.get()); | 677 controller_impl->UpdateState(true, events.get()); |
673 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | 678 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), |
674 dummy_impl.scroll_offset()); | 679 dummy_impl.scroll_offset()); |
675 event = GetMostRecentPropertyUpdateEvent(events.get()); | 680 event = GetMostRecentPropertyUpdateEvent(events.get()); |
676 EXPECT_FALSE(event); | 681 EXPECT_FALSE(event); |
677 | 682 |
678 controller_impl->Animate(kInitialTickTime + duration); | 683 controller_impl->Animate(GetTimeTicks(kInitialTickTime + duration)); |
679 controller_impl->UpdateState(true, events.get()); | 684 controller_impl->UpdateState(true, events.get()); |
680 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | 685 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); |
681 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 686 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
682 event = GetMostRecentPropertyUpdateEvent(events.get()); | 687 event = GetMostRecentPropertyUpdateEvent(events.get()); |
683 EXPECT_FALSE(event); | 688 EXPECT_FALSE(event); |
684 | 689 |
685 controller->Animate(kInitialTickTime + duration); | 690 controller->Animate(GetTimeTicks(kInitialTickTime + duration)); |
686 controller->UpdateState(true, NULL); | 691 controller->UpdateState(true, NULL); |
687 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); | 692 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); |
688 EXPECT_FALSE(controller->HasActiveAnimation()); | 693 EXPECT_FALSE(controller->HasActiveAnimation()); |
689 } | 694 } |
690 | 695 |
691 // Ensure that when the impl controller doesn't have a value provider, | 696 // Ensure that when the impl controller doesn't have a value provider, |
692 // the main-thread controller's value provider is used to obtain the intial | 697 // the main-thread controller's value provider is used to obtain the intial |
693 // scroll offset. | 698 // scroll offset. |
694 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { | 699 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { |
695 FakeLayerAnimationValueObserver dummy_impl; | 700 FakeLayerAnimationValueObserver dummy_impl; |
(...skipping 24 matching lines...) Expand all Loading... | |
720 dummy_provider.set_scroll_offset(initial_value); | 725 dummy_provider.set_scroll_offset(initial_value); |
721 controller->PushAnimationUpdatesTo(controller_impl.get()); | 726 controller->PushAnimationUpdatesTo(controller_impl.get()); |
722 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); | 727 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); |
723 double duration = controller_impl->GetAnimation( | 728 double duration = controller_impl->GetAnimation( |
724 Animation::ScrollOffset)->curve()->Duration(); | 729 Animation::ScrollOffset)->curve()->Duration(); |
725 | 730 |
726 EXPECT_EQ( | 731 EXPECT_EQ( |
727 duration, | 732 duration, |
728 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); | 733 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); |
729 | 734 |
730 controller->Animate(kInitialTickTime); | 735 controller->Animate(GetTimeTicks(kInitialTickTime)); |
731 controller->UpdateState(true, NULL); | 736 controller->UpdateState(true, NULL); |
732 EXPECT_TRUE(controller->HasActiveAnimation()); | 737 EXPECT_TRUE(controller->HasActiveAnimation()); |
733 EXPECT_EQ(initial_value, dummy.scroll_offset()); | 738 EXPECT_EQ(initial_value, dummy.scroll_offset()); |
734 | 739 |
735 controller_impl->Animate(kInitialTickTime); | 740 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
736 controller_impl->UpdateState(true, events.get()); | 741 controller_impl->UpdateState(true, events.get()); |
737 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 742 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
738 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 743 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
739 // Scroll offset animations should not generate property updates. | 744 // Scroll offset animations should not generate property updates. |
740 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 745 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
741 EXPECT_FALSE(event); | 746 EXPECT_FALSE(event); |
742 | 747 |
743 controller->NotifyAnimationStarted((*events)[0]); | 748 controller->NotifyAnimationStarted((*events)[0]); |
744 controller->Animate(kInitialTickTime + duration/2.0); | 749 controller->Animate(GetTimeTicks(kInitialTickTime + duration / 2.0)); |
745 controller->UpdateState(true, NULL); | 750 controller->UpdateState(true, NULL); |
746 EXPECT_TRUE(controller->HasActiveAnimation()); | 751 EXPECT_TRUE(controller->HasActiveAnimation()); |
747 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset()); | 752 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset()); |
748 | 753 |
749 controller_impl->Animate(kInitialTickTime + duration/2.0); | 754 controller_impl->Animate(GetTimeTicks(kInitialTickTime + duration / 2.0)); |
750 controller_impl->UpdateState(true, events.get()); | 755 controller_impl->UpdateState(true, events.get()); |
751 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), | 756 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), |
752 dummy_impl.scroll_offset()); | 757 dummy_impl.scroll_offset()); |
753 event = GetMostRecentPropertyUpdateEvent(events.get()); | 758 event = GetMostRecentPropertyUpdateEvent(events.get()); |
754 EXPECT_FALSE(event); | 759 EXPECT_FALSE(event); |
755 | 760 |
756 controller_impl->Animate(kInitialTickTime + duration); | 761 controller_impl->Animate(GetTimeTicks(kInitialTickTime + duration)); |
757 controller_impl->UpdateState(true, events.get()); | 762 controller_impl->UpdateState(true, events.get()); |
758 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | 763 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); |
759 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 764 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
760 event = GetMostRecentPropertyUpdateEvent(events.get()); | 765 event = GetMostRecentPropertyUpdateEvent(events.get()); |
761 EXPECT_FALSE(event); | 766 EXPECT_FALSE(event); |
762 | 767 |
763 controller->Animate(kInitialTickTime + duration); | 768 controller->Animate(GetTimeTicks(kInitialTickTime + duration)); |
764 controller->UpdateState(true, NULL); | 769 controller->UpdateState(true, NULL); |
765 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); | 770 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); |
766 EXPECT_FALSE(controller->HasActiveAnimation()); | 771 EXPECT_FALSE(controller->HasActiveAnimation()); |
767 } | 772 } |
768 | 773 |
769 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { | 774 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { |
770 FakeLayerAnimationValueObserver dummy_impl; | 775 FakeLayerAnimationValueObserver dummy_impl; |
771 scoped_refptr<LayerAnimationController> controller_impl( | 776 scoped_refptr<LayerAnimationController> controller_impl( |
772 LayerAnimationController::Create(0)); | 777 LayerAnimationController::Create(0)); |
773 controller_impl->AddValueObserver(&dummy_impl); | 778 controller_impl->AddValueObserver(&dummy_impl); |
774 scoped_ptr<AnimationEventsVector> events( | 779 scoped_ptr<AnimationEventsVector> events( |
775 make_scoped_ptr(new AnimationEventsVector)); | 780 make_scoped_ptr(new AnimationEventsVector)); |
776 | 781 |
777 gfx::Vector2dF initial_value(100.f, 300.f); | 782 gfx::Vector2dF initial_value(100.f, 300.f); |
778 gfx::Vector2dF target_value(300.f, 200.f); | 783 gfx::Vector2dF target_value(300.f, 200.f); |
779 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 784 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
780 ScrollOffsetAnimationCurve::Create( | 785 ScrollOffsetAnimationCurve::Create( |
781 target_value, | 786 target_value, |
782 EaseInOutTimingFunction::Create().Pass())); | 787 EaseInOutTimingFunction::Create().Pass())); |
783 curve->SetInitialValue(initial_value); | 788 curve->SetInitialValue(initial_value); |
784 double duration = curve->Duration(); | 789 double duration = curve->Duration(); |
785 | 790 |
786 scoped_ptr<Animation> animation(Animation::Create( | 791 scoped_ptr<Animation> animation(Animation::Create( |
787 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset)); | 792 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset)); |
788 animation->set_is_impl_only(true); | 793 animation->set_is_impl_only(true); |
789 controller_impl->AddAnimation(animation.Pass()); | 794 controller_impl->AddAnimation(animation.Pass()); |
790 | 795 |
791 controller_impl->Animate(kInitialTickTime); | 796 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
792 controller_impl->UpdateState(true, events.get()); | 797 controller_impl->UpdateState(true, events.get()); |
793 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 798 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
794 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 799 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
795 // Scroll offset animations should not generate property updates. | 800 // Scroll offset animations should not generate property updates. |
796 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 801 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
797 EXPECT_FALSE(event); | 802 EXPECT_FALSE(event); |
798 | 803 |
799 controller_impl->Animate(kInitialTickTime + duration/2.0); | 804 controller_impl->Animate(GetTimeTicks(kInitialTickTime + duration / 2.0)); |
800 controller_impl->UpdateState(true, events.get()); | 805 controller_impl->UpdateState(true, events.get()); |
801 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | 806 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), |
802 dummy_impl.scroll_offset()); | 807 dummy_impl.scroll_offset()); |
803 event = GetMostRecentPropertyUpdateEvent(events.get()); | 808 event = GetMostRecentPropertyUpdateEvent(events.get()); |
804 EXPECT_FALSE(event); | 809 EXPECT_FALSE(event); |
805 | 810 |
806 controller_impl->Animate(kInitialTickTime + duration); | 811 controller_impl->Animate(GetTimeTicks(kInitialTickTime + duration)); |
807 controller_impl->UpdateState(true, events.get()); | 812 controller_impl->UpdateState(true, events.get()); |
808 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | 813 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); |
809 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 814 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
810 event = GetMostRecentPropertyUpdateEvent(events.get()); | 815 event = GetMostRecentPropertyUpdateEvent(events.get()); |
811 EXPECT_FALSE(event); | 816 EXPECT_FALSE(event); |
812 } | 817 } |
813 | 818 |
814 class FakeAnimationDelegate : public AnimationDelegate { | 819 class FakeAnimationDelegate : public AnimationDelegate { |
815 public: | 820 public: |
816 FakeAnimationDelegate() | 821 FakeAnimationDelegate() |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 FakeAnimationDelegate delegate; | 860 FakeAnimationDelegate delegate; |
856 controller->set_layer_animation_delegate(&delegate); | 861 controller->set_layer_animation_delegate(&delegate); |
857 | 862 |
858 scoped_ptr<Animation> to_add(CreateAnimation( | 863 scoped_ptr<Animation> to_add(CreateAnimation( |
859 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 864 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
860 1, | 865 1, |
861 Animation::Opacity)); | 866 Animation::Opacity)); |
862 to_add->set_is_impl_only(true); | 867 to_add->set_is_impl_only(true); |
863 controller_impl->AddAnimation(to_add.Pass()); | 868 controller_impl->AddAnimation(to_add.Pass()); |
864 | 869 |
865 controller_impl->Animate(kInitialTickTime); | 870 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
866 controller_impl->UpdateState(true, events.get()); | 871 controller_impl->UpdateState(true, events.get()); |
867 | 872 |
868 // We should receive 2 events (a started notification and a property update). | 873 // We should receive 2 events (a started notification and a property update). |
869 EXPECT_EQ(2u, events->size()); | 874 EXPECT_EQ(2u, events->size()); |
870 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); | 875 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); |
871 EXPECT_TRUE((*events)[0].is_impl_only); | 876 EXPECT_TRUE((*events)[0].is_impl_only); |
872 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type); | 877 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type); |
873 EXPECT_TRUE((*events)[1].is_impl_only); | 878 EXPECT_TRUE((*events)[1].is_impl_only); |
874 | 879 |
875 // Passing on the start event to the main thread controller should cause the | 880 // Passing on the start event to the main thread controller should cause the |
876 // delegate to get notified. | 881 // delegate to get notified. |
877 EXPECT_FALSE(delegate.started()); | 882 EXPECT_FALSE(delegate.started()); |
878 controller->NotifyAnimationStarted((*events)[0]); | 883 controller->NotifyAnimationStarted((*events)[0]); |
879 EXPECT_TRUE(delegate.started()); | 884 EXPECT_TRUE(delegate.started()); |
880 | 885 |
881 events.reset(new AnimationEventsVector); | 886 events.reset(new AnimationEventsVector); |
882 controller_impl->Animate(kInitialTickTime + 1.0); | 887 controller_impl->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
883 controller_impl->UpdateState(true, events.get()); | 888 controller_impl->UpdateState(true, events.get()); |
884 | 889 |
885 // We should receive 2 events (a finished notification and a property update). | 890 // We should receive 2 events (a finished notification and a property update). |
886 EXPECT_EQ(2u, events->size()); | 891 EXPECT_EQ(2u, events->size()); |
887 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 892 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); |
888 EXPECT_TRUE((*events)[0].is_impl_only); | 893 EXPECT_TRUE((*events)[0].is_impl_only); |
889 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type); | 894 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type); |
890 EXPECT_TRUE((*events)[1].is_impl_only); | 895 EXPECT_TRUE((*events)[1].is_impl_only); |
891 | 896 |
892 // Passing on the finished event to the main thread controller should cause | 897 // Passing on the finished event to the main thread controller should cause |
(...skipping 16 matching lines...) Expand all Loading... | |
909 | 914 |
910 scoped_ptr<Animation> to_add(CreateAnimation( | 915 scoped_ptr<Animation> to_add(CreateAnimation( |
911 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 916 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
912 1, | 917 1, |
913 Animation::Opacity)); | 918 Animation::Opacity)); |
914 to_add->set_needs_synchronized_start_time(true); | 919 to_add->set_needs_synchronized_start_time(true); |
915 | 920 |
916 // We should pause at the first keyframe indefinitely waiting for that | 921 // We should pause at the first keyframe indefinitely waiting for that |
917 // animation to start. | 922 // animation to start. |
918 controller->AddAnimation(to_add.Pass()); | 923 controller->AddAnimation(to_add.Pass()); |
919 controller->Animate(kInitialTickTime); | 924 controller->Animate(GetTimeTicks(kInitialTickTime)); |
920 controller->UpdateState(true, events.get()); | 925 controller->UpdateState(true, events.get()); |
921 EXPECT_TRUE(controller->HasActiveAnimation()); | 926 EXPECT_TRUE(controller->HasActiveAnimation()); |
922 EXPECT_EQ(0.f, dummy.opacity()); | 927 EXPECT_EQ(0.f, dummy.opacity()); |
923 controller->Animate(kInitialTickTime + 1.0); | 928 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
924 controller->UpdateState(true, events.get()); | 929 controller->UpdateState(true, events.get()); |
925 EXPECT_TRUE(controller->HasActiveAnimation()); | 930 EXPECT_TRUE(controller->HasActiveAnimation()); |
926 EXPECT_EQ(0.f, dummy.opacity()); | 931 EXPECT_EQ(0.f, dummy.opacity()); |
927 controller->Animate(kInitialTickTime + 2.0); | 932 controller->Animate(GetTimeTicks(kInitialTickTime + 2.0)); |
928 controller->UpdateState(true, events.get()); | 933 controller->UpdateState(true, events.get()); |
929 EXPECT_TRUE(controller->HasActiveAnimation()); | 934 EXPECT_TRUE(controller->HasActiveAnimation()); |
930 EXPECT_EQ(0.f, dummy.opacity()); | 935 EXPECT_EQ(0.f, dummy.opacity()); |
931 | 936 |
932 // Send the synchronized start time. | 937 // Send the synchronized start time. |
933 controller->NotifyAnimationStarted(AnimationEvent( | 938 controller->NotifyAnimationStarted(AnimationEvent( |
934 AnimationEvent::Started, 0, 1, Animation::Opacity, kInitialTickTime + 2)); | 939 AnimationEvent::Started, 0, 1, Animation::Opacity, kInitialTickTime + 2)); |
935 controller->Animate(kInitialTickTime + 5.0); | 940 controller->Animate(GetTimeTicks(kInitialTickTime + 5.0)); |
936 controller->UpdateState(true, events.get()); | 941 controller->UpdateState(true, events.get()); |
937 EXPECT_EQ(1.f, dummy.opacity()); | 942 EXPECT_EQ(1.f, dummy.opacity()); |
938 EXPECT_FALSE(controller->HasActiveAnimation()); | 943 EXPECT_FALSE(controller->HasActiveAnimation()); |
939 } | 944 } |
940 | 945 |
941 // Tests that two queued animations affecting the same property run in sequence. | 946 // Tests that two queued animations affecting the same property run in sequence. |
942 TEST(LayerAnimationControllerTest, TrivialQueuing) { | 947 TEST(LayerAnimationControllerTest, TrivialQueuing) { |
943 scoped_ptr<AnimationEventsVector> events( | 948 scoped_ptr<AnimationEventsVector> events( |
944 make_scoped_ptr(new AnimationEventsVector)); | 949 make_scoped_ptr(new AnimationEventsVector)); |
945 FakeLayerAnimationValueObserver dummy; | 950 FakeLayerAnimationValueObserver dummy; |
946 scoped_refptr<LayerAnimationController> controller( | 951 scoped_refptr<LayerAnimationController> controller( |
947 LayerAnimationController::Create(0)); | 952 LayerAnimationController::Create(0)); |
948 controller->AddValueObserver(&dummy); | 953 controller->AddValueObserver(&dummy); |
949 | 954 |
950 controller->AddAnimation(CreateAnimation( | 955 controller->AddAnimation(CreateAnimation( |
951 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 956 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
952 1, | 957 1, |
953 Animation::Opacity)); | 958 Animation::Opacity)); |
954 controller->AddAnimation(CreateAnimation( | 959 controller->AddAnimation(CreateAnimation( |
955 scoped_ptr<AnimationCurve>( | 960 scoped_ptr<AnimationCurve>( |
956 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), | 961 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), |
957 2, | 962 2, |
958 Animation::Opacity)); | 963 Animation::Opacity)); |
959 | 964 |
960 controller->Animate(kInitialTickTime); | 965 controller->Animate(GetTimeTicks(kInitialTickTime)); |
961 controller->UpdateState(true, events.get()); | 966 controller->UpdateState(true, events.get()); |
962 EXPECT_TRUE(controller->HasActiveAnimation()); | 967 EXPECT_TRUE(controller->HasActiveAnimation()); |
963 EXPECT_EQ(0.f, dummy.opacity()); | 968 EXPECT_EQ(0.f, dummy.opacity()); |
964 controller->Animate(kInitialTickTime + 1.0); | 969 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
965 controller->UpdateState(true, events.get()); | 970 controller->UpdateState(true, events.get()); |
966 EXPECT_TRUE(controller->HasActiveAnimation()); | 971 EXPECT_TRUE(controller->HasActiveAnimation()); |
967 EXPECT_EQ(1.f, dummy.opacity()); | 972 EXPECT_EQ(1.f, dummy.opacity()); |
968 controller->Animate(kInitialTickTime + 2.0); | 973 controller->Animate(GetTimeTicks(kInitialTickTime + 2.0)); |
969 controller->UpdateState(true, events.get()); | 974 controller->UpdateState(true, events.get()); |
970 EXPECT_EQ(0.5f, dummy.opacity()); | 975 EXPECT_EQ(0.5f, dummy.opacity()); |
971 EXPECT_FALSE(controller->HasActiveAnimation()); | 976 EXPECT_FALSE(controller->HasActiveAnimation()); |
972 } | 977 } |
973 | 978 |
974 // Tests interrupting a transition with another transition. | 979 // Tests interrupting a transition with another transition. |
975 TEST(LayerAnimationControllerTest, Interrupt) { | 980 TEST(LayerAnimationControllerTest, Interrupt) { |
976 scoped_ptr<AnimationEventsVector> events( | 981 scoped_ptr<AnimationEventsVector> events( |
977 make_scoped_ptr(new AnimationEventsVector)); | 982 make_scoped_ptr(new AnimationEventsVector)); |
978 FakeLayerAnimationValueObserver dummy; | 983 FakeLayerAnimationValueObserver dummy; |
979 scoped_refptr<LayerAnimationController> controller( | 984 scoped_refptr<LayerAnimationController> controller( |
980 LayerAnimationController::Create(0)); | 985 LayerAnimationController::Create(0)); |
981 controller->AddValueObserver(&dummy); | 986 controller->AddValueObserver(&dummy); |
982 controller->AddAnimation(CreateAnimation( | 987 controller->AddAnimation(CreateAnimation( |
983 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 988 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
984 1, | 989 1, |
985 Animation::Opacity)); | 990 Animation::Opacity)); |
986 controller->Animate(kInitialTickTime); | 991 controller->Animate(GetTimeTicks(kInitialTickTime)); |
987 controller->UpdateState(true, events.get()); | 992 controller->UpdateState(true, events.get()); |
988 EXPECT_TRUE(controller->HasActiveAnimation()); | 993 EXPECT_TRUE(controller->HasActiveAnimation()); |
989 EXPECT_EQ(0.f, dummy.opacity()); | 994 EXPECT_EQ(0.f, dummy.opacity()); |
990 | 995 |
991 scoped_ptr<Animation> to_add(CreateAnimation( | 996 scoped_ptr<Animation> to_add(CreateAnimation( |
992 scoped_ptr<AnimationCurve>( | 997 scoped_ptr<AnimationCurve>( |
993 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), | 998 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), |
994 2, | 999 2, |
995 Animation::Opacity)); | 1000 Animation::Opacity)); |
996 controller->AbortAnimations(Animation::Opacity); | 1001 controller->AbortAnimations(Animation::Opacity); |
997 controller->AddAnimation(to_add.Pass()); | 1002 controller->AddAnimation(to_add.Pass()); |
998 | 1003 |
999 // Since the previous animation was aborted, the new animation should start | 1004 // Since the previous animation was aborted, the new animation should start |
1000 // right in this call to animate. | 1005 // right in this call to animate. |
1001 controller->Animate(kInitialTickTime + 0.5); | 1006 controller->Animate(GetTimeTicks(kInitialTickTime + 0.5)); |
1002 controller->UpdateState(true, events.get()); | 1007 controller->UpdateState(true, events.get()); |
1003 EXPECT_TRUE(controller->HasActiveAnimation()); | 1008 EXPECT_TRUE(controller->HasActiveAnimation()); |
1004 EXPECT_EQ(1.f, dummy.opacity()); | 1009 EXPECT_EQ(1.f, dummy.opacity()); |
1005 controller->Animate(kInitialTickTime + 1.5); | 1010 controller->Animate(GetTimeTicks(kInitialTickTime + 1.5)); |
1006 controller->UpdateState(true, events.get()); | 1011 controller->UpdateState(true, events.get()); |
1007 EXPECT_EQ(0.5f, dummy.opacity()); | 1012 EXPECT_EQ(0.5f, dummy.opacity()); |
1008 EXPECT_FALSE(controller->HasActiveAnimation()); | 1013 EXPECT_FALSE(controller->HasActiveAnimation()); |
1009 } | 1014 } |
1010 | 1015 |
1011 // Tests scheduling two animations to run together when only one property is | 1016 // Tests scheduling two animations to run together when only one property is |
1012 // free. | 1017 // free. |
1013 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { | 1018 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { |
1014 scoped_ptr<AnimationEventsVector> events( | 1019 scoped_ptr<AnimationEventsVector> events( |
1015 make_scoped_ptr(new AnimationEventsVector)); | 1020 make_scoped_ptr(new AnimationEventsVector)); |
1016 FakeLayerAnimationValueObserver dummy; | 1021 FakeLayerAnimationValueObserver dummy; |
1017 scoped_refptr<LayerAnimationController> controller( | 1022 scoped_refptr<LayerAnimationController> controller( |
1018 LayerAnimationController::Create(0)); | 1023 LayerAnimationController::Create(0)); |
1019 controller->AddValueObserver(&dummy); | 1024 controller->AddValueObserver(&dummy); |
1020 | 1025 |
1021 controller->AddAnimation(CreateAnimation( | 1026 controller->AddAnimation(CreateAnimation( |
1022 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), | 1027 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), |
1023 1, | 1028 1, |
1024 Animation::Transform)); | 1029 Animation::Transform)); |
1025 controller->AddAnimation(CreateAnimation( | 1030 controller->AddAnimation(CreateAnimation( |
1026 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), | 1031 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), |
1027 2, | 1032 2, |
1028 Animation::Transform)); | 1033 Animation::Transform)); |
1029 controller->AddAnimation(CreateAnimation( | 1034 controller->AddAnimation(CreateAnimation( |
1030 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1035 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1031 2, | 1036 2, |
1032 Animation::Opacity)); | 1037 Animation::Opacity)); |
1033 | 1038 |
1034 controller->Animate(kInitialTickTime); | 1039 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1035 controller->UpdateState(true, events.get()); | 1040 controller->UpdateState(true, events.get()); |
1036 EXPECT_EQ(0.f, dummy.opacity()); | 1041 EXPECT_EQ(0.f, dummy.opacity()); |
1037 EXPECT_TRUE(controller->HasActiveAnimation()); | 1042 EXPECT_TRUE(controller->HasActiveAnimation()); |
1038 controller->Animate(kInitialTickTime + 1.0); | 1043 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
1039 controller->UpdateState(true, events.get()); | 1044 controller->UpdateState(true, events.get()); |
1040 // Should not have started the float transition yet. | 1045 // Should not have started the float transition yet. |
1041 EXPECT_TRUE(controller->HasActiveAnimation()); | 1046 EXPECT_TRUE(controller->HasActiveAnimation()); |
1042 EXPECT_EQ(0.f, dummy.opacity()); | 1047 EXPECT_EQ(0.f, dummy.opacity()); |
1043 // The float animation should have started at time 1 and should be done. | 1048 // The float animation should have started at time 1 and should be done. |
1044 controller->Animate(kInitialTickTime + 2.0); | 1049 controller->Animate(GetTimeTicks(kInitialTickTime + 2.0)); |
1045 controller->UpdateState(true, events.get()); | 1050 controller->UpdateState(true, events.get()); |
1046 EXPECT_EQ(1.f, dummy.opacity()); | 1051 EXPECT_EQ(1.f, dummy.opacity()); |
1047 EXPECT_FALSE(controller->HasActiveAnimation()); | 1052 EXPECT_FALSE(controller->HasActiveAnimation()); |
1048 } | 1053 } |
1049 | 1054 |
1050 // Tests scheduling two animations to run together with different lengths and | 1055 // Tests scheduling two animations to run together with different lengths and |
1051 // another animation queued to start when the shorter animation finishes (should | 1056 // another animation queued to start when the shorter animation finishes (should |
1052 // wait for both to finish). | 1057 // wait for both to finish). |
1053 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { | 1058 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { |
1054 scoped_ptr<AnimationEventsVector> events( | 1059 scoped_ptr<AnimationEventsVector> events( |
(...skipping 11 matching lines...) Expand all Loading... | |
1066 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1071 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1067 1, | 1072 1, |
1068 Animation::Opacity)); | 1073 Animation::Opacity)); |
1069 controller->AddAnimation(CreateAnimation( | 1074 controller->AddAnimation(CreateAnimation( |
1070 scoped_ptr<AnimationCurve>( | 1075 scoped_ptr<AnimationCurve>( |
1071 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), | 1076 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), |
1072 2, | 1077 2, |
1073 Animation::Opacity)); | 1078 Animation::Opacity)); |
1074 | 1079 |
1075 // Animations with id 1 should both start now. | 1080 // Animations with id 1 should both start now. |
1076 controller->Animate(kInitialTickTime); | 1081 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1077 controller->UpdateState(true, events.get()); | 1082 controller->UpdateState(true, events.get()); |
1078 EXPECT_TRUE(controller->HasActiveAnimation()); | 1083 EXPECT_TRUE(controller->HasActiveAnimation()); |
1079 EXPECT_EQ(0.f, dummy.opacity()); | 1084 EXPECT_EQ(0.f, dummy.opacity()); |
1080 // The opacity animation should have finished at time 1, but the group | 1085 // The opacity animation should have finished at time 1, but the group |
1081 // of animations with id 1 don't finish until time 2 because of the length | 1086 // of animations with id 1 don't finish until time 2 because of the length |
1082 // of the transform animation. | 1087 // of the transform animation. |
1083 controller->Animate(kInitialTickTime + 2.0); | 1088 controller->Animate(GetTimeTicks(kInitialTickTime + 2.0)); |
1084 controller->UpdateState(true, events.get()); | 1089 controller->UpdateState(true, events.get()); |
1085 // Should not have started the float transition yet. | 1090 // Should not have started the float transition yet. |
1086 EXPECT_TRUE(controller->HasActiveAnimation()); | 1091 EXPECT_TRUE(controller->HasActiveAnimation()); |
1087 EXPECT_EQ(1.f, dummy.opacity()); | 1092 EXPECT_EQ(1.f, dummy.opacity()); |
1088 | 1093 |
1089 // The second opacity animation should start at time 2 and should be done by | 1094 // The second opacity animation should start at time 2 and should be done by |
1090 // time 3. | 1095 // time 3. |
1091 controller->Animate(kInitialTickTime + 3.0); | 1096 controller->Animate(GetTimeTicks(kInitialTickTime + 3.0)); |
1092 controller->UpdateState(true, events.get()); | 1097 controller->UpdateState(true, events.get()); |
1093 EXPECT_EQ(0.5f, dummy.opacity()); | 1098 EXPECT_EQ(0.5f, dummy.opacity()); |
1094 EXPECT_FALSE(controller->HasActiveAnimation()); | 1099 EXPECT_FALSE(controller->HasActiveAnimation()); |
1095 } | 1100 } |
1096 | 1101 |
1097 // Test that a looping animation loops and for the correct number of iterations. | 1102 // Test that a looping animation loops and for the correct number of iterations. |
1098 TEST(LayerAnimationControllerTest, TrivialLooping) { | 1103 TEST(LayerAnimationControllerTest, TrivialLooping) { |
1099 scoped_ptr<AnimationEventsVector> events( | 1104 scoped_ptr<AnimationEventsVector> events( |
1100 make_scoped_ptr(new AnimationEventsVector)); | 1105 make_scoped_ptr(new AnimationEventsVector)); |
1101 FakeLayerAnimationValueObserver dummy; | 1106 FakeLayerAnimationValueObserver dummy; |
1102 scoped_refptr<LayerAnimationController> controller( | 1107 scoped_refptr<LayerAnimationController> controller( |
1103 LayerAnimationController::Create(0)); | 1108 LayerAnimationController::Create(0)); |
1104 controller->AddValueObserver(&dummy); | 1109 controller->AddValueObserver(&dummy); |
1105 | 1110 |
1106 scoped_ptr<Animation> to_add(CreateAnimation( | 1111 scoped_ptr<Animation> to_add(CreateAnimation( |
1107 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1112 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1108 1, | 1113 1, |
1109 Animation::Opacity)); | 1114 Animation::Opacity)); |
1110 to_add->set_iterations(3); | 1115 to_add->set_iterations(3); |
1111 controller->AddAnimation(to_add.Pass()); | 1116 controller->AddAnimation(to_add.Pass()); |
1112 | 1117 |
1113 controller->Animate(kInitialTickTime); | 1118 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1114 controller->UpdateState(true, events.get()); | 1119 controller->UpdateState(true, events.get()); |
1115 EXPECT_TRUE(controller->HasActiveAnimation()); | 1120 EXPECT_TRUE(controller->HasActiveAnimation()); |
1116 EXPECT_EQ(0.f, dummy.opacity()); | 1121 EXPECT_EQ(0.f, dummy.opacity()); |
1117 controller->Animate(kInitialTickTime + 1.25); | 1122 controller->Animate(GetTimeTicks(kInitialTickTime + 1.25)); |
1118 controller->UpdateState(true, events.get()); | 1123 controller->UpdateState(true, events.get()); |
1119 EXPECT_TRUE(controller->HasActiveAnimation()); | 1124 EXPECT_TRUE(controller->HasActiveAnimation()); |
1120 EXPECT_EQ(0.25f, dummy.opacity()); | 1125 EXPECT_EQ(0.25f, dummy.opacity()); |
1121 controller->Animate(kInitialTickTime + 1.75); | 1126 controller->Animate(GetTimeTicks(kInitialTickTime + 1.75)); |
1122 controller->UpdateState(true, events.get()); | 1127 controller->UpdateState(true, events.get()); |
1123 EXPECT_TRUE(controller->HasActiveAnimation()); | 1128 EXPECT_TRUE(controller->HasActiveAnimation()); |
1124 EXPECT_EQ(0.75f, dummy.opacity()); | 1129 EXPECT_EQ(0.75f, dummy.opacity()); |
1125 controller->Animate(kInitialTickTime + 2.25); | 1130 controller->Animate(GetTimeTicks(kInitialTickTime + 2.25)); |
1126 controller->UpdateState(true, events.get()); | 1131 controller->UpdateState(true, events.get()); |
1127 EXPECT_TRUE(controller->HasActiveAnimation()); | 1132 EXPECT_TRUE(controller->HasActiveAnimation()); |
1128 EXPECT_EQ(0.25f, dummy.opacity()); | 1133 EXPECT_EQ(0.25f, dummy.opacity()); |
1129 controller->Animate(kInitialTickTime + 2.75); | 1134 controller->Animate(GetTimeTicks(kInitialTickTime + 2.75)); |
1130 controller->UpdateState(true, events.get()); | 1135 controller->UpdateState(true, events.get()); |
1131 EXPECT_TRUE(controller->HasActiveAnimation()); | 1136 EXPECT_TRUE(controller->HasActiveAnimation()); |
1132 EXPECT_EQ(0.75f, dummy.opacity()); | 1137 EXPECT_EQ(0.75f, dummy.opacity()); |
1133 controller->Animate(kInitialTickTime + 3.0); | 1138 controller->Animate(GetTimeTicks(kInitialTickTime + 3.0)); |
1134 controller->UpdateState(true, events.get()); | 1139 controller->UpdateState(true, events.get()); |
1135 EXPECT_FALSE(controller->HasActiveAnimation()); | 1140 EXPECT_FALSE(controller->HasActiveAnimation()); |
1136 EXPECT_EQ(1.f, dummy.opacity()); | 1141 EXPECT_EQ(1.f, dummy.opacity()); |
1137 | 1142 |
1138 // Just be extra sure. | 1143 // Just be extra sure. |
1139 controller->Animate(kInitialTickTime + 4.0); | 1144 controller->Animate(GetTimeTicks(kInitialTickTime + 4.0)); |
1140 controller->UpdateState(true, events.get()); | 1145 controller->UpdateState(true, events.get()); |
1141 EXPECT_EQ(1.f, dummy.opacity()); | 1146 EXPECT_EQ(1.f, dummy.opacity()); |
1142 } | 1147 } |
1143 | 1148 |
1144 // Test that an infinitely looping animation does indeed go until aborted. | 1149 // Test that an infinitely looping animation does indeed go until aborted. |
1145 TEST(LayerAnimationControllerTest, InfiniteLooping) { | 1150 TEST(LayerAnimationControllerTest, InfiniteLooping) { |
1146 scoped_ptr<AnimationEventsVector> events( | 1151 scoped_ptr<AnimationEventsVector> events( |
1147 make_scoped_ptr(new AnimationEventsVector)); | 1152 make_scoped_ptr(new AnimationEventsVector)); |
1148 FakeLayerAnimationValueObserver dummy; | 1153 FakeLayerAnimationValueObserver dummy; |
1149 scoped_refptr<LayerAnimationController> controller( | 1154 scoped_refptr<LayerAnimationController> controller( |
1150 LayerAnimationController::Create(0)); | 1155 LayerAnimationController::Create(0)); |
1151 controller->AddValueObserver(&dummy); | 1156 controller->AddValueObserver(&dummy); |
1152 | 1157 |
1153 const int id = 1; | 1158 const int id = 1; |
1154 scoped_ptr<Animation> to_add(CreateAnimation( | 1159 scoped_ptr<Animation> to_add(CreateAnimation( |
1155 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1160 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1156 id, | 1161 id, |
1157 Animation::Opacity)); | 1162 Animation::Opacity)); |
1158 to_add->set_iterations(-1); | 1163 to_add->set_iterations(-1); |
1159 controller->AddAnimation(to_add.Pass()); | 1164 controller->AddAnimation(to_add.Pass()); |
1160 | 1165 |
1161 controller->Animate(kInitialTickTime); | 1166 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1162 controller->UpdateState(true, events.get()); | 1167 controller->UpdateState(true, events.get()); |
1163 EXPECT_TRUE(controller->HasActiveAnimation()); | 1168 EXPECT_TRUE(controller->HasActiveAnimation()); |
1164 EXPECT_EQ(0.f, dummy.opacity()); | 1169 EXPECT_EQ(0.f, dummy.opacity()); |
1165 controller->Animate(kInitialTickTime + 1.25); | 1170 controller->Animate(GetTimeTicks(kInitialTickTime + 1.25)); |
1166 controller->UpdateState(true, events.get()); | 1171 controller->UpdateState(true, events.get()); |
1167 EXPECT_TRUE(controller->HasActiveAnimation()); | 1172 EXPECT_TRUE(controller->HasActiveAnimation()); |
1168 EXPECT_EQ(0.25f, dummy.opacity()); | 1173 EXPECT_EQ(0.25f, dummy.opacity()); |
1169 controller->Animate(kInitialTickTime + 1.75); | 1174 controller->Animate(GetTimeTicks(kInitialTickTime + 1.75)); |
1170 controller->UpdateState(true, events.get()); | 1175 controller->UpdateState(true, events.get()); |
1171 EXPECT_TRUE(controller->HasActiveAnimation()); | 1176 EXPECT_TRUE(controller->HasActiveAnimation()); |
1172 EXPECT_EQ(0.75f, dummy.opacity()); | 1177 EXPECT_EQ(0.75f, dummy.opacity()); |
1173 | 1178 |
1174 controller->Animate(kInitialTickTime + 1073741824.25); | 1179 controller->Animate(GetTimeTicks(kInitialTickTime + 1073741824.25)); |
1175 controller->UpdateState(true, events.get()); | 1180 controller->UpdateState(true, events.get()); |
1176 EXPECT_TRUE(controller->HasActiveAnimation()); | 1181 EXPECT_TRUE(controller->HasActiveAnimation()); |
1177 EXPECT_EQ(0.25f, dummy.opacity()); | 1182 EXPECT_EQ(0.25f, dummy.opacity()); |
1178 controller->Animate(kInitialTickTime + 1073741824.75); | 1183 controller->Animate(GetTimeTicks(kInitialTickTime + 1073741824.75)); |
1179 controller->UpdateState(true, events.get()); | 1184 controller->UpdateState(true, events.get()); |
1180 EXPECT_TRUE(controller->HasActiveAnimation()); | 1185 EXPECT_TRUE(controller->HasActiveAnimation()); |
1181 EXPECT_EQ(0.75f, dummy.opacity()); | 1186 EXPECT_EQ(0.75f, dummy.opacity()); |
1182 | 1187 |
1183 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); | 1188 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
1184 controller->GetAnimation(id, Animation::Opacity)->SetRunState( | 1189 controller->GetAnimation(id, Animation::Opacity)->SetRunState( |
1185 Animation::Aborted, kInitialTickTime + 0.75); | 1190 Animation::Aborted, kInitialTickTime + 0.75); |
1186 EXPECT_FALSE(controller->HasActiveAnimation()); | 1191 EXPECT_FALSE(controller->HasActiveAnimation()); |
1187 EXPECT_EQ(0.75f, dummy.opacity()); | 1192 EXPECT_EQ(0.75f, dummy.opacity()); |
1188 } | 1193 } |
1189 | 1194 |
1190 // Test that pausing and resuming work as expected. | 1195 // Test that pausing and resuming work as expected. |
1191 TEST(LayerAnimationControllerTest, PauseResume) { | 1196 TEST(LayerAnimationControllerTest, PauseResume) { |
1192 scoped_ptr<AnimationEventsVector> events( | 1197 scoped_ptr<AnimationEventsVector> events( |
1193 make_scoped_ptr(new AnimationEventsVector)); | 1198 make_scoped_ptr(new AnimationEventsVector)); |
1194 FakeLayerAnimationValueObserver dummy; | 1199 FakeLayerAnimationValueObserver dummy; |
1195 scoped_refptr<LayerAnimationController> controller( | 1200 scoped_refptr<LayerAnimationController> controller( |
1196 LayerAnimationController::Create(0)); | 1201 LayerAnimationController::Create(0)); |
1197 controller->AddValueObserver(&dummy); | 1202 controller->AddValueObserver(&dummy); |
1198 | 1203 |
1199 const int id = 1; | 1204 const int id = 1; |
1200 controller->AddAnimation(CreateAnimation( | 1205 controller->AddAnimation(CreateAnimation( |
1201 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1206 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1202 id, | 1207 id, |
1203 Animation::Opacity)); | 1208 Animation::Opacity)); |
1204 | 1209 |
1205 controller->Animate(kInitialTickTime); | 1210 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1206 controller->UpdateState(true, events.get()); | 1211 controller->UpdateState(true, events.get()); |
1207 EXPECT_TRUE(controller->HasActiveAnimation()); | 1212 EXPECT_TRUE(controller->HasActiveAnimation()); |
1208 EXPECT_EQ(0.f, dummy.opacity()); | 1213 EXPECT_EQ(0.f, dummy.opacity()); |
1209 controller->Animate(kInitialTickTime + 0.5); | 1214 controller->Animate(GetTimeTicks(kInitialTickTime + 0.5)); |
1210 controller->UpdateState(true, events.get()); | 1215 controller->UpdateState(true, events.get()); |
1211 EXPECT_TRUE(controller->HasActiveAnimation()); | 1216 EXPECT_TRUE(controller->HasActiveAnimation()); |
1212 EXPECT_EQ(0.5f, dummy.opacity()); | 1217 EXPECT_EQ(0.5f, dummy.opacity()); |
1213 | 1218 |
1214 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); | 1219 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
1215 controller->GetAnimation(id, Animation::Opacity)->SetRunState( | 1220 controller->GetAnimation(id, Animation::Opacity)->SetRunState( |
1216 Animation::Paused, kInitialTickTime + 0.5); | 1221 Animation::Paused, kInitialTickTime + 0.5); |
1217 | 1222 |
1218 controller->Animate(kInitialTickTime + 1024.0); | 1223 controller->Animate(GetTimeTicks(kInitialTickTime + 1024.0)); |
1219 controller->UpdateState(true, events.get()); | 1224 controller->UpdateState(true, events.get()); |
1220 EXPECT_TRUE(controller->HasActiveAnimation()); | 1225 EXPECT_TRUE(controller->HasActiveAnimation()); |
1221 EXPECT_EQ(0.5f, dummy.opacity()); | 1226 EXPECT_EQ(0.5f, dummy.opacity()); |
1222 | 1227 |
1223 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); | 1228 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
1224 controller->GetAnimation(id, Animation::Opacity)->SetRunState( | 1229 controller->GetAnimation(id, Animation::Opacity)->SetRunState( |
1225 Animation::Running, kInitialTickTime + 1024); | 1230 Animation::Running, kInitialTickTime + 1024); |
1226 | 1231 |
1227 controller->Animate(kInitialTickTime + 1024.25); | 1232 controller->Animate(GetTimeTicks(kInitialTickTime + 1024.25)); |
1228 controller->UpdateState(true, events.get()); | 1233 controller->UpdateState(true, events.get()); |
1229 EXPECT_TRUE(controller->HasActiveAnimation()); | 1234 EXPECT_TRUE(controller->HasActiveAnimation()); |
1230 EXPECT_EQ(0.75f, dummy.opacity()); | 1235 EXPECT_EQ(0.75f, dummy.opacity()); |
1231 controller->Animate(kInitialTickTime + 1024.5); | 1236 controller->Animate(GetTimeTicks(kInitialTickTime + 1024.5)); |
1232 controller->UpdateState(true, events.get()); | 1237 controller->UpdateState(true, events.get()); |
1233 EXPECT_FALSE(controller->HasActiveAnimation()); | 1238 EXPECT_FALSE(controller->HasActiveAnimation()); |
1234 EXPECT_EQ(1.f, dummy.opacity()); | 1239 EXPECT_EQ(1.f, dummy.opacity()); |
1235 } | 1240 } |
1236 | 1241 |
1237 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { | 1242 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { |
1238 scoped_ptr<AnimationEventsVector> events( | 1243 scoped_ptr<AnimationEventsVector> events( |
1239 make_scoped_ptr(new AnimationEventsVector)); | 1244 make_scoped_ptr(new AnimationEventsVector)); |
1240 FakeLayerAnimationValueObserver dummy; | 1245 FakeLayerAnimationValueObserver dummy; |
1241 scoped_refptr<LayerAnimationController> controller( | 1246 scoped_refptr<LayerAnimationController> controller( |
1242 LayerAnimationController::Create(0)); | 1247 LayerAnimationController::Create(0)); |
1243 controller->AddValueObserver(&dummy); | 1248 controller->AddValueObserver(&dummy); |
1244 | 1249 |
1245 const int id = 1; | 1250 const int id = 1; |
1246 controller->AddAnimation(CreateAnimation( | 1251 controller->AddAnimation(CreateAnimation( |
1247 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), | 1252 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), |
1248 id, | 1253 id, |
1249 Animation::Transform)); | 1254 Animation::Transform)); |
1250 controller->AddAnimation(CreateAnimation( | 1255 controller->AddAnimation(CreateAnimation( |
1251 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), | 1256 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), |
1252 id, | 1257 id, |
1253 Animation::Opacity)); | 1258 Animation::Opacity)); |
1254 controller->AddAnimation(CreateAnimation( | 1259 controller->AddAnimation(CreateAnimation( |
1255 scoped_ptr<AnimationCurve>( | 1260 scoped_ptr<AnimationCurve>( |
1256 new FakeFloatTransition(1.0, 1.f, 0.75f)).Pass(), | 1261 new FakeFloatTransition(1.0, 1.f, 0.75f)).Pass(), |
1257 2, | 1262 2, |
1258 Animation::Opacity)); | 1263 Animation::Opacity)); |
1259 | 1264 |
1260 controller->Animate(kInitialTickTime); | 1265 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1261 controller->UpdateState(true, events.get()); | 1266 controller->UpdateState(true, events.get()); |
1262 EXPECT_TRUE(controller->HasActiveAnimation()); | 1267 EXPECT_TRUE(controller->HasActiveAnimation()); |
1263 EXPECT_EQ(0.f, dummy.opacity()); | 1268 EXPECT_EQ(0.f, dummy.opacity()); |
1264 controller->Animate(kInitialTickTime + 1.0); | 1269 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
1265 controller->UpdateState(true, events.get()); | 1270 controller->UpdateState(true, events.get()); |
1266 EXPECT_TRUE(controller->HasActiveAnimation()); | 1271 EXPECT_TRUE(controller->HasActiveAnimation()); |
1267 EXPECT_EQ(0.5f, dummy.opacity()); | 1272 EXPECT_EQ(0.5f, dummy.opacity()); |
1268 | 1273 |
1269 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); | 1274 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
1270 controller->GetAnimation(id, Animation::Opacity)->SetRunState( | 1275 controller->GetAnimation(id, Animation::Opacity)->SetRunState( |
1271 Animation::Aborted, kInitialTickTime + 1.0); | 1276 Animation::Aborted, kInitialTickTime + 1.0); |
1272 controller->Animate(kInitialTickTime + 1.0); | 1277 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
1273 controller->UpdateState(true, events.get()); | 1278 controller->UpdateState(true, events.get()); |
1274 EXPECT_TRUE(controller->HasActiveAnimation()); | 1279 EXPECT_TRUE(controller->HasActiveAnimation()); |
1275 EXPECT_EQ(1.f, dummy.opacity()); | 1280 EXPECT_EQ(1.f, dummy.opacity()); |
1276 controller->Animate(kInitialTickTime + 2.0); | 1281 controller->Animate(GetTimeTicks(kInitialTickTime + 2.0)); |
1277 controller->UpdateState(true, events.get()); | 1282 controller->UpdateState(true, events.get()); |
1278 EXPECT_TRUE(!controller->HasActiveAnimation()); | 1283 EXPECT_TRUE(!controller->HasActiveAnimation()); |
1279 EXPECT_EQ(0.75f, dummy.opacity()); | 1284 EXPECT_EQ(0.75f, dummy.opacity()); |
1280 } | 1285 } |
1281 | 1286 |
1282 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { | 1287 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { |
1283 FakeLayerAnimationValueObserver dummy_impl; | 1288 FakeLayerAnimationValueObserver dummy_impl; |
1284 scoped_refptr<LayerAnimationController> controller_impl( | 1289 scoped_refptr<LayerAnimationController> controller_impl( |
1285 LayerAnimationController::Create(0)); | 1290 LayerAnimationController::Create(0)); |
1286 controller_impl->AddValueObserver(&dummy_impl); | 1291 controller_impl->AddValueObserver(&dummy_impl); |
1287 scoped_ptr<AnimationEventsVector> events( | 1292 scoped_ptr<AnimationEventsVector> events( |
1288 make_scoped_ptr(new AnimationEventsVector)); | 1293 make_scoped_ptr(new AnimationEventsVector)); |
1289 FakeLayerAnimationValueObserver dummy; | 1294 FakeLayerAnimationValueObserver dummy; |
1290 scoped_refptr<LayerAnimationController> controller( | 1295 scoped_refptr<LayerAnimationController> controller( |
1291 LayerAnimationController::Create(0)); | 1296 LayerAnimationController::Create(0)); |
1292 controller->AddValueObserver(&dummy); | 1297 controller->AddValueObserver(&dummy); |
1293 | 1298 |
1294 scoped_ptr<Animation> to_add(CreateAnimation( | 1299 scoped_ptr<Animation> to_add(CreateAnimation( |
1295 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), | 1300 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), |
1296 0, | 1301 0, |
1297 Animation::Opacity)); | 1302 Animation::Opacity)); |
1298 to_add->set_needs_synchronized_start_time(true); | 1303 to_add->set_needs_synchronized_start_time(true); |
1299 controller->AddAnimation(to_add.Pass()); | 1304 controller->AddAnimation(to_add.Pass()); |
1300 | 1305 |
1301 controller->Animate(kInitialTickTime); | 1306 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1302 controller->UpdateState(true, events.get()); | 1307 controller->UpdateState(true, events.get()); |
1303 EXPECT_TRUE(controller->HasActiveAnimation()); | 1308 EXPECT_TRUE(controller->HasActiveAnimation()); |
1304 Animation* active_animation = controller->GetAnimation(0, Animation::Opacity); | 1309 Animation* active_animation = controller->GetAnimation(0, Animation::Opacity); |
1305 EXPECT_TRUE(active_animation); | 1310 EXPECT_TRUE(active_animation); |
1306 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); | 1311 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); |
1307 | 1312 |
1308 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1313 controller->PushAnimationUpdatesTo(controller_impl.get()); |
1309 | 1314 |
1310 active_animation = controller_impl->GetAnimation(0, Animation::Opacity); | 1315 active_animation = controller_impl->GetAnimation(0, Animation::Opacity); |
1311 EXPECT_TRUE(active_animation); | 1316 EXPECT_TRUE(active_animation); |
1312 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 1317 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
1313 active_animation->run_state()); | 1318 active_animation->run_state()); |
1314 } | 1319 } |
1315 | 1320 |
1316 // Tests that skipping a call to UpdateState works as expected. | 1321 // Tests that skipping a call to UpdateState works as expected. |
1317 TEST(LayerAnimationControllerTest, SkipUpdateState) { | 1322 TEST(LayerAnimationControllerTest, SkipUpdateState) { |
1318 scoped_ptr<AnimationEventsVector> events( | 1323 scoped_ptr<AnimationEventsVector> events( |
1319 make_scoped_ptr(new AnimationEventsVector)); | 1324 make_scoped_ptr(new AnimationEventsVector)); |
1320 FakeLayerAnimationValueObserver dummy; | 1325 FakeLayerAnimationValueObserver dummy; |
1321 scoped_refptr<LayerAnimationController> controller( | 1326 scoped_refptr<LayerAnimationController> controller( |
1322 LayerAnimationController::Create(0)); | 1327 LayerAnimationController::Create(0)); |
1323 controller->AddValueObserver(&dummy); | 1328 controller->AddValueObserver(&dummy); |
1324 | 1329 |
1325 controller->AddAnimation(CreateAnimation( | 1330 controller->AddAnimation(CreateAnimation( |
1326 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), | 1331 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), |
1327 1, | 1332 1, |
1328 Animation::Transform)); | 1333 Animation::Transform)); |
1329 | 1334 |
1330 controller->Animate(kInitialTickTime); | 1335 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1331 controller->UpdateState(true, events.get()); | 1336 controller->UpdateState(true, events.get()); |
1332 | 1337 |
1333 controller->AddAnimation(CreateAnimation( | 1338 controller->AddAnimation(CreateAnimation( |
1334 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1339 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1335 2, | 1340 2, |
1336 Animation::Opacity)); | 1341 Animation::Opacity)); |
1337 | 1342 |
1338 // Animate but don't UpdateState. | 1343 // Animate but don't UpdateState. |
1339 controller->Animate(kInitialTickTime + 1.0); | 1344 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
1340 | 1345 |
1341 controller->Animate(kInitialTickTime + 2.0); | 1346 controller->Animate(GetTimeTicks(kInitialTickTime + 2.0)); |
1342 events.reset(new AnimationEventsVector); | 1347 events.reset(new AnimationEventsVector); |
1343 controller->UpdateState(true, events.get()); | 1348 controller->UpdateState(true, events.get()); |
1344 | 1349 |
1345 // Should have one Started event and one Finished event. | 1350 // Should have one Started event and one Finished event. |
1346 EXPECT_EQ(2u, events->size()); | 1351 EXPECT_EQ(2u, events->size()); |
1347 EXPECT_NE((*events)[0].type, (*events)[1].type); | 1352 EXPECT_NE((*events)[0].type, (*events)[1].type); |
1348 | 1353 |
1349 // The float transition should still be at its starting point. | 1354 // The float transition should still be at its starting point. |
1350 EXPECT_TRUE(controller->HasActiveAnimation()); | 1355 EXPECT_TRUE(controller->HasActiveAnimation()); |
1351 EXPECT_EQ(0.f, dummy.opacity()); | 1356 EXPECT_EQ(0.f, dummy.opacity()); |
1352 | 1357 |
1353 controller->Animate(kInitialTickTime + 3.0); | 1358 controller->Animate(GetTimeTicks(kInitialTickTime + 3.0)); |
1354 controller->UpdateState(true, events.get()); | 1359 controller->UpdateState(true, events.get()); |
1355 | 1360 |
1356 // The float tranisition should now be done. | 1361 // The float tranisition should now be done. |
1357 EXPECT_EQ(1.f, dummy.opacity()); | 1362 EXPECT_EQ(1.f, dummy.opacity()); |
1358 EXPECT_FALSE(controller->HasActiveAnimation()); | 1363 EXPECT_FALSE(controller->HasActiveAnimation()); |
1359 } | 1364 } |
1360 | 1365 |
1361 // Tests that an animation controller with only an inactive observer gets ticked | 1366 // Tests that an animation controller with only an inactive observer gets ticked |
1362 // but doesn't progress animations past the Starting state. | 1367 // but doesn't progress animations past the Starting state. |
1363 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { | 1368 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { |
1364 scoped_ptr<AnimationEventsVector> events( | 1369 scoped_ptr<AnimationEventsVector> events( |
1365 make_scoped_ptr(new AnimationEventsVector)); | 1370 make_scoped_ptr(new AnimationEventsVector)); |
1366 FakeLayerAnimationValueObserver dummy; | 1371 FakeLayerAnimationValueObserver dummy; |
1367 FakeInactiveLayerAnimationValueObserver inactive_dummy; | 1372 FakeInactiveLayerAnimationValueObserver inactive_dummy; |
1368 scoped_refptr<LayerAnimationController> controller( | 1373 scoped_refptr<LayerAnimationController> controller( |
1369 LayerAnimationController::Create(0)); | 1374 LayerAnimationController::Create(0)); |
1370 | 1375 |
1371 const int id = 1; | 1376 const int id = 1; |
1372 controller->AddAnimation(CreateAnimation(scoped_ptr<AnimationCurve>( | 1377 controller->AddAnimation(CreateAnimation(scoped_ptr<AnimationCurve>( |
1373 new FakeFloatTransition(1.0, 0.5f, 1.f)).Pass(), | 1378 new FakeFloatTransition(1.0, 0.5f, 1.f)).Pass(), |
1374 id, | 1379 id, |
1375 Animation::Opacity)); | 1380 Animation::Opacity)); |
1376 | 1381 |
1377 // Without an observer, the animation shouldn't progress to the Starting | 1382 // Without an observer, the animation shouldn't progress to the Starting |
1378 // state. | 1383 // state. |
1379 controller->Animate(kInitialTickTime); | 1384 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1380 controller->UpdateState(true, events.get()); | 1385 controller->UpdateState(true, events.get()); |
1381 EXPECT_EQ(0u, events->size()); | 1386 EXPECT_EQ(0u, events->size()); |
1382 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 1387 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
1383 controller->GetAnimation(id, Animation::Opacity)->run_state()); | 1388 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
1384 | 1389 |
1385 controller->AddValueObserver(&inactive_dummy); | 1390 controller->AddValueObserver(&inactive_dummy); |
1386 | 1391 |
1387 // With only an inactive observer, the animation should progress to the | 1392 // With only an inactive observer, the animation should progress to the |
1388 // Starting state and get ticked at its starting point, but should not | 1393 // Starting state and get ticked at its starting point, but should not |
1389 // progress to Running. | 1394 // progress to Running. |
1390 controller->Animate(kInitialTickTime + 1.0); | 1395 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
1391 controller->UpdateState(true, events.get()); | 1396 controller->UpdateState(true, events.get()); |
1392 EXPECT_EQ(0u, events->size()); | 1397 EXPECT_EQ(0u, events->size()); |
1393 EXPECT_EQ(Animation::Starting, | 1398 EXPECT_EQ(Animation::Starting, |
1394 controller->GetAnimation(id, Animation::Opacity)->run_state()); | 1399 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
1395 EXPECT_EQ(0.5f, inactive_dummy.opacity()); | 1400 EXPECT_EQ(0.5f, inactive_dummy.opacity()); |
1396 | 1401 |
1397 // Even when already in the Starting state, the animation should stay | 1402 // Even when already in the Starting state, the animation should stay |
1398 // there, and shouldn't be ticked past its starting point. | 1403 // there, and shouldn't be ticked past its starting point. |
1399 controller->Animate(kInitialTickTime + 2.0); | 1404 controller->Animate(GetTimeTicks(kInitialTickTime + 2.0)); |
1400 controller->UpdateState(true, events.get()); | 1405 controller->UpdateState(true, events.get()); |
1401 EXPECT_EQ(0u, events->size()); | 1406 EXPECT_EQ(0u, events->size()); |
1402 EXPECT_EQ(Animation::Starting, | 1407 EXPECT_EQ(Animation::Starting, |
1403 controller->GetAnimation(id, Animation::Opacity)->run_state()); | 1408 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
1404 EXPECT_EQ(0.5f, inactive_dummy.opacity()); | 1409 EXPECT_EQ(0.5f, inactive_dummy.opacity()); |
1405 | 1410 |
1406 controller->AddValueObserver(&dummy); | 1411 controller->AddValueObserver(&dummy); |
1407 | 1412 |
1408 // Now that an active observer has been added, the animation should still | 1413 // Now that an active observer has been added, the animation should still |
1409 // initially tick at its starting point, but should now progress to Running. | 1414 // initially tick at its starting point, but should now progress to Running. |
1410 controller->Animate(kInitialTickTime + 3.0); | 1415 controller->Animate(GetTimeTicks(kInitialTickTime + 3.0)); |
1411 controller->UpdateState(true, events.get()); | 1416 controller->UpdateState(true, events.get()); |
1412 EXPECT_EQ(1u, events->size()); | 1417 EXPECT_EQ(1u, events->size()); |
1413 EXPECT_EQ(Animation::Running, | 1418 EXPECT_EQ(Animation::Running, |
1414 controller->GetAnimation(id, Animation::Opacity)->run_state()); | 1419 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
1415 EXPECT_EQ(0.5f, inactive_dummy.opacity()); | 1420 EXPECT_EQ(0.5f, inactive_dummy.opacity()); |
1416 EXPECT_EQ(0.5f, dummy.opacity()); | 1421 EXPECT_EQ(0.5f, dummy.opacity()); |
1417 | 1422 |
1418 // The animation should now tick past its starting point. | 1423 // The animation should now tick past its starting point. |
1419 controller->Animate(kInitialTickTime + 3.5); | 1424 controller->Animate(GetTimeTicks(kInitialTickTime + 3.5)); |
1420 EXPECT_NE(0.5f, inactive_dummy.opacity()); | 1425 EXPECT_NE(0.5f, inactive_dummy.opacity()); |
1421 EXPECT_NE(0.5f, dummy.opacity()); | 1426 EXPECT_NE(0.5f, dummy.opacity()); |
1422 } | 1427 } |
1423 | 1428 |
1424 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { | 1429 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { |
1425 scoped_refptr<LayerAnimationController> controller_impl( | 1430 scoped_refptr<LayerAnimationController> controller_impl( |
1426 LayerAnimationController::Create(0)); | 1431 LayerAnimationController::Create(0)); |
1427 | 1432 |
1428 scoped_ptr<KeyframedTransformAnimationCurve> curve1( | 1433 scoped_ptr<KeyframedTransformAnimationCurve> curve1( |
1429 KeyframedTransformAnimationCurve::Create()); | 1434 KeyframedTransformAnimationCurve::Create()); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1515 Animation::Transform)); | 1520 Animation::Transform)); |
1516 controller->AddAnimation(CreateAnimation( | 1521 controller->AddAnimation(CreateAnimation( |
1517 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), | 1522 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), |
1518 4, | 1523 4, |
1519 Animation::Transform)); | 1524 Animation::Transform)); |
1520 controller->AddAnimation(CreateAnimation( | 1525 controller->AddAnimation(CreateAnimation( |
1521 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1526 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1522 5, | 1527 5, |
1523 Animation::Opacity)); | 1528 Animation::Opacity)); |
1524 | 1529 |
1525 controller->Animate(kInitialTickTime); | 1530 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1526 controller->UpdateState(true, NULL); | 1531 controller->UpdateState(true, NULL); |
1527 controller->Animate(kInitialTickTime + 1.0); | 1532 controller->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
1528 controller->UpdateState(true, NULL); | 1533 controller->UpdateState(true, NULL); |
1529 | 1534 |
1530 EXPECT_EQ(Animation::Finished, | 1535 EXPECT_EQ(Animation::Finished, |
1531 controller->GetAnimation(1, Animation::Transform)->run_state()); | 1536 controller->GetAnimation(1, Animation::Transform)->run_state()); |
1532 EXPECT_EQ(Animation::Finished, | 1537 EXPECT_EQ(Animation::Finished, |
1533 controller->GetAnimation(2, Animation::Opacity)->run_state()); | 1538 controller->GetAnimation(2, Animation::Opacity)->run_state()); |
1534 EXPECT_EQ(Animation::Running, | 1539 EXPECT_EQ(Animation::Running, |
1535 controller->GetAnimation(3, Animation::Transform)->run_state()); | 1540 controller->GetAnimation(3, Animation::Transform)->run_state()); |
1536 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 1541 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
1537 controller->GetAnimation(4, Animation::Transform)->run_state()); | 1542 controller->GetAnimation(4, Animation::Transform)->run_state()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1569 | 1574 |
1570 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1575 controller->PushAnimationUpdatesTo(controller_impl.get()); |
1571 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); | 1576 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); |
1572 | 1577 |
1573 controller->AbortAnimations(Animation::Opacity); | 1578 controller->AbortAnimations(Animation::Opacity); |
1574 EXPECT_EQ(Animation::Aborted, | 1579 EXPECT_EQ(Animation::Aborted, |
1575 controller->GetAnimation(Animation::Opacity)->run_state()); | 1580 controller->GetAnimation(Animation::Opacity)->run_state()); |
1576 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | 1581 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); |
1577 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | 1582 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); |
1578 | 1583 |
1579 controller->Animate(kInitialTickTime); | 1584 controller->Animate(GetTimeTicks(kInitialTickTime)); |
1580 controller->UpdateState(true, NULL); | 1585 controller->UpdateState(true, NULL); |
1581 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 1586 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
1582 EXPECT_EQ(Animation::WaitingForDeletion, | 1587 EXPECT_EQ(Animation::WaitingForDeletion, |
1583 controller->GetAnimation(Animation::Opacity)->run_state()); | 1588 controller->GetAnimation(Animation::Opacity)->run_state()); |
1584 | 1589 |
1585 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1590 controller->PushAnimationUpdatesTo(controller_impl.get()); |
1586 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity)); | 1591 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity)); |
1587 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); | 1592 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); |
1588 } | 1593 } |
1589 | 1594 |
(...skipping 14 matching lines...) Expand all Loading... | |
1604 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1609 controller->PushAnimationUpdatesTo(controller_impl.get()); |
1605 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); | 1610 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); |
1606 | 1611 |
1607 controller_impl->AbortAnimations(Animation::Opacity); | 1612 controller_impl->AbortAnimations(Animation::Opacity); |
1608 EXPECT_EQ(Animation::Aborted, | 1613 EXPECT_EQ(Animation::Aborted, |
1609 controller_impl->GetAnimation(Animation::Opacity)->run_state()); | 1614 controller_impl->GetAnimation(Animation::Opacity)->run_state()); |
1610 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | 1615 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); |
1611 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | 1616 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); |
1612 | 1617 |
1613 AnimationEventsVector events; | 1618 AnimationEventsVector events; |
1614 controller_impl->Animate(kInitialTickTime); | 1619 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
1615 controller_impl->UpdateState(true, &events); | 1620 controller_impl->UpdateState(true, &events); |
1616 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | 1621 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); |
1617 EXPECT_EQ(1u, events.size()); | 1622 EXPECT_EQ(1u, events.size()); |
1618 EXPECT_EQ(AnimationEvent::Aborted, events[0].type); | 1623 EXPECT_EQ(AnimationEvent::Aborted, events[0].type); |
1619 EXPECT_EQ(Animation::WaitingForDeletion, | 1624 EXPECT_EQ(Animation::WaitingForDeletion, |
1620 controller_impl->GetAnimation(Animation::Opacity)->run_state()); | 1625 controller_impl->GetAnimation(Animation::Opacity)->run_state()); |
1621 | 1626 |
1622 controller->NotifyAnimationAborted(events[0]); | 1627 controller->NotifyAnimationAborted(events[0]); |
1623 EXPECT_EQ(Animation::Aborted, | 1628 EXPECT_EQ(Animation::Aborted, |
1624 controller->GetAnimation(Animation::Opacity)->run_state()); | 1629 controller->GetAnimation(Animation::Opacity)->run_state()); |
1625 | 1630 |
1626 controller->Animate(kInitialTickTime + 0.5); | 1631 controller->Animate(GetTimeTicks(kInitialTickTime + 0.5)); |
1627 controller->UpdateState(true, NULL); | 1632 controller->UpdateState(true, NULL); |
1628 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 1633 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
1629 EXPECT_EQ(Animation::WaitingForDeletion, | 1634 EXPECT_EQ(Animation::WaitingForDeletion, |
1630 controller->GetAnimation(Animation::Opacity)->run_state()); | 1635 controller->GetAnimation(Animation::Opacity)->run_state()); |
1631 | 1636 |
1632 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1637 controller->PushAnimationUpdatesTo(controller_impl.get()); |
1633 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity)); | 1638 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity)); |
1634 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); | 1639 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); |
1635 } | 1640 } |
1636 | 1641 |
(...skipping 10 matching lines...) Expand all Loading... | |
1647 // Add two animations with the same group id but different durations. | 1652 // Add two animations with the same group id but different durations. |
1648 controller_impl->AddAnimation(CreateAnimation( | 1653 controller_impl->AddAnimation(CreateAnimation( |
1649 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), | 1654 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), |
1650 1, | 1655 1, |
1651 Animation::Transform)); | 1656 Animation::Transform)); |
1652 controller_impl->AddAnimation(CreateAnimation( | 1657 controller_impl->AddAnimation(CreateAnimation( |
1653 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1658 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1654 1, | 1659 1, |
1655 Animation::Opacity)); | 1660 Animation::Opacity)); |
1656 | 1661 |
1657 controller_impl->Animate(kInitialTickTime); | 1662 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
1658 controller_impl->UpdateState(true, events.get()); | 1663 controller_impl->UpdateState(true, events.get()); |
1659 | 1664 |
1660 // Both animations should have started. | 1665 // Both animations should have started. |
1661 EXPECT_EQ(2u, events->size()); | 1666 EXPECT_EQ(2u, events->size()); |
1662 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); | 1667 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); |
1663 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); | 1668 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); |
1664 | 1669 |
1665 events.reset(new AnimationEventsVector); | 1670 events.reset(new AnimationEventsVector); |
1666 controller_impl->Animate(kInitialTickTime + 1.0); | 1671 controller_impl->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
1667 controller_impl->UpdateState(true, events.get()); | 1672 controller_impl->UpdateState(true, events.get()); |
1668 | 1673 |
1669 // The opacity animation should be finished, but should not have generated | 1674 // The opacity animation should be finished, but should not have generated |
1670 // a Finished event yet. | 1675 // a Finished event yet. |
1671 EXPECT_EQ(0u, events->size()); | 1676 EXPECT_EQ(0u, events->size()); |
1672 EXPECT_EQ(Animation::Finished, | 1677 EXPECT_EQ(Animation::Finished, |
1673 controller_impl->GetAnimation(1, Animation::Opacity)->run_state()); | 1678 controller_impl->GetAnimation(1, Animation::Opacity)->run_state()); |
1674 EXPECT_EQ(Animation::Running, | 1679 EXPECT_EQ(Animation::Running, |
1675 controller_impl->GetAnimation(1, | 1680 controller_impl->GetAnimation(1, |
1676 Animation::Transform)->run_state()); | 1681 Animation::Transform)->run_state()); |
1677 | 1682 |
1678 controller_impl->Animate(kInitialTickTime + 2.0); | 1683 controller_impl->Animate(GetTimeTicks(kInitialTickTime + 2.0)); |
1679 controller_impl->UpdateState(true, events.get()); | 1684 controller_impl->UpdateState(true, events.get()); |
1680 | 1685 |
1681 // Both animations should have generated Finished events. | 1686 // Both animations should have generated Finished events. |
1682 EXPECT_EQ(2u, events->size()); | 1687 EXPECT_EQ(2u, events->size()); |
1683 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 1688 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); |
1684 EXPECT_EQ(AnimationEvent::Finished, (*events)[1].type); | 1689 EXPECT_EQ(AnimationEvent::Finished, (*events)[1].type); |
1685 } | 1690 } |
1686 | 1691 |
1687 // Ensure that when a group has a mix of aborted and finished animations, | 1692 // Ensure that when a group has a mix of aborted and finished animations, |
1688 // we generate a Finished event for the finished animation and an Aborted | 1693 // we generate a Finished event for the finished animation and an Aborted |
1689 // event for the aborted animation. | 1694 // event for the aborted animation. |
1690 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { | 1695 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { |
1691 scoped_ptr<AnimationEventsVector> events( | 1696 scoped_ptr<AnimationEventsVector> events( |
1692 make_scoped_ptr(new AnimationEventsVector)); | 1697 make_scoped_ptr(new AnimationEventsVector)); |
1693 FakeLayerAnimationValueObserver dummy_impl; | 1698 FakeLayerAnimationValueObserver dummy_impl; |
1694 scoped_refptr<LayerAnimationController> controller_impl( | 1699 scoped_refptr<LayerAnimationController> controller_impl( |
1695 LayerAnimationController::Create(0)); | 1700 LayerAnimationController::Create(0)); |
1696 controller_impl->AddValueObserver(&dummy_impl); | 1701 controller_impl->AddValueObserver(&dummy_impl); |
1697 | 1702 |
1698 // Add two animations with the same group id. | 1703 // Add two animations with the same group id. |
1699 controller_impl->AddAnimation(CreateAnimation( | 1704 controller_impl->AddAnimation(CreateAnimation( |
1700 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), | 1705 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), |
1701 1, | 1706 1, |
1702 Animation::Transform)); | 1707 Animation::Transform)); |
1703 controller_impl->AddAnimation(CreateAnimation( | 1708 controller_impl->AddAnimation(CreateAnimation( |
1704 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1709 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1705 1, | 1710 1, |
1706 Animation::Opacity)); | 1711 Animation::Opacity)); |
1707 | 1712 |
1708 controller_impl->Animate(kInitialTickTime); | 1713 controller_impl->Animate(GetTimeTicks(kInitialTickTime)); |
1709 controller_impl->UpdateState(true, events.get()); | 1714 controller_impl->UpdateState(true, events.get()); |
1710 | 1715 |
1711 // Both animations should have started. | 1716 // Both animations should have started. |
1712 EXPECT_EQ(2u, events->size()); | 1717 EXPECT_EQ(2u, events->size()); |
1713 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); | 1718 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); |
1714 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); | 1719 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); |
1715 | 1720 |
1716 controller_impl->AbortAnimations(Animation::Opacity); | 1721 controller_impl->AbortAnimations(Animation::Opacity); |
1717 | 1722 |
1718 events.reset(new AnimationEventsVector); | 1723 events.reset(new AnimationEventsVector); |
1719 controller_impl->Animate(kInitialTickTime + 1.0); | 1724 controller_impl->Animate(GetTimeTicks(kInitialTickTime + 1.0)); |
1720 controller_impl->UpdateState(true, events.get()); | 1725 controller_impl->UpdateState(true, events.get()); |
1721 | 1726 |
1722 // We should have exactly 2 events: a Finished event for the tranform | 1727 // We should have exactly 2 events: a Finished event for the tranform |
1723 // animation, and an Aborted event for the opacity animation. | 1728 // animation, and an Aborted event for the opacity animation. |
1724 EXPECT_EQ(2u, events->size()); | 1729 EXPECT_EQ(2u, events->size()); |
1725 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 1730 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); |
1726 EXPECT_EQ(Animation::Transform, (*events)[0].target_property); | 1731 EXPECT_EQ(Animation::Transform, (*events)[0].target_property); |
1727 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type); | 1732 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type); |
1728 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property); | 1733 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property); |
1729 } | 1734 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1903 ->SetRunState(Animation::Finished, 0.0); | 1908 ->SetRunState(Animation::Finished, 0.0); |
1904 | 1909 |
1905 // Only unfinished animations should be considered by | 1910 // Only unfinished animations should be considered by |
1906 // MaximumScale. | 1911 // MaximumScale. |
1907 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale)); | 1912 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale)); |
1908 EXPECT_EQ(4.f, max_scale); | 1913 EXPECT_EQ(4.f, max_scale); |
1909 } | 1914 } |
1910 | 1915 |
1911 } // namespace | 1916 } // namespace |
1912 } // namespace cc | 1917 } // namespace cc |
OLD | NEW |