| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 TEST(LayerAnimationControllerTest, SyncNewAnimation) { | 42 TEST(LayerAnimationControllerTest, SyncNewAnimation) { |
| 43 FakeLayerAnimationValueObserver dummy_impl; | 43 FakeLayerAnimationValueObserver dummy_impl; |
| 44 scoped_refptr<LayerAnimationController> controller_impl( | 44 scoped_refptr<LayerAnimationController> controller_impl( |
| 45 LayerAnimationController::Create(0)); | 45 LayerAnimationController::Create(0)); |
| 46 controller_impl->AddValueObserver(&dummy_impl); | 46 controller_impl->AddValueObserver(&dummy_impl); |
| 47 FakeLayerAnimationValueObserver dummy; | 47 FakeLayerAnimationValueObserver dummy; |
| 48 scoped_refptr<LayerAnimationController> controller( | 48 scoped_refptr<LayerAnimationController> controller( |
| 49 LayerAnimationController::Create(0)); | 49 LayerAnimationController::Create(0)); |
| 50 controller->AddValueObserver(&dummy); | 50 controller->AddValueObserver(&dummy); |
| 51 | 51 |
| 52 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); | 52 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY)); |
| 53 | 53 |
| 54 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 54 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 55 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | 55 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); |
| 56 | 56 |
| 57 int animation_id = | 57 int animation_id = |
| 58 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 58 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 59 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 59 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 60 | 60 |
| 61 controller->PushAnimationUpdatesTo(controller_impl.get()); | 61 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 62 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); | 62 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); |
| 63 controller_impl->ActivateAnimations(); | 63 controller_impl->ActivateAnimations(); |
| 64 | 64 |
| 65 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 65 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 66 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 66 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 67 controller_impl->GetAnimationById(animation_id)->run_state()); | 67 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // If an animation is started on the impl thread before it is ticked on the main | 70 // If an animation is started on the impl thread before it is ticked on the main |
| 71 // thread, we must be sure to respect the synchronized start time. | 71 // thread, we must be sure to respect the synchronized start time. |
| 72 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) { | 72 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) { |
| 73 FakeLayerAnimationValueObserver dummy_impl; | 73 FakeLayerAnimationValueObserver dummy_impl; |
| 74 scoped_refptr<LayerAnimationController> controller_impl( | 74 scoped_refptr<LayerAnimationController> controller_impl( |
| 75 LayerAnimationController::Create(0)); | 75 LayerAnimationController::Create(0)); |
| 76 controller_impl->AddValueObserver(&dummy_impl); | 76 controller_impl->AddValueObserver(&dummy_impl); |
| 77 FakeLayerAnimationValueObserver dummy; | 77 FakeLayerAnimationValueObserver dummy; |
| 78 scoped_refptr<LayerAnimationController> controller( | 78 scoped_refptr<LayerAnimationController> controller( |
| 79 LayerAnimationController::Create(0)); | 79 LayerAnimationController::Create(0)); |
| 80 controller->AddValueObserver(&dummy); | 80 controller->AddValueObserver(&dummy); |
| 81 | 81 |
| 82 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); | 82 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY)); |
| 83 | 83 |
| 84 int animation_id = | 84 int animation_id = |
| 85 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 85 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 86 | 86 |
| 87 controller->PushAnimationUpdatesTo(controller_impl.get()); | 87 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 88 controller_impl->ActivateAnimations(); | 88 controller_impl->ActivateAnimations(); |
| 89 | 89 |
| 90 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 90 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 91 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 91 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 92 controller_impl->GetAnimationById(animation_id)->run_state()); | 92 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 93 | 93 |
| 94 AnimationEventsVector events; | 94 AnimationEventsVector events; |
| 95 controller_impl->Animate(kInitialTickTime); | 95 controller_impl->Animate(kInitialTickTime); |
| 96 controller_impl->UpdateState(true, &events); | 96 controller_impl->UpdateState(true, &events); |
| 97 | 97 |
| 98 // Synchronize the start times. | 98 // Synchronize the start times. |
| 99 EXPECT_EQ(1u, events.size()); | 99 EXPECT_EQ(1u, events.size()); |
| 100 controller->NotifyAnimationStarted(events[0]); | 100 controller->NotifyAnimationStarted(events[0]); |
| 101 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | 101 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 115 controller_impl->AddValueObserver(&dummy_impl); | 115 controller_impl->AddValueObserver(&dummy_impl); |
| 116 FakeLayerAnimationValueObserver dummy; | 116 FakeLayerAnimationValueObserver dummy; |
| 117 scoped_refptr<LayerAnimationController> controller( | 117 scoped_refptr<LayerAnimationController> controller( |
| 118 LayerAnimationController::Create(0)); | 118 LayerAnimationController::Create(0)); |
| 119 controller->AddValueObserver(&dummy); | 119 controller->AddValueObserver(&dummy); |
| 120 | 120 |
| 121 int animation_id = | 121 int animation_id = |
| 122 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 122 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 123 | 123 |
| 124 const TimeTicks start_time = TicksFromSecondsF(123); | 124 const TimeTicks start_time = TicksFromSecondsF(123); |
| 125 controller->GetAnimation(Animation::Opacity)->set_start_time(start_time); | 125 controller->GetAnimation(Animation::OPACITY)->set_start_time(start_time); |
| 126 | 126 |
| 127 controller->PushAnimationUpdatesTo(controller_impl.get()); | 127 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 128 controller_impl->ActivateAnimations(); | 128 controller_impl->ActivateAnimations(); |
| 129 | 129 |
| 130 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 130 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 131 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 131 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 132 controller_impl->GetAnimationById(animation_id)->run_state()); | 132 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 133 | 133 |
| 134 AnimationEventsVector events; | 134 AnimationEventsVector events; |
| 135 controller_impl->Animate(kInitialTickTime); | 135 controller_impl->Animate(kInitialTickTime); |
| 136 controller_impl->UpdateState(true, &events); | 136 controller_impl->UpdateState(true, &events); |
| 137 | 137 |
| 138 // Synchronize the start times. | 138 // Synchronize the start times. |
| 139 EXPECT_EQ(1u, events.size()); | 139 EXPECT_EQ(1u, events.size()); |
| 140 controller->NotifyAnimationStarted(events[0]); | 140 controller->NotifyAnimationStarted(events[0]); |
| 141 | 141 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 196 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
| 197 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); | 197 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); |
| 198 | 198 |
| 199 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 199 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 200 controller->UpdateState(true, nullptr); | 200 controller->UpdateState(true, nullptr); |
| 201 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 201 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
| 202 | 202 |
| 203 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 203 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 204 controller->UpdateState(true, nullptr); | 204 controller->UpdateState(true, nullptr); |
| 205 EXPECT_EQ(Animation::Finished, | 205 EXPECT_EQ(Animation::FINISHED, |
| 206 controller->GetAnimation(Animation::Opacity)->run_state()); | 206 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 207 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); | 207 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
| 208 | 208 |
| 209 events.reset(new AnimationEventsVector); | 209 events.reset(new AnimationEventsVector); |
| 210 controller_impl->Animate(kInitialTickTime + | 210 controller_impl->Animate(kInitialTickTime + |
| 211 TimeDelta::FromMilliseconds(1500)); | 211 TimeDelta::FromMilliseconds(1500)); |
| 212 controller_impl->UpdateState(true, events.get()); | 212 controller_impl->UpdateState(true, events.get()); |
| 213 | 213 |
| 214 EXPECT_EQ(Animation::WaitingForDeletion, | 214 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 215 controller_impl->GetAnimation(Animation::Opacity)->run_state()); | 215 controller_impl->GetAnimation(Animation::OPACITY)->run_state()); |
| 216 // The impl thread controller should have de-activated. | 216 // The impl thread controller should have de-activated. |
| 217 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size()); | 217 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size()); |
| 218 | 218 |
| 219 EXPECT_EQ(1u, events->size()); | 219 EXPECT_EQ(1u, events->size()); |
| 220 controller->NotifyAnimationFinished((*events)[0]); | 220 controller->NotifyAnimationFinished((*events)[0]); |
| 221 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | 221 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); |
| 222 controller->UpdateState(true, nullptr); | 222 controller->UpdateState(true, nullptr); |
| 223 | 223 |
| 224 EXPECT_EQ(Animation::WaitingForDeletion, | 224 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 225 controller->GetAnimation(Animation::Opacity)->run_state()); | 225 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 226 // The main thread controller should have de-activated. | 226 // The main thread controller should have de-activated. |
| 227 EXPECT_EQ(0u, registrar->active_animation_controllers().size()); | 227 EXPECT_EQ(0u, registrar->active_animation_controllers().size()); |
| 228 | 228 |
| 229 controller->PushAnimationUpdatesTo(controller_impl.get()); | 229 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 230 controller_impl->ActivateAnimations(); | 230 controller_impl->ActivateAnimations(); |
| 231 EXPECT_FALSE(controller->has_any_animation()); | 231 EXPECT_FALSE(controller->has_any_animation()); |
| 232 EXPECT_FALSE(controller_impl->has_any_animation()); | 232 EXPECT_FALSE(controller_impl->has_any_animation()); |
| 233 EXPECT_EQ(0u, registrar->active_animation_controllers().size()); | 233 EXPECT_EQ(0u, registrar->active_animation_controllers().size()); |
| 234 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size()); | 234 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size()); |
| 235 | 235 |
| 236 controller->SetAnimationRegistrar(nullptr); | 236 controller->SetAnimationRegistrar(nullptr); |
| 237 controller_impl->SetAnimationRegistrar(nullptr); | 237 controller_impl->SetAnimationRegistrar(nullptr); |
| 238 } | 238 } |
| 239 | 239 |
| 240 TEST(LayerAnimationControllerTest, SyncPause) { | 240 TEST(LayerAnimationControllerTest, SyncPause) { |
| 241 FakeLayerAnimationValueObserver dummy_impl; | 241 FakeLayerAnimationValueObserver dummy_impl; |
| 242 scoped_refptr<LayerAnimationController> controller_impl( | 242 scoped_refptr<LayerAnimationController> controller_impl( |
| 243 LayerAnimationController::Create(0)); | 243 LayerAnimationController::Create(0)); |
| 244 controller_impl->AddValueObserver(&dummy_impl); | 244 controller_impl->AddValueObserver(&dummy_impl); |
| 245 FakeLayerAnimationValueObserver dummy; | 245 FakeLayerAnimationValueObserver dummy; |
| 246 scoped_refptr<LayerAnimationController> controller( | 246 scoped_refptr<LayerAnimationController> controller( |
| 247 LayerAnimationController::Create(0)); | 247 LayerAnimationController::Create(0)); |
| 248 controller->AddValueObserver(&dummy); | 248 controller->AddValueObserver(&dummy); |
| 249 | 249 |
| 250 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); | 250 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY)); |
| 251 | 251 |
| 252 int animation_id = | 252 int animation_id = |
| 253 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 253 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 254 | 254 |
| 255 controller->PushAnimationUpdatesTo(controller_impl.get()); | 255 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 256 controller_impl->ActivateAnimations(); | 256 controller_impl->ActivateAnimations(); |
| 257 | 257 |
| 258 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 258 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 259 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 259 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 260 controller_impl->GetAnimationById(animation_id)->run_state()); | 260 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 261 | 261 |
| 262 // Start the animations on each controller. | 262 // Start the animations on each controller. |
| 263 AnimationEventsVector events; | 263 AnimationEventsVector events; |
| 264 controller_impl->Animate(kInitialTickTime); | 264 controller_impl->Animate(kInitialTickTime); |
| 265 controller_impl->UpdateState(true, &events); | 265 controller_impl->UpdateState(true, &events); |
| 266 controller->Animate(kInitialTickTime); | 266 controller->Animate(kInitialTickTime); |
| 267 controller->UpdateState(true, nullptr); | 267 controller->UpdateState(true, nullptr); |
| 268 EXPECT_EQ(Animation::Running, | 268 EXPECT_EQ(Animation::RUNNING, |
| 269 controller_impl->GetAnimationById(animation_id)->run_state()); | 269 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 270 EXPECT_EQ(Animation::Running, | 270 EXPECT_EQ(Animation::RUNNING, |
| 271 controller->GetAnimationById(animation_id)->run_state()); | 271 controller->GetAnimationById(animation_id)->run_state()); |
| 272 | 272 |
| 273 // Pause the main-thread animation. | 273 // Pause the main-thread animation. |
| 274 controller->PauseAnimation( | 274 controller->PauseAnimation( |
| 275 animation_id, | 275 animation_id, |
| 276 TimeDelta::FromMilliseconds(1000) + TimeDelta::FromMilliseconds(1000)); | 276 TimeDelta::FromMilliseconds(1000) + TimeDelta::FromMilliseconds(1000)); |
| 277 EXPECT_EQ(Animation::Paused, | 277 EXPECT_EQ(Animation::PAUSED, |
| 278 controller->GetAnimationById(animation_id)->run_state()); | 278 controller->GetAnimationById(animation_id)->run_state()); |
| 279 | 279 |
| 280 // The pause run state change should make it to the impl thread controller. | 280 // The pause run state change should make it to the impl thread controller. |
| 281 controller->PushAnimationUpdatesTo(controller_impl.get()); | 281 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 282 controller_impl->ActivateAnimations(); | 282 controller_impl->ActivateAnimations(); |
| 283 EXPECT_EQ(Animation::Paused, | 283 EXPECT_EQ(Animation::PAUSED, |
| 284 controller_impl->GetAnimationById(animation_id)->run_state()); | 284 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 285 } | 285 } |
| 286 | 286 |
| 287 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { | 287 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { |
| 288 FakeLayerAnimationValueObserver dummy_impl; | 288 FakeLayerAnimationValueObserver dummy_impl; |
| 289 scoped_refptr<LayerAnimationController> controller_impl( | 289 scoped_refptr<LayerAnimationController> controller_impl( |
| 290 LayerAnimationController::Create(0)); | 290 LayerAnimationController::Create(0)); |
| 291 controller_impl->AddValueObserver(&dummy_impl); | 291 controller_impl->AddValueObserver(&dummy_impl); |
| 292 FakeLayerAnimationValueObserver dummy; | 292 FakeLayerAnimationValueObserver dummy; |
| 293 scoped_refptr<LayerAnimationController> controller( | 293 scoped_refptr<LayerAnimationController> controller( |
| 294 LayerAnimationController::Create(0)); | 294 LayerAnimationController::Create(0)); |
| 295 controller->AddValueObserver(&dummy); | 295 controller->AddValueObserver(&dummy); |
| 296 | 296 |
| 297 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); | 297 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY)); |
| 298 | 298 |
| 299 int animation_id = | 299 int animation_id = |
| 300 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 300 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 301 int group_id = controller->GetAnimationById(animation_id)->group(); | 301 int group_id = controller->GetAnimationById(animation_id)->group(); |
| 302 | 302 |
| 303 controller->PushAnimationUpdatesTo(controller_impl.get()); | 303 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 304 controller_impl->ActivateAnimations(); | 304 controller_impl->ActivateAnimations(); |
| 305 | 305 |
| 306 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 306 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 307 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 307 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 308 controller_impl->GetAnimationById(animation_id)->run_state()); | 308 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 309 | 309 |
| 310 // Notify main thread controller that the animation has started. | 310 // Notify main thread controller that the animation has started. |
| 311 AnimationEvent animation_started_event(AnimationEvent::Started, | 311 AnimationEvent animation_started_event(AnimationEvent::STARTED, 0, group_id, |
| 312 0, | 312 Animation::OPACITY, kInitialTickTime); |
| 313 group_id, | |
| 314 Animation::Opacity, | |
| 315 kInitialTickTime); | |
| 316 controller->NotifyAnimationStarted(animation_started_event); | 313 controller->NotifyAnimationStarted(animation_started_event); |
| 317 | 314 |
| 318 // Force animation to complete on impl thread. | 315 // Force animation to complete on impl thread. |
| 319 controller_impl->RemoveAnimation(animation_id); | 316 controller_impl->RemoveAnimation(animation_id); |
| 320 | 317 |
| 321 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | 318 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); |
| 322 | 319 |
| 323 controller->PushAnimationUpdatesTo(controller_impl.get()); | 320 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 324 controller_impl->ActivateAnimations(); | 321 controller_impl->ActivateAnimations(); |
| 325 | 322 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 344 | 341 |
| 345 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); | 342 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); |
| 346 controller->Animate(kInitialTickTime); | 343 controller->Animate(kInitialTickTime); |
| 347 controller->UpdateState(true, nullptr); | 344 controller->UpdateState(true, nullptr); |
| 348 controller->PushAnimationUpdatesTo(controller_impl.get()); | 345 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 349 controller_impl->ActivateAnimations(); | 346 controller_impl->ActivateAnimations(); |
| 350 | 347 |
| 351 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 348 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 352 controller_impl->UpdateState(true, events.get()); | 349 controller_impl->UpdateState(true, events.get()); |
| 353 | 350 |
| 354 // There should be a Started event for the animation. | 351 // There should be a STARTED event for the animation. |
| 355 EXPECT_EQ(1u, events->size()); | 352 EXPECT_EQ(1u, events->size()); |
| 356 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); | 353 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type); |
| 357 controller->NotifyAnimationStarted((*events)[0]); | 354 controller->NotifyAnimationStarted((*events)[0]); |
| 358 | 355 |
| 359 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 356 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 360 controller->UpdateState(true, nullptr); | 357 controller->UpdateState(true, nullptr); |
| 361 | 358 |
| 362 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | 359 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); |
| 363 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | 360 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); |
| 364 | 361 |
| 365 events.reset(new AnimationEventsVector); | 362 events.reset(new AnimationEventsVector); |
| 366 controller_impl->Animate(kInitialTickTime + | 363 controller_impl->Animate(kInitialTickTime + |
| 367 TimeDelta::FromMilliseconds(2000)); | 364 TimeDelta::FromMilliseconds(2000)); |
| 368 controller_impl->UpdateState(true, events.get()); | 365 controller_impl->UpdateState(true, events.get()); |
| 369 | 366 |
| 370 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | 367 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); |
| 371 | 368 |
| 372 // There should be a Finished event for the animation. | 369 // There should be a FINISHED event for the animation. |
| 373 EXPECT_EQ(1u, events->size()); | 370 EXPECT_EQ(1u, events->size()); |
| 374 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 371 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type); |
| 375 | 372 |
| 376 // Neither controller should have deleted the animation yet. | 373 // Neither controller should have deleted the animation yet. |
| 377 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity)); | 374 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY)); |
| 378 EXPECT_TRUE(controller_impl->GetAnimation(Animation::Opacity)); | 375 EXPECT_TRUE(controller_impl->GetAnimation(Animation::OPACITY)); |
| 379 | 376 |
| 380 controller->NotifyAnimationFinished((*events)[0]); | 377 controller->NotifyAnimationFinished((*events)[0]); |
| 381 | 378 |
| 382 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 379 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 383 controller->UpdateState(true, nullptr); | 380 controller->UpdateState(true, nullptr); |
| 384 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 381 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
| 385 | 382 |
| 386 controller->PushAnimationUpdatesTo(controller_impl.get()); | 383 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 387 | 384 |
| 388 // Both controllers should now have deleted the animation. The impl controller | 385 // Both controllers should now have deleted the animation. The impl controller |
| 389 // should have deleted the animation even though activation has not occurred, | 386 // should have deleted the animation even though activation has not occurred, |
| 390 // since the animation was already waiting for deletion when | 387 // since the animation was already waiting for deletion when |
| 391 // PushAnimationUpdatesTo was called. | 388 // PushAnimationUpdatesTo was called. |
| 392 EXPECT_FALSE(controller->has_any_animation()); | 389 EXPECT_FALSE(controller->has_any_animation()); |
| 393 EXPECT_FALSE(controller_impl->has_any_animation()); | 390 EXPECT_FALSE(controller_impl->has_any_animation()); |
| 394 } | 391 } |
| 395 | 392 |
| 396 // Tests that transitioning opacity from 0 to 1 works as expected. | 393 // Tests that transitioning opacity from 0 to 1 works as expected. |
| 397 | 394 |
| 398 static const AnimationEvent* GetMostRecentPropertyUpdateEvent( | 395 static const AnimationEvent* GetMostRecentPropertyUpdateEvent( |
| 399 const AnimationEventsVector* events) { | 396 const AnimationEventsVector* events) { |
| 400 const AnimationEvent* event = 0; | 397 const AnimationEvent* event = 0; |
| 401 for (size_t i = 0; i < events->size(); ++i) | 398 for (size_t i = 0; i < events->size(); ++i) |
| 402 if ((*events)[i].type == AnimationEvent::PropertyUpdate) | 399 if ((*events)[i].type == AnimationEvent::PROPERTY_UPDATE) |
| 403 event = &(*events)[i]; | 400 event = &(*events)[i]; |
| 404 | 401 |
| 405 return event; | 402 return event; |
| 406 } | 403 } |
| 407 | 404 |
| 408 TEST(LayerAnimationControllerTest, TrivialTransition) { | 405 TEST(LayerAnimationControllerTest, TrivialTransition) { |
| 409 scoped_ptr<AnimationEventsVector> events( | 406 scoped_ptr<AnimationEventsVector> events( |
| 410 make_scoped_ptr(new AnimationEventsVector)); | 407 make_scoped_ptr(new AnimationEventsVector)); |
| 411 FakeLayerAnimationValueObserver dummy; | 408 FakeLayerAnimationValueObserver dummy; |
| 412 scoped_refptr<LayerAnimationController> controller( | 409 scoped_refptr<LayerAnimationController> controller( |
| 413 LayerAnimationController::Create(0)); | 410 LayerAnimationController::Create(0)); |
| 414 controller->AddValueObserver(&dummy); | 411 controller->AddValueObserver(&dummy); |
| 415 | 412 |
| 416 scoped_ptr<Animation> to_add(CreateAnimation( | 413 scoped_ptr<Animation> to_add(CreateAnimation( |
| 417 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 414 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 418 1, | 415 1, Animation::OPACITY)); |
| 419 Animation::Opacity)); | |
| 420 | 416 |
| 421 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 417 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 422 controller->AddAnimation(to_add.Pass()); | 418 controller->AddAnimation(to_add.Pass()); |
| 423 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 419 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 424 controller->Animate(kInitialTickTime); | 420 controller->Animate(kInitialTickTime); |
| 425 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 421 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 426 controller->UpdateState(true, events.get()); | 422 controller->UpdateState(true, events.get()); |
| 427 EXPECT_TRUE(controller->HasActiveAnimation()); | 423 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 428 EXPECT_EQ(0.f, dummy.opacity()); | 424 EXPECT_EQ(0.f, dummy.opacity()); |
| 429 // A non-impl-only animation should not generate property updates. | 425 // A non-impl-only animation should not generate property updates. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 440 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { | 436 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { |
| 441 scoped_ptr<AnimationEventsVector> events( | 437 scoped_ptr<AnimationEventsVector> events( |
| 442 make_scoped_ptr(new AnimationEventsVector)); | 438 make_scoped_ptr(new AnimationEventsVector)); |
| 443 FakeLayerAnimationValueObserver dummy_impl; | 439 FakeLayerAnimationValueObserver dummy_impl; |
| 444 scoped_refptr<LayerAnimationController> controller_impl( | 440 scoped_refptr<LayerAnimationController> controller_impl( |
| 445 LayerAnimationController::Create(0)); | 441 LayerAnimationController::Create(0)); |
| 446 controller_impl->AddValueObserver(&dummy_impl); | 442 controller_impl->AddValueObserver(&dummy_impl); |
| 447 | 443 |
| 448 scoped_ptr<Animation> to_add(CreateAnimation( | 444 scoped_ptr<Animation> to_add(CreateAnimation( |
| 449 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 445 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 450 1, | 446 1, Animation::OPACITY)); |
| 451 Animation::Opacity)); | |
| 452 to_add->set_is_impl_only(true); | 447 to_add->set_is_impl_only(true); |
| 453 | 448 |
| 454 controller_impl->AddAnimation(to_add.Pass()); | 449 controller_impl->AddAnimation(to_add.Pass()); |
| 455 controller_impl->Animate(kInitialTickTime); | 450 controller_impl->Animate(kInitialTickTime); |
| 456 controller_impl->UpdateState(true, events.get()); | 451 controller_impl->UpdateState(true, events.get()); |
| 457 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 452 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 458 EXPECT_EQ(0.f, dummy_impl.opacity()); | 453 EXPECT_EQ(0.f, dummy_impl.opacity()); |
| 459 EXPECT_EQ(1u, events->size()); | 454 EXPECT_EQ(1u, events->size()); |
| 460 const AnimationEvent* start_opacity_event = | 455 const AnimationEvent* start_opacity_event = |
| 461 GetMostRecentPropertyUpdateEvent(events.get()); | 456 GetMostRecentPropertyUpdateEvent(events.get()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 481 controller_impl->AddValueObserver(&dummy_impl); | 476 controller_impl->AddValueObserver(&dummy_impl); |
| 482 | 477 |
| 483 // Choose different values for x and y to avoid coincidental values in the | 478 // Choose different values for x and y to avoid coincidental values in the |
| 484 // observed transforms. | 479 // observed transforms. |
| 485 const float delta_x = 3; | 480 const float delta_x = 3; |
| 486 const float delta_y = 4; | 481 const float delta_y = 4; |
| 487 | 482 |
| 488 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 483 scoped_ptr<KeyframedTransformAnimationCurve> curve( |
| 489 KeyframedTransformAnimationCurve::Create()); | 484 KeyframedTransformAnimationCurve::Create()); |
| 490 | 485 |
| 491 // Create simple Transform animation. | 486 // Create simple TRANSFORM animation. |
| 492 TransformOperations operations; | 487 TransformOperations operations; |
| 493 curve->AddKeyframe( | 488 curve->AddKeyframe( |
| 494 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr)); | 489 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr)); |
| 495 operations.AppendTranslate(delta_x, delta_y, 0); | 490 operations.AppendTranslate(delta_x, delta_y, 0); |
| 496 curve->AddKeyframe(TransformKeyframe::Create( | 491 curve->AddKeyframe(TransformKeyframe::Create( |
| 497 base::TimeDelta::FromSecondsD(1.0), operations, nullptr)); | 492 base::TimeDelta::FromSecondsD(1.0), operations, nullptr)); |
| 498 | 493 |
| 499 scoped_ptr<Animation> animation( | 494 scoped_ptr<Animation> animation( |
| 500 Animation::Create(curve.Pass(), 1, 0, Animation::Transform)); | 495 Animation::Create(curve.Pass(), 1, 0, Animation::TRANSFORM)); |
| 501 animation->set_is_impl_only(true); | 496 animation->set_is_impl_only(true); |
| 502 controller_impl->AddAnimation(animation.Pass()); | 497 controller_impl->AddAnimation(animation.Pass()); |
| 503 | 498 |
| 504 // Run animation. | 499 // Run animation. |
| 505 controller_impl->Animate(kInitialTickTime); | 500 controller_impl->Animate(kInitialTickTime); |
| 506 controller_impl->UpdateState(true, events.get()); | 501 controller_impl->UpdateState(true, events.get()); |
| 507 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 502 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 508 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); | 503 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); |
| 509 EXPECT_EQ(1u, events->size()); | 504 EXPECT_EQ(1u, events->size()); |
| 510 const AnimationEvent* start_transform_event = | 505 const AnimationEvent* start_transform_event = |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 FilterOperations start_filters; | 537 FilterOperations start_filters; |
| 543 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); | 538 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); |
| 544 curve->AddKeyframe( | 539 curve->AddKeyframe( |
| 545 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); | 540 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 546 FilterOperations end_filters; | 541 FilterOperations end_filters; |
| 547 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 542 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
| 548 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 543 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
| 549 end_filters, nullptr)); | 544 end_filters, nullptr)); |
| 550 | 545 |
| 551 scoped_ptr<Animation> animation( | 546 scoped_ptr<Animation> animation( |
| 552 Animation::Create(curve.Pass(), 1, 0, Animation::Filter)); | 547 Animation::Create(curve.Pass(), 1, 0, Animation::FILTER)); |
| 553 controller->AddAnimation(animation.Pass()); | 548 controller->AddAnimation(animation.Pass()); |
| 554 | 549 |
| 555 controller->Animate(kInitialTickTime); | 550 controller->Animate(kInitialTickTime); |
| 556 controller->UpdateState(true, events.get()); | 551 controller->UpdateState(true, events.get()); |
| 557 EXPECT_TRUE(controller->HasActiveAnimation()); | 552 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 558 EXPECT_EQ(start_filters, dummy.filters()); | 553 EXPECT_EQ(start_filters, dummy.filters()); |
| 559 // A non-impl-only animation should not generate property updates. | 554 // A non-impl-only animation should not generate property updates. |
| 560 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 555 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 561 EXPECT_FALSE(event); | 556 EXPECT_FALSE(event); |
| 562 | 557 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 580 scoped_ptr<AnimationEventsVector> events( | 575 scoped_ptr<AnimationEventsVector> events( |
| 581 make_scoped_ptr(new AnimationEventsVector)); | 576 make_scoped_ptr(new AnimationEventsVector)); |
| 582 FakeLayerAnimationValueObserver dummy_impl; | 577 FakeLayerAnimationValueObserver dummy_impl; |
| 583 scoped_refptr<LayerAnimationController> controller_impl( | 578 scoped_refptr<LayerAnimationController> controller_impl( |
| 584 LayerAnimationController::Create(0)); | 579 LayerAnimationController::Create(0)); |
| 585 controller_impl->AddValueObserver(&dummy_impl); | 580 controller_impl->AddValueObserver(&dummy_impl); |
| 586 | 581 |
| 587 scoped_ptr<KeyframedFilterAnimationCurve> curve( | 582 scoped_ptr<KeyframedFilterAnimationCurve> curve( |
| 588 KeyframedFilterAnimationCurve::Create()); | 583 KeyframedFilterAnimationCurve::Create()); |
| 589 | 584 |
| 590 // Create simple Filter animation. | 585 // Create simple FILTER animation. |
| 591 FilterOperations start_filters; | 586 FilterOperations start_filters; |
| 592 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); | 587 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); |
| 593 curve->AddKeyframe( | 588 curve->AddKeyframe( |
| 594 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); | 589 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 595 FilterOperations end_filters; | 590 FilterOperations end_filters; |
| 596 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 591 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
| 597 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 592 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
| 598 end_filters, nullptr)); | 593 end_filters, nullptr)); |
| 599 | 594 |
| 600 scoped_ptr<Animation> animation( | 595 scoped_ptr<Animation> animation( |
| 601 Animation::Create(curve.Pass(), 1, 0, Animation::Filter)); | 596 Animation::Create(curve.Pass(), 1, 0, Animation::FILTER)); |
| 602 animation->set_is_impl_only(true); | 597 animation->set_is_impl_only(true); |
| 603 controller_impl->AddAnimation(animation.Pass()); | 598 controller_impl->AddAnimation(animation.Pass()); |
| 604 | 599 |
| 605 // Run animation. | 600 // Run animation. |
| 606 controller_impl->Animate(kInitialTickTime); | 601 controller_impl->Animate(kInitialTickTime); |
| 607 controller_impl->UpdateState(true, events.get()); | 602 controller_impl->UpdateState(true, events.get()); |
| 608 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 603 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 609 EXPECT_EQ(start_filters, dummy_impl.filters()); | 604 EXPECT_EQ(start_filters, dummy_impl.filters()); |
| 610 EXPECT_EQ(1u, events->size()); | 605 EXPECT_EQ(1u, events->size()); |
| 611 const AnimationEvent* start_filter_event = | 606 const AnimationEvent* start_filter_event = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 controller->set_value_provider(&dummy_provider); | 639 controller->set_value_provider(&dummy_provider); |
| 645 | 640 |
| 646 gfx::ScrollOffset initial_value(100.f, 300.f); | 641 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 647 gfx::ScrollOffset target_value(300.f, 200.f); | 642 gfx::ScrollOffset target_value(300.f, 200.f); |
| 648 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 643 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 649 ScrollOffsetAnimationCurve::Create( | 644 ScrollOffsetAnimationCurve::Create( |
| 650 target_value, | 645 target_value, |
| 651 EaseInOutTimingFunction::Create().Pass())); | 646 EaseInOutTimingFunction::Create().Pass())); |
| 652 | 647 |
| 653 scoped_ptr<Animation> animation( | 648 scoped_ptr<Animation> animation( |
| 654 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset)); | 649 Animation::Create(curve.Pass(), 1, 0, Animation::SCROLL_OFFSET)); |
| 655 animation->set_needs_synchronized_start_time(true); | 650 animation->set_needs_synchronized_start_time(true); |
| 656 controller->AddAnimation(animation.Pass()); | 651 controller->AddAnimation(animation.Pass()); |
| 657 | 652 |
| 658 dummy_provider_impl.set_scroll_offset(initial_value); | 653 dummy_provider_impl.set_scroll_offset(initial_value); |
| 659 controller->PushAnimationUpdatesTo(controller_impl.get()); | 654 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 660 controller_impl->ActivateAnimations(); | 655 controller_impl->ActivateAnimations(); |
| 661 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); | 656 EXPECT_TRUE(controller_impl->GetAnimation(Animation::SCROLL_OFFSET)); |
| 662 TimeDelta duration = controller_impl->GetAnimation(Animation::ScrollOffset) | 657 TimeDelta duration = controller_impl->GetAnimation(Animation::SCROLL_OFFSET) |
| 663 ->curve() | 658 ->curve() |
| 664 ->Duration(); | 659 ->Duration(); |
| 665 EXPECT_EQ( | 660 EXPECT_EQ( |
| 666 duration, | 661 duration, |
| 667 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); | 662 controller->GetAnimation(Animation::SCROLL_OFFSET)->curve()->Duration()); |
| 668 | 663 |
| 669 controller->Animate(kInitialTickTime); | 664 controller->Animate(kInitialTickTime); |
| 670 controller->UpdateState(true, nullptr); | 665 controller->UpdateState(true, nullptr); |
| 671 EXPECT_TRUE(controller->HasActiveAnimation()); | 666 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 672 EXPECT_EQ(initial_value, dummy.scroll_offset()); | 667 EXPECT_EQ(initial_value, dummy.scroll_offset()); |
| 673 | 668 |
| 674 controller_impl->Animate(kInitialTickTime); | 669 controller_impl->Animate(kInitialTickTime); |
| 675 controller_impl->UpdateState(true, events.get()); | 670 controller_impl->UpdateState(true, events.get()); |
| 676 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 671 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 677 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 672 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 controller->set_value_provider(&dummy_provider); | 718 controller->set_value_provider(&dummy_provider); |
| 724 | 719 |
| 725 gfx::ScrollOffset initial_value(500.f, 100.f); | 720 gfx::ScrollOffset initial_value(500.f, 100.f); |
| 726 gfx::ScrollOffset target_value(300.f, 200.f); | 721 gfx::ScrollOffset target_value(300.f, 200.f); |
| 727 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 722 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 728 ScrollOffsetAnimationCurve::Create( | 723 ScrollOffsetAnimationCurve::Create( |
| 729 target_value, | 724 target_value, |
| 730 EaseInOutTimingFunction::Create().Pass())); | 725 EaseInOutTimingFunction::Create().Pass())); |
| 731 | 726 |
| 732 scoped_ptr<Animation> animation( | 727 scoped_ptr<Animation> animation( |
| 733 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset)); | 728 Animation::Create(curve.Pass(), 1, 0, Animation::SCROLL_OFFSET)); |
| 734 animation->set_needs_synchronized_start_time(true); | 729 animation->set_needs_synchronized_start_time(true); |
| 735 controller->AddAnimation(animation.Pass()); | 730 controller->AddAnimation(animation.Pass()); |
| 736 | 731 |
| 737 dummy_provider.set_scroll_offset(initial_value); | 732 dummy_provider.set_scroll_offset(initial_value); |
| 738 controller->PushAnimationUpdatesTo(controller_impl.get()); | 733 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 739 controller_impl->ActivateAnimations(); | 734 controller_impl->ActivateAnimations(); |
| 740 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); | 735 EXPECT_TRUE(controller_impl->GetAnimation(Animation::SCROLL_OFFSET)); |
| 741 TimeDelta duration = controller_impl->GetAnimation(Animation::ScrollOffset) | 736 TimeDelta duration = controller_impl->GetAnimation(Animation::SCROLL_OFFSET) |
| 742 ->curve() | 737 ->curve() |
| 743 ->Duration(); | 738 ->Duration(); |
| 744 EXPECT_EQ( | 739 EXPECT_EQ( |
| 745 duration, | 740 duration, |
| 746 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); | 741 controller->GetAnimation(Animation::SCROLL_OFFSET)->curve()->Duration()); |
| 747 | 742 |
| 748 controller->Animate(kInitialTickTime); | 743 controller->Animate(kInitialTickTime); |
| 749 controller->UpdateState(true, nullptr); | 744 controller->UpdateState(true, nullptr); |
| 750 EXPECT_TRUE(controller->HasActiveAnimation()); | 745 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 751 EXPECT_EQ(initial_value, dummy.scroll_offset()); | 746 EXPECT_EQ(initial_value, dummy.scroll_offset()); |
| 752 | 747 |
| 753 controller_impl->Animate(kInitialTickTime); | 748 controller_impl->Animate(kInitialTickTime); |
| 754 controller_impl->UpdateState(true, events.get()); | 749 controller_impl->UpdateState(true, events.get()); |
| 755 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 750 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 756 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 751 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 gfx::ScrollOffset initial_value(100.f, 300.f); | 791 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 797 gfx::ScrollOffset target_value(300.f, 200.f); | 792 gfx::ScrollOffset target_value(300.f, 200.f); |
| 798 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 793 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 799 ScrollOffsetAnimationCurve::Create( | 794 ScrollOffsetAnimationCurve::Create( |
| 800 target_value, | 795 target_value, |
| 801 EaseInOutTimingFunction::Create().Pass())); | 796 EaseInOutTimingFunction::Create().Pass())); |
| 802 curve->SetInitialValue(initial_value); | 797 curve->SetInitialValue(initial_value); |
| 803 double duration_in_seconds = curve->Duration().InSecondsF(); | 798 double duration_in_seconds = curve->Duration().InSecondsF(); |
| 804 | 799 |
| 805 scoped_ptr<Animation> animation( | 800 scoped_ptr<Animation> animation( |
| 806 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset)); | 801 Animation::Create(curve.Pass(), 1, 0, Animation::SCROLL_OFFSET)); |
| 807 animation->set_is_impl_only(true); | 802 animation->set_is_impl_only(true); |
| 808 controller_impl->AddAnimation(animation.Pass()); | 803 controller_impl->AddAnimation(animation.Pass()); |
| 809 | 804 |
| 810 controller_impl->Animate(kInitialTickTime); | 805 controller_impl->Animate(kInitialTickTime); |
| 811 controller_impl->UpdateState(true, events.get()); | 806 controller_impl->UpdateState(true, events.get()); |
| 812 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 807 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 813 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 808 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
| 814 // Scroll offset animations should not generate property updates. | 809 // Scroll offset animations should not generate property updates. |
| 815 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 810 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 816 EXPECT_FALSE(event); | 811 EXPECT_FALSE(event); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 controller->set_value_provider(&dummy_provider); | 845 controller->set_value_provider(&dummy_provider); |
| 851 | 846 |
| 852 // First test the 1-argument version of RemoveAnimation. | 847 // First test the 1-argument version of RemoveAnimation. |
| 853 gfx::ScrollOffset target_value(300.f, 200.f); | 848 gfx::ScrollOffset target_value(300.f, 200.f); |
| 854 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 849 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 855 ScrollOffsetAnimationCurve::Create( | 850 ScrollOffsetAnimationCurve::Create( |
| 856 target_value, EaseInOutTimingFunction::Create().Pass())); | 851 target_value, EaseInOutTimingFunction::Create().Pass())); |
| 857 | 852 |
| 858 int animation_id = 1; | 853 int animation_id = 1; |
| 859 scoped_ptr<Animation> animation(Animation::Create( | 854 scoped_ptr<Animation> animation(Animation::Create( |
| 860 curve.Pass(), animation_id, 0, Animation::ScrollOffset)); | 855 curve.Pass(), animation_id, 0, Animation::SCROLL_OFFSET)); |
| 861 animation->set_needs_synchronized_start_time(true); | 856 animation->set_needs_synchronized_start_time(true); |
| 862 controller->AddAnimation(animation.Pass()); | 857 controller->AddAnimation(animation.Pass()); |
| 863 controller->PushAnimationUpdatesTo(controller_impl.get()); | 858 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 864 controller_impl->ActivateAnimations(); | 859 controller_impl->ActivateAnimations(); |
| 865 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | 860 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); |
| 866 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | 861 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); |
| 867 | 862 |
| 868 controller->RemoveAnimation(animation_id); | 863 controller->RemoveAnimation(animation_id); |
| 869 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted()); | 864 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted()); |
| 870 | 865 |
| 871 controller->PushAnimationUpdatesTo(controller_impl.get()); | 866 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 872 EXPECT_TRUE(controller_impl->scroll_offset_animation_was_interrupted()); | 867 EXPECT_TRUE(controller_impl->scroll_offset_animation_was_interrupted()); |
| 873 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | 868 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); |
| 874 | 869 |
| 875 controller_impl->ActivateAnimations(); | 870 controller_impl->ActivateAnimations(); |
| 876 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | 871 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); |
| 877 | 872 |
| 878 // Now, test the 2-argument version of RemoveAnimation. | 873 // Now, test the 2-argument version of RemoveAnimation. |
| 879 curve = ScrollOffsetAnimationCurve::Create( | 874 curve = ScrollOffsetAnimationCurve::Create( |
| 880 target_value, EaseInOutTimingFunction::Create().Pass()); | 875 target_value, EaseInOutTimingFunction::Create().Pass()); |
| 881 animation = | 876 animation = Animation::Create(curve.Pass(), animation_id, 0, |
| 882 Animation::Create(curve.Pass(), animation_id, 0, Animation::ScrollOffset); | 877 Animation::SCROLL_OFFSET); |
| 883 animation->set_needs_synchronized_start_time(true); | 878 animation->set_needs_synchronized_start_time(true); |
| 884 controller->AddAnimation(animation.Pass()); | 879 controller->AddAnimation(animation.Pass()); |
| 885 controller->PushAnimationUpdatesTo(controller_impl.get()); | 880 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 886 controller_impl->ActivateAnimations(); | 881 controller_impl->ActivateAnimations(); |
| 887 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | 882 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); |
| 888 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | 883 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); |
| 889 | 884 |
| 890 controller->RemoveAnimation(animation_id); | 885 controller->RemoveAnimation(animation_id); |
| 891 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted()); | 886 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted()); |
| 892 | 887 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 scoped_refptr<LayerAnimationController> controller_impl( | 963 scoped_refptr<LayerAnimationController> controller_impl( |
| 969 LayerAnimationController::Create(0)); | 964 LayerAnimationController::Create(0)); |
| 970 controller_impl->AddValueObserver(&dummy_impl); | 965 controller_impl->AddValueObserver(&dummy_impl); |
| 971 scoped_ptr<AnimationEventsVector> events( | 966 scoped_ptr<AnimationEventsVector> events( |
| 972 make_scoped_ptr(new AnimationEventsVector)); | 967 make_scoped_ptr(new AnimationEventsVector)); |
| 973 FakeAnimationDelegate delegate; | 968 FakeAnimationDelegate delegate; |
| 974 controller_impl->set_layer_animation_delegate(&delegate); | 969 controller_impl->set_layer_animation_delegate(&delegate); |
| 975 | 970 |
| 976 scoped_ptr<Animation> to_add(CreateAnimation( | 971 scoped_ptr<Animation> to_add(CreateAnimation( |
| 977 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 972 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 978 1, | 973 1, Animation::OPACITY)); |
| 979 Animation::Opacity)); | |
| 980 to_add->set_is_impl_only(true); | 974 to_add->set_is_impl_only(true); |
| 981 controller_impl->AddAnimation(to_add.Pass()); | 975 controller_impl->AddAnimation(to_add.Pass()); |
| 982 | 976 |
| 983 EXPECT_FALSE(delegate.started()); | 977 EXPECT_FALSE(delegate.started()); |
| 984 EXPECT_FALSE(delegate.finished()); | 978 EXPECT_FALSE(delegate.finished()); |
| 985 | 979 |
| 986 controller_impl->Animate(kInitialTickTime); | 980 controller_impl->Animate(kInitialTickTime); |
| 987 controller_impl->UpdateState(true, events.get()); | 981 controller_impl->UpdateState(true, events.get()); |
| 988 | 982 |
| 989 EXPECT_TRUE(delegate.started()); | 983 EXPECT_TRUE(delegate.started()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1004 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { | 998 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { |
| 1005 scoped_ptr<AnimationEventsVector> events( | 999 scoped_ptr<AnimationEventsVector> events( |
| 1006 make_scoped_ptr(new AnimationEventsVector)); | 1000 make_scoped_ptr(new AnimationEventsVector)); |
| 1007 FakeLayerAnimationValueObserver dummy; | 1001 FakeLayerAnimationValueObserver dummy; |
| 1008 scoped_refptr<LayerAnimationController> controller( | 1002 scoped_refptr<LayerAnimationController> controller( |
| 1009 LayerAnimationController::Create(0)); | 1003 LayerAnimationController::Create(0)); |
| 1010 controller->AddValueObserver(&dummy); | 1004 controller->AddValueObserver(&dummy); |
| 1011 | 1005 |
| 1012 scoped_ptr<Animation> to_add(CreateAnimation( | 1006 scoped_ptr<Animation> to_add(CreateAnimation( |
| 1013 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1007 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1014 1, | 1008 1, Animation::OPACITY)); |
| 1015 Animation::Opacity)); | |
| 1016 to_add->set_needs_synchronized_start_time(true); | 1009 to_add->set_needs_synchronized_start_time(true); |
| 1017 | 1010 |
| 1018 // We should pause at the first keyframe indefinitely waiting for that | 1011 // We should pause at the first keyframe indefinitely waiting for that |
| 1019 // animation to start. | 1012 // animation to start. |
| 1020 controller->AddAnimation(to_add.Pass()); | 1013 controller->AddAnimation(to_add.Pass()); |
| 1021 controller->Animate(kInitialTickTime); | 1014 controller->Animate(kInitialTickTime); |
| 1022 controller->UpdateState(true, events.get()); | 1015 controller->UpdateState(true, events.get()); |
| 1023 EXPECT_TRUE(controller->HasActiveAnimation()); | 1016 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1024 EXPECT_EQ(0.f, dummy.opacity()); | 1017 EXPECT_EQ(0.f, dummy.opacity()); |
| 1025 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1018 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1026 controller->UpdateState(true, events.get()); | 1019 controller->UpdateState(true, events.get()); |
| 1027 EXPECT_TRUE(controller->HasActiveAnimation()); | 1020 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1028 EXPECT_EQ(0.f, dummy.opacity()); | 1021 EXPECT_EQ(0.f, dummy.opacity()); |
| 1029 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1022 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1030 controller->UpdateState(true, events.get()); | 1023 controller->UpdateState(true, events.get()); |
| 1031 EXPECT_TRUE(controller->HasActiveAnimation()); | 1024 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1032 EXPECT_EQ(0.f, dummy.opacity()); | 1025 EXPECT_EQ(0.f, dummy.opacity()); |
| 1033 | 1026 |
| 1034 // Send the synchronized start time. | 1027 // Send the synchronized start time. |
| 1035 controller->NotifyAnimationStarted( | 1028 controller->NotifyAnimationStarted( |
| 1036 AnimationEvent(AnimationEvent::Started, | 1029 AnimationEvent(AnimationEvent::STARTED, 0, 1, Animation::OPACITY, |
| 1037 0, | |
| 1038 1, | |
| 1039 Animation::Opacity, | |
| 1040 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); | 1030 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); |
| 1041 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); | 1031 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); |
| 1042 controller->UpdateState(true, events.get()); | 1032 controller->UpdateState(true, events.get()); |
| 1043 EXPECT_EQ(1.f, dummy.opacity()); | 1033 EXPECT_EQ(1.f, dummy.opacity()); |
| 1044 EXPECT_FALSE(controller->HasActiveAnimation()); | 1034 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1045 } | 1035 } |
| 1046 | 1036 |
| 1047 // Tests that two queued animations affecting the same property run in sequence. | 1037 // Tests that two queued animations affecting the same property run in sequence. |
| 1048 TEST(LayerAnimationControllerTest, TrivialQueuing) { | 1038 TEST(LayerAnimationControllerTest, TrivialQueuing) { |
| 1049 scoped_ptr<AnimationEventsVector> events( | 1039 scoped_ptr<AnimationEventsVector> events( |
| 1050 make_scoped_ptr(new AnimationEventsVector)); | 1040 make_scoped_ptr(new AnimationEventsVector)); |
| 1051 FakeLayerAnimationValueObserver dummy; | 1041 FakeLayerAnimationValueObserver dummy; |
| 1052 scoped_refptr<LayerAnimationController> controller( | 1042 scoped_refptr<LayerAnimationController> controller( |
| 1053 LayerAnimationController::Create(0)); | 1043 LayerAnimationController::Create(0)); |
| 1054 controller->AddValueObserver(&dummy); | 1044 controller->AddValueObserver(&dummy); |
| 1055 | 1045 |
| 1056 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 1046 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 1057 | 1047 |
| 1058 controller->AddAnimation(CreateAnimation( | 1048 controller->AddAnimation(CreateAnimation( |
| 1059 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1049 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1060 1, | 1050 1, Animation::OPACITY)); |
| 1061 Animation::Opacity)); | |
| 1062 controller->AddAnimation(CreateAnimation( | 1051 controller->AddAnimation(CreateAnimation( |
| 1063 scoped_ptr<AnimationCurve>( | 1052 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)) |
| 1064 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), | 1053 .Pass(), |
| 1065 2, | 1054 2, Animation::OPACITY)); |
| 1066 Animation::Opacity)); | |
| 1067 | 1055 |
| 1068 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 1056 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 1069 | 1057 |
| 1070 controller->Animate(kInitialTickTime); | 1058 controller->Animate(kInitialTickTime); |
| 1071 | 1059 |
| 1072 // The second animation still needs to be started. | 1060 // The second animation still needs to be started. |
| 1073 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 1061 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 1074 | 1062 |
| 1075 controller->UpdateState(true, events.get()); | 1063 controller->UpdateState(true, events.get()); |
| 1076 EXPECT_TRUE(controller->HasActiveAnimation()); | 1064 EXPECT_TRUE(controller->HasActiveAnimation()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1092 // Tests interrupting a transition with another transition. | 1080 // Tests interrupting a transition with another transition. |
| 1093 TEST(LayerAnimationControllerTest, Interrupt) { | 1081 TEST(LayerAnimationControllerTest, Interrupt) { |
| 1094 scoped_ptr<AnimationEventsVector> events( | 1082 scoped_ptr<AnimationEventsVector> events( |
| 1095 make_scoped_ptr(new AnimationEventsVector)); | 1083 make_scoped_ptr(new AnimationEventsVector)); |
| 1096 FakeLayerAnimationValueObserver dummy; | 1084 FakeLayerAnimationValueObserver dummy; |
| 1097 scoped_refptr<LayerAnimationController> controller( | 1085 scoped_refptr<LayerAnimationController> controller( |
| 1098 LayerAnimationController::Create(0)); | 1086 LayerAnimationController::Create(0)); |
| 1099 controller->AddValueObserver(&dummy); | 1087 controller->AddValueObserver(&dummy); |
| 1100 controller->AddAnimation(CreateAnimation( | 1088 controller->AddAnimation(CreateAnimation( |
| 1101 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1089 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1102 1, | 1090 1, Animation::OPACITY)); |
| 1103 Animation::Opacity)); | |
| 1104 controller->Animate(kInitialTickTime); | 1091 controller->Animate(kInitialTickTime); |
| 1105 controller->UpdateState(true, events.get()); | 1092 controller->UpdateState(true, events.get()); |
| 1106 EXPECT_TRUE(controller->HasActiveAnimation()); | 1093 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1107 EXPECT_EQ(0.f, dummy.opacity()); | 1094 EXPECT_EQ(0.f, dummy.opacity()); |
| 1108 | 1095 |
| 1109 scoped_ptr<Animation> to_add(CreateAnimation( | 1096 scoped_ptr<Animation> to_add(CreateAnimation( |
| 1110 scoped_ptr<AnimationCurve>( | 1097 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)) |
| 1111 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), | 1098 .Pass(), |
| 1112 2, | 1099 2, Animation::OPACITY)); |
| 1113 Animation::Opacity)); | 1100 controller->AbortAnimations(Animation::OPACITY); |
| 1114 controller->AbortAnimations(Animation::Opacity); | |
| 1115 controller->AddAnimation(to_add.Pass()); | 1101 controller->AddAnimation(to_add.Pass()); |
| 1116 | 1102 |
| 1117 // Since the previous animation was aborted, the new animation should start | 1103 // Since the previous animation was aborted, the new animation should start |
| 1118 // right in this call to animate. | 1104 // right in this call to animate. |
| 1119 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1105 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 1120 controller->UpdateState(true, events.get()); | 1106 controller->UpdateState(true, events.get()); |
| 1121 EXPECT_TRUE(controller->HasActiveAnimation()); | 1107 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1122 EXPECT_EQ(1.f, dummy.opacity()); | 1108 EXPECT_EQ(1.f, dummy.opacity()); |
| 1123 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | 1109 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); |
| 1124 controller->UpdateState(true, events.get()); | 1110 controller->UpdateState(true, events.get()); |
| 1125 EXPECT_EQ(0.5f, dummy.opacity()); | 1111 EXPECT_EQ(0.5f, dummy.opacity()); |
| 1126 EXPECT_FALSE(controller->HasActiveAnimation()); | 1112 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1127 } | 1113 } |
| 1128 | 1114 |
| 1129 // Tests scheduling two animations to run together when only one property is | 1115 // Tests scheduling two animations to run together when only one property is |
| 1130 // free. | 1116 // free. |
| 1131 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { | 1117 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { |
| 1132 scoped_ptr<AnimationEventsVector> events( | 1118 scoped_ptr<AnimationEventsVector> events( |
| 1133 make_scoped_ptr(new AnimationEventsVector)); | 1119 make_scoped_ptr(new AnimationEventsVector)); |
| 1134 FakeLayerAnimationValueObserver dummy; | 1120 FakeLayerAnimationValueObserver dummy; |
| 1135 scoped_refptr<LayerAnimationController> controller( | 1121 scoped_refptr<LayerAnimationController> controller( |
| 1136 LayerAnimationController::Create(0)); | 1122 LayerAnimationController::Create(0)); |
| 1137 controller->AddValueObserver(&dummy); | 1123 controller->AddValueObserver(&dummy); |
| 1138 | 1124 |
| 1139 controller->AddAnimation(CreateAnimation( | 1125 controller->AddAnimation(CreateAnimation( |
| 1140 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), | 1126 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 1, |
| 1141 1, | 1127 Animation::TRANSFORM)); |
| 1142 Animation::Transform)); | |
| 1143 controller->AddAnimation(CreateAnimation( | 1128 controller->AddAnimation(CreateAnimation( |
| 1144 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), | 1129 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 2, |
| 1145 2, | 1130 Animation::TRANSFORM)); |
| 1146 Animation::Transform)); | |
| 1147 controller->AddAnimation(CreateAnimation( | 1131 controller->AddAnimation(CreateAnimation( |
| 1148 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1132 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1149 2, | 1133 2, Animation::OPACITY)); |
| 1150 Animation::Opacity)); | |
| 1151 | 1134 |
| 1152 controller->Animate(kInitialTickTime); | 1135 controller->Animate(kInitialTickTime); |
| 1153 controller->UpdateState(true, events.get()); | 1136 controller->UpdateState(true, events.get()); |
| 1154 EXPECT_EQ(0.f, dummy.opacity()); | 1137 EXPECT_EQ(0.f, dummy.opacity()); |
| 1155 EXPECT_TRUE(controller->HasActiveAnimation()); | 1138 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1156 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1139 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1157 controller->UpdateState(true, events.get()); | 1140 controller->UpdateState(true, events.get()); |
| 1158 // Should not have started the float transition yet. | 1141 // Should not have started the float transition yet. |
| 1159 EXPECT_TRUE(controller->HasActiveAnimation()); | 1142 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1160 EXPECT_EQ(0.f, dummy.opacity()); | 1143 EXPECT_EQ(0.f, dummy.opacity()); |
| 1161 // The float animation should have started at time 1 and should be done. | 1144 // The float animation should have started at time 1 and should be done. |
| 1162 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1145 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1163 controller->UpdateState(true, events.get()); | 1146 controller->UpdateState(true, events.get()); |
| 1164 EXPECT_EQ(1.f, dummy.opacity()); | 1147 EXPECT_EQ(1.f, dummy.opacity()); |
| 1165 EXPECT_FALSE(controller->HasActiveAnimation()); | 1148 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1166 } | 1149 } |
| 1167 | 1150 |
| 1168 // Tests scheduling two animations to run together with different lengths and | 1151 // Tests scheduling two animations to run together with different lengths and |
| 1169 // another animation queued to start when the shorter animation finishes (should | 1152 // another animation queued to start when the shorter animation finishes (should |
| 1170 // wait for both to finish). | 1153 // wait for both to finish). |
| 1171 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { | 1154 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { |
| 1172 scoped_ptr<AnimationEventsVector> events( | 1155 scoped_ptr<AnimationEventsVector> events( |
| 1173 make_scoped_ptr(new AnimationEventsVector)); | 1156 make_scoped_ptr(new AnimationEventsVector)); |
| 1174 FakeLayerAnimationValueObserver dummy; | 1157 FakeLayerAnimationValueObserver dummy; |
| 1175 scoped_refptr<LayerAnimationController> controller( | 1158 scoped_refptr<LayerAnimationController> controller( |
| 1176 LayerAnimationController::Create(0)); | 1159 LayerAnimationController::Create(0)); |
| 1177 controller->AddValueObserver(&dummy); | 1160 controller->AddValueObserver(&dummy); |
| 1178 | 1161 |
| 1179 controller->AddAnimation(CreateAnimation( | 1162 controller->AddAnimation(CreateAnimation( |
| 1180 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2)).Pass(), | 1163 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2)).Pass(), 1, |
| 1181 1, | 1164 Animation::TRANSFORM)); |
| 1182 Animation::Transform)); | |
| 1183 controller->AddAnimation(CreateAnimation( | 1165 controller->AddAnimation(CreateAnimation( |
| 1184 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1166 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1185 1, | 1167 1, Animation::OPACITY)); |
| 1186 Animation::Opacity)); | |
| 1187 controller->AddAnimation(CreateAnimation( | 1168 controller->AddAnimation(CreateAnimation( |
| 1188 scoped_ptr<AnimationCurve>( | 1169 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)) |
| 1189 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), | 1170 .Pass(), |
| 1190 2, | 1171 2, Animation::OPACITY)); |
| 1191 Animation::Opacity)); | |
| 1192 | 1172 |
| 1193 // Animations with id 1 should both start now. | 1173 // Animations with id 1 should both start now. |
| 1194 controller->Animate(kInitialTickTime); | 1174 controller->Animate(kInitialTickTime); |
| 1195 controller->UpdateState(true, events.get()); | 1175 controller->UpdateState(true, events.get()); |
| 1196 EXPECT_TRUE(controller->HasActiveAnimation()); | 1176 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1197 EXPECT_EQ(0.f, dummy.opacity()); | 1177 EXPECT_EQ(0.f, dummy.opacity()); |
| 1198 // The opacity animation should have finished at time 1, but the group | 1178 // The opacity animation should have finished at time 1, but the group |
| 1199 // of animations with id 1 don't finish until time 2 because of the length | 1179 // of animations with id 1 don't finish until time 2 because of the length |
| 1200 // of the transform animation. | 1180 // of the transform animation. |
| 1201 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1181 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1216 TEST(LayerAnimationControllerTest, TrivialLooping) { | 1196 TEST(LayerAnimationControllerTest, TrivialLooping) { |
| 1217 scoped_ptr<AnimationEventsVector> events( | 1197 scoped_ptr<AnimationEventsVector> events( |
| 1218 make_scoped_ptr(new AnimationEventsVector)); | 1198 make_scoped_ptr(new AnimationEventsVector)); |
| 1219 FakeLayerAnimationValueObserver dummy; | 1199 FakeLayerAnimationValueObserver dummy; |
| 1220 scoped_refptr<LayerAnimationController> controller( | 1200 scoped_refptr<LayerAnimationController> controller( |
| 1221 LayerAnimationController::Create(0)); | 1201 LayerAnimationController::Create(0)); |
| 1222 controller->AddValueObserver(&dummy); | 1202 controller->AddValueObserver(&dummy); |
| 1223 | 1203 |
| 1224 scoped_ptr<Animation> to_add(CreateAnimation( | 1204 scoped_ptr<Animation> to_add(CreateAnimation( |
| 1225 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1205 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1226 1, | 1206 1, Animation::OPACITY)); |
| 1227 Animation::Opacity)); | |
| 1228 to_add->set_iterations(3); | 1207 to_add->set_iterations(3); |
| 1229 controller->AddAnimation(to_add.Pass()); | 1208 controller->AddAnimation(to_add.Pass()); |
| 1230 | 1209 |
| 1231 controller->Animate(kInitialTickTime); | 1210 controller->Animate(kInitialTickTime); |
| 1232 controller->UpdateState(true, events.get()); | 1211 controller->UpdateState(true, events.get()); |
| 1233 EXPECT_TRUE(controller->HasActiveAnimation()); | 1212 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1234 EXPECT_EQ(0.f, dummy.opacity()); | 1213 EXPECT_EQ(0.f, dummy.opacity()); |
| 1235 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); | 1214 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); |
| 1236 controller->UpdateState(true, events.get()); | 1215 controller->UpdateState(true, events.get()); |
| 1237 EXPECT_TRUE(controller->HasActiveAnimation()); | 1216 EXPECT_TRUE(controller->HasActiveAnimation()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1263 TEST(LayerAnimationControllerTest, InfiniteLooping) { | 1242 TEST(LayerAnimationControllerTest, InfiniteLooping) { |
| 1264 scoped_ptr<AnimationEventsVector> events( | 1243 scoped_ptr<AnimationEventsVector> events( |
| 1265 make_scoped_ptr(new AnimationEventsVector)); | 1244 make_scoped_ptr(new AnimationEventsVector)); |
| 1266 FakeLayerAnimationValueObserver dummy; | 1245 FakeLayerAnimationValueObserver dummy; |
| 1267 scoped_refptr<LayerAnimationController> controller( | 1246 scoped_refptr<LayerAnimationController> controller( |
| 1268 LayerAnimationController::Create(0)); | 1247 LayerAnimationController::Create(0)); |
| 1269 controller->AddValueObserver(&dummy); | 1248 controller->AddValueObserver(&dummy); |
| 1270 | 1249 |
| 1271 scoped_ptr<Animation> to_add(CreateAnimation( | 1250 scoped_ptr<Animation> to_add(CreateAnimation( |
| 1272 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1251 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1273 1, Animation::Opacity)); | 1252 1, Animation::OPACITY)); |
| 1274 to_add->set_iterations(-1); | 1253 to_add->set_iterations(-1); |
| 1275 controller->AddAnimation(to_add.Pass()); | 1254 controller->AddAnimation(to_add.Pass()); |
| 1276 | 1255 |
| 1277 controller->Animate(kInitialTickTime); | 1256 controller->Animate(kInitialTickTime); |
| 1278 controller->UpdateState(true, events.get()); | 1257 controller->UpdateState(true, events.get()); |
| 1279 EXPECT_TRUE(controller->HasActiveAnimation()); | 1258 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1280 EXPECT_EQ(0.f, dummy.opacity()); | 1259 EXPECT_EQ(0.f, dummy.opacity()); |
| 1281 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); | 1260 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); |
| 1282 controller->UpdateState(true, events.get()); | 1261 controller->UpdateState(true, events.get()); |
| 1283 EXPECT_TRUE(controller->HasActiveAnimation()); | 1262 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1284 EXPECT_EQ(0.25f, dummy.opacity()); | 1263 EXPECT_EQ(0.25f, dummy.opacity()); |
| 1285 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); | 1264 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); |
| 1286 controller->UpdateState(true, events.get()); | 1265 controller->UpdateState(true, events.get()); |
| 1287 EXPECT_TRUE(controller->HasActiveAnimation()); | 1266 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1288 EXPECT_EQ(0.75f, dummy.opacity()); | 1267 EXPECT_EQ(0.75f, dummy.opacity()); |
| 1289 | 1268 |
| 1290 controller->Animate(kInitialTickTime + | 1269 controller->Animate(kInitialTickTime + |
| 1291 TimeDelta::FromMilliseconds(1073741824250)); | 1270 TimeDelta::FromMilliseconds(1073741824250)); |
| 1292 controller->UpdateState(true, events.get()); | 1271 controller->UpdateState(true, events.get()); |
| 1293 EXPECT_TRUE(controller->HasActiveAnimation()); | 1272 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1294 EXPECT_EQ(0.25f, dummy.opacity()); | 1273 EXPECT_EQ(0.25f, dummy.opacity()); |
| 1295 controller->Animate(kInitialTickTime + | 1274 controller->Animate(kInitialTickTime + |
| 1296 TimeDelta::FromMilliseconds(1073741824750)); | 1275 TimeDelta::FromMilliseconds(1073741824750)); |
| 1297 controller->UpdateState(true, events.get()); | 1276 controller->UpdateState(true, events.get()); |
| 1298 EXPECT_TRUE(controller->HasActiveAnimation()); | 1277 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1299 EXPECT_EQ(0.75f, dummy.opacity()); | 1278 EXPECT_EQ(0.75f, dummy.opacity()); |
| 1300 | 1279 |
| 1301 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity)); | 1280 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY)); |
| 1302 controller->GetAnimation(Animation::Opacity) | 1281 controller->GetAnimation(Animation::OPACITY) |
| 1303 ->SetRunState(Animation::Aborted, | 1282 ->SetRunState(Animation::ABORTED, |
| 1304 kInitialTickTime + TimeDelta::FromMilliseconds(750)); | 1283 kInitialTickTime + TimeDelta::FromMilliseconds(750)); |
| 1305 EXPECT_FALSE(controller->HasActiveAnimation()); | 1284 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1306 EXPECT_EQ(0.75f, dummy.opacity()); | 1285 EXPECT_EQ(0.75f, dummy.opacity()); |
| 1307 } | 1286 } |
| 1308 | 1287 |
| 1309 // Test that pausing and resuming work as expected. | 1288 // Test that pausing and resuming work as expected. |
| 1310 TEST(LayerAnimationControllerTest, PauseResume) { | 1289 TEST(LayerAnimationControllerTest, PauseResume) { |
| 1311 scoped_ptr<AnimationEventsVector> events( | 1290 scoped_ptr<AnimationEventsVector> events( |
| 1312 make_scoped_ptr(new AnimationEventsVector)); | 1291 make_scoped_ptr(new AnimationEventsVector)); |
| 1313 FakeLayerAnimationValueObserver dummy; | 1292 FakeLayerAnimationValueObserver dummy; |
| 1314 scoped_refptr<LayerAnimationController> controller( | 1293 scoped_refptr<LayerAnimationController> controller( |
| 1315 LayerAnimationController::Create(0)); | 1294 LayerAnimationController::Create(0)); |
| 1316 controller->AddValueObserver(&dummy); | 1295 controller->AddValueObserver(&dummy); |
| 1317 | 1296 |
| 1318 controller->AddAnimation(CreateAnimation( | 1297 controller->AddAnimation(CreateAnimation( |
| 1319 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1298 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1320 1, Animation::Opacity)); | 1299 1, Animation::OPACITY)); |
| 1321 | 1300 |
| 1322 controller->Animate(kInitialTickTime); | 1301 controller->Animate(kInitialTickTime); |
| 1323 controller->UpdateState(true, events.get()); | 1302 controller->UpdateState(true, events.get()); |
| 1324 EXPECT_TRUE(controller->HasActiveAnimation()); | 1303 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1325 EXPECT_EQ(0.f, dummy.opacity()); | 1304 EXPECT_EQ(0.f, dummy.opacity()); |
| 1326 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1305 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 1327 controller->UpdateState(true, events.get()); | 1306 controller->UpdateState(true, events.get()); |
| 1328 EXPECT_TRUE(controller->HasActiveAnimation()); | 1307 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1329 EXPECT_EQ(0.5f, dummy.opacity()); | 1308 EXPECT_EQ(0.5f, dummy.opacity()); |
| 1330 | 1309 |
| 1331 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity)); | 1310 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY)); |
| 1332 controller->GetAnimation(Animation::Opacity) | 1311 controller->GetAnimation(Animation::OPACITY) |
| 1333 ->SetRunState(Animation::Paused, | 1312 ->SetRunState(Animation::PAUSED, |
| 1334 kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1313 kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 1335 | 1314 |
| 1336 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); | 1315 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); |
| 1337 controller->UpdateState(true, events.get()); | 1316 controller->UpdateState(true, events.get()); |
| 1338 EXPECT_TRUE(controller->HasActiveAnimation()); | 1317 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1339 EXPECT_EQ(0.5f, dummy.opacity()); | 1318 EXPECT_EQ(0.5f, dummy.opacity()); |
| 1340 | 1319 |
| 1341 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity)); | 1320 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY)); |
| 1342 controller->GetAnimation(Animation::Opacity) | 1321 controller->GetAnimation(Animation::OPACITY) |
| 1343 ->SetRunState(Animation::Running, | 1322 ->SetRunState(Animation::RUNNING, |
| 1344 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); | 1323 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); |
| 1345 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250)); | 1324 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250)); |
| 1346 controller->UpdateState(true, events.get()); | 1325 controller->UpdateState(true, events.get()); |
| 1347 EXPECT_TRUE(controller->HasActiveAnimation()); | 1326 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1348 EXPECT_EQ(0.75f, dummy.opacity()); | 1327 EXPECT_EQ(0.75f, dummy.opacity()); |
| 1349 | 1328 |
| 1350 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); | 1329 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); |
| 1351 controller->UpdateState(true, events.get()); | 1330 controller->UpdateState(true, events.get()); |
| 1352 EXPECT_FALSE(controller->HasActiveAnimation()); | 1331 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1353 EXPECT_EQ(1.f, dummy.opacity()); | 1332 EXPECT_EQ(1.f, dummy.opacity()); |
| 1354 } | 1333 } |
| 1355 | 1334 |
| 1356 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { | 1335 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { |
| 1357 scoped_ptr<AnimationEventsVector> events( | 1336 scoped_ptr<AnimationEventsVector> events( |
| 1358 make_scoped_ptr(new AnimationEventsVector)); | 1337 make_scoped_ptr(new AnimationEventsVector)); |
| 1359 FakeLayerAnimationValueObserver dummy; | 1338 FakeLayerAnimationValueObserver dummy; |
| 1360 scoped_refptr<LayerAnimationController> controller( | 1339 scoped_refptr<LayerAnimationController> controller( |
| 1361 LayerAnimationController::Create(0)); | 1340 LayerAnimationController::Create(0)); |
| 1362 controller->AddValueObserver(&dummy); | 1341 controller->AddValueObserver(&dummy); |
| 1363 | 1342 |
| 1364 const int animation_id = 2; | 1343 const int animation_id = 2; |
| 1365 controller->AddAnimation(Animation::Create( | 1344 controller->AddAnimation(Animation::Create( |
| 1366 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 1, 1, | 1345 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 1, 1, |
| 1367 Animation::Transform)); | 1346 Animation::TRANSFORM)); |
| 1368 controller->AddAnimation(Animation::Create( | 1347 controller->AddAnimation(Animation::Create( |
| 1369 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), | 1348 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), |
| 1370 animation_id, 1, Animation::Opacity)); | 1349 animation_id, 1, Animation::OPACITY)); |
| 1371 controller->AddAnimation(Animation::Create( | 1350 controller->AddAnimation(Animation::Create( |
| 1372 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)) | 1351 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)) |
| 1373 .Pass(), | 1352 .Pass(), |
| 1374 3, 2, Animation::Opacity)); | 1353 3, 2, Animation::OPACITY)); |
| 1375 | 1354 |
| 1376 controller->Animate(kInitialTickTime); | 1355 controller->Animate(kInitialTickTime); |
| 1377 controller->UpdateState(true, events.get()); | 1356 controller->UpdateState(true, events.get()); |
| 1378 EXPECT_TRUE(controller->HasActiveAnimation()); | 1357 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1379 EXPECT_EQ(0.f, dummy.opacity()); | 1358 EXPECT_EQ(0.f, dummy.opacity()); |
| 1380 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1359 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1381 controller->UpdateState(true, events.get()); | 1360 controller->UpdateState(true, events.get()); |
| 1382 EXPECT_TRUE(controller->HasActiveAnimation()); | 1361 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1383 EXPECT_EQ(0.5f, dummy.opacity()); | 1362 EXPECT_EQ(0.5f, dummy.opacity()); |
| 1384 | 1363 |
| 1385 EXPECT_TRUE(controller->GetAnimationById(animation_id)); | 1364 EXPECT_TRUE(controller->GetAnimationById(animation_id)); |
| 1386 controller->GetAnimationById(animation_id) | 1365 controller->GetAnimationById(animation_id) |
| 1387 ->SetRunState(Animation::Aborted, | 1366 ->SetRunState(Animation::ABORTED, |
| 1388 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1367 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1389 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1368 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1390 controller->UpdateState(true, events.get()); | 1369 controller->UpdateState(true, events.get()); |
| 1391 EXPECT_TRUE(controller->HasActiveAnimation()); | 1370 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1392 EXPECT_EQ(1.f, dummy.opacity()); | 1371 EXPECT_EQ(1.f, dummy.opacity()); |
| 1393 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1372 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1394 controller->UpdateState(true, events.get()); | 1373 controller->UpdateState(true, events.get()); |
| 1395 EXPECT_TRUE(!controller->HasActiveAnimation()); | 1374 EXPECT_TRUE(!controller->HasActiveAnimation()); |
| 1396 EXPECT_EQ(0.75f, dummy.opacity()); | 1375 EXPECT_EQ(0.75f, dummy.opacity()); |
| 1397 } | 1376 } |
| 1398 | 1377 |
| 1399 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { | 1378 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { |
| 1400 FakeLayerAnimationValueObserver dummy_impl; | 1379 FakeLayerAnimationValueObserver dummy_impl; |
| 1401 scoped_refptr<LayerAnimationController> controller_impl( | 1380 scoped_refptr<LayerAnimationController> controller_impl( |
| 1402 LayerAnimationController::Create(0)); | 1381 LayerAnimationController::Create(0)); |
| 1403 controller_impl->AddValueObserver(&dummy_impl); | 1382 controller_impl->AddValueObserver(&dummy_impl); |
| 1404 scoped_ptr<AnimationEventsVector> events( | 1383 scoped_ptr<AnimationEventsVector> events( |
| 1405 make_scoped_ptr(new AnimationEventsVector)); | 1384 make_scoped_ptr(new AnimationEventsVector)); |
| 1406 FakeLayerAnimationValueObserver dummy; | 1385 FakeLayerAnimationValueObserver dummy; |
| 1407 scoped_refptr<LayerAnimationController> controller( | 1386 scoped_refptr<LayerAnimationController> controller( |
| 1408 LayerAnimationController::Create(0)); | 1387 LayerAnimationController::Create(0)); |
| 1409 controller->AddValueObserver(&dummy); | 1388 controller->AddValueObserver(&dummy); |
| 1410 | 1389 |
| 1411 scoped_ptr<Animation> to_add(CreateAnimation( | 1390 scoped_ptr<Animation> to_add(CreateAnimation( |
| 1412 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), | 1391 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), |
| 1413 0, | 1392 0, Animation::OPACITY)); |
| 1414 Animation::Opacity)); | |
| 1415 to_add->set_needs_synchronized_start_time(true); | 1393 to_add->set_needs_synchronized_start_time(true); |
| 1416 controller->AddAnimation(to_add.Pass()); | 1394 controller->AddAnimation(to_add.Pass()); |
| 1417 | 1395 |
| 1418 controller->Animate(kInitialTickTime); | 1396 controller->Animate(kInitialTickTime); |
| 1419 controller->UpdateState(true, events.get()); | 1397 controller->UpdateState(true, events.get()); |
| 1420 EXPECT_TRUE(controller->HasActiveAnimation()); | 1398 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1421 Animation* active_animation = controller->GetAnimation(Animation::Opacity); | 1399 Animation* active_animation = controller->GetAnimation(Animation::OPACITY); |
| 1422 EXPECT_TRUE(active_animation); | 1400 EXPECT_TRUE(active_animation); |
| 1423 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); | 1401 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); |
| 1424 | 1402 |
| 1425 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1403 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1426 controller_impl->ActivateAnimations(); | 1404 controller_impl->ActivateAnimations(); |
| 1427 | 1405 |
| 1428 active_animation = controller_impl->GetAnimation(Animation::Opacity); | 1406 active_animation = controller_impl->GetAnimation(Animation::OPACITY); |
| 1429 EXPECT_TRUE(active_animation); | 1407 EXPECT_TRUE(active_animation); |
| 1430 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 1408 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 1431 active_animation->run_state()); | 1409 active_animation->run_state()); |
| 1432 } | 1410 } |
| 1433 | 1411 |
| 1434 // Tests that skipping a call to UpdateState works as expected. | 1412 // Tests that skipping a call to UpdateState works as expected. |
| 1435 TEST(LayerAnimationControllerTest, SkipUpdateState) { | 1413 TEST(LayerAnimationControllerTest, SkipUpdateState) { |
| 1436 scoped_ptr<AnimationEventsVector> events( | 1414 scoped_ptr<AnimationEventsVector> events( |
| 1437 make_scoped_ptr(new AnimationEventsVector)); | 1415 make_scoped_ptr(new AnimationEventsVector)); |
| 1438 FakeLayerAnimationValueObserver dummy; | 1416 FakeLayerAnimationValueObserver dummy; |
| 1439 scoped_refptr<LayerAnimationController> controller( | 1417 scoped_refptr<LayerAnimationController> controller( |
| 1440 LayerAnimationController::Create(0)); | 1418 LayerAnimationController::Create(0)); |
| 1441 controller->AddValueObserver(&dummy); | 1419 controller->AddValueObserver(&dummy); |
| 1442 | 1420 |
| 1443 controller->AddAnimation(CreateAnimation( | 1421 controller->AddAnimation(CreateAnimation( |
| 1444 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), | 1422 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 1, |
| 1445 1, | 1423 Animation::TRANSFORM)); |
| 1446 Animation::Transform)); | |
| 1447 | 1424 |
| 1448 controller->Animate(kInitialTickTime); | 1425 controller->Animate(kInitialTickTime); |
| 1449 controller->UpdateState(true, events.get()); | 1426 controller->UpdateState(true, events.get()); |
| 1450 | 1427 |
| 1451 controller->AddAnimation(CreateAnimation( | 1428 controller->AddAnimation(CreateAnimation( |
| 1452 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1429 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1453 2, | 1430 2, Animation::OPACITY)); |
| 1454 Animation::Opacity)); | |
| 1455 | 1431 |
| 1456 // Animate but don't UpdateState. | 1432 // Animate but don't UpdateState. |
| 1457 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1433 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1458 | 1434 |
| 1459 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1435 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1460 events.reset(new AnimationEventsVector); | 1436 events.reset(new AnimationEventsVector); |
| 1461 controller->UpdateState(true, events.get()); | 1437 controller->UpdateState(true, events.get()); |
| 1462 | 1438 |
| 1463 // Should have one Started event and one Finished event. | 1439 // Should have one STARTED event and one FINISHED event. |
| 1464 EXPECT_EQ(2u, events->size()); | 1440 EXPECT_EQ(2u, events->size()); |
| 1465 EXPECT_NE((*events)[0].type, (*events)[1].type); | 1441 EXPECT_NE((*events)[0].type, (*events)[1].type); |
| 1466 | 1442 |
| 1467 // The float transition should still be at its starting point. | 1443 // The float transition should still be at its starting point. |
| 1468 EXPECT_TRUE(controller->HasActiveAnimation()); | 1444 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1469 EXPECT_EQ(0.f, dummy.opacity()); | 1445 EXPECT_EQ(0.f, dummy.opacity()); |
| 1470 | 1446 |
| 1471 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1447 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 1472 controller->UpdateState(true, events.get()); | 1448 controller->UpdateState(true, events.get()); |
| 1473 | 1449 |
| 1474 // The float tranisition should now be done. | 1450 // The float tranisition should now be done. |
| 1475 EXPECT_EQ(1.f, dummy.opacity()); | 1451 EXPECT_EQ(1.f, dummy.opacity()); |
| 1476 EXPECT_FALSE(controller->HasActiveAnimation()); | 1452 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1477 } | 1453 } |
| 1478 | 1454 |
| 1479 // Tests that an animation controller with only a pending observer gets ticked | 1455 // Tests that an animation controller with only a pending observer gets ticked |
| 1480 // but doesn't progress animations past the Starting state. | 1456 // but doesn't progress animations past the STARTING state. |
| 1481 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { | 1457 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { |
| 1482 scoped_ptr<AnimationEventsVector> events( | 1458 scoped_ptr<AnimationEventsVector> events( |
| 1483 make_scoped_ptr(new AnimationEventsVector)); | 1459 make_scoped_ptr(new AnimationEventsVector)); |
| 1484 FakeLayerAnimationValueObserver dummy; | 1460 FakeLayerAnimationValueObserver dummy; |
| 1485 FakeInactiveLayerAnimationValueObserver pending_dummy; | 1461 FakeInactiveLayerAnimationValueObserver pending_dummy; |
| 1486 scoped_refptr<LayerAnimationController> controller( | 1462 scoped_refptr<LayerAnimationController> controller( |
| 1487 LayerAnimationController::Create(0)); | 1463 LayerAnimationController::Create(0)); |
| 1488 | 1464 |
| 1489 const int id = 1; | 1465 const int id = 1; |
| 1490 controller->AddAnimation(CreateAnimation(scoped_ptr<AnimationCurve>( | 1466 controller->AddAnimation(CreateAnimation( |
| 1491 new FakeFloatTransition(1.0, 0.5f, 1.f)).Pass(), | 1467 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)) |
| 1492 id, | 1468 .Pass(), |
| 1493 Animation::Opacity)); | 1469 id, Animation::OPACITY)); |
| 1494 | 1470 |
| 1495 // Without an observer, the animation shouldn't progress to the Starting | 1471 // Without an observer, the animation shouldn't progress to the STARTING |
| 1496 // state. | 1472 // state. |
| 1497 controller->Animate(kInitialTickTime); | 1473 controller->Animate(kInitialTickTime); |
| 1498 controller->UpdateState(true, events.get()); | 1474 controller->UpdateState(true, events.get()); |
| 1499 EXPECT_EQ(0u, events->size()); | 1475 EXPECT_EQ(0u, events->size()); |
| 1500 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 1476 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 1501 controller->GetAnimation(Animation::Opacity)->run_state()); | 1477 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1502 | 1478 |
| 1503 controller->AddValueObserver(&pending_dummy); | 1479 controller->AddValueObserver(&pending_dummy); |
| 1504 | 1480 |
| 1505 // With only a pending observer, the animation should progress to the | 1481 // With only a pending observer, the animation should progress to the |
| 1506 // Starting state and get ticked at its starting point, but should not | 1482 // STARTING state and get ticked at its starting point, but should not |
| 1507 // progress to Running. | 1483 // progress to RUNNING. |
| 1508 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1484 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1509 controller->UpdateState(true, events.get()); | 1485 controller->UpdateState(true, events.get()); |
| 1510 EXPECT_EQ(0u, events->size()); | 1486 EXPECT_EQ(0u, events->size()); |
| 1511 EXPECT_EQ(Animation::Starting, | 1487 EXPECT_EQ(Animation::STARTING, |
| 1512 controller->GetAnimation(Animation::Opacity)->run_state()); | 1488 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1513 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1489 EXPECT_EQ(0.5f, pending_dummy.opacity()); |
| 1514 | 1490 |
| 1515 // Even when already in the Starting state, the animation should stay | 1491 // Even when already in the STARTING state, the animation should stay |
| 1516 // there, and shouldn't be ticked past its starting point. | 1492 // there, and shouldn't be ticked past its starting point. |
| 1517 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1493 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1518 controller->UpdateState(true, events.get()); | 1494 controller->UpdateState(true, events.get()); |
| 1519 EXPECT_EQ(0u, events->size()); | 1495 EXPECT_EQ(0u, events->size()); |
| 1520 EXPECT_EQ(Animation::Starting, | 1496 EXPECT_EQ(Animation::STARTING, |
| 1521 controller->GetAnimation(Animation::Opacity)->run_state()); | 1497 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1522 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1498 EXPECT_EQ(0.5f, pending_dummy.opacity()); |
| 1523 | 1499 |
| 1524 controller->AddValueObserver(&dummy); | 1500 controller->AddValueObserver(&dummy); |
| 1525 | 1501 |
| 1526 // Now that an active observer has been added, the animation should still | 1502 // Now that an active observer has been added, the animation should still |
| 1527 // initially tick at its starting point, but should now progress to Running. | 1503 // initially tick at its starting point, but should now progress to RUNNING. |
| 1528 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1504 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 1529 controller->UpdateState(true, events.get()); | 1505 controller->UpdateState(true, events.get()); |
| 1530 EXPECT_EQ(1u, events->size()); | 1506 EXPECT_EQ(1u, events->size()); |
| 1531 EXPECT_EQ(Animation::Running, | 1507 EXPECT_EQ(Animation::RUNNING, |
| 1532 controller->GetAnimation(Animation::Opacity)->run_state()); | 1508 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1533 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1509 EXPECT_EQ(0.5f, pending_dummy.opacity()); |
| 1534 EXPECT_EQ(0.5f, dummy.opacity()); | 1510 EXPECT_EQ(0.5f, dummy.opacity()); |
| 1535 | 1511 |
| 1536 // The animation should now tick past its starting point. | 1512 // The animation should now tick past its starting point. |
| 1537 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); | 1513 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); |
| 1538 EXPECT_NE(0.5f, pending_dummy.opacity()); | 1514 EXPECT_NE(0.5f, pending_dummy.opacity()); |
| 1539 EXPECT_NE(0.5f, dummy.opacity()); | 1515 EXPECT_NE(0.5f, dummy.opacity()); |
| 1540 } | 1516 } |
| 1541 | 1517 |
| 1542 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { | 1518 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { |
| 1543 scoped_refptr<LayerAnimationController> controller_impl( | 1519 scoped_refptr<LayerAnimationController> controller_impl( |
| 1544 LayerAnimationController::Create(0)); | 1520 LayerAnimationController::Create(0)); |
| 1545 | 1521 |
| 1546 scoped_ptr<KeyframedTransformAnimationCurve> curve1( | 1522 scoped_ptr<KeyframedTransformAnimationCurve> curve1( |
| 1547 KeyframedTransformAnimationCurve::Create()); | 1523 KeyframedTransformAnimationCurve::Create()); |
| 1548 | 1524 |
| 1549 TransformOperations operations1; | 1525 TransformOperations operations1; |
| 1550 curve1->AddKeyframe( | 1526 curve1->AddKeyframe( |
| 1551 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 1527 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
| 1552 operations1.AppendTranslate(10.0, 15.0, 0.0); | 1528 operations1.AppendTranslate(10.0, 15.0, 0.0); |
| 1553 curve1->AddKeyframe(TransformKeyframe::Create( | 1529 curve1->AddKeyframe(TransformKeyframe::Create( |
| 1554 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | 1530 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); |
| 1555 | 1531 |
| 1556 scoped_ptr<Animation> animation( | 1532 scoped_ptr<Animation> animation( |
| 1557 Animation::Create(curve1.Pass(), 1, 1, Animation::Transform)); | 1533 Animation::Create(curve1.Pass(), 1, 1, Animation::TRANSFORM)); |
| 1558 controller_impl->AddAnimation(animation.Pass()); | 1534 controller_impl->AddAnimation(animation.Pass()); |
| 1559 | 1535 |
| 1560 scoped_ptr<KeyframedTransformAnimationCurve> curve2( | 1536 scoped_ptr<KeyframedTransformAnimationCurve> curve2( |
| 1561 KeyframedTransformAnimationCurve::Create()); | 1537 KeyframedTransformAnimationCurve::Create()); |
| 1562 | 1538 |
| 1563 TransformOperations operations2; | 1539 TransformOperations operations2; |
| 1564 curve2->AddKeyframe( | 1540 curve2->AddKeyframe( |
| 1565 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | 1541 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); |
| 1566 operations2.AppendScale(2.0, 3.0, 4.0); | 1542 operations2.AppendScale(2.0, 3.0, 4.0); |
| 1567 curve2->AddKeyframe(TransformKeyframe::Create( | 1543 curve2->AddKeyframe(TransformKeyframe::Create( |
| 1568 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 1544 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
| 1569 | 1545 |
| 1570 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::Transform); | 1546 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::TRANSFORM); |
| 1571 controller_impl->AddAnimation(animation.Pass()); | 1547 controller_impl->AddAnimation(animation.Pass()); |
| 1572 | 1548 |
| 1573 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f); | 1549 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f); |
| 1574 gfx::BoxF bounds; | 1550 gfx::BoxF bounds; |
| 1575 | 1551 |
| 1576 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); | 1552 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); |
| 1577 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(), | 1553 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(), |
| 1578 bounds.ToString()); | 1554 bounds.ToString()); |
| 1579 | 1555 |
| 1580 controller_impl->GetAnimationById(1) | 1556 controller_impl->GetAnimationById(1) |
| 1581 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); | 1557 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); |
| 1582 | 1558 |
| 1583 // Only the unfinished animation should affect the animated bounds. | 1559 // Only the unfinished animation should affect the animated bounds. |
| 1584 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); | 1560 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); |
| 1585 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(), | 1561 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(), |
| 1586 bounds.ToString()); | 1562 bounds.ToString()); |
| 1587 | 1563 |
| 1588 controller_impl->GetAnimationById(2) | 1564 controller_impl->GetAnimationById(2) |
| 1589 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); | 1565 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); |
| 1590 | 1566 |
| 1591 // There are no longer any running animations. | 1567 // There are no longer any running animations. |
| 1592 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds()); | 1568 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds()); |
| 1593 | 1569 |
| 1594 // Add an animation whose bounds we don't yet support computing. | 1570 // Add an animation whose bounds we don't yet support computing. |
| 1595 scoped_ptr<KeyframedTransformAnimationCurve> curve3( | 1571 scoped_ptr<KeyframedTransformAnimationCurve> curve3( |
| 1596 KeyframedTransformAnimationCurve::Create()); | 1572 KeyframedTransformAnimationCurve::Create()); |
| 1597 TransformOperations operations3; | 1573 TransformOperations operations3; |
| 1598 gfx::Transform transform3; | 1574 gfx::Transform transform3; |
| 1599 transform3.Scale3d(1.0, 2.0, 3.0); | 1575 transform3.Scale3d(1.0, 2.0, 3.0); |
| 1600 curve3->AddKeyframe( | 1576 curve3->AddKeyframe( |
| 1601 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); | 1577 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); |
| 1602 operations3.AppendMatrix(transform3); | 1578 operations3.AppendMatrix(transform3); |
| 1603 curve3->AddKeyframe(TransformKeyframe::Create( | 1579 curve3->AddKeyframe(TransformKeyframe::Create( |
| 1604 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); | 1580 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); |
| 1605 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::Transform); | 1581 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::TRANSFORM); |
| 1606 controller_impl->AddAnimation(animation.Pass()); | 1582 controller_impl->AddAnimation(animation.Pass()); |
| 1607 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); | 1583 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); |
| 1608 } | 1584 } |
| 1609 | 1585 |
| 1610 // Tests that AbortAnimations aborts all animations targeting the specified | 1586 // Tests that AbortAnimations aborts all animations targeting the specified |
| 1611 // property. | 1587 // property. |
| 1612 TEST(LayerAnimationControllerTest, AbortAnimations) { | 1588 TEST(LayerAnimationControllerTest, AbortAnimations) { |
| 1613 FakeLayerAnimationValueObserver dummy; | 1589 FakeLayerAnimationValueObserver dummy; |
| 1614 scoped_refptr<LayerAnimationController> controller( | 1590 scoped_refptr<LayerAnimationController> controller( |
| 1615 LayerAnimationController::Create(0)); | 1591 LayerAnimationController::Create(0)); |
| 1616 controller->AddValueObserver(&dummy); | 1592 controller->AddValueObserver(&dummy); |
| 1617 | 1593 |
| 1618 // Start with several animations, and allow some of them to reach the finished | 1594 // Start with several animations, and allow some of them to reach the finished |
| 1619 // state. | 1595 // state. |
| 1620 controller->AddAnimation(Animation::Create( | 1596 controller->AddAnimation(Animation::Create( |
| 1621 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 1, 1, | 1597 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 1, 1, |
| 1622 Animation::Transform)); | 1598 Animation::TRANSFORM)); |
| 1623 controller->AddAnimation(Animation::Create( | 1599 controller->AddAnimation(Animation::Create( |
| 1624 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1600 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1625 2, 2, Animation::Opacity)); | 1601 2, 2, Animation::OPACITY)); |
| 1626 controller->AddAnimation(Animation::Create( | 1602 controller->AddAnimation(Animation::Create( |
| 1627 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 3, 3, | 1603 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 3, 3, |
| 1628 Animation::Transform)); | 1604 Animation::TRANSFORM)); |
| 1629 controller->AddAnimation(Animation::Create( | 1605 controller->AddAnimation(Animation::Create( |
| 1630 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), 4, 4, | 1606 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), 4, 4, |
| 1631 Animation::Transform)); | 1607 Animation::TRANSFORM)); |
| 1632 controller->AddAnimation(Animation::Create( | 1608 controller->AddAnimation(Animation::Create( |
| 1633 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1609 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1634 5, 5, Animation::Opacity)); | 1610 5, 5, Animation::OPACITY)); |
| 1635 | 1611 |
| 1636 controller->Animate(kInitialTickTime); | 1612 controller->Animate(kInitialTickTime); |
| 1637 controller->UpdateState(true, nullptr); | 1613 controller->UpdateState(true, nullptr); |
| 1638 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1614 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1639 controller->UpdateState(true, nullptr); | 1615 controller->UpdateState(true, nullptr); |
| 1640 | 1616 |
| 1641 EXPECT_EQ(Animation::Finished, controller->GetAnimationById(1)->run_state()); | 1617 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(1)->run_state()); |
| 1642 EXPECT_EQ(Animation::Finished, controller->GetAnimationById(2)->run_state()); | 1618 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(2)->run_state()); |
| 1643 EXPECT_EQ(Animation::Running, controller->GetAnimationById(3)->run_state()); | 1619 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(3)->run_state()); |
| 1644 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 1620 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 1645 controller->GetAnimationById(4)->run_state()); | 1621 controller->GetAnimationById(4)->run_state()); |
| 1646 EXPECT_EQ(Animation::Running, controller->GetAnimationById(5)->run_state()); | 1622 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(5)->run_state()); |
| 1647 | 1623 |
| 1648 controller->AbortAnimations(Animation::Transform); | 1624 controller->AbortAnimations(Animation::TRANSFORM); |
| 1649 | 1625 |
| 1650 // Only un-finished Transform animations should have been aborted. | 1626 // Only un-finished TRANSFORM animations should have been aborted. |
| 1651 EXPECT_EQ(Animation::Finished, controller->GetAnimationById(1)->run_state()); | 1627 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(1)->run_state()); |
| 1652 EXPECT_EQ(Animation::Finished, controller->GetAnimationById(2)->run_state()); | 1628 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(2)->run_state()); |
| 1653 EXPECT_EQ(Animation::Aborted, controller->GetAnimationById(3)->run_state()); | 1629 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(3)->run_state()); |
| 1654 EXPECT_EQ(Animation::Aborted, controller->GetAnimationById(4)->run_state()); | 1630 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(4)->run_state()); |
| 1655 EXPECT_EQ(Animation::Running, controller->GetAnimationById(5)->run_state()); | 1631 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(5)->run_state()); |
| 1656 } | 1632 } |
| 1657 | 1633 |
| 1658 // An animation aborted on the main thread should get deleted on both threads. | 1634 // An animation aborted on the main thread should get deleted on both threads. |
| 1659 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) { | 1635 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) { |
| 1660 FakeLayerAnimationValueObserver dummy_impl; | 1636 FakeLayerAnimationValueObserver dummy_impl; |
| 1661 scoped_refptr<LayerAnimationController> controller_impl( | 1637 scoped_refptr<LayerAnimationController> controller_impl( |
| 1662 LayerAnimationController::Create(0)); | 1638 LayerAnimationController::Create(0)); |
| 1663 controller_impl->AddValueObserver(&dummy_impl); | 1639 controller_impl->AddValueObserver(&dummy_impl); |
| 1664 FakeLayerAnimationValueObserver dummy; | 1640 FakeLayerAnimationValueObserver dummy; |
| 1665 scoped_refptr<LayerAnimationController> controller( | 1641 scoped_refptr<LayerAnimationController> controller( |
| 1666 LayerAnimationController::Create(0)); | 1642 LayerAnimationController::Create(0)); |
| 1667 controller->AddValueObserver(&dummy); | 1643 controller->AddValueObserver(&dummy); |
| 1668 | 1644 |
| 1669 int animation_id = | 1645 int animation_id = |
| 1670 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); | 1646 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); |
| 1671 | 1647 |
| 1672 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1648 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1673 controller_impl->ActivateAnimations(); | 1649 controller_impl->ActivateAnimations(); |
| 1674 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 1650 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 1675 | 1651 |
| 1676 controller->AbortAnimations(Animation::Opacity); | 1652 controller->AbortAnimations(Animation::OPACITY); |
| 1677 EXPECT_EQ(Animation::Aborted, | 1653 EXPECT_EQ(Animation::ABORTED, |
| 1678 controller->GetAnimation(Animation::Opacity)->run_state()); | 1654 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1679 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | 1655 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); |
| 1680 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | 1656 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); |
| 1681 | 1657 |
| 1682 controller->Animate(kInitialTickTime); | 1658 controller->Animate(kInitialTickTime); |
| 1683 controller->UpdateState(true, nullptr); | 1659 controller->UpdateState(true, nullptr); |
| 1684 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 1660 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
| 1685 EXPECT_EQ(Animation::WaitingForDeletion, | 1661 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 1686 controller->GetAnimation(Animation::Opacity)->run_state()); | 1662 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1687 | 1663 |
| 1688 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1664 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1689 controller_impl->ActivateAnimations(); | 1665 controller_impl->ActivateAnimations(); |
| 1690 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | 1666 EXPECT_FALSE(controller->GetAnimationById(animation_id)); |
| 1691 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | 1667 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); |
| 1692 } | 1668 } |
| 1693 | 1669 |
| 1694 // An animation aborted on the impl thread should get deleted on both threads. | 1670 // An animation aborted on the impl thread should get deleted on both threads. |
| 1695 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) { | 1671 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) { |
| 1696 FakeLayerAnimationValueObserver dummy_impl; | 1672 FakeLayerAnimationValueObserver dummy_impl; |
| 1697 scoped_refptr<LayerAnimationController> controller_impl( | 1673 scoped_refptr<LayerAnimationController> controller_impl( |
| 1698 LayerAnimationController::Create(0)); | 1674 LayerAnimationController::Create(0)); |
| 1699 controller_impl->AddValueObserver(&dummy_impl); | 1675 controller_impl->AddValueObserver(&dummy_impl); |
| 1700 FakeLayerAnimationValueObserver dummy; | 1676 FakeLayerAnimationValueObserver dummy; |
| 1701 scoped_refptr<LayerAnimationController> controller( | 1677 scoped_refptr<LayerAnimationController> controller( |
| 1702 LayerAnimationController::Create(0)); | 1678 LayerAnimationController::Create(0)); |
| 1703 controller->AddValueObserver(&dummy); | 1679 controller->AddValueObserver(&dummy); |
| 1704 | 1680 |
| 1705 int animation_id = | 1681 int animation_id = |
| 1706 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); | 1682 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); |
| 1707 | 1683 |
| 1708 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1684 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1709 controller_impl->ActivateAnimations(); | 1685 controller_impl->ActivateAnimations(); |
| 1710 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 1686 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 1711 | 1687 |
| 1712 controller_impl->AbortAnimations(Animation::Opacity); | 1688 controller_impl->AbortAnimations(Animation::OPACITY); |
| 1713 EXPECT_EQ(Animation::Aborted, | 1689 EXPECT_EQ(Animation::ABORTED, |
| 1714 controller_impl->GetAnimation(Animation::Opacity)->run_state()); | 1690 controller_impl->GetAnimation(Animation::OPACITY)->run_state()); |
| 1715 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | 1691 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); |
| 1716 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | 1692 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); |
| 1717 | 1693 |
| 1718 AnimationEventsVector events; | 1694 AnimationEventsVector events; |
| 1719 controller_impl->Animate(kInitialTickTime); | 1695 controller_impl->Animate(kInitialTickTime); |
| 1720 controller_impl->UpdateState(true, &events); | 1696 controller_impl->UpdateState(true, &events); |
| 1721 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | 1697 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); |
| 1722 EXPECT_EQ(1u, events.size()); | 1698 EXPECT_EQ(1u, events.size()); |
| 1723 EXPECT_EQ(AnimationEvent::Aborted, events[0].type); | 1699 EXPECT_EQ(AnimationEvent::ABORTED, events[0].type); |
| 1724 EXPECT_EQ(Animation::WaitingForDeletion, | 1700 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 1725 controller_impl->GetAnimation(Animation::Opacity)->run_state()); | 1701 controller_impl->GetAnimation(Animation::OPACITY)->run_state()); |
| 1726 | 1702 |
| 1727 controller->NotifyAnimationAborted(events[0]); | 1703 controller->NotifyAnimationAborted(events[0]); |
| 1728 EXPECT_EQ(Animation::Aborted, | 1704 EXPECT_EQ(Animation::ABORTED, |
| 1729 controller->GetAnimation(Animation::Opacity)->run_state()); | 1705 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1730 | 1706 |
| 1731 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1707 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 1732 controller->UpdateState(true, nullptr); | 1708 controller->UpdateState(true, nullptr); |
| 1733 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 1709 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
| 1734 EXPECT_EQ(Animation::WaitingForDeletion, | 1710 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 1735 controller->GetAnimation(Animation::Opacity)->run_state()); | 1711 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1736 | 1712 |
| 1737 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1713 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1738 controller_impl->ActivateAnimations(); | 1714 controller_impl->ActivateAnimations(); |
| 1739 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | 1715 EXPECT_FALSE(controller->GetAnimationById(animation_id)); |
| 1740 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | 1716 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); |
| 1741 } | 1717 } |
| 1742 | 1718 |
| 1743 // Ensure that we only generate Finished events for animations in a group | 1719 // Ensure that we only generate FINISHED events for animations in a group |
| 1744 // once all animations in that group are finished. | 1720 // once all animations in that group are finished. |
| 1745 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { | 1721 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { |
| 1746 scoped_ptr<AnimationEventsVector> events( | 1722 scoped_ptr<AnimationEventsVector> events( |
| 1747 make_scoped_ptr(new AnimationEventsVector)); | 1723 make_scoped_ptr(new AnimationEventsVector)); |
| 1748 FakeLayerAnimationValueObserver dummy_impl; | 1724 FakeLayerAnimationValueObserver dummy_impl; |
| 1749 scoped_refptr<LayerAnimationController> controller_impl( | 1725 scoped_refptr<LayerAnimationController> controller_impl( |
| 1750 LayerAnimationController::Create(0)); | 1726 LayerAnimationController::Create(0)); |
| 1751 controller_impl->AddValueObserver(&dummy_impl); | 1727 controller_impl->AddValueObserver(&dummy_impl); |
| 1752 | 1728 |
| 1753 const int group_id = 1; | 1729 const int group_id = 1; |
| 1754 | 1730 |
| 1755 // Add two animations with the same group id but different durations. | 1731 // Add two animations with the same group id but different durations. |
| 1756 controller_impl->AddAnimation(Animation::Create( | 1732 controller_impl->AddAnimation(Animation::Create( |
| 1757 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), 1, | 1733 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), 1, |
| 1758 group_id, Animation::Transform)); | 1734 group_id, Animation::TRANSFORM)); |
| 1759 controller_impl->AddAnimation(Animation::Create( | 1735 controller_impl->AddAnimation(Animation::Create( |
| 1760 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1736 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1761 2, group_id, Animation::Opacity)); | 1737 2, group_id, Animation::OPACITY)); |
| 1762 | 1738 |
| 1763 controller_impl->Animate(kInitialTickTime); | 1739 controller_impl->Animate(kInitialTickTime); |
| 1764 controller_impl->UpdateState(true, events.get()); | 1740 controller_impl->UpdateState(true, events.get()); |
| 1765 | 1741 |
| 1766 // Both animations should have started. | 1742 // Both animations should have started. |
| 1767 EXPECT_EQ(2u, events->size()); | 1743 EXPECT_EQ(2u, events->size()); |
| 1768 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); | 1744 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type); |
| 1769 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); | 1745 EXPECT_EQ(AnimationEvent::STARTED, (*events)[1].type); |
| 1770 | 1746 |
| 1771 events.reset(new AnimationEventsVector); | 1747 events.reset(new AnimationEventsVector); |
| 1772 controller_impl->Animate(kInitialTickTime + | 1748 controller_impl->Animate(kInitialTickTime + |
| 1773 TimeDelta::FromMilliseconds(1000)); | 1749 TimeDelta::FromMilliseconds(1000)); |
| 1774 controller_impl->UpdateState(true, events.get()); | 1750 controller_impl->UpdateState(true, events.get()); |
| 1775 | 1751 |
| 1776 // The opacity animation should be finished, but should not have generated | 1752 // The opacity animation should be finished, but should not have generated |
| 1777 // a Finished event yet. | 1753 // a FINISHED event yet. |
| 1778 EXPECT_EQ(0u, events->size()); | 1754 EXPECT_EQ(0u, events->size()); |
| 1779 EXPECT_EQ(Animation::Finished, | 1755 EXPECT_EQ(Animation::FINISHED, |
| 1780 controller_impl->GetAnimationById(2)->run_state()); | 1756 controller_impl->GetAnimationById(2)->run_state()); |
| 1781 EXPECT_EQ(Animation::Running, | 1757 EXPECT_EQ(Animation::RUNNING, |
| 1782 controller_impl->GetAnimationById(1)->run_state()); | 1758 controller_impl->GetAnimationById(1)->run_state()); |
| 1783 | 1759 |
| 1784 controller_impl->Animate(kInitialTickTime + | 1760 controller_impl->Animate(kInitialTickTime + |
| 1785 TimeDelta::FromMilliseconds(2000)); | 1761 TimeDelta::FromMilliseconds(2000)); |
| 1786 controller_impl->UpdateState(true, events.get()); | 1762 controller_impl->UpdateState(true, events.get()); |
| 1787 | 1763 |
| 1788 // Both animations should have generated Finished events. | 1764 // Both animations should have generated FINISHED events. |
| 1789 EXPECT_EQ(2u, events->size()); | 1765 EXPECT_EQ(2u, events->size()); |
| 1790 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 1766 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type); |
| 1791 EXPECT_EQ(AnimationEvent::Finished, (*events)[1].type); | 1767 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[1].type); |
| 1792 } | 1768 } |
| 1793 | 1769 |
| 1794 // Ensure that when a group has a mix of aborted and finished animations, | 1770 // Ensure that when a group has a mix of aborted and finished animations, |
| 1795 // we generate a Finished event for the finished animation and an Aborted | 1771 // we generate a FINISHED event for the finished animation and an ABORTED |
| 1796 // event for the aborted animation. | 1772 // event for the aborted animation. |
| 1797 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { | 1773 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { |
| 1798 scoped_ptr<AnimationEventsVector> events( | 1774 scoped_ptr<AnimationEventsVector> events( |
| 1799 make_scoped_ptr(new AnimationEventsVector)); | 1775 make_scoped_ptr(new AnimationEventsVector)); |
| 1800 FakeLayerAnimationValueObserver dummy_impl; | 1776 FakeLayerAnimationValueObserver dummy_impl; |
| 1801 scoped_refptr<LayerAnimationController> controller_impl( | 1777 scoped_refptr<LayerAnimationController> controller_impl( |
| 1802 LayerAnimationController::Create(0)); | 1778 LayerAnimationController::Create(0)); |
| 1803 controller_impl->AddValueObserver(&dummy_impl); | 1779 controller_impl->AddValueObserver(&dummy_impl); |
| 1804 | 1780 |
| 1805 // Add two animations with the same group id. | 1781 // Add two animations with the same group id. |
| 1806 controller_impl->AddAnimation(CreateAnimation( | 1782 controller_impl->AddAnimation(CreateAnimation( |
| 1807 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), | 1783 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 1, |
| 1808 1, | 1784 Animation::TRANSFORM)); |
| 1809 Animation::Transform)); | |
| 1810 controller_impl->AddAnimation(CreateAnimation( | 1785 controller_impl->AddAnimation(CreateAnimation( |
| 1811 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1786 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1812 1, | 1787 1, Animation::OPACITY)); |
| 1813 Animation::Opacity)); | |
| 1814 | 1788 |
| 1815 controller_impl->Animate(kInitialTickTime); | 1789 controller_impl->Animate(kInitialTickTime); |
| 1816 controller_impl->UpdateState(true, events.get()); | 1790 controller_impl->UpdateState(true, events.get()); |
| 1817 | 1791 |
| 1818 // Both animations should have started. | 1792 // Both animations should have started. |
| 1819 EXPECT_EQ(2u, events->size()); | 1793 EXPECT_EQ(2u, events->size()); |
| 1820 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); | 1794 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type); |
| 1821 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); | 1795 EXPECT_EQ(AnimationEvent::STARTED, (*events)[1].type); |
| 1822 | 1796 |
| 1823 controller_impl->AbortAnimations(Animation::Opacity); | 1797 controller_impl->AbortAnimations(Animation::OPACITY); |
| 1824 | 1798 |
| 1825 events.reset(new AnimationEventsVector); | 1799 events.reset(new AnimationEventsVector); |
| 1826 controller_impl->Animate(kInitialTickTime + | 1800 controller_impl->Animate(kInitialTickTime + |
| 1827 TimeDelta::FromMilliseconds(1000)); | 1801 TimeDelta::FromMilliseconds(1000)); |
| 1828 controller_impl->UpdateState(true, events.get()); | 1802 controller_impl->UpdateState(true, events.get()); |
| 1829 | 1803 |
| 1830 // We should have exactly 2 events: a Finished event for the tranform | 1804 // We should have exactly 2 events: a FINISHED event for the tranform |
| 1831 // animation, and an Aborted event for the opacity animation. | 1805 // animation, and an ABORTED event for the opacity animation. |
| 1832 EXPECT_EQ(2u, events->size()); | 1806 EXPECT_EQ(2u, events->size()); |
| 1833 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 1807 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type); |
| 1834 EXPECT_EQ(Animation::Transform, (*events)[0].target_property); | 1808 EXPECT_EQ(Animation::TRANSFORM, (*events)[0].target_property); |
| 1835 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type); | 1809 EXPECT_EQ(AnimationEvent::ABORTED, (*events)[1].type); |
| 1836 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property); | 1810 EXPECT_EQ(Animation::OPACITY, (*events)[1].target_property); |
| 1837 } | 1811 } |
| 1838 | 1812 |
| 1839 TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) { | 1813 TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) { |
| 1840 scoped_refptr<LayerAnimationController> controller_impl( | 1814 scoped_refptr<LayerAnimationController> controller_impl( |
| 1841 LayerAnimationController::Create(0)); | 1815 LayerAnimationController::Create(0)); |
| 1842 | 1816 |
| 1843 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); | 1817 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); |
| 1844 | 1818 |
| 1845 controller_impl->AddAnimation(CreateAnimation( | 1819 controller_impl->AddAnimation(CreateAnimation( |
| 1846 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1820 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1847 1, | 1821 1, Animation::OPACITY)); |
| 1848 Animation::Opacity)); | |
| 1849 | 1822 |
| 1850 // Opacity animations don't affect scale. | 1823 // Opacity animations don't affect scale. |
| 1851 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); | 1824 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); |
| 1852 | 1825 |
| 1853 scoped_ptr<KeyframedTransformAnimationCurve> curve1( | 1826 scoped_ptr<KeyframedTransformAnimationCurve> curve1( |
| 1854 KeyframedTransformAnimationCurve::Create()); | 1827 KeyframedTransformAnimationCurve::Create()); |
| 1855 | 1828 |
| 1856 TransformOperations operations1; | 1829 TransformOperations operations1; |
| 1857 curve1->AddKeyframe( | 1830 curve1->AddKeyframe( |
| 1858 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 1831 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
| 1859 operations1.AppendTranslate(10.0, 15.0, 0.0); | 1832 operations1.AppendTranslate(10.0, 15.0, 0.0); |
| 1860 curve1->AddKeyframe(TransformKeyframe::Create( | 1833 curve1->AddKeyframe(TransformKeyframe::Create( |
| 1861 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | 1834 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); |
| 1862 | 1835 |
| 1863 scoped_ptr<Animation> animation( | 1836 scoped_ptr<Animation> animation( |
| 1864 Animation::Create(curve1.Pass(), 2, 2, Animation::Transform)); | 1837 Animation::Create(curve1.Pass(), 2, 2, Animation::TRANSFORM)); |
| 1865 controller_impl->AddAnimation(animation.Pass()); | 1838 controller_impl->AddAnimation(animation.Pass()); |
| 1866 | 1839 |
| 1867 // Translations don't affect scale. | 1840 // Translations don't affect scale. |
| 1868 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); | 1841 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); |
| 1869 | 1842 |
| 1870 scoped_ptr<KeyframedTransformAnimationCurve> curve2( | 1843 scoped_ptr<KeyframedTransformAnimationCurve> curve2( |
| 1871 KeyframedTransformAnimationCurve::Create()); | 1844 KeyframedTransformAnimationCurve::Create()); |
| 1872 | 1845 |
| 1873 TransformOperations operations2; | 1846 TransformOperations operations2; |
| 1874 curve2->AddKeyframe( | 1847 curve2->AddKeyframe( |
| 1875 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | 1848 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); |
| 1876 operations2.AppendScale(2.0, 3.0, 4.0); | 1849 operations2.AppendScale(2.0, 3.0, 4.0); |
| 1877 curve2->AddKeyframe(TransformKeyframe::Create( | 1850 curve2->AddKeyframe(TransformKeyframe::Create( |
| 1878 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 1851 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
| 1879 | 1852 |
| 1880 animation = Animation::Create(curve2.Pass(), 3, 3, Animation::Transform); | 1853 animation = Animation::Create(curve2.Pass(), 3, 3, Animation::TRANSFORM); |
| 1881 controller_impl->AddAnimation(animation.Pass()); | 1854 controller_impl->AddAnimation(animation.Pass()); |
| 1882 | 1855 |
| 1883 EXPECT_TRUE(controller_impl->HasAnimationThatAffectsScale()); | 1856 EXPECT_TRUE(controller_impl->HasAnimationThatAffectsScale()); |
| 1884 | 1857 |
| 1885 controller_impl->GetAnimationById(3) | 1858 controller_impl->GetAnimationById(3) |
| 1886 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); | 1859 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); |
| 1887 | 1860 |
| 1888 // Only unfinished animations should be considered by | 1861 // Only unfinished animations should be considered by |
| 1889 // HasAnimationThatAffectsScale. | 1862 // HasAnimationThatAffectsScale. |
| 1890 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); | 1863 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); |
| 1891 } | 1864 } |
| 1892 | 1865 |
| 1893 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) { | 1866 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) { |
| 1894 scoped_refptr<LayerAnimationController> controller_impl( | 1867 scoped_refptr<LayerAnimationController> controller_impl( |
| 1895 LayerAnimationController::Create(0)); | 1868 LayerAnimationController::Create(0)); |
| 1896 | 1869 |
| 1897 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); | 1870 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); |
| 1898 | 1871 |
| 1899 controller_impl->AddAnimation(CreateAnimation( | 1872 controller_impl->AddAnimation(CreateAnimation( |
| 1900 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 1873 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 1901 1, | 1874 1, Animation::OPACITY)); |
| 1902 Animation::Opacity)); | |
| 1903 | 1875 |
| 1904 // Opacity animations aren't non-translation transforms. | 1876 // Opacity animations aren't non-translation transforms. |
| 1905 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); | 1877 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); |
| 1906 | 1878 |
| 1907 scoped_ptr<KeyframedTransformAnimationCurve> curve1( | 1879 scoped_ptr<KeyframedTransformAnimationCurve> curve1( |
| 1908 KeyframedTransformAnimationCurve::Create()); | 1880 KeyframedTransformAnimationCurve::Create()); |
| 1909 | 1881 |
| 1910 TransformOperations operations1; | 1882 TransformOperations operations1; |
| 1911 curve1->AddKeyframe( | 1883 curve1->AddKeyframe( |
| 1912 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 1884 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
| 1913 operations1.AppendTranslate(10.0, 15.0, 0.0); | 1885 operations1.AppendTranslate(10.0, 15.0, 0.0); |
| 1914 curve1->AddKeyframe(TransformKeyframe::Create( | 1886 curve1->AddKeyframe(TransformKeyframe::Create( |
| 1915 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | 1887 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); |
| 1916 | 1888 |
| 1917 scoped_ptr<Animation> animation( | 1889 scoped_ptr<Animation> animation( |
| 1918 Animation::Create(curve1.Pass(), 2, 2, Animation::Transform)); | 1890 Animation::Create(curve1.Pass(), 2, 2, Animation::TRANSFORM)); |
| 1919 controller_impl->AddAnimation(animation.Pass()); | 1891 controller_impl->AddAnimation(animation.Pass()); |
| 1920 | 1892 |
| 1921 // The only transform animation we've added is a translation. | 1893 // The only transform animation we've added is a translation. |
| 1922 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); | 1894 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); |
| 1923 | 1895 |
| 1924 scoped_ptr<KeyframedTransformAnimationCurve> curve2( | 1896 scoped_ptr<KeyframedTransformAnimationCurve> curve2( |
| 1925 KeyframedTransformAnimationCurve::Create()); | 1897 KeyframedTransformAnimationCurve::Create()); |
| 1926 | 1898 |
| 1927 TransformOperations operations2; | 1899 TransformOperations operations2; |
| 1928 curve2->AddKeyframe( | 1900 curve2->AddKeyframe( |
| 1929 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | 1901 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); |
| 1930 operations2.AppendScale(2.0, 3.0, 4.0); | 1902 operations2.AppendScale(2.0, 3.0, 4.0); |
| 1931 curve2->AddKeyframe(TransformKeyframe::Create( | 1903 curve2->AddKeyframe(TransformKeyframe::Create( |
| 1932 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 1904 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
| 1933 | 1905 |
| 1934 animation = Animation::Create(curve2.Pass(), 3, 3, Animation::Transform); | 1906 animation = Animation::Create(curve2.Pass(), 3, 3, Animation::TRANSFORM); |
| 1935 controller_impl->AddAnimation(animation.Pass()); | 1907 controller_impl->AddAnimation(animation.Pass()); |
| 1936 | 1908 |
| 1937 // A scale animation is not a translation. | 1909 // A scale animation is not a translation. |
| 1938 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms()); | 1910 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms()); |
| 1939 | 1911 |
| 1940 controller_impl->GetAnimationById(3) | 1912 controller_impl->GetAnimationById(3) |
| 1941 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); | 1913 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); |
| 1942 | 1914 |
| 1943 // Only unfinished animations should be considered by | 1915 // Only unfinished animations should be considered by |
| 1944 // HasOnlyTranslationTransforms. | 1916 // HasOnlyTranslationTransforms. |
| 1945 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); | 1917 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); |
| 1946 } | 1918 } |
| 1947 | 1919 |
| 1948 TEST(LayerAnimationControllerTest, MaximumTargetScale) { | 1920 TEST(LayerAnimationControllerTest, MaximumTargetScale) { |
| 1949 scoped_refptr<LayerAnimationController> controller_impl( | 1921 scoped_refptr<LayerAnimationController> controller_impl( |
| 1950 LayerAnimationController::Create(0)); | 1922 LayerAnimationController::Create(0)); |
| 1951 | 1923 |
| 1952 float max_scale = 0.f; | 1924 float max_scale = 0.f; |
| 1953 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 1925 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 1954 EXPECT_EQ(0.f, max_scale); | 1926 EXPECT_EQ(0.f, max_scale); |
| 1955 | 1927 |
| 1956 scoped_ptr<KeyframedTransformAnimationCurve> curve1( | 1928 scoped_ptr<KeyframedTransformAnimationCurve> curve1( |
| 1957 KeyframedTransformAnimationCurve::Create()); | 1929 KeyframedTransformAnimationCurve::Create()); |
| 1958 | 1930 |
| 1959 TransformOperations operations1; | 1931 TransformOperations operations1; |
| 1960 curve1->AddKeyframe( | 1932 curve1->AddKeyframe( |
| 1961 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 1933 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
| 1962 operations1.AppendScale(2.0, 3.0, 4.0); | 1934 operations1.AppendScale(2.0, 3.0, 4.0); |
| 1963 curve1->AddKeyframe(TransformKeyframe::Create( | 1935 curve1->AddKeyframe(TransformKeyframe::Create( |
| 1964 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | 1936 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); |
| 1965 | 1937 |
| 1966 scoped_ptr<Animation> animation( | 1938 scoped_ptr<Animation> animation( |
| 1967 Animation::Create(curve1.Pass(), 1, 1, Animation::Transform)); | 1939 Animation::Create(curve1.Pass(), 1, 1, Animation::TRANSFORM)); |
| 1968 controller_impl->AddAnimation(animation.Pass()); | 1940 controller_impl->AddAnimation(animation.Pass()); |
| 1969 | 1941 |
| 1970 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 1942 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 1971 EXPECT_EQ(4.f, max_scale); | 1943 EXPECT_EQ(4.f, max_scale); |
| 1972 | 1944 |
| 1973 scoped_ptr<KeyframedTransformAnimationCurve> curve2( | 1945 scoped_ptr<KeyframedTransformAnimationCurve> curve2( |
| 1974 KeyframedTransformAnimationCurve::Create()); | 1946 KeyframedTransformAnimationCurve::Create()); |
| 1975 | 1947 |
| 1976 TransformOperations operations2; | 1948 TransformOperations operations2; |
| 1977 curve2->AddKeyframe( | 1949 curve2->AddKeyframe( |
| 1978 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | 1950 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); |
| 1979 operations2.AppendScale(6.0, 5.0, 4.0); | 1951 operations2.AppendScale(6.0, 5.0, 4.0); |
| 1980 curve2->AddKeyframe(TransformKeyframe::Create( | 1952 curve2->AddKeyframe(TransformKeyframe::Create( |
| 1981 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 1953 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
| 1982 | 1954 |
| 1983 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::Transform); | 1955 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::TRANSFORM); |
| 1984 controller_impl->AddAnimation(animation.Pass()); | 1956 controller_impl->AddAnimation(animation.Pass()); |
| 1985 | 1957 |
| 1986 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 1958 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 1987 EXPECT_EQ(6.f, max_scale); | 1959 EXPECT_EQ(6.f, max_scale); |
| 1988 | 1960 |
| 1989 scoped_ptr<KeyframedTransformAnimationCurve> curve3( | 1961 scoped_ptr<KeyframedTransformAnimationCurve> curve3( |
| 1990 KeyframedTransformAnimationCurve::Create()); | 1962 KeyframedTransformAnimationCurve::Create()); |
| 1991 | 1963 |
| 1992 TransformOperations operations3; | 1964 TransformOperations operations3; |
| 1993 curve3->AddKeyframe( | 1965 curve3->AddKeyframe( |
| 1994 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); | 1966 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); |
| 1995 operations3.AppendPerspective(6.0); | 1967 operations3.AppendPerspective(6.0); |
| 1996 curve3->AddKeyframe(TransformKeyframe::Create( | 1968 curve3->AddKeyframe(TransformKeyframe::Create( |
| 1997 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); | 1969 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); |
| 1998 | 1970 |
| 1999 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::Transform); | 1971 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::TRANSFORM); |
| 2000 controller_impl->AddAnimation(animation.Pass()); | 1972 controller_impl->AddAnimation(animation.Pass()); |
| 2001 | 1973 |
| 2002 EXPECT_FALSE(controller_impl->MaximumTargetScale(&max_scale)); | 1974 EXPECT_FALSE(controller_impl->MaximumTargetScale(&max_scale)); |
| 2003 | 1975 |
| 2004 controller_impl->GetAnimationById(3) | 1976 controller_impl->GetAnimationById(3) |
| 2005 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); | 1977 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); |
| 2006 controller_impl->GetAnimationById(2) | 1978 controller_impl->GetAnimationById(2) |
| 2007 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); | 1979 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); |
| 2008 | 1980 |
| 2009 // Only unfinished animations should be considered by | 1981 // Only unfinished animations should be considered by |
| 2010 // MaximumTargetScale. | 1982 // MaximumTargetScale. |
| 2011 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 1983 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 2012 EXPECT_EQ(4.f, max_scale); | 1984 EXPECT_EQ(4.f, max_scale); |
| 2013 } | 1985 } |
| 2014 | 1986 |
| 2015 TEST(LayerAnimationControllerTest, MaximumTargetScaleWithDirection) { | 1987 TEST(LayerAnimationControllerTest, MaximumTargetScaleWithDirection) { |
| 2016 scoped_refptr<LayerAnimationController> controller_impl( | 1988 scoped_refptr<LayerAnimationController> controller_impl( |
| 2017 LayerAnimationController::Create(0)); | 1989 LayerAnimationController::Create(0)); |
| 2018 | 1990 |
| 2019 scoped_ptr<KeyframedTransformAnimationCurve> curve1( | 1991 scoped_ptr<KeyframedTransformAnimationCurve> curve1( |
| 2020 KeyframedTransformAnimationCurve::Create()); | 1992 KeyframedTransformAnimationCurve::Create()); |
| 2021 TransformOperations operations1; | 1993 TransformOperations operations1; |
| 2022 operations1.AppendScale(1.0, 2.0, 3.0); | 1994 operations1.AppendScale(1.0, 2.0, 3.0); |
| 2023 curve1->AddKeyframe( | 1995 curve1->AddKeyframe( |
| 2024 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 1996 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
| 2025 TransformOperations operations2; | 1997 TransformOperations operations2; |
| 2026 operations2.AppendScale(4.0, 5.0, 6.0); | 1998 operations2.AppendScale(4.0, 5.0, 6.0); |
| 2027 curve1->AddKeyframe(TransformKeyframe::Create( | 1999 curve1->AddKeyframe(TransformKeyframe::Create( |
| 2028 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 2000 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
| 2029 | 2001 |
| 2030 scoped_ptr<Animation> animation_owned( | 2002 scoped_ptr<Animation> animation_owned( |
| 2031 Animation::Create(curve1.Pass(), 1, 1, Animation::Transform)); | 2003 Animation::Create(curve1.Pass(), 1, 1, Animation::TRANSFORM)); |
| 2032 Animation* animation = animation_owned.get(); | 2004 Animation* animation = animation_owned.get(); |
| 2033 controller_impl->AddAnimation(animation_owned.Pass()); | 2005 controller_impl->AddAnimation(animation_owned.Pass()); |
| 2034 | 2006 |
| 2035 float max_scale = 0.f; | 2007 float max_scale = 0.f; |
| 2036 | 2008 |
| 2037 EXPECT_GT(animation->playback_rate(), 0.0); | 2009 EXPECT_GT(animation->playback_rate(), 0.0); |
| 2038 | 2010 |
| 2039 // Normal direction with positive playback rate. | 2011 // NORMAL direction with positive playback rate. |
| 2040 animation->set_direction(Animation::Normal); | 2012 animation->set_direction(Animation::DIRECTION_NORMAL); |
| 2041 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 2013 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 2042 EXPECT_EQ(6.f, max_scale); | 2014 EXPECT_EQ(6.f, max_scale); |
| 2043 | 2015 |
| 2044 // Alternate direction with positive playback rate. | 2016 // ALTERNATE direction with positive playback rate. |
| 2045 animation->set_direction(Animation::Alternate); | 2017 animation->set_direction(Animation::DIRECTION_ALTERNATE); |
| 2046 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 2018 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 2047 EXPECT_EQ(6.f, max_scale); | 2019 EXPECT_EQ(6.f, max_scale); |
| 2048 | 2020 |
| 2049 // Reverse direction with positive playback rate. | 2021 // REVERSE direction with positive playback rate. |
| 2050 animation->set_direction(Animation::Reverse); | 2022 animation->set_direction(Animation::DIRECTION_REVERSE); |
| 2051 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 2023 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 2052 EXPECT_EQ(3.f, max_scale); | 2024 EXPECT_EQ(3.f, max_scale); |
| 2053 | 2025 |
| 2054 // Alternate reverse direction. | 2026 // ALTERNATE reverse direction. |
| 2055 animation->set_direction(Animation::Reverse); | 2027 animation->set_direction(Animation::DIRECTION_REVERSE); |
| 2056 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 2028 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 2057 EXPECT_EQ(3.f, max_scale); | 2029 EXPECT_EQ(3.f, max_scale); |
| 2058 | 2030 |
| 2059 animation->set_playback_rate(-1.0); | 2031 animation->set_playback_rate(-1.0); |
| 2060 | 2032 |
| 2061 // Normal direction with negative playback rate. | 2033 // NORMAL direction with negative playback rate. |
| 2062 animation->set_direction(Animation::Normal); | 2034 animation->set_direction(Animation::DIRECTION_NORMAL); |
| 2063 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 2035 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 2064 EXPECT_EQ(3.f, max_scale); | 2036 EXPECT_EQ(3.f, max_scale); |
| 2065 | 2037 |
| 2066 // Alternate direction with negative playback rate. | 2038 // ALTERNATE direction with negative playback rate. |
| 2067 animation->set_direction(Animation::Alternate); | 2039 animation->set_direction(Animation::DIRECTION_ALTERNATE); |
| 2068 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 2040 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 2069 EXPECT_EQ(3.f, max_scale); | 2041 EXPECT_EQ(3.f, max_scale); |
| 2070 | 2042 |
| 2071 // Reverse direction with negative playback rate. | 2043 // REVERSE direction with negative playback rate. |
| 2072 animation->set_direction(Animation::Reverse); | 2044 animation->set_direction(Animation::DIRECTION_REVERSE); |
| 2073 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 2045 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 2074 EXPECT_EQ(6.f, max_scale); | 2046 EXPECT_EQ(6.f, max_scale); |
| 2075 | 2047 |
| 2076 // Alternate reverse direction with negative playback rate. | 2048 // ALTERNATE reverse direction with negative playback rate. |
| 2077 animation->set_direction(Animation::Reverse); | 2049 animation->set_direction(Animation::DIRECTION_REVERSE); |
| 2078 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); | 2050 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); |
| 2079 EXPECT_EQ(6.f, max_scale); | 2051 EXPECT_EQ(6.f, max_scale); |
| 2080 } | 2052 } |
| 2081 | 2053 |
| 2082 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { | 2054 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { |
| 2083 scoped_ptr<AnimationEventsVector> events( | 2055 scoped_ptr<AnimationEventsVector> events( |
| 2084 make_scoped_ptr(new AnimationEventsVector)); | 2056 make_scoped_ptr(new AnimationEventsVector)); |
| 2085 FakeLayerAnimationValueObserver dummy_impl; | 2057 FakeLayerAnimationValueObserver dummy_impl; |
| 2086 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | 2058 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; |
| 2087 scoped_refptr<LayerAnimationController> controller_impl( | 2059 scoped_refptr<LayerAnimationController> controller_impl( |
| 2088 LayerAnimationController::Create(0)); | 2060 LayerAnimationController::Create(0)); |
| 2089 controller_impl->AddValueObserver(&dummy_impl); | 2061 controller_impl->AddValueObserver(&dummy_impl); |
| 2090 controller_impl->AddValueObserver(&pending_dummy_impl); | 2062 controller_impl->AddValueObserver(&pending_dummy_impl); |
| 2091 FakeLayerAnimationValueObserver dummy; | 2063 FakeLayerAnimationValueObserver dummy; |
| 2092 scoped_refptr<LayerAnimationController> controller( | 2064 scoped_refptr<LayerAnimationController> controller( |
| 2093 LayerAnimationController::Create(0)); | 2065 LayerAnimationController::Create(0)); |
| 2094 controller->AddValueObserver(&dummy); | 2066 controller->AddValueObserver(&dummy); |
| 2095 | 2067 |
| 2096 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 2068 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 2097 int animation_id = | 2069 int animation_id = |
| 2098 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false); | 2070 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false); |
| 2099 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 2071 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 2100 | 2072 |
| 2101 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | 2073 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); |
| 2102 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2074 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2103 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); | 2075 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); |
| 2104 | 2076 |
| 2105 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 2077 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 2106 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 2078 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 2107 controller_impl->GetAnimationById(animation_id)->run_state()); | 2079 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2108 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2080 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2109 ->affects_pending_observers()); | 2081 ->affects_pending_observers()); |
| 2110 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | 2082 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) |
| 2111 ->affects_active_observers()); | 2083 ->affects_active_observers()); |
| 2112 | 2084 |
| 2113 controller_impl->Animate(kInitialTickTime); | 2085 controller_impl->Animate(kInitialTickTime); |
| 2114 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | 2086 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); |
| 2115 controller_impl->UpdateState(true, events.get()); | 2087 controller_impl->UpdateState(true, events.get()); |
| 2116 | 2088 |
| 2117 // Since the animation hasn't been activated, it should still be Starting | 2089 // Since the animation hasn't been activated, it should still be STARTING |
| 2118 // rather than Running. | 2090 // rather than RUNNING. |
| 2119 EXPECT_EQ(Animation::Starting, | 2091 EXPECT_EQ(Animation::STARTING, |
| 2120 controller_impl->GetAnimationById(animation_id)->run_state()); | 2092 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2121 | 2093 |
| 2122 // Since the animation hasn't been activated, only the pending observer | 2094 // Since the animation hasn't been activated, only the pending observer |
| 2123 // should have been ticked. | 2095 // should have been ticked. |
| 2124 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2096 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); |
| 2125 EXPECT_EQ(0.f, dummy_impl.opacity()); | 2097 EXPECT_EQ(0.f, dummy_impl.opacity()); |
| 2126 | 2098 |
| 2127 controller_impl->ActivateAnimations(); | 2099 controller_impl->ActivateAnimations(); |
| 2128 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2100 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2129 ->affects_pending_observers()); | 2101 ->affects_pending_observers()); |
| 2130 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2102 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2131 ->affects_active_observers()); | 2103 ->affects_active_observers()); |
| 2132 | 2104 |
| 2133 controller_impl->Animate(kInitialTickTime + | 2105 controller_impl->Animate(kInitialTickTime + |
| 2134 TimeDelta::FromMilliseconds(1000)); | 2106 TimeDelta::FromMilliseconds(1000)); |
| 2135 controller_impl->UpdateState(true, events.get()); | 2107 controller_impl->UpdateState(true, events.get()); |
| 2136 | 2108 |
| 2137 // Since the animation has been activated, it should have reached the | 2109 // Since the animation has been activated, it should have reached the |
| 2138 // Running state and the active observer should start to get ticked. | 2110 // RUNNING state and the active observer should start to get ticked. |
| 2139 EXPECT_EQ(Animation::Running, | 2111 EXPECT_EQ(Animation::RUNNING, |
| 2140 controller_impl->GetAnimationById(animation_id)->run_state()); | 2112 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2141 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2113 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); |
| 2142 EXPECT_EQ(0.5f, dummy_impl.opacity()); | 2114 EXPECT_EQ(0.5f, dummy_impl.opacity()); |
| 2143 } | 2115 } |
| 2144 | 2116 |
| 2145 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { | 2117 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { |
| 2146 scoped_ptr<AnimationEventsVector> events( | 2118 scoped_ptr<AnimationEventsVector> events( |
| 2147 make_scoped_ptr(new AnimationEventsVector)); | 2119 make_scoped_ptr(new AnimationEventsVector)); |
| 2148 FakeLayerAnimationValueObserver dummy_impl; | 2120 FakeLayerAnimationValueObserver dummy_impl; |
| 2149 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | 2121 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; |
| 2150 scoped_refptr<LayerAnimationController> controller_impl( | 2122 scoped_refptr<LayerAnimationController> controller_impl( |
| 2151 LayerAnimationController::Create(0)); | 2123 LayerAnimationController::Create(0)); |
| 2152 controller_impl->AddValueObserver(&dummy_impl); | 2124 controller_impl->AddValueObserver(&dummy_impl); |
| 2153 controller_impl->AddValueObserver(&pending_dummy_impl); | 2125 controller_impl->AddValueObserver(&pending_dummy_impl); |
| 2154 FakeLayerAnimationValueObserver dummy; | 2126 FakeLayerAnimationValueObserver dummy; |
| 2155 scoped_refptr<LayerAnimationController> controller( | 2127 scoped_refptr<LayerAnimationController> controller( |
| 2156 LayerAnimationController::Create(0)); | 2128 LayerAnimationController::Create(0)); |
| 2157 controller->AddValueObserver(&dummy); | 2129 controller->AddValueObserver(&dummy); |
| 2158 | 2130 |
| 2159 int animation_id = | 2131 int animation_id = |
| 2160 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); | 2132 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); |
| 2161 | 2133 |
| 2162 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2134 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2163 | 2135 |
| 2164 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 2136 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 2165 EXPECT_EQ(Animation::WaitingForTargetAvailability, | 2137 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 2166 controller_impl->GetAnimationById(animation_id)->run_state()); | 2138 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2167 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2139 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2168 ->affects_pending_observers()); | 2140 ->affects_pending_observers()); |
| 2169 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | 2141 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) |
| 2170 ->affects_active_observers()); | 2142 ->affects_active_observers()); |
| 2171 | 2143 |
| 2172 controller_impl->Animate(kInitialTickTime); | 2144 controller_impl->Animate(kInitialTickTime); |
| 2173 | 2145 |
| 2174 // Since the animation hasn't been activated, only the pending observer | 2146 // Since the animation hasn't been activated, only the pending observer |
| 2175 // should have been ticked. | 2147 // should have been ticked. |
| 2176 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2148 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); |
| 2177 EXPECT_EQ(0.f, dummy_impl.opacity()); | 2149 EXPECT_EQ(0.f, dummy_impl.opacity()); |
| 2178 | 2150 |
| 2179 controller_impl->ActivateAnimations(); | 2151 controller_impl->ActivateAnimations(); |
| 2180 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2152 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2181 ->affects_pending_observers()); | 2153 ->affects_pending_observers()); |
| 2182 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2154 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2183 ->affects_active_observers()); | 2155 ->affects_active_observers()); |
| 2184 | 2156 |
| 2185 controller_impl->UpdateState(true, events.get()); | 2157 controller_impl->UpdateState(true, events.get()); |
| 2186 | 2158 |
| 2187 // Since the animation has been activated, it should have reached the | 2159 // Since the animation has been activated, it should have reached the |
| 2188 // Running state. | 2160 // RUNNING state. |
| 2189 EXPECT_EQ(Animation::Running, | 2161 EXPECT_EQ(Animation::RUNNING, |
| 2190 controller_impl->GetAnimationById(animation_id)->run_state()); | 2162 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2191 | 2163 |
| 2192 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2164 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 2193 | 2165 |
| 2194 // Both observers should have been ticked. | 2166 // Both observers should have been ticked. |
| 2195 EXPECT_EQ(0.75f, pending_dummy_impl.opacity()); | 2167 EXPECT_EQ(0.75f, pending_dummy_impl.opacity()); |
| 2196 EXPECT_EQ(0.75f, dummy_impl.opacity()); | 2168 EXPECT_EQ(0.75f, dummy_impl.opacity()); |
| 2197 } | 2169 } |
| 2198 | 2170 |
| 2199 TEST(LayerAnimationControllerTest, ClippedOpacityValues) { | 2171 TEST(LayerAnimationControllerTest, ClippedOpacityValues) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2242 LayerAnimationController::Create(0)); | 2214 LayerAnimationController::Create(0)); |
| 2243 controller->AddValueObserver(&dummy); | 2215 controller->AddValueObserver(&dummy); |
| 2244 | 2216 |
| 2245 int animation_id = | 2217 int animation_id = |
| 2246 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); | 2218 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); |
| 2247 | 2219 |
| 2248 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2220 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2249 controller_impl->ActivateAnimations(); | 2221 controller_impl->ActivateAnimations(); |
| 2250 controller_impl->Animate(kInitialTickTime); | 2222 controller_impl->Animate(kInitialTickTime); |
| 2251 controller_impl->UpdateState(true, events.get()); | 2223 controller_impl->UpdateState(true, events.get()); |
| 2252 EXPECT_EQ(Animation::Running, | 2224 EXPECT_EQ(Animation::RUNNING, |
| 2253 controller_impl->GetAnimationById(animation_id)->run_state()); | 2225 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2254 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2226 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); |
| 2255 EXPECT_EQ(0.5f, dummy_impl.opacity()); | 2227 EXPECT_EQ(0.5f, dummy_impl.opacity()); |
| 2256 | 2228 |
| 2257 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2229 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2258 ->affects_pending_observers()); | 2230 ->affects_pending_observers()); |
| 2259 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2231 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2260 ->affects_active_observers()); | 2232 ->affects_active_observers()); |
| 2261 | 2233 |
| 2262 // Delete the animation on the main-thread controller. | 2234 // Delete the animation on the main-thread controller. |
| 2263 controller->RemoveAnimation( | 2235 controller->RemoveAnimation( |
| 2264 controller->GetAnimation(Animation::Opacity)->id()); | 2236 controller->GetAnimation(Animation::OPACITY)->id()); |
| 2265 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2237 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2266 | 2238 |
| 2267 // The animation should no longer affect pending observers. | 2239 // The animation should no longer affect pending observers. |
| 2268 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | 2240 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) |
| 2269 ->affects_pending_observers()); | 2241 ->affects_pending_observers()); |
| 2270 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2242 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2271 ->affects_active_observers()); | 2243 ->affects_active_observers()); |
| 2272 | 2244 |
| 2273 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2245 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 2274 controller_impl->UpdateState(true, events.get()); | 2246 controller_impl->UpdateState(true, events.get()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2303 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true); | 2275 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true); |
| 2304 | 2276 |
| 2305 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2277 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2306 controller_impl->ActivateAnimations(); | 2278 controller_impl->ActivateAnimations(); |
| 2307 controller_impl->Animate(kInitialTickTime); | 2279 controller_impl->Animate(kInitialTickTime); |
| 2308 controller_impl->UpdateState(true, events.get()); | 2280 controller_impl->UpdateState(true, events.get()); |
| 2309 | 2281 |
| 2310 // Remove the first animation from the main-thread controller, and add a | 2282 // Remove the first animation from the main-thread controller, and add a |
| 2311 // new animation affecting the same property. | 2283 // new animation affecting the same property. |
| 2312 controller->RemoveAnimation( | 2284 controller->RemoveAnimation( |
| 2313 controller->GetAnimation(Animation::Opacity)->id()); | 2285 controller->GetAnimation(Animation::OPACITY)->id()); |
| 2314 int second_animation_id = | 2286 int second_animation_id = |
| 2315 AddOpacityTransitionToController(controller.get(), 1, 1.f, 0.5f, true); | 2287 AddOpacityTransitionToController(controller.get(), 1, 1.f, 0.5f, true); |
| 2316 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2288 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2317 | 2289 |
| 2318 // The original animation should only affect active observers, and the new | 2290 // The original animation should only affect active observers, and the new |
| 2319 // animation should only affect pending observers. | 2291 // animation should only affect pending observers. |
| 2320 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id) | 2292 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id) |
| 2321 ->affects_pending_observers()); | 2293 ->affects_pending_observers()); |
| 2322 EXPECT_TRUE(controller_impl->GetAnimationById(first_animation_id) | 2294 EXPECT_TRUE(controller_impl->GetAnimationById(first_animation_id) |
| 2323 ->affects_active_observers()); | 2295 ->affects_active_observers()); |
| 2324 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) | 2296 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) |
| 2325 ->affects_pending_observers()); | 2297 ->affects_pending_observers()); |
| 2326 EXPECT_FALSE(controller_impl->GetAnimationById(second_animation_id) | 2298 EXPECT_FALSE(controller_impl->GetAnimationById(second_animation_id) |
| 2327 ->affects_active_observers()); | 2299 ->affects_active_observers()); |
| 2328 | 2300 |
| 2329 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2301 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 2330 controller_impl->UpdateState(true, events.get()); | 2302 controller_impl->UpdateState(true, events.get()); |
| 2331 | 2303 |
| 2332 // The original animation should still be running, and the new animation | 2304 // The original animation should still be running, and the new animation |
| 2333 // should be starting. | 2305 // should be starting. |
| 2334 EXPECT_EQ(Animation::Running, | 2306 EXPECT_EQ(Animation::RUNNING, |
| 2335 controller_impl->GetAnimationById(first_animation_id)->run_state()); | 2307 controller_impl->GetAnimationById(first_animation_id)->run_state()); |
| 2336 EXPECT_EQ( | 2308 EXPECT_EQ( |
| 2337 Animation::Starting, | 2309 Animation::STARTING, |
| 2338 controller_impl->GetAnimationById(second_animation_id)->run_state()); | 2310 controller_impl->GetAnimationById(second_animation_id)->run_state()); |
| 2339 | 2311 |
| 2340 // The active observer should have been ticked by the original animation, | 2312 // The active observer should have been ticked by the original animation, |
| 2341 // and the pending observer should have been ticked by the new animation. | 2313 // and the pending observer should have been ticked by the new animation. |
| 2342 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); | 2314 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); |
| 2343 EXPECT_EQ(0.5f, dummy_impl.opacity()); | 2315 EXPECT_EQ(0.5f, dummy_impl.opacity()); |
| 2344 | 2316 |
| 2345 controller_impl->ActivateAnimations(); | 2317 controller_impl->ActivateAnimations(); |
| 2346 | 2318 |
| 2347 // The original animation should have been deleted, and the new animation | 2319 // The original animation should have been deleted, and the new animation |
| 2348 // should now affect both observers. | 2320 // should now affect both observers. |
| 2349 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id)); | 2321 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id)); |
| 2350 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) | 2322 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) |
| 2351 ->affects_pending_observers()); | 2323 ->affects_pending_observers()); |
| 2352 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) | 2324 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) |
| 2353 ->affects_active_observers()); | 2325 ->affects_active_observers()); |
| 2354 | 2326 |
| 2355 controller_impl->Animate(kInitialTickTime + | 2327 controller_impl->Animate(kInitialTickTime + |
| 2356 TimeDelta::FromMilliseconds(1000)); | 2328 TimeDelta::FromMilliseconds(1000)); |
| 2357 controller_impl->UpdateState(true, events.get()); | 2329 controller_impl->UpdateState(true, events.get()); |
| 2358 | 2330 |
| 2359 // The new animation should be running, and the active observer should have | 2331 // The new animation should be running, and the active observer should have |
| 2360 // been ticked at the new animation's starting point. | 2332 // been ticked at the new animation's starting point. |
| 2361 EXPECT_EQ( | 2333 EXPECT_EQ( |
| 2362 Animation::Running, | 2334 Animation::RUNNING, |
| 2363 controller_impl->GetAnimationById(second_animation_id)->run_state()); | 2335 controller_impl->GetAnimationById(second_animation_id)->run_state()); |
| 2364 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); | 2336 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); |
| 2365 EXPECT_EQ(1.f, dummy_impl.opacity()); | 2337 EXPECT_EQ(1.f, dummy_impl.opacity()); |
| 2366 } | 2338 } |
| 2367 | 2339 |
| 2368 TEST(LayerAnimationControllerTest, TestIsAnimatingProperty) { | 2340 TEST(LayerAnimationControllerTest, TestIsAnimatingProperty) { |
| 2369 FakeLayerAnimationValueObserver dummy; | 2341 FakeLayerAnimationValueObserver dummy; |
| 2370 scoped_refptr<LayerAnimationController> controller( | 2342 scoped_refptr<LayerAnimationController> controller( |
| 2371 LayerAnimationController::Create(0)); | 2343 LayerAnimationController::Create(0)); |
| 2372 controller->AddValueObserver(&dummy); | 2344 controller->AddValueObserver(&dummy); |
| 2373 | 2345 |
| 2374 scoped_ptr<Animation> animation(CreateAnimation( | 2346 scoped_ptr<Animation> animation(CreateAnimation( |
| 2375 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 2347 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 2376 1, | 2348 1, Animation::OPACITY)); |
| 2377 Animation::Opacity)); | |
| 2378 controller->AddAnimation(animation.Pass()); | 2349 controller->AddAnimation(animation.Pass()); |
| 2379 controller->Animate(kInitialTickTime); | 2350 controller->Animate(kInitialTickTime); |
| 2380 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::Opacity)); | 2351 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::OPACITY)); |
| 2381 controller->UpdateState(true, nullptr); | 2352 controller->UpdateState(true, nullptr); |
| 2382 EXPECT_TRUE(controller->HasActiveAnimation()); | 2353 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 2383 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::Opacity)); | 2354 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::OPACITY)); |
| 2384 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Filter)); | 2355 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::FILTER)); |
| 2385 EXPECT_EQ(0.f, dummy.opacity()); | 2356 EXPECT_EQ(0.f, dummy.opacity()); |
| 2386 } | 2357 } |
| 2387 | 2358 |
| 2388 TEST(LayerAnimationControllerTest, TestIsAnimatingPropertyTimeOffsetFillMode) { | 2359 TEST(LayerAnimationControllerTest, TestIsAnimatingPropertyTimeOffsetFillMode) { |
| 2389 FakeLayerAnimationValueObserver dummy; | 2360 FakeLayerAnimationValueObserver dummy; |
| 2390 scoped_refptr<LayerAnimationController> controller( | 2361 scoped_refptr<LayerAnimationController> controller( |
| 2391 LayerAnimationController::Create(0)); | 2362 LayerAnimationController::Create(0)); |
| 2392 controller->AddValueObserver(&dummy); | 2363 controller->AddValueObserver(&dummy); |
| 2393 | 2364 |
| 2394 scoped_ptr<Animation> animation(CreateAnimation( | 2365 scoped_ptr<Animation> animation(CreateAnimation( |
| 2395 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | 2366 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
| 2396 1, | 2367 1, Animation::OPACITY)); |
| 2397 Animation::Opacity)); | 2368 animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 2398 animation->set_fill_mode(Animation::FillModeNone); | |
| 2399 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); | 2369 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); |
| 2400 controller->AddAnimation(animation.Pass()); | 2370 controller->AddAnimation(animation.Pass()); |
| 2401 | 2371 |
| 2402 controller->Animate(kInitialTickTime); | 2372 controller->Animate(kInitialTickTime); |
| 2403 controller->UpdateState(true, nullptr); | 2373 controller->UpdateState(true, nullptr); |
| 2404 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Opacity)); | 2374 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::OPACITY)); |
| 2405 EXPECT_TRUE(controller->HasActiveAnimation()); | 2375 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 2406 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Opacity)); | 2376 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::OPACITY)); |
| 2407 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Filter)); | 2377 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::FILTER)); |
| 2408 | 2378 |
| 2409 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 2379 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 2410 controller->UpdateState(true, nullptr); | 2380 controller->UpdateState(true, nullptr); |
| 2411 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::Opacity)); | 2381 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::OPACITY)); |
| 2412 } | 2382 } |
| 2413 | 2383 |
| 2414 } // namespace | 2384 } // namespace |
| 2415 } // namespace cc | 2385 } // namespace cc |
| OLD | NEW |