| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "cc/animation/animation.h" | 9 #include "cc/animation/animation.h" |
| 10 #include "cc/animation/animation_curve.h" | 10 #include "cc/animation/animation_curve.h" |
| 11 #include "cc/animation/animation_delegate.h" | 11 #include "cc/animation/animation_delegate.h" |
| 12 #include "cc/animation/animation_events.h" |
| 12 #include "cc/animation/animation_registrar.h" | 13 #include "cc/animation/animation_registrar.h" |
| 13 #include "cc/animation/keyframed_animation_curve.h" | 14 #include "cc/animation/keyframed_animation_curve.h" |
| 14 #include "cc/animation/scroll_offset_animation_curve.h" | 15 #include "cc/animation/scroll_offset_animation_curve.h" |
| 15 #include "cc/animation/transform_operations.h" | 16 #include "cc/animation/transform_operations.h" |
| 16 #include "cc/test/animation_test_common.h" | 17 #include "cc/test/animation_test_common.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/gfx/geometry/box_f.h" | 20 #include "ui/gfx/geometry/box_f.h" |
| 20 #include "ui/gfx/transform.h" | 21 #include "ui/gfx/transform.h" |
| 21 | 22 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 int animation_id = | 143 int animation_id = |
| 143 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 144 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 144 | 145 |
| 145 controller->PushAnimationUpdatesTo(controller_impl.get()); | 146 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 146 controller_impl->ActivateAnimations(); | 147 controller_impl->ActivateAnimations(); |
| 147 | 148 |
| 148 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 149 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 149 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 150 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 150 controller_impl->GetAnimationById(animation_id)->run_state()); | 151 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 151 | 152 |
| 152 AnimationEventsVector events; | 153 AnimationEvents events; |
| 153 controller_impl->Animate(kInitialTickTime); | 154 controller_impl->Animate(kInitialTickTime); |
| 154 controller_impl->UpdateState(true, &events); | 155 controller_impl->UpdateState(true, &events); |
| 155 | 156 |
| 156 // Synchronize the start times. | 157 // Synchronize the start times. |
| 157 EXPECT_EQ(1u, events.size()); | 158 EXPECT_EQ(1u, events.events_.size()); |
| 158 controller->NotifyAnimationStarted(events[0]); | 159 controller->NotifyAnimationStarted(events.events_[0]); |
| 159 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | 160 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), |
| 160 controller_impl->GetAnimationById(animation_id)->start_time()); | 161 controller_impl->GetAnimationById(animation_id)->start_time()); |
| 161 | 162 |
| 162 // Start the animation on the main thread. Should not affect the start time. | 163 // Start the animation on the main thread. Should not affect the start time. |
| 163 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 164 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 164 controller->UpdateState(true, nullptr); | 165 controller->UpdateState(true, nullptr); |
| 165 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | 166 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), |
| 166 controller_impl->GetAnimationById(animation_id)->start_time()); | 167 controller_impl->GetAnimationById(animation_id)->start_time()); |
| 167 } | 168 } |
| 168 | 169 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 182 const TimeTicks start_time = TicksFromSecondsF(123); | 183 const TimeTicks start_time = TicksFromSecondsF(123); |
| 183 controller->GetAnimation(Animation::OPACITY)->set_start_time(start_time); | 184 controller->GetAnimation(Animation::OPACITY)->set_start_time(start_time); |
| 184 | 185 |
| 185 controller->PushAnimationUpdatesTo(controller_impl.get()); | 186 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 186 controller_impl->ActivateAnimations(); | 187 controller_impl->ActivateAnimations(); |
| 187 | 188 |
| 188 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 189 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 189 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 190 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 190 controller_impl->GetAnimationById(animation_id)->run_state()); | 191 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 191 | 192 |
| 192 AnimationEventsVector events; | 193 AnimationEvents events; |
| 193 controller_impl->Animate(kInitialTickTime); | 194 controller_impl->Animate(kInitialTickTime); |
| 194 controller_impl->UpdateState(true, &events); | 195 controller_impl->UpdateState(true, &events); |
| 195 | 196 |
| 196 // Synchronize the start times. | 197 // Synchronize the start times. |
| 197 EXPECT_EQ(1u, events.size()); | 198 EXPECT_EQ(1u, events.events_.size()); |
| 198 controller->NotifyAnimationStarted(events[0]); | 199 controller->NotifyAnimationStarted(events.events_[0]); |
| 199 | 200 |
| 200 EXPECT_EQ(start_time, | 201 EXPECT_EQ(start_time, |
| 201 controller->GetAnimationById(animation_id)->start_time()); | 202 controller->GetAnimationById(animation_id)->start_time()); |
| 202 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | 203 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), |
| 203 controller_impl->GetAnimationById(animation_id)->start_time()); | 204 controller_impl->GetAnimationById(animation_id)->start_time()); |
| 204 | 205 |
| 205 // Start the animation on the main thread. Should not affect the start time. | 206 // Start the animation on the main thread. Should not affect the start time. |
| 206 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 207 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 207 controller->UpdateState(true, nullptr); | 208 controller->UpdateState(true, nullptr); |
| 208 EXPECT_EQ(start_time, | 209 EXPECT_EQ(start_time, |
| 209 controller->GetAnimationById(animation_id)->start_time()); | 210 controller->GetAnimationById(animation_id)->start_time()); |
| 210 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | 211 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), |
| 211 controller_impl->GetAnimationById(animation_id)->start_time()); | 212 controller_impl->GetAnimationById(animation_id)->start_time()); |
| 212 } | 213 } |
| 213 | 214 |
| 214 // Tests that controllers activate and deactivate as expected. | 215 // Tests that controllers activate and deactivate as expected. |
| 215 TEST(LayerAnimationControllerTest, Activation) { | 216 TEST(LayerAnimationControllerTest, Activation) { |
| 216 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); | 217 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); |
| 217 scoped_ptr<AnimationRegistrar> registrar_impl = AnimationRegistrar::Create(); | 218 scoped_ptr<AnimationRegistrar> registrar_impl = AnimationRegistrar::Create(); |
| 218 | 219 |
| 219 FakeLayerAnimationValueObserver dummy_impl; | 220 FakeLayerAnimationValueObserver dummy_impl; |
| 220 scoped_refptr<LayerAnimationController> controller_impl( | 221 scoped_refptr<LayerAnimationController> controller_impl( |
| 221 LayerAnimationController::Create(0)); | 222 LayerAnimationController::Create(0)); |
| 222 controller_impl->AddValueObserver(&dummy_impl); | 223 controller_impl->AddValueObserver(&dummy_impl); |
| 223 FakeLayerAnimationValueObserver dummy; | 224 FakeLayerAnimationValueObserver dummy; |
| 224 scoped_refptr<LayerAnimationController> controller( | 225 scoped_refptr<LayerAnimationController> controller( |
| 225 LayerAnimationController::Create(0)); | 226 LayerAnimationController::Create(0)); |
| 226 controller->AddValueObserver(&dummy); | 227 controller->AddValueObserver(&dummy); |
| 227 scoped_ptr<AnimationEventsVector> events( | 228 scoped_ptr<AnimationEvents> events = registrar->CreateEvents(); |
| 228 make_scoped_ptr(new AnimationEventsVector)); | |
| 229 | 229 |
| 230 controller->SetAnimationRegistrar(registrar.get()); | 230 controller->SetAnimationRegistrar(registrar.get()); |
| 231 controller_impl->SetAnimationRegistrar(registrar_impl.get()); | 231 controller_impl->SetAnimationRegistrar(registrar_impl.get()); |
| 232 EXPECT_EQ(1u, registrar->all_animation_controllers_for_testing().size()); | 232 EXPECT_EQ(1u, registrar->all_animation_controllers_for_testing().size()); |
| 233 EXPECT_EQ(1u, registrar_impl->all_animation_controllers_for_testing().size()); | 233 EXPECT_EQ(1u, registrar_impl->all_animation_controllers_for_testing().size()); |
| 234 | 234 |
| 235 // Initially, both controllers should be inactive. | 235 // Initially, both controllers should be inactive. |
| 236 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size()); | 236 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size()); |
| 237 EXPECT_EQ(0u, | 237 EXPECT_EQ(0u, |
| 238 registrar_impl->active_animation_controllers_for_testing().size()); | 238 registrar_impl->active_animation_controllers_for_testing().size()); |
| 239 | 239 |
| 240 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 240 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 241 // The main thread controller should now be active. | 241 // The main thread controller should now be active. |
| 242 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); | 242 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); |
| 243 | 243 |
| 244 controller->PushAnimationUpdatesTo(controller_impl.get()); | 244 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 245 controller_impl->ActivateAnimations(); | 245 controller_impl->ActivateAnimations(); |
| 246 // Both controllers should now be active. | 246 // Both controllers should now be active. |
| 247 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); | 247 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); |
| 248 EXPECT_EQ(1u, | 248 EXPECT_EQ(1u, |
| 249 registrar_impl->active_animation_controllers_for_testing().size()); | 249 registrar_impl->active_animation_controllers_for_testing().size()); |
| 250 | 250 |
| 251 controller_impl->Animate(kInitialTickTime); | 251 controller_impl->Animate(kInitialTickTime); |
| 252 controller_impl->UpdateState(true, events.get()); | 252 controller_impl->UpdateState(true, events.get()); |
| 253 EXPECT_EQ(1u, events->size()); | 253 EXPECT_EQ(1u, events->events_.size()); |
| 254 controller->NotifyAnimationStarted((*events)[0]); | 254 controller->NotifyAnimationStarted(events->events_[0]); |
| 255 | 255 |
| 256 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); | 256 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); |
| 257 EXPECT_EQ(1u, | 257 EXPECT_EQ(1u, |
| 258 registrar_impl->active_animation_controllers_for_testing().size()); | 258 registrar_impl->active_animation_controllers_for_testing().size()); |
| 259 | 259 |
| 260 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 260 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 261 controller->UpdateState(true, nullptr); | 261 controller->UpdateState(true, nullptr); |
| 262 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); | 262 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); |
| 263 | 263 |
| 264 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 264 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 265 controller->UpdateState(true, nullptr); | 265 controller->UpdateState(true, nullptr); |
| 266 EXPECT_EQ(Animation::FINISHED, | 266 EXPECT_EQ(Animation::FINISHED, |
| 267 controller->GetAnimation(Animation::OPACITY)->run_state()); | 267 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 268 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); | 268 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); |
| 269 | 269 |
| 270 events.reset(new AnimationEventsVector); | 270 events.reset(new AnimationEvents); |
| 271 controller_impl->Animate(kInitialTickTime + | 271 controller_impl->Animate(kInitialTickTime + |
| 272 TimeDelta::FromMilliseconds(1500)); | 272 TimeDelta::FromMilliseconds(1500)); |
| 273 controller_impl->UpdateState(true, events.get()); | 273 controller_impl->UpdateState(true, events.get()); |
| 274 | 274 |
| 275 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | 275 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 276 controller_impl->GetAnimation(Animation::OPACITY)->run_state()); | 276 controller_impl->GetAnimation(Animation::OPACITY)->run_state()); |
| 277 // The impl thread controller should have de-activated. | 277 // The impl thread controller should have de-activated. |
| 278 EXPECT_EQ(0u, | 278 EXPECT_EQ(0u, |
| 279 registrar_impl->active_animation_controllers_for_testing().size()); | 279 registrar_impl->active_animation_controllers_for_testing().size()); |
| 280 | 280 |
| 281 EXPECT_EQ(1u, events->size()); | 281 EXPECT_EQ(1u, events->events_.size()); |
| 282 controller->NotifyAnimationFinished((*events)[0]); | 282 controller->NotifyAnimationFinished(events->events_[0]); |
| 283 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | 283 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); |
| 284 controller->UpdateState(true, nullptr); | 284 controller->UpdateState(true, nullptr); |
| 285 | 285 |
| 286 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | 286 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 287 controller->GetAnimation(Animation::OPACITY)->run_state()); | 287 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 288 // The main thread controller should have de-activated. | 288 // The main thread controller should have de-activated. |
| 289 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size()); | 289 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size()); |
| 290 | 290 |
| 291 controller->PushAnimationUpdatesTo(controller_impl.get()); | 291 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 292 controller_impl->ActivateAnimations(); | 292 controller_impl->ActivateAnimations(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 controller->PushAnimationUpdatesTo(controller_impl.get()); | 324 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 325 controller_impl->ActivateAnimations(); | 325 controller_impl->ActivateAnimations(); |
| 326 | 326 |
| 327 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 327 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 328 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 328 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 329 controller_impl->GetAnimationById(animation_id)->run_state()); | 329 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 330 | 330 |
| 331 TimeTicks time = kInitialTickTime; | 331 TimeTicks time = kInitialTickTime; |
| 332 | 332 |
| 333 // Start the animations on each controller. | 333 // Start the animations on each controller. |
| 334 AnimationEventsVector events; | 334 AnimationEvents events; |
| 335 controller_impl->Animate(time); | 335 controller_impl->Animate(time); |
| 336 controller_impl->UpdateState(true, &events); | 336 controller_impl->UpdateState(true, &events); |
| 337 EXPECT_EQ(1u, events.size()); | 337 EXPECT_EQ(1u, events.events_.size()); |
| 338 | 338 |
| 339 controller->Animate(time); | 339 controller->Animate(time); |
| 340 controller->UpdateState(true, nullptr); | 340 controller->UpdateState(true, nullptr); |
| 341 controller->NotifyAnimationStarted(events[0]); | 341 controller->NotifyAnimationStarted(events.events_[0]); |
| 342 | 342 |
| 343 EXPECT_EQ(Animation::RUNNING, | 343 EXPECT_EQ(Animation::RUNNING, |
| 344 controller_impl->GetAnimationById(animation_id)->run_state()); | 344 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 345 EXPECT_EQ(Animation::RUNNING, | 345 EXPECT_EQ(Animation::RUNNING, |
| 346 controller->GetAnimationById(animation_id)->run_state()); | 346 controller->GetAnimationById(animation_id)->run_state()); |
| 347 | 347 |
| 348 EXPECT_EQ(0.3f, dummy.opacity()); | 348 EXPECT_EQ(0.3f, dummy.opacity()); |
| 349 EXPECT_EQ(0.3f, dummy_impl.opacity()); | 349 EXPECT_EQ(0.3f, dummy_impl.opacity()); |
| 350 | 350 |
| 351 EXPECT_EQ(kInitialTickTime, | 351 EXPECT_EQ(kInitialTickTime, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 378 | 378 |
| 379 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { | 379 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { |
| 380 FakeLayerAnimationValueObserver dummy_impl; | 380 FakeLayerAnimationValueObserver dummy_impl; |
| 381 scoped_refptr<LayerAnimationController> controller_impl( | 381 scoped_refptr<LayerAnimationController> controller_impl( |
| 382 LayerAnimationController::Create(0)); | 382 LayerAnimationController::Create(0)); |
| 383 controller_impl->AddValueObserver(&dummy_impl); | 383 controller_impl->AddValueObserver(&dummy_impl); |
| 384 FakeLayerAnimationValueObserver dummy; | 384 FakeLayerAnimationValueObserver dummy; |
| 385 scoped_refptr<LayerAnimationController> controller( | 385 scoped_refptr<LayerAnimationController> controller( |
| 386 LayerAnimationController::Create(0)); | 386 LayerAnimationController::Create(0)); |
| 387 controller->AddValueObserver(&dummy); | 387 controller->AddValueObserver(&dummy); |
| 388 scoped_ptr<AnimationEventsVector> events( | 388 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 389 make_scoped_ptr(new AnimationEventsVector)); | |
| 390 | 389 |
| 391 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY)); | 390 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY)); |
| 392 | 391 |
| 393 int animation_id = | 392 int animation_id = |
| 394 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 393 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 395 | 394 |
| 396 controller->PushAnimationUpdatesTo(controller_impl.get()); | 395 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 397 controller_impl->ActivateAnimations(); | 396 controller_impl->ActivateAnimations(); |
| 398 | 397 |
| 399 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 398 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 400 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 399 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 401 controller_impl->GetAnimationById(animation_id)->run_state()); | 400 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 402 | 401 |
| 403 events.reset(new AnimationEventsVector); | 402 events.reset(new AnimationEvents); |
| 404 controller_impl->Animate(kInitialTickTime); | 403 controller_impl->Animate(kInitialTickTime); |
| 405 controller_impl->UpdateState(true, events.get()); | 404 controller_impl->UpdateState(true, events.get()); |
| 406 EXPECT_EQ(1u, events->size()); | 405 EXPECT_EQ(1u, events->events_.size()); |
| 407 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type); | 406 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); |
| 408 | 407 |
| 409 // Notify main thread controller that the animation has started. | 408 // Notify main thread controller that the animation has started. |
| 410 controller->NotifyAnimationStarted((*events)[0]); | 409 controller->NotifyAnimationStarted(events->events_[0]); |
| 411 | 410 |
| 412 // Complete animation on impl thread. | 411 // Complete animation on impl thread. |
| 413 events.reset(new AnimationEventsVector); | 412 events.reset(new AnimationEvents); |
| 414 controller_impl->Animate(kInitialTickTime + TimeDelta::FromSeconds(1)); | 413 controller_impl->Animate(kInitialTickTime + TimeDelta::FromSeconds(1)); |
| 415 controller_impl->UpdateState(true, events.get()); | 414 controller_impl->UpdateState(true, events.get()); |
| 416 EXPECT_EQ(1u, events->size()); | 415 EXPECT_EQ(1u, events->events_.size()); |
| 417 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type); | 416 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); |
| 418 | 417 |
| 419 controller->NotifyAnimationFinished((*events)[0]); | 418 controller->NotifyAnimationFinished(events->events_[0]); |
| 420 | 419 |
| 421 controller->Animate(kInitialTickTime + TimeDelta::FromSeconds(2)); | 420 controller->Animate(kInitialTickTime + TimeDelta::FromSeconds(2)); |
| 422 controller->UpdateState(true, nullptr); | 421 controller->UpdateState(true, nullptr); |
| 423 | 422 |
| 424 controller->PushAnimationUpdatesTo(controller_impl.get()); | 423 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 425 controller_impl->ActivateAnimations(); | 424 controller_impl->ActivateAnimations(); |
| 426 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | 425 EXPECT_FALSE(controller->GetAnimationById(animation_id)); |
| 427 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | 426 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); |
| 428 } | 427 } |
| 429 | 428 |
| 430 // Ensure that a finished animation is eventually deleted by both the | 429 // Ensure that a finished animation is eventually deleted by both the |
| 431 // main-thread and the impl-thread controllers. | 430 // main-thread and the impl-thread controllers. |
| 432 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) { | 431 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) { |
| 433 FakeLayerAnimationValueObserver dummy; | 432 FakeLayerAnimationValueObserver dummy; |
| 434 FakeLayerAnimationValueObserver dummy_impl; | 433 FakeLayerAnimationValueObserver dummy_impl; |
| 435 scoped_ptr<AnimationEventsVector> events( | 434 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 436 make_scoped_ptr(new AnimationEventsVector)); | |
| 437 scoped_refptr<LayerAnimationController> controller( | 435 scoped_refptr<LayerAnimationController> controller( |
| 438 LayerAnimationController::Create(0)); | 436 LayerAnimationController::Create(0)); |
| 439 scoped_refptr<LayerAnimationController> controller_impl( | 437 scoped_refptr<LayerAnimationController> controller_impl( |
| 440 LayerAnimationController::Create(0)); | 438 LayerAnimationController::Create(0)); |
| 441 controller->AddValueObserver(&dummy); | 439 controller->AddValueObserver(&dummy); |
| 442 controller_impl->AddValueObserver(&dummy_impl); | 440 controller_impl->AddValueObserver(&dummy_impl); |
| 443 | 441 |
| 444 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); | 442 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); |
| 445 controller->Animate(kInitialTickTime); | 443 controller->Animate(kInitialTickTime); |
| 446 controller->UpdateState(true, nullptr); | 444 controller->UpdateState(true, nullptr); |
| 447 controller->PushAnimationUpdatesTo(controller_impl.get()); | 445 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 448 controller_impl->ActivateAnimations(); | 446 controller_impl->ActivateAnimations(); |
| 449 | 447 |
| 450 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 448 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 451 controller_impl->UpdateState(true, events.get()); | 449 controller_impl->UpdateState(true, events.get()); |
| 452 | 450 |
| 453 // There should be a STARTED event for the animation. | 451 // There should be a STARTED event for the animation. |
| 454 EXPECT_EQ(1u, events->size()); | 452 EXPECT_EQ(1u, events->events_.size()); |
| 455 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type); | 453 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); |
| 456 controller->NotifyAnimationStarted((*events)[0]); | 454 controller->NotifyAnimationStarted(events->events_[0]); |
| 457 | 455 |
| 458 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 456 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 459 controller->UpdateState(true, nullptr); | 457 controller->UpdateState(true, nullptr); |
| 460 | 458 |
| 461 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | 459 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); |
| 462 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | 460 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); |
| 463 | 461 |
| 464 events.reset(new AnimationEventsVector); | 462 events.reset(new AnimationEvents); |
| 465 controller_impl->Animate(kInitialTickTime + | 463 controller_impl->Animate(kInitialTickTime + |
| 466 TimeDelta::FromMilliseconds(2000)); | 464 TimeDelta::FromMilliseconds(2000)); |
| 467 controller_impl->UpdateState(true, events.get()); | 465 controller_impl->UpdateState(true, events.get()); |
| 468 | 466 |
| 469 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | 467 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); |
| 470 | 468 |
| 471 // There should be a FINISHED event for the animation. | 469 // There should be a FINISHED event for the animation. |
| 472 EXPECT_EQ(1u, events->size()); | 470 EXPECT_EQ(1u, events->events_.size()); |
| 473 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type); | 471 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); |
| 474 | 472 |
| 475 // Neither controller should have deleted the animation yet. | 473 // Neither controller should have deleted the animation yet. |
| 476 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY)); | 474 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY)); |
| 477 EXPECT_TRUE(controller_impl->GetAnimation(Animation::OPACITY)); | 475 EXPECT_TRUE(controller_impl->GetAnimation(Animation::OPACITY)); |
| 478 | 476 |
| 479 controller->NotifyAnimationFinished((*events)[0]); | 477 controller->NotifyAnimationFinished(events->events_[0]); |
| 480 | 478 |
| 481 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 479 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 482 controller->UpdateState(true, nullptr); | 480 controller->UpdateState(true, nullptr); |
| 483 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 481 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
| 484 | 482 |
| 485 controller->PushAnimationUpdatesTo(controller_impl.get()); | 483 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 486 | 484 |
| 487 // Both controllers should now have deleted the animation. The impl controller | 485 // Both controllers should now have deleted the animation. The impl controller |
| 488 // should have deleted the animation even though activation has not occurred, | 486 // should have deleted the animation even though activation has not occurred, |
| 489 // since the animation was already waiting for deletion when | 487 // since the animation was already waiting for deletion when |
| 490 // PushAnimationUpdatesTo was called. | 488 // PushAnimationUpdatesTo was called. |
| 491 EXPECT_FALSE(controller->has_any_animation()); | 489 EXPECT_FALSE(controller->has_any_animation()); |
| 492 EXPECT_FALSE(controller_impl->has_any_animation()); | 490 EXPECT_FALSE(controller_impl->has_any_animation()); |
| 493 } | 491 } |
| 494 | 492 |
| 495 // Tests that transitioning opacity from 0 to 1 works as expected. | 493 // Tests that transitioning opacity from 0 to 1 works as expected. |
| 496 | 494 |
| 497 static const AnimationEvent* GetMostRecentPropertyUpdateEvent( | 495 static const AnimationEvent* GetMostRecentPropertyUpdateEvent( |
| 498 const AnimationEventsVector* events) { | 496 const AnimationEvents* events) { |
| 499 const AnimationEvent* event = 0; | 497 const AnimationEvent* event = 0; |
| 500 for (size_t i = 0; i < events->size(); ++i) | 498 for (size_t i = 0; i < events->events_.size(); ++i) |
| 501 if ((*events)[i].type == AnimationEvent::PROPERTY_UPDATE) | 499 if (events->events_[i].type == AnimationEvent::PROPERTY_UPDATE) |
| 502 event = &(*events)[i]; | 500 event = &events->events_[i]; |
| 503 | 501 |
| 504 return event; | 502 return event; |
| 505 } | 503 } |
| 506 | 504 |
| 507 TEST(LayerAnimationControllerTest, TrivialTransition) { | 505 TEST(LayerAnimationControllerTest, TrivialTransition) { |
| 508 scoped_ptr<AnimationEventsVector> events( | 506 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 509 make_scoped_ptr(new AnimationEventsVector)); | |
| 510 FakeLayerAnimationValueObserver dummy; | 507 FakeLayerAnimationValueObserver dummy; |
| 511 scoped_refptr<LayerAnimationController> controller( | 508 scoped_refptr<LayerAnimationController> controller( |
| 512 LayerAnimationController::Create(0)); | 509 LayerAnimationController::Create(0)); |
| 513 controller->AddValueObserver(&dummy); | 510 controller->AddValueObserver(&dummy); |
| 514 | 511 |
| 515 scoped_ptr<Animation> to_add(CreateAnimation( | 512 scoped_ptr<Animation> to_add(CreateAnimation( |
| 516 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 513 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| 517 Animation::OPACITY)); | 514 Animation::OPACITY)); |
| 518 | 515 |
| 519 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 516 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 520 controller->AddAnimation(std::move(to_add)); | 517 controller->AddAnimation(std::move(to_add)); |
| 521 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 518 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 522 controller->Animate(kInitialTickTime); | 519 controller->Animate(kInitialTickTime); |
| 523 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 520 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 524 controller->UpdateState(true, events.get()); | 521 controller->UpdateState(true, events.get()); |
| 525 EXPECT_TRUE(controller->HasActiveAnimation()); | 522 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 526 EXPECT_EQ(0.f, dummy.opacity()); | 523 EXPECT_EQ(0.f, dummy.opacity()); |
| 527 // A non-impl-only animation should not generate property updates. | 524 // A non-impl-only animation should not generate property updates. |
| 528 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 525 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 529 EXPECT_FALSE(event); | 526 EXPECT_FALSE(event); |
| 530 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 527 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 531 controller->UpdateState(true, events.get()); | 528 controller->UpdateState(true, events.get()); |
| 532 EXPECT_EQ(1.f, dummy.opacity()); | 529 EXPECT_EQ(1.f, dummy.opacity()); |
| 533 EXPECT_FALSE(controller->HasActiveAnimation()); | 530 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 534 event = GetMostRecentPropertyUpdateEvent(events.get()); | 531 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 535 EXPECT_FALSE(event); | 532 EXPECT_FALSE(event); |
| 536 } | 533 } |
| 537 | 534 |
| 538 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { | 535 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { |
| 539 scoped_ptr<AnimationEventsVector> events( | 536 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 540 make_scoped_ptr(new AnimationEventsVector)); | |
| 541 FakeLayerAnimationValueObserver dummy_impl; | 537 FakeLayerAnimationValueObserver dummy_impl; |
| 542 scoped_refptr<LayerAnimationController> controller_impl( | 538 scoped_refptr<LayerAnimationController> controller_impl( |
| 543 LayerAnimationController::Create(0)); | 539 LayerAnimationController::Create(0)); |
| 544 controller_impl->AddValueObserver(&dummy_impl); | 540 controller_impl->AddValueObserver(&dummy_impl); |
| 545 | 541 |
| 546 scoped_ptr<Animation> to_add(CreateAnimation( | 542 scoped_ptr<Animation> to_add(CreateAnimation( |
| 547 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 543 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| 548 Animation::OPACITY)); | 544 Animation::OPACITY)); |
| 549 to_add->set_is_impl_only(true); | 545 to_add->set_is_impl_only(true); |
| 550 | 546 |
| 551 controller_impl->AddAnimation(std::move(to_add)); | 547 controller_impl->AddAnimation(std::move(to_add)); |
| 552 controller_impl->Animate(kInitialTickTime); | 548 controller_impl->Animate(kInitialTickTime); |
| 553 controller_impl->UpdateState(true, events.get()); | 549 controller_impl->UpdateState(true, events.get()); |
| 554 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 550 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 555 EXPECT_EQ(0.f, dummy_impl.opacity()); | 551 EXPECT_EQ(0.f, dummy_impl.opacity()); |
| 556 EXPECT_EQ(1u, events->size()); | 552 EXPECT_EQ(1u, events->events_.size()); |
| 557 const AnimationEvent* start_opacity_event = | 553 const AnimationEvent* start_opacity_event = |
| 558 GetMostRecentPropertyUpdateEvent(events.get()); | 554 GetMostRecentPropertyUpdateEvent(events.get()); |
| 559 EXPECT_EQ(0.f, start_opacity_event->opacity); | 555 EXPECT_EQ(0.f, start_opacity_event->opacity); |
| 560 | 556 |
| 561 controller_impl->Animate(kInitialTickTime + | 557 controller_impl->Animate(kInitialTickTime + |
| 562 TimeDelta::FromMilliseconds(1000)); | 558 TimeDelta::FromMilliseconds(1000)); |
| 563 controller_impl->UpdateState(true, events.get()); | 559 controller_impl->UpdateState(true, events.get()); |
| 564 EXPECT_EQ(1.f, dummy_impl.opacity()); | 560 EXPECT_EQ(1.f, dummy_impl.opacity()); |
| 565 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 561 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
| 566 EXPECT_EQ(2u, events->size()); | 562 EXPECT_EQ(2u, events->events_.size()); |
| 567 const AnimationEvent* end_opacity_event = | 563 const AnimationEvent* end_opacity_event = |
| 568 GetMostRecentPropertyUpdateEvent(events.get()); | 564 GetMostRecentPropertyUpdateEvent(events.get()); |
| 569 EXPECT_EQ(1.f, end_opacity_event->opacity); | 565 EXPECT_EQ(1.f, end_opacity_event->opacity); |
| 570 } | 566 } |
| 571 | 567 |
| 572 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { | 568 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { |
| 573 scoped_ptr<AnimationEventsVector> events( | 569 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 574 make_scoped_ptr(new AnimationEventsVector)); | |
| 575 FakeLayerAnimationValueObserver dummy_impl; | 570 FakeLayerAnimationValueObserver dummy_impl; |
| 576 scoped_refptr<LayerAnimationController> controller_impl( | 571 scoped_refptr<LayerAnimationController> controller_impl( |
| 577 LayerAnimationController::Create(0)); | 572 LayerAnimationController::Create(0)); |
| 578 controller_impl->AddValueObserver(&dummy_impl); | 573 controller_impl->AddValueObserver(&dummy_impl); |
| 579 | 574 |
| 580 // Choose different values for x and y to avoid coincidental values in the | 575 // Choose different values for x and y to avoid coincidental values in the |
| 581 // observed transforms. | 576 // observed transforms. |
| 582 const float delta_x = 3; | 577 const float delta_x = 3; |
| 583 const float delta_y = 4; | 578 const float delta_y = 4; |
| 584 | 579 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 596 scoped_ptr<Animation> animation( | 591 scoped_ptr<Animation> animation( |
| 597 Animation::Create(std::move(curve), 1, 0, Animation::TRANSFORM)); | 592 Animation::Create(std::move(curve), 1, 0, Animation::TRANSFORM)); |
| 598 animation->set_is_impl_only(true); | 593 animation->set_is_impl_only(true); |
| 599 controller_impl->AddAnimation(std::move(animation)); | 594 controller_impl->AddAnimation(std::move(animation)); |
| 600 | 595 |
| 601 // Run animation. | 596 // Run animation. |
| 602 controller_impl->Animate(kInitialTickTime); | 597 controller_impl->Animate(kInitialTickTime); |
| 603 controller_impl->UpdateState(true, events.get()); | 598 controller_impl->UpdateState(true, events.get()); |
| 604 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 599 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 605 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); | 600 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); |
| 606 EXPECT_EQ(1u, events->size()); | 601 EXPECT_EQ(1u, events->events_.size()); |
| 607 const AnimationEvent* start_transform_event = | 602 const AnimationEvent* start_transform_event = |
| 608 GetMostRecentPropertyUpdateEvent(events.get()); | 603 GetMostRecentPropertyUpdateEvent(events.get()); |
| 609 ASSERT_TRUE(start_transform_event); | 604 ASSERT_TRUE(start_transform_event); |
| 610 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); | 605 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); |
| 611 EXPECT_TRUE(start_transform_event->is_impl_only); | 606 EXPECT_TRUE(start_transform_event->is_impl_only); |
| 612 | 607 |
| 613 gfx::Transform expected_transform; | 608 gfx::Transform expected_transform; |
| 614 expected_transform.Translate(delta_x, delta_y); | 609 expected_transform.Translate(delta_x, delta_y); |
| 615 | 610 |
| 616 controller_impl->Animate(kInitialTickTime + | 611 controller_impl->Animate(kInitialTickTime + |
| 617 TimeDelta::FromMilliseconds(1000)); | 612 TimeDelta::FromMilliseconds(1000)); |
| 618 controller_impl->UpdateState(true, events.get()); | 613 controller_impl->UpdateState(true, events.get()); |
| 619 EXPECT_EQ(expected_transform, dummy_impl.transform()); | 614 EXPECT_EQ(expected_transform, dummy_impl.transform()); |
| 620 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 615 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
| 621 EXPECT_EQ(2u, events->size()); | 616 EXPECT_EQ(2u, events->events_.size()); |
| 622 const AnimationEvent* end_transform_event = | 617 const AnimationEvent* end_transform_event = |
| 623 GetMostRecentPropertyUpdateEvent(events.get()); | 618 GetMostRecentPropertyUpdateEvent(events.get()); |
| 624 EXPECT_EQ(expected_transform, end_transform_event->transform); | 619 EXPECT_EQ(expected_transform, end_transform_event->transform); |
| 625 EXPECT_TRUE(end_transform_event->is_impl_only); | 620 EXPECT_TRUE(end_transform_event->is_impl_only); |
| 626 } | 621 } |
| 627 | 622 |
| 628 TEST(LayerAnimationControllerTest, FilterTransition) { | 623 TEST(LayerAnimationControllerTest, FilterTransition) { |
| 629 scoped_ptr<AnimationEventsVector> events( | 624 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 630 make_scoped_ptr(new AnimationEventsVector)); | |
| 631 FakeLayerAnimationValueObserver dummy; | 625 FakeLayerAnimationValueObserver dummy; |
| 632 scoped_refptr<LayerAnimationController> controller( | 626 scoped_refptr<LayerAnimationController> controller( |
| 633 LayerAnimationController::Create(0)); | 627 LayerAnimationController::Create(0)); |
| 634 controller->AddValueObserver(&dummy); | 628 controller->AddValueObserver(&dummy); |
| 635 | 629 |
| 636 scoped_ptr<KeyframedFilterAnimationCurve> curve( | 630 scoped_ptr<KeyframedFilterAnimationCurve> curve( |
| 637 KeyframedFilterAnimationCurve::Create()); | 631 KeyframedFilterAnimationCurve::Create()); |
| 638 | 632 |
| 639 FilterOperations start_filters; | 633 FilterOperations start_filters; |
| 640 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); | 634 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 667 | 661 |
| 668 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 662 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 669 controller->UpdateState(true, events.get()); | 663 controller->UpdateState(true, events.get()); |
| 670 EXPECT_EQ(end_filters, dummy.filters()); | 664 EXPECT_EQ(end_filters, dummy.filters()); |
| 671 EXPECT_FALSE(controller->HasActiveAnimation()); | 665 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 672 event = GetMostRecentPropertyUpdateEvent(events.get()); | 666 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 673 EXPECT_FALSE(event); | 667 EXPECT_FALSE(event); |
| 674 } | 668 } |
| 675 | 669 |
| 676 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) { | 670 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) { |
| 677 scoped_ptr<AnimationEventsVector> events( | 671 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 678 make_scoped_ptr(new AnimationEventsVector)); | |
| 679 FakeLayerAnimationValueObserver dummy_impl; | 672 FakeLayerAnimationValueObserver dummy_impl; |
| 680 scoped_refptr<LayerAnimationController> controller_impl( | 673 scoped_refptr<LayerAnimationController> controller_impl( |
| 681 LayerAnimationController::Create(0)); | 674 LayerAnimationController::Create(0)); |
| 682 controller_impl->AddValueObserver(&dummy_impl); | 675 controller_impl->AddValueObserver(&dummy_impl); |
| 683 | 676 |
| 684 scoped_ptr<KeyframedFilterAnimationCurve> curve( | 677 scoped_ptr<KeyframedFilterAnimationCurve> curve( |
| 685 KeyframedFilterAnimationCurve::Create()); | 678 KeyframedFilterAnimationCurve::Create()); |
| 686 | 679 |
| 687 // Create simple FILTER animation. | 680 // Create simple FILTER animation. |
| 688 FilterOperations start_filters; | 681 FilterOperations start_filters; |
| 689 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); | 682 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); |
| 690 curve->AddKeyframe( | 683 curve->AddKeyframe( |
| 691 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); | 684 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 692 FilterOperations end_filters; | 685 FilterOperations end_filters; |
| 693 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 686 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
| 694 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 687 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
| 695 end_filters, nullptr)); | 688 end_filters, nullptr)); |
| 696 | 689 |
| 697 scoped_ptr<Animation> animation( | 690 scoped_ptr<Animation> animation( |
| 698 Animation::Create(std::move(curve), 1, 0, Animation::FILTER)); | 691 Animation::Create(std::move(curve), 1, 0, Animation::FILTER)); |
| 699 animation->set_is_impl_only(true); | 692 animation->set_is_impl_only(true); |
| 700 controller_impl->AddAnimation(std::move(animation)); | 693 controller_impl->AddAnimation(std::move(animation)); |
| 701 | 694 |
| 702 // Run animation. | 695 // Run animation. |
| 703 controller_impl->Animate(kInitialTickTime); | 696 controller_impl->Animate(kInitialTickTime); |
| 704 controller_impl->UpdateState(true, events.get()); | 697 controller_impl->UpdateState(true, events.get()); |
| 705 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 698 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 706 EXPECT_EQ(start_filters, dummy_impl.filters()); | 699 EXPECT_EQ(start_filters, dummy_impl.filters()); |
| 707 EXPECT_EQ(1u, events->size()); | 700 EXPECT_EQ(1u, events->events_.size()); |
| 708 const AnimationEvent* start_filter_event = | 701 const AnimationEvent* start_filter_event = |
| 709 GetMostRecentPropertyUpdateEvent(events.get()); | 702 GetMostRecentPropertyUpdateEvent(events.get()); |
| 710 EXPECT_TRUE(start_filter_event); | 703 EXPECT_TRUE(start_filter_event); |
| 711 EXPECT_EQ(start_filters, start_filter_event->filters); | 704 EXPECT_EQ(start_filters, start_filter_event->filters); |
| 712 EXPECT_TRUE(start_filter_event->is_impl_only); | 705 EXPECT_TRUE(start_filter_event->is_impl_only); |
| 713 | 706 |
| 714 controller_impl->Animate(kInitialTickTime + | 707 controller_impl->Animate(kInitialTickTime + |
| 715 TimeDelta::FromMilliseconds(1000)); | 708 TimeDelta::FromMilliseconds(1000)); |
| 716 controller_impl->UpdateState(true, events.get()); | 709 controller_impl->UpdateState(true, events.get()); |
| 717 EXPECT_EQ(end_filters, dummy_impl.filters()); | 710 EXPECT_EQ(end_filters, dummy_impl.filters()); |
| 718 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 711 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
| 719 EXPECT_EQ(2u, events->size()); | 712 EXPECT_EQ(2u, events->events_.size()); |
| 720 const AnimationEvent* end_filter_event = | 713 const AnimationEvent* end_filter_event = |
| 721 GetMostRecentPropertyUpdateEvent(events.get()); | 714 GetMostRecentPropertyUpdateEvent(events.get()); |
| 722 EXPECT_TRUE(end_filter_event); | 715 EXPECT_TRUE(end_filter_event); |
| 723 EXPECT_EQ(end_filters, end_filter_event->filters); | 716 EXPECT_EQ(end_filters, end_filter_event->filters); |
| 724 EXPECT_TRUE(end_filter_event->is_impl_only); | 717 EXPECT_TRUE(end_filter_event->is_impl_only); |
| 725 } | 718 } |
| 726 | 719 |
| 727 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) { | 720 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) { |
| 728 FakeLayerAnimationValueObserver dummy_impl; | 721 FakeLayerAnimationValueObserver dummy_impl; |
| 729 FakeLayerAnimationValueProvider dummy_provider_impl; | 722 FakeLayerAnimationValueProvider dummy_provider_impl; |
| 730 scoped_refptr<LayerAnimationController> controller_impl( | 723 scoped_refptr<LayerAnimationController> controller_impl( |
| 731 LayerAnimationController::Create(0)); | 724 LayerAnimationController::Create(0)); |
| 732 controller_impl->AddValueObserver(&dummy_impl); | 725 controller_impl->AddValueObserver(&dummy_impl); |
| 733 controller_impl->set_value_provider(&dummy_provider_impl); | 726 controller_impl->set_value_provider(&dummy_provider_impl); |
| 734 scoped_ptr<AnimationEventsVector> events( | 727 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 735 make_scoped_ptr(new AnimationEventsVector)); | |
| 736 FakeLayerAnimationValueObserver dummy; | 728 FakeLayerAnimationValueObserver dummy; |
| 737 FakeLayerAnimationValueProvider dummy_provider; | 729 FakeLayerAnimationValueProvider dummy_provider; |
| 738 scoped_refptr<LayerAnimationController> controller( | 730 scoped_refptr<LayerAnimationController> controller( |
| 739 LayerAnimationController::Create(0)); | 731 LayerAnimationController::Create(0)); |
| 740 controller->AddValueObserver(&dummy); | 732 controller->AddValueObserver(&dummy); |
| 741 controller->set_value_provider(&dummy_provider); | 733 controller->set_value_provider(&dummy_provider); |
| 742 | 734 |
| 743 gfx::ScrollOffset initial_value(100.f, 300.f); | 735 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 744 gfx::ScrollOffset target_value(300.f, 200.f); | 736 gfx::ScrollOffset target_value(300.f, 200.f); |
| 745 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 737 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 768 EXPECT_EQ(initial_value, dummy.scroll_offset()); | 760 EXPECT_EQ(initial_value, dummy.scroll_offset()); |
| 769 | 761 |
| 770 controller_impl->Animate(kInitialTickTime); | 762 controller_impl->Animate(kInitialTickTime); |
| 771 controller_impl->UpdateState(true, events.get()); | 763 controller_impl->UpdateState(true, events.get()); |
| 772 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 764 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 773 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 765 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
| 774 // Scroll offset animations should not generate property updates. | 766 // Scroll offset animations should not generate property updates. |
| 775 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 767 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 776 EXPECT_FALSE(event); | 768 EXPECT_FALSE(event); |
| 777 | 769 |
| 778 controller->NotifyAnimationStarted((*events)[0]); | 770 controller->NotifyAnimationStarted(events->events_[0]); |
| 779 controller->Animate(kInitialTickTime + duration / 2); | 771 controller->Animate(kInitialTickTime + duration / 2); |
| 780 controller->UpdateState(true, nullptr); | 772 controller->UpdateState(true, nullptr); |
| 781 EXPECT_TRUE(controller->HasActiveAnimation()); | 773 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 782 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset()); | 774 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset()); |
| 783 | 775 |
| 784 controller_impl->Animate(kInitialTickTime + duration / 2); | 776 controller_impl->Animate(kInitialTickTime + duration / 2); |
| 785 controller_impl->UpdateState(true, events.get()); | 777 controller_impl->UpdateState(true, events.get()); |
| 786 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | 778 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), |
| 787 dummy_impl.scroll_offset()); | 779 dummy_impl.scroll_offset()); |
| 788 event = GetMostRecentPropertyUpdateEvent(events.get()); | 780 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 802 } | 794 } |
| 803 | 795 |
| 804 // Ensure that when the impl controller doesn't have a value provider, | 796 // Ensure that when the impl controller doesn't have a value provider, |
| 805 // the main-thread controller's value provider is used to obtain the intial | 797 // the main-thread controller's value provider is used to obtain the intial |
| 806 // scroll offset. | 798 // scroll offset. |
| 807 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { | 799 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { |
| 808 FakeLayerAnimationValueObserver dummy_impl; | 800 FakeLayerAnimationValueObserver dummy_impl; |
| 809 scoped_refptr<LayerAnimationController> controller_impl( | 801 scoped_refptr<LayerAnimationController> controller_impl( |
| 810 LayerAnimationController::Create(0)); | 802 LayerAnimationController::Create(0)); |
| 811 controller_impl->AddValueObserver(&dummy_impl); | 803 controller_impl->AddValueObserver(&dummy_impl); |
| 812 scoped_ptr<AnimationEventsVector> events( | 804 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 813 make_scoped_ptr(new AnimationEventsVector)); | |
| 814 FakeLayerAnimationValueObserver dummy; | 805 FakeLayerAnimationValueObserver dummy; |
| 815 FakeLayerAnimationValueProvider dummy_provider; | 806 FakeLayerAnimationValueProvider dummy_provider; |
| 816 scoped_refptr<LayerAnimationController> controller( | 807 scoped_refptr<LayerAnimationController> controller( |
| 817 LayerAnimationController::Create(0)); | 808 LayerAnimationController::Create(0)); |
| 818 controller->AddValueObserver(&dummy); | 809 controller->AddValueObserver(&dummy); |
| 819 controller->set_value_provider(&dummy_provider); | 810 controller->set_value_provider(&dummy_provider); |
| 820 | 811 |
| 821 gfx::ScrollOffset initial_value(500.f, 100.f); | 812 gfx::ScrollOffset initial_value(500.f, 100.f); |
| 822 gfx::ScrollOffset target_value(300.f, 200.f); | 813 gfx::ScrollOffset target_value(300.f, 200.f); |
| 823 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 814 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 846 EXPECT_EQ(initial_value, dummy.scroll_offset()); | 837 EXPECT_EQ(initial_value, dummy.scroll_offset()); |
| 847 | 838 |
| 848 controller_impl->Animate(kInitialTickTime); | 839 controller_impl->Animate(kInitialTickTime); |
| 849 controller_impl->UpdateState(true, events.get()); | 840 controller_impl->UpdateState(true, events.get()); |
| 850 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 841 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 851 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 842 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); |
| 852 // Scroll offset animations should not generate property updates. | 843 // Scroll offset animations should not generate property updates. |
| 853 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 844 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 854 EXPECT_FALSE(event); | 845 EXPECT_FALSE(event); |
| 855 | 846 |
| 856 | 847 controller->NotifyAnimationStarted(events->events_[0]); |
| 857 controller->NotifyAnimationStarted((*events)[0]); | |
| 858 controller->Animate(kInitialTickTime + duration / 2); | 848 controller->Animate(kInitialTickTime + duration / 2); |
| 859 controller->UpdateState(true, nullptr); | 849 controller->UpdateState(true, nullptr); |
| 860 EXPECT_TRUE(controller->HasActiveAnimation()); | 850 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 861 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset()); | 851 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset()); |
| 862 | 852 |
| 863 controller_impl->Animate(kInitialTickTime + duration / 2); | 853 controller_impl->Animate(kInitialTickTime + duration / 2); |
| 864 controller_impl->UpdateState(true, events.get()); | 854 controller_impl->UpdateState(true, events.get()); |
| 865 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), | 855 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), |
| 866 dummy_impl.scroll_offset()); | 856 dummy_impl.scroll_offset()); |
| 867 event = GetMostRecentPropertyUpdateEvent(events.get()); | 857 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 878 controller->UpdateState(true, nullptr); | 868 controller->UpdateState(true, nullptr); |
| 879 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); | 869 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); |
| 880 EXPECT_FALSE(controller->HasActiveAnimation()); | 870 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 881 } | 871 } |
| 882 | 872 |
| 883 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { | 873 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { |
| 884 FakeLayerAnimationValueObserver dummy_impl; | 874 FakeLayerAnimationValueObserver dummy_impl; |
| 885 scoped_refptr<LayerAnimationController> controller_impl( | 875 scoped_refptr<LayerAnimationController> controller_impl( |
| 886 LayerAnimationController::Create(0)); | 876 LayerAnimationController::Create(0)); |
| 887 controller_impl->AddValueObserver(&dummy_impl); | 877 controller_impl->AddValueObserver(&dummy_impl); |
| 888 scoped_ptr<AnimationEventsVector> events( | 878 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 889 make_scoped_ptr(new AnimationEventsVector)); | |
| 890 | 879 |
| 891 gfx::ScrollOffset initial_value(100.f, 300.f); | 880 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 892 gfx::ScrollOffset target_value(300.f, 200.f); | 881 gfx::ScrollOffset target_value(300.f, 200.f); |
| 893 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 882 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 894 ScrollOffsetAnimationCurve::Create(target_value, | 883 ScrollOffsetAnimationCurve::Create(target_value, |
| 895 EaseInOutTimingFunction::Create())); | 884 EaseInOutTimingFunction::Create())); |
| 896 curve->SetInitialValue(initial_value); | 885 curve->SetInitialValue(initial_value); |
| 897 double duration_in_seconds = curve->Duration().InSecondsF(); | 886 double duration_in_seconds = curve->Duration().InSecondsF(); |
| 898 | 887 |
| 899 scoped_ptr<Animation> animation( | 888 scoped_ptr<Animation> animation( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 927 EXPECT_FALSE(event); | 916 EXPECT_FALSE(event); |
| 928 } | 917 } |
| 929 | 918 |
| 930 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) { | 919 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) { |
| 931 FakeLayerAnimationValueObserver dummy_impl; | 920 FakeLayerAnimationValueObserver dummy_impl; |
| 932 FakeLayerAnimationValueProvider dummy_provider_impl; | 921 FakeLayerAnimationValueProvider dummy_provider_impl; |
| 933 scoped_refptr<LayerAnimationController> controller_impl( | 922 scoped_refptr<LayerAnimationController> controller_impl( |
| 934 LayerAnimationController::Create(0)); | 923 LayerAnimationController::Create(0)); |
| 935 controller_impl->AddValueObserver(&dummy_impl); | 924 controller_impl->AddValueObserver(&dummy_impl); |
| 936 controller_impl->set_value_provider(&dummy_provider_impl); | 925 controller_impl->set_value_provider(&dummy_provider_impl); |
| 937 scoped_ptr<AnimationEventsVector> events( | 926 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 938 make_scoped_ptr(new AnimationEventsVector)); | |
| 939 FakeLayerAnimationValueObserver dummy; | 927 FakeLayerAnimationValueObserver dummy; |
| 940 FakeLayerAnimationValueProvider dummy_provider; | 928 FakeLayerAnimationValueProvider dummy_provider; |
| 941 scoped_refptr<LayerAnimationController> controller( | 929 scoped_refptr<LayerAnimationController> controller( |
| 942 LayerAnimationController::Create(0)); | 930 LayerAnimationController::Create(0)); |
| 943 controller->AddValueObserver(&dummy); | 931 controller->AddValueObserver(&dummy); |
| 944 controller->set_value_provider(&dummy_provider); | 932 controller->set_value_provider(&dummy_provider); |
| 945 | 933 |
| 946 // First test the 1-argument version of RemoveAnimation. | 934 // First test the 1-argument version of RemoveAnimation. |
| 947 gfx::ScrollOffset target_value(300.f, 200.f); | 935 gfx::ScrollOffset target_value(300.f, 200.f); |
| 948 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 936 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 }; | 1046 }; |
| 1059 | 1047 |
| 1060 // Tests that impl-only animations lead to start and finished notifications | 1048 // Tests that impl-only animations lead to start and finished notifications |
| 1061 // on the impl thread controller's animation delegate. | 1049 // on the impl thread controller's animation delegate. |
| 1062 TEST(LayerAnimationControllerTest, | 1050 TEST(LayerAnimationControllerTest, |
| 1063 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { | 1051 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { |
| 1064 FakeLayerAnimationValueObserver dummy_impl; | 1052 FakeLayerAnimationValueObserver dummy_impl; |
| 1065 scoped_refptr<LayerAnimationController> controller_impl( | 1053 scoped_refptr<LayerAnimationController> controller_impl( |
| 1066 LayerAnimationController::Create(0)); | 1054 LayerAnimationController::Create(0)); |
| 1067 controller_impl->AddValueObserver(&dummy_impl); | 1055 controller_impl->AddValueObserver(&dummy_impl); |
| 1068 scoped_ptr<AnimationEventsVector> events( | 1056 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1069 make_scoped_ptr(new AnimationEventsVector)); | |
| 1070 FakeAnimationDelegate delegate; | 1057 FakeAnimationDelegate delegate; |
| 1071 controller_impl->set_layer_animation_delegate(&delegate); | 1058 controller_impl->set_layer_animation_delegate(&delegate); |
| 1072 | 1059 |
| 1073 scoped_ptr<Animation> to_add(CreateAnimation( | 1060 scoped_ptr<Animation> to_add(CreateAnimation( |
| 1074 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 1061 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| 1075 Animation::OPACITY)); | 1062 Animation::OPACITY)); |
| 1076 to_add->set_is_impl_only(true); | 1063 to_add->set_is_impl_only(true); |
| 1077 controller_impl->AddAnimation(std::move(to_add)); | 1064 controller_impl->AddAnimation(std::move(to_add)); |
| 1078 | 1065 |
| 1079 EXPECT_FALSE(delegate.started()); | 1066 EXPECT_FALSE(delegate.started()); |
| 1080 EXPECT_FALSE(delegate.finished()); | 1067 EXPECT_FALSE(delegate.finished()); |
| 1081 | 1068 |
| 1082 controller_impl->Animate(kInitialTickTime); | 1069 controller_impl->Animate(kInitialTickTime); |
| 1083 controller_impl->UpdateState(true, events.get()); | 1070 controller_impl->UpdateState(true, events.get()); |
| 1084 | 1071 |
| 1085 EXPECT_TRUE(delegate.started()); | 1072 EXPECT_TRUE(delegate.started()); |
| 1086 EXPECT_FALSE(delegate.finished()); | 1073 EXPECT_FALSE(delegate.finished()); |
| 1087 | 1074 |
| 1088 events.reset(new AnimationEventsVector); | 1075 events.reset(new AnimationEvents); |
| 1089 controller_impl->Animate(kInitialTickTime + | 1076 controller_impl->Animate(kInitialTickTime + |
| 1090 TimeDelta::FromMilliseconds(1000)); | 1077 TimeDelta::FromMilliseconds(1000)); |
| 1091 controller_impl->UpdateState(true, events.get()); | 1078 controller_impl->UpdateState(true, events.get()); |
| 1092 | 1079 |
| 1093 EXPECT_TRUE(delegate.started()); | 1080 EXPECT_TRUE(delegate.started()); |
| 1094 EXPECT_TRUE(delegate.finished()); | 1081 EXPECT_TRUE(delegate.finished()); |
| 1095 } | 1082 } |
| 1096 | 1083 |
| 1097 // Tests that specified start times are sent to the main thread delegate | 1084 // Tests that specified start times are sent to the main thread delegate |
| 1098 TEST(LayerAnimationControllerTest, | 1085 TEST(LayerAnimationControllerTest, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1114 const TimeTicks start_time = TicksFromSecondsF(123); | 1101 const TimeTicks start_time = TicksFromSecondsF(123); |
| 1115 controller->GetAnimation(Animation::OPACITY)->set_start_time(start_time); | 1102 controller->GetAnimation(Animation::OPACITY)->set_start_time(start_time); |
| 1116 | 1103 |
| 1117 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1104 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1118 controller_impl->ActivateAnimations(); | 1105 controller_impl->ActivateAnimations(); |
| 1119 | 1106 |
| 1120 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 1107 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 1121 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 1108 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 1122 controller_impl->GetAnimationById(animation_id)->run_state()); | 1109 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 1123 | 1110 |
| 1124 AnimationEventsVector events; | 1111 AnimationEvents events; |
| 1125 controller_impl->Animate(kInitialTickTime); | 1112 controller_impl->Animate(kInitialTickTime); |
| 1126 controller_impl->UpdateState(true, &events); | 1113 controller_impl->UpdateState(true, &events); |
| 1127 | 1114 |
| 1128 // Synchronize the start times. | 1115 // Synchronize the start times. |
| 1129 EXPECT_EQ(1u, events.size()); | 1116 EXPECT_EQ(1u, events.events_.size()); |
| 1130 controller->NotifyAnimationStarted(events[0]); | 1117 controller->NotifyAnimationStarted(events.events_[0]); |
| 1131 | 1118 |
| 1132 // Validate start time on the main thread delegate. | 1119 // Validate start time on the main thread delegate. |
| 1133 EXPECT_EQ(start_time, delegate.start_time()); | 1120 EXPECT_EQ(start_time, delegate.start_time()); |
| 1134 } | 1121 } |
| 1135 | 1122 |
| 1136 class FakeLayerAnimationEventObserver : public LayerAnimationEventObserver { | 1123 class FakeLayerAnimationEventObserver : public LayerAnimationEventObserver { |
| 1137 public: | 1124 public: |
| 1138 FakeLayerAnimationEventObserver() : start_time_(base::TimeTicks()) {} | 1125 FakeLayerAnimationEventObserver() : start_time_(base::TimeTicks()) {} |
| 1139 | 1126 |
| 1140 void OnAnimationStarted(const AnimationEvent& event) override { | 1127 void OnAnimationStarted(const AnimationEvent& event) override { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1166 const TimeTicks start_time = TicksFromSecondsF(123); | 1153 const TimeTicks start_time = TicksFromSecondsF(123); |
| 1167 controller->GetAnimation(Animation::OPACITY)->set_start_time(start_time); | 1154 controller->GetAnimation(Animation::OPACITY)->set_start_time(start_time); |
| 1168 | 1155 |
| 1169 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1156 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1170 controller_impl->ActivateAnimations(); | 1157 controller_impl->ActivateAnimations(); |
| 1171 | 1158 |
| 1172 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 1159 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 1173 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 1160 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 1174 controller_impl->GetAnimationById(animation_id)->run_state()); | 1161 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 1175 | 1162 |
| 1176 AnimationEventsVector events; | 1163 AnimationEvents events; |
| 1177 controller_impl->Animate(kInitialTickTime); | 1164 controller_impl->Animate(kInitialTickTime); |
| 1178 controller_impl->UpdateState(true, &events); | 1165 controller_impl->UpdateState(true, &events); |
| 1179 | 1166 |
| 1180 // Synchronize the start times. | 1167 // Synchronize the start times. |
| 1181 EXPECT_EQ(1u, events.size()); | 1168 EXPECT_EQ(1u, events.events_.size()); |
| 1182 controller->NotifyAnimationStarted(events[0]); | 1169 controller->NotifyAnimationStarted(events.events_[0]); |
| 1183 | 1170 |
| 1184 // Validate start time on the event observer. | 1171 // Validate start time on the event observer. |
| 1185 EXPECT_EQ(start_time, observer.start_time()); | 1172 EXPECT_EQ(start_time, observer.start_time()); |
| 1186 } | 1173 } |
| 1187 | 1174 |
| 1188 // Tests animations that are waiting for a synchronized start time do not | 1175 // Tests animations that are waiting for a synchronized start time do not |
| 1189 // finish. | 1176 // finish. |
| 1190 TEST(LayerAnimationControllerTest, | 1177 TEST(LayerAnimationControllerTest, |
| 1191 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { | 1178 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { |
| 1192 scoped_ptr<AnimationEventsVector> events( | 1179 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1193 make_scoped_ptr(new AnimationEventsVector)); | |
| 1194 FakeLayerAnimationValueObserver dummy; | 1180 FakeLayerAnimationValueObserver dummy; |
| 1195 scoped_refptr<LayerAnimationController> controller( | 1181 scoped_refptr<LayerAnimationController> controller( |
| 1196 LayerAnimationController::Create(0)); | 1182 LayerAnimationController::Create(0)); |
| 1197 controller->AddValueObserver(&dummy); | 1183 controller->AddValueObserver(&dummy); |
| 1198 | 1184 |
| 1199 scoped_ptr<Animation> to_add(CreateAnimation( | 1185 scoped_ptr<Animation> to_add(CreateAnimation( |
| 1200 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 1186 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| 1201 Animation::OPACITY)); | 1187 Animation::OPACITY)); |
| 1202 to_add->set_needs_synchronized_start_time(true); | 1188 to_add->set_needs_synchronized_start_time(true); |
| 1203 | 1189 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1222 AnimationEvent(AnimationEvent::STARTED, 0, 1, Animation::OPACITY, | 1208 AnimationEvent(AnimationEvent::STARTED, 0, 1, Animation::OPACITY, |
| 1223 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); | 1209 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); |
| 1224 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); | 1210 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); |
| 1225 controller->UpdateState(true, events.get()); | 1211 controller->UpdateState(true, events.get()); |
| 1226 EXPECT_EQ(1.f, dummy.opacity()); | 1212 EXPECT_EQ(1.f, dummy.opacity()); |
| 1227 EXPECT_FALSE(controller->HasActiveAnimation()); | 1213 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1228 } | 1214 } |
| 1229 | 1215 |
| 1230 // Tests that two queued animations affecting the same property run in sequence. | 1216 // Tests that two queued animations affecting the same property run in sequence. |
| 1231 TEST(LayerAnimationControllerTest, TrivialQueuing) { | 1217 TEST(LayerAnimationControllerTest, TrivialQueuing) { |
| 1232 scoped_ptr<AnimationEventsVector> events( | 1218 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1233 make_scoped_ptr(new AnimationEventsVector)); | |
| 1234 FakeLayerAnimationValueObserver dummy; | 1219 FakeLayerAnimationValueObserver dummy; |
| 1235 scoped_refptr<LayerAnimationController> controller( | 1220 scoped_refptr<LayerAnimationController> controller( |
| 1236 LayerAnimationController::Create(0)); | 1221 LayerAnimationController::Create(0)); |
| 1237 controller->AddValueObserver(&dummy); | 1222 controller->AddValueObserver(&dummy); |
| 1238 | 1223 |
| 1239 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 1224 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 1240 | 1225 |
| 1241 controller->AddAnimation(CreateAnimation( | 1226 controller->AddAnimation(CreateAnimation( |
| 1242 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 1227 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| 1243 Animation::OPACITY)); | 1228 Animation::OPACITY)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1264 EXPECT_TRUE(controller->HasActiveAnimation()); | 1249 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1265 EXPECT_EQ(1.f, dummy.opacity()); | 1250 EXPECT_EQ(1.f, dummy.opacity()); |
| 1266 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1251 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1267 controller->UpdateState(true, events.get()); | 1252 controller->UpdateState(true, events.get()); |
| 1268 EXPECT_EQ(0.5f, dummy.opacity()); | 1253 EXPECT_EQ(0.5f, dummy.opacity()); |
| 1269 EXPECT_FALSE(controller->HasActiveAnimation()); | 1254 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1270 } | 1255 } |
| 1271 | 1256 |
| 1272 // Tests interrupting a transition with another transition. | 1257 // Tests interrupting a transition with another transition. |
| 1273 TEST(LayerAnimationControllerTest, Interrupt) { | 1258 TEST(LayerAnimationControllerTest, Interrupt) { |
| 1274 scoped_ptr<AnimationEventsVector> events( | 1259 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1275 make_scoped_ptr(new AnimationEventsVector)); | |
| 1276 FakeLayerAnimationValueObserver dummy; | 1260 FakeLayerAnimationValueObserver dummy; |
| 1277 scoped_refptr<LayerAnimationController> controller( | 1261 scoped_refptr<LayerAnimationController> controller( |
| 1278 LayerAnimationController::Create(0)); | 1262 LayerAnimationController::Create(0)); |
| 1279 controller->AddValueObserver(&dummy); | 1263 controller->AddValueObserver(&dummy); |
| 1280 controller->AddAnimation(CreateAnimation( | 1264 controller->AddAnimation(CreateAnimation( |
| 1281 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 1265 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| 1282 Animation::OPACITY)); | 1266 Animation::OPACITY)); |
| 1283 controller->Animate(kInitialTickTime); | 1267 controller->Animate(kInitialTickTime); |
| 1284 controller->UpdateState(true, events.get()); | 1268 controller->UpdateState(true, events.get()); |
| 1285 EXPECT_TRUE(controller->HasActiveAnimation()); | 1269 EXPECT_TRUE(controller->HasActiveAnimation()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1299 EXPECT_EQ(1.f, dummy.opacity()); | 1283 EXPECT_EQ(1.f, dummy.opacity()); |
| 1300 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | 1284 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); |
| 1301 controller->UpdateState(true, events.get()); | 1285 controller->UpdateState(true, events.get()); |
| 1302 EXPECT_EQ(0.5f, dummy.opacity()); | 1286 EXPECT_EQ(0.5f, dummy.opacity()); |
| 1303 EXPECT_FALSE(controller->HasActiveAnimation()); | 1287 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1304 } | 1288 } |
| 1305 | 1289 |
| 1306 // Tests scheduling two animations to run together when only one property is | 1290 // Tests scheduling two animations to run together when only one property is |
| 1307 // free. | 1291 // free. |
| 1308 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { | 1292 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { |
| 1309 scoped_ptr<AnimationEventsVector> events( | 1293 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1310 make_scoped_ptr(new AnimationEventsVector)); | |
| 1311 FakeLayerAnimationValueObserver dummy; | 1294 FakeLayerAnimationValueObserver dummy; |
| 1312 scoped_refptr<LayerAnimationController> controller( | 1295 scoped_refptr<LayerAnimationController> controller( |
| 1313 LayerAnimationController::Create(0)); | 1296 LayerAnimationController::Create(0)); |
| 1314 controller->AddValueObserver(&dummy); | 1297 controller->AddValueObserver(&dummy); |
| 1315 | 1298 |
| 1316 controller->AddAnimation(CreateAnimation( | 1299 controller->AddAnimation(CreateAnimation( |
| 1317 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | 1300 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, |
| 1318 Animation::TRANSFORM)); | 1301 Animation::TRANSFORM)); |
| 1319 controller->AddAnimation(CreateAnimation( | 1302 controller->AddAnimation(CreateAnimation( |
| 1320 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, | 1303 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1336 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1319 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1337 controller->UpdateState(true, events.get()); | 1320 controller->UpdateState(true, events.get()); |
| 1338 EXPECT_EQ(1.f, dummy.opacity()); | 1321 EXPECT_EQ(1.f, dummy.opacity()); |
| 1339 EXPECT_FALSE(controller->HasActiveAnimation()); | 1322 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1340 } | 1323 } |
| 1341 | 1324 |
| 1342 // Tests scheduling two animations to run together with different lengths and | 1325 // Tests scheduling two animations to run together with different lengths and |
| 1343 // another animation queued to start when the shorter animation finishes (should | 1326 // another animation queued to start when the shorter animation finishes (should |
| 1344 // wait for both to finish). | 1327 // wait for both to finish). |
| 1345 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { | 1328 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { |
| 1346 scoped_ptr<AnimationEventsVector> events( | 1329 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1347 make_scoped_ptr(new AnimationEventsVector)); | |
| 1348 FakeLayerAnimationValueObserver dummy; | 1330 FakeLayerAnimationValueObserver dummy; |
| 1349 scoped_refptr<LayerAnimationController> controller( | 1331 scoped_refptr<LayerAnimationController> controller( |
| 1350 LayerAnimationController::Create(0)); | 1332 LayerAnimationController::Create(0)); |
| 1351 controller->AddValueObserver(&dummy); | 1333 controller->AddValueObserver(&dummy); |
| 1352 | 1334 |
| 1353 controller->AddAnimation(CreateAnimation( | 1335 controller->AddAnimation(CreateAnimation( |
| 1354 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, | 1336 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, |
| 1355 Animation::TRANSFORM)); | 1337 Animation::TRANSFORM)); |
| 1356 controller->AddAnimation(CreateAnimation( | 1338 controller->AddAnimation(CreateAnimation( |
| 1357 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 1339 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1377 // The second opacity animation should start at time 2 and should be done by | 1359 // The second opacity animation should start at time 2 and should be done by |
| 1378 // time 3. | 1360 // time 3. |
| 1379 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1361 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 1380 controller->UpdateState(true, events.get()); | 1362 controller->UpdateState(true, events.get()); |
| 1381 EXPECT_EQ(0.5f, dummy.opacity()); | 1363 EXPECT_EQ(0.5f, dummy.opacity()); |
| 1382 EXPECT_FALSE(controller->HasActiveAnimation()); | 1364 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1383 } | 1365 } |
| 1384 | 1366 |
| 1385 // Test that a looping animation loops and for the correct number of iterations. | 1367 // Test that a looping animation loops and for the correct number of iterations. |
| 1386 TEST(LayerAnimationControllerTest, TrivialLooping) { | 1368 TEST(LayerAnimationControllerTest, TrivialLooping) { |
| 1387 scoped_ptr<AnimationEventsVector> events( | 1369 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1388 make_scoped_ptr(new AnimationEventsVector)); | |
| 1389 FakeLayerAnimationValueObserver dummy; | 1370 FakeLayerAnimationValueObserver dummy; |
| 1390 scoped_refptr<LayerAnimationController> controller( | 1371 scoped_refptr<LayerAnimationController> controller( |
| 1391 LayerAnimationController::Create(0)); | 1372 LayerAnimationController::Create(0)); |
| 1392 controller->AddValueObserver(&dummy); | 1373 controller->AddValueObserver(&dummy); |
| 1393 | 1374 |
| 1394 scoped_ptr<Animation> to_add(CreateAnimation( | 1375 scoped_ptr<Animation> to_add(CreateAnimation( |
| 1395 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 1376 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| 1396 Animation::OPACITY)); | 1377 Animation::OPACITY)); |
| 1397 to_add->set_iterations(3); | 1378 to_add->set_iterations(3); |
| 1398 controller->AddAnimation(std::move(to_add)); | 1379 controller->AddAnimation(std::move(to_add)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1423 EXPECT_EQ(1.f, dummy.opacity()); | 1404 EXPECT_EQ(1.f, dummy.opacity()); |
| 1424 | 1405 |
| 1425 // Just be extra sure. | 1406 // Just be extra sure. |
| 1426 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); | 1407 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); |
| 1427 controller->UpdateState(true, events.get()); | 1408 controller->UpdateState(true, events.get()); |
| 1428 EXPECT_EQ(1.f, dummy.opacity()); | 1409 EXPECT_EQ(1.f, dummy.opacity()); |
| 1429 } | 1410 } |
| 1430 | 1411 |
| 1431 // Test that an infinitely looping animation does indeed go until aborted. | 1412 // Test that an infinitely looping animation does indeed go until aborted. |
| 1432 TEST(LayerAnimationControllerTest, InfiniteLooping) { | 1413 TEST(LayerAnimationControllerTest, InfiniteLooping) { |
| 1433 scoped_ptr<AnimationEventsVector> events( | 1414 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1434 make_scoped_ptr(new AnimationEventsVector)); | |
| 1435 FakeLayerAnimationValueObserver dummy; | 1415 FakeLayerAnimationValueObserver dummy; |
| 1436 scoped_refptr<LayerAnimationController> controller( | 1416 scoped_refptr<LayerAnimationController> controller( |
| 1437 LayerAnimationController::Create(0)); | 1417 LayerAnimationController::Create(0)); |
| 1438 controller->AddValueObserver(&dummy); | 1418 controller->AddValueObserver(&dummy); |
| 1439 | 1419 |
| 1440 scoped_ptr<Animation> to_add(CreateAnimation( | 1420 scoped_ptr<Animation> to_add(CreateAnimation( |
| 1441 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 1421 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| 1442 Animation::OPACITY)); | 1422 Animation::OPACITY)); |
| 1443 to_add->set_iterations(-1); | 1423 to_add->set_iterations(-1); |
| 1444 controller->AddAnimation(std::move(to_add)); | 1424 controller->AddAnimation(std::move(to_add)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1470 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY)); | 1450 EXPECT_TRUE(controller->GetAnimation(Animation::OPACITY)); |
| 1471 controller->GetAnimation(Animation::OPACITY) | 1451 controller->GetAnimation(Animation::OPACITY) |
| 1472 ->SetRunState(Animation::ABORTED, | 1452 ->SetRunState(Animation::ABORTED, |
| 1473 kInitialTickTime + TimeDelta::FromMilliseconds(750)); | 1453 kInitialTickTime + TimeDelta::FromMilliseconds(750)); |
| 1474 EXPECT_FALSE(controller->HasActiveAnimation()); | 1454 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1475 EXPECT_EQ(0.75f, dummy.opacity()); | 1455 EXPECT_EQ(0.75f, dummy.opacity()); |
| 1476 } | 1456 } |
| 1477 | 1457 |
| 1478 // Test that pausing and resuming work as expected. | 1458 // Test that pausing and resuming work as expected. |
| 1479 TEST(LayerAnimationControllerTest, PauseResume) { | 1459 TEST(LayerAnimationControllerTest, PauseResume) { |
| 1480 scoped_ptr<AnimationEventsVector> events( | 1460 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1481 make_scoped_ptr(new AnimationEventsVector)); | |
| 1482 FakeLayerAnimationValueObserver dummy; | 1461 FakeLayerAnimationValueObserver dummy; |
| 1483 scoped_refptr<LayerAnimationController> controller( | 1462 scoped_refptr<LayerAnimationController> controller( |
| 1484 LayerAnimationController::Create(0)); | 1463 LayerAnimationController::Create(0)); |
| 1485 controller->AddValueObserver(&dummy); | 1464 controller->AddValueObserver(&dummy); |
| 1486 | 1465 |
| 1487 controller->AddAnimation(CreateAnimation( | 1466 controller->AddAnimation(CreateAnimation( |
| 1488 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 1467 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| 1489 Animation::OPACITY)); | 1468 Animation::OPACITY)); |
| 1490 | 1469 |
| 1491 controller->Animate(kInitialTickTime); | 1470 controller->Animate(kInitialTickTime); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1516 EXPECT_TRUE(controller->HasActiveAnimation()); | 1495 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1517 EXPECT_EQ(0.75f, dummy.opacity()); | 1496 EXPECT_EQ(0.75f, dummy.opacity()); |
| 1518 | 1497 |
| 1519 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); | 1498 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); |
| 1520 controller->UpdateState(true, events.get()); | 1499 controller->UpdateState(true, events.get()); |
| 1521 EXPECT_FALSE(controller->HasActiveAnimation()); | 1500 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1522 EXPECT_EQ(1.f, dummy.opacity()); | 1501 EXPECT_EQ(1.f, dummy.opacity()); |
| 1523 } | 1502 } |
| 1524 | 1503 |
| 1525 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { | 1504 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { |
| 1526 scoped_ptr<AnimationEventsVector> events( | 1505 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1527 make_scoped_ptr(new AnimationEventsVector)); | |
| 1528 FakeLayerAnimationValueObserver dummy; | 1506 FakeLayerAnimationValueObserver dummy; |
| 1529 scoped_refptr<LayerAnimationController> controller( | 1507 scoped_refptr<LayerAnimationController> controller( |
| 1530 LayerAnimationController::Create(0)); | 1508 LayerAnimationController::Create(0)); |
| 1531 controller->AddValueObserver(&dummy); | 1509 controller->AddValueObserver(&dummy); |
| 1532 | 1510 |
| 1533 const int animation_id = 2; | 1511 const int animation_id = 2; |
| 1534 controller->AddAnimation(Animation::Create( | 1512 controller->AddAnimation(Animation::Create( |
| 1535 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, | 1513 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, |
| 1536 Animation::TRANSFORM)); | 1514 Animation::TRANSFORM)); |
| 1537 controller->AddAnimation(Animation::Create( | 1515 controller->AddAnimation(Animation::Create( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1562 controller->UpdateState(true, events.get()); | 1540 controller->UpdateState(true, events.get()); |
| 1563 EXPECT_TRUE(!controller->HasActiveAnimation()); | 1541 EXPECT_TRUE(!controller->HasActiveAnimation()); |
| 1564 EXPECT_EQ(0.75f, dummy.opacity()); | 1542 EXPECT_EQ(0.75f, dummy.opacity()); |
| 1565 } | 1543 } |
| 1566 | 1544 |
| 1567 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { | 1545 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { |
| 1568 FakeLayerAnimationValueObserver dummy_impl; | 1546 FakeLayerAnimationValueObserver dummy_impl; |
| 1569 scoped_refptr<LayerAnimationController> controller_impl( | 1547 scoped_refptr<LayerAnimationController> controller_impl( |
| 1570 LayerAnimationController::Create(0)); | 1548 LayerAnimationController::Create(0)); |
| 1571 controller_impl->AddValueObserver(&dummy_impl); | 1549 controller_impl->AddValueObserver(&dummy_impl); |
| 1572 scoped_ptr<AnimationEventsVector> events( | 1550 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1573 make_scoped_ptr(new AnimationEventsVector)); | |
| 1574 FakeLayerAnimationValueObserver dummy; | 1551 FakeLayerAnimationValueObserver dummy; |
| 1575 scoped_refptr<LayerAnimationController> controller( | 1552 scoped_refptr<LayerAnimationController> controller( |
| 1576 LayerAnimationController::Create(0)); | 1553 LayerAnimationController::Create(0)); |
| 1577 controller->AddValueObserver(&dummy); | 1554 controller->AddValueObserver(&dummy); |
| 1578 | 1555 |
| 1579 scoped_ptr<Animation> to_add(CreateAnimation( | 1556 scoped_ptr<Animation> to_add(CreateAnimation( |
| 1580 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), 0, | 1557 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), 0, |
| 1581 Animation::OPACITY)); | 1558 Animation::OPACITY)); |
| 1582 to_add->set_needs_synchronized_start_time(true); | 1559 to_add->set_needs_synchronized_start_time(true); |
| 1583 controller->AddAnimation(std::move(to_add)); | 1560 controller->AddAnimation(std::move(to_add)); |
| 1584 | 1561 |
| 1585 controller->Animate(kInitialTickTime); | 1562 controller->Animate(kInitialTickTime); |
| 1586 controller->UpdateState(true, events.get()); | 1563 controller->UpdateState(true, events.get()); |
| 1587 EXPECT_TRUE(controller->HasActiveAnimation()); | 1564 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1588 Animation* active_animation = controller->GetAnimation(Animation::OPACITY); | 1565 Animation* active_animation = controller->GetAnimation(Animation::OPACITY); |
| 1589 EXPECT_TRUE(active_animation); | 1566 EXPECT_TRUE(active_animation); |
| 1590 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); | 1567 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); |
| 1591 | 1568 |
| 1592 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1569 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1593 controller_impl->ActivateAnimations(); | 1570 controller_impl->ActivateAnimations(); |
| 1594 | 1571 |
| 1595 active_animation = controller_impl->GetAnimation(Animation::OPACITY); | 1572 active_animation = controller_impl->GetAnimation(Animation::OPACITY); |
| 1596 EXPECT_TRUE(active_animation); | 1573 EXPECT_TRUE(active_animation); |
| 1597 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 1574 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 1598 active_animation->run_state()); | 1575 active_animation->run_state()); |
| 1599 } | 1576 } |
| 1600 | 1577 |
| 1601 // Tests that skipping a call to UpdateState works as expected. | 1578 // Tests that skipping a call to UpdateState works as expected. |
| 1602 TEST(LayerAnimationControllerTest, SkipUpdateState) { | 1579 TEST(LayerAnimationControllerTest, SkipUpdateState) { |
| 1603 scoped_ptr<AnimationEventsVector> events( | 1580 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1604 make_scoped_ptr(new AnimationEventsVector)); | |
| 1605 FakeLayerAnimationValueObserver dummy; | 1581 FakeLayerAnimationValueObserver dummy; |
| 1606 scoped_refptr<LayerAnimationController> controller( | 1582 scoped_refptr<LayerAnimationController> controller( |
| 1607 LayerAnimationController::Create(0)); | 1583 LayerAnimationController::Create(0)); |
| 1608 controller->AddValueObserver(&dummy); | 1584 controller->AddValueObserver(&dummy); |
| 1609 | 1585 |
| 1610 scoped_ptr<Animation> first_animation(CreateAnimation( | 1586 scoped_ptr<Animation> first_animation(CreateAnimation( |
| 1611 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | 1587 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, |
| 1612 Animation::TRANSFORM)); | 1588 Animation::TRANSFORM)); |
| 1613 first_animation->set_is_controlling_instance_for_test(true); | 1589 first_animation->set_is_controlling_instance_for_test(true); |
| 1614 controller->AddAnimation(std::move(first_animation)); | 1590 controller->AddAnimation(std::move(first_animation)); |
| 1615 | 1591 |
| 1616 controller->Animate(kInitialTickTime); | 1592 controller->Animate(kInitialTickTime); |
| 1617 controller->UpdateState(true, events.get()); | 1593 controller->UpdateState(true, events.get()); |
| 1618 | 1594 |
| 1619 scoped_ptr<Animation> second_animation(CreateAnimation( | 1595 scoped_ptr<Animation> second_animation(CreateAnimation( |
| 1620 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 2, | 1596 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 2, |
| 1621 Animation::OPACITY)); | 1597 Animation::OPACITY)); |
| 1622 second_animation->set_is_controlling_instance_for_test(true); | 1598 second_animation->set_is_controlling_instance_for_test(true); |
| 1623 controller->AddAnimation(std::move(second_animation)); | 1599 controller->AddAnimation(std::move(second_animation)); |
| 1624 | 1600 |
| 1625 // Animate but don't UpdateState. | 1601 // Animate but don't UpdateState. |
| 1626 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1602 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1627 | 1603 |
| 1628 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1604 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1629 events.reset(new AnimationEventsVector); | 1605 events.reset(new AnimationEvents); |
| 1630 controller->UpdateState(true, events.get()); | 1606 controller->UpdateState(true, events.get()); |
| 1631 | 1607 |
| 1632 // Should have one STARTED event and one FINISHED event. | 1608 // Should have one STARTED event and one FINISHED event. |
| 1633 EXPECT_EQ(2u, events->size()); | 1609 EXPECT_EQ(2u, events->events_.size()); |
| 1634 EXPECT_NE((*events)[0].type, (*events)[1].type); | 1610 EXPECT_NE(events->events_[0].type, events->events_[1].type); |
| 1635 | 1611 |
| 1636 // The float transition should still be at its starting point. | 1612 // The float transition should still be at its starting point. |
| 1637 EXPECT_TRUE(controller->HasActiveAnimation()); | 1613 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1638 EXPECT_EQ(0.f, dummy.opacity()); | 1614 EXPECT_EQ(0.f, dummy.opacity()); |
| 1639 | 1615 |
| 1640 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1616 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 1641 controller->UpdateState(true, events.get()); | 1617 controller->UpdateState(true, events.get()); |
| 1642 | 1618 |
| 1643 // The float tranisition should now be done. | 1619 // The float tranisition should now be done. |
| 1644 EXPECT_EQ(1.f, dummy.opacity()); | 1620 EXPECT_EQ(1.f, dummy.opacity()); |
| 1645 EXPECT_FALSE(controller->HasActiveAnimation()); | 1621 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1646 } | 1622 } |
| 1647 | 1623 |
| 1648 // Tests that an animation controller with only a pending observer gets ticked | 1624 // Tests that an animation controller with only a pending observer gets ticked |
| 1649 // but doesn't progress animations past the STARTING state. | 1625 // but doesn't progress animations past the STARTING state. |
| 1650 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { | 1626 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { |
| 1651 scoped_ptr<AnimationEventsVector> events( | 1627 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1652 make_scoped_ptr(new AnimationEventsVector)); | |
| 1653 FakeLayerAnimationValueObserver dummy; | 1628 FakeLayerAnimationValueObserver dummy; |
| 1654 FakeInactiveLayerAnimationValueObserver pending_dummy; | 1629 FakeInactiveLayerAnimationValueObserver pending_dummy; |
| 1655 scoped_refptr<LayerAnimationController> controller( | 1630 scoped_refptr<LayerAnimationController> controller( |
| 1656 LayerAnimationController::Create(0)); | 1631 LayerAnimationController::Create(0)); |
| 1657 | 1632 |
| 1658 const int id = 1; | 1633 const int id = 1; |
| 1659 controller->AddAnimation(CreateAnimation( | 1634 controller->AddAnimation(CreateAnimation( |
| 1660 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), id, | 1635 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), id, |
| 1661 Animation::OPACITY)); | 1636 Animation::OPACITY)); |
| 1662 | 1637 |
| 1663 // Without an observer, the animation shouldn't progress to the STARTING | 1638 // Without an observer, the animation shouldn't progress to the STARTING |
| 1664 // state. | 1639 // state. |
| 1665 controller->Animate(kInitialTickTime); | 1640 controller->Animate(kInitialTickTime); |
| 1666 controller->UpdateState(true, events.get()); | 1641 controller->UpdateState(true, events.get()); |
| 1667 EXPECT_EQ(0u, events->size()); | 1642 EXPECT_EQ(0u, events->events_.size()); |
| 1668 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 1643 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 1669 controller->GetAnimation(Animation::OPACITY)->run_state()); | 1644 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1670 | 1645 |
| 1671 controller->AddValueObserver(&pending_dummy); | 1646 controller->AddValueObserver(&pending_dummy); |
| 1672 | 1647 |
| 1673 // With only a pending observer, the animation should progress to the | 1648 // With only a pending observer, the animation should progress to the |
| 1674 // STARTING state and get ticked at its starting point, but should not | 1649 // STARTING state and get ticked at its starting point, but should not |
| 1675 // progress to RUNNING. | 1650 // progress to RUNNING. |
| 1676 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1651 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1677 controller->UpdateState(true, events.get()); | 1652 controller->UpdateState(true, events.get()); |
| 1678 EXPECT_EQ(0u, events->size()); | 1653 EXPECT_EQ(0u, events->events_.size()); |
| 1679 EXPECT_EQ(Animation::STARTING, | 1654 EXPECT_EQ(Animation::STARTING, |
| 1680 controller->GetAnimation(Animation::OPACITY)->run_state()); | 1655 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1681 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1656 EXPECT_EQ(0.5f, pending_dummy.opacity()); |
| 1682 | 1657 |
| 1683 // Even when already in the STARTING state, the animation should stay | 1658 // Even when already in the STARTING state, the animation should stay |
| 1684 // there, and shouldn't be ticked past its starting point. | 1659 // there, and shouldn't be ticked past its starting point. |
| 1685 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1660 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1686 controller->UpdateState(true, events.get()); | 1661 controller->UpdateState(true, events.get()); |
| 1687 EXPECT_EQ(0u, events->size()); | 1662 EXPECT_EQ(0u, events->events_.size()); |
| 1688 EXPECT_EQ(Animation::STARTING, | 1663 EXPECT_EQ(Animation::STARTING, |
| 1689 controller->GetAnimation(Animation::OPACITY)->run_state()); | 1664 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1690 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1665 EXPECT_EQ(0.5f, pending_dummy.opacity()); |
| 1691 | 1666 |
| 1692 controller->AddValueObserver(&dummy); | 1667 controller->AddValueObserver(&dummy); |
| 1693 | 1668 |
| 1694 // Now that an active observer has been added, the animation should still | 1669 // Now that an active observer has been added, the animation should still |
| 1695 // initially tick at its starting point, but should now progress to RUNNING. | 1670 // initially tick at its starting point, but should now progress to RUNNING. |
| 1696 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1671 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 1697 controller->UpdateState(true, events.get()); | 1672 controller->UpdateState(true, events.get()); |
| 1698 EXPECT_EQ(1u, events->size()); | 1673 EXPECT_EQ(1u, events->events_.size()); |
| 1699 EXPECT_EQ(Animation::RUNNING, | 1674 EXPECT_EQ(Animation::RUNNING, |
| 1700 controller->GetAnimation(Animation::OPACITY)->run_state()); | 1675 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1701 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1676 EXPECT_EQ(0.5f, pending_dummy.opacity()); |
| 1702 EXPECT_EQ(0.5f, dummy.opacity()); | 1677 EXPECT_EQ(0.5f, dummy.opacity()); |
| 1703 | 1678 |
| 1704 // The animation should now tick past its starting point. | 1679 // The animation should now tick past its starting point. |
| 1705 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); | 1680 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); |
| 1706 EXPECT_NE(0.5f, pending_dummy.opacity()); | 1681 EXPECT_NE(0.5f, pending_dummy.opacity()); |
| 1707 EXPECT_NE(0.5f, dummy.opacity()); | 1682 EXPECT_NE(0.5f, dummy.opacity()); |
| 1708 } | 1683 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1850 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1876 controller_impl->ActivateAnimations(); | 1851 controller_impl->ActivateAnimations(); |
| 1877 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 1852 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 1878 | 1853 |
| 1879 controller_impl->AbortAnimations(Animation::OPACITY); | 1854 controller_impl->AbortAnimations(Animation::OPACITY); |
| 1880 EXPECT_EQ(Animation::ABORTED, | 1855 EXPECT_EQ(Animation::ABORTED, |
| 1881 controller_impl->GetAnimation(Animation::OPACITY)->run_state()); | 1856 controller_impl->GetAnimation(Animation::OPACITY)->run_state()); |
| 1882 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | 1857 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); |
| 1883 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | 1858 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); |
| 1884 | 1859 |
| 1885 AnimationEventsVector events; | 1860 AnimationEvents events; |
| 1886 controller_impl->Animate(kInitialTickTime); | 1861 controller_impl->Animate(kInitialTickTime); |
| 1887 controller_impl->UpdateState(true, &events); | 1862 controller_impl->UpdateState(true, &events); |
| 1888 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | 1863 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); |
| 1889 EXPECT_EQ(1u, events.size()); | 1864 EXPECT_EQ(1u, events.events_.size()); |
| 1890 EXPECT_EQ(AnimationEvent::ABORTED, events[0].type); | 1865 EXPECT_EQ(AnimationEvent::ABORTED, events.events_[0].type); |
| 1891 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | 1866 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 1892 controller_impl->GetAnimation(Animation::OPACITY)->run_state()); | 1867 controller_impl->GetAnimation(Animation::OPACITY)->run_state()); |
| 1893 | 1868 |
| 1894 controller->NotifyAnimationAborted(events[0]); | 1869 controller->NotifyAnimationAborted(events.events_[0]); |
| 1895 EXPECT_EQ(Animation::ABORTED, | 1870 EXPECT_EQ(Animation::ABORTED, |
| 1896 controller->GetAnimation(Animation::OPACITY)->run_state()); | 1871 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1897 | 1872 |
| 1898 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1873 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 1899 controller->UpdateState(true, nullptr); | 1874 controller->UpdateState(true, nullptr); |
| 1900 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 1875 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
| 1901 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | 1876 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 1902 controller->GetAnimation(Animation::OPACITY)->run_state()); | 1877 controller->GetAnimation(Animation::OPACITY)->run_state()); |
| 1903 | 1878 |
| 1904 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1879 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1905 controller_impl->ActivateAnimations(); | 1880 controller_impl->ActivateAnimations(); |
| 1906 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | 1881 EXPECT_FALSE(controller->GetAnimationById(animation_id)); |
| 1907 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | 1882 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); |
| 1908 } | 1883 } |
| 1909 | 1884 |
| 1910 // Ensure that we only generate FINISHED events for animations in a group | 1885 // Ensure that we only generate FINISHED events for animations in a group |
| 1911 // once all animations in that group are finished. | 1886 // once all animations in that group are finished. |
| 1912 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { | 1887 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { |
| 1913 scoped_ptr<AnimationEventsVector> events( | 1888 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1914 make_scoped_ptr(new AnimationEventsVector)); | |
| 1915 FakeLayerAnimationValueObserver dummy_impl; | 1889 FakeLayerAnimationValueObserver dummy_impl; |
| 1916 scoped_refptr<LayerAnimationController> controller_impl( | 1890 scoped_refptr<LayerAnimationController> controller_impl( |
| 1917 LayerAnimationController::Create(0)); | 1891 LayerAnimationController::Create(0)); |
| 1918 controller_impl->AddValueObserver(&dummy_impl); | 1892 controller_impl->AddValueObserver(&dummy_impl); |
| 1919 | 1893 |
| 1920 const int group_id = 1; | 1894 const int group_id = 1; |
| 1921 | 1895 |
| 1922 // Add two animations with the same group id but different durations. | 1896 // Add two animations with the same group id but different durations. |
| 1923 scoped_ptr<Animation> first_animation(Animation::Create( | 1897 scoped_ptr<Animation> first_animation(Animation::Create( |
| 1924 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1, group_id, | 1898 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1, group_id, |
| 1925 Animation::TRANSFORM)); | 1899 Animation::TRANSFORM)); |
| 1926 first_animation->set_is_controlling_instance_for_test(true); | 1900 first_animation->set_is_controlling_instance_for_test(true); |
| 1927 controller_impl->AddAnimation(std::move(first_animation)); | 1901 controller_impl->AddAnimation(std::move(first_animation)); |
| 1928 | 1902 |
| 1929 scoped_ptr<Animation> second_animation(Animation::Create( | 1903 scoped_ptr<Animation> second_animation(Animation::Create( |
| 1930 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 2, | 1904 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 2, |
| 1931 group_id, Animation::OPACITY)); | 1905 group_id, Animation::OPACITY)); |
| 1932 second_animation->set_is_controlling_instance_for_test(true); | 1906 second_animation->set_is_controlling_instance_for_test(true); |
| 1933 controller_impl->AddAnimation(std::move(second_animation)); | 1907 controller_impl->AddAnimation(std::move(second_animation)); |
| 1934 | 1908 |
| 1935 controller_impl->Animate(kInitialTickTime); | 1909 controller_impl->Animate(kInitialTickTime); |
| 1936 controller_impl->UpdateState(true, events.get()); | 1910 controller_impl->UpdateState(true, events.get()); |
| 1937 | 1911 |
| 1938 // Both animations should have started. | 1912 // Both animations should have started. |
| 1939 EXPECT_EQ(2u, events->size()); | 1913 EXPECT_EQ(2u, events->events_.size()); |
| 1940 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type); | 1914 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); |
| 1941 EXPECT_EQ(AnimationEvent::STARTED, (*events)[1].type); | 1915 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); |
| 1942 | 1916 |
| 1943 events.reset(new AnimationEventsVector); | 1917 events.reset(new AnimationEvents); |
| 1944 controller_impl->Animate(kInitialTickTime + | 1918 controller_impl->Animate(kInitialTickTime + |
| 1945 TimeDelta::FromMilliseconds(1000)); | 1919 TimeDelta::FromMilliseconds(1000)); |
| 1946 controller_impl->UpdateState(true, events.get()); | 1920 controller_impl->UpdateState(true, events.get()); |
| 1947 | 1921 |
| 1948 // The opacity animation should be finished, but should not have generated | 1922 // The opacity animation should be finished, but should not have generated |
| 1949 // a FINISHED event yet. | 1923 // a FINISHED event yet. |
| 1950 EXPECT_EQ(0u, events->size()); | 1924 EXPECT_EQ(0u, events->events_.size()); |
| 1951 EXPECT_EQ(Animation::FINISHED, | 1925 EXPECT_EQ(Animation::FINISHED, |
| 1952 controller_impl->GetAnimationById(2)->run_state()); | 1926 controller_impl->GetAnimationById(2)->run_state()); |
| 1953 EXPECT_EQ(Animation::RUNNING, | 1927 EXPECT_EQ(Animation::RUNNING, |
| 1954 controller_impl->GetAnimationById(1)->run_state()); | 1928 controller_impl->GetAnimationById(1)->run_state()); |
| 1955 | 1929 |
| 1956 controller_impl->Animate(kInitialTickTime + | 1930 controller_impl->Animate(kInitialTickTime + |
| 1957 TimeDelta::FromMilliseconds(2000)); | 1931 TimeDelta::FromMilliseconds(2000)); |
| 1958 controller_impl->UpdateState(true, events.get()); | 1932 controller_impl->UpdateState(true, events.get()); |
| 1959 | 1933 |
| 1960 // Both animations should have generated FINISHED events. | 1934 // Both animations should have generated FINISHED events. |
| 1961 EXPECT_EQ(2u, events->size()); | 1935 EXPECT_EQ(2u, events->events_.size()); |
| 1962 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type); | 1936 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); |
| 1963 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[1].type); | 1937 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[1].type); |
| 1964 } | 1938 } |
| 1965 | 1939 |
| 1966 // Ensure that when a group has a mix of aborted and finished animations, | 1940 // Ensure that when a group has a mix of aborted and finished animations, |
| 1967 // we generate a FINISHED event for the finished animation and an ABORTED | 1941 // we generate a FINISHED event for the finished animation and an ABORTED |
| 1968 // event for the aborted animation. | 1942 // event for the aborted animation. |
| 1969 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { | 1943 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { |
| 1970 scoped_ptr<AnimationEventsVector> events( | 1944 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1971 make_scoped_ptr(new AnimationEventsVector)); | |
| 1972 FakeLayerAnimationValueObserver dummy_impl; | 1945 FakeLayerAnimationValueObserver dummy_impl; |
| 1973 scoped_refptr<LayerAnimationController> controller_impl( | 1946 scoped_refptr<LayerAnimationController> controller_impl( |
| 1974 LayerAnimationController::Create(0)); | 1947 LayerAnimationController::Create(0)); |
| 1975 controller_impl->AddValueObserver(&dummy_impl); | 1948 controller_impl->AddValueObserver(&dummy_impl); |
| 1976 | 1949 |
| 1977 // Add two animations with the same group id. | 1950 // Add two animations with the same group id. |
| 1978 scoped_ptr<Animation> first_animation(CreateAnimation( | 1951 scoped_ptr<Animation> first_animation(CreateAnimation( |
| 1979 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, | 1952 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, |
| 1980 Animation::TRANSFORM)); | 1953 Animation::TRANSFORM)); |
| 1981 first_animation->set_is_controlling_instance_for_test(true); | 1954 first_animation->set_is_controlling_instance_for_test(true); |
| 1982 controller_impl->AddAnimation(std::move(first_animation)); | 1955 controller_impl->AddAnimation(std::move(first_animation)); |
| 1983 | 1956 |
| 1984 scoped_ptr<Animation> second_animation(CreateAnimation( | 1957 scoped_ptr<Animation> second_animation(CreateAnimation( |
| 1985 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 1958 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| 1986 Animation::OPACITY)); | 1959 Animation::OPACITY)); |
| 1987 second_animation->set_is_controlling_instance_for_test(true); | 1960 second_animation->set_is_controlling_instance_for_test(true); |
| 1988 controller_impl->AddAnimation(std::move(second_animation)); | 1961 controller_impl->AddAnimation(std::move(second_animation)); |
| 1989 | 1962 |
| 1990 controller_impl->Animate(kInitialTickTime); | 1963 controller_impl->Animate(kInitialTickTime); |
| 1991 controller_impl->UpdateState(true, events.get()); | 1964 controller_impl->UpdateState(true, events.get()); |
| 1992 | 1965 |
| 1993 // Both animations should have started. | 1966 // Both animations should have started. |
| 1994 EXPECT_EQ(2u, events->size()); | 1967 EXPECT_EQ(2u, events->events_.size()); |
| 1995 EXPECT_EQ(AnimationEvent::STARTED, (*events)[0].type); | 1968 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); |
| 1996 EXPECT_EQ(AnimationEvent::STARTED, (*events)[1].type); | 1969 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); |
| 1997 | 1970 |
| 1998 controller_impl->AbortAnimations(Animation::OPACITY); | 1971 controller_impl->AbortAnimations(Animation::OPACITY); |
| 1999 | 1972 |
| 2000 events.reset(new AnimationEventsVector); | 1973 events.reset(new AnimationEvents); |
| 2001 controller_impl->Animate(kInitialTickTime + | 1974 controller_impl->Animate(kInitialTickTime + |
| 2002 TimeDelta::FromMilliseconds(1000)); | 1975 TimeDelta::FromMilliseconds(1000)); |
| 2003 controller_impl->UpdateState(true, events.get()); | 1976 controller_impl->UpdateState(true, events.get()); |
| 2004 | 1977 |
| 2005 // We should have exactly 2 events: a FINISHED event for the tranform | 1978 // We should have exactly 2 events: a FINISHED event for the tranform |
| 2006 // animation, and an ABORTED event for the opacity animation. | 1979 // animation, and an ABORTED event for the opacity animation. |
| 2007 EXPECT_EQ(2u, events->size()); | 1980 EXPECT_EQ(2u, events->events_.size()); |
| 2008 EXPECT_EQ(AnimationEvent::FINISHED, (*events)[0].type); | 1981 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); |
| 2009 EXPECT_EQ(Animation::TRANSFORM, (*events)[0].target_property); | 1982 EXPECT_EQ(Animation::TRANSFORM, events->events_[0].target_property); |
| 2010 EXPECT_EQ(AnimationEvent::ABORTED, (*events)[1].type); | 1983 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[1].type); |
| 2011 EXPECT_EQ(Animation::OPACITY, (*events)[1].target_property); | 1984 EXPECT_EQ(Animation::OPACITY, events->events_[1].target_property); |
| 2012 } | 1985 } |
| 2013 | 1986 |
| 2014 TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) { | 1987 TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) { |
| 2015 scoped_refptr<LayerAnimationController> controller_impl( | 1988 scoped_refptr<LayerAnimationController> controller_impl( |
| 2016 LayerAnimationController::Create(0)); | 1989 LayerAnimationController::Create(0)); |
| 2017 | 1990 |
| 2018 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); | 1991 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); |
| 2019 | 1992 |
| 2020 controller_impl->AddAnimation(CreateAnimation( | 1993 controller_impl->AddAnimation(CreateAnimation( |
| 2021 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, | 1994 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1, |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2446 animation->set_direction(Animation::DIRECTION_REVERSE); | 2419 animation->set_direction(Animation::DIRECTION_REVERSE); |
| 2447 EXPECT_TRUE(controller_impl->MaximumTargetScale( | 2420 EXPECT_TRUE(controller_impl->MaximumTargetScale( |
| 2448 LayerAnimationController::ObserverType::PENDING, &max_scale)); | 2421 LayerAnimationController::ObserverType::PENDING, &max_scale)); |
| 2449 EXPECT_EQ(6.f, max_scale); | 2422 EXPECT_EQ(6.f, max_scale); |
| 2450 EXPECT_TRUE(controller_impl->MaximumTargetScale( | 2423 EXPECT_TRUE(controller_impl->MaximumTargetScale( |
| 2451 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | 2424 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); |
| 2452 EXPECT_EQ(6.f, max_scale); | 2425 EXPECT_EQ(6.f, max_scale); |
| 2453 } | 2426 } |
| 2454 | 2427 |
| 2455 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { | 2428 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { |
| 2456 scoped_ptr<AnimationEventsVector> events( | 2429 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 2457 make_scoped_ptr(new AnimationEventsVector)); | |
| 2458 FakeLayerAnimationValueObserver dummy_impl; | 2430 FakeLayerAnimationValueObserver dummy_impl; |
| 2459 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | 2431 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; |
| 2460 scoped_refptr<LayerAnimationController> controller_impl( | 2432 scoped_refptr<LayerAnimationController> controller_impl( |
| 2461 LayerAnimationController::Create(0)); | 2433 LayerAnimationController::Create(0)); |
| 2462 controller_impl->AddValueObserver(&dummy_impl); | 2434 controller_impl->AddValueObserver(&dummy_impl); |
| 2463 controller_impl->AddValueObserver(&pending_dummy_impl); | 2435 controller_impl->AddValueObserver(&pending_dummy_impl); |
| 2464 FakeLayerAnimationValueObserver dummy; | 2436 FakeLayerAnimationValueObserver dummy; |
| 2465 scoped_refptr<LayerAnimationController> controller( | 2437 scoped_refptr<LayerAnimationController> controller( |
| 2466 LayerAnimationController::Create(0)); | 2438 LayerAnimationController::Create(0)); |
| 2467 controller->AddValueObserver(&dummy); | 2439 controller->AddValueObserver(&dummy); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2509 | 2481 |
| 2510 // Since the animation has been activated, it should have reached the | 2482 // Since the animation has been activated, it should have reached the |
| 2511 // RUNNING state and the active observer should start to get ticked. | 2483 // RUNNING state and the active observer should start to get ticked. |
| 2512 EXPECT_EQ(Animation::RUNNING, | 2484 EXPECT_EQ(Animation::RUNNING, |
| 2513 controller_impl->GetAnimationById(animation_id)->run_state()); | 2485 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2514 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2486 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); |
| 2515 EXPECT_EQ(0.5f, dummy_impl.opacity()); | 2487 EXPECT_EQ(0.5f, dummy_impl.opacity()); |
| 2516 } | 2488 } |
| 2517 | 2489 |
| 2518 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { | 2490 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { |
| 2519 scoped_ptr<AnimationEventsVector> events( | 2491 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 2520 make_scoped_ptr(new AnimationEventsVector)); | |
| 2521 FakeLayerAnimationValueObserver dummy_impl; | 2492 FakeLayerAnimationValueObserver dummy_impl; |
| 2522 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | 2493 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; |
| 2523 scoped_refptr<LayerAnimationController> controller_impl( | 2494 scoped_refptr<LayerAnimationController> controller_impl( |
| 2524 LayerAnimationController::Create(0)); | 2495 LayerAnimationController::Create(0)); |
| 2525 controller_impl->AddValueObserver(&dummy_impl); | 2496 controller_impl->AddValueObserver(&dummy_impl); |
| 2526 controller_impl->AddValueObserver(&pending_dummy_impl); | 2497 controller_impl->AddValueObserver(&pending_dummy_impl); |
| 2527 FakeLayerAnimationValueObserver dummy; | 2498 FakeLayerAnimationValueObserver dummy; |
| 2528 scoped_refptr<LayerAnimationController> controller( | 2499 scoped_refptr<LayerAnimationController> controller( |
| 2529 LayerAnimationController::Create(0)); | 2500 LayerAnimationController::Create(0)); |
| 2530 controller->AddValueObserver(&dummy); | 2501 controller->AddValueObserver(&dummy); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2564 | 2535 |
| 2565 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2536 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 2566 | 2537 |
| 2567 // Both observers should have been ticked. | 2538 // Both observers should have been ticked. |
| 2568 EXPECT_EQ(0.75f, pending_dummy_impl.opacity()); | 2539 EXPECT_EQ(0.75f, pending_dummy_impl.opacity()); |
| 2569 EXPECT_EQ(0.75f, dummy_impl.opacity()); | 2540 EXPECT_EQ(0.75f, dummy_impl.opacity()); |
| 2570 } | 2541 } |
| 2571 | 2542 |
| 2572 TEST(LayerAnimationControllerTest, | 2543 TEST(LayerAnimationControllerTest, |
| 2573 ObserverNotifiedWhenTransformIsPotentiallyAnimatingChanges) { | 2544 ObserverNotifiedWhenTransformIsPotentiallyAnimatingChanges) { |
| 2574 AnimationEventsVector events; | 2545 AnimationEvents events; |
| 2575 FakeLayerAnimationValueObserver active_dummy_impl; | 2546 FakeLayerAnimationValueObserver active_dummy_impl; |
| 2576 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | 2547 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; |
| 2577 scoped_refptr<LayerAnimationController> controller_impl( | 2548 scoped_refptr<LayerAnimationController> controller_impl( |
| 2578 LayerAnimationController::Create(0)); | 2549 LayerAnimationController::Create(0)); |
| 2579 controller_impl->AddValueObserver(&active_dummy_impl); | 2550 controller_impl->AddValueObserver(&active_dummy_impl); |
| 2580 controller_impl->AddValueObserver(&pending_dummy_impl); | 2551 controller_impl->AddValueObserver(&pending_dummy_impl); |
| 2581 FakeLayerAnimationValueObserver dummy; | 2552 FakeLayerAnimationValueObserver dummy; |
| 2582 scoped_refptr<LayerAnimationController> controller( | 2553 scoped_refptr<LayerAnimationController> controller( |
| 2583 LayerAnimationController::Create(0)); | 2554 LayerAnimationController::Create(0)); |
| 2584 controller->AddValueObserver(&dummy); | 2555 controller->AddValueObserver(&dummy); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2595 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2566 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); |
| 2596 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2567 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); |
| 2597 | 2568 |
| 2598 controller_impl->ActivateAnimations(); | 2569 controller_impl->ActivateAnimations(); |
| 2599 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2570 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); |
| 2600 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2571 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); |
| 2601 | 2572 |
| 2602 controller_impl->Animate(kInitialTickTime); | 2573 controller_impl->Animate(kInitialTickTime); |
| 2603 controller_impl->UpdateState(true, &events); | 2574 controller_impl->UpdateState(true, &events); |
| 2604 | 2575 |
| 2605 controller->NotifyAnimationStarted(events[0]); | 2576 controller->NotifyAnimationStarted(events.events_[0]); |
| 2606 events.clear(); | 2577 events.events_.clear(); |
| 2607 | 2578 |
| 2608 // Finish the animation. | 2579 // Finish the animation. |
| 2609 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2580 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 2610 controller->UpdateState(true, nullptr); | 2581 controller->UpdateState(true, nullptr); |
| 2611 EXPECT_FALSE(dummy.transform_is_animating()); | 2582 EXPECT_FALSE(dummy.transform_is_animating()); |
| 2612 | 2583 |
| 2613 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2584 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2614 | 2585 |
| 2615 // controller_impl hasn't yet ticked at/past the end of the animation. | 2586 // controller_impl hasn't yet ticked at/past the end of the animation. |
| 2616 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2587 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); |
| 2617 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2588 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); |
| 2618 | 2589 |
| 2619 controller_impl->Animate(kInitialTickTime + | 2590 controller_impl->Animate(kInitialTickTime + |
| 2620 TimeDelta::FromMilliseconds(1000)); | 2591 TimeDelta::FromMilliseconds(1000)); |
| 2621 controller_impl->UpdateState(true, &events); | 2592 controller_impl->UpdateState(true, &events); |
| 2622 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2593 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); |
| 2623 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2594 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); |
| 2624 | 2595 |
| 2625 controller->NotifyAnimationFinished(events[0]); | 2596 controller->NotifyAnimationFinished(events.events_[0]); |
| 2626 events.clear(); | 2597 events.events_.clear(); |
| 2627 | 2598 |
| 2628 // Case 2: An animation that's removed before it finishes. | 2599 // Case 2: An animation that's removed before it finishes. |
| 2629 int animation_id = | 2600 int animation_id = |
| 2630 AddAnimatedTransformToController(controller.get(), 10.0, 2, 2); | 2601 AddAnimatedTransformToController(controller.get(), 10.0, 2, 2); |
| 2631 EXPECT_TRUE(dummy.transform_is_animating()); | 2602 EXPECT_TRUE(dummy.transform_is_animating()); |
| 2632 | 2603 |
| 2633 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2604 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2634 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2605 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); |
| 2635 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2606 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); |
| 2636 | 2607 |
| 2637 controller_impl->ActivateAnimations(); | 2608 controller_impl->ActivateAnimations(); |
| 2638 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2609 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); |
| 2639 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2610 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); |
| 2640 | 2611 |
| 2641 controller_impl->Animate(kInitialTickTime + | 2612 controller_impl->Animate(kInitialTickTime + |
| 2642 TimeDelta::FromMilliseconds(2000)); | 2613 TimeDelta::FromMilliseconds(2000)); |
| 2643 controller_impl->UpdateState(true, &events); | 2614 controller_impl->UpdateState(true, &events); |
| 2644 | 2615 |
| 2645 controller->NotifyAnimationStarted(events[0]); | 2616 controller->NotifyAnimationStarted(events.events_[0]); |
| 2646 events.clear(); | 2617 events.events_.clear(); |
| 2647 | 2618 |
| 2648 controller->RemoveAnimation(animation_id); | 2619 controller->RemoveAnimation(animation_id); |
| 2649 EXPECT_FALSE(dummy.transform_is_animating()); | 2620 EXPECT_FALSE(dummy.transform_is_animating()); |
| 2650 | 2621 |
| 2651 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2622 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2652 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2623 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); |
| 2653 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2624 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); |
| 2654 | 2625 |
| 2655 controller_impl->ActivateAnimations(); | 2626 controller_impl->ActivateAnimations(); |
| 2656 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2627 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); |
| 2657 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2628 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); |
| 2658 | 2629 |
| 2659 // Case 3: An animation that's aborted before it finishes. | 2630 // Case 3: An animation that's aborted before it finishes. |
| 2660 animation_id = AddAnimatedTransformToController(controller.get(), 10.0, 3, 3); | 2631 animation_id = AddAnimatedTransformToController(controller.get(), 10.0, 3, 3); |
| 2661 EXPECT_TRUE(dummy.transform_is_animating()); | 2632 EXPECT_TRUE(dummy.transform_is_animating()); |
| 2662 | 2633 |
| 2663 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2634 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2664 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2635 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); |
| 2665 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2636 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); |
| 2666 | 2637 |
| 2667 controller_impl->ActivateAnimations(); | 2638 controller_impl->ActivateAnimations(); |
| 2668 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2639 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); |
| 2669 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2640 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); |
| 2670 | 2641 |
| 2671 controller_impl->Animate(kInitialTickTime + | 2642 controller_impl->Animate(kInitialTickTime + |
| 2672 TimeDelta::FromMilliseconds(3000)); | 2643 TimeDelta::FromMilliseconds(3000)); |
| 2673 controller_impl->UpdateState(true, &events); | 2644 controller_impl->UpdateState(true, &events); |
| 2674 | 2645 |
| 2675 controller->NotifyAnimationStarted(events[0]); | 2646 controller->NotifyAnimationStarted(events.events_[0]); |
| 2676 events.clear(); | 2647 events.events_.clear(); |
| 2677 | 2648 |
| 2678 controller_impl->AbortAnimations(Animation::TRANSFORM); | 2649 controller_impl->AbortAnimations(Animation::TRANSFORM); |
| 2679 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2650 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); |
| 2680 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2651 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); |
| 2681 | 2652 |
| 2682 controller_impl->Animate(kInitialTickTime + | 2653 controller_impl->Animate(kInitialTickTime + |
| 2683 TimeDelta::FromMilliseconds(4000)); | 2654 TimeDelta::FromMilliseconds(4000)); |
| 2684 controller_impl->UpdateState(true, &events); | 2655 controller_impl->UpdateState(true, &events); |
| 2685 | 2656 |
| 2686 controller->NotifyAnimationAborted(events[0]); | 2657 controller->NotifyAnimationAborted(events.events_[0]); |
| 2687 EXPECT_FALSE(dummy.transform_is_animating()); | 2658 EXPECT_FALSE(dummy.transform_is_animating()); |
| 2688 } | 2659 } |
| 2689 | 2660 |
| 2690 TEST(LayerAnimationControllerTest, ClippedOpacityValues) { | 2661 TEST(LayerAnimationControllerTest, ClippedOpacityValues) { |
| 2691 FakeLayerAnimationValueObserver dummy; | 2662 FakeLayerAnimationValueObserver dummy; |
| 2692 scoped_refptr<LayerAnimationController> controller( | 2663 scoped_refptr<LayerAnimationController> controller( |
| 2693 LayerAnimationController::Create(0)); | 2664 LayerAnimationController::Create(0)); |
| 2694 controller->AddValueObserver(&dummy); | 2665 controller->AddValueObserver(&dummy); |
| 2695 | 2666 |
| 2696 AddOpacityTransitionToController(controller.get(), 1, 1.f, 2.f, true); | 2667 AddOpacityTransitionToController(controller.get(), 1, 1.f, 2.f, true); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2713 | 2684 |
| 2714 controller->Animate(kInitialTickTime); | 2685 controller->Animate(kInitialTickTime); |
| 2715 EXPECT_EQ(0.f, dummy.opacity()); | 2686 EXPECT_EQ(0.f, dummy.opacity()); |
| 2716 | 2687 |
| 2717 // Opacity values are clipped [0,1] | 2688 // Opacity values are clipped [0,1] |
| 2718 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2689 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 2719 EXPECT_EQ(0.f, dummy.opacity()); | 2690 EXPECT_EQ(0.f, dummy.opacity()); |
| 2720 } | 2691 } |
| 2721 | 2692 |
| 2722 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) { | 2693 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) { |
| 2723 scoped_ptr<AnimationEventsVector> events( | 2694 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 2724 make_scoped_ptr(new AnimationEventsVector)); | |
| 2725 FakeLayerAnimationValueObserver dummy_impl; | 2695 FakeLayerAnimationValueObserver dummy_impl; |
| 2726 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | 2696 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; |
| 2727 scoped_refptr<LayerAnimationController> controller_impl( | 2697 scoped_refptr<LayerAnimationController> controller_impl( |
| 2728 LayerAnimationController::Create(0)); | 2698 LayerAnimationController::Create(0)); |
| 2729 controller_impl->AddValueObserver(&dummy_impl); | 2699 controller_impl->AddValueObserver(&dummy_impl); |
| 2730 controller_impl->AddValueObserver(&pending_dummy_impl); | 2700 controller_impl->AddValueObserver(&pending_dummy_impl); |
| 2731 FakeLayerAnimationValueObserver dummy; | 2701 FakeLayerAnimationValueObserver dummy; |
| 2732 scoped_refptr<LayerAnimationController> controller( | 2702 scoped_refptr<LayerAnimationController> controller( |
| 2733 LayerAnimationController::Create(0)); | 2703 LayerAnimationController::Create(0)); |
| 2734 controller->AddValueObserver(&dummy); | 2704 controller->AddValueObserver(&dummy); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2770 | 2740 |
| 2771 controller_impl->ActivateAnimations(); | 2741 controller_impl->ActivateAnimations(); |
| 2772 | 2742 |
| 2773 // Activation should cause the animation to be deleted. | 2743 // Activation should cause the animation to be deleted. |
| 2774 EXPECT_FALSE(controller_impl->has_any_animation()); | 2744 EXPECT_FALSE(controller_impl->has_any_animation()); |
| 2775 } | 2745 } |
| 2776 | 2746 |
| 2777 // Tests that an animation that affects only active observers won't block | 2747 // Tests that an animation that affects only active observers won't block |
| 2778 // an animation that affects only pending observers from starting. | 2748 // an animation that affects only pending observers from starting. |
| 2779 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) { | 2749 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) { |
| 2780 scoped_ptr<AnimationEventsVector> events( | 2750 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 2781 make_scoped_ptr(new AnimationEventsVector)); | |
| 2782 FakeLayerAnimationValueObserver dummy_impl; | 2751 FakeLayerAnimationValueObserver dummy_impl; |
| 2783 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | 2752 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; |
| 2784 scoped_refptr<LayerAnimationController> controller_impl( | 2753 scoped_refptr<LayerAnimationController> controller_impl( |
| 2785 LayerAnimationController::Create(0)); | 2754 LayerAnimationController::Create(0)); |
| 2786 controller_impl->AddValueObserver(&dummy_impl); | 2755 controller_impl->AddValueObserver(&dummy_impl); |
| 2787 controller_impl->AddValueObserver(&pending_dummy_impl); | 2756 controller_impl->AddValueObserver(&pending_dummy_impl); |
| 2788 FakeLayerAnimationValueObserver dummy; | 2757 FakeLayerAnimationValueObserver dummy; |
| 2789 scoped_refptr<LayerAnimationController> controller( | 2758 scoped_refptr<LayerAnimationController> controller( |
| 2790 LayerAnimationController::Create(0)); | 2759 LayerAnimationController::Create(0)); |
| 2791 controller->AddValueObserver(&dummy); | 2760 controller->AddValueObserver(&dummy); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3003 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty( | 2972 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty( |
| 3004 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 2973 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3005 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 2974 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3006 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING)); | 2975 Animation::OPACITY, LayerAnimationController::ObserverType::PENDING)); |
| 3007 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 2976 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3008 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 2977 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3009 } | 2978 } |
| 3010 | 2979 |
| 3011 } // namespace | 2980 } // namespace |
| 3012 } // namespace cc | 2981 } // namespace cc |
| OLD | NEW |