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 using base::TimeDelta; | |
24 using base::TimeTicks; | |
25 | |
23 // A LayerAnimationController cannot be ticked at 0.0, since an animation | 26 // 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 | 27 // with start time 0.0 is treated as an animation whose start time has |
25 // not yet been set. | 28 // not yet been set. |
26 const double kInitialTickTime = 1.0; | 29 const TimeTicks kInitialTickTime = TimeTicks::FromSeconds(1.0); |
27 | 30 |
28 scoped_ptr<Animation> CreateAnimation(scoped_ptr<AnimationCurve> curve, | 31 scoped_ptr<Animation> CreateAnimation(scoped_ptr<AnimationCurve> curve, |
29 int id, | 32 int id, |
30 Animation::TargetProperty property) { | 33 Animation::TargetProperty property) { |
31 return Animation::Create(curve.Pass(), 0, id, property); | 34 return Animation::Create(curve.Pass(), 0, id, property); |
32 } | 35 } |
33 | 36 |
34 TEST(LayerAnimationControllerTest, SyncNewAnimation) { | 37 TEST(LayerAnimationControllerTest, SyncNewAnimation) { |
35 FakeLayerAnimationValueObserver dummy_impl; | 38 FakeLayerAnimationValueObserver dummy_impl; |
36 scoped_refptr<LayerAnimationController> controller_impl( | 39 scoped_refptr<LayerAnimationController> controller_impl( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 | 87 |
85 // Synchronize the start times. | 88 // Synchronize the start times. |
86 EXPECT_EQ(1u, events.size()); | 89 EXPECT_EQ(1u, events.size()); |
87 controller->NotifyAnimationStarted(events[0]); | 90 controller->NotifyAnimationStarted(events[0]); |
88 EXPECT_EQ(controller->GetAnimation(group_id, | 91 EXPECT_EQ(controller->GetAnimation(group_id, |
89 Animation::Opacity)->start_time(), | 92 Animation::Opacity)->start_time(), |
90 controller_impl->GetAnimation(group_id, | 93 controller_impl->GetAnimation(group_id, |
91 Animation::Opacity)->start_time()); | 94 Animation::Opacity)->start_time()); |
92 | 95 |
93 // Start the animation on the main thread. Should not affect the start time. | 96 // Start the animation on the main thread. Should not affect the start time. |
94 controller->Animate(kInitialTickTime + 0.5); | 97 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
95 controller->UpdateState(true, NULL); | 98 controller->UpdateState(true, NULL); |
96 EXPECT_EQ(controller->GetAnimation(group_id, | 99 EXPECT_EQ(controller->GetAnimation(group_id, |
97 Animation::Opacity)->start_time(), | 100 Animation::Opacity)->start_time(), |
98 controller_impl->GetAnimation(group_id, | 101 controller_impl->GetAnimation(group_id, |
99 Animation::Opacity)->start_time()); | 102 Animation::Opacity)->start_time()); |
100 } | 103 } |
101 | 104 |
102 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) { | 105 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) { |
103 FakeLayerAnimationValueObserver dummy_impl; | 106 FakeLayerAnimationValueObserver dummy_impl; |
104 scoped_refptr<LayerAnimationController> controller_impl( | 107 scoped_refptr<LayerAnimationController> controller_impl( |
105 LayerAnimationController::Create(0)); | 108 LayerAnimationController::Create(0)); |
106 controller_impl->AddValueObserver(&dummy_impl); | 109 controller_impl->AddValueObserver(&dummy_impl); |
107 FakeLayerAnimationValueObserver dummy; | 110 FakeLayerAnimationValueObserver dummy; |
108 scoped_refptr<LayerAnimationController> controller( | 111 scoped_refptr<LayerAnimationController> controller( |
109 LayerAnimationController::Create(0)); | 112 LayerAnimationController::Create(0)); |
110 controller->AddValueObserver(&dummy); | 113 controller->AddValueObserver(&dummy); |
111 | 114 |
112 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 115 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
113 int group_id = controller->GetAnimation(Animation::Opacity)->group(); | 116 int group_id = controller->GetAnimation(Animation::Opacity)->group(); |
114 | 117 |
115 const double start_time = 123; | 118 const TimeTicks start_time = TimeTicks::FromSeconds(123); |
116 controller->GetAnimation(Animation::Opacity)->set_start_time(start_time); | 119 controller->GetAnimation(Animation::Opacity)->set_start_time(start_time); |
117 | 120 |
118 controller->PushAnimationUpdatesTo(controller_impl.get()); | 121 controller->PushAnimationUpdatesTo(controller_impl.get()); |
119 | 122 |
120 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); | 123 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); |
121 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 124 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
122 controller_impl->GetAnimation(group_id, | 125 controller_impl->GetAnimation(group_id, |
123 Animation::Opacity)->run_state()); | 126 Animation::Opacity)->run_state()); |
124 | 127 |
125 AnimationEventsVector events; | 128 AnimationEventsVector events; |
126 controller_impl->Animate(kInitialTickTime); | 129 controller_impl->Animate(kInitialTickTime); |
127 controller_impl->UpdateState(true, &events); | 130 controller_impl->UpdateState(true, &events); |
128 | 131 |
129 // Synchronize the start times. | 132 // Synchronize the start times. |
130 EXPECT_EQ(1u, events.size()); | 133 EXPECT_EQ(1u, events.size()); |
131 controller->NotifyAnimationStarted(events[0]); | 134 controller->NotifyAnimationStarted(events[0]); |
132 | 135 |
133 EXPECT_EQ(start_time, | 136 EXPECT_EQ(start_time, |
134 controller->GetAnimation(group_id, | 137 controller->GetAnimation(group_id, |
135 Animation::Opacity)->start_time()); | 138 Animation::Opacity)->start_time()); |
136 EXPECT_EQ(controller->GetAnimation(group_id, | 139 EXPECT_EQ(controller->GetAnimation(group_id, |
137 Animation::Opacity)->start_time(), | 140 Animation::Opacity)->start_time(), |
138 controller_impl->GetAnimation(group_id, | 141 controller_impl->GetAnimation(group_id, |
139 Animation::Opacity)->start_time()); | 142 Animation::Opacity)->start_time()); |
140 | 143 |
141 // Start the animation on the main thread. Should not affect the start time. | 144 // Start the animation on the main thread. Should not affect the start time. |
142 controller->Animate(kInitialTickTime + 0.5); | 145 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
143 controller->UpdateState(true, NULL); | 146 controller->UpdateState(true, NULL); |
144 EXPECT_EQ(start_time, | 147 EXPECT_EQ(start_time, |
145 controller->GetAnimation(group_id, | 148 controller->GetAnimation(group_id, |
146 Animation::Opacity)->start_time()); | 149 Animation::Opacity)->start_time()); |
147 EXPECT_EQ(controller->GetAnimation(group_id, | 150 EXPECT_EQ(controller->GetAnimation(group_id, |
148 Animation::Opacity)->start_time(), | 151 Animation::Opacity)->start_time(), |
149 controller_impl->GetAnimation(group_id, | 152 controller_impl->GetAnimation(group_id, |
150 Animation::Opacity)->start_time()); | 153 Animation::Opacity)->start_time()); |
151 } | 154 } |
152 | 155 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); | 188 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); |
186 | 189 |
187 controller_impl->Animate(kInitialTickTime); | 190 controller_impl->Animate(kInitialTickTime); |
188 controller_impl->UpdateState(true, events.get()); | 191 controller_impl->UpdateState(true, events.get()); |
189 EXPECT_EQ(1u, events->size()); | 192 EXPECT_EQ(1u, events->size()); |
190 controller->NotifyAnimationStarted((*events)[0]); | 193 controller->NotifyAnimationStarted((*events)[0]); |
191 | 194 |
192 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 195 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
193 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); | 196 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); |
194 | 197 |
195 controller->Animate(kInitialTickTime + 0.5); | 198 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
196 controller->UpdateState(true, NULL); | 199 controller->UpdateState(true, NULL); |
197 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 200 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
198 | 201 |
199 controller->Animate(kInitialTickTime + 1.0); | 202 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
200 controller->UpdateState(true, NULL); | 203 controller->UpdateState(true, NULL); |
201 EXPECT_EQ(Animation::Finished, | 204 EXPECT_EQ(Animation::Finished, |
202 controller->GetAnimation(Animation::Opacity)->run_state()); | 205 controller->GetAnimation(Animation::Opacity)->run_state()); |
203 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 206 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
204 | 207 |
205 events.reset(new AnimationEventsVector); | 208 events.reset(new AnimationEventsVector); |
206 controller_impl->Animate(kInitialTickTime + 1.5); | 209 controller_impl->Animate(kInitialTickTime + |
210 TimeDelta::FromMilliseconds(1500)); | |
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(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); |
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 controller->Animate(kInitialTickTime); | 265 controller->Animate(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( |
276 animation_id, | |
277 TimeDelta::FromMilliseconds(1000) + TimeDelta::FromMilliseconds(1000)); | |
272 EXPECT_EQ(Animation::Paused, | 278 EXPECT_EQ(Animation::Paused, |
273 controller->GetAnimation(group_id, | 279 controller->GetAnimation(group_id, |
274 Animation::Opacity)->run_state()); | 280 Animation::Opacity)->run_state()); |
275 | 281 |
276 // The pause run state change should make it to the impl thread controller. | 282 // The pause run state change should make it to the impl thread controller. |
277 controller->PushAnimationUpdatesTo(controller_impl.get()); | 283 controller->PushAnimationUpdatesTo(controller_impl.get()); |
278 EXPECT_EQ(Animation::Paused, | 284 EXPECT_EQ(Animation::Paused, |
279 controller_impl->GetAnimation(group_id, | 285 controller_impl->GetAnimation(group_id, |
280 Animation::Opacity)->run_state()); | 286 Animation::Opacity)->run_state()); |
281 } | 287 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 scoped_refptr<LayerAnimationController> controller_impl( | 341 scoped_refptr<LayerAnimationController> controller_impl( |
336 LayerAnimationController::Create(0)); | 342 LayerAnimationController::Create(0)); |
337 controller->AddValueObserver(&dummy); | 343 controller->AddValueObserver(&dummy); |
338 controller_impl->AddValueObserver(&dummy_impl); | 344 controller_impl->AddValueObserver(&dummy_impl); |
339 | 345 |
340 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); | 346 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); |
341 controller->Animate(kInitialTickTime); | 347 controller->Animate(kInitialTickTime); |
342 controller->UpdateState(true, NULL); | 348 controller->UpdateState(true, NULL); |
343 controller->PushAnimationUpdatesTo(controller_impl.get()); | 349 controller->PushAnimationUpdatesTo(controller_impl.get()); |
344 | 350 |
345 controller_impl->Animate(kInitialTickTime + 0.5); | 351 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
346 controller_impl->UpdateState(true, events.get()); | 352 controller_impl->UpdateState(true, events.get()); |
347 | 353 |
348 // There should be a Started event for the animation. | 354 // There should be a Started event for the animation. |
349 EXPECT_EQ(1u, events->size()); | 355 EXPECT_EQ(1u, events->size()); |
350 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); | 356 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); |
351 controller->NotifyAnimationStarted((*events)[0]); | 357 controller->NotifyAnimationStarted((*events)[0]); |
352 | 358 |
353 controller->Animate(kInitialTickTime + 1.0); | 359 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
354 controller->UpdateState(true, NULL); | 360 controller->UpdateState(true, NULL); |
355 | 361 |
356 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | 362 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); |
357 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | 363 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); |
358 | 364 |
359 events.reset(new AnimationEventsVector); | 365 events.reset(new AnimationEventsVector); |
360 controller_impl->Animate(kInitialTickTime + 2.0); | 366 controller_impl->Animate(kInitialTickTime + |
367 TimeDelta::FromMilliseconds(2000)); | |
361 controller_impl->UpdateState(true, events.get()); | 368 controller_impl->UpdateState(true, events.get()); |
362 | 369 |
363 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | 370 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); |
364 | 371 |
365 // There should be a Finished event for the animation. | 372 // There should be a Finished event for the animation. |
366 EXPECT_EQ(1u, events->size()); | 373 EXPECT_EQ(1u, events->size()); |
367 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 374 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); |
368 | 375 |
369 // Neither controller should have deleted the animation yet. | 376 // Neither controller should have deleted the animation yet. |
370 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity)); | 377 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity)); |
371 EXPECT_TRUE(controller_impl->GetAnimation(Animation::Opacity)); | 378 EXPECT_TRUE(controller_impl->GetAnimation(Animation::Opacity)); |
372 | 379 |
373 controller->NotifyAnimationFinished((*events)[0]); | 380 controller->NotifyAnimationFinished((*events)[0]); |
374 | 381 |
375 controller->Animate(kInitialTickTime + 3.0); | 382 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
376 controller->UpdateState(true, NULL); | 383 controller->UpdateState(true, NULL); |
377 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 384 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
378 | 385 |
379 controller->PushAnimationUpdatesTo(controller_impl.get()); | 386 controller->PushAnimationUpdatesTo(controller_impl.get()); |
380 | 387 |
381 // Both controllers should now have deleted the animation. | 388 // Both controllers should now have deleted the animation. |
382 EXPECT_FALSE(controller->has_any_animation()); | 389 EXPECT_FALSE(controller->has_any_animation()); |
383 EXPECT_FALSE(controller_impl->has_any_animation()); | 390 EXPECT_FALSE(controller_impl->has_any_animation()); |
384 } | 391 } |
385 | 392 |
(...skipping 23 matching lines...) Expand all Loading... | |
409 Animation::Opacity)); | 416 Animation::Opacity)); |
410 | 417 |
411 controller->AddAnimation(to_add.Pass()); | 418 controller->AddAnimation(to_add.Pass()); |
412 controller->Animate(kInitialTickTime); | 419 controller->Animate(kInitialTickTime); |
413 controller->UpdateState(true, events.get()); | 420 controller->UpdateState(true, events.get()); |
414 EXPECT_TRUE(controller->HasActiveAnimation()); | 421 EXPECT_TRUE(controller->HasActiveAnimation()); |
415 EXPECT_EQ(0.f, dummy.opacity()); | 422 EXPECT_EQ(0.f, dummy.opacity()); |
416 // A non-impl-only animation should not generate property updates. | 423 // A non-impl-only animation should not generate property updates. |
417 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 424 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
418 EXPECT_FALSE(event); | 425 EXPECT_FALSE(event); |
419 controller->Animate(kInitialTickTime + 1.0); | 426 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
420 controller->UpdateState(true, events.get()); | 427 controller->UpdateState(true, events.get()); |
421 EXPECT_EQ(1.f, dummy.opacity()); | 428 EXPECT_EQ(1.f, dummy.opacity()); |
422 EXPECT_FALSE(controller->HasActiveAnimation()); | 429 EXPECT_FALSE(controller->HasActiveAnimation()); |
423 event = GetMostRecentPropertyUpdateEvent(events.get()); | 430 event = GetMostRecentPropertyUpdateEvent(events.get()); |
424 EXPECT_FALSE(event); | 431 EXPECT_FALSE(event); |
425 } | 432 } |
426 | 433 |
427 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { | 434 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { |
428 scoped_ptr<AnimationEventsVector> events( | 435 scoped_ptr<AnimationEventsVector> events( |
429 make_scoped_ptr(new AnimationEventsVector)); | 436 make_scoped_ptr(new AnimationEventsVector)); |
(...skipping 11 matching lines...) Expand all Loading... | |
441 controller_impl->AddAnimation(to_add.Pass()); | 448 controller_impl->AddAnimation(to_add.Pass()); |
442 controller_impl->Animate(kInitialTickTime); | 449 controller_impl->Animate(kInitialTickTime); |
443 controller_impl->UpdateState(true, events.get()); | 450 controller_impl->UpdateState(true, events.get()); |
444 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 451 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
445 EXPECT_EQ(0.f, dummy_impl.opacity()); | 452 EXPECT_EQ(0.f, dummy_impl.opacity()); |
446 EXPECT_EQ(2u, events->size()); | 453 EXPECT_EQ(2u, events->size()); |
447 const AnimationEvent* start_opacity_event = | 454 const AnimationEvent* start_opacity_event = |
448 GetMostRecentPropertyUpdateEvent(events.get()); | 455 GetMostRecentPropertyUpdateEvent(events.get()); |
449 EXPECT_EQ(0.f, start_opacity_event->opacity); | 456 EXPECT_EQ(0.f, start_opacity_event->opacity); |
450 | 457 |
451 controller_impl->Animate(kInitialTickTime + 1.0); | 458 controller_impl->Animate(kInitialTickTime + |
459 TimeDelta::FromMilliseconds(1000)); | |
452 controller_impl->UpdateState(true, events.get()); | 460 controller_impl->UpdateState(true, events.get()); |
453 EXPECT_EQ(1.f, dummy_impl.opacity()); | 461 EXPECT_EQ(1.f, dummy_impl.opacity()); |
454 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 462 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
455 EXPECT_EQ(4u, events->size()); | 463 EXPECT_EQ(4u, events->size()); |
456 const AnimationEvent* end_opacity_event = | 464 const AnimationEvent* end_opacity_event = |
457 GetMostRecentPropertyUpdateEvent(events.get()); | 465 GetMostRecentPropertyUpdateEvent(events.get()); |
458 EXPECT_EQ(1.f, end_opacity_event->opacity); | 466 EXPECT_EQ(1.f, end_opacity_event->opacity); |
459 } | 467 } |
460 | 468 |
461 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { | 469 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 EXPECT_EQ(2u, events->size()); | 503 EXPECT_EQ(2u, events->size()); |
496 const AnimationEvent* start_transform_event = | 504 const AnimationEvent* start_transform_event = |
497 GetMostRecentPropertyUpdateEvent(events.get()); | 505 GetMostRecentPropertyUpdateEvent(events.get()); |
498 ASSERT_TRUE(start_transform_event); | 506 ASSERT_TRUE(start_transform_event); |
499 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); | 507 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); |
500 EXPECT_TRUE(start_transform_event->is_impl_only); | 508 EXPECT_TRUE(start_transform_event->is_impl_only); |
501 | 509 |
502 gfx::Transform expected_transform; | 510 gfx::Transform expected_transform; |
503 expected_transform.Translate(delta_x, delta_y); | 511 expected_transform.Translate(delta_x, delta_y); |
504 | 512 |
505 controller_impl->Animate(kInitialTickTime + 1.0); | 513 controller_impl->Animate(kInitialTickTime + |
514 TimeDelta::FromMilliseconds(1000)); | |
506 controller_impl->UpdateState(true, events.get()); | 515 controller_impl->UpdateState(true, events.get()); |
507 EXPECT_EQ(expected_transform, dummy_impl.transform()); | 516 EXPECT_EQ(expected_transform, dummy_impl.transform()); |
508 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 517 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
509 EXPECT_EQ(4u, events->size()); | 518 EXPECT_EQ(4u, events->size()); |
510 const AnimationEvent* end_transform_event = | 519 const AnimationEvent* end_transform_event = |
511 GetMostRecentPropertyUpdateEvent(events.get()); | 520 GetMostRecentPropertyUpdateEvent(events.get()); |
512 EXPECT_EQ(expected_transform, end_transform_event->transform); | 521 EXPECT_EQ(expected_transform, end_transform_event->transform); |
513 EXPECT_TRUE(end_transform_event->is_impl_only); | 522 EXPECT_TRUE(end_transform_event->is_impl_only); |
514 } | 523 } |
515 | 524 |
(...skipping 22 matching lines...) Expand all Loading... | |
538 controller->AddAnimation(animation.Pass()); | 547 controller->AddAnimation(animation.Pass()); |
539 | 548 |
540 controller->Animate(kInitialTickTime); | 549 controller->Animate(kInitialTickTime); |
541 controller->UpdateState(true, events.get()); | 550 controller->UpdateState(true, events.get()); |
542 EXPECT_TRUE(controller->HasActiveAnimation()); | 551 EXPECT_TRUE(controller->HasActiveAnimation()); |
543 EXPECT_EQ(start_filters, dummy.filters()); | 552 EXPECT_EQ(start_filters, dummy.filters()); |
544 // A non-impl-only animation should not generate property updates. | 553 // A non-impl-only animation should not generate property updates. |
545 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 554 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
546 EXPECT_FALSE(event); | 555 EXPECT_FALSE(event); |
547 | 556 |
548 controller->Animate(kInitialTickTime + 0.5); | 557 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
549 controller->UpdateState(true, events.get()); | 558 controller->UpdateState(true, events.get()); |
550 EXPECT_EQ(1u, dummy.filters().size()); | 559 EXPECT_EQ(1u, dummy.filters().size()); |
551 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), | 560 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), |
552 dummy.filters().at(0)); | 561 dummy.filters().at(0)); |
553 event = GetMostRecentPropertyUpdateEvent(events.get()); | 562 event = GetMostRecentPropertyUpdateEvent(events.get()); |
554 EXPECT_FALSE(event); | 563 EXPECT_FALSE(event); |
555 | 564 |
556 controller->Animate(kInitialTickTime + 1.0); | 565 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
557 controller->UpdateState(true, events.get()); | 566 controller->UpdateState(true, events.get()); |
558 EXPECT_EQ(end_filters, dummy.filters()); | 567 EXPECT_EQ(end_filters, dummy.filters()); |
559 EXPECT_FALSE(controller->HasActiveAnimation()); | 568 EXPECT_FALSE(controller->HasActiveAnimation()); |
560 event = GetMostRecentPropertyUpdateEvent(events.get()); | 569 event = GetMostRecentPropertyUpdateEvent(events.get()); |
561 EXPECT_FALSE(event); | 570 EXPECT_FALSE(event); |
562 } | 571 } |
563 | 572 |
564 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) { | 573 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) { |
565 scoped_ptr<AnimationEventsVector> events( | 574 scoped_ptr<AnimationEventsVector> events( |
566 make_scoped_ptr(new AnimationEventsVector)); | 575 make_scoped_ptr(new AnimationEventsVector)); |
(...skipping 25 matching lines...) Expand all Loading... | |
592 controller_impl->UpdateState(true, events.get()); | 601 controller_impl->UpdateState(true, events.get()); |
593 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 602 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
594 EXPECT_EQ(start_filters, dummy_impl.filters()); | 603 EXPECT_EQ(start_filters, dummy_impl.filters()); |
595 EXPECT_EQ(2u, events->size()); | 604 EXPECT_EQ(2u, events->size()); |
596 const AnimationEvent* start_filter_event = | 605 const AnimationEvent* start_filter_event = |
597 GetMostRecentPropertyUpdateEvent(events.get()); | 606 GetMostRecentPropertyUpdateEvent(events.get()); |
598 EXPECT_TRUE(start_filter_event); | 607 EXPECT_TRUE(start_filter_event); |
599 EXPECT_EQ(start_filters, start_filter_event->filters); | 608 EXPECT_EQ(start_filters, start_filter_event->filters); |
600 EXPECT_TRUE(start_filter_event->is_impl_only); | 609 EXPECT_TRUE(start_filter_event->is_impl_only); |
601 | 610 |
602 controller_impl->Animate(kInitialTickTime + 1.0); | 611 controller_impl->Animate(kInitialTickTime + |
612 TimeDelta::FromMilliseconds(1000)); | |
603 controller_impl->UpdateState(true, events.get()); | 613 controller_impl->UpdateState(true, events.get()); |
604 EXPECT_EQ(end_filters, dummy_impl.filters()); | 614 EXPECT_EQ(end_filters, dummy_impl.filters()); |
605 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 615 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
606 EXPECT_EQ(4u, events->size()); | 616 EXPECT_EQ(4u, events->size()); |
607 const AnimationEvent* end_filter_event = | 617 const AnimationEvent* end_filter_event = |
608 GetMostRecentPropertyUpdateEvent(events.get()); | 618 GetMostRecentPropertyUpdateEvent(events.get()); |
609 EXPECT_TRUE(end_filter_event); | 619 EXPECT_TRUE(end_filter_event); |
610 EXPECT_EQ(end_filters, end_filter_event->filters); | 620 EXPECT_EQ(end_filters, end_filter_event->filters); |
611 EXPECT_TRUE(end_filter_event->is_impl_only); | 621 EXPECT_TRUE(end_filter_event->is_impl_only); |
612 } | 622 } |
(...skipping 22 matching lines...) Expand all Loading... | |
635 EaseInOutTimingFunction::Create().Pass())); | 645 EaseInOutTimingFunction::Create().Pass())); |
636 | 646 |
637 scoped_ptr<Animation> animation(Animation::Create( | 647 scoped_ptr<Animation> animation(Animation::Create( |
638 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset)); | 648 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset)); |
639 animation->set_needs_synchronized_start_time(true); | 649 animation->set_needs_synchronized_start_time(true); |
640 controller->AddAnimation(animation.Pass()); | 650 controller->AddAnimation(animation.Pass()); |
641 | 651 |
642 dummy_provider_impl.set_scroll_offset(initial_value); | 652 dummy_provider_impl.set_scroll_offset(initial_value); |
643 controller->PushAnimationUpdatesTo(controller_impl.get()); | 653 controller->PushAnimationUpdatesTo(controller_impl.get()); |
644 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); | 654 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); |
645 double duration = controller_impl->GetAnimation( | 655 double duration = controller_impl->GetAnimation(Animation::ScrollOffset) |
646 Animation::ScrollOffset)->curve()->Duration(); | 656 ->curve() |
647 | 657 ->Duration(); |
658 TimeDelta time_delta = TimeDelta::FromMicroseconds( | |
659 duration * base::Time::kMicrosecondsPerSecond); | |
648 EXPECT_EQ( | 660 EXPECT_EQ( |
649 duration, | 661 duration, |
650 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); | 662 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); |
651 | |
652 controller->Animate(kInitialTickTime); | 663 controller->Animate(kInitialTickTime); |
653 controller->UpdateState(true, NULL); | 664 controller->UpdateState(true, NULL); |
654 EXPECT_TRUE(controller->HasActiveAnimation()); | 665 EXPECT_TRUE(controller->HasActiveAnimation()); |
655 EXPECT_EQ(initial_value, dummy.scroll_offset()); | 666 EXPECT_EQ(initial_value, dummy.scroll_offset()); |
656 | 667 |
657 controller_impl->Animate(kInitialTickTime); | 668 controller_impl->Animate(kInitialTickTime); |
658 controller_impl->UpdateState(true, events.get()); | 669 controller_impl->UpdateState(true, events.get()); |
659 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 670 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
660 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 671 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
661 // Scroll offset animations should not generate property updates. | 672 // Scroll offset animations should not generate property updates. |
662 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 673 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
663 EXPECT_FALSE(event); | 674 EXPECT_FALSE(event); |
664 | |
665 controller->NotifyAnimationStarted((*events)[0]); | 675 controller->NotifyAnimationStarted((*events)[0]); |
666 controller->Animate(kInitialTickTime + duration/2.0); | 676 controller->Animate(kInitialTickTime + time_delta / 2.0f); |
ajuma
2014/04/24 20:41:36
Note that TimeDelta doesn't have an operator/ that
Sikugu_
2014/05/05 07:09:19
Done.
| |
667 controller->UpdateState(true, NULL); | 677 controller->UpdateState(true, NULL); |
668 EXPECT_TRUE(controller->HasActiveAnimation()); | 678 EXPECT_TRUE(controller->HasActiveAnimation()); |
669 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset()); | 679 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset()); |
670 | 680 |
671 controller_impl->Animate(kInitialTickTime + duration/2.0); | 681 controller_impl->Animate(kInitialTickTime + time_delta / 2.0f); |
ajuma
2014/04/24 20:41:36
Same comment as above about division.
Sikugu_
2014/05/05 07:09:19
Done.
| |
672 controller_impl->UpdateState(true, events.get()); | 682 controller_impl->UpdateState(true, events.get()); |
673 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | 683 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), |
674 dummy_impl.scroll_offset()); | 684 dummy_impl.scroll_offset()); |
675 event = GetMostRecentPropertyUpdateEvent(events.get()); | 685 event = GetMostRecentPropertyUpdateEvent(events.get()); |
676 EXPECT_FALSE(event); | 686 EXPECT_FALSE(event); |
677 | 687 |
678 controller_impl->Animate(kInitialTickTime + duration); | 688 controller_impl->Animate(kInitialTickTime + time_delta); |
679 controller_impl->UpdateState(true, events.get()); | 689 controller_impl->UpdateState(true, events.get()); |
680 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | 690 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); |
681 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 691 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
682 event = GetMostRecentPropertyUpdateEvent(events.get()); | 692 event = GetMostRecentPropertyUpdateEvent(events.get()); |
683 EXPECT_FALSE(event); | 693 EXPECT_FALSE(event); |
684 | 694 |
685 controller->Animate(kInitialTickTime + duration); | 695 controller->Animate(kInitialTickTime + time_delta); |
686 controller->UpdateState(true, NULL); | 696 controller->UpdateState(true, NULL); |
687 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); | 697 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); |
688 EXPECT_FALSE(controller->HasActiveAnimation()); | 698 EXPECT_FALSE(controller->HasActiveAnimation()); |
689 } | 699 } |
690 | 700 |
691 // Ensure that when the impl controller doesn't have a value provider, | 701 // 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 | 702 // the main-thread controller's value provider is used to obtain the intial |
693 // scroll offset. | 703 // scroll offset. |
694 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { | 704 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { |
695 FakeLayerAnimationValueObserver dummy_impl; | 705 FakeLayerAnimationValueObserver dummy_impl; |
(...skipping 19 matching lines...) Expand all Loading... | |
715 scoped_ptr<Animation> animation(Animation::Create( | 725 scoped_ptr<Animation> animation(Animation::Create( |
716 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset)); | 726 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset)); |
717 animation->set_needs_synchronized_start_time(true); | 727 animation->set_needs_synchronized_start_time(true); |
718 controller->AddAnimation(animation.Pass()); | 728 controller->AddAnimation(animation.Pass()); |
719 | 729 |
720 dummy_provider.set_scroll_offset(initial_value); | 730 dummy_provider.set_scroll_offset(initial_value); |
721 controller->PushAnimationUpdatesTo(controller_impl.get()); | 731 controller->PushAnimationUpdatesTo(controller_impl.get()); |
722 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); | 732 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); |
723 double duration = controller_impl->GetAnimation( | 733 double duration = controller_impl->GetAnimation( |
724 Animation::ScrollOffset)->curve()->Duration(); | 734 Animation::ScrollOffset)->curve()->Duration(); |
725 | |
726 EXPECT_EQ( | 735 EXPECT_EQ( |
727 duration, | 736 duration, |
728 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); | 737 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); |
729 | 738 |
730 controller->Animate(kInitialTickTime); | 739 controller->Animate(kInitialTickTime); |
731 controller->UpdateState(true, NULL); | 740 controller->UpdateState(true, NULL); |
732 EXPECT_TRUE(controller->HasActiveAnimation()); | 741 EXPECT_TRUE(controller->HasActiveAnimation()); |
733 EXPECT_EQ(initial_value, dummy.scroll_offset()); | 742 EXPECT_EQ(initial_value, dummy.scroll_offset()); |
734 | 743 |
735 controller_impl->Animate(kInitialTickTime); | 744 controller_impl->Animate(kInitialTickTime); |
736 controller_impl->UpdateState(true, events.get()); | 745 controller_impl->UpdateState(true, events.get()); |
737 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 746 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
738 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 747 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
739 // Scroll offset animations should not generate property updates. | 748 // Scroll offset animations should not generate property updates. |
740 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 749 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
741 EXPECT_FALSE(event); | 750 EXPECT_FALSE(event); |
742 | 751 |
752 TimeDelta time_delta = TimeDelta::FromMicroseconds( | |
753 duration * base::Time::kMicrosecondsPerSecond); | |
754 | |
743 controller->NotifyAnimationStarted((*events)[0]); | 755 controller->NotifyAnimationStarted((*events)[0]); |
744 controller->Animate(kInitialTickTime + duration/2.0); | 756 controller->Animate(kInitialTickTime + time_delta / 2.0); |
ajuma
2014/04/24 20:41:36
See comment above about division.
Sikugu_
2014/05/05 07:09:19
Done.
| |
745 controller->UpdateState(true, NULL); | 757 controller->UpdateState(true, NULL); |
746 EXPECT_TRUE(controller->HasActiveAnimation()); | 758 EXPECT_TRUE(controller->HasActiveAnimation()); |
747 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset()); | 759 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset()); |
748 | 760 |
749 controller_impl->Animate(kInitialTickTime + duration/2.0); | 761 controller_impl->Animate(kInitialTickTime + time_delta / 2.0); |
ajuma
2014/04/24 20:41:36
See comment above about division.
Sikugu_
2014/05/05 07:09:19
Done.
| |
750 controller_impl->UpdateState(true, events.get()); | 762 controller_impl->UpdateState(true, events.get()); |
751 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), | 763 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), |
752 dummy_impl.scroll_offset()); | 764 dummy_impl.scroll_offset()); |
753 event = GetMostRecentPropertyUpdateEvent(events.get()); | 765 event = GetMostRecentPropertyUpdateEvent(events.get()); |
754 EXPECT_FALSE(event); | 766 EXPECT_FALSE(event); |
755 | 767 |
756 controller_impl->Animate(kInitialTickTime + duration); | 768 controller_impl->Animate(kInitialTickTime + time_delta); |
757 controller_impl->UpdateState(true, events.get()); | 769 controller_impl->UpdateState(true, events.get()); |
758 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | 770 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); |
759 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 771 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
760 event = GetMostRecentPropertyUpdateEvent(events.get()); | 772 event = GetMostRecentPropertyUpdateEvent(events.get()); |
761 EXPECT_FALSE(event); | 773 EXPECT_FALSE(event); |
762 | 774 |
763 controller->Animate(kInitialTickTime + duration); | 775 controller->Animate(kInitialTickTime + time_delta); |
764 controller->UpdateState(true, NULL); | 776 controller->UpdateState(true, NULL); |
765 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); | 777 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); |
766 EXPECT_FALSE(controller->HasActiveAnimation()); | 778 EXPECT_FALSE(controller->HasActiveAnimation()); |
767 } | 779 } |
768 | 780 |
769 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { | 781 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { |
770 FakeLayerAnimationValueObserver dummy_impl; | 782 FakeLayerAnimationValueObserver dummy_impl; |
771 scoped_refptr<LayerAnimationController> controller_impl( | 783 scoped_refptr<LayerAnimationController> controller_impl( |
772 LayerAnimationController::Create(0)); | 784 LayerAnimationController::Create(0)); |
773 controller_impl->AddValueObserver(&dummy_impl); | 785 controller_impl->AddValueObserver(&dummy_impl); |
(...skipping 15 matching lines...) Expand all Loading... | |
789 controller_impl->AddAnimation(animation.Pass()); | 801 controller_impl->AddAnimation(animation.Pass()); |
790 | 802 |
791 controller_impl->Animate(kInitialTickTime); | 803 controller_impl->Animate(kInitialTickTime); |
792 controller_impl->UpdateState(true, events.get()); | 804 controller_impl->UpdateState(true, events.get()); |
793 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 805 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
794 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 806 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
795 // Scroll offset animations should not generate property updates. | 807 // Scroll offset animations should not generate property updates. |
796 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 808 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
797 EXPECT_FALSE(event); | 809 EXPECT_FALSE(event); |
798 | 810 |
799 controller_impl->Animate(kInitialTickTime + duration/2.0); | 811 TimeDelta time_delta = TimeDelta::FromMicroseconds( |
812 duration * base::Time::kMicrosecondsPerSecond); | |
813 | |
814 controller_impl->Animate(kInitialTickTime + time_delta / 2.0); | |
ajuma
2014/04/24 20:41:36
Here too.
Sikugu_
2014/05/05 07:09:19
Done.
| |
800 controller_impl->UpdateState(true, events.get()); | 815 controller_impl->UpdateState(true, events.get()); |
801 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | 816 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), |
802 dummy_impl.scroll_offset()); | 817 dummy_impl.scroll_offset()); |
803 event = GetMostRecentPropertyUpdateEvent(events.get()); | 818 event = GetMostRecentPropertyUpdateEvent(events.get()); |
804 EXPECT_FALSE(event); | 819 EXPECT_FALSE(event); |
805 | 820 |
806 controller_impl->Animate(kInitialTickTime + duration); | 821 controller_impl->Animate(kInitialTickTime + time_delta); |
807 controller_impl->UpdateState(true, events.get()); | 822 controller_impl->UpdateState(true, events.get()); |
808 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | 823 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); |
809 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 824 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
810 event = GetMostRecentPropertyUpdateEvent(events.get()); | 825 event = GetMostRecentPropertyUpdateEvent(events.get()); |
811 EXPECT_FALSE(event); | 826 EXPECT_FALSE(event); |
812 } | 827 } |
813 | 828 |
814 class FakeAnimationDelegate : public AnimationDelegate { | 829 class FakeAnimationDelegate : public AnimationDelegate { |
815 public: | 830 public: |
816 FakeAnimationDelegate() | 831 FakeAnimationDelegate() |
817 : started_(false), | 832 : started_(false), |
818 finished_(false) {} | 833 finished_(false) {} |
819 | 834 |
820 virtual void NotifyAnimationStarted( | 835 virtual void NotifyAnimationStarted( |
821 base::TimeTicks monotonic_time, | 836 TimeTicks monotonic_time, |
822 Animation::TargetProperty target_property) OVERRIDE { | 837 Animation::TargetProperty target_property) OVERRIDE { |
823 started_ = true; | 838 started_ = true; |
824 } | 839 } |
825 | 840 |
826 virtual void NotifyAnimationFinished( | 841 virtual void NotifyAnimationFinished( |
827 base::TimeTicks monotonic_time, | 842 TimeTicks monotonic_time, |
828 Animation::TargetProperty target_property) OVERRIDE { | 843 Animation::TargetProperty target_property) OVERRIDE { |
829 finished_ = true; | 844 finished_ = true; |
830 } | 845 } |
831 | 846 |
832 bool started() { return started_; } | 847 bool started() { return started_; } |
833 | 848 |
834 bool finished() { return finished_; } | 849 bool finished() { return finished_; } |
835 | 850 |
836 private: | 851 private: |
837 bool started_; | 852 bool started_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type); | 887 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type); |
873 EXPECT_TRUE((*events)[1].is_impl_only); | 888 EXPECT_TRUE((*events)[1].is_impl_only); |
874 | 889 |
875 // Passing on the start event to the main thread controller should cause the | 890 // Passing on the start event to the main thread controller should cause the |
876 // delegate to get notified. | 891 // delegate to get notified. |
877 EXPECT_FALSE(delegate.started()); | 892 EXPECT_FALSE(delegate.started()); |
878 controller->NotifyAnimationStarted((*events)[0]); | 893 controller->NotifyAnimationStarted((*events)[0]); |
879 EXPECT_TRUE(delegate.started()); | 894 EXPECT_TRUE(delegate.started()); |
880 | 895 |
881 events.reset(new AnimationEventsVector); | 896 events.reset(new AnimationEventsVector); |
882 controller_impl->Animate(kInitialTickTime + 1.0); | 897 controller_impl->Animate(kInitialTickTime + |
898 TimeDelta::FromMilliseconds(1000)); | |
883 controller_impl->UpdateState(true, events.get()); | 899 controller_impl->UpdateState(true, events.get()); |
884 | 900 |
885 // We should receive 2 events (a finished notification and a property update). | 901 // We should receive 2 events (a finished notification and a property update). |
886 EXPECT_EQ(2u, events->size()); | 902 EXPECT_EQ(2u, events->size()); |
887 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 903 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); |
888 EXPECT_TRUE((*events)[0].is_impl_only); | 904 EXPECT_TRUE((*events)[0].is_impl_only); |
889 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type); | 905 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type); |
890 EXPECT_TRUE((*events)[1].is_impl_only); | 906 EXPECT_TRUE((*events)[1].is_impl_only); |
891 | 907 |
892 // Passing on the finished event to the main thread controller should cause | 908 // Passing on the finished event to the main thread controller should cause |
(...skipping 20 matching lines...) Expand all Loading... | |
913 Animation::Opacity)); | 929 Animation::Opacity)); |
914 to_add->set_needs_synchronized_start_time(true); | 930 to_add->set_needs_synchronized_start_time(true); |
915 | 931 |
916 // We should pause at the first keyframe indefinitely waiting for that | 932 // We should pause at the first keyframe indefinitely waiting for that |
917 // animation to start. | 933 // animation to start. |
918 controller->AddAnimation(to_add.Pass()); | 934 controller->AddAnimation(to_add.Pass()); |
919 controller->Animate(kInitialTickTime); | 935 controller->Animate(kInitialTickTime); |
920 controller->UpdateState(true, events.get()); | 936 controller->UpdateState(true, events.get()); |
921 EXPECT_TRUE(controller->HasActiveAnimation()); | 937 EXPECT_TRUE(controller->HasActiveAnimation()); |
922 EXPECT_EQ(0.f, dummy.opacity()); | 938 EXPECT_EQ(0.f, dummy.opacity()); |
923 controller->Animate(kInitialTickTime + 1.0); | 939 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
924 controller->UpdateState(true, events.get()); | 940 controller->UpdateState(true, events.get()); |
925 EXPECT_TRUE(controller->HasActiveAnimation()); | 941 EXPECT_TRUE(controller->HasActiveAnimation()); |
926 EXPECT_EQ(0.f, dummy.opacity()); | 942 EXPECT_EQ(0.f, dummy.opacity()); |
927 controller->Animate(kInitialTickTime + 2.0); | 943 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
928 controller->UpdateState(true, events.get()); | 944 controller->UpdateState(true, events.get()); |
929 EXPECT_TRUE(controller->HasActiveAnimation()); | 945 EXPECT_TRUE(controller->HasActiveAnimation()); |
930 EXPECT_EQ(0.f, dummy.opacity()); | 946 EXPECT_EQ(0.f, dummy.opacity()); |
931 | 947 |
932 // Send the synchronized start time. | 948 // Send the synchronized start time. |
933 controller->NotifyAnimationStarted(AnimationEvent( | 949 controller->NotifyAnimationStarted( |
934 AnimationEvent::Started, 0, 1, Animation::Opacity, kInitialTickTime + 2)); | 950 AnimationEvent(AnimationEvent::Started, |
935 controller->Animate(kInitialTickTime + 5.0); | 951 0, |
952 1, | |
953 Animation::Opacity, | |
954 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); | |
955 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); | |
936 controller->UpdateState(true, events.get()); | 956 controller->UpdateState(true, events.get()); |
937 EXPECT_EQ(1.f, dummy.opacity()); | 957 EXPECT_EQ(1.f, dummy.opacity()); |
938 EXPECT_FALSE(controller->HasActiveAnimation()); | 958 EXPECT_FALSE(controller->HasActiveAnimation()); |
939 } | 959 } |
940 | 960 |
941 // Tests that two queued animations affecting the same property run in sequence. | 961 // Tests that two queued animations affecting the same property run in sequence. |
942 TEST(LayerAnimationControllerTest, TrivialQueuing) { | 962 TEST(LayerAnimationControllerTest, TrivialQueuing) { |
943 scoped_ptr<AnimationEventsVector> events( | 963 scoped_ptr<AnimationEventsVector> events( |
944 make_scoped_ptr(new AnimationEventsVector)); | 964 make_scoped_ptr(new AnimationEventsVector)); |
945 FakeLayerAnimationValueObserver dummy; | 965 FakeLayerAnimationValueObserver dummy; |
946 scoped_refptr<LayerAnimationController> controller( | 966 scoped_refptr<LayerAnimationController> controller( |
947 LayerAnimationController::Create(0)); | 967 LayerAnimationController::Create(0)); |
948 controller->AddValueObserver(&dummy); | 968 controller->AddValueObserver(&dummy); |
949 | 969 |
950 controller->AddAnimation(CreateAnimation( | 970 controller->AddAnimation(CreateAnimation( |
951 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 971 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
952 1, | 972 1, |
953 Animation::Opacity)); | 973 Animation::Opacity)); |
954 controller->AddAnimation(CreateAnimation( | 974 controller->AddAnimation(CreateAnimation( |
955 scoped_ptr<AnimationCurve>( | 975 scoped_ptr<AnimationCurve>( |
956 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), | 976 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), |
957 2, | 977 2, |
958 Animation::Opacity)); | 978 Animation::Opacity)); |
959 | 979 |
960 controller->Animate(kInitialTickTime); | 980 controller->Animate(kInitialTickTime); |
961 controller->UpdateState(true, events.get()); | 981 controller->UpdateState(true, events.get()); |
962 EXPECT_TRUE(controller->HasActiveAnimation()); | 982 EXPECT_TRUE(controller->HasActiveAnimation()); |
963 EXPECT_EQ(0.f, dummy.opacity()); | 983 EXPECT_EQ(0.f, dummy.opacity()); |
964 controller->Animate(kInitialTickTime + 1.0); | 984 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
965 controller->UpdateState(true, events.get()); | 985 controller->UpdateState(true, events.get()); |
966 EXPECT_TRUE(controller->HasActiveAnimation()); | 986 EXPECT_TRUE(controller->HasActiveAnimation()); |
967 EXPECT_EQ(1.f, dummy.opacity()); | 987 EXPECT_EQ(1.f, dummy.opacity()); |
968 controller->Animate(kInitialTickTime + 2.0); | 988 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
969 controller->UpdateState(true, events.get()); | 989 controller->UpdateState(true, events.get()); |
970 EXPECT_EQ(0.5f, dummy.opacity()); | 990 EXPECT_EQ(0.5f, dummy.opacity()); |
971 EXPECT_FALSE(controller->HasActiveAnimation()); | 991 EXPECT_FALSE(controller->HasActiveAnimation()); |
972 } | 992 } |
973 | 993 |
974 // Tests interrupting a transition with another transition. | 994 // Tests interrupting a transition with another transition. |
975 TEST(LayerAnimationControllerTest, Interrupt) { | 995 TEST(LayerAnimationControllerTest, Interrupt) { |
976 scoped_ptr<AnimationEventsVector> events( | 996 scoped_ptr<AnimationEventsVector> events( |
977 make_scoped_ptr(new AnimationEventsVector)); | 997 make_scoped_ptr(new AnimationEventsVector)); |
978 FakeLayerAnimationValueObserver dummy; | 998 FakeLayerAnimationValueObserver dummy; |
(...skipping 12 matching lines...) Expand all Loading... | |
991 scoped_ptr<Animation> to_add(CreateAnimation( | 1011 scoped_ptr<Animation> to_add(CreateAnimation( |
992 scoped_ptr<AnimationCurve>( | 1012 scoped_ptr<AnimationCurve>( |
993 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), | 1013 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), |
994 2, | 1014 2, |
995 Animation::Opacity)); | 1015 Animation::Opacity)); |
996 controller->AbortAnimations(Animation::Opacity); | 1016 controller->AbortAnimations(Animation::Opacity); |
997 controller->AddAnimation(to_add.Pass()); | 1017 controller->AddAnimation(to_add.Pass()); |
998 | 1018 |
999 // Since the previous animation was aborted, the new animation should start | 1019 // Since the previous animation was aborted, the new animation should start |
1000 // right in this call to animate. | 1020 // right in this call to animate. |
1001 controller->Animate(kInitialTickTime + 0.5); | 1021 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
1002 controller->UpdateState(true, events.get()); | 1022 controller->UpdateState(true, events.get()); |
1003 EXPECT_TRUE(controller->HasActiveAnimation()); | 1023 EXPECT_TRUE(controller->HasActiveAnimation()); |
1004 EXPECT_EQ(1.f, dummy.opacity()); | 1024 EXPECT_EQ(1.f, dummy.opacity()); |
1005 controller->Animate(kInitialTickTime + 1.5); | 1025 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); |
1006 controller->UpdateState(true, events.get()); | 1026 controller->UpdateState(true, events.get()); |
1007 EXPECT_EQ(0.5f, dummy.opacity()); | 1027 EXPECT_EQ(0.5f, dummy.opacity()); |
1008 EXPECT_FALSE(controller->HasActiveAnimation()); | 1028 EXPECT_FALSE(controller->HasActiveAnimation()); |
1009 } | 1029 } |
1010 | 1030 |
1011 // Tests scheduling two animations to run together when only one property is | 1031 // Tests scheduling two animations to run together when only one property is |
1012 // free. | 1032 // free. |
1013 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { | 1033 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { |
1014 scoped_ptr<AnimationEventsVector> events( | 1034 scoped_ptr<AnimationEventsVector> events( |
1015 make_scoped_ptr(new AnimationEventsVector)); | 1035 make_scoped_ptr(new AnimationEventsVector)); |
(...skipping 12 matching lines...) Expand all Loading... | |
1028 Animation::Transform)); | 1048 Animation::Transform)); |
1029 controller->AddAnimation(CreateAnimation( | 1049 controller->AddAnimation(CreateAnimation( |
1030 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1050 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1031 2, | 1051 2, |
1032 Animation::Opacity)); | 1052 Animation::Opacity)); |
1033 | 1053 |
1034 controller->Animate(kInitialTickTime); | 1054 controller->Animate(kInitialTickTime); |
1035 controller->UpdateState(true, events.get()); | 1055 controller->UpdateState(true, events.get()); |
1036 EXPECT_EQ(0.f, dummy.opacity()); | 1056 EXPECT_EQ(0.f, dummy.opacity()); |
1037 EXPECT_TRUE(controller->HasActiveAnimation()); | 1057 EXPECT_TRUE(controller->HasActiveAnimation()); |
1038 controller->Animate(kInitialTickTime + 1.0); | 1058 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1039 controller->UpdateState(true, events.get()); | 1059 controller->UpdateState(true, events.get()); |
1040 // Should not have started the float transition yet. | 1060 // Should not have started the float transition yet. |
1041 EXPECT_TRUE(controller->HasActiveAnimation()); | 1061 EXPECT_TRUE(controller->HasActiveAnimation()); |
1042 EXPECT_EQ(0.f, dummy.opacity()); | 1062 EXPECT_EQ(0.f, dummy.opacity()); |
1043 // The float animation should have started at time 1 and should be done. | 1063 // The float animation should have started at time 1 and should be done. |
1044 controller->Animate(kInitialTickTime + 2.0); | 1064 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1045 controller->UpdateState(true, events.get()); | 1065 controller->UpdateState(true, events.get()); |
1046 EXPECT_EQ(1.f, dummy.opacity()); | 1066 EXPECT_EQ(1.f, dummy.opacity()); |
1047 EXPECT_FALSE(controller->HasActiveAnimation()); | 1067 EXPECT_FALSE(controller->HasActiveAnimation()); |
1048 } | 1068 } |
1049 | 1069 |
1050 // Tests scheduling two animations to run together with different lengths and | 1070 // Tests scheduling two animations to run together with different lengths and |
1051 // another animation queued to start when the shorter animation finishes (should | 1071 // another animation queued to start when the shorter animation finishes (should |
1052 // wait for both to finish). | 1072 // wait for both to finish). |
1053 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { | 1073 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { |
1054 scoped_ptr<AnimationEventsVector> events( | 1074 scoped_ptr<AnimationEventsVector> events( |
(...skipping 18 matching lines...) Expand all Loading... | |
1073 Animation::Opacity)); | 1093 Animation::Opacity)); |
1074 | 1094 |
1075 // Animations with id 1 should both start now. | 1095 // Animations with id 1 should both start now. |
1076 controller->Animate(kInitialTickTime); | 1096 controller->Animate(kInitialTickTime); |
1077 controller->UpdateState(true, events.get()); | 1097 controller->UpdateState(true, events.get()); |
1078 EXPECT_TRUE(controller->HasActiveAnimation()); | 1098 EXPECT_TRUE(controller->HasActiveAnimation()); |
1079 EXPECT_EQ(0.f, dummy.opacity()); | 1099 EXPECT_EQ(0.f, dummy.opacity()); |
1080 // The opacity animation should have finished at time 1, but the group | 1100 // 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 | 1101 // of animations with id 1 don't finish until time 2 because of the length |
1082 // of the transform animation. | 1102 // of the transform animation. |
1083 controller->Animate(kInitialTickTime + 2.0); | 1103 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1084 controller->UpdateState(true, events.get()); | 1104 controller->UpdateState(true, events.get()); |
1085 // Should not have started the float transition yet. | 1105 // Should not have started the float transition yet. |
1086 EXPECT_TRUE(controller->HasActiveAnimation()); | 1106 EXPECT_TRUE(controller->HasActiveAnimation()); |
1087 EXPECT_EQ(1.f, dummy.opacity()); | 1107 EXPECT_EQ(1.f, dummy.opacity()); |
1088 | 1108 |
1089 // The second opacity animation should start at time 2 and should be done by | 1109 // The second opacity animation should start at time 2 and should be done by |
1090 // time 3. | 1110 // time 3. |
1091 controller->Animate(kInitialTickTime + 3.0); | 1111 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
1092 controller->UpdateState(true, events.get()); | 1112 controller->UpdateState(true, events.get()); |
1093 EXPECT_EQ(0.5f, dummy.opacity()); | 1113 EXPECT_EQ(0.5f, dummy.opacity()); |
1094 EXPECT_FALSE(controller->HasActiveAnimation()); | 1114 EXPECT_FALSE(controller->HasActiveAnimation()); |
1095 } | 1115 } |
1096 | 1116 |
1097 // Test that a looping animation loops and for the correct number of iterations. | 1117 // Test that a looping animation loops and for the correct number of iterations. |
1098 TEST(LayerAnimationControllerTest, TrivialLooping) { | 1118 TEST(LayerAnimationControllerTest, TrivialLooping) { |
1099 scoped_ptr<AnimationEventsVector> events( | 1119 scoped_ptr<AnimationEventsVector> events( |
1100 make_scoped_ptr(new AnimationEventsVector)); | 1120 make_scoped_ptr(new AnimationEventsVector)); |
1101 FakeLayerAnimationValueObserver dummy; | 1121 FakeLayerAnimationValueObserver dummy; |
1102 scoped_refptr<LayerAnimationController> controller( | 1122 scoped_refptr<LayerAnimationController> controller( |
1103 LayerAnimationController::Create(0)); | 1123 LayerAnimationController::Create(0)); |
1104 controller->AddValueObserver(&dummy); | 1124 controller->AddValueObserver(&dummy); |
1105 | 1125 |
1106 scoped_ptr<Animation> to_add(CreateAnimation( | 1126 scoped_ptr<Animation> to_add(CreateAnimation( |
1107 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1127 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1108 1, | 1128 1, |
1109 Animation::Opacity)); | 1129 Animation::Opacity)); |
1110 to_add->set_iterations(3); | 1130 to_add->set_iterations(3); |
1111 controller->AddAnimation(to_add.Pass()); | 1131 controller->AddAnimation(to_add.Pass()); |
1112 | 1132 |
1113 controller->Animate(kInitialTickTime); | 1133 controller->Animate(kInitialTickTime); |
1114 controller->UpdateState(true, events.get()); | 1134 controller->UpdateState(true, events.get()); |
1115 EXPECT_TRUE(controller->HasActiveAnimation()); | 1135 EXPECT_TRUE(controller->HasActiveAnimation()); |
1116 EXPECT_EQ(0.f, dummy.opacity()); | 1136 EXPECT_EQ(0.f, dummy.opacity()); |
1117 controller->Animate(kInitialTickTime + 1.25); | 1137 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); |
1118 controller->UpdateState(true, events.get()); | 1138 controller->UpdateState(true, events.get()); |
1119 EXPECT_TRUE(controller->HasActiveAnimation()); | 1139 EXPECT_TRUE(controller->HasActiveAnimation()); |
1120 EXPECT_EQ(0.25f, dummy.opacity()); | 1140 EXPECT_EQ(0.25f, dummy.opacity()); |
1121 controller->Animate(kInitialTickTime + 1.75); | 1141 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); |
1122 controller->UpdateState(true, events.get()); | 1142 controller->UpdateState(true, events.get()); |
1123 EXPECT_TRUE(controller->HasActiveAnimation()); | 1143 EXPECT_TRUE(controller->HasActiveAnimation()); |
1124 EXPECT_EQ(0.75f, dummy.opacity()); | 1144 EXPECT_EQ(0.75f, dummy.opacity()); |
1125 controller->Animate(kInitialTickTime + 2.25); | 1145 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2250)); |
1126 controller->UpdateState(true, events.get()); | 1146 controller->UpdateState(true, events.get()); |
1127 EXPECT_TRUE(controller->HasActiveAnimation()); | 1147 EXPECT_TRUE(controller->HasActiveAnimation()); |
1128 EXPECT_EQ(0.25f, dummy.opacity()); | 1148 EXPECT_EQ(0.25f, dummy.opacity()); |
1129 controller->Animate(kInitialTickTime + 2.75); | 1149 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2750)); |
1130 controller->UpdateState(true, events.get()); | 1150 controller->UpdateState(true, events.get()); |
1131 EXPECT_TRUE(controller->HasActiveAnimation()); | 1151 EXPECT_TRUE(controller->HasActiveAnimation()); |
1132 EXPECT_EQ(0.75f, dummy.opacity()); | 1152 EXPECT_EQ(0.75f, dummy.opacity()); |
1133 controller->Animate(kInitialTickTime + 3.0); | 1153 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
1134 controller->UpdateState(true, events.get()); | 1154 controller->UpdateState(true, events.get()); |
1135 EXPECT_FALSE(controller->HasActiveAnimation()); | 1155 EXPECT_FALSE(controller->HasActiveAnimation()); |
1136 EXPECT_EQ(1.f, dummy.opacity()); | 1156 EXPECT_EQ(1.f, dummy.opacity()); |
1137 | 1157 |
1138 // Just be extra sure. | 1158 // Just be extra sure. |
1139 controller->Animate(kInitialTickTime + 4.0); | 1159 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); |
1140 controller->UpdateState(true, events.get()); | 1160 controller->UpdateState(true, events.get()); |
1141 EXPECT_EQ(1.f, dummy.opacity()); | 1161 EXPECT_EQ(1.f, dummy.opacity()); |
1142 } | 1162 } |
1143 | 1163 |
1144 // Test that an infinitely looping animation does indeed go until aborted. | 1164 // Test that an infinitely looping animation does indeed go until aborted. |
1145 TEST(LayerAnimationControllerTest, InfiniteLooping) { | 1165 TEST(LayerAnimationControllerTest, InfiniteLooping) { |
1146 scoped_ptr<AnimationEventsVector> events( | 1166 scoped_ptr<AnimationEventsVector> events( |
1147 make_scoped_ptr(new AnimationEventsVector)); | 1167 make_scoped_ptr(new AnimationEventsVector)); |
1148 FakeLayerAnimationValueObserver dummy; | 1168 FakeLayerAnimationValueObserver dummy; |
1149 scoped_refptr<LayerAnimationController> controller( | 1169 scoped_refptr<LayerAnimationController> controller( |
1150 LayerAnimationController::Create(0)); | 1170 LayerAnimationController::Create(0)); |
1151 controller->AddValueObserver(&dummy); | 1171 controller->AddValueObserver(&dummy); |
1152 | 1172 |
1153 const int id = 1; | 1173 const int id = 1; |
1154 scoped_ptr<Animation> to_add(CreateAnimation( | 1174 scoped_ptr<Animation> to_add(CreateAnimation( |
1155 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1175 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1156 id, | 1176 id, |
1157 Animation::Opacity)); | 1177 Animation::Opacity)); |
1158 to_add->set_iterations(-1); | 1178 to_add->set_iterations(-1); |
1159 controller->AddAnimation(to_add.Pass()); | 1179 controller->AddAnimation(to_add.Pass()); |
1160 | 1180 |
1161 controller->Animate(kInitialTickTime); | 1181 controller->Animate(kInitialTickTime); |
1162 controller->UpdateState(true, events.get()); | 1182 controller->UpdateState(true, events.get()); |
1163 EXPECT_TRUE(controller->HasActiveAnimation()); | 1183 EXPECT_TRUE(controller->HasActiveAnimation()); |
1164 EXPECT_EQ(0.f, dummy.opacity()); | 1184 EXPECT_EQ(0.f, dummy.opacity()); |
1165 controller->Animate(kInitialTickTime + 1.25); | 1185 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); |
1166 controller->UpdateState(true, events.get()); | 1186 controller->UpdateState(true, events.get()); |
1167 EXPECT_TRUE(controller->HasActiveAnimation()); | 1187 EXPECT_TRUE(controller->HasActiveAnimation()); |
1168 EXPECT_EQ(0.25f, dummy.opacity()); | 1188 EXPECT_EQ(0.25f, dummy.opacity()); |
1169 controller->Animate(kInitialTickTime + 1.75); | 1189 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); |
1170 controller->UpdateState(true, events.get()); | 1190 controller->UpdateState(true, events.get()); |
1171 EXPECT_TRUE(controller->HasActiveAnimation()); | 1191 EXPECT_TRUE(controller->HasActiveAnimation()); |
1172 EXPECT_EQ(0.75f, dummy.opacity()); | 1192 EXPECT_EQ(0.75f, dummy.opacity()); |
1173 | 1193 |
1174 controller->Animate(kInitialTickTime + 1073741824.25); | 1194 controller->Animate(kInitialTickTime + |
1195 TimeDelta::FromMilliseconds(1073741824250)); | |
1175 controller->UpdateState(true, events.get()); | 1196 controller->UpdateState(true, events.get()); |
1176 EXPECT_TRUE(controller->HasActiveAnimation()); | 1197 EXPECT_TRUE(controller->HasActiveAnimation()); |
1177 EXPECT_EQ(0.25f, dummy.opacity()); | 1198 EXPECT_EQ(0.25f, dummy.opacity()); |
1178 controller->Animate(kInitialTickTime + 1073741824.75); | 1199 controller->Animate(kInitialTickTime + |
1200 TimeDelta::FromMilliseconds(1073741824750)); | |
1179 controller->UpdateState(true, events.get()); | 1201 controller->UpdateState(true, events.get()); |
1180 EXPECT_TRUE(controller->HasActiveAnimation()); | 1202 EXPECT_TRUE(controller->HasActiveAnimation()); |
1181 EXPECT_EQ(0.75f, dummy.opacity()); | 1203 EXPECT_EQ(0.75f, dummy.opacity()); |
1182 | 1204 |
1183 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); | 1205 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
1184 controller->GetAnimation(id, Animation::Opacity)->SetRunState( | 1206 controller->GetAnimation(id, Animation::Opacity)->SetRunState( |
1185 Animation::Aborted, kInitialTickTime + 0.75); | 1207 Animation::Aborted, kInitialTickTime + TimeDelta::FromMilliseconds(750)); |
1186 EXPECT_FALSE(controller->HasActiveAnimation()); | 1208 EXPECT_FALSE(controller->HasActiveAnimation()); |
1187 EXPECT_EQ(0.75f, dummy.opacity()); | 1209 EXPECT_EQ(0.75f, dummy.opacity()); |
1188 } | 1210 } |
1189 | 1211 |
1190 // Test that pausing and resuming work as expected. | 1212 // Test that pausing and resuming work as expected. |
1191 TEST(LayerAnimationControllerTest, PauseResume) { | 1213 TEST(LayerAnimationControllerTest, PauseResume) { |
1192 scoped_ptr<AnimationEventsVector> events( | 1214 scoped_ptr<AnimationEventsVector> events( |
1193 make_scoped_ptr(new AnimationEventsVector)); | 1215 make_scoped_ptr(new AnimationEventsVector)); |
1194 FakeLayerAnimationValueObserver dummy; | 1216 FakeLayerAnimationValueObserver dummy; |
1195 scoped_refptr<LayerAnimationController> controller( | 1217 scoped_refptr<LayerAnimationController> controller( |
1196 LayerAnimationController::Create(0)); | 1218 LayerAnimationController::Create(0)); |
1197 controller->AddValueObserver(&dummy); | 1219 controller->AddValueObserver(&dummy); |
1198 | 1220 |
1199 const int id = 1; | 1221 const int id = 1; |
1200 controller->AddAnimation(CreateAnimation( | 1222 controller->AddAnimation(CreateAnimation( |
1201 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1223 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1202 id, | 1224 id, |
1203 Animation::Opacity)); | 1225 Animation::Opacity)); |
1204 | 1226 |
1205 controller->Animate(kInitialTickTime); | 1227 controller->Animate(kInitialTickTime); |
1206 controller->UpdateState(true, events.get()); | 1228 controller->UpdateState(true, events.get()); |
1207 EXPECT_TRUE(controller->HasActiveAnimation()); | 1229 EXPECT_TRUE(controller->HasActiveAnimation()); |
1208 EXPECT_EQ(0.f, dummy.opacity()); | 1230 EXPECT_EQ(0.f, dummy.opacity()); |
1209 controller->Animate(kInitialTickTime + 0.5); | 1231 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
1210 controller->UpdateState(true, events.get()); | 1232 controller->UpdateState(true, events.get()); |
1211 EXPECT_TRUE(controller->HasActiveAnimation()); | 1233 EXPECT_TRUE(controller->HasActiveAnimation()); |
1212 EXPECT_EQ(0.5f, dummy.opacity()); | 1234 EXPECT_EQ(0.5f, dummy.opacity()); |
1213 | 1235 |
1214 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); | 1236 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
1215 controller->GetAnimation(id, Animation::Opacity)->SetRunState( | 1237 controller->GetAnimation(id, Animation::Opacity)->SetRunState( |
1216 Animation::Paused, kInitialTickTime + 0.5); | 1238 Animation::Paused, kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
1217 | 1239 |
1218 controller->Animate(kInitialTickTime + 1024.0); | 1240 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); |
1219 controller->UpdateState(true, events.get()); | 1241 controller->UpdateState(true, events.get()); |
1220 EXPECT_TRUE(controller->HasActiveAnimation()); | 1242 EXPECT_TRUE(controller->HasActiveAnimation()); |
1221 EXPECT_EQ(0.5f, dummy.opacity()); | 1243 EXPECT_EQ(0.5f, dummy.opacity()); |
1222 | 1244 |
1223 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); | 1245 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
1224 controller->GetAnimation(id, Animation::Opacity)->SetRunState( | 1246 controller->GetAnimation(id, Animation::Opacity) |
1225 Animation::Running, kInitialTickTime + 1024); | 1247 ->SetRunState(Animation::Running, |
1226 | 1248 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); |
1227 controller->Animate(kInitialTickTime + 1024.25); | 1249 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250)); |
1228 controller->UpdateState(true, events.get()); | 1250 controller->UpdateState(true, events.get()); |
1229 EXPECT_TRUE(controller->HasActiveAnimation()); | 1251 EXPECT_TRUE(controller->HasActiveAnimation()); |
1230 EXPECT_EQ(0.75f, dummy.opacity()); | 1252 EXPECT_EQ(0.75f, dummy.opacity()); |
1231 controller->Animate(kInitialTickTime + 1024.5); | 1253 |
1254 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); | |
1232 controller->UpdateState(true, events.get()); | 1255 controller->UpdateState(true, events.get()); |
1233 EXPECT_FALSE(controller->HasActiveAnimation()); | 1256 EXPECT_FALSE(controller->HasActiveAnimation()); |
1234 EXPECT_EQ(1.f, dummy.opacity()); | 1257 EXPECT_EQ(1.f, dummy.opacity()); |
1235 } | 1258 } |
1236 | 1259 |
1237 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { | 1260 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { |
1238 scoped_ptr<AnimationEventsVector> events( | 1261 scoped_ptr<AnimationEventsVector> events( |
1239 make_scoped_ptr(new AnimationEventsVector)); | 1262 make_scoped_ptr(new AnimationEventsVector)); |
1240 FakeLayerAnimationValueObserver dummy; | 1263 FakeLayerAnimationValueObserver dummy; |
1241 scoped_refptr<LayerAnimationController> controller( | 1264 scoped_refptr<LayerAnimationController> controller( |
(...skipping 12 matching lines...) Expand all Loading... | |
1254 controller->AddAnimation(CreateAnimation( | 1277 controller->AddAnimation(CreateAnimation( |
1255 scoped_ptr<AnimationCurve>( | 1278 scoped_ptr<AnimationCurve>( |
1256 new FakeFloatTransition(1.0, 1.f, 0.75f)).Pass(), | 1279 new FakeFloatTransition(1.0, 1.f, 0.75f)).Pass(), |
1257 2, | 1280 2, |
1258 Animation::Opacity)); | 1281 Animation::Opacity)); |
1259 | 1282 |
1260 controller->Animate(kInitialTickTime); | 1283 controller->Animate(kInitialTickTime); |
1261 controller->UpdateState(true, events.get()); | 1284 controller->UpdateState(true, events.get()); |
1262 EXPECT_TRUE(controller->HasActiveAnimation()); | 1285 EXPECT_TRUE(controller->HasActiveAnimation()); |
1263 EXPECT_EQ(0.f, dummy.opacity()); | 1286 EXPECT_EQ(0.f, dummy.opacity()); |
1264 controller->Animate(kInitialTickTime + 1.0); | 1287 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1265 controller->UpdateState(true, events.get()); | 1288 controller->UpdateState(true, events.get()); |
1266 EXPECT_TRUE(controller->HasActiveAnimation()); | 1289 EXPECT_TRUE(controller->HasActiveAnimation()); |
1267 EXPECT_EQ(0.5f, dummy.opacity()); | 1290 EXPECT_EQ(0.5f, dummy.opacity()); |
1268 | 1291 |
1269 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); | 1292 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
1270 controller->GetAnimation(id, Animation::Opacity)->SetRunState( | 1293 controller->GetAnimation(id, Animation::Opacity)->SetRunState( |
1271 Animation::Aborted, kInitialTickTime + 1.0); | 1294 Animation::Aborted, kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1272 controller->Animate(kInitialTickTime + 1.0); | 1295 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1273 controller->UpdateState(true, events.get()); | 1296 controller->UpdateState(true, events.get()); |
1274 EXPECT_TRUE(controller->HasActiveAnimation()); | 1297 EXPECT_TRUE(controller->HasActiveAnimation()); |
1275 EXPECT_EQ(1.f, dummy.opacity()); | 1298 EXPECT_EQ(1.f, dummy.opacity()); |
1276 controller->Animate(kInitialTickTime + 2.0); | 1299 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1277 controller->UpdateState(true, events.get()); | 1300 controller->UpdateState(true, events.get()); |
1278 EXPECT_TRUE(!controller->HasActiveAnimation()); | 1301 EXPECT_TRUE(!controller->HasActiveAnimation()); |
1279 EXPECT_EQ(0.75f, dummy.opacity()); | 1302 EXPECT_EQ(0.75f, dummy.opacity()); |
1280 } | 1303 } |
1281 | 1304 |
1282 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { | 1305 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { |
1283 FakeLayerAnimationValueObserver dummy_impl; | 1306 FakeLayerAnimationValueObserver dummy_impl; |
1284 scoped_refptr<LayerAnimationController> controller_impl( | 1307 scoped_refptr<LayerAnimationController> controller_impl( |
1285 LayerAnimationController::Create(0)); | 1308 LayerAnimationController::Create(0)); |
1286 controller_impl->AddValueObserver(&dummy_impl); | 1309 controller_impl->AddValueObserver(&dummy_impl); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1329 | 1352 |
1330 controller->Animate(kInitialTickTime); | 1353 controller->Animate(kInitialTickTime); |
1331 controller->UpdateState(true, events.get()); | 1354 controller->UpdateState(true, events.get()); |
1332 | 1355 |
1333 controller->AddAnimation(CreateAnimation( | 1356 controller->AddAnimation(CreateAnimation( |
1334 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1357 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1335 2, | 1358 2, |
1336 Animation::Opacity)); | 1359 Animation::Opacity)); |
1337 | 1360 |
1338 // Animate but don't UpdateState. | 1361 // Animate but don't UpdateState. |
1339 controller->Animate(kInitialTickTime + 1.0); | 1362 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1340 | 1363 |
1341 controller->Animate(kInitialTickTime + 2.0); | 1364 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1342 events.reset(new AnimationEventsVector); | 1365 events.reset(new AnimationEventsVector); |
1343 controller->UpdateState(true, events.get()); | 1366 controller->UpdateState(true, events.get()); |
1344 | 1367 |
1345 // Should have one Started event and one Finished event. | 1368 // Should have one Started event and one Finished event. |
1346 EXPECT_EQ(2u, events->size()); | 1369 EXPECT_EQ(2u, events->size()); |
1347 EXPECT_NE((*events)[0].type, (*events)[1].type); | 1370 EXPECT_NE((*events)[0].type, (*events)[1].type); |
1348 | 1371 |
1349 // The float transition should still be at its starting point. | 1372 // The float transition should still be at its starting point. |
1350 EXPECT_TRUE(controller->HasActiveAnimation()); | 1373 EXPECT_TRUE(controller->HasActiveAnimation()); |
1351 EXPECT_EQ(0.f, dummy.opacity()); | 1374 EXPECT_EQ(0.f, dummy.opacity()); |
1352 | 1375 |
1353 controller->Animate(kInitialTickTime + 3.0); | 1376 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
1354 controller->UpdateState(true, events.get()); | 1377 controller->UpdateState(true, events.get()); |
1355 | 1378 |
1356 // The float tranisition should now be done. | 1379 // The float tranisition should now be done. |
1357 EXPECT_EQ(1.f, dummy.opacity()); | 1380 EXPECT_EQ(1.f, dummy.opacity()); |
1358 EXPECT_FALSE(controller->HasActiveAnimation()); | 1381 EXPECT_FALSE(controller->HasActiveAnimation()); |
1359 } | 1382 } |
1360 | 1383 |
1361 // Tests that an animation controller with only an inactive observer gets ticked | 1384 // Tests that an animation controller with only an inactive observer gets ticked |
1362 // but doesn't progress animations past the Starting state. | 1385 // but doesn't progress animations past the Starting state. |
1363 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { | 1386 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { |
(...skipping 16 matching lines...) Expand all Loading... | |
1380 controller->UpdateState(true, events.get()); | 1403 controller->UpdateState(true, events.get()); |
1381 EXPECT_EQ(0u, events->size()); | 1404 EXPECT_EQ(0u, events->size()); |
1382 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 1405 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
1383 controller->GetAnimation(id, Animation::Opacity)->run_state()); | 1406 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
1384 | 1407 |
1385 controller->AddValueObserver(&inactive_dummy); | 1408 controller->AddValueObserver(&inactive_dummy); |
1386 | 1409 |
1387 // With only an inactive observer, the animation should progress to the | 1410 // With only an inactive observer, the animation should progress to the |
1388 // Starting state and get ticked at its starting point, but should not | 1411 // Starting state and get ticked at its starting point, but should not |
1389 // progress to Running. | 1412 // progress to Running. |
1390 controller->Animate(kInitialTickTime + 1.0); | 1413 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1391 controller->UpdateState(true, events.get()); | 1414 controller->UpdateState(true, events.get()); |
1392 EXPECT_EQ(0u, events->size()); | 1415 EXPECT_EQ(0u, events->size()); |
1393 EXPECT_EQ(Animation::Starting, | 1416 EXPECT_EQ(Animation::Starting, |
1394 controller->GetAnimation(id, Animation::Opacity)->run_state()); | 1417 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
1395 EXPECT_EQ(0.5f, inactive_dummy.opacity()); | 1418 EXPECT_EQ(0.5f, inactive_dummy.opacity()); |
1396 | 1419 |
1397 // Even when already in the Starting state, the animation should stay | 1420 // Even when already in the Starting state, the animation should stay |
1398 // there, and shouldn't be ticked past its starting point. | 1421 // there, and shouldn't be ticked past its starting point. |
1399 controller->Animate(kInitialTickTime + 2.0); | 1422 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1400 controller->UpdateState(true, events.get()); | 1423 controller->UpdateState(true, events.get()); |
1401 EXPECT_EQ(0u, events->size()); | 1424 EXPECT_EQ(0u, events->size()); |
1402 EXPECT_EQ(Animation::Starting, | 1425 EXPECT_EQ(Animation::Starting, |
1403 controller->GetAnimation(id, Animation::Opacity)->run_state()); | 1426 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
1404 EXPECT_EQ(0.5f, inactive_dummy.opacity()); | 1427 EXPECT_EQ(0.5f, inactive_dummy.opacity()); |
1405 | 1428 |
1406 controller->AddValueObserver(&dummy); | 1429 controller->AddValueObserver(&dummy); |
1407 | 1430 |
1408 // Now that an active observer has been added, the animation should still | 1431 // 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. | 1432 // initially tick at its starting point, but should now progress to Running. |
1410 controller->Animate(kInitialTickTime + 3.0); | 1433 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
1411 controller->UpdateState(true, events.get()); | 1434 controller->UpdateState(true, events.get()); |
1412 EXPECT_EQ(1u, events->size()); | 1435 EXPECT_EQ(1u, events->size()); |
1413 EXPECT_EQ(Animation::Running, | 1436 EXPECT_EQ(Animation::Running, |
1414 controller->GetAnimation(id, Animation::Opacity)->run_state()); | 1437 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
1415 EXPECT_EQ(0.5f, inactive_dummy.opacity()); | 1438 EXPECT_EQ(0.5f, inactive_dummy.opacity()); |
1416 EXPECT_EQ(0.5f, dummy.opacity()); | 1439 EXPECT_EQ(0.5f, dummy.opacity()); |
1417 | 1440 |
1418 // The animation should now tick past its starting point. | 1441 // The animation should now tick past its starting point. |
1419 controller->Animate(kInitialTickTime + 3.5); | 1442 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); |
1420 EXPECT_NE(0.5f, inactive_dummy.opacity()); | 1443 EXPECT_NE(0.5f, inactive_dummy.opacity()); |
1421 EXPECT_NE(0.5f, dummy.opacity()); | 1444 EXPECT_NE(0.5f, dummy.opacity()); |
1422 } | 1445 } |
1423 | 1446 |
1424 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { | 1447 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { |
1425 scoped_refptr<LayerAnimationController> controller_impl( | 1448 scoped_refptr<LayerAnimationController> controller_impl( |
1426 LayerAnimationController::Create(0)); | 1449 LayerAnimationController::Create(0)); |
1427 | 1450 |
1428 scoped_ptr<KeyframedTransformAnimationCurve> curve1( | 1451 scoped_ptr<KeyframedTransformAnimationCurve> curve1( |
1429 KeyframedTransformAnimationCurve::Create()); | 1452 KeyframedTransformAnimationCurve::Create()); |
(...skipping 24 matching lines...) Expand all Loading... | |
1454 controller_impl->AddAnimation(animation.Pass()); | 1477 controller_impl->AddAnimation(animation.Pass()); |
1455 | 1478 |
1456 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f); | 1479 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f); |
1457 gfx::BoxF bounds; | 1480 gfx::BoxF bounds; |
1458 | 1481 |
1459 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); | 1482 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); |
1460 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(), | 1483 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(), |
1461 bounds.ToString()); | 1484 bounds.ToString()); |
1462 | 1485 |
1463 controller_impl->GetAnimation(1, Animation::Transform) | 1486 controller_impl->GetAnimation(1, Animation::Transform) |
1464 ->SetRunState(Animation::Finished, 0.0); | 1487 ->SetRunState(Animation::Finished, TimeTicks::FromSeconds(0.0)); |
1465 | 1488 |
1466 // Only the unfinished animation should affect the animated bounds. | 1489 // Only the unfinished animation should affect the animated bounds. |
1467 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); | 1490 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); |
1468 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(), | 1491 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(), |
1469 bounds.ToString()); | 1492 bounds.ToString()); |
1470 | 1493 |
1471 controller_impl->GetAnimation(2, Animation::Transform) | 1494 controller_impl->GetAnimation(2, Animation::Transform) |
1472 ->SetRunState(Animation::Finished, 0.0); | 1495 ->SetRunState(Animation::Finished, TimeTicks::FromSeconds(0.0)); |
1473 | 1496 |
1474 // There are no longer any running animations. | 1497 // There are no longer any running animations. |
1475 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds()); | 1498 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds()); |
1476 | 1499 |
1477 // Add an animation whose bounds we don't yet support computing. | 1500 // Add an animation whose bounds we don't yet support computing. |
1478 scoped_ptr<KeyframedTransformAnimationCurve> curve3( | 1501 scoped_ptr<KeyframedTransformAnimationCurve> curve3( |
1479 KeyframedTransformAnimationCurve::Create()); | 1502 KeyframedTransformAnimationCurve::Create()); |
1480 TransformOperations operations3; | 1503 TransformOperations operations3; |
1481 gfx::Transform transform3; | 1504 gfx::Transform transform3; |
1482 transform3.Scale3d(1.0, 2.0, 3.0); | 1505 transform3.Scale3d(1.0, 2.0, 3.0); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1517 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), | 1540 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), |
1518 4, | 1541 4, |
1519 Animation::Transform)); | 1542 Animation::Transform)); |
1520 controller->AddAnimation(CreateAnimation( | 1543 controller->AddAnimation(CreateAnimation( |
1521 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1544 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
1522 5, | 1545 5, |
1523 Animation::Opacity)); | 1546 Animation::Opacity)); |
1524 | 1547 |
1525 controller->Animate(kInitialTickTime); | 1548 controller->Animate(kInitialTickTime); |
1526 controller->UpdateState(true, NULL); | 1549 controller->UpdateState(true, NULL); |
1527 controller->Animate(kInitialTickTime + 1.0); | 1550 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1528 controller->UpdateState(true, NULL); | 1551 controller->UpdateState(true, NULL); |
1529 | 1552 |
1530 EXPECT_EQ(Animation::Finished, | 1553 EXPECT_EQ(Animation::Finished, |
1531 controller->GetAnimation(1, Animation::Transform)->run_state()); | 1554 controller->GetAnimation(1, Animation::Transform)->run_state()); |
1532 EXPECT_EQ(Animation::Finished, | 1555 EXPECT_EQ(Animation::Finished, |
1533 controller->GetAnimation(2, Animation::Opacity)->run_state()); | 1556 controller->GetAnimation(2, Animation::Opacity)->run_state()); |
1534 EXPECT_EQ(Animation::Running, | 1557 EXPECT_EQ(Animation::Running, |
1535 controller->GetAnimation(3, Animation::Transform)->run_state()); | 1558 controller->GetAnimation(3, Animation::Transform)->run_state()); |
1536 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 1559 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
1537 controller->GetAnimation(4, Animation::Transform)->run_state()); | 1560 controller->GetAnimation(4, Animation::Transform)->run_state()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1616 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | 1639 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); |
1617 EXPECT_EQ(1u, events.size()); | 1640 EXPECT_EQ(1u, events.size()); |
1618 EXPECT_EQ(AnimationEvent::Aborted, events[0].type); | 1641 EXPECT_EQ(AnimationEvent::Aborted, events[0].type); |
1619 EXPECT_EQ(Animation::WaitingForDeletion, | 1642 EXPECT_EQ(Animation::WaitingForDeletion, |
1620 controller_impl->GetAnimation(Animation::Opacity)->run_state()); | 1643 controller_impl->GetAnimation(Animation::Opacity)->run_state()); |
1621 | 1644 |
1622 controller->NotifyAnimationAborted(events[0]); | 1645 controller->NotifyAnimationAborted(events[0]); |
1623 EXPECT_EQ(Animation::Aborted, | 1646 EXPECT_EQ(Animation::Aborted, |
1624 controller->GetAnimation(Animation::Opacity)->run_state()); | 1647 controller->GetAnimation(Animation::Opacity)->run_state()); |
1625 | 1648 |
1626 controller->Animate(kInitialTickTime + 0.5); | 1649 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
1627 controller->UpdateState(true, NULL); | 1650 controller->UpdateState(true, NULL); |
1628 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 1651 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
1629 EXPECT_EQ(Animation::WaitingForDeletion, | 1652 EXPECT_EQ(Animation::WaitingForDeletion, |
1630 controller->GetAnimation(Animation::Opacity)->run_state()); | 1653 controller->GetAnimation(Animation::Opacity)->run_state()); |
1631 | 1654 |
1632 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1655 controller->PushAnimationUpdatesTo(controller_impl.get()); |
1633 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity)); | 1656 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity)); |
1634 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); | 1657 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); |
1635 } | 1658 } |
1636 | 1659 |
(...skipping 19 matching lines...) Expand all Loading... | |
1656 | 1679 |
1657 controller_impl->Animate(kInitialTickTime); | 1680 controller_impl->Animate(kInitialTickTime); |
1658 controller_impl->UpdateState(true, events.get()); | 1681 controller_impl->UpdateState(true, events.get()); |
1659 | 1682 |
1660 // Both animations should have started. | 1683 // Both animations should have started. |
1661 EXPECT_EQ(2u, events->size()); | 1684 EXPECT_EQ(2u, events->size()); |
1662 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); | 1685 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); |
1663 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); | 1686 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); |
1664 | 1687 |
1665 events.reset(new AnimationEventsVector); | 1688 events.reset(new AnimationEventsVector); |
1666 controller_impl->Animate(kInitialTickTime + 1.0); | 1689 controller_impl->Animate(kInitialTickTime + |
1690 TimeDelta::FromMilliseconds(1000)); | |
1667 controller_impl->UpdateState(true, events.get()); | 1691 controller_impl->UpdateState(true, events.get()); |
1668 | 1692 |
1669 // The opacity animation should be finished, but should not have generated | 1693 // The opacity animation should be finished, but should not have generated |
1670 // a Finished event yet. | 1694 // a Finished event yet. |
1671 EXPECT_EQ(0u, events->size()); | 1695 EXPECT_EQ(0u, events->size()); |
1672 EXPECT_EQ(Animation::Finished, | 1696 EXPECT_EQ(Animation::Finished, |
1673 controller_impl->GetAnimation(1, Animation::Opacity)->run_state()); | 1697 controller_impl->GetAnimation(1, Animation::Opacity)->run_state()); |
1674 EXPECT_EQ(Animation::Running, | 1698 EXPECT_EQ(Animation::Running, |
1675 controller_impl->GetAnimation(1, | 1699 controller_impl->GetAnimation(1, |
1676 Animation::Transform)->run_state()); | 1700 Animation::Transform)->run_state()); |
1677 | 1701 |
1678 controller_impl->Animate(kInitialTickTime + 2.0); | 1702 controller_impl->Animate(kInitialTickTime + |
1703 TimeDelta::FromMilliseconds(2000)); | |
1679 controller_impl->UpdateState(true, events.get()); | 1704 controller_impl->UpdateState(true, events.get()); |
1680 | 1705 |
1681 // Both animations should have generated Finished events. | 1706 // Both animations should have generated Finished events. |
1682 EXPECT_EQ(2u, events->size()); | 1707 EXPECT_EQ(2u, events->size()); |
1683 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 1708 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); |
1684 EXPECT_EQ(AnimationEvent::Finished, (*events)[1].type); | 1709 EXPECT_EQ(AnimationEvent::Finished, (*events)[1].type); |
1685 } | 1710 } |
1686 | 1711 |
1687 // Ensure that when a group has a mix of aborted and finished animations, | 1712 // 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 | 1713 // we generate a Finished event for the finished animation and an Aborted |
(...skipping 20 matching lines...) Expand all Loading... | |
1709 controller_impl->UpdateState(true, events.get()); | 1734 controller_impl->UpdateState(true, events.get()); |
1710 | 1735 |
1711 // Both animations should have started. | 1736 // Both animations should have started. |
1712 EXPECT_EQ(2u, events->size()); | 1737 EXPECT_EQ(2u, events->size()); |
1713 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); | 1738 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); |
1714 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); | 1739 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); |
1715 | 1740 |
1716 controller_impl->AbortAnimations(Animation::Opacity); | 1741 controller_impl->AbortAnimations(Animation::Opacity); |
1717 | 1742 |
1718 events.reset(new AnimationEventsVector); | 1743 events.reset(new AnimationEventsVector); |
1719 controller_impl->Animate(kInitialTickTime + 1.0); | 1744 controller_impl->Animate(kInitialTickTime + |
1745 TimeDelta::FromMilliseconds(1000)); | |
1720 controller_impl->UpdateState(true, events.get()); | 1746 controller_impl->UpdateState(true, events.get()); |
1721 | 1747 |
1722 // We should have exactly 2 events: a Finished event for the tranform | 1748 // We should have exactly 2 events: a Finished event for the tranform |
1723 // animation, and an Aborted event for the opacity animation. | 1749 // animation, and an Aborted event for the opacity animation. |
1724 EXPECT_EQ(2u, events->size()); | 1750 EXPECT_EQ(2u, events->size()); |
1725 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 1751 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); |
1726 EXPECT_EQ(Animation::Transform, (*events)[0].target_property); | 1752 EXPECT_EQ(Animation::Transform, (*events)[0].target_property); |
1727 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type); | 1753 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type); |
1728 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property); | 1754 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property); |
1729 } | 1755 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1769 curve2->AddKeyframe(TransformKeyframe::Create( | 1795 curve2->AddKeyframe(TransformKeyframe::Create( |
1770 1.0, operations2, scoped_ptr<TimingFunction>())); | 1796 1.0, operations2, scoped_ptr<TimingFunction>())); |
1771 | 1797 |
1772 animation = Animation::Create( | 1798 animation = Animation::Create( |
1773 curve2.PassAs<AnimationCurve>(), 3, 3, Animation::Transform); | 1799 curve2.PassAs<AnimationCurve>(), 3, 3, Animation::Transform); |
1774 controller_impl->AddAnimation(animation.Pass()); | 1800 controller_impl->AddAnimation(animation.Pass()); |
1775 | 1801 |
1776 EXPECT_TRUE(controller_impl->HasAnimationThatAffectsScale()); | 1802 EXPECT_TRUE(controller_impl->HasAnimationThatAffectsScale()); |
1777 | 1803 |
1778 controller_impl->GetAnimation(3, Animation::Transform) | 1804 controller_impl->GetAnimation(3, Animation::Transform) |
1779 ->SetRunState(Animation::Finished, 0.0); | 1805 ->SetRunState(Animation::Finished, TimeTicks::FromSeconds(0.0)); |
1780 | 1806 |
1781 // Only unfinished animations should be considered by | 1807 // Only unfinished animations should be considered by |
1782 // HasAnimationThatAffectsScale. | 1808 // HasAnimationThatAffectsScale. |
1783 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); | 1809 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); |
1784 } | 1810 } |
1785 | 1811 |
1786 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) { | 1812 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) { |
1787 scoped_refptr<LayerAnimationController> controller_impl( | 1813 scoped_refptr<LayerAnimationController> controller_impl( |
1788 LayerAnimationController::Create(0)); | 1814 LayerAnimationController::Create(0)); |
1789 | 1815 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1825 1.0, operations2, scoped_ptr<TimingFunction>())); | 1851 1.0, operations2, scoped_ptr<TimingFunction>())); |
1826 | 1852 |
1827 animation = Animation::Create( | 1853 animation = Animation::Create( |
1828 curve2.PassAs<AnimationCurve>(), 3, 3, Animation::Transform); | 1854 curve2.PassAs<AnimationCurve>(), 3, 3, Animation::Transform); |
1829 controller_impl->AddAnimation(animation.Pass()); | 1855 controller_impl->AddAnimation(animation.Pass()); |
1830 | 1856 |
1831 // A scale animation is not a translation. | 1857 // A scale animation is not a translation. |
1832 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms()); | 1858 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms()); |
1833 | 1859 |
1834 controller_impl->GetAnimation(3, Animation::Transform) | 1860 controller_impl->GetAnimation(3, Animation::Transform) |
1835 ->SetRunState(Animation::Finished, 0.0); | 1861 ->SetRunState(Animation::Finished, TimeTicks::FromSeconds(0.0)); |
1836 | 1862 |
1837 // Only unfinished animations should be considered by | 1863 // Only unfinished animations should be considered by |
1838 // HasOnlyTranslationTransforms. | 1864 // HasOnlyTranslationTransforms. |
1839 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); | 1865 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); |
1840 } | 1866 } |
1841 | 1867 |
1842 TEST(LayerAnimationControllerTest, MaximumScale) { | 1868 TEST(LayerAnimationControllerTest, MaximumScale) { |
1843 scoped_refptr<LayerAnimationController> controller_impl( | 1869 scoped_refptr<LayerAnimationController> controller_impl( |
1844 LayerAnimationController::Create(0)); | 1870 LayerAnimationController::Create(0)); |
1845 | 1871 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1891 curve3->AddKeyframe(TransformKeyframe::Create( | 1917 curve3->AddKeyframe(TransformKeyframe::Create( |
1892 1.0, operations3, scoped_ptr<TimingFunction>())); | 1918 1.0, operations3, scoped_ptr<TimingFunction>())); |
1893 | 1919 |
1894 animation = Animation::Create( | 1920 animation = Animation::Create( |
1895 curve3.PassAs<AnimationCurve>(), 3, 3, Animation::Transform); | 1921 curve3.PassAs<AnimationCurve>(), 3, 3, Animation::Transform); |
1896 controller_impl->AddAnimation(animation.Pass()); | 1922 controller_impl->AddAnimation(animation.Pass()); |
1897 | 1923 |
1898 EXPECT_FALSE(controller_impl->MaximumScale(&max_scale)); | 1924 EXPECT_FALSE(controller_impl->MaximumScale(&max_scale)); |
1899 | 1925 |
1900 controller_impl->GetAnimation(3, Animation::Transform) | 1926 controller_impl->GetAnimation(3, Animation::Transform) |
1901 ->SetRunState(Animation::Finished, 0.0); | 1927 ->SetRunState(Animation::Finished, TimeTicks::FromSeconds(0.0)); |
1902 controller_impl->GetAnimation(2, Animation::Transform) | 1928 controller_impl->GetAnimation(2, Animation::Transform) |
1903 ->SetRunState(Animation::Finished, 0.0); | 1929 ->SetRunState(Animation::Finished, TimeTicks::FromSeconds(0.0)); |
1904 | 1930 |
1905 // Only unfinished animations should be considered by | 1931 // Only unfinished animations should be considered by |
1906 // MaximumScale. | 1932 // MaximumScale. |
1907 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale)); | 1933 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale)); |
1908 EXPECT_EQ(4.f, max_scale); | 1934 EXPECT_EQ(4.f, max_scale); |
1909 } | 1935 } |
1910 | 1936 |
1911 } // namespace | 1937 } // namespace |
1912 } // namespace cc | 1938 } // namespace cc |
OLD | NEW |