| 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 "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "cc/animation/animation.h" | 10 #include "cc/animation/animation.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 std::unique_ptr<AnimationCurve> curve, | 41 std::unique_ptr<AnimationCurve> curve, |
| 42 int group_id, | 42 int group_id, |
| 43 TargetProperty::Type property) { | 43 TargetProperty::Type property) { |
| 44 return Animation::Create(std::move(curve), 0, group_id, property); | 44 return Animation::Create(std::move(curve), 0, group_id, property); |
| 45 } | 45 } |
| 46 | 46 |
| 47 TEST(LayerAnimationControllerTest, SyncNewAnimation) { | 47 TEST(LayerAnimationControllerTest, SyncNewAnimation) { |
| 48 FakeLayerAnimationValueObserver dummy_impl; | 48 FakeLayerAnimationValueObserver dummy_impl; |
| 49 scoped_refptr<LayerAnimationController> controller_impl( | 49 scoped_refptr<LayerAnimationController> controller_impl( |
| 50 LayerAnimationController::Create(0)); | 50 LayerAnimationController::Create(0)); |
| 51 controller_impl->AddValueObserver(&dummy_impl); | 51 controller_impl->SetValueObserver(&dummy_impl); |
| 52 controller_impl->SetNeedsActiveValueObservations(true); |
| 53 |
| 52 FakeLayerAnimationValueObserver dummy; | 54 FakeLayerAnimationValueObserver dummy; |
| 53 scoped_refptr<LayerAnimationController> controller( | 55 scoped_refptr<LayerAnimationController> controller( |
| 54 LayerAnimationController::Create(0)); | 56 LayerAnimationController::Create(0)); |
| 55 controller->AddValueObserver(&dummy); | 57 controller->SetValueObserver(&dummy); |
| 58 controller_impl->SetNeedsActiveValueObservations(true); |
| 56 | 59 |
| 57 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); | 60 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); |
| 58 | 61 |
| 59 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 62 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 60 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | 63 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); |
| 61 | 64 |
| 62 int animation_id = | 65 int animation_id = |
| 63 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 66 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 64 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 67 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 65 | 68 |
| 66 controller->PushAnimationUpdatesTo(controller_impl.get()); | 69 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 67 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); | 70 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); |
| 68 controller_impl->ActivateAnimations(); | 71 controller_impl->ActivateAnimations(); |
| 69 | 72 |
| 70 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 73 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 71 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 74 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 72 controller_impl->GetAnimationById(animation_id)->run_state()); | 75 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 73 } | 76 } |
| 74 | 77 |
| 75 TEST(LayerAnimationControllerTest, | 78 TEST(LayerAnimationControllerTest, |
| 76 SyncScrollOffsetAnimationRespectsHasSetInitialValue) { | 79 SyncScrollOffsetAnimationRespectsHasSetInitialValue) { |
| 77 FakeLayerAnimationValueObserver dummy_impl; | 80 FakeLayerAnimationValueObserver dummy_impl; |
| 78 FakeLayerAnimationValueProvider dummy_provider_impl; | 81 FakeLayerAnimationValueProvider dummy_provider_impl; |
| 79 scoped_refptr<LayerAnimationController> controller_impl( | 82 scoped_refptr<LayerAnimationController> controller_impl( |
| 80 LayerAnimationController::Create(0)); | 83 LayerAnimationController::Create(0)); |
| 81 controller_impl->AddValueObserver(&dummy_impl); | 84 controller_impl->SetValueObserver(&dummy_impl); |
| 85 controller_impl->SetNeedsActiveValueObservations(true); |
| 82 controller_impl->set_value_provider(&dummy_provider_impl); | 86 controller_impl->set_value_provider(&dummy_provider_impl); |
| 87 |
| 83 FakeLayerAnimationValueObserver dummy; | 88 FakeLayerAnimationValueObserver dummy; |
| 84 FakeLayerAnimationValueProvider dummy_provider; | 89 FakeLayerAnimationValueProvider dummy_provider; |
| 85 scoped_refptr<LayerAnimationController> controller( | 90 scoped_refptr<LayerAnimationController> controller( |
| 86 LayerAnimationController::Create(0)); | 91 LayerAnimationController::Create(0)); |
| 87 controller->AddValueObserver(&dummy); | 92 controller->SetValueObserver(&dummy); |
| 93 controller->SetNeedsActiveValueObservations(true); |
| 88 controller->set_value_provider(&dummy_provider); | 94 controller->set_value_provider(&dummy_provider); |
| 89 | 95 |
| 90 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); | 96 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); |
| 91 | 97 |
| 92 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 98 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 93 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | 99 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); |
| 94 | 100 |
| 95 gfx::ScrollOffset initial_value(100.f, 300.f); | 101 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 96 gfx::ScrollOffset provider_initial_value(150.f, 300.f); | 102 gfx::ScrollOffset provider_initial_value(150.f, 300.f); |
| 97 gfx::ScrollOffset target_value(300.f, 200.f); | 103 gfx::ScrollOffset target_value(300.f, 200.f); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 128 ->ToScrollOffsetAnimationCurve() | 134 ->ToScrollOffsetAnimationCurve() |
| 129 ->GetValue(base::TimeDelta())); | 135 ->GetValue(base::TimeDelta())); |
| 130 } | 136 } |
| 131 | 137 |
| 132 // If an animation is started on the impl thread before it is ticked on the main | 138 // If an animation is started on the impl thread before it is ticked on the main |
| 133 // thread, we must be sure to respect the synchronized start time. | 139 // thread, we must be sure to respect the synchronized start time. |
| 134 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) { | 140 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) { |
| 135 FakeLayerAnimationValueObserver dummy_impl; | 141 FakeLayerAnimationValueObserver dummy_impl; |
| 136 scoped_refptr<LayerAnimationController> controller_impl( | 142 scoped_refptr<LayerAnimationController> controller_impl( |
| 137 LayerAnimationController::Create(0)); | 143 LayerAnimationController::Create(0)); |
| 138 controller_impl->AddValueObserver(&dummy_impl); | 144 controller_impl->SetValueObserver(&dummy_impl); |
| 145 controller_impl->SetNeedsActiveValueObservations(true); |
| 146 |
| 139 FakeLayerAnimationValueObserver dummy; | 147 FakeLayerAnimationValueObserver dummy; |
| 140 scoped_refptr<LayerAnimationController> controller( | 148 scoped_refptr<LayerAnimationController> controller( |
| 141 LayerAnimationController::Create(0)); | 149 LayerAnimationController::Create(0)); |
| 142 controller->AddValueObserver(&dummy); | 150 controller->SetValueObserver(&dummy); |
| 151 controller->SetNeedsActiveValueObservations(true); |
| 143 | 152 |
| 144 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); | 153 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); |
| 145 | 154 |
| 146 int animation_id = | 155 int animation_id = |
| 147 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 156 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 148 | 157 |
| 149 controller->PushAnimationUpdatesTo(controller_impl.get()); | 158 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 150 controller_impl->ActivateAnimations(); | 159 controller_impl->ActivateAnimations(); |
| 151 | 160 |
| 152 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 161 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 167 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 176 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 168 controller->UpdateState(true, nullptr); | 177 controller->UpdateState(true, nullptr); |
| 169 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | 178 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), |
| 170 controller_impl->GetAnimationById(animation_id)->start_time()); | 179 controller_impl->GetAnimationById(animation_id)->start_time()); |
| 171 } | 180 } |
| 172 | 181 |
| 173 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) { | 182 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) { |
| 174 FakeLayerAnimationValueObserver dummy_impl; | 183 FakeLayerAnimationValueObserver dummy_impl; |
| 175 scoped_refptr<LayerAnimationController> controller_impl( | 184 scoped_refptr<LayerAnimationController> controller_impl( |
| 176 LayerAnimationController::Create(0)); | 185 LayerAnimationController::Create(0)); |
| 177 controller_impl->AddValueObserver(&dummy_impl); | 186 controller_impl->SetValueObserver(&dummy_impl); |
| 187 controller_impl->SetNeedsActiveValueObservations(true); |
| 188 |
| 178 FakeLayerAnimationValueObserver dummy; | 189 FakeLayerAnimationValueObserver dummy; |
| 179 scoped_refptr<LayerAnimationController> controller( | 190 scoped_refptr<LayerAnimationController> controller( |
| 180 LayerAnimationController::Create(0)); | 191 LayerAnimationController::Create(0)); |
| 181 controller->AddValueObserver(&dummy); | 192 controller->SetValueObserver(&dummy); |
| 193 controller->SetNeedsActiveValueObservations(true); |
| 182 | 194 |
| 183 int animation_id = | 195 int animation_id = |
| 184 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 196 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 185 | 197 |
| 186 const TimeTicks start_time = TicksFromSecondsF(123); | 198 const TimeTicks start_time = TicksFromSecondsF(123); |
| 187 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); | 199 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); |
| 188 | 200 |
| 189 controller->PushAnimationUpdatesTo(controller_impl.get()); | 201 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 190 controller_impl->ActivateAnimations(); | 202 controller_impl->ActivateAnimations(); |
| 191 | 203 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 218 // Tests that controllers activate and deactivate as expected. | 230 // Tests that controllers activate and deactivate as expected. |
| 219 TEST(LayerAnimationControllerTest, Activation) { | 231 TEST(LayerAnimationControllerTest, Activation) { |
| 220 std::unique_ptr<AnimationHost> host = | 232 std::unique_ptr<AnimationHost> host = |
| 221 AnimationHost::Create(ThreadInstance::MAIN); | 233 AnimationHost::Create(ThreadInstance::MAIN); |
| 222 std::unique_ptr<AnimationHost> host_impl = | 234 std::unique_ptr<AnimationHost> host_impl = |
| 223 AnimationHost::Create(ThreadInstance::IMPL); | 235 AnimationHost::Create(ThreadInstance::IMPL); |
| 224 | 236 |
| 225 FakeLayerAnimationValueObserver dummy_impl; | 237 FakeLayerAnimationValueObserver dummy_impl; |
| 226 scoped_refptr<LayerAnimationController> controller_impl( | 238 scoped_refptr<LayerAnimationController> controller_impl( |
| 227 LayerAnimationController::Create(0)); | 239 LayerAnimationController::Create(0)); |
| 228 controller_impl->AddValueObserver(&dummy_impl); | 240 controller_impl->SetValueObserver(&dummy_impl); |
| 241 controller_impl->SetNeedsActiveValueObservations(true); |
| 242 |
| 229 FakeLayerAnimationValueObserver dummy; | 243 FakeLayerAnimationValueObserver dummy; |
| 230 scoped_refptr<LayerAnimationController> controller( | 244 scoped_refptr<LayerAnimationController> controller( |
| 231 LayerAnimationController::Create(0)); | 245 LayerAnimationController::Create(0)); |
| 232 controller->AddValueObserver(&dummy); | 246 controller->SetValueObserver(&dummy); |
| 247 controller->SetNeedsActiveValueObservations(true); |
| 248 |
| 233 std::unique_ptr<AnimationEvents> events = host->CreateEvents(); | 249 std::unique_ptr<AnimationEvents> events = host->CreateEvents(); |
| 234 | 250 |
| 235 controller->SetAnimationHost(host.get()); | 251 controller->SetAnimationHost(host.get()); |
| 236 controller_impl->SetAnimationHost(host_impl.get()); | 252 controller_impl->SetAnimationHost(host_impl.get()); |
| 237 EXPECT_EQ(1u, host->all_animation_controllers_for_testing().size()); | 253 EXPECT_EQ(1u, host->all_animation_controllers_for_testing().size()); |
| 238 EXPECT_EQ(1u, host_impl->all_animation_controllers_for_testing().size()); | 254 EXPECT_EQ(1u, host_impl->all_animation_controllers_for_testing().size()); |
| 239 | 255 |
| 240 // Initially, both controllers should be inactive. | 256 // Initially, both controllers should be inactive. |
| 241 EXPECT_EQ(0u, host->active_animation_controllers_for_testing().size()); | 257 EXPECT_EQ(0u, host->active_animation_controllers_for_testing().size()); |
| 242 EXPECT_EQ(0u, host_impl->active_animation_controllers_for_testing().size()); | 258 EXPECT_EQ(0u, host_impl->active_animation_controllers_for_testing().size()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 EXPECT_EQ(0u, host_impl->active_animation_controllers_for_testing().size()); | 314 EXPECT_EQ(0u, host_impl->active_animation_controllers_for_testing().size()); |
| 299 | 315 |
| 300 controller->SetAnimationHost(nullptr); | 316 controller->SetAnimationHost(nullptr); |
| 301 controller_impl->SetAnimationHost(nullptr); | 317 controller_impl->SetAnimationHost(nullptr); |
| 302 } | 318 } |
| 303 | 319 |
| 304 TEST(LayerAnimationControllerTest, SyncPause) { | 320 TEST(LayerAnimationControllerTest, SyncPause) { |
| 305 FakeLayerAnimationValueObserver dummy_impl; | 321 FakeLayerAnimationValueObserver dummy_impl; |
| 306 scoped_refptr<LayerAnimationController> controller_impl( | 322 scoped_refptr<LayerAnimationController> controller_impl( |
| 307 LayerAnimationController::Create(0)); | 323 LayerAnimationController::Create(0)); |
| 308 controller_impl->AddValueObserver(&dummy_impl); | 324 controller_impl->SetValueObserver(&dummy_impl); |
| 325 controller_impl->SetNeedsActiveValueObservations(true); |
| 326 |
| 309 FakeLayerAnimationValueObserver dummy; | 327 FakeLayerAnimationValueObserver dummy; |
| 310 scoped_refptr<LayerAnimationController> controller( | 328 scoped_refptr<LayerAnimationController> controller( |
| 311 LayerAnimationController::Create(0)); | 329 LayerAnimationController::Create(0)); |
| 312 controller->AddValueObserver(&dummy); | 330 controller->SetValueObserver(&dummy); |
| 331 controller->SetNeedsActiveValueObservations(true); |
| 313 | 332 |
| 314 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); | 333 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); |
| 315 | 334 |
| 316 // Two steps, three ranges: [0-1) -> 0.2, [1-2) -> 0.3, [2-3] -> 0.4. | 335 // Two steps, three ranges: [0-1) -> 0.2, [1-2) -> 0.3, [2-3] -> 0.4. |
| 317 const double duration = 3.0; | 336 const double duration = 3.0; |
| 318 const int animation_id = | 337 const int animation_id = |
| 319 AddOpacityStepsToController(controller.get(), duration, 0.2f, 0.4f, 2); | 338 AddOpacityStepsToController(controller.get(), duration, 0.2f, 0.4f, 2); |
| 320 | 339 |
| 321 // Set start offset to be at the beginning of the second range. | 340 // Set start offset to be at the beginning of the second range. |
| 322 controller->GetAnimationById(animation_id) | 341 controller->GetAnimationById(animation_id) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 393 |
| 375 // Opacity value doesn't depend on time if paused at specified time offset. | 394 // Opacity value doesn't depend on time if paused at specified time offset. |
| 376 EXPECT_EQ(0.4f, dummy.opacity()); | 395 EXPECT_EQ(0.4f, dummy.opacity()); |
| 377 EXPECT_EQ(0.4f, dummy_impl.opacity()); | 396 EXPECT_EQ(0.4f, dummy_impl.opacity()); |
| 378 } | 397 } |
| 379 | 398 |
| 380 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { | 399 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { |
| 381 FakeLayerAnimationValueObserver dummy_impl; | 400 FakeLayerAnimationValueObserver dummy_impl; |
| 382 scoped_refptr<LayerAnimationController> controller_impl( | 401 scoped_refptr<LayerAnimationController> controller_impl( |
| 383 LayerAnimationController::Create(0)); | 402 LayerAnimationController::Create(0)); |
| 384 controller_impl->AddValueObserver(&dummy_impl); | 403 controller_impl->SetValueObserver(&dummy_impl); |
| 404 controller_impl->SetNeedsActiveValueObservations(true); |
| 405 |
| 385 FakeLayerAnimationValueObserver dummy; | 406 FakeLayerAnimationValueObserver dummy; |
| 386 scoped_refptr<LayerAnimationController> controller( | 407 scoped_refptr<LayerAnimationController> controller( |
| 387 LayerAnimationController::Create(0)); | 408 LayerAnimationController::Create(0)); |
| 388 controller->AddValueObserver(&dummy); | 409 controller->SetValueObserver(&dummy); |
| 410 controller->SetNeedsActiveValueObservations(true); |
| 411 |
| 389 std::unique_ptr<AnimationEvents> events( | 412 std::unique_ptr<AnimationEvents> events( |
| 390 base::WrapUnique(new AnimationEvents)); | 413 base::WrapUnique(new AnimationEvents)); |
| 391 | 414 |
| 392 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); | 415 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); |
| 393 | 416 |
| 394 int animation_id = | 417 int animation_id = |
| 395 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 418 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 396 | 419 |
| 397 controller->PushAnimationUpdatesTo(controller_impl.get()); | 420 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 398 controller_impl->ActivateAnimations(); | 421 controller_impl->ActivateAnimations(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 // main-thread and the impl-thread controllers. | 455 // main-thread and the impl-thread controllers. |
| 433 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) { | 456 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) { |
| 434 FakeLayerAnimationValueObserver dummy; | 457 FakeLayerAnimationValueObserver dummy; |
| 435 FakeLayerAnimationValueObserver dummy_impl; | 458 FakeLayerAnimationValueObserver dummy_impl; |
| 436 std::unique_ptr<AnimationEvents> events( | 459 std::unique_ptr<AnimationEvents> events( |
| 437 base::WrapUnique(new AnimationEvents)); | 460 base::WrapUnique(new AnimationEvents)); |
| 438 scoped_refptr<LayerAnimationController> controller( | 461 scoped_refptr<LayerAnimationController> controller( |
| 439 LayerAnimationController::Create(0)); | 462 LayerAnimationController::Create(0)); |
| 440 scoped_refptr<LayerAnimationController> controller_impl( | 463 scoped_refptr<LayerAnimationController> controller_impl( |
| 441 LayerAnimationController::Create(0)); | 464 LayerAnimationController::Create(0)); |
| 442 controller->AddValueObserver(&dummy); | 465 controller->SetValueObserver(&dummy); |
| 443 controller_impl->AddValueObserver(&dummy_impl); | 466 controller->SetNeedsActiveValueObservations(true); |
| 467 controller_impl->SetValueObserver(&dummy_impl); |
| 468 controller_impl->SetNeedsActiveValueObservations(true); |
| 444 | 469 |
| 445 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); | 470 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); |
| 446 controller->Animate(kInitialTickTime); | 471 controller->Animate(kInitialTickTime); |
| 447 controller->UpdateState(true, nullptr); | 472 controller->UpdateState(true, nullptr); |
| 448 controller->PushAnimationUpdatesTo(controller_impl.get()); | 473 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 449 controller_impl->ActivateAnimations(); | 474 controller_impl->ActivateAnimations(); |
| 450 | 475 |
| 451 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 476 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 452 controller_impl->UpdateState(true, events.get()); | 477 controller_impl->UpdateState(true, events.get()); |
| 453 | 478 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 | 529 |
| 505 return event; | 530 return event; |
| 506 } | 531 } |
| 507 | 532 |
| 508 TEST(LayerAnimationControllerTest, TrivialTransition) { | 533 TEST(LayerAnimationControllerTest, TrivialTransition) { |
| 509 std::unique_ptr<AnimationEvents> events( | 534 std::unique_ptr<AnimationEvents> events( |
| 510 base::WrapUnique(new AnimationEvents)); | 535 base::WrapUnique(new AnimationEvents)); |
| 511 FakeLayerAnimationValueObserver dummy; | 536 FakeLayerAnimationValueObserver dummy; |
| 512 scoped_refptr<LayerAnimationController> controller( | 537 scoped_refptr<LayerAnimationController> controller( |
| 513 LayerAnimationController::Create(0)); | 538 LayerAnimationController::Create(0)); |
| 514 controller->AddValueObserver(&dummy); | 539 controller->SetValueObserver(&dummy); |
| 540 controller->SetNeedsActiveValueObservations(true); |
| 515 | 541 |
| 516 std::unique_ptr<Animation> to_add(CreateAnimation( | 542 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 517 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 543 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 518 1, TargetProperty::OPACITY)); | 544 1, TargetProperty::OPACITY)); |
| 519 | 545 |
| 520 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 546 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 521 controller->AddAnimation(std::move(to_add)); | 547 controller->AddAnimation(std::move(to_add)); |
| 522 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 548 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 523 controller->Animate(kInitialTickTime); | 549 controller->Animate(kInitialTickTime); |
| 524 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 550 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 535 event = GetMostRecentPropertyUpdateEvent(events.get()); | 561 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 536 EXPECT_FALSE(event); | 562 EXPECT_FALSE(event); |
| 537 } | 563 } |
| 538 | 564 |
| 539 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { | 565 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { |
| 540 std::unique_ptr<AnimationEvents> events( | 566 std::unique_ptr<AnimationEvents> events( |
| 541 base::WrapUnique(new AnimationEvents)); | 567 base::WrapUnique(new AnimationEvents)); |
| 542 FakeLayerAnimationValueObserver dummy_impl; | 568 FakeLayerAnimationValueObserver dummy_impl; |
| 543 scoped_refptr<LayerAnimationController> controller_impl( | 569 scoped_refptr<LayerAnimationController> controller_impl( |
| 544 LayerAnimationController::Create(0)); | 570 LayerAnimationController::Create(0)); |
| 545 controller_impl->AddValueObserver(&dummy_impl); | 571 controller_impl->SetValueObserver(&dummy_impl); |
| 572 controller_impl->SetNeedsActiveValueObservations(true); |
| 546 | 573 |
| 547 std::unique_ptr<Animation> to_add(CreateAnimation( | 574 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 548 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 575 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 549 1, TargetProperty::OPACITY)); | 576 1, TargetProperty::OPACITY)); |
| 550 to_add->set_is_impl_only(true); | 577 to_add->set_is_impl_only(true); |
| 551 | 578 |
| 552 controller_impl->AddAnimation(std::move(to_add)); | 579 controller_impl->AddAnimation(std::move(to_add)); |
| 553 controller_impl->Animate(kInitialTickTime); | 580 controller_impl->Animate(kInitialTickTime); |
| 554 controller_impl->UpdateState(true, events.get()); | 581 controller_impl->UpdateState(true, events.get()); |
| 555 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 582 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 569 GetMostRecentPropertyUpdateEvent(events.get()); | 596 GetMostRecentPropertyUpdateEvent(events.get()); |
| 570 EXPECT_EQ(1.f, end_opacity_event->opacity); | 597 EXPECT_EQ(1.f, end_opacity_event->opacity); |
| 571 } | 598 } |
| 572 | 599 |
| 573 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { | 600 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { |
| 574 std::unique_ptr<AnimationEvents> events( | 601 std::unique_ptr<AnimationEvents> events( |
| 575 base::WrapUnique(new AnimationEvents)); | 602 base::WrapUnique(new AnimationEvents)); |
| 576 FakeLayerAnimationValueObserver dummy_impl; | 603 FakeLayerAnimationValueObserver dummy_impl; |
| 577 scoped_refptr<LayerAnimationController> controller_impl( | 604 scoped_refptr<LayerAnimationController> controller_impl( |
| 578 LayerAnimationController::Create(0)); | 605 LayerAnimationController::Create(0)); |
| 579 controller_impl->AddValueObserver(&dummy_impl); | 606 controller_impl->SetValueObserver(&dummy_impl); |
| 607 controller_impl->SetNeedsActiveValueObservations(true); |
| 580 | 608 |
| 581 // Choose different values for x and y to avoid coincidental values in the | 609 // Choose different values for x and y to avoid coincidental values in the |
| 582 // observed transforms. | 610 // observed transforms. |
| 583 const float delta_x = 3; | 611 const float delta_x = 3; |
| 584 const float delta_y = 4; | 612 const float delta_y = 4; |
| 585 | 613 |
| 586 std::unique_ptr<KeyframedTransformAnimationCurve> curve( | 614 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 587 KeyframedTransformAnimationCurve::Create()); | 615 KeyframedTransformAnimationCurve::Create()); |
| 588 | 616 |
| 589 // Create simple TRANSFORM animation. | 617 // Create simple TRANSFORM animation. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 EXPECT_EQ(expected_transform, end_transform_event->transform); | 653 EXPECT_EQ(expected_transform, end_transform_event->transform); |
| 626 EXPECT_TRUE(end_transform_event->is_impl_only); | 654 EXPECT_TRUE(end_transform_event->is_impl_only); |
| 627 } | 655 } |
| 628 | 656 |
| 629 TEST(LayerAnimationControllerTest, FilterTransition) { | 657 TEST(LayerAnimationControllerTest, FilterTransition) { |
| 630 std::unique_ptr<AnimationEvents> events( | 658 std::unique_ptr<AnimationEvents> events( |
| 631 base::WrapUnique(new AnimationEvents)); | 659 base::WrapUnique(new AnimationEvents)); |
| 632 FakeLayerAnimationValueObserver dummy; | 660 FakeLayerAnimationValueObserver dummy; |
| 633 scoped_refptr<LayerAnimationController> controller( | 661 scoped_refptr<LayerAnimationController> controller( |
| 634 LayerAnimationController::Create(0)); | 662 LayerAnimationController::Create(0)); |
| 635 controller->AddValueObserver(&dummy); | 663 controller->SetValueObserver(&dummy); |
| 664 controller->SetNeedsActiveValueObservations(true); |
| 636 | 665 |
| 637 std::unique_ptr<KeyframedFilterAnimationCurve> curve( | 666 std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
| 638 KeyframedFilterAnimationCurve::Create()); | 667 KeyframedFilterAnimationCurve::Create()); |
| 639 | 668 |
| 640 FilterOperations start_filters; | 669 FilterOperations start_filters; |
| 641 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); | 670 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); |
| 642 curve->AddKeyframe( | 671 curve->AddKeyframe( |
| 643 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); | 672 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 644 FilterOperations end_filters; | 673 FilterOperations end_filters; |
| 645 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 674 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 673 event = GetMostRecentPropertyUpdateEvent(events.get()); | 702 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 674 EXPECT_FALSE(event); | 703 EXPECT_FALSE(event); |
| 675 } | 704 } |
| 676 | 705 |
| 677 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) { | 706 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) { |
| 678 std::unique_ptr<AnimationEvents> events( | 707 std::unique_ptr<AnimationEvents> events( |
| 679 base::WrapUnique(new AnimationEvents)); | 708 base::WrapUnique(new AnimationEvents)); |
| 680 FakeLayerAnimationValueObserver dummy_impl; | 709 FakeLayerAnimationValueObserver dummy_impl; |
| 681 scoped_refptr<LayerAnimationController> controller_impl( | 710 scoped_refptr<LayerAnimationController> controller_impl( |
| 682 LayerAnimationController::Create(0)); | 711 LayerAnimationController::Create(0)); |
| 683 controller_impl->AddValueObserver(&dummy_impl); | 712 controller_impl->SetValueObserver(&dummy_impl); |
| 713 controller_impl->SetNeedsActiveValueObservations(true); |
| 684 | 714 |
| 685 std::unique_ptr<KeyframedFilterAnimationCurve> curve( | 715 std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
| 686 KeyframedFilterAnimationCurve::Create()); | 716 KeyframedFilterAnimationCurve::Create()); |
| 687 | 717 |
| 688 // Create simple FILTER animation. | 718 // Create simple FILTER animation. |
| 689 FilterOperations start_filters; | 719 FilterOperations start_filters; |
| 690 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); | 720 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); |
| 691 curve->AddKeyframe( | 721 curve->AddKeyframe( |
| 692 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); | 722 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 693 FilterOperations end_filters; | 723 FilterOperations end_filters; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 723 EXPECT_TRUE(end_filter_event); | 753 EXPECT_TRUE(end_filter_event); |
| 724 EXPECT_EQ(end_filters, end_filter_event->filters); | 754 EXPECT_EQ(end_filters, end_filter_event->filters); |
| 725 EXPECT_TRUE(end_filter_event->is_impl_only); | 755 EXPECT_TRUE(end_filter_event->is_impl_only); |
| 726 } | 756 } |
| 727 | 757 |
| 728 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) { | 758 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) { |
| 729 FakeLayerAnimationValueObserver dummy_impl; | 759 FakeLayerAnimationValueObserver dummy_impl; |
| 730 FakeLayerAnimationValueProvider dummy_provider_impl; | 760 FakeLayerAnimationValueProvider dummy_provider_impl; |
| 731 scoped_refptr<LayerAnimationController> controller_impl( | 761 scoped_refptr<LayerAnimationController> controller_impl( |
| 732 LayerAnimationController::Create(0)); | 762 LayerAnimationController::Create(0)); |
| 733 controller_impl->AddValueObserver(&dummy_impl); | 763 controller_impl->SetValueObserver(&dummy_impl); |
| 764 controller_impl->SetNeedsActiveValueObservations(true); |
| 765 |
| 734 controller_impl->set_value_provider(&dummy_provider_impl); | 766 controller_impl->set_value_provider(&dummy_provider_impl); |
| 735 std::unique_ptr<AnimationEvents> events( | 767 std::unique_ptr<AnimationEvents> events( |
| 736 base::WrapUnique(new AnimationEvents)); | 768 base::WrapUnique(new AnimationEvents)); |
| 737 FakeLayerAnimationValueObserver dummy; | 769 FakeLayerAnimationValueObserver dummy; |
| 738 FakeLayerAnimationValueProvider dummy_provider; | 770 FakeLayerAnimationValueProvider dummy_provider; |
| 739 scoped_refptr<LayerAnimationController> controller( | 771 scoped_refptr<LayerAnimationController> controller( |
| 740 LayerAnimationController::Create(0)); | 772 LayerAnimationController::Create(0)); |
| 741 controller->AddValueObserver(&dummy); | 773 controller->SetValueObserver(&dummy); |
| 774 controller->SetNeedsActiveValueObservations(true); |
| 742 controller->set_value_provider(&dummy_provider); | 775 controller->set_value_provider(&dummy_provider); |
| 743 | 776 |
| 744 gfx::ScrollOffset initial_value(100.f, 300.f); | 777 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 745 gfx::ScrollOffset target_value(300.f, 200.f); | 778 gfx::ScrollOffset target_value(300.f, 200.f); |
| 746 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 779 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 747 ScrollOffsetAnimationCurve::Create(target_value, | 780 ScrollOffsetAnimationCurve::Create(target_value, |
| 748 EaseInOutTimingFunction::Create())); | 781 EaseInOutTimingFunction::Create())); |
| 749 | 782 |
| 750 std::unique_ptr<Animation> animation( | 783 std::unique_ptr<Animation> animation( |
| 751 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 784 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 EXPECT_FALSE(controller->HasActiveAnimation()); | 836 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 804 } | 837 } |
| 805 | 838 |
| 806 // Ensure that when the impl controller doesn't have a value provider, | 839 // Ensure that when the impl controller doesn't have a value provider, |
| 807 // the main-thread controller's value provider is used to obtain the intial | 840 // the main-thread controller's value provider is used to obtain the intial |
| 808 // scroll offset. | 841 // scroll offset. |
| 809 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { | 842 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { |
| 810 FakeLayerAnimationValueObserver dummy_impl; | 843 FakeLayerAnimationValueObserver dummy_impl; |
| 811 scoped_refptr<LayerAnimationController> controller_impl( | 844 scoped_refptr<LayerAnimationController> controller_impl( |
| 812 LayerAnimationController::Create(0)); | 845 LayerAnimationController::Create(0)); |
| 813 controller_impl->AddValueObserver(&dummy_impl); | 846 controller_impl->SetValueObserver(&dummy_impl); |
| 847 controller_impl->SetNeedsActiveValueObservations(true); |
| 848 |
| 814 std::unique_ptr<AnimationEvents> events( | 849 std::unique_ptr<AnimationEvents> events( |
| 815 base::WrapUnique(new AnimationEvents)); | 850 base::WrapUnique(new AnimationEvents)); |
| 816 FakeLayerAnimationValueObserver dummy; | 851 FakeLayerAnimationValueObserver dummy; |
| 817 FakeLayerAnimationValueProvider dummy_provider; | 852 FakeLayerAnimationValueProvider dummy_provider; |
| 818 scoped_refptr<LayerAnimationController> controller( | 853 scoped_refptr<LayerAnimationController> controller( |
| 819 LayerAnimationController::Create(0)); | 854 LayerAnimationController::Create(0)); |
| 820 controller->AddValueObserver(&dummy); | 855 controller->SetValueObserver(&dummy); |
| 856 controller->SetNeedsActiveValueObservations(true); |
| 821 controller->set_value_provider(&dummy_provider); | 857 controller->set_value_provider(&dummy_provider); |
| 822 | 858 |
| 823 gfx::ScrollOffset initial_value(500.f, 100.f); | 859 gfx::ScrollOffset initial_value(500.f, 100.f); |
| 824 gfx::ScrollOffset target_value(300.f, 200.f); | 860 gfx::ScrollOffset target_value(300.f, 200.f); |
| 825 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 861 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 826 ScrollOffsetAnimationCurve::Create(target_value, | 862 ScrollOffsetAnimationCurve::Create(target_value, |
| 827 EaseInOutTimingFunction::Create())); | 863 EaseInOutTimingFunction::Create())); |
| 828 | 864 |
| 829 std::unique_ptr<Animation> animation( | 865 std::unique_ptr<Animation> animation( |
| 830 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 866 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 controller->Animate(kInitialTickTime + duration); | 915 controller->Animate(kInitialTickTime + duration); |
| 880 controller->UpdateState(true, nullptr); | 916 controller->UpdateState(true, nullptr); |
| 881 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); | 917 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); |
| 882 EXPECT_FALSE(controller->HasActiveAnimation()); | 918 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 883 } | 919 } |
| 884 | 920 |
| 885 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { | 921 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { |
| 886 FakeLayerAnimationValueObserver dummy_impl; | 922 FakeLayerAnimationValueObserver dummy_impl; |
| 887 scoped_refptr<LayerAnimationController> controller_impl( | 923 scoped_refptr<LayerAnimationController> controller_impl( |
| 888 LayerAnimationController::Create(0)); | 924 LayerAnimationController::Create(0)); |
| 889 controller_impl->AddValueObserver(&dummy_impl); | 925 controller_impl->SetValueObserver(&dummy_impl); |
| 926 controller_impl->SetNeedsActiveValueObservations(true); |
| 890 std::unique_ptr<AnimationEvents> events( | 927 std::unique_ptr<AnimationEvents> events( |
| 891 base::WrapUnique(new AnimationEvents)); | 928 base::WrapUnique(new AnimationEvents)); |
| 892 | 929 |
| 893 gfx::ScrollOffset initial_value(100.f, 300.f); | 930 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 894 gfx::ScrollOffset target_value(300.f, 200.f); | 931 gfx::ScrollOffset target_value(300.f, 200.f); |
| 895 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 932 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 896 ScrollOffsetAnimationCurve::Create(target_value, | 933 ScrollOffsetAnimationCurve::Create(target_value, |
| 897 EaseInOutTimingFunction::Create())); | 934 EaseInOutTimingFunction::Create())); |
| 898 curve->SetInitialValue(initial_value); | 935 curve->SetInitialValue(initial_value); |
| 899 double duration_in_seconds = curve->Duration().InSecondsF(); | 936 double duration_in_seconds = curve->Duration().InSecondsF(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 927 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 964 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
| 928 event = GetMostRecentPropertyUpdateEvent(events.get()); | 965 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 929 EXPECT_FALSE(event); | 966 EXPECT_FALSE(event); |
| 930 } | 967 } |
| 931 | 968 |
| 932 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) { | 969 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) { |
| 933 FakeLayerAnimationValueObserver dummy_impl; | 970 FakeLayerAnimationValueObserver dummy_impl; |
| 934 FakeLayerAnimationValueProvider dummy_provider_impl; | 971 FakeLayerAnimationValueProvider dummy_provider_impl; |
| 935 scoped_refptr<LayerAnimationController> controller_impl( | 972 scoped_refptr<LayerAnimationController> controller_impl( |
| 936 LayerAnimationController::Create(0)); | 973 LayerAnimationController::Create(0)); |
| 937 controller_impl->AddValueObserver(&dummy_impl); | 974 controller_impl->SetValueObserver(&dummy_impl); |
| 975 controller_impl->SetNeedsActiveValueObservations(true); |
| 938 controller_impl->set_value_provider(&dummy_provider_impl); | 976 controller_impl->set_value_provider(&dummy_provider_impl); |
| 939 std::unique_ptr<AnimationEvents> events( | 977 std::unique_ptr<AnimationEvents> events( |
| 940 base::WrapUnique(new AnimationEvents)); | 978 base::WrapUnique(new AnimationEvents)); |
| 941 FakeLayerAnimationValueObserver dummy; | 979 FakeLayerAnimationValueObserver dummy; |
| 942 FakeLayerAnimationValueProvider dummy_provider; | 980 FakeLayerAnimationValueProvider dummy_provider; |
| 943 scoped_refptr<LayerAnimationController> controller( | 981 scoped_refptr<LayerAnimationController> controller( |
| 944 LayerAnimationController::Create(0)); | 982 LayerAnimationController::Create(0)); |
| 945 controller->AddValueObserver(&dummy); | 983 controller->SetValueObserver(&dummy); |
| 984 controller->SetNeedsActiveValueObservations(true); |
| 946 controller->set_value_provider(&dummy_provider); | 985 controller->set_value_provider(&dummy_provider); |
| 947 | 986 |
| 948 // First test the 1-argument version of RemoveAnimation. | 987 // First test the 1-argument version of RemoveAnimation. |
| 949 gfx::ScrollOffset target_value(300.f, 200.f); | 988 gfx::ScrollOffset target_value(300.f, 200.f); |
| 950 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 989 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 951 ScrollOffsetAnimationCurve::Create(target_value, | 990 ScrollOffsetAnimationCurve::Create(target_value, |
| 952 EaseInOutTimingFunction::Create())); | 991 EaseInOutTimingFunction::Create())); |
| 953 | 992 |
| 954 int animation_id = 1; | 993 int animation_id = 1; |
| 955 std::unique_ptr<Animation> animation(Animation::Create( | 994 std::unique_ptr<Animation> animation(Animation::Create( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 TimeTicks start_time_; | 1121 TimeTicks start_time_; |
| 1083 }; | 1122 }; |
| 1084 | 1123 |
| 1085 // Tests that impl-only animations lead to start and finished notifications | 1124 // Tests that impl-only animations lead to start and finished notifications |
| 1086 // on the impl thread controller's animation delegate. | 1125 // on the impl thread controller's animation delegate. |
| 1087 TEST(LayerAnimationControllerTest, | 1126 TEST(LayerAnimationControllerTest, |
| 1088 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { | 1127 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { |
| 1089 FakeLayerAnimationValueObserver dummy_impl; | 1128 FakeLayerAnimationValueObserver dummy_impl; |
| 1090 scoped_refptr<LayerAnimationController> controller_impl( | 1129 scoped_refptr<LayerAnimationController> controller_impl( |
| 1091 LayerAnimationController::Create(0)); | 1130 LayerAnimationController::Create(0)); |
| 1092 controller_impl->AddValueObserver(&dummy_impl); | 1131 controller_impl->SetValueObserver(&dummy_impl); |
| 1132 controller_impl->SetNeedsActiveValueObservations(true); |
| 1133 |
| 1093 std::unique_ptr<AnimationEvents> events( | 1134 std::unique_ptr<AnimationEvents> events( |
| 1094 base::WrapUnique(new AnimationEvents)); | 1135 base::WrapUnique(new AnimationEvents)); |
| 1095 FakeAnimationDelegate delegate; | 1136 FakeAnimationDelegate delegate; |
| 1096 controller_impl->set_layer_animation_delegate(&delegate); | 1137 controller_impl->set_layer_animation_delegate(&delegate); |
| 1097 | 1138 |
| 1098 std::unique_ptr<Animation> to_add(CreateAnimation( | 1139 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1099 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1140 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1100 1, TargetProperty::OPACITY)); | 1141 1, TargetProperty::OPACITY)); |
| 1101 to_add->set_is_impl_only(true); | 1142 to_add->set_is_impl_only(true); |
| 1102 controller_impl->AddAnimation(std::move(to_add)); | 1143 controller_impl->AddAnimation(std::move(to_add)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1118 EXPECT_TRUE(delegate.started()); | 1159 EXPECT_TRUE(delegate.started()); |
| 1119 EXPECT_TRUE(delegate.finished()); | 1160 EXPECT_TRUE(delegate.finished()); |
| 1120 } | 1161 } |
| 1121 | 1162 |
| 1122 // Tests that specified start times are sent to the main thread delegate | 1163 // Tests that specified start times are sent to the main thread delegate |
| 1123 TEST(LayerAnimationControllerTest, | 1164 TEST(LayerAnimationControllerTest, |
| 1124 SpecifiedStartTimesAreSentToMainThreadDelegate) { | 1165 SpecifiedStartTimesAreSentToMainThreadDelegate) { |
| 1125 FakeLayerAnimationValueObserver dummy_impl; | 1166 FakeLayerAnimationValueObserver dummy_impl; |
| 1126 scoped_refptr<LayerAnimationController> controller_impl( | 1167 scoped_refptr<LayerAnimationController> controller_impl( |
| 1127 LayerAnimationController::Create(0)); | 1168 LayerAnimationController::Create(0)); |
| 1128 controller_impl->AddValueObserver(&dummy_impl); | 1169 controller_impl->SetValueObserver(&dummy_impl); |
| 1170 controller_impl->SetNeedsActiveValueObservations(true); |
| 1171 |
| 1129 FakeLayerAnimationValueObserver dummy; | 1172 FakeLayerAnimationValueObserver dummy; |
| 1130 scoped_refptr<LayerAnimationController> controller( | 1173 scoped_refptr<LayerAnimationController> controller( |
| 1131 LayerAnimationController::Create(0)); | 1174 LayerAnimationController::Create(0)); |
| 1132 controller->AddValueObserver(&dummy); | 1175 controller->SetValueObserver(&dummy); |
| 1176 controller->SetNeedsActiveValueObservations(true); |
| 1177 |
| 1133 FakeAnimationDelegate delegate; | 1178 FakeAnimationDelegate delegate; |
| 1134 controller->set_layer_animation_delegate(&delegate); | 1179 controller->set_layer_animation_delegate(&delegate); |
| 1135 | 1180 |
| 1136 int animation_id = | 1181 int animation_id = |
| 1137 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 1182 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 1138 | 1183 |
| 1139 const TimeTicks start_time = TicksFromSecondsF(123); | 1184 const TimeTicks start_time = TicksFromSecondsF(123); |
| 1140 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); | 1185 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); |
| 1141 | 1186 |
| 1142 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1187 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1170 | 1215 |
| 1171 private: | 1216 private: |
| 1172 TimeTicks start_time_; | 1217 TimeTicks start_time_; |
| 1173 }; | 1218 }; |
| 1174 | 1219 |
| 1175 // Tests that specified start times are sent to the event observers | 1220 // Tests that specified start times are sent to the event observers |
| 1176 TEST(LayerAnimationControllerTest, SpecifiedStartTimesAreSentToEventObservers) { | 1221 TEST(LayerAnimationControllerTest, SpecifiedStartTimesAreSentToEventObservers) { |
| 1177 FakeLayerAnimationValueObserver dummy_impl; | 1222 FakeLayerAnimationValueObserver dummy_impl; |
| 1178 scoped_refptr<LayerAnimationController> controller_impl( | 1223 scoped_refptr<LayerAnimationController> controller_impl( |
| 1179 LayerAnimationController::Create(0)); | 1224 LayerAnimationController::Create(0)); |
| 1180 controller_impl->AddValueObserver(&dummy_impl); | 1225 controller_impl->SetValueObserver(&dummy_impl); |
| 1226 controller_impl->SetNeedsActiveValueObservations(true); |
| 1227 |
| 1181 FakeLayerAnimationValueObserver dummy; | 1228 FakeLayerAnimationValueObserver dummy; |
| 1182 scoped_refptr<LayerAnimationController> controller( | 1229 scoped_refptr<LayerAnimationController> controller( |
| 1183 LayerAnimationController::Create(0)); | 1230 LayerAnimationController::Create(0)); |
| 1184 controller->AddValueObserver(&dummy); | 1231 controller->SetValueObserver(&dummy); |
| 1232 controller->SetNeedsActiveValueObservations(true); |
| 1233 |
| 1185 FakeLayerAnimationEventObserver observer; | 1234 FakeLayerAnimationEventObserver observer; |
| 1186 controller->AddEventObserver(&observer); | 1235 controller->AddEventObserver(&observer); |
| 1187 | 1236 |
| 1188 int animation_id = | 1237 int animation_id = |
| 1189 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 1238 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 1190 | 1239 |
| 1191 const TimeTicks start_time = TicksFromSecondsF(123); | 1240 const TimeTicks start_time = TicksFromSecondsF(123); |
| 1192 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); | 1241 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); |
| 1193 | 1242 |
| 1194 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1243 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1212 | 1261 |
| 1213 // Tests animations that are waiting for a synchronized start time do not | 1262 // Tests animations that are waiting for a synchronized start time do not |
| 1214 // finish. | 1263 // finish. |
| 1215 TEST(LayerAnimationControllerTest, | 1264 TEST(LayerAnimationControllerTest, |
| 1216 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { | 1265 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { |
| 1217 std::unique_ptr<AnimationEvents> events( | 1266 std::unique_ptr<AnimationEvents> events( |
| 1218 base::WrapUnique(new AnimationEvents)); | 1267 base::WrapUnique(new AnimationEvents)); |
| 1219 FakeLayerAnimationValueObserver dummy; | 1268 FakeLayerAnimationValueObserver dummy; |
| 1220 scoped_refptr<LayerAnimationController> controller( | 1269 scoped_refptr<LayerAnimationController> controller( |
| 1221 LayerAnimationController::Create(0)); | 1270 LayerAnimationController::Create(0)); |
| 1222 controller->AddValueObserver(&dummy); | 1271 controller->SetValueObserver(&dummy); |
| 1272 controller->SetNeedsActiveValueObservations(true); |
| 1223 | 1273 |
| 1224 std::unique_ptr<Animation> to_add(CreateAnimation( | 1274 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1225 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1275 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1226 1, TargetProperty::OPACITY)); | 1276 1, TargetProperty::OPACITY)); |
| 1227 to_add->set_needs_synchronized_start_time(true); | 1277 to_add->set_needs_synchronized_start_time(true); |
| 1228 | 1278 |
| 1229 // We should pause at the first keyframe indefinitely waiting for that | 1279 // We should pause at the first keyframe indefinitely waiting for that |
| 1230 // animation to start. | 1280 // animation to start. |
| 1231 controller->AddAnimation(std::move(to_add)); | 1281 controller->AddAnimation(std::move(to_add)); |
| 1232 controller->Animate(kInitialTickTime); | 1282 controller->Animate(kInitialTickTime); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1252 EXPECT_FALSE(controller->HasActiveAnimation()); | 1302 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1253 } | 1303 } |
| 1254 | 1304 |
| 1255 // Tests that two queued animations affecting the same property run in sequence. | 1305 // Tests that two queued animations affecting the same property run in sequence. |
| 1256 TEST(LayerAnimationControllerTest, TrivialQueuing) { | 1306 TEST(LayerAnimationControllerTest, TrivialQueuing) { |
| 1257 std::unique_ptr<AnimationEvents> events( | 1307 std::unique_ptr<AnimationEvents> events( |
| 1258 base::WrapUnique(new AnimationEvents)); | 1308 base::WrapUnique(new AnimationEvents)); |
| 1259 FakeLayerAnimationValueObserver dummy; | 1309 FakeLayerAnimationValueObserver dummy; |
| 1260 scoped_refptr<LayerAnimationController> controller( | 1310 scoped_refptr<LayerAnimationController> controller( |
| 1261 LayerAnimationController::Create(0)); | 1311 LayerAnimationController::Create(0)); |
| 1262 controller->AddValueObserver(&dummy); | 1312 controller->SetValueObserver(&dummy); |
| 1313 controller->SetNeedsActiveValueObservations(true); |
| 1263 | 1314 |
| 1264 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 1315 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 1265 | 1316 |
| 1266 controller->AddAnimation(CreateAnimation( | 1317 controller->AddAnimation(CreateAnimation( |
| 1267 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1318 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1268 1, TargetProperty::OPACITY)); | 1319 1, TargetProperty::OPACITY)); |
| 1269 controller->AddAnimation(CreateAnimation( | 1320 controller->AddAnimation(CreateAnimation( |
| 1270 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1321 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
| 1271 2, TargetProperty::OPACITY)); | 1322 2, TargetProperty::OPACITY)); |
| 1272 | 1323 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1294 EXPECT_FALSE(controller->HasActiveAnimation()); | 1345 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1295 } | 1346 } |
| 1296 | 1347 |
| 1297 // Tests interrupting a transition with another transition. | 1348 // Tests interrupting a transition with another transition. |
| 1298 TEST(LayerAnimationControllerTest, Interrupt) { | 1349 TEST(LayerAnimationControllerTest, Interrupt) { |
| 1299 std::unique_ptr<AnimationEvents> events( | 1350 std::unique_ptr<AnimationEvents> events( |
| 1300 base::WrapUnique(new AnimationEvents)); | 1351 base::WrapUnique(new AnimationEvents)); |
| 1301 FakeLayerAnimationValueObserver dummy; | 1352 FakeLayerAnimationValueObserver dummy; |
| 1302 scoped_refptr<LayerAnimationController> controller( | 1353 scoped_refptr<LayerAnimationController> controller( |
| 1303 LayerAnimationController::Create(0)); | 1354 LayerAnimationController::Create(0)); |
| 1304 controller->AddValueObserver(&dummy); | 1355 controller->SetValueObserver(&dummy); |
| 1356 controller->SetNeedsActiveValueObservations(true); |
| 1357 |
| 1305 controller->AddAnimation(CreateAnimation( | 1358 controller->AddAnimation(CreateAnimation( |
| 1306 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1359 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1307 1, TargetProperty::OPACITY)); | 1360 1, TargetProperty::OPACITY)); |
| 1308 controller->Animate(kInitialTickTime); | 1361 controller->Animate(kInitialTickTime); |
| 1309 controller->UpdateState(true, events.get()); | 1362 controller->UpdateState(true, events.get()); |
| 1310 EXPECT_TRUE(controller->HasActiveAnimation()); | 1363 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1311 EXPECT_EQ(0.f, dummy.opacity()); | 1364 EXPECT_EQ(0.f, dummy.opacity()); |
| 1312 | 1365 |
| 1313 std::unique_ptr<Animation> to_add(CreateAnimation( | 1366 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1314 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1367 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1329 } | 1382 } |
| 1330 | 1383 |
| 1331 // Tests scheduling two animations to run together when only one property is | 1384 // Tests scheduling two animations to run together when only one property is |
| 1332 // free. | 1385 // free. |
| 1333 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { | 1386 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { |
| 1334 std::unique_ptr<AnimationEvents> events( | 1387 std::unique_ptr<AnimationEvents> events( |
| 1335 base::WrapUnique(new AnimationEvents)); | 1388 base::WrapUnique(new AnimationEvents)); |
| 1336 FakeLayerAnimationValueObserver dummy; | 1389 FakeLayerAnimationValueObserver dummy; |
| 1337 scoped_refptr<LayerAnimationController> controller( | 1390 scoped_refptr<LayerAnimationController> controller( |
| 1338 LayerAnimationController::Create(0)); | 1391 LayerAnimationController::Create(0)); |
| 1339 controller->AddValueObserver(&dummy); | 1392 controller->SetValueObserver(&dummy); |
| 1393 controller->SetNeedsActiveValueObservations(true); |
| 1340 | 1394 |
| 1341 controller->AddAnimation(CreateAnimation( | 1395 controller->AddAnimation(CreateAnimation( |
| 1342 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | 1396 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, |
| 1343 TargetProperty::TRANSFORM)); | 1397 TargetProperty::TRANSFORM)); |
| 1344 controller->AddAnimation(CreateAnimation( | 1398 controller->AddAnimation(CreateAnimation( |
| 1345 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, | 1399 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, |
| 1346 TargetProperty::TRANSFORM)); | 1400 TargetProperty::TRANSFORM)); |
| 1347 controller->AddAnimation(CreateAnimation( | 1401 controller->AddAnimation(CreateAnimation( |
| 1348 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1402 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1349 2, TargetProperty::OPACITY)); | 1403 2, TargetProperty::OPACITY)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1366 | 1420 |
| 1367 // Tests scheduling two animations to run together with different lengths and | 1421 // Tests scheduling two animations to run together with different lengths and |
| 1368 // another animation queued to start when the shorter animation finishes (should | 1422 // another animation queued to start when the shorter animation finishes (should |
| 1369 // wait for both to finish). | 1423 // wait for both to finish). |
| 1370 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { | 1424 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { |
| 1371 std::unique_ptr<AnimationEvents> events( | 1425 std::unique_ptr<AnimationEvents> events( |
| 1372 base::WrapUnique(new AnimationEvents)); | 1426 base::WrapUnique(new AnimationEvents)); |
| 1373 FakeLayerAnimationValueObserver dummy; | 1427 FakeLayerAnimationValueObserver dummy; |
| 1374 scoped_refptr<LayerAnimationController> controller( | 1428 scoped_refptr<LayerAnimationController> controller( |
| 1375 LayerAnimationController::Create(0)); | 1429 LayerAnimationController::Create(0)); |
| 1376 controller->AddValueObserver(&dummy); | 1430 controller->SetValueObserver(&dummy); |
| 1431 controller->SetNeedsActiveValueObservations(true); |
| 1377 | 1432 |
| 1378 controller->AddAnimation(CreateAnimation( | 1433 controller->AddAnimation(CreateAnimation( |
| 1379 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, | 1434 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, |
| 1380 TargetProperty::TRANSFORM)); | 1435 TargetProperty::TRANSFORM)); |
| 1381 controller->AddAnimation(CreateAnimation( | 1436 controller->AddAnimation(CreateAnimation( |
| 1382 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1437 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1383 1, TargetProperty::OPACITY)); | 1438 1, TargetProperty::OPACITY)); |
| 1384 controller->AddAnimation(CreateAnimation( | 1439 controller->AddAnimation(CreateAnimation( |
| 1385 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1440 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
| 1386 2, TargetProperty::OPACITY)); | 1441 2, TargetProperty::OPACITY)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1407 EXPECT_FALSE(controller->HasActiveAnimation()); | 1462 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1408 } | 1463 } |
| 1409 | 1464 |
| 1410 // Test that a looping animation loops and for the correct number of iterations. | 1465 // Test that a looping animation loops and for the correct number of iterations. |
| 1411 TEST(LayerAnimationControllerTest, TrivialLooping) { | 1466 TEST(LayerAnimationControllerTest, TrivialLooping) { |
| 1412 std::unique_ptr<AnimationEvents> events( | 1467 std::unique_ptr<AnimationEvents> events( |
| 1413 base::WrapUnique(new AnimationEvents)); | 1468 base::WrapUnique(new AnimationEvents)); |
| 1414 FakeLayerAnimationValueObserver dummy; | 1469 FakeLayerAnimationValueObserver dummy; |
| 1415 scoped_refptr<LayerAnimationController> controller( | 1470 scoped_refptr<LayerAnimationController> controller( |
| 1416 LayerAnimationController::Create(0)); | 1471 LayerAnimationController::Create(0)); |
| 1417 controller->AddValueObserver(&dummy); | 1472 controller->SetValueObserver(&dummy); |
| 1473 controller->SetNeedsActiveValueObservations(true); |
| 1418 | 1474 |
| 1419 std::unique_ptr<Animation> to_add(CreateAnimation( | 1475 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1420 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1476 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1421 1, TargetProperty::OPACITY)); | 1477 1, TargetProperty::OPACITY)); |
| 1422 to_add->set_iterations(3); | 1478 to_add->set_iterations(3); |
| 1423 controller->AddAnimation(std::move(to_add)); | 1479 controller->AddAnimation(std::move(to_add)); |
| 1424 | 1480 |
| 1425 controller->Animate(kInitialTickTime); | 1481 controller->Animate(kInitialTickTime); |
| 1426 controller->UpdateState(true, events.get()); | 1482 controller->UpdateState(true, events.get()); |
| 1427 EXPECT_TRUE(controller->HasActiveAnimation()); | 1483 EXPECT_TRUE(controller->HasActiveAnimation()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1453 EXPECT_EQ(1.f, dummy.opacity()); | 1509 EXPECT_EQ(1.f, dummy.opacity()); |
| 1454 } | 1510 } |
| 1455 | 1511 |
| 1456 // Test that an infinitely looping animation does indeed go until aborted. | 1512 // Test that an infinitely looping animation does indeed go until aborted. |
| 1457 TEST(LayerAnimationControllerTest, InfiniteLooping) { | 1513 TEST(LayerAnimationControllerTest, InfiniteLooping) { |
| 1458 std::unique_ptr<AnimationEvents> events( | 1514 std::unique_ptr<AnimationEvents> events( |
| 1459 base::WrapUnique(new AnimationEvents)); | 1515 base::WrapUnique(new AnimationEvents)); |
| 1460 FakeLayerAnimationValueObserver dummy; | 1516 FakeLayerAnimationValueObserver dummy; |
| 1461 scoped_refptr<LayerAnimationController> controller( | 1517 scoped_refptr<LayerAnimationController> controller( |
| 1462 LayerAnimationController::Create(0)); | 1518 LayerAnimationController::Create(0)); |
| 1463 controller->AddValueObserver(&dummy); | 1519 controller->SetValueObserver(&dummy); |
| 1520 controller->SetNeedsActiveValueObservations(true); |
| 1464 | 1521 |
| 1465 std::unique_ptr<Animation> to_add(CreateAnimation( | 1522 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1466 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1523 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1467 1, TargetProperty::OPACITY)); | 1524 1, TargetProperty::OPACITY)); |
| 1468 to_add->set_iterations(-1); | 1525 to_add->set_iterations(-1); |
| 1469 controller->AddAnimation(std::move(to_add)); | 1526 controller->AddAnimation(std::move(to_add)); |
| 1470 | 1527 |
| 1471 controller->Animate(kInitialTickTime); | 1528 controller->Animate(kInitialTickTime); |
| 1472 controller->UpdateState(true, events.get()); | 1529 controller->UpdateState(true, events.get()); |
| 1473 EXPECT_TRUE(controller->HasActiveAnimation()); | 1530 EXPECT_TRUE(controller->HasActiveAnimation()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1500 EXPECT_EQ(0.75f, dummy.opacity()); | 1557 EXPECT_EQ(0.75f, dummy.opacity()); |
| 1501 } | 1558 } |
| 1502 | 1559 |
| 1503 // Test that pausing and resuming work as expected. | 1560 // Test that pausing and resuming work as expected. |
| 1504 TEST(LayerAnimationControllerTest, PauseResume) { | 1561 TEST(LayerAnimationControllerTest, PauseResume) { |
| 1505 std::unique_ptr<AnimationEvents> events( | 1562 std::unique_ptr<AnimationEvents> events( |
| 1506 base::WrapUnique(new AnimationEvents)); | 1563 base::WrapUnique(new AnimationEvents)); |
| 1507 FakeLayerAnimationValueObserver dummy; | 1564 FakeLayerAnimationValueObserver dummy; |
| 1508 scoped_refptr<LayerAnimationController> controller( | 1565 scoped_refptr<LayerAnimationController> controller( |
| 1509 LayerAnimationController::Create(0)); | 1566 LayerAnimationController::Create(0)); |
| 1510 controller->AddValueObserver(&dummy); | 1567 controller->SetValueObserver(&dummy); |
| 1568 controller->SetNeedsActiveValueObservations(true); |
| 1511 | 1569 |
| 1512 controller->AddAnimation(CreateAnimation( | 1570 controller->AddAnimation(CreateAnimation( |
| 1513 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1571 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1514 1, TargetProperty::OPACITY)); | 1572 1, TargetProperty::OPACITY)); |
| 1515 | 1573 |
| 1516 controller->Animate(kInitialTickTime); | 1574 controller->Animate(kInitialTickTime); |
| 1517 controller->UpdateState(true, events.get()); | 1575 controller->UpdateState(true, events.get()); |
| 1518 EXPECT_TRUE(controller->HasActiveAnimation()); | 1576 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1519 EXPECT_EQ(0.f, dummy.opacity()); | 1577 EXPECT_EQ(0.f, dummy.opacity()); |
| 1520 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1578 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1546 EXPECT_FALSE(controller->HasActiveAnimation()); | 1604 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1547 EXPECT_EQ(1.f, dummy.opacity()); | 1605 EXPECT_EQ(1.f, dummy.opacity()); |
| 1548 } | 1606 } |
| 1549 | 1607 |
| 1550 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { | 1608 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { |
| 1551 std::unique_ptr<AnimationEvents> events( | 1609 std::unique_ptr<AnimationEvents> events( |
| 1552 base::WrapUnique(new AnimationEvents)); | 1610 base::WrapUnique(new AnimationEvents)); |
| 1553 FakeLayerAnimationValueObserver dummy; | 1611 FakeLayerAnimationValueObserver dummy; |
| 1554 scoped_refptr<LayerAnimationController> controller( | 1612 scoped_refptr<LayerAnimationController> controller( |
| 1555 LayerAnimationController::Create(0)); | 1613 LayerAnimationController::Create(0)); |
| 1556 controller->AddValueObserver(&dummy); | 1614 controller->SetValueObserver(&dummy); |
| 1615 controller->SetNeedsActiveValueObservations(true); |
| 1557 | 1616 |
| 1558 const int animation_id = 2; | 1617 const int animation_id = 2; |
| 1559 controller->AddAnimation(Animation::Create( | 1618 controller->AddAnimation(Animation::Create( |
| 1560 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, | 1619 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, |
| 1561 TargetProperty::TRANSFORM)); | 1620 TargetProperty::TRANSFORM)); |
| 1562 controller->AddAnimation(Animation::Create( | 1621 controller->AddAnimation(Animation::Create( |
| 1563 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), | 1622 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), |
| 1564 animation_id, 1, TargetProperty::OPACITY)); | 1623 animation_id, 1, TargetProperty::OPACITY)); |
| 1565 controller->AddAnimation(Animation::Create( | 1624 controller->AddAnimation(Animation::Create( |
| 1566 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), | 1625 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1586 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1645 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1587 controller->UpdateState(true, events.get()); | 1646 controller->UpdateState(true, events.get()); |
| 1588 EXPECT_TRUE(!controller->HasActiveAnimation()); | 1647 EXPECT_TRUE(!controller->HasActiveAnimation()); |
| 1589 EXPECT_EQ(0.75f, dummy.opacity()); | 1648 EXPECT_EQ(0.75f, dummy.opacity()); |
| 1590 } | 1649 } |
| 1591 | 1650 |
| 1592 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { | 1651 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { |
| 1593 FakeLayerAnimationValueObserver dummy_impl; | 1652 FakeLayerAnimationValueObserver dummy_impl; |
| 1594 scoped_refptr<LayerAnimationController> controller_impl( | 1653 scoped_refptr<LayerAnimationController> controller_impl( |
| 1595 LayerAnimationController::Create(0)); | 1654 LayerAnimationController::Create(0)); |
| 1596 controller_impl->AddValueObserver(&dummy_impl); | 1655 controller_impl->SetValueObserver(&dummy_impl); |
| 1656 controller_impl->SetNeedsActiveValueObservations(true); |
| 1597 std::unique_ptr<AnimationEvents> events( | 1657 std::unique_ptr<AnimationEvents> events( |
| 1598 base::WrapUnique(new AnimationEvents)); | 1658 base::WrapUnique(new AnimationEvents)); |
| 1599 FakeLayerAnimationValueObserver dummy; | 1659 FakeLayerAnimationValueObserver dummy; |
| 1600 scoped_refptr<LayerAnimationController> controller( | 1660 scoped_refptr<LayerAnimationController> controller( |
| 1601 LayerAnimationController::Create(0)); | 1661 LayerAnimationController::Create(0)); |
| 1602 controller->AddValueObserver(&dummy); | 1662 controller->SetValueObserver(&dummy); |
| 1663 controller->SetNeedsActiveValueObservations(true); |
| 1603 | 1664 |
| 1604 std::unique_ptr<Animation> to_add(CreateAnimation( | 1665 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1605 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), | 1666 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), |
| 1606 0, TargetProperty::OPACITY)); | 1667 0, TargetProperty::OPACITY)); |
| 1607 to_add->set_needs_synchronized_start_time(true); | 1668 to_add->set_needs_synchronized_start_time(true); |
| 1608 controller->AddAnimation(std::move(to_add)); | 1669 controller->AddAnimation(std::move(to_add)); |
| 1609 | 1670 |
| 1610 controller->Animate(kInitialTickTime); | 1671 controller->Animate(kInitialTickTime); |
| 1611 controller->UpdateState(true, events.get()); | 1672 controller->UpdateState(true, events.get()); |
| 1612 EXPECT_TRUE(controller->HasActiveAnimation()); | 1673 EXPECT_TRUE(controller->HasActiveAnimation()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1624 active_animation->run_state()); | 1685 active_animation->run_state()); |
| 1625 } | 1686 } |
| 1626 | 1687 |
| 1627 // Tests that skipping a call to UpdateState works as expected. | 1688 // Tests that skipping a call to UpdateState works as expected. |
| 1628 TEST(LayerAnimationControllerTest, SkipUpdateState) { | 1689 TEST(LayerAnimationControllerTest, SkipUpdateState) { |
| 1629 std::unique_ptr<AnimationEvents> events( | 1690 std::unique_ptr<AnimationEvents> events( |
| 1630 base::WrapUnique(new AnimationEvents)); | 1691 base::WrapUnique(new AnimationEvents)); |
| 1631 FakeLayerAnimationValueObserver dummy; | 1692 FakeLayerAnimationValueObserver dummy; |
| 1632 scoped_refptr<LayerAnimationController> controller( | 1693 scoped_refptr<LayerAnimationController> controller( |
| 1633 LayerAnimationController::Create(0)); | 1694 LayerAnimationController::Create(0)); |
| 1634 controller->AddValueObserver(&dummy); | 1695 controller->SetValueObserver(&dummy); |
| 1696 controller->SetNeedsActiveValueObservations(true); |
| 1635 | 1697 |
| 1636 std::unique_ptr<Animation> first_animation(CreateAnimation( | 1698 std::unique_ptr<Animation> first_animation(CreateAnimation( |
| 1637 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | 1699 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, |
| 1638 TargetProperty::TRANSFORM)); | 1700 TargetProperty::TRANSFORM)); |
| 1639 first_animation->set_is_controlling_instance_for_test(true); | 1701 first_animation->set_is_controlling_instance_for_test(true); |
| 1640 controller->AddAnimation(std::move(first_animation)); | 1702 controller->AddAnimation(std::move(first_animation)); |
| 1641 | 1703 |
| 1642 controller->Animate(kInitialTickTime); | 1704 controller->Animate(kInitialTickTime); |
| 1643 controller->UpdateState(true, events.get()); | 1705 controller->UpdateState(true, events.get()); |
| 1644 | 1706 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1669 // The float tranisition should now be done. | 1731 // The float tranisition should now be done. |
| 1670 EXPECT_EQ(1.f, dummy.opacity()); | 1732 EXPECT_EQ(1.f, dummy.opacity()); |
| 1671 EXPECT_FALSE(controller->HasActiveAnimation()); | 1733 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1672 } | 1734 } |
| 1673 | 1735 |
| 1674 // Tests that an animation controller with only a pending observer gets ticked | 1736 // Tests that an animation controller with only a pending observer gets ticked |
| 1675 // but doesn't progress animations past the STARTING state. | 1737 // but doesn't progress animations past the STARTING state. |
| 1676 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { | 1738 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { |
| 1677 std::unique_ptr<AnimationEvents> events( | 1739 std::unique_ptr<AnimationEvents> events( |
| 1678 base::WrapUnique(new AnimationEvents)); | 1740 base::WrapUnique(new AnimationEvents)); |
| 1679 FakeLayerAnimationValueObserver dummy; | 1741 FakeTypedLayerAnimationValueObserver dummy; |
| 1680 FakeInactiveLayerAnimationValueObserver pending_dummy; | |
| 1681 scoped_refptr<LayerAnimationController> controller( | 1742 scoped_refptr<LayerAnimationController> controller( |
| 1682 LayerAnimationController::Create(0)); | 1743 LayerAnimationController::Create(0)); |
| 1744 controller->SetValueObserver(&dummy); |
| 1683 | 1745 |
| 1684 const int id = 1; | 1746 const int id = 1; |
| 1685 controller->AddAnimation(CreateAnimation( | 1747 controller->AddAnimation(CreateAnimation( |
| 1686 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), | 1748 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), |
| 1687 id, TargetProperty::OPACITY)); | 1749 id, TargetProperty::OPACITY)); |
| 1688 | 1750 |
| 1689 // Without an observer, the animation shouldn't progress to the STARTING | 1751 // Without an observer, the animation shouldn't progress to the STARTING |
| 1690 // state. | 1752 // state. |
| 1691 controller->Animate(kInitialTickTime); | 1753 controller->Animate(kInitialTickTime); |
| 1692 controller->UpdateState(true, events.get()); | 1754 controller->UpdateState(true, events.get()); |
| 1693 EXPECT_EQ(0u, events->events_.size()); | 1755 EXPECT_EQ(0u, events->events_.size()); |
| 1694 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 1756 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 1695 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1757 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 1696 | 1758 |
| 1697 controller->AddValueObserver(&pending_dummy); | 1759 controller->SetNeedsPendingValueObservations(true); |
| 1698 | 1760 |
| 1699 // With only a pending observer, the animation should progress to the | 1761 // With only a pending observer, the animation should progress to the |
| 1700 // STARTING state and get ticked at its starting point, but should not | 1762 // STARTING state and get ticked at its starting point, but should not |
| 1701 // progress to RUNNING. | 1763 // progress to RUNNING. |
| 1702 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1764 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1703 controller->UpdateState(true, events.get()); | 1765 controller->UpdateState(true, events.get()); |
| 1704 EXPECT_EQ(0u, events->events_.size()); | 1766 EXPECT_EQ(0u, events->events_.size()); |
| 1705 EXPECT_EQ(Animation::STARTING, | 1767 EXPECT_EQ(Animation::STARTING, |
| 1706 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1768 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 1707 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1769 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::PENDING)); |
| 1708 | 1770 |
| 1709 // Even when already in the STARTING state, the animation should stay | 1771 // Even when already in the STARTING state, the animation should stay |
| 1710 // there, and shouldn't be ticked past its starting point. | 1772 // there, and shouldn't be ticked past its starting point. |
| 1711 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1773 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1712 controller->UpdateState(true, events.get()); | 1774 controller->UpdateState(true, events.get()); |
| 1713 EXPECT_EQ(0u, events->events_.size()); | 1775 EXPECT_EQ(0u, events->events_.size()); |
| 1714 EXPECT_EQ(Animation::STARTING, | 1776 EXPECT_EQ(Animation::STARTING, |
| 1715 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1777 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 1716 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1778 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::PENDING)); |
| 1717 | 1779 |
| 1718 controller->AddValueObserver(&dummy); | 1780 controller->SetNeedsActiveValueObservations(true); |
| 1719 | 1781 |
| 1720 // Now that an active observer has been added, the animation should still | 1782 // Now that an active observer has been added, the animation should still |
| 1721 // initially tick at its starting point, but should now progress to RUNNING. | 1783 // initially tick at its starting point, but should now progress to RUNNING. |
| 1722 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1784 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 1723 controller->UpdateState(true, events.get()); | 1785 controller->UpdateState(true, events.get()); |
| 1724 EXPECT_EQ(1u, events->events_.size()); | 1786 EXPECT_EQ(1u, events->events_.size()); |
| 1725 EXPECT_EQ(Animation::RUNNING, | 1787 EXPECT_EQ(Animation::RUNNING, |
| 1726 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1788 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 1727 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1789 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::PENDING)); |
| 1728 EXPECT_EQ(0.5f, dummy.opacity()); | 1790 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1729 | 1791 |
| 1730 // The animation should now tick past its starting point. | 1792 // The animation should now tick past its starting point. |
| 1731 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); | 1793 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); |
| 1732 EXPECT_NE(0.5f, pending_dummy.opacity()); | 1794 EXPECT_NE(0.5f, dummy.opacity(LayerTreeType::PENDING)); |
| 1733 EXPECT_NE(0.5f, dummy.opacity()); | 1795 EXPECT_NE(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1734 } | 1796 } |
| 1735 | 1797 |
| 1736 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { | 1798 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { |
| 1737 scoped_refptr<LayerAnimationController> controller_impl( | 1799 scoped_refptr<LayerAnimationController> controller_impl( |
| 1738 LayerAnimationController::Create(0)); | 1800 LayerAnimationController::Create(0)); |
| 1739 | 1801 |
| 1740 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | 1802 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( |
| 1741 KeyframedTransformAnimationCurve::Create()); | 1803 KeyframedTransformAnimationCurve::Create()); |
| 1742 | 1804 |
| 1743 TransformOperations operations1; | 1805 TransformOperations operations1; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1802 controller_impl->AddAnimation(std::move(animation)); | 1864 controller_impl->AddAnimation(std::move(animation)); |
| 1803 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); | 1865 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); |
| 1804 } | 1866 } |
| 1805 | 1867 |
| 1806 // Tests that AbortAnimations aborts all animations targeting the specified | 1868 // Tests that AbortAnimations aborts all animations targeting the specified |
| 1807 // property. | 1869 // property. |
| 1808 TEST(LayerAnimationControllerTest, AbortAnimations) { | 1870 TEST(LayerAnimationControllerTest, AbortAnimations) { |
| 1809 FakeLayerAnimationValueObserver dummy; | 1871 FakeLayerAnimationValueObserver dummy; |
| 1810 scoped_refptr<LayerAnimationController> controller( | 1872 scoped_refptr<LayerAnimationController> controller( |
| 1811 LayerAnimationController::Create(0)); | 1873 LayerAnimationController::Create(0)); |
| 1812 controller->AddValueObserver(&dummy); | 1874 controller->SetValueObserver(&dummy); |
| 1875 controller->SetNeedsActiveValueObservations(true); |
| 1813 | 1876 |
| 1814 // Start with several animations, and allow some of them to reach the finished | 1877 // Start with several animations, and allow some of them to reach the finished |
| 1815 // state. | 1878 // state. |
| 1816 controller->AddAnimation(Animation::Create( | 1879 controller->AddAnimation(Animation::Create( |
| 1817 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, 1, | 1880 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, 1, |
| 1818 TargetProperty::TRANSFORM)); | 1881 TargetProperty::TRANSFORM)); |
| 1819 controller->AddAnimation(Animation::Create( | 1882 controller->AddAnimation(Animation::Create( |
| 1820 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1883 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1821 2, 2, TargetProperty::OPACITY)); | 1884 2, 2, TargetProperty::OPACITY)); |
| 1822 controller->AddAnimation(Animation::Create( | 1885 controller->AddAnimation(Animation::Create( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1849 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(3)->run_state()); | 1912 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(3)->run_state()); |
| 1850 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(4)->run_state()); | 1913 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(4)->run_state()); |
| 1851 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(5)->run_state()); | 1914 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(5)->run_state()); |
| 1852 } | 1915 } |
| 1853 | 1916 |
| 1854 // An animation aborted on the main thread should get deleted on both threads. | 1917 // An animation aborted on the main thread should get deleted on both threads. |
| 1855 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) { | 1918 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) { |
| 1856 FakeLayerAnimationValueObserver dummy_impl; | 1919 FakeLayerAnimationValueObserver dummy_impl; |
| 1857 scoped_refptr<LayerAnimationController> controller_impl( | 1920 scoped_refptr<LayerAnimationController> controller_impl( |
| 1858 LayerAnimationController::Create(0)); | 1921 LayerAnimationController::Create(0)); |
| 1859 controller_impl->AddValueObserver(&dummy_impl); | 1922 controller_impl->SetValueObserver(&dummy_impl); |
| 1923 controller_impl->SetNeedsActiveValueObservations(true); |
| 1860 FakeLayerAnimationValueObserver dummy; | 1924 FakeLayerAnimationValueObserver dummy; |
| 1861 scoped_refptr<LayerAnimationController> controller( | 1925 scoped_refptr<LayerAnimationController> controller( |
| 1862 LayerAnimationController::Create(0)); | 1926 LayerAnimationController::Create(0)); |
| 1863 controller->AddValueObserver(&dummy); | 1927 controller->SetValueObserver(&dummy); |
| 1928 controller->SetNeedsActiveValueObservations(true); |
| 1864 | 1929 |
| 1865 int animation_id = | 1930 int animation_id = |
| 1866 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); | 1931 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); |
| 1867 | 1932 |
| 1868 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1933 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1869 controller_impl->ActivateAnimations(); | 1934 controller_impl->ActivateAnimations(); |
| 1870 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 1935 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 1871 | 1936 |
| 1872 controller->AbortAnimations(TargetProperty::OPACITY); | 1937 controller->AbortAnimations(TargetProperty::OPACITY); |
| 1873 EXPECT_EQ(Animation::ABORTED, | 1938 EXPECT_EQ(Animation::ABORTED, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1884 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1949 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1885 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | 1950 EXPECT_FALSE(controller->GetAnimationById(animation_id)); |
| 1886 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | 1951 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); |
| 1887 } | 1952 } |
| 1888 | 1953 |
| 1889 // An animation aborted on the impl thread should get deleted on both threads. | 1954 // An animation aborted on the impl thread should get deleted on both threads. |
| 1890 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) { | 1955 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) { |
| 1891 FakeLayerAnimationValueObserver dummy_impl; | 1956 FakeLayerAnimationValueObserver dummy_impl; |
| 1892 scoped_refptr<LayerAnimationController> controller_impl( | 1957 scoped_refptr<LayerAnimationController> controller_impl( |
| 1893 LayerAnimationController::Create(0)); | 1958 LayerAnimationController::Create(0)); |
| 1894 controller_impl->AddValueObserver(&dummy_impl); | 1959 controller_impl->SetValueObserver(&dummy_impl); |
| 1960 controller_impl->SetNeedsActiveValueObservations(true); |
| 1895 FakeLayerAnimationValueObserver dummy; | 1961 FakeLayerAnimationValueObserver dummy; |
| 1896 scoped_refptr<LayerAnimationController> controller( | 1962 scoped_refptr<LayerAnimationController> controller( |
| 1897 LayerAnimationController::Create(0)); | 1963 LayerAnimationController::Create(0)); |
| 1898 controller->AddValueObserver(&dummy); | 1964 controller->SetValueObserver(&dummy); |
| 1965 controller->SetNeedsActiveValueObservations(true); |
| 1899 FakeAnimationDelegate delegate; | 1966 FakeAnimationDelegate delegate; |
| 1900 controller->set_layer_animation_delegate(&delegate); | 1967 controller->set_layer_animation_delegate(&delegate); |
| 1901 | 1968 |
| 1902 int animation_id = | 1969 int animation_id = |
| 1903 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); | 1970 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); |
| 1904 | 1971 |
| 1905 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1972 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1906 controller_impl->ActivateAnimations(); | 1973 controller_impl->ActivateAnimations(); |
| 1907 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 1974 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 1908 | 1975 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1939 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | 2006 EXPECT_FALSE(controller->GetAnimationById(animation_id)); |
| 1940 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | 2007 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); |
| 1941 } | 2008 } |
| 1942 | 2009 |
| 1943 // Test that an impl-only scroll offset animation that needs to be completed on | 2010 // Test that an impl-only scroll offset animation that needs to be completed on |
| 1944 // the main thread gets deleted. | 2011 // the main thread gets deleted. |
| 1945 TEST(LayerAnimationControllerTest, ImplThreadTakeoverAnimationGetsDeleted) { | 2012 TEST(LayerAnimationControllerTest, ImplThreadTakeoverAnimationGetsDeleted) { |
| 1946 FakeLayerAnimationValueObserver dummy_impl; | 2013 FakeLayerAnimationValueObserver dummy_impl; |
| 1947 scoped_refptr<LayerAnimationController> controller_impl( | 2014 scoped_refptr<LayerAnimationController> controller_impl( |
| 1948 LayerAnimationController::Create(0)); | 2015 LayerAnimationController::Create(0)); |
| 1949 controller_impl->AddValueObserver(&dummy_impl); | 2016 controller_impl->SetValueObserver(&dummy_impl); |
| 2017 controller_impl->SetNeedsActiveValueObservations(true); |
| 1950 FakeLayerAnimationValueObserver dummy; | 2018 FakeLayerAnimationValueObserver dummy; |
| 1951 scoped_refptr<LayerAnimationController> controller( | 2019 scoped_refptr<LayerAnimationController> controller( |
| 1952 LayerAnimationController::Create(0)); | 2020 LayerAnimationController::Create(0)); |
| 1953 controller->AddValueObserver(&dummy); | 2021 controller->SetValueObserver(&dummy); |
| 2022 controller->SetNeedsActiveValueObservations(true); |
| 1954 FakeAnimationDelegate delegate_impl; | 2023 FakeAnimationDelegate delegate_impl; |
| 1955 controller_impl->set_layer_animation_delegate(&delegate_impl); | 2024 controller_impl->set_layer_animation_delegate(&delegate_impl); |
| 1956 FakeAnimationDelegate delegate; | 2025 FakeAnimationDelegate delegate; |
| 1957 controller->set_layer_animation_delegate(&delegate); | 2026 controller->set_layer_animation_delegate(&delegate); |
| 1958 | 2027 |
| 1959 // Add impl-only scroll offset animation. | 2028 // Add impl-only scroll offset animation. |
| 1960 int animation_id = 1; | 2029 int animation_id = 1; |
| 1961 gfx::ScrollOffset initial_value(100.f, 300.f); | 2030 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 1962 gfx::ScrollOffset target_value(300.f, 200.f); | 2031 gfx::ScrollOffset target_value(300.f, 200.f); |
| 1963 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 2032 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2007 } | 2076 } |
| 2008 | 2077 |
| 2009 // Ensure that we only generate FINISHED events for animations in a group | 2078 // Ensure that we only generate FINISHED events for animations in a group |
| 2010 // once all animations in that group are finished. | 2079 // once all animations in that group are finished. |
| 2011 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { | 2080 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { |
| 2012 std::unique_ptr<AnimationEvents> events( | 2081 std::unique_ptr<AnimationEvents> events( |
| 2013 base::WrapUnique(new AnimationEvents)); | 2082 base::WrapUnique(new AnimationEvents)); |
| 2014 FakeLayerAnimationValueObserver dummy_impl; | 2083 FakeLayerAnimationValueObserver dummy_impl; |
| 2015 scoped_refptr<LayerAnimationController> controller_impl( | 2084 scoped_refptr<LayerAnimationController> controller_impl( |
| 2016 LayerAnimationController::Create(0)); | 2085 LayerAnimationController::Create(0)); |
| 2017 controller_impl->AddValueObserver(&dummy_impl); | 2086 controller_impl->SetValueObserver(&dummy_impl); |
| 2087 controller_impl->SetNeedsActiveValueObservations(true); |
| 2018 | 2088 |
| 2019 const int group_id = 1; | 2089 const int group_id = 1; |
| 2020 | 2090 |
| 2021 // Add two animations with the same group id but different durations. | 2091 // Add two animations with the same group id but different durations. |
| 2022 std::unique_ptr<Animation> first_animation(Animation::Create( | 2092 std::unique_ptr<Animation> first_animation(Animation::Create( |
| 2023 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1, | 2093 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1, |
| 2024 group_id, TargetProperty::TRANSFORM)); | 2094 group_id, TargetProperty::TRANSFORM)); |
| 2025 first_animation->set_is_controlling_instance_for_test(true); | 2095 first_animation->set_is_controlling_instance_for_test(true); |
| 2026 controller_impl->AddAnimation(std::move(first_animation)); | 2096 controller_impl->AddAnimation(std::move(first_animation)); |
| 2027 | 2097 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 | 2134 |
| 2065 // Ensure that when a group has a mix of aborted and finished animations, | 2135 // Ensure that when a group has a mix of aborted and finished animations, |
| 2066 // we generate a FINISHED event for the finished animation and an ABORTED | 2136 // we generate a FINISHED event for the finished animation and an ABORTED |
| 2067 // event for the aborted animation. | 2137 // event for the aborted animation. |
| 2068 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { | 2138 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { |
| 2069 std::unique_ptr<AnimationEvents> events( | 2139 std::unique_ptr<AnimationEvents> events( |
| 2070 base::WrapUnique(new AnimationEvents)); | 2140 base::WrapUnique(new AnimationEvents)); |
| 2071 FakeLayerAnimationValueObserver dummy_impl; | 2141 FakeLayerAnimationValueObserver dummy_impl; |
| 2072 scoped_refptr<LayerAnimationController> controller_impl( | 2142 scoped_refptr<LayerAnimationController> controller_impl( |
| 2073 LayerAnimationController::Create(0)); | 2143 LayerAnimationController::Create(0)); |
| 2074 controller_impl->AddValueObserver(&dummy_impl); | 2144 controller_impl->SetValueObserver(&dummy_impl); |
| 2145 controller_impl->SetNeedsActiveValueObservations(true); |
| 2075 | 2146 |
| 2076 // Add two animations with the same group id. | 2147 // Add two animations with the same group id. |
| 2077 std::unique_ptr<Animation> first_animation(CreateAnimation( | 2148 std::unique_ptr<Animation> first_animation(CreateAnimation( |
| 2078 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, | 2149 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, |
| 2079 TargetProperty::TRANSFORM)); | 2150 TargetProperty::TRANSFORM)); |
| 2080 first_animation->set_is_controlling_instance_for_test(true); | 2151 first_animation->set_is_controlling_instance_for_test(true); |
| 2081 controller_impl->AddAnimation(std::move(first_animation)); | 2152 controller_impl->AddAnimation(std::move(first_animation)); |
| 2082 | 2153 |
| 2083 std::unique_ptr<Animation> second_animation(CreateAnimation( | 2154 std::unique_ptr<Animation> second_animation(CreateAnimation( |
| 2084 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 2155 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2553 LayerAnimationController::ObserverType::PENDING, &max_scale)); | 2624 LayerAnimationController::ObserverType::PENDING, &max_scale)); |
| 2554 EXPECT_EQ(6.f, max_scale); | 2625 EXPECT_EQ(6.f, max_scale); |
| 2555 EXPECT_TRUE(controller_impl->MaximumTargetScale( | 2626 EXPECT_TRUE(controller_impl->MaximumTargetScale( |
| 2556 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | 2627 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); |
| 2557 EXPECT_EQ(6.f, max_scale); | 2628 EXPECT_EQ(6.f, max_scale); |
| 2558 } | 2629 } |
| 2559 | 2630 |
| 2560 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { | 2631 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { |
| 2561 std::unique_ptr<AnimationEvents> events( | 2632 std::unique_ptr<AnimationEvents> events( |
| 2562 base::WrapUnique(new AnimationEvents)); | 2633 base::WrapUnique(new AnimationEvents)); |
| 2563 FakeLayerAnimationValueObserver dummy_impl; | 2634 FakeTypedLayerAnimationValueObserver dummy_impl; |
| 2564 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | |
| 2565 scoped_refptr<LayerAnimationController> controller_impl( | 2635 scoped_refptr<LayerAnimationController> controller_impl( |
| 2566 LayerAnimationController::Create(0)); | 2636 LayerAnimationController::Create(0)); |
| 2567 controller_impl->AddValueObserver(&dummy_impl); | 2637 controller_impl->SetValueObserver(&dummy_impl); |
| 2568 controller_impl->AddValueObserver(&pending_dummy_impl); | 2638 controller_impl->SetNeedsActiveValueObservations(true); |
| 2639 controller_impl->SetNeedsPendingValueObservations(true); |
| 2569 FakeLayerAnimationValueObserver dummy; | 2640 FakeLayerAnimationValueObserver dummy; |
| 2570 scoped_refptr<LayerAnimationController> controller( | 2641 scoped_refptr<LayerAnimationController> controller( |
| 2571 LayerAnimationController::Create(0)); | 2642 LayerAnimationController::Create(0)); |
| 2572 controller->AddValueObserver(&dummy); | 2643 controller->SetValueObserver(&dummy); |
| 2644 controller->SetNeedsActiveValueObservations(true); |
| 2573 | 2645 |
| 2574 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 2646 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 2575 int animation_id = | 2647 int animation_id = |
| 2576 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false); | 2648 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false); |
| 2577 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 2649 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 2578 | 2650 |
| 2579 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | 2651 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); |
| 2580 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2652 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2581 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); | 2653 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); |
| 2582 | 2654 |
| 2583 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 2655 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 2584 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 2656 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 2585 controller_impl->GetAnimationById(animation_id)->run_state()); | 2657 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2586 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2658 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2587 ->affects_pending_observers()); | 2659 ->affects_pending_observers()); |
| 2588 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | 2660 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) |
| 2589 ->affects_active_observers()); | 2661 ->affects_active_observers()); |
| 2590 | 2662 |
| 2591 controller_impl->Animate(kInitialTickTime); | 2663 controller_impl->Animate(kInitialTickTime); |
| 2592 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | 2664 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); |
| 2593 controller_impl->UpdateState(true, events.get()); | 2665 controller_impl->UpdateState(true, events.get()); |
| 2594 | 2666 |
| 2595 // Since the animation hasn't been activated, it should still be STARTING | 2667 // Since the animation hasn't been activated, it should still be STARTING |
| 2596 // rather than RUNNING. | 2668 // rather than RUNNING. |
| 2597 EXPECT_EQ(Animation::STARTING, | 2669 EXPECT_EQ(Animation::STARTING, |
| 2598 controller_impl->GetAnimationById(animation_id)->run_state()); | 2670 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2599 | 2671 |
| 2600 // Since the animation hasn't been activated, only the pending observer | 2672 // Since the animation hasn't been activated, only the pending observer |
| 2601 // should have been ticked. | 2673 // should have been ticked. |
| 2602 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2674 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2603 EXPECT_EQ(0.f, dummy_impl.opacity()); | 2675 EXPECT_EQ(0.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2604 | 2676 |
| 2605 controller_impl->ActivateAnimations(); | 2677 controller_impl->ActivateAnimations(); |
| 2606 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2678 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2607 ->affects_pending_observers()); | 2679 ->affects_pending_observers()); |
| 2608 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2680 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2609 ->affects_active_observers()); | 2681 ->affects_active_observers()); |
| 2610 | 2682 |
| 2611 controller_impl->Animate(kInitialTickTime + | 2683 controller_impl->Animate(kInitialTickTime + |
| 2612 TimeDelta::FromMilliseconds(1000)); | 2684 TimeDelta::FromMilliseconds(1000)); |
| 2613 controller_impl->UpdateState(true, events.get()); | 2685 controller_impl->UpdateState(true, events.get()); |
| 2614 | 2686 |
| 2615 // Since the animation has been activated, it should have reached the | 2687 // Since the animation has been activated, it should have reached the |
| 2616 // RUNNING state and the active observer should start to get ticked. | 2688 // RUNNING state and the active observer should start to get ticked. |
| 2617 EXPECT_EQ(Animation::RUNNING, | 2689 EXPECT_EQ(Animation::RUNNING, |
| 2618 controller_impl->GetAnimationById(animation_id)->run_state()); | 2690 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2619 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2691 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2620 EXPECT_EQ(0.5f, dummy_impl.opacity()); | 2692 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2621 } | 2693 } |
| 2622 | 2694 |
| 2623 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { | 2695 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { |
| 2624 std::unique_ptr<AnimationEvents> events( | 2696 std::unique_ptr<AnimationEvents> events( |
| 2625 base::WrapUnique(new AnimationEvents)); | 2697 base::WrapUnique(new AnimationEvents)); |
| 2626 FakeLayerAnimationValueObserver dummy_impl; | 2698 FakeTypedLayerAnimationValueObserver dummy_impl; |
| 2627 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | |
| 2628 scoped_refptr<LayerAnimationController> controller_impl( | 2699 scoped_refptr<LayerAnimationController> controller_impl( |
| 2629 LayerAnimationController::Create(0)); | 2700 LayerAnimationController::Create(0)); |
| 2630 controller_impl->AddValueObserver(&dummy_impl); | 2701 controller_impl->SetValueObserver(&dummy_impl); |
| 2631 controller_impl->AddValueObserver(&pending_dummy_impl); | 2702 controller_impl->SetNeedsActiveValueObservations(true); |
| 2703 controller_impl->SetNeedsPendingValueObservations(true); |
| 2704 |
| 2632 FakeLayerAnimationValueObserver dummy; | 2705 FakeLayerAnimationValueObserver dummy; |
| 2633 scoped_refptr<LayerAnimationController> controller( | 2706 scoped_refptr<LayerAnimationController> controller( |
| 2634 LayerAnimationController::Create(0)); | 2707 LayerAnimationController::Create(0)); |
| 2635 controller->AddValueObserver(&dummy); | 2708 controller->SetValueObserver(&dummy); |
| 2709 controller->SetNeedsActiveValueObservations(true); |
| 2636 | 2710 |
| 2637 int animation_id = | 2711 int animation_id = |
| 2638 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); | 2712 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); |
| 2639 | 2713 |
| 2640 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2714 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2641 | 2715 |
| 2642 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 2716 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 2643 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 2717 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 2644 controller_impl->GetAnimationById(animation_id)->run_state()); | 2718 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2645 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2719 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2646 ->affects_pending_observers()); | 2720 ->affects_pending_observers()); |
| 2647 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | 2721 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) |
| 2648 ->affects_active_observers()); | 2722 ->affects_active_observers()); |
| 2649 | 2723 |
| 2650 controller_impl->Animate(kInitialTickTime); | 2724 controller_impl->Animate(kInitialTickTime); |
| 2651 | 2725 |
| 2652 // Since the animation hasn't been activated, only the pending observer | 2726 // Since the animation hasn't been activated, only the pending observer |
| 2653 // should have been ticked. | 2727 // should have been ticked. |
| 2654 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2728 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2655 EXPECT_EQ(0.f, dummy_impl.opacity()); | 2729 EXPECT_EQ(0.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2656 | 2730 |
| 2657 controller_impl->ActivateAnimations(); | 2731 controller_impl->ActivateAnimations(); |
| 2658 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2732 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2659 ->affects_pending_observers()); | 2733 ->affects_pending_observers()); |
| 2660 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2734 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2661 ->affects_active_observers()); | 2735 ->affects_active_observers()); |
| 2662 | 2736 |
| 2663 controller_impl->UpdateState(true, events.get()); | 2737 controller_impl->UpdateState(true, events.get()); |
| 2664 | 2738 |
| 2665 // Since the animation has been activated, it should have reached the | 2739 // Since the animation has been activated, it should have reached the |
| 2666 // RUNNING state. | 2740 // RUNNING state. |
| 2667 EXPECT_EQ(Animation::RUNNING, | 2741 EXPECT_EQ(Animation::RUNNING, |
| 2668 controller_impl->GetAnimationById(animation_id)->run_state()); | 2742 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2669 | 2743 |
| 2670 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2744 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 2671 | 2745 |
| 2672 // Both observers should have been ticked. | 2746 // Both observers should have been ticked. |
| 2673 EXPECT_EQ(0.75f, pending_dummy_impl.opacity()); | 2747 EXPECT_EQ(0.75f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2674 EXPECT_EQ(0.75f, dummy_impl.opacity()); | 2748 EXPECT_EQ(0.75f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2675 } | 2749 } |
| 2676 | 2750 |
| 2677 TEST(LayerAnimationControllerTest, | 2751 TEST(LayerAnimationControllerTest, |
| 2678 ObserverNotifiedWhenTransformIsPotentiallyAnimatingChanges) { | 2752 ObserverNotifiedWhenTransformIsPotentiallyAnimatingChanges) { |
| 2679 AnimationEvents events; | 2753 AnimationEvents events; |
| 2680 FakeLayerAnimationValueObserver active_dummy_impl; | 2754 FakeTypedLayerAnimationValueObserver dummy_impl; |
| 2681 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | |
| 2682 scoped_refptr<LayerAnimationController> controller_impl( | 2755 scoped_refptr<LayerAnimationController> controller_impl( |
| 2683 LayerAnimationController::Create(0)); | 2756 LayerAnimationController::Create(0)); |
| 2684 controller_impl->AddValueObserver(&active_dummy_impl); | 2757 controller_impl->SetValueObserver(&dummy_impl); |
| 2685 controller_impl->AddValueObserver(&pending_dummy_impl); | 2758 controller_impl->SetNeedsActiveValueObservations(true); |
| 2759 controller_impl->SetNeedsPendingValueObservations(true); |
| 2760 |
| 2686 FakeLayerAnimationValueObserver dummy; | 2761 FakeLayerAnimationValueObserver dummy; |
| 2687 scoped_refptr<LayerAnimationController> controller( | 2762 scoped_refptr<LayerAnimationController> controller( |
| 2688 LayerAnimationController::Create(0)); | 2763 LayerAnimationController::Create(0)); |
| 2689 controller->AddValueObserver(&dummy); | 2764 controller->SetValueObserver(&dummy); |
| 2765 controller->SetNeedsActiveValueObservations(true); |
| 2690 | 2766 |
| 2691 EXPECT_FALSE(dummy.transform_is_animating()); | 2767 EXPECT_FALSE(dummy.transform_is_animating()); |
| 2692 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2768 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2693 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2769 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2694 | 2770 |
| 2695 // Case 1: An animation that's allowed to run until its finish point. | 2771 // Case 1: An animation that's allowed to run until its finish point. |
| 2696 AddAnimatedTransformToController(controller.get(), 1.0, 1, 1); | 2772 AddAnimatedTransformToController(controller.get(), 1.0, 1, 1); |
| 2697 EXPECT_TRUE(dummy.transform_is_animating()); | 2773 EXPECT_TRUE(dummy.transform_is_animating()); |
| 2698 | 2774 |
| 2699 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2775 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2700 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2776 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2701 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2777 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2702 | 2778 |
| 2703 controller_impl->ActivateAnimations(); | 2779 controller_impl->ActivateAnimations(); |
| 2704 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2780 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2705 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2781 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2706 | 2782 |
| 2707 controller_impl->Animate(kInitialTickTime); | 2783 controller_impl->Animate(kInitialTickTime); |
| 2708 controller_impl->UpdateState(true, &events); | 2784 controller_impl->UpdateState(true, &events); |
| 2709 | 2785 |
| 2710 controller->NotifyAnimationStarted(events.events_[0]); | 2786 controller->NotifyAnimationStarted(events.events_[0]); |
| 2711 events.events_.clear(); | 2787 events.events_.clear(); |
| 2712 | 2788 |
| 2713 // Finish the animation. | 2789 // Finish the animation. |
| 2714 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2790 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 2715 controller->UpdateState(true, nullptr); | 2791 controller->UpdateState(true, nullptr); |
| 2716 EXPECT_FALSE(dummy.transform_is_animating()); | 2792 EXPECT_FALSE(dummy.transform_is_animating()); |
| 2717 | 2793 |
| 2718 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2794 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2719 | 2795 |
| 2720 // controller_impl hasn't yet ticked at/past the end of the animation. | 2796 // controller_impl hasn't yet ticked at/past the end of the animation. |
| 2721 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2797 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2722 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2798 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2723 | 2799 |
| 2724 controller_impl->Animate(kInitialTickTime + | 2800 controller_impl->Animate(kInitialTickTime + |
| 2725 TimeDelta::FromMilliseconds(1000)); | 2801 TimeDelta::FromMilliseconds(1000)); |
| 2726 controller_impl->UpdateState(true, &events); | 2802 controller_impl->UpdateState(true, &events); |
| 2727 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2803 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2728 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2804 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2729 | 2805 |
| 2730 controller->NotifyAnimationFinished(events.events_[0]); | 2806 controller->NotifyAnimationFinished(events.events_[0]); |
| 2731 events.events_.clear(); | 2807 events.events_.clear(); |
| 2732 | 2808 |
| 2733 // Case 2: An animation that's removed before it finishes. | 2809 // Case 2: An animation that's removed before it finishes. |
| 2734 int animation_id = | 2810 int animation_id = |
| 2735 AddAnimatedTransformToController(controller.get(), 10.0, 2, 2); | 2811 AddAnimatedTransformToController(controller.get(), 10.0, 2, 2); |
| 2736 EXPECT_TRUE(dummy.transform_is_animating()); | 2812 EXPECT_TRUE(dummy.transform_is_animating()); |
| 2737 | 2813 |
| 2738 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2814 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2739 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2815 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2740 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2816 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2741 | 2817 |
| 2742 controller_impl->ActivateAnimations(); | 2818 controller_impl->ActivateAnimations(); |
| 2743 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2819 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2744 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2820 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2745 | 2821 |
| 2746 controller_impl->Animate(kInitialTickTime + | 2822 controller_impl->Animate(kInitialTickTime + |
| 2747 TimeDelta::FromMilliseconds(2000)); | 2823 TimeDelta::FromMilliseconds(2000)); |
| 2748 controller_impl->UpdateState(true, &events); | 2824 controller_impl->UpdateState(true, &events); |
| 2749 | 2825 |
| 2750 controller->NotifyAnimationStarted(events.events_[0]); | 2826 controller->NotifyAnimationStarted(events.events_[0]); |
| 2751 events.events_.clear(); | 2827 events.events_.clear(); |
| 2752 | 2828 |
| 2753 controller->RemoveAnimation(animation_id); | 2829 controller->RemoveAnimation(animation_id); |
| 2754 EXPECT_FALSE(dummy.transform_is_animating()); | 2830 EXPECT_FALSE(dummy.transform_is_animating()); |
| 2755 | 2831 |
| 2756 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2832 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2757 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2833 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2758 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2834 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2759 | 2835 |
| 2760 controller_impl->ActivateAnimations(); | 2836 controller_impl->ActivateAnimations(); |
| 2761 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2837 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2762 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2838 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2763 | 2839 |
| 2764 // Case 3: An animation that's aborted before it finishes. | 2840 // Case 3: An animation that's aborted before it finishes. |
| 2765 animation_id = AddAnimatedTransformToController(controller.get(), 10.0, 3, 3); | 2841 animation_id = AddAnimatedTransformToController(controller.get(), 10.0, 3, 3); |
| 2766 EXPECT_TRUE(dummy.transform_is_animating()); | 2842 EXPECT_TRUE(dummy.transform_is_animating()); |
| 2767 | 2843 |
| 2768 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2844 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2769 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2845 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2770 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2846 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2771 | 2847 |
| 2772 controller_impl->ActivateAnimations(); | 2848 controller_impl->ActivateAnimations(); |
| 2773 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2849 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2774 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2850 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2775 | 2851 |
| 2776 controller_impl->Animate(kInitialTickTime + | 2852 controller_impl->Animate(kInitialTickTime + |
| 2777 TimeDelta::FromMilliseconds(3000)); | 2853 TimeDelta::FromMilliseconds(3000)); |
| 2778 controller_impl->UpdateState(true, &events); | 2854 controller_impl->UpdateState(true, &events); |
| 2779 | 2855 |
| 2780 controller->NotifyAnimationStarted(events.events_[0]); | 2856 controller->NotifyAnimationStarted(events.events_[0]); |
| 2781 events.events_.clear(); | 2857 events.events_.clear(); |
| 2782 | 2858 |
| 2783 controller_impl->AbortAnimations(TargetProperty::TRANSFORM); | 2859 controller_impl->AbortAnimations(TargetProperty::TRANSFORM); |
| 2784 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2860 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2785 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2861 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2786 | 2862 |
| 2787 controller_impl->Animate(kInitialTickTime + | 2863 controller_impl->Animate(kInitialTickTime + |
| 2788 TimeDelta::FromMilliseconds(4000)); | 2864 TimeDelta::FromMilliseconds(4000)); |
| 2789 controller_impl->UpdateState(true, &events); | 2865 controller_impl->UpdateState(true, &events); |
| 2790 | 2866 |
| 2791 controller->NotifyAnimationAborted(events.events_[0]); | 2867 controller->NotifyAnimationAborted(events.events_[0]); |
| 2792 EXPECT_FALSE(dummy.transform_is_animating()); | 2868 EXPECT_FALSE(dummy.transform_is_animating()); |
| 2793 } | 2869 } |
| 2794 | 2870 |
| 2795 TEST(LayerAnimationControllerTest, ClippedOpacityValues) { | 2871 TEST(LayerAnimationControllerTest, ClippedOpacityValues) { |
| 2796 FakeLayerAnimationValueObserver dummy; | 2872 FakeLayerAnimationValueObserver dummy; |
| 2797 scoped_refptr<LayerAnimationController> controller( | 2873 scoped_refptr<LayerAnimationController> controller( |
| 2798 LayerAnimationController::Create(0)); | 2874 LayerAnimationController::Create(0)); |
| 2799 controller->AddValueObserver(&dummy); | 2875 controller->SetValueObserver(&dummy); |
| 2876 controller->SetNeedsActiveValueObservations(true); |
| 2800 | 2877 |
| 2801 AddOpacityTransitionToController(controller.get(), 1, 1.f, 2.f, true); | 2878 AddOpacityTransitionToController(controller.get(), 1, 1.f, 2.f, true); |
| 2802 | 2879 |
| 2803 controller->Animate(kInitialTickTime); | 2880 controller->Animate(kInitialTickTime); |
| 2804 EXPECT_EQ(1.f, dummy.opacity()); | 2881 EXPECT_EQ(1.f, dummy.opacity()); |
| 2805 | 2882 |
| 2806 // Opacity values are clipped [0,1] | 2883 // Opacity values are clipped [0,1] |
| 2807 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2884 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 2808 EXPECT_EQ(1.f, dummy.opacity()); | 2885 EXPECT_EQ(1.f, dummy.opacity()); |
| 2809 } | 2886 } |
| 2810 | 2887 |
| 2811 TEST(LayerAnimationControllerTest, ClippedNegativeOpacityValues) { | 2888 TEST(LayerAnimationControllerTest, ClippedNegativeOpacityValues) { |
| 2812 FakeLayerAnimationValueObserver dummy; | 2889 FakeLayerAnimationValueObserver dummy; |
| 2813 scoped_refptr<LayerAnimationController> controller( | 2890 scoped_refptr<LayerAnimationController> controller( |
| 2814 LayerAnimationController::Create(0)); | 2891 LayerAnimationController::Create(0)); |
| 2815 controller->AddValueObserver(&dummy); | 2892 controller->SetValueObserver(&dummy); |
| 2893 controller->SetNeedsActiveValueObservations(true); |
| 2816 | 2894 |
| 2817 AddOpacityTransitionToController(controller.get(), 1, 0.f, -2.f, true); | 2895 AddOpacityTransitionToController(controller.get(), 1, 0.f, -2.f, true); |
| 2818 | 2896 |
| 2819 controller->Animate(kInitialTickTime); | 2897 controller->Animate(kInitialTickTime); |
| 2820 EXPECT_EQ(0.f, dummy.opacity()); | 2898 EXPECT_EQ(0.f, dummy.opacity()); |
| 2821 | 2899 |
| 2822 // Opacity values are clipped [0,1] | 2900 // Opacity values are clipped [0,1] |
| 2823 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2901 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 2824 EXPECT_EQ(0.f, dummy.opacity()); | 2902 EXPECT_EQ(0.f, dummy.opacity()); |
| 2825 } | 2903 } |
| 2826 | 2904 |
| 2827 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) { | 2905 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) { |
| 2828 std::unique_ptr<AnimationEvents> events( | 2906 std::unique_ptr<AnimationEvents> events( |
| 2829 base::WrapUnique(new AnimationEvents)); | 2907 base::WrapUnique(new AnimationEvents)); |
| 2830 FakeLayerAnimationValueObserver dummy_impl; | 2908 FakeTypedLayerAnimationValueObserver dummy_impl; |
| 2831 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | |
| 2832 scoped_refptr<LayerAnimationController> controller_impl( | 2909 scoped_refptr<LayerAnimationController> controller_impl( |
| 2833 LayerAnimationController::Create(0)); | 2910 LayerAnimationController::Create(0)); |
| 2834 controller_impl->AddValueObserver(&dummy_impl); | 2911 controller_impl->SetValueObserver(&dummy_impl); |
| 2835 controller_impl->AddValueObserver(&pending_dummy_impl); | 2912 controller_impl->SetNeedsActiveValueObservations(true); |
| 2913 controller_impl->SetNeedsPendingValueObservations(true); |
| 2914 |
| 2836 FakeLayerAnimationValueObserver dummy; | 2915 FakeLayerAnimationValueObserver dummy; |
| 2837 scoped_refptr<LayerAnimationController> controller( | 2916 scoped_refptr<LayerAnimationController> controller( |
| 2838 LayerAnimationController::Create(0)); | 2917 LayerAnimationController::Create(0)); |
| 2839 controller->AddValueObserver(&dummy); | 2918 controller->SetValueObserver(&dummy); |
| 2919 controller->SetNeedsActiveValueObservations(true); |
| 2840 | 2920 |
| 2841 int animation_id = | 2921 int animation_id = |
| 2842 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); | 2922 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); |
| 2843 | 2923 |
| 2844 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2924 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2845 controller_impl->ActivateAnimations(); | 2925 controller_impl->ActivateAnimations(); |
| 2846 controller_impl->Animate(kInitialTickTime); | 2926 controller_impl->Animate(kInitialTickTime); |
| 2847 controller_impl->UpdateState(true, events.get()); | 2927 controller_impl->UpdateState(true, events.get()); |
| 2848 EXPECT_EQ(Animation::RUNNING, | 2928 EXPECT_EQ(Animation::RUNNING, |
| 2849 controller_impl->GetAnimationById(animation_id)->run_state()); | 2929 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2850 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2930 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2851 EXPECT_EQ(0.5f, dummy_impl.opacity()); | 2931 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2852 | 2932 |
| 2853 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2933 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2854 ->affects_pending_observers()); | 2934 ->affects_pending_observers()); |
| 2855 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2935 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2856 ->affects_active_observers()); | 2936 ->affects_active_observers()); |
| 2857 | 2937 |
| 2858 // Delete the animation on the main-thread controller. | 2938 // Delete the animation on the main-thread controller. |
| 2859 controller->RemoveAnimation( | 2939 controller->RemoveAnimation( |
| 2860 controller->GetAnimation(TargetProperty::OPACITY)->id()); | 2940 controller->GetAnimation(TargetProperty::OPACITY)->id()); |
| 2861 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2941 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2862 | 2942 |
| 2863 // The animation should no longer affect pending observers. | 2943 // The animation should no longer affect pending observers. |
| 2864 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | 2944 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) |
| 2865 ->affects_pending_observers()); | 2945 ->affects_pending_observers()); |
| 2866 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2946 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2867 ->affects_active_observers()); | 2947 ->affects_active_observers()); |
| 2868 | 2948 |
| 2869 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2949 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 2870 controller_impl->UpdateState(true, events.get()); | 2950 controller_impl->UpdateState(true, events.get()); |
| 2871 | 2951 |
| 2872 // Only the active observer should have been ticked. | 2952 // Only the active observer should have been ticked. |
| 2873 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2953 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2874 EXPECT_EQ(0.75f, dummy_impl.opacity()); | 2954 EXPECT_EQ(0.75f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2875 | 2955 |
| 2876 controller_impl->ActivateAnimations(); | 2956 controller_impl->ActivateAnimations(); |
| 2877 | 2957 |
| 2878 // Activation should cause the animation to be deleted. | 2958 // Activation should cause the animation to be deleted. |
| 2879 EXPECT_FALSE(controller_impl->has_any_animation()); | 2959 EXPECT_FALSE(controller_impl->has_any_animation()); |
| 2880 } | 2960 } |
| 2881 | 2961 |
| 2882 // Tests that an animation that affects only active observers won't block | 2962 // Tests that an animation that affects only active observers won't block |
| 2883 // an animation that affects only pending observers from starting. | 2963 // an animation that affects only pending observers from starting. |
| 2884 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) { | 2964 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) { |
| 2885 std::unique_ptr<AnimationEvents> events( | 2965 std::unique_ptr<AnimationEvents> events( |
| 2886 base::WrapUnique(new AnimationEvents)); | 2966 base::WrapUnique(new AnimationEvents)); |
| 2887 FakeLayerAnimationValueObserver dummy_impl; | 2967 FakeTypedLayerAnimationValueObserver dummy_impl; |
| 2888 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | |
| 2889 scoped_refptr<LayerAnimationController> controller_impl( | 2968 scoped_refptr<LayerAnimationController> controller_impl( |
| 2890 LayerAnimationController::Create(0)); | 2969 LayerAnimationController::Create(0)); |
| 2891 controller_impl->AddValueObserver(&dummy_impl); | 2970 controller_impl->SetValueObserver(&dummy_impl); |
| 2892 controller_impl->AddValueObserver(&pending_dummy_impl); | 2971 controller_impl->SetNeedsActiveValueObservations(true); |
| 2972 controller_impl->SetNeedsPendingValueObservations(true); |
| 2973 |
| 2893 FakeLayerAnimationValueObserver dummy; | 2974 FakeLayerAnimationValueObserver dummy; |
| 2894 scoped_refptr<LayerAnimationController> controller( | 2975 scoped_refptr<LayerAnimationController> controller( |
| 2895 LayerAnimationController::Create(0)); | 2976 LayerAnimationController::Create(0)); |
| 2896 controller->AddValueObserver(&dummy); | 2977 controller->SetValueObserver(&dummy); |
| 2978 controller->SetNeedsActiveValueObservations(true); |
| 2897 | 2979 |
| 2898 int first_animation_id = | 2980 int first_animation_id = |
| 2899 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true); | 2981 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true); |
| 2900 | 2982 |
| 2901 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2983 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2902 controller_impl->ActivateAnimations(); | 2984 controller_impl->ActivateAnimations(); |
| 2903 controller_impl->Animate(kInitialTickTime); | 2985 controller_impl->Animate(kInitialTickTime); |
| 2904 controller_impl->UpdateState(true, events.get()); | 2986 controller_impl->UpdateState(true, events.get()); |
| 2905 | 2987 |
| 2906 // Remove the first animation from the main-thread controller, and add a | 2988 // Remove the first animation from the main-thread controller, and add a |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2928 // The original animation should still be running, and the new animation | 3010 // The original animation should still be running, and the new animation |
| 2929 // should be starting. | 3011 // should be starting. |
| 2930 EXPECT_EQ(Animation::RUNNING, | 3012 EXPECT_EQ(Animation::RUNNING, |
| 2931 controller_impl->GetAnimationById(first_animation_id)->run_state()); | 3013 controller_impl->GetAnimationById(first_animation_id)->run_state()); |
| 2932 EXPECT_EQ( | 3014 EXPECT_EQ( |
| 2933 Animation::STARTING, | 3015 Animation::STARTING, |
| 2934 controller_impl->GetAnimationById(second_animation_id)->run_state()); | 3016 controller_impl->GetAnimationById(second_animation_id)->run_state()); |
| 2935 | 3017 |
| 2936 // The active observer should have been ticked by the original animation, | 3018 // The active observer should have been ticked by the original animation, |
| 2937 // and the pending observer should have been ticked by the new animation. | 3019 // and the pending observer should have been ticked by the new animation. |
| 2938 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); | 3020 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2939 EXPECT_EQ(0.5f, dummy_impl.opacity()); | 3021 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2940 | 3022 |
| 2941 controller_impl->ActivateAnimations(); | 3023 controller_impl->ActivateAnimations(); |
| 2942 | 3024 |
| 2943 // The original animation should have been deleted, and the new animation | 3025 // The original animation should have been deleted, and the new animation |
| 2944 // should now affect both observers. | 3026 // should now affect both observers. |
| 2945 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id)); | 3027 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id)); |
| 2946 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) | 3028 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) |
| 2947 ->affects_pending_observers()); | 3029 ->affects_pending_observers()); |
| 2948 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) | 3030 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) |
| 2949 ->affects_active_observers()); | 3031 ->affects_active_observers()); |
| 2950 | 3032 |
| 2951 controller_impl->Animate(kInitialTickTime + | 3033 controller_impl->Animate(kInitialTickTime + |
| 2952 TimeDelta::FromMilliseconds(1000)); | 3034 TimeDelta::FromMilliseconds(1000)); |
| 2953 controller_impl->UpdateState(true, events.get()); | 3035 controller_impl->UpdateState(true, events.get()); |
| 2954 | 3036 |
| 2955 // The new animation should be running, and the active observer should have | 3037 // The new animation should be running, and the active observer should have |
| 2956 // been ticked at the new animation's starting point. | 3038 // been ticked at the new animation's starting point. |
| 2957 EXPECT_EQ( | 3039 EXPECT_EQ( |
| 2958 Animation::RUNNING, | 3040 Animation::RUNNING, |
| 2959 controller_impl->GetAnimationById(second_animation_id)->run_state()); | 3041 controller_impl->GetAnimationById(second_animation_id)->run_state()); |
| 2960 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); | 3042 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2961 EXPECT_EQ(1.f, dummy_impl.opacity()); | 3043 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2962 } | 3044 } |
| 2963 | 3045 |
| 2964 TEST(LayerAnimationControllerTest, TestIsCurrentlyAnimatingProperty) { | 3046 TEST(LayerAnimationControllerTest, TestIsCurrentlyAnimatingProperty) { |
| 2965 FakeLayerAnimationValueObserver dummy; | 3047 FakeLayerAnimationValueObserver dummy; |
| 2966 scoped_refptr<LayerAnimationController> controller( | 3048 scoped_refptr<LayerAnimationController> controller( |
| 2967 LayerAnimationController::Create(0)); | 3049 LayerAnimationController::Create(0)); |
| 2968 controller->AddValueObserver(&dummy); | 3050 controller->SetValueObserver(&dummy); |
| 3051 controller->SetNeedsActiveValueObservations(true); |
| 2969 | 3052 |
| 2970 // Create an animation that initially affects only pending observers. | 3053 // Create an animation that initially affects only pending observers. |
| 2971 std::unique_ptr<Animation> animation(CreateAnimation( | 3054 std::unique_ptr<Animation> animation(CreateAnimation( |
| 2972 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 3055 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 2973 1, TargetProperty::OPACITY)); | 3056 1, TargetProperty::OPACITY)); |
| 2974 animation->set_affects_active_observers(false); | 3057 animation->set_affects_active_observers(false); |
| 2975 | 3058 |
| 2976 controller->AddAnimation(std::move(animation)); | 3059 controller->AddAnimation(std::move(animation)); |
| 2977 controller->Animate(kInitialTickTime); | 3060 controller->Animate(kInitialTickTime); |
| 2978 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | 3061 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3034 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3117 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3035 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); | 3118 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); |
| 3036 | 3119 |
| 3037 EXPECT_EQ(1.f, dummy.opacity()); | 3120 EXPECT_EQ(1.f, dummy.opacity()); |
| 3038 } | 3121 } |
| 3039 | 3122 |
| 3040 TEST(LayerAnimationControllerTest, TestIsAnimatingPropertyTimeOffsetFillMode) { | 3123 TEST(LayerAnimationControllerTest, TestIsAnimatingPropertyTimeOffsetFillMode) { |
| 3041 FakeLayerAnimationValueObserver dummy; | 3124 FakeLayerAnimationValueObserver dummy; |
| 3042 scoped_refptr<LayerAnimationController> controller( | 3125 scoped_refptr<LayerAnimationController> controller( |
| 3043 LayerAnimationController::Create(0)); | 3126 LayerAnimationController::Create(0)); |
| 3044 controller->AddValueObserver(&dummy); | 3127 controller->SetValueObserver(&dummy); |
| 3128 controller->SetNeedsActiveValueObservations(true); |
| 3045 | 3129 |
| 3046 // Create an animation that initially affects only pending observers, and has | 3130 // Create an animation that initially affects only pending observers, and has |
| 3047 // a start delay of 2 seconds. | 3131 // a start delay of 2 seconds. |
| 3048 std::unique_ptr<Animation> animation(CreateAnimation( | 3132 std::unique_ptr<Animation> animation(CreateAnimation( |
| 3049 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 3133 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 3050 1, TargetProperty::OPACITY)); | 3134 1, TargetProperty::OPACITY)); |
| 3051 animation->set_fill_mode(Animation::FILL_MODE_NONE); | 3135 animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 3052 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); | 3136 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); |
| 3053 animation->set_affects_active_observers(false); | 3137 animation->set_affects_active_observers(false); |
| 3054 | 3138 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3121 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 3205 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3122 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3206 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3123 TargetProperty::OPACITY, | 3207 TargetProperty::OPACITY, |
| 3124 LayerAnimationController::ObserverType::PENDING)); | 3208 LayerAnimationController::ObserverType::PENDING)); |
| 3125 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3209 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3126 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 3210 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3127 } | 3211 } |
| 3128 | 3212 |
| 3129 } // namespace | 3213 } // namespace |
| 3130 } // namespace cc | 3214 } // namespace cc |
| OLD | NEW |