| 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->set_value_observer(&dummy_impl); |
| 52 controller_impl->set_needs_active_value_observations(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->set_value_observer(&dummy); |
| 58 controller_impl->set_needs_active_value_observations(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->set_value_observer(&dummy_impl); |
| 85 controller_impl->set_needs_active_value_observations(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->set_value_observer(&dummy); |
| 93 controller->set_needs_active_value_observations(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->set_value_observer(&dummy_impl); |
| 145 controller_impl->set_needs_active_value_observations(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->set_value_observer(&dummy); |
| 151 controller->set_needs_active_value_observations(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->set_value_observer(&dummy_impl); |
| 187 controller_impl->set_needs_active_value_observations(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->set_value_observer(&dummy); |
| 193 controller->set_needs_active_value_observations(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->set_value_observer(&dummy_impl); |
| 241 controller_impl->set_needs_active_value_observations(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->set_value_observer(&dummy); |
| 247 controller->set_needs_active_value_observations(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->set_value_observer(&dummy_impl); |
| 325 controller_impl->set_needs_active_value_observations(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->set_value_observer(&dummy); |
| 331 controller->set_needs_active_value_observations(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 16 matching lines...) Expand all Loading... |
| 339 | 358 |
| 340 controller->Animate(time); | 359 controller->Animate(time); |
| 341 controller->UpdateState(true, nullptr); | 360 controller->UpdateState(true, nullptr); |
| 342 controller->NotifyAnimationStarted(events.events_[0]); | 361 controller->NotifyAnimationStarted(events.events_[0]); |
| 343 | 362 |
| 344 EXPECT_EQ(Animation::RUNNING, | 363 EXPECT_EQ(Animation::RUNNING, |
| 345 controller_impl->GetAnimationById(animation_id)->run_state()); | 364 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 346 EXPECT_EQ(Animation::RUNNING, | 365 EXPECT_EQ(Animation::RUNNING, |
| 347 controller->GetAnimationById(animation_id)->run_state()); | 366 controller->GetAnimationById(animation_id)->run_state()); |
| 348 | 367 |
| 349 EXPECT_EQ(0.3f, dummy.opacity()); | 368 EXPECT_EQ(0.3f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 350 EXPECT_EQ(0.3f, dummy_impl.opacity()); | 369 EXPECT_EQ(0.3f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 351 | 370 |
| 352 EXPECT_EQ(kInitialTickTime, | 371 EXPECT_EQ(kInitialTickTime, |
| 353 controller->GetAnimationById(animation_id)->start_time()); | 372 controller->GetAnimationById(animation_id)->start_time()); |
| 354 EXPECT_EQ(kInitialTickTime, | 373 EXPECT_EQ(kInitialTickTime, |
| 355 controller_impl->GetAnimationById(animation_id)->start_time()); | 374 controller_impl->GetAnimationById(animation_id)->start_time()); |
| 356 | 375 |
| 357 // Pause the animation at the middle of the second range so the offset | 376 // Pause the animation at the middle of the second range so the offset |
| 358 // delays animation until the middle of the third range. | 377 // delays animation until the middle of the third range. |
| 359 controller->PauseAnimation(animation_id, TimeDelta::FromSecondsD(1.5)); | 378 controller->PauseAnimation(animation_id, TimeDelta::FromSecondsD(1.5)); |
| 360 EXPECT_EQ(Animation::PAUSED, | 379 EXPECT_EQ(Animation::PAUSED, |
| 361 controller->GetAnimationById(animation_id)->run_state()); | 380 controller->GetAnimationById(animation_id)->run_state()); |
| 362 | 381 |
| 363 // The pause run state change should make it to the impl thread controller. | 382 // The pause run state change should make it to the impl thread controller. |
| 364 controller->PushAnimationUpdatesTo(controller_impl.get()); | 383 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 365 controller_impl->ActivateAnimations(); | 384 controller_impl->ActivateAnimations(); |
| 366 | 385 |
| 367 // Advance time so it stays within the first range. | 386 // Advance time so it stays within the first range. |
| 368 time += TimeDelta::FromMilliseconds(10); | 387 time += TimeDelta::FromMilliseconds(10); |
| 369 controller->Animate(time); | 388 controller->Animate(time); |
| 370 controller_impl->Animate(time); | 389 controller_impl->Animate(time); |
| 371 | 390 |
| 372 EXPECT_EQ(Animation::PAUSED, | 391 EXPECT_EQ(Animation::PAUSED, |
| 373 controller_impl->GetAnimationById(animation_id)->run_state()); | 392 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 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(LayerTreeType::ACTIVE)); |
| 377 EXPECT_EQ(0.4f, dummy_impl.opacity()); | 396 EXPECT_EQ(0.4f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 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->set_value_observer(&dummy_impl); |
| 404 controller_impl->set_needs_active_value_observations(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->set_value_observer(&dummy); |
| 410 controller->set_needs_active_value_observations(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->set_value_observer(&dummy); |
| 443 controller_impl->AddValueObserver(&dummy_impl); | 466 controller->set_needs_active_value_observations(true); |
| 467 controller_impl->set_value_observer(&dummy_impl); |
| 468 controller_impl->set_needs_active_value_observations(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->set_value_observer(&dummy); |
| 540 controller->set_needs_active_value_observations(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()); |
| 525 controller->UpdateState(true, events.get()); | 551 controller->UpdateState(true, events.get()); |
| 526 EXPECT_TRUE(controller->HasActiveAnimation()); | 552 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 527 EXPECT_EQ(0.f, dummy.opacity()); | 553 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 528 // A non-impl-only animation should not generate property updates. | 554 // A non-impl-only animation should not generate property updates. |
| 529 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 555 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 530 EXPECT_FALSE(event); | 556 EXPECT_FALSE(event); |
| 531 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 557 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 532 controller->UpdateState(true, events.get()); | 558 controller->UpdateState(true, events.get()); |
| 533 EXPECT_EQ(1.f, dummy.opacity()); | 559 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 534 EXPECT_FALSE(controller->HasActiveAnimation()); | 560 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 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->set_value_observer(&dummy_impl); |
| 572 controller_impl->set_needs_active_value_observations(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()); |
| 556 EXPECT_EQ(0.f, dummy_impl.opacity()); | 583 EXPECT_EQ(0.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 557 EXPECT_EQ(1u, events->events_.size()); | 584 EXPECT_EQ(1u, events->events_.size()); |
| 558 const AnimationEvent* start_opacity_event = | 585 const AnimationEvent* start_opacity_event = |
| 559 GetMostRecentPropertyUpdateEvent(events.get()); | 586 GetMostRecentPropertyUpdateEvent(events.get()); |
| 560 EXPECT_EQ(0.f, start_opacity_event->opacity); | 587 EXPECT_EQ(0.f, start_opacity_event->opacity); |
| 561 | 588 |
| 562 controller_impl->Animate(kInitialTickTime + | 589 controller_impl->Animate(kInitialTickTime + |
| 563 TimeDelta::FromMilliseconds(1000)); | 590 TimeDelta::FromMilliseconds(1000)); |
| 564 controller_impl->UpdateState(true, events.get()); | 591 controller_impl->UpdateState(true, events.get()); |
| 565 EXPECT_EQ(1.f, dummy_impl.opacity()); | 592 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 566 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 593 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
| 567 EXPECT_EQ(2u, events->events_.size()); | 594 EXPECT_EQ(2u, events->events_.size()); |
| 568 const AnimationEvent* end_opacity_event = | 595 const AnimationEvent* end_opacity_event = |
| 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->set_value_observer(&dummy_impl); |
| 607 controller_impl->set_needs_active_value_observations(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. |
| 590 TransformOperations operations; | 618 TransformOperations operations; |
| 591 curve->AddKeyframe( | 619 curve->AddKeyframe( |
| 592 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr)); | 620 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr)); |
| 593 operations.AppendTranslate(delta_x, delta_y, 0); | 621 operations.AppendTranslate(delta_x, delta_y, 0); |
| 594 curve->AddKeyframe(TransformKeyframe::Create( | 622 curve->AddKeyframe(TransformKeyframe::Create( |
| 595 base::TimeDelta::FromSecondsD(1.0), operations, nullptr)); | 623 base::TimeDelta::FromSecondsD(1.0), operations, nullptr)); |
| 596 | 624 |
| 597 std::unique_ptr<Animation> animation( | 625 std::unique_ptr<Animation> animation( |
| 598 Animation::Create(std::move(curve), 1, 0, TargetProperty::TRANSFORM)); | 626 Animation::Create(std::move(curve), 1, 0, TargetProperty::TRANSFORM)); |
| 599 animation->set_is_impl_only(true); | 627 animation->set_is_impl_only(true); |
| 600 controller_impl->AddAnimation(std::move(animation)); | 628 controller_impl->AddAnimation(std::move(animation)); |
| 601 | 629 |
| 602 // Run animation. | 630 // Run animation. |
| 603 controller_impl->Animate(kInitialTickTime); | 631 controller_impl->Animate(kInitialTickTime); |
| 604 controller_impl->UpdateState(true, events.get()); | 632 controller_impl->UpdateState(true, events.get()); |
| 605 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 633 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 606 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); | 634 EXPECT_EQ(gfx::Transform(), dummy_impl.transform(LayerTreeType::ACTIVE)); |
| 607 EXPECT_EQ(1u, events->events_.size()); | 635 EXPECT_EQ(1u, events->events_.size()); |
| 608 const AnimationEvent* start_transform_event = | 636 const AnimationEvent* start_transform_event = |
| 609 GetMostRecentPropertyUpdateEvent(events.get()); | 637 GetMostRecentPropertyUpdateEvent(events.get()); |
| 610 ASSERT_TRUE(start_transform_event); | 638 ASSERT_TRUE(start_transform_event); |
| 611 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); | 639 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); |
| 612 EXPECT_TRUE(start_transform_event->is_impl_only); | 640 EXPECT_TRUE(start_transform_event->is_impl_only); |
| 613 | 641 |
| 614 gfx::Transform expected_transform; | 642 gfx::Transform expected_transform; |
| 615 expected_transform.Translate(delta_x, delta_y); | 643 expected_transform.Translate(delta_x, delta_y); |
| 616 | 644 |
| 617 controller_impl->Animate(kInitialTickTime + | 645 controller_impl->Animate(kInitialTickTime + |
| 618 TimeDelta::FromMilliseconds(1000)); | 646 TimeDelta::FromMilliseconds(1000)); |
| 619 controller_impl->UpdateState(true, events.get()); | 647 controller_impl->UpdateState(true, events.get()); |
| 620 EXPECT_EQ(expected_transform, dummy_impl.transform()); | 648 EXPECT_EQ(expected_transform, dummy_impl.transform(LayerTreeType::ACTIVE)); |
| 621 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 649 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
| 622 EXPECT_EQ(2u, events->events_.size()); | 650 EXPECT_EQ(2u, events->events_.size()); |
| 623 const AnimationEvent* end_transform_event = | 651 const AnimationEvent* end_transform_event = |
| 624 GetMostRecentPropertyUpdateEvent(events.get()); | 652 GetMostRecentPropertyUpdateEvent(events.get()); |
| 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->set_value_observer(&dummy); |
| 664 controller->set_needs_active_value_observations(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)); |
| 646 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 675 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
| 647 end_filters, nullptr)); | 676 end_filters, nullptr)); |
| 648 | 677 |
| 649 std::unique_ptr<Animation> animation( | 678 std::unique_ptr<Animation> animation( |
| 650 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); | 679 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); |
| 651 controller->AddAnimation(std::move(animation)); | 680 controller->AddAnimation(std::move(animation)); |
| 652 | 681 |
| 653 controller->Animate(kInitialTickTime); | 682 controller->Animate(kInitialTickTime); |
| 654 controller->UpdateState(true, events.get()); | 683 controller->UpdateState(true, events.get()); |
| 655 EXPECT_TRUE(controller->HasActiveAnimation()); | 684 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 656 EXPECT_EQ(start_filters, dummy.filters()); | 685 EXPECT_EQ(start_filters, dummy.filters(LayerTreeType::ACTIVE)); |
| 657 // A non-impl-only animation should not generate property updates. | 686 // A non-impl-only animation should not generate property updates. |
| 658 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 687 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 659 EXPECT_FALSE(event); | 688 EXPECT_FALSE(event); |
| 660 | 689 |
| 661 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 690 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 662 controller->UpdateState(true, events.get()); | 691 controller->UpdateState(true, events.get()); |
| 663 EXPECT_EQ(1u, dummy.filters().size()); | 692 EXPECT_EQ(1u, dummy.filters(LayerTreeType::ACTIVE).size()); |
| 664 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), | 693 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), |
| 665 dummy.filters().at(0)); | 694 dummy.filters(LayerTreeType::ACTIVE).at(0)); |
| 666 event = GetMostRecentPropertyUpdateEvent(events.get()); | 695 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 667 EXPECT_FALSE(event); | 696 EXPECT_FALSE(event); |
| 668 | 697 |
| 669 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 698 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 670 controller->UpdateState(true, events.get()); | 699 controller->UpdateState(true, events.get()); |
| 671 EXPECT_EQ(end_filters, dummy.filters()); | 700 EXPECT_EQ(end_filters, dummy.filters(LayerTreeType::ACTIVE)); |
| 672 EXPECT_FALSE(controller->HasActiveAnimation()); | 701 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 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->set_value_observer(&dummy_impl); |
| 713 controller_impl->set_needs_active_value_observations(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; |
| 694 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 724 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
| 695 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 725 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
| 696 end_filters, nullptr)); | 726 end_filters, nullptr)); |
| 697 | 727 |
| 698 std::unique_ptr<Animation> animation( | 728 std::unique_ptr<Animation> animation( |
| 699 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); | 729 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); |
| 700 animation->set_is_impl_only(true); | 730 animation->set_is_impl_only(true); |
| 701 controller_impl->AddAnimation(std::move(animation)); | 731 controller_impl->AddAnimation(std::move(animation)); |
| 702 | 732 |
| 703 // Run animation. | 733 // Run animation. |
| 704 controller_impl->Animate(kInitialTickTime); | 734 controller_impl->Animate(kInitialTickTime); |
| 705 controller_impl->UpdateState(true, events.get()); | 735 controller_impl->UpdateState(true, events.get()); |
| 706 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 736 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 707 EXPECT_EQ(start_filters, dummy_impl.filters()); | 737 EXPECT_EQ(start_filters, dummy_impl.filters(LayerTreeType::ACTIVE)); |
| 708 EXPECT_EQ(1u, events->events_.size()); | 738 EXPECT_EQ(1u, events->events_.size()); |
| 709 const AnimationEvent* start_filter_event = | 739 const AnimationEvent* start_filter_event = |
| 710 GetMostRecentPropertyUpdateEvent(events.get()); | 740 GetMostRecentPropertyUpdateEvent(events.get()); |
| 711 EXPECT_TRUE(start_filter_event); | 741 EXPECT_TRUE(start_filter_event); |
| 712 EXPECT_EQ(start_filters, start_filter_event->filters); | 742 EXPECT_EQ(start_filters, start_filter_event->filters); |
| 713 EXPECT_TRUE(start_filter_event->is_impl_only); | 743 EXPECT_TRUE(start_filter_event->is_impl_only); |
| 714 | 744 |
| 715 controller_impl->Animate(kInitialTickTime + | 745 controller_impl->Animate(kInitialTickTime + |
| 716 TimeDelta::FromMilliseconds(1000)); | 746 TimeDelta::FromMilliseconds(1000)); |
| 717 controller_impl->UpdateState(true, events.get()); | 747 controller_impl->UpdateState(true, events.get()); |
| 718 EXPECT_EQ(end_filters, dummy_impl.filters()); | 748 EXPECT_EQ(end_filters, dummy_impl.filters(LayerTreeType::ACTIVE)); |
| 719 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 749 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
| 720 EXPECT_EQ(2u, events->events_.size()); | 750 EXPECT_EQ(2u, events->events_.size()); |
| 721 const AnimationEvent* end_filter_event = | 751 const AnimationEvent* end_filter_event = |
| 722 GetMostRecentPropertyUpdateEvent(events.get()); | 752 GetMostRecentPropertyUpdateEvent(events.get()); |
| 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->set_value_observer(&dummy_impl); |
| 764 controller_impl->set_needs_active_value_observations(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->set_value_observer(&dummy); |
| 774 controller->set_needs_active_value_observations(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)); |
| 752 animation->set_needs_synchronized_start_time(true); | 785 animation->set_needs_synchronized_start_time(true); |
| 753 controller->AddAnimation(std::move(animation)); | 786 controller->AddAnimation(std::move(animation)); |
| 754 | 787 |
| 755 dummy_provider_impl.set_scroll_offset(initial_value); | 788 dummy_provider_impl.set_scroll_offset(initial_value); |
| 756 controller->PushAnimationUpdatesTo(controller_impl.get()); | 789 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 757 controller_impl->ActivateAnimations(); | 790 controller_impl->ActivateAnimations(); |
| 758 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); | 791 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); |
| 759 TimeDelta duration = | 792 TimeDelta duration = |
| 760 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 793 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) |
| 761 ->curve() | 794 ->curve() |
| 762 ->Duration(); | 795 ->Duration(); |
| 763 EXPECT_EQ(duration, controller->GetAnimation(TargetProperty::SCROLL_OFFSET) | 796 EXPECT_EQ(duration, controller->GetAnimation(TargetProperty::SCROLL_OFFSET) |
| 764 ->curve() | 797 ->curve() |
| 765 ->Duration()); | 798 ->Duration()); |
| 766 | 799 |
| 767 controller->Animate(kInitialTickTime); | 800 controller->Animate(kInitialTickTime); |
| 768 controller->UpdateState(true, nullptr); | 801 controller->UpdateState(true, nullptr); |
| 769 EXPECT_TRUE(controller->HasActiveAnimation()); | 802 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 770 EXPECT_EQ(initial_value, dummy.scroll_offset()); | 803 EXPECT_EQ(initial_value, dummy.scroll_offset(LayerTreeType::ACTIVE)); |
| 771 | 804 |
| 772 controller_impl->Animate(kInitialTickTime); | 805 controller_impl->Animate(kInitialTickTime); |
| 773 controller_impl->UpdateState(true, events.get()); | 806 controller_impl->UpdateState(true, events.get()); |
| 774 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 807 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 775 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 808 EXPECT_EQ(initial_value, dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); |
| 776 // Scroll offset animations should not generate property updates. | 809 // Scroll offset animations should not generate property updates. |
| 777 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 810 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 778 EXPECT_FALSE(event); | 811 EXPECT_FALSE(event); |
| 779 | 812 |
| 780 controller->NotifyAnimationStarted(events->events_[0]); | 813 controller->NotifyAnimationStarted(events->events_[0]); |
| 781 controller->Animate(kInitialTickTime + duration / 2); | 814 controller->Animate(kInitialTickTime + duration / 2); |
| 782 controller->UpdateState(true, nullptr); | 815 controller->UpdateState(true, nullptr); |
| 783 EXPECT_TRUE(controller->HasActiveAnimation()); | 816 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 784 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset()); | 817 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), |
| 818 dummy.scroll_offset(LayerTreeType::ACTIVE)); |
| 785 | 819 |
| 786 controller_impl->Animate(kInitialTickTime + duration / 2); | 820 controller_impl->Animate(kInitialTickTime + duration / 2); |
| 787 controller_impl->UpdateState(true, events.get()); | 821 controller_impl->UpdateState(true, events.get()); |
| 788 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | 822 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), |
| 789 dummy_impl.scroll_offset()); | 823 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); |
| 790 event = GetMostRecentPropertyUpdateEvent(events.get()); | 824 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 791 EXPECT_FALSE(event); | 825 EXPECT_FALSE(event); |
| 792 | 826 |
| 793 controller_impl->Animate(kInitialTickTime + duration); | 827 controller_impl->Animate(kInitialTickTime + duration); |
| 794 controller_impl->UpdateState(true, events.get()); | 828 controller_impl->UpdateState(true, events.get()); |
| 795 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | 829 EXPECT_VECTOR2DF_EQ(target_value, |
| 830 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); |
| 796 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 831 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
| 797 event = GetMostRecentPropertyUpdateEvent(events.get()); | 832 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 798 EXPECT_FALSE(event); | 833 EXPECT_FALSE(event); |
| 799 | 834 |
| 800 controller->Animate(kInitialTickTime + duration); | 835 controller->Animate(kInitialTickTime + duration); |
| 801 controller->UpdateState(true, nullptr); | 836 controller->UpdateState(true, nullptr); |
| 802 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); | 837 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset(LayerTreeType::ACTIVE)); |
| 803 EXPECT_FALSE(controller->HasActiveAnimation()); | 838 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 804 } | 839 } |
| 805 | 840 |
| 806 // Ensure that when the impl controller doesn't have a value provider, | 841 // 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 | 842 // the main-thread controller's value provider is used to obtain the intial |
| 808 // scroll offset. | 843 // scroll offset. |
| 809 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { | 844 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { |
| 810 FakeLayerAnimationValueObserver dummy_impl; | 845 FakeLayerAnimationValueObserver dummy_impl; |
| 811 scoped_refptr<LayerAnimationController> controller_impl( | 846 scoped_refptr<LayerAnimationController> controller_impl( |
| 812 LayerAnimationController::Create(0)); | 847 LayerAnimationController::Create(0)); |
| 813 controller_impl->AddValueObserver(&dummy_impl); | 848 controller_impl->set_value_observer(&dummy_impl); |
| 849 controller_impl->set_needs_active_value_observations(true); |
| 850 |
| 814 std::unique_ptr<AnimationEvents> events( | 851 std::unique_ptr<AnimationEvents> events( |
| 815 base::WrapUnique(new AnimationEvents)); | 852 base::WrapUnique(new AnimationEvents)); |
| 816 FakeLayerAnimationValueObserver dummy; | 853 FakeLayerAnimationValueObserver dummy; |
| 817 FakeLayerAnimationValueProvider dummy_provider; | 854 FakeLayerAnimationValueProvider dummy_provider; |
| 818 scoped_refptr<LayerAnimationController> controller( | 855 scoped_refptr<LayerAnimationController> controller( |
| 819 LayerAnimationController::Create(0)); | 856 LayerAnimationController::Create(0)); |
| 820 controller->AddValueObserver(&dummy); | 857 controller->set_value_observer(&dummy); |
| 858 controller->set_needs_active_value_observations(true); |
| 821 controller->set_value_provider(&dummy_provider); | 859 controller->set_value_provider(&dummy_provider); |
| 822 | 860 |
| 823 gfx::ScrollOffset initial_value(500.f, 100.f); | 861 gfx::ScrollOffset initial_value(500.f, 100.f); |
| 824 gfx::ScrollOffset target_value(300.f, 200.f); | 862 gfx::ScrollOffset target_value(300.f, 200.f); |
| 825 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 863 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 826 ScrollOffsetAnimationCurve::Create(target_value, | 864 ScrollOffsetAnimationCurve::Create(target_value, |
| 827 EaseInOutTimingFunction::Create())); | 865 EaseInOutTimingFunction::Create())); |
| 828 | 866 |
| 829 std::unique_ptr<Animation> animation( | 867 std::unique_ptr<Animation> animation( |
| 830 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 868 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
| 831 animation->set_needs_synchronized_start_time(true); | 869 animation->set_needs_synchronized_start_time(true); |
| 832 controller->AddAnimation(std::move(animation)); | 870 controller->AddAnimation(std::move(animation)); |
| 833 | 871 |
| 834 dummy_provider.set_scroll_offset(initial_value); | 872 dummy_provider.set_scroll_offset(initial_value); |
| 835 controller->PushAnimationUpdatesTo(controller_impl.get()); | 873 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 836 controller_impl->ActivateAnimations(); | 874 controller_impl->ActivateAnimations(); |
| 837 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); | 875 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); |
| 838 TimeDelta duration = | 876 TimeDelta duration = |
| 839 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 877 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) |
| 840 ->curve() | 878 ->curve() |
| 841 ->Duration(); | 879 ->Duration(); |
| 842 EXPECT_EQ(duration, controller->GetAnimation(TargetProperty::SCROLL_OFFSET) | 880 EXPECT_EQ(duration, controller->GetAnimation(TargetProperty::SCROLL_OFFSET) |
| 843 ->curve() | 881 ->curve() |
| 844 ->Duration()); | 882 ->Duration()); |
| 845 | 883 |
| 846 controller->Animate(kInitialTickTime); | 884 controller->Animate(kInitialTickTime); |
| 847 controller->UpdateState(true, nullptr); | 885 controller->UpdateState(true, nullptr); |
| 848 EXPECT_TRUE(controller->HasActiveAnimation()); | 886 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 849 EXPECT_EQ(initial_value, dummy.scroll_offset()); | 887 EXPECT_EQ(initial_value, dummy.scroll_offset(LayerTreeType::ACTIVE)); |
| 850 | 888 |
| 851 controller_impl->Animate(kInitialTickTime); | 889 controller_impl->Animate(kInitialTickTime); |
| 852 controller_impl->UpdateState(true, events.get()); | 890 controller_impl->UpdateState(true, events.get()); |
| 853 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 891 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 854 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 892 EXPECT_EQ(initial_value, dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); |
| 855 // Scroll offset animations should not generate property updates. | 893 // Scroll offset animations should not generate property updates. |
| 856 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 894 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 857 EXPECT_FALSE(event); | 895 EXPECT_FALSE(event); |
| 858 | 896 |
| 859 controller->NotifyAnimationStarted(events->events_[0]); | 897 controller->NotifyAnimationStarted(events->events_[0]); |
| 860 controller->Animate(kInitialTickTime + duration / 2); | 898 controller->Animate(kInitialTickTime + duration / 2); |
| 861 controller->UpdateState(true, nullptr); | 899 controller->UpdateState(true, nullptr); |
| 862 EXPECT_TRUE(controller->HasActiveAnimation()); | 900 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 863 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset()); | 901 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), |
| 902 dummy.scroll_offset(LayerTreeType::ACTIVE)); |
| 864 | 903 |
| 865 controller_impl->Animate(kInitialTickTime + duration / 2); | 904 controller_impl->Animate(kInitialTickTime + duration / 2); |
| 866 controller_impl->UpdateState(true, events.get()); | 905 controller_impl->UpdateState(true, events.get()); |
| 867 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), | 906 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), |
| 868 dummy_impl.scroll_offset()); | 907 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); |
| 869 event = GetMostRecentPropertyUpdateEvent(events.get()); | 908 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 870 EXPECT_FALSE(event); | 909 EXPECT_FALSE(event); |
| 871 | 910 |
| 872 controller_impl->Animate(kInitialTickTime + duration); | 911 controller_impl->Animate(kInitialTickTime + duration); |
| 873 controller_impl->UpdateState(true, events.get()); | 912 controller_impl->UpdateState(true, events.get()); |
| 874 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | 913 EXPECT_VECTOR2DF_EQ(target_value, |
| 914 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); |
| 875 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 915 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
| 876 event = GetMostRecentPropertyUpdateEvent(events.get()); | 916 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 877 EXPECT_FALSE(event); | 917 EXPECT_FALSE(event); |
| 878 | 918 |
| 879 controller->Animate(kInitialTickTime + duration); | 919 controller->Animate(kInitialTickTime + duration); |
| 880 controller->UpdateState(true, nullptr); | 920 controller->UpdateState(true, nullptr); |
| 881 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); | 921 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset(LayerTreeType::ACTIVE)); |
| 882 EXPECT_FALSE(controller->HasActiveAnimation()); | 922 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 883 } | 923 } |
| 884 | 924 |
| 885 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { | 925 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { |
| 886 FakeLayerAnimationValueObserver dummy_impl; | 926 FakeLayerAnimationValueObserver dummy_impl; |
| 887 scoped_refptr<LayerAnimationController> controller_impl( | 927 scoped_refptr<LayerAnimationController> controller_impl( |
| 888 LayerAnimationController::Create(0)); | 928 LayerAnimationController::Create(0)); |
| 889 controller_impl->AddValueObserver(&dummy_impl); | 929 controller_impl->set_value_observer(&dummy_impl); |
| 930 controller_impl->set_needs_active_value_observations(true); |
| 890 std::unique_ptr<AnimationEvents> events( | 931 std::unique_ptr<AnimationEvents> events( |
| 891 base::WrapUnique(new AnimationEvents)); | 932 base::WrapUnique(new AnimationEvents)); |
| 892 | 933 |
| 893 gfx::ScrollOffset initial_value(100.f, 300.f); | 934 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 894 gfx::ScrollOffset target_value(300.f, 200.f); | 935 gfx::ScrollOffset target_value(300.f, 200.f); |
| 895 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 936 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 896 ScrollOffsetAnimationCurve::Create(target_value, | 937 ScrollOffsetAnimationCurve::Create(target_value, |
| 897 EaseInOutTimingFunction::Create())); | 938 EaseInOutTimingFunction::Create())); |
| 898 curve->SetInitialValue(initial_value); | 939 curve->SetInitialValue(initial_value); |
| 899 double duration_in_seconds = curve->Duration().InSecondsF(); | 940 double duration_in_seconds = curve->Duration().InSecondsF(); |
| 900 | 941 |
| 901 std::unique_ptr<Animation> animation( | 942 std::unique_ptr<Animation> animation( |
| 902 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 943 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
| 903 animation->set_is_impl_only(true); | 944 animation->set_is_impl_only(true); |
| 904 controller_impl->AddAnimation(std::move(animation)); | 945 controller_impl->AddAnimation(std::move(animation)); |
| 905 | 946 |
| 906 controller_impl->Animate(kInitialTickTime); | 947 controller_impl->Animate(kInitialTickTime); |
| 907 controller_impl->UpdateState(true, events.get()); | 948 controller_impl->UpdateState(true, events.get()); |
| 908 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | 949 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
| 909 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | 950 EXPECT_EQ(initial_value, dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); |
| 910 // Scroll offset animations should not generate property updates. | 951 // Scroll offset animations should not generate property updates. |
| 911 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 952 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 912 EXPECT_FALSE(event); | 953 EXPECT_FALSE(event); |
| 913 | 954 |
| 914 TimeDelta duration = TimeDelta::FromMicroseconds( | 955 TimeDelta duration = TimeDelta::FromMicroseconds( |
| 915 duration_in_seconds * base::Time::kMicrosecondsPerSecond); | 956 duration_in_seconds * base::Time::kMicrosecondsPerSecond); |
| 916 | 957 |
| 917 controller_impl->Animate(kInitialTickTime + duration / 2); | 958 controller_impl->Animate(kInitialTickTime + duration / 2); |
| 918 controller_impl->UpdateState(true, events.get()); | 959 controller_impl->UpdateState(true, events.get()); |
| 919 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | 960 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), |
| 920 dummy_impl.scroll_offset()); | 961 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); |
| 921 event = GetMostRecentPropertyUpdateEvent(events.get()); | 962 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 922 EXPECT_FALSE(event); | 963 EXPECT_FALSE(event); |
| 923 | 964 |
| 924 controller_impl->Animate(kInitialTickTime + duration); | 965 controller_impl->Animate(kInitialTickTime + duration); |
| 925 controller_impl->UpdateState(true, events.get()); | 966 controller_impl->UpdateState(true, events.get()); |
| 926 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | 967 EXPECT_VECTOR2DF_EQ(target_value, |
| 968 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); |
| 927 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 969 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
| 928 event = GetMostRecentPropertyUpdateEvent(events.get()); | 970 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 929 EXPECT_FALSE(event); | 971 EXPECT_FALSE(event); |
| 930 } | 972 } |
| 931 | 973 |
| 932 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) { | 974 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) { |
| 933 FakeLayerAnimationValueObserver dummy_impl; | 975 FakeLayerAnimationValueObserver dummy_impl; |
| 934 FakeLayerAnimationValueProvider dummy_provider_impl; | 976 FakeLayerAnimationValueProvider dummy_provider_impl; |
| 935 scoped_refptr<LayerAnimationController> controller_impl( | 977 scoped_refptr<LayerAnimationController> controller_impl( |
| 936 LayerAnimationController::Create(0)); | 978 LayerAnimationController::Create(0)); |
| 937 controller_impl->AddValueObserver(&dummy_impl); | 979 controller_impl->set_value_observer(&dummy_impl); |
| 980 controller_impl->set_needs_active_value_observations(true); |
| 938 controller_impl->set_value_provider(&dummy_provider_impl); | 981 controller_impl->set_value_provider(&dummy_provider_impl); |
| 939 std::unique_ptr<AnimationEvents> events( | 982 std::unique_ptr<AnimationEvents> events( |
| 940 base::WrapUnique(new AnimationEvents)); | 983 base::WrapUnique(new AnimationEvents)); |
| 941 FakeLayerAnimationValueObserver dummy; | 984 FakeLayerAnimationValueObserver dummy; |
| 942 FakeLayerAnimationValueProvider dummy_provider; | 985 FakeLayerAnimationValueProvider dummy_provider; |
| 943 scoped_refptr<LayerAnimationController> controller( | 986 scoped_refptr<LayerAnimationController> controller( |
| 944 LayerAnimationController::Create(0)); | 987 LayerAnimationController::Create(0)); |
| 945 controller->AddValueObserver(&dummy); | 988 controller->set_value_observer(&dummy); |
| 989 controller->set_needs_active_value_observations(true); |
| 946 controller->set_value_provider(&dummy_provider); | 990 controller->set_value_provider(&dummy_provider); |
| 947 | 991 |
| 948 // First test the 1-argument version of RemoveAnimation. | 992 // First test the 1-argument version of RemoveAnimation. |
| 949 gfx::ScrollOffset target_value(300.f, 200.f); | 993 gfx::ScrollOffset target_value(300.f, 200.f); |
| 950 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 994 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 951 ScrollOffsetAnimationCurve::Create(target_value, | 995 ScrollOffsetAnimationCurve::Create(target_value, |
| 952 EaseInOutTimingFunction::Create())); | 996 EaseInOutTimingFunction::Create())); |
| 953 | 997 |
| 954 int animation_id = 1; | 998 int animation_id = 1; |
| 955 std::unique_ptr<Animation> animation(Animation::Create( | 999 std::unique_ptr<Animation> animation(Animation::Create( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 TimeTicks start_time_; | 1126 TimeTicks start_time_; |
| 1083 }; | 1127 }; |
| 1084 | 1128 |
| 1085 // Tests that impl-only animations lead to start and finished notifications | 1129 // Tests that impl-only animations lead to start and finished notifications |
| 1086 // on the impl thread controller's animation delegate. | 1130 // on the impl thread controller's animation delegate. |
| 1087 TEST(LayerAnimationControllerTest, | 1131 TEST(LayerAnimationControllerTest, |
| 1088 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { | 1132 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { |
| 1089 FakeLayerAnimationValueObserver dummy_impl; | 1133 FakeLayerAnimationValueObserver dummy_impl; |
| 1090 scoped_refptr<LayerAnimationController> controller_impl( | 1134 scoped_refptr<LayerAnimationController> controller_impl( |
| 1091 LayerAnimationController::Create(0)); | 1135 LayerAnimationController::Create(0)); |
| 1092 controller_impl->AddValueObserver(&dummy_impl); | 1136 controller_impl->set_value_observer(&dummy_impl); |
| 1137 controller_impl->set_needs_active_value_observations(true); |
| 1138 |
| 1093 std::unique_ptr<AnimationEvents> events( | 1139 std::unique_ptr<AnimationEvents> events( |
| 1094 base::WrapUnique(new AnimationEvents)); | 1140 base::WrapUnique(new AnimationEvents)); |
| 1095 FakeAnimationDelegate delegate; | 1141 FakeAnimationDelegate delegate; |
| 1096 controller_impl->set_layer_animation_delegate(&delegate); | 1142 controller_impl->set_layer_animation_delegate(&delegate); |
| 1097 | 1143 |
| 1098 std::unique_ptr<Animation> to_add(CreateAnimation( | 1144 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1099 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1145 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1100 1, TargetProperty::OPACITY)); | 1146 1, TargetProperty::OPACITY)); |
| 1101 to_add->set_is_impl_only(true); | 1147 to_add->set_is_impl_only(true); |
| 1102 controller_impl->AddAnimation(std::move(to_add)); | 1148 controller_impl->AddAnimation(std::move(to_add)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1118 EXPECT_TRUE(delegate.started()); | 1164 EXPECT_TRUE(delegate.started()); |
| 1119 EXPECT_TRUE(delegate.finished()); | 1165 EXPECT_TRUE(delegate.finished()); |
| 1120 } | 1166 } |
| 1121 | 1167 |
| 1122 // Tests that specified start times are sent to the main thread delegate | 1168 // Tests that specified start times are sent to the main thread delegate |
| 1123 TEST(LayerAnimationControllerTest, | 1169 TEST(LayerAnimationControllerTest, |
| 1124 SpecifiedStartTimesAreSentToMainThreadDelegate) { | 1170 SpecifiedStartTimesAreSentToMainThreadDelegate) { |
| 1125 FakeLayerAnimationValueObserver dummy_impl; | 1171 FakeLayerAnimationValueObserver dummy_impl; |
| 1126 scoped_refptr<LayerAnimationController> controller_impl( | 1172 scoped_refptr<LayerAnimationController> controller_impl( |
| 1127 LayerAnimationController::Create(0)); | 1173 LayerAnimationController::Create(0)); |
| 1128 controller_impl->AddValueObserver(&dummy_impl); | 1174 controller_impl->set_value_observer(&dummy_impl); |
| 1175 controller_impl->set_needs_active_value_observations(true); |
| 1176 |
| 1129 FakeLayerAnimationValueObserver dummy; | 1177 FakeLayerAnimationValueObserver dummy; |
| 1130 scoped_refptr<LayerAnimationController> controller( | 1178 scoped_refptr<LayerAnimationController> controller( |
| 1131 LayerAnimationController::Create(0)); | 1179 LayerAnimationController::Create(0)); |
| 1132 controller->AddValueObserver(&dummy); | 1180 controller->set_value_observer(&dummy); |
| 1181 controller->set_needs_active_value_observations(true); |
| 1182 |
| 1133 FakeAnimationDelegate delegate; | 1183 FakeAnimationDelegate delegate; |
| 1134 controller->set_layer_animation_delegate(&delegate); | 1184 controller->set_layer_animation_delegate(&delegate); |
| 1135 | 1185 |
| 1136 int animation_id = | 1186 int animation_id = |
| 1137 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 1187 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 1138 | 1188 |
| 1139 const TimeTicks start_time = TicksFromSecondsF(123); | 1189 const TimeTicks start_time = TicksFromSecondsF(123); |
| 1140 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); | 1190 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); |
| 1141 | 1191 |
| 1142 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1192 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1170 | 1220 |
| 1171 private: | 1221 private: |
| 1172 TimeTicks start_time_; | 1222 TimeTicks start_time_; |
| 1173 }; | 1223 }; |
| 1174 | 1224 |
| 1175 // Tests that specified start times are sent to the event observers | 1225 // Tests that specified start times are sent to the event observers |
| 1176 TEST(LayerAnimationControllerTest, SpecifiedStartTimesAreSentToEventObservers) { | 1226 TEST(LayerAnimationControllerTest, SpecifiedStartTimesAreSentToEventObservers) { |
| 1177 FakeLayerAnimationValueObserver dummy_impl; | 1227 FakeLayerAnimationValueObserver dummy_impl; |
| 1178 scoped_refptr<LayerAnimationController> controller_impl( | 1228 scoped_refptr<LayerAnimationController> controller_impl( |
| 1179 LayerAnimationController::Create(0)); | 1229 LayerAnimationController::Create(0)); |
| 1180 controller_impl->AddValueObserver(&dummy_impl); | 1230 controller_impl->set_value_observer(&dummy_impl); |
| 1231 controller_impl->set_needs_active_value_observations(true); |
| 1232 |
| 1181 FakeLayerAnimationValueObserver dummy; | 1233 FakeLayerAnimationValueObserver dummy; |
| 1182 scoped_refptr<LayerAnimationController> controller( | 1234 scoped_refptr<LayerAnimationController> controller( |
| 1183 LayerAnimationController::Create(0)); | 1235 LayerAnimationController::Create(0)); |
| 1184 controller->AddValueObserver(&dummy); | 1236 controller->set_value_observer(&dummy); |
| 1237 controller->set_needs_active_value_observations(true); |
| 1238 |
| 1185 FakeLayerAnimationEventObserver observer; | 1239 FakeLayerAnimationEventObserver observer; |
| 1186 controller->AddEventObserver(&observer); | 1240 controller->AddEventObserver(&observer); |
| 1187 | 1241 |
| 1188 int animation_id = | 1242 int animation_id = |
| 1189 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 1243 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 1190 | 1244 |
| 1191 const TimeTicks start_time = TicksFromSecondsF(123); | 1245 const TimeTicks start_time = TicksFromSecondsF(123); |
| 1192 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); | 1246 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); |
| 1193 | 1247 |
| 1194 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1248 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1212 | 1266 |
| 1213 // Tests animations that are waiting for a synchronized start time do not | 1267 // Tests animations that are waiting for a synchronized start time do not |
| 1214 // finish. | 1268 // finish. |
| 1215 TEST(LayerAnimationControllerTest, | 1269 TEST(LayerAnimationControllerTest, |
| 1216 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { | 1270 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { |
| 1217 std::unique_ptr<AnimationEvents> events( | 1271 std::unique_ptr<AnimationEvents> events( |
| 1218 base::WrapUnique(new AnimationEvents)); | 1272 base::WrapUnique(new AnimationEvents)); |
| 1219 FakeLayerAnimationValueObserver dummy; | 1273 FakeLayerAnimationValueObserver dummy; |
| 1220 scoped_refptr<LayerAnimationController> controller( | 1274 scoped_refptr<LayerAnimationController> controller( |
| 1221 LayerAnimationController::Create(0)); | 1275 LayerAnimationController::Create(0)); |
| 1222 controller->AddValueObserver(&dummy); | 1276 controller->set_value_observer(&dummy); |
| 1277 controller->set_needs_active_value_observations(true); |
| 1223 | 1278 |
| 1224 std::unique_ptr<Animation> to_add(CreateAnimation( | 1279 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1225 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1280 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1226 1, TargetProperty::OPACITY)); | 1281 1, TargetProperty::OPACITY)); |
| 1227 to_add->set_needs_synchronized_start_time(true); | 1282 to_add->set_needs_synchronized_start_time(true); |
| 1228 | 1283 |
| 1229 // We should pause at the first keyframe indefinitely waiting for that | 1284 // We should pause at the first keyframe indefinitely waiting for that |
| 1230 // animation to start. | 1285 // animation to start. |
| 1231 controller->AddAnimation(std::move(to_add)); | 1286 controller->AddAnimation(std::move(to_add)); |
| 1232 controller->Animate(kInitialTickTime); | 1287 controller->Animate(kInitialTickTime); |
| 1233 controller->UpdateState(true, events.get()); | 1288 controller->UpdateState(true, events.get()); |
| 1234 EXPECT_TRUE(controller->HasActiveAnimation()); | 1289 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1235 EXPECT_EQ(0.f, dummy.opacity()); | 1290 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1236 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1291 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1237 controller->UpdateState(true, events.get()); | 1292 controller->UpdateState(true, events.get()); |
| 1238 EXPECT_TRUE(controller->HasActiveAnimation()); | 1293 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1239 EXPECT_EQ(0.f, dummy.opacity()); | 1294 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1240 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1295 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1241 controller->UpdateState(true, events.get()); | 1296 controller->UpdateState(true, events.get()); |
| 1242 EXPECT_TRUE(controller->HasActiveAnimation()); | 1297 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1243 EXPECT_EQ(0.f, dummy.opacity()); | 1298 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1244 | 1299 |
| 1245 // Send the synchronized start time. | 1300 // Send the synchronized start time. |
| 1246 controller->NotifyAnimationStarted( | 1301 controller->NotifyAnimationStarted( |
| 1247 AnimationEvent(AnimationEvent::STARTED, 0, 1, TargetProperty::OPACITY, | 1302 AnimationEvent(AnimationEvent::STARTED, 0, 1, TargetProperty::OPACITY, |
| 1248 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); | 1303 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); |
| 1249 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); | 1304 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); |
| 1250 controller->UpdateState(true, events.get()); | 1305 controller->UpdateState(true, events.get()); |
| 1251 EXPECT_EQ(1.f, dummy.opacity()); | 1306 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1252 EXPECT_FALSE(controller->HasActiveAnimation()); | 1307 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1253 } | 1308 } |
| 1254 | 1309 |
| 1255 // Tests that two queued animations affecting the same property run in sequence. | 1310 // Tests that two queued animations affecting the same property run in sequence. |
| 1256 TEST(LayerAnimationControllerTest, TrivialQueuing) { | 1311 TEST(LayerAnimationControllerTest, TrivialQueuing) { |
| 1257 std::unique_ptr<AnimationEvents> events( | 1312 std::unique_ptr<AnimationEvents> events( |
| 1258 base::WrapUnique(new AnimationEvents)); | 1313 base::WrapUnique(new AnimationEvents)); |
| 1259 FakeLayerAnimationValueObserver dummy; | 1314 FakeLayerAnimationValueObserver dummy; |
| 1260 scoped_refptr<LayerAnimationController> controller( | 1315 scoped_refptr<LayerAnimationController> controller( |
| 1261 LayerAnimationController::Create(0)); | 1316 LayerAnimationController::Create(0)); |
| 1262 controller->AddValueObserver(&dummy); | 1317 controller->set_value_observer(&dummy); |
| 1318 controller->set_needs_active_value_observations(true); |
| 1263 | 1319 |
| 1264 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 1320 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 1265 | 1321 |
| 1266 controller->AddAnimation(CreateAnimation( | 1322 controller->AddAnimation(CreateAnimation( |
| 1267 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1323 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1268 1, TargetProperty::OPACITY)); | 1324 1, TargetProperty::OPACITY)); |
| 1269 controller->AddAnimation(CreateAnimation( | 1325 controller->AddAnimation(CreateAnimation( |
| 1270 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1326 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
| 1271 2, TargetProperty::OPACITY)); | 1327 2, TargetProperty::OPACITY)); |
| 1272 | 1328 |
| 1273 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 1329 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 1274 | 1330 |
| 1275 controller->Animate(kInitialTickTime); | 1331 controller->Animate(kInitialTickTime); |
| 1276 | 1332 |
| 1277 // The second animation still needs to be started. | 1333 // The second animation still needs to be started. |
| 1278 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 1334 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 1279 | 1335 |
| 1280 controller->UpdateState(true, events.get()); | 1336 controller->UpdateState(true, events.get()); |
| 1281 EXPECT_TRUE(controller->HasActiveAnimation()); | 1337 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1282 EXPECT_EQ(0.f, dummy.opacity()); | 1338 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1283 | 1339 |
| 1284 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1340 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1285 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 1341 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 1286 controller->UpdateState(true, events.get()); | 1342 controller->UpdateState(true, events.get()); |
| 1287 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 1343 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 1288 | 1344 |
| 1289 EXPECT_TRUE(controller->HasActiveAnimation()); | 1345 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1290 EXPECT_EQ(1.f, dummy.opacity()); | 1346 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1291 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1347 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1292 controller->UpdateState(true, events.get()); | 1348 controller->UpdateState(true, events.get()); |
| 1293 EXPECT_EQ(0.5f, dummy.opacity()); | 1349 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1294 EXPECT_FALSE(controller->HasActiveAnimation()); | 1350 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1295 } | 1351 } |
| 1296 | 1352 |
| 1297 // Tests interrupting a transition with another transition. | 1353 // Tests interrupting a transition with another transition. |
| 1298 TEST(LayerAnimationControllerTest, Interrupt) { | 1354 TEST(LayerAnimationControllerTest, Interrupt) { |
| 1299 std::unique_ptr<AnimationEvents> events( | 1355 std::unique_ptr<AnimationEvents> events( |
| 1300 base::WrapUnique(new AnimationEvents)); | 1356 base::WrapUnique(new AnimationEvents)); |
| 1301 FakeLayerAnimationValueObserver dummy; | 1357 FakeLayerAnimationValueObserver dummy; |
| 1302 scoped_refptr<LayerAnimationController> controller( | 1358 scoped_refptr<LayerAnimationController> controller( |
| 1303 LayerAnimationController::Create(0)); | 1359 LayerAnimationController::Create(0)); |
| 1304 controller->AddValueObserver(&dummy); | 1360 controller->set_value_observer(&dummy); |
| 1361 controller->set_needs_active_value_observations(true); |
| 1362 |
| 1305 controller->AddAnimation(CreateAnimation( | 1363 controller->AddAnimation(CreateAnimation( |
| 1306 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1364 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1307 1, TargetProperty::OPACITY)); | 1365 1, TargetProperty::OPACITY)); |
| 1308 controller->Animate(kInitialTickTime); | 1366 controller->Animate(kInitialTickTime); |
| 1309 controller->UpdateState(true, events.get()); | 1367 controller->UpdateState(true, events.get()); |
| 1310 EXPECT_TRUE(controller->HasActiveAnimation()); | 1368 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1311 EXPECT_EQ(0.f, dummy.opacity()); | 1369 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1312 | 1370 |
| 1313 std::unique_ptr<Animation> to_add(CreateAnimation( | 1371 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1314 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1372 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
| 1315 2, TargetProperty::OPACITY)); | 1373 2, TargetProperty::OPACITY)); |
| 1316 controller->AbortAnimations(TargetProperty::OPACITY); | 1374 controller->AbortAnimations(TargetProperty::OPACITY); |
| 1317 controller->AddAnimation(std::move(to_add)); | 1375 controller->AddAnimation(std::move(to_add)); |
| 1318 | 1376 |
| 1319 // Since the previous animation was aborted, the new animation should start | 1377 // Since the previous animation was aborted, the new animation should start |
| 1320 // right in this call to animate. | 1378 // right in this call to animate. |
| 1321 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1379 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 1322 controller->UpdateState(true, events.get()); | 1380 controller->UpdateState(true, events.get()); |
| 1323 EXPECT_TRUE(controller->HasActiveAnimation()); | 1381 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1324 EXPECT_EQ(1.f, dummy.opacity()); | 1382 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1325 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | 1383 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); |
| 1326 controller->UpdateState(true, events.get()); | 1384 controller->UpdateState(true, events.get()); |
| 1327 EXPECT_EQ(0.5f, dummy.opacity()); | 1385 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1328 EXPECT_FALSE(controller->HasActiveAnimation()); | 1386 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1329 } | 1387 } |
| 1330 | 1388 |
| 1331 // Tests scheduling two animations to run together when only one property is | 1389 // Tests scheduling two animations to run together when only one property is |
| 1332 // free. | 1390 // free. |
| 1333 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { | 1391 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { |
| 1334 std::unique_ptr<AnimationEvents> events( | 1392 std::unique_ptr<AnimationEvents> events( |
| 1335 base::WrapUnique(new AnimationEvents)); | 1393 base::WrapUnique(new AnimationEvents)); |
| 1336 FakeLayerAnimationValueObserver dummy; | 1394 FakeLayerAnimationValueObserver dummy; |
| 1337 scoped_refptr<LayerAnimationController> controller( | 1395 scoped_refptr<LayerAnimationController> controller( |
| 1338 LayerAnimationController::Create(0)); | 1396 LayerAnimationController::Create(0)); |
| 1339 controller->AddValueObserver(&dummy); | 1397 controller->set_value_observer(&dummy); |
| 1398 controller->set_needs_active_value_observations(true); |
| 1340 | 1399 |
| 1341 controller->AddAnimation(CreateAnimation( | 1400 controller->AddAnimation(CreateAnimation( |
| 1342 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | 1401 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, |
| 1343 TargetProperty::TRANSFORM)); | 1402 TargetProperty::TRANSFORM)); |
| 1344 controller->AddAnimation(CreateAnimation( | 1403 controller->AddAnimation(CreateAnimation( |
| 1345 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, | 1404 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, |
| 1346 TargetProperty::TRANSFORM)); | 1405 TargetProperty::TRANSFORM)); |
| 1347 controller->AddAnimation(CreateAnimation( | 1406 controller->AddAnimation(CreateAnimation( |
| 1348 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1407 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1349 2, TargetProperty::OPACITY)); | 1408 2, TargetProperty::OPACITY)); |
| 1350 | 1409 |
| 1351 controller->Animate(kInitialTickTime); | 1410 controller->Animate(kInitialTickTime); |
| 1352 controller->UpdateState(true, events.get()); | 1411 controller->UpdateState(true, events.get()); |
| 1353 EXPECT_EQ(0.f, dummy.opacity()); | 1412 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1354 EXPECT_TRUE(controller->HasActiveAnimation()); | 1413 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1355 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1414 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1356 controller->UpdateState(true, events.get()); | 1415 controller->UpdateState(true, events.get()); |
| 1357 // Should not have started the float transition yet. | 1416 // Should not have started the float transition yet. |
| 1358 EXPECT_TRUE(controller->HasActiveAnimation()); | 1417 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1359 EXPECT_EQ(0.f, dummy.opacity()); | 1418 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1360 // The float animation should have started at time 1 and should be done. | 1419 // The float animation should have started at time 1 and should be done. |
| 1361 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1420 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1362 controller->UpdateState(true, events.get()); | 1421 controller->UpdateState(true, events.get()); |
| 1363 EXPECT_EQ(1.f, dummy.opacity()); | 1422 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1364 EXPECT_FALSE(controller->HasActiveAnimation()); | 1423 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1365 } | 1424 } |
| 1366 | 1425 |
| 1367 // Tests scheduling two animations to run together with different lengths and | 1426 // Tests scheduling two animations to run together with different lengths and |
| 1368 // another animation queued to start when the shorter animation finishes (should | 1427 // another animation queued to start when the shorter animation finishes (should |
| 1369 // wait for both to finish). | 1428 // wait for both to finish). |
| 1370 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { | 1429 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { |
| 1371 std::unique_ptr<AnimationEvents> events( | 1430 std::unique_ptr<AnimationEvents> events( |
| 1372 base::WrapUnique(new AnimationEvents)); | 1431 base::WrapUnique(new AnimationEvents)); |
| 1373 FakeLayerAnimationValueObserver dummy; | 1432 FakeLayerAnimationValueObserver dummy; |
| 1374 scoped_refptr<LayerAnimationController> controller( | 1433 scoped_refptr<LayerAnimationController> controller( |
| 1375 LayerAnimationController::Create(0)); | 1434 LayerAnimationController::Create(0)); |
| 1376 controller->AddValueObserver(&dummy); | 1435 controller->set_value_observer(&dummy); |
| 1436 controller->set_needs_active_value_observations(true); |
| 1377 | 1437 |
| 1378 controller->AddAnimation(CreateAnimation( | 1438 controller->AddAnimation(CreateAnimation( |
| 1379 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, | 1439 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, |
| 1380 TargetProperty::TRANSFORM)); | 1440 TargetProperty::TRANSFORM)); |
| 1381 controller->AddAnimation(CreateAnimation( | 1441 controller->AddAnimation(CreateAnimation( |
| 1382 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1442 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1383 1, TargetProperty::OPACITY)); | 1443 1, TargetProperty::OPACITY)); |
| 1384 controller->AddAnimation(CreateAnimation( | 1444 controller->AddAnimation(CreateAnimation( |
| 1385 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1445 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
| 1386 2, TargetProperty::OPACITY)); | 1446 2, TargetProperty::OPACITY)); |
| 1387 | 1447 |
| 1388 // Animations with id 1 should both start now. | 1448 // Animations with id 1 should both start now. |
| 1389 controller->Animate(kInitialTickTime); | 1449 controller->Animate(kInitialTickTime); |
| 1390 controller->UpdateState(true, events.get()); | 1450 controller->UpdateState(true, events.get()); |
| 1391 EXPECT_TRUE(controller->HasActiveAnimation()); | 1451 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1392 EXPECT_EQ(0.f, dummy.opacity()); | 1452 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1393 // The opacity animation should have finished at time 1, but the group | 1453 // The opacity animation should have finished at time 1, but the group |
| 1394 // of animations with id 1 don't finish until time 2 because of the length | 1454 // of animations with id 1 don't finish until time 2 because of the length |
| 1395 // of the transform animation. | 1455 // of the transform animation. |
| 1396 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1456 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1397 controller->UpdateState(true, events.get()); | 1457 controller->UpdateState(true, events.get()); |
| 1398 // Should not have started the float transition yet. | 1458 // Should not have started the float transition yet. |
| 1399 EXPECT_TRUE(controller->HasActiveAnimation()); | 1459 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1400 EXPECT_EQ(1.f, dummy.opacity()); | 1460 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1401 | 1461 |
| 1402 // The second opacity animation should start at time 2 and should be done by | 1462 // The second opacity animation should start at time 2 and should be done by |
| 1403 // time 3. | 1463 // time 3. |
| 1404 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1464 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 1405 controller->UpdateState(true, events.get()); | 1465 controller->UpdateState(true, events.get()); |
| 1406 EXPECT_EQ(0.5f, dummy.opacity()); | 1466 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1407 EXPECT_FALSE(controller->HasActiveAnimation()); | 1467 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1408 } | 1468 } |
| 1409 | 1469 |
| 1410 // Test that a looping animation loops and for the correct number of iterations. | 1470 // Test that a looping animation loops and for the correct number of iterations. |
| 1411 TEST(LayerAnimationControllerTest, TrivialLooping) { | 1471 TEST(LayerAnimationControllerTest, TrivialLooping) { |
| 1412 std::unique_ptr<AnimationEvents> events( | 1472 std::unique_ptr<AnimationEvents> events( |
| 1413 base::WrapUnique(new AnimationEvents)); | 1473 base::WrapUnique(new AnimationEvents)); |
| 1414 FakeLayerAnimationValueObserver dummy; | 1474 FakeLayerAnimationValueObserver dummy; |
| 1415 scoped_refptr<LayerAnimationController> controller( | 1475 scoped_refptr<LayerAnimationController> controller( |
| 1416 LayerAnimationController::Create(0)); | 1476 LayerAnimationController::Create(0)); |
| 1417 controller->AddValueObserver(&dummy); | 1477 controller->set_value_observer(&dummy); |
| 1478 controller->set_needs_active_value_observations(true); |
| 1418 | 1479 |
| 1419 std::unique_ptr<Animation> to_add(CreateAnimation( | 1480 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1420 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1481 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1421 1, TargetProperty::OPACITY)); | 1482 1, TargetProperty::OPACITY)); |
| 1422 to_add->set_iterations(3); | 1483 to_add->set_iterations(3); |
| 1423 controller->AddAnimation(std::move(to_add)); | 1484 controller->AddAnimation(std::move(to_add)); |
| 1424 | 1485 |
| 1425 controller->Animate(kInitialTickTime); | 1486 controller->Animate(kInitialTickTime); |
| 1426 controller->UpdateState(true, events.get()); | 1487 controller->UpdateState(true, events.get()); |
| 1427 EXPECT_TRUE(controller->HasActiveAnimation()); | 1488 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1428 EXPECT_EQ(0.f, dummy.opacity()); | 1489 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1429 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); | 1490 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); |
| 1430 controller->UpdateState(true, events.get()); | 1491 controller->UpdateState(true, events.get()); |
| 1431 EXPECT_TRUE(controller->HasActiveAnimation()); | 1492 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1432 EXPECT_EQ(0.25f, dummy.opacity()); | 1493 EXPECT_EQ(0.25f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1433 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); | 1494 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); |
| 1434 controller->UpdateState(true, events.get()); | 1495 controller->UpdateState(true, events.get()); |
| 1435 EXPECT_TRUE(controller->HasActiveAnimation()); | 1496 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1436 EXPECT_EQ(0.75f, dummy.opacity()); | 1497 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1437 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2250)); | 1498 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2250)); |
| 1438 controller->UpdateState(true, events.get()); | 1499 controller->UpdateState(true, events.get()); |
| 1439 EXPECT_TRUE(controller->HasActiveAnimation()); | 1500 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1440 EXPECT_EQ(0.25f, dummy.opacity()); | 1501 EXPECT_EQ(0.25f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1441 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2750)); | 1502 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2750)); |
| 1442 controller->UpdateState(true, events.get()); | 1503 controller->UpdateState(true, events.get()); |
| 1443 EXPECT_TRUE(controller->HasActiveAnimation()); | 1504 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1444 EXPECT_EQ(0.75f, dummy.opacity()); | 1505 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1445 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1506 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 1446 controller->UpdateState(true, events.get()); | 1507 controller->UpdateState(true, events.get()); |
| 1447 EXPECT_FALSE(controller->HasActiveAnimation()); | 1508 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1448 EXPECT_EQ(1.f, dummy.opacity()); | 1509 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1449 | 1510 |
| 1450 // Just be extra sure. | 1511 // Just be extra sure. |
| 1451 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); | 1512 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); |
| 1452 controller->UpdateState(true, events.get()); | 1513 controller->UpdateState(true, events.get()); |
| 1453 EXPECT_EQ(1.f, dummy.opacity()); | 1514 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1454 } | 1515 } |
| 1455 | 1516 |
| 1456 // Test that an infinitely looping animation does indeed go until aborted. | 1517 // Test that an infinitely looping animation does indeed go until aborted. |
| 1457 TEST(LayerAnimationControllerTest, InfiniteLooping) { | 1518 TEST(LayerAnimationControllerTest, InfiniteLooping) { |
| 1458 std::unique_ptr<AnimationEvents> events( | 1519 std::unique_ptr<AnimationEvents> events( |
| 1459 base::WrapUnique(new AnimationEvents)); | 1520 base::WrapUnique(new AnimationEvents)); |
| 1460 FakeLayerAnimationValueObserver dummy; | 1521 FakeLayerAnimationValueObserver dummy; |
| 1461 scoped_refptr<LayerAnimationController> controller( | 1522 scoped_refptr<LayerAnimationController> controller( |
| 1462 LayerAnimationController::Create(0)); | 1523 LayerAnimationController::Create(0)); |
| 1463 controller->AddValueObserver(&dummy); | 1524 controller->set_value_observer(&dummy); |
| 1525 controller->set_needs_active_value_observations(true); |
| 1464 | 1526 |
| 1465 std::unique_ptr<Animation> to_add(CreateAnimation( | 1527 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1466 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1528 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1467 1, TargetProperty::OPACITY)); | 1529 1, TargetProperty::OPACITY)); |
| 1468 to_add->set_iterations(-1); | 1530 to_add->set_iterations(-1); |
| 1469 controller->AddAnimation(std::move(to_add)); | 1531 controller->AddAnimation(std::move(to_add)); |
| 1470 | 1532 |
| 1471 controller->Animate(kInitialTickTime); | 1533 controller->Animate(kInitialTickTime); |
| 1472 controller->UpdateState(true, events.get()); | 1534 controller->UpdateState(true, events.get()); |
| 1473 EXPECT_TRUE(controller->HasActiveAnimation()); | 1535 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1474 EXPECT_EQ(0.f, dummy.opacity()); | 1536 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1475 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); | 1537 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); |
| 1476 controller->UpdateState(true, events.get()); | 1538 controller->UpdateState(true, events.get()); |
| 1477 EXPECT_TRUE(controller->HasActiveAnimation()); | 1539 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1478 EXPECT_EQ(0.25f, dummy.opacity()); | 1540 EXPECT_EQ(0.25f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1479 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); | 1541 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); |
| 1480 controller->UpdateState(true, events.get()); | 1542 controller->UpdateState(true, events.get()); |
| 1481 EXPECT_TRUE(controller->HasActiveAnimation()); | 1543 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1482 EXPECT_EQ(0.75f, dummy.opacity()); | 1544 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1483 | 1545 |
| 1484 controller->Animate(kInitialTickTime + | 1546 controller->Animate(kInitialTickTime + |
| 1485 TimeDelta::FromMilliseconds(1073741824250)); | 1547 TimeDelta::FromMilliseconds(1073741824250)); |
| 1486 controller->UpdateState(true, events.get()); | 1548 controller->UpdateState(true, events.get()); |
| 1487 EXPECT_TRUE(controller->HasActiveAnimation()); | 1549 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1488 EXPECT_EQ(0.25f, dummy.opacity()); | 1550 EXPECT_EQ(0.25f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1489 controller->Animate(kInitialTickTime + | 1551 controller->Animate(kInitialTickTime + |
| 1490 TimeDelta::FromMilliseconds(1073741824750)); | 1552 TimeDelta::FromMilliseconds(1073741824750)); |
| 1491 controller->UpdateState(true, events.get()); | 1553 controller->UpdateState(true, events.get()); |
| 1492 EXPECT_TRUE(controller->HasActiveAnimation()); | 1554 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1493 EXPECT_EQ(0.75f, dummy.opacity()); | 1555 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1494 | 1556 |
| 1495 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); | 1557 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); |
| 1496 controller->GetAnimation(TargetProperty::OPACITY) | 1558 controller->GetAnimation(TargetProperty::OPACITY) |
| 1497 ->SetRunState(Animation::ABORTED, | 1559 ->SetRunState(Animation::ABORTED, |
| 1498 kInitialTickTime + TimeDelta::FromMilliseconds(750)); | 1560 kInitialTickTime + TimeDelta::FromMilliseconds(750)); |
| 1499 EXPECT_FALSE(controller->HasActiveAnimation()); | 1561 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1500 EXPECT_EQ(0.75f, dummy.opacity()); | 1562 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1501 } | 1563 } |
| 1502 | 1564 |
| 1503 // Test that pausing and resuming work as expected. | 1565 // Test that pausing and resuming work as expected. |
| 1504 TEST(LayerAnimationControllerTest, PauseResume) { | 1566 TEST(LayerAnimationControllerTest, PauseResume) { |
| 1505 std::unique_ptr<AnimationEvents> events( | 1567 std::unique_ptr<AnimationEvents> events( |
| 1506 base::WrapUnique(new AnimationEvents)); | 1568 base::WrapUnique(new AnimationEvents)); |
| 1507 FakeLayerAnimationValueObserver dummy; | 1569 FakeLayerAnimationValueObserver dummy; |
| 1508 scoped_refptr<LayerAnimationController> controller( | 1570 scoped_refptr<LayerAnimationController> controller( |
| 1509 LayerAnimationController::Create(0)); | 1571 LayerAnimationController::Create(0)); |
| 1510 controller->AddValueObserver(&dummy); | 1572 controller->set_value_observer(&dummy); |
| 1573 controller->set_needs_active_value_observations(true); |
| 1511 | 1574 |
| 1512 controller->AddAnimation(CreateAnimation( | 1575 controller->AddAnimation(CreateAnimation( |
| 1513 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1576 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1514 1, TargetProperty::OPACITY)); | 1577 1, TargetProperty::OPACITY)); |
| 1515 | 1578 |
| 1516 controller->Animate(kInitialTickTime); | 1579 controller->Animate(kInitialTickTime); |
| 1517 controller->UpdateState(true, events.get()); | 1580 controller->UpdateState(true, events.get()); |
| 1518 EXPECT_TRUE(controller->HasActiveAnimation()); | 1581 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1519 EXPECT_EQ(0.f, dummy.opacity()); | 1582 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1520 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1583 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 1521 controller->UpdateState(true, events.get()); | 1584 controller->UpdateState(true, events.get()); |
| 1522 EXPECT_TRUE(controller->HasActiveAnimation()); | 1585 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1523 EXPECT_EQ(0.5f, dummy.opacity()); | 1586 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1524 | 1587 |
| 1525 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); | 1588 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); |
| 1526 controller->GetAnimation(TargetProperty::OPACITY) | 1589 controller->GetAnimation(TargetProperty::OPACITY) |
| 1527 ->SetRunState(Animation::PAUSED, | 1590 ->SetRunState(Animation::PAUSED, |
| 1528 kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1591 kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 1529 | 1592 |
| 1530 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); | 1593 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); |
| 1531 controller->UpdateState(true, events.get()); | 1594 controller->UpdateState(true, events.get()); |
| 1532 EXPECT_TRUE(controller->HasActiveAnimation()); | 1595 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1533 EXPECT_EQ(0.5f, dummy.opacity()); | 1596 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1534 | 1597 |
| 1535 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); | 1598 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); |
| 1536 controller->GetAnimation(TargetProperty::OPACITY) | 1599 controller->GetAnimation(TargetProperty::OPACITY) |
| 1537 ->SetRunState(Animation::RUNNING, | 1600 ->SetRunState(Animation::RUNNING, |
| 1538 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); | 1601 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); |
| 1539 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250)); | 1602 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250)); |
| 1540 controller->UpdateState(true, events.get()); | 1603 controller->UpdateState(true, events.get()); |
| 1541 EXPECT_TRUE(controller->HasActiveAnimation()); | 1604 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1542 EXPECT_EQ(0.75f, dummy.opacity()); | 1605 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1543 | 1606 |
| 1544 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); | 1607 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); |
| 1545 controller->UpdateState(true, events.get()); | 1608 controller->UpdateState(true, events.get()); |
| 1546 EXPECT_FALSE(controller->HasActiveAnimation()); | 1609 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1547 EXPECT_EQ(1.f, dummy.opacity()); | 1610 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1548 } | 1611 } |
| 1549 | 1612 |
| 1550 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { | 1613 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { |
| 1551 std::unique_ptr<AnimationEvents> events( | 1614 std::unique_ptr<AnimationEvents> events( |
| 1552 base::WrapUnique(new AnimationEvents)); | 1615 base::WrapUnique(new AnimationEvents)); |
| 1553 FakeLayerAnimationValueObserver dummy; | 1616 FakeLayerAnimationValueObserver dummy; |
| 1554 scoped_refptr<LayerAnimationController> controller( | 1617 scoped_refptr<LayerAnimationController> controller( |
| 1555 LayerAnimationController::Create(0)); | 1618 LayerAnimationController::Create(0)); |
| 1556 controller->AddValueObserver(&dummy); | 1619 controller->set_value_observer(&dummy); |
| 1620 controller->set_needs_active_value_observations(true); |
| 1557 | 1621 |
| 1558 const int animation_id = 2; | 1622 const int animation_id = 2; |
| 1559 controller->AddAnimation(Animation::Create( | 1623 controller->AddAnimation(Animation::Create( |
| 1560 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, | 1624 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, |
| 1561 TargetProperty::TRANSFORM)); | 1625 TargetProperty::TRANSFORM)); |
| 1562 controller->AddAnimation(Animation::Create( | 1626 controller->AddAnimation(Animation::Create( |
| 1563 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), | 1627 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), |
| 1564 animation_id, 1, TargetProperty::OPACITY)); | 1628 animation_id, 1, TargetProperty::OPACITY)); |
| 1565 controller->AddAnimation(Animation::Create( | 1629 controller->AddAnimation(Animation::Create( |
| 1566 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), | 1630 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), |
| 1567 3, 2, TargetProperty::OPACITY)); | 1631 3, 2, TargetProperty::OPACITY)); |
| 1568 | 1632 |
| 1569 controller->Animate(kInitialTickTime); | 1633 controller->Animate(kInitialTickTime); |
| 1570 controller->UpdateState(true, events.get()); | 1634 controller->UpdateState(true, events.get()); |
| 1571 EXPECT_TRUE(controller->HasActiveAnimation()); | 1635 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1572 EXPECT_EQ(0.f, dummy.opacity()); | 1636 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1573 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1637 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1574 controller->UpdateState(true, events.get()); | 1638 controller->UpdateState(true, events.get()); |
| 1575 EXPECT_TRUE(controller->HasActiveAnimation()); | 1639 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1576 EXPECT_EQ(0.5f, dummy.opacity()); | 1640 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1577 | 1641 |
| 1578 EXPECT_TRUE(controller->GetAnimationById(animation_id)); | 1642 EXPECT_TRUE(controller->GetAnimationById(animation_id)); |
| 1579 controller->GetAnimationById(animation_id) | 1643 controller->GetAnimationById(animation_id) |
| 1580 ->SetRunState(Animation::ABORTED, | 1644 ->SetRunState(Animation::ABORTED, |
| 1581 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1645 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1582 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1646 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1583 controller->UpdateState(true, events.get()); | 1647 controller->UpdateState(true, events.get()); |
| 1584 EXPECT_TRUE(controller->HasActiveAnimation()); | 1648 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1585 EXPECT_EQ(1.f, dummy.opacity()); | 1649 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1586 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1650 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1587 controller->UpdateState(true, events.get()); | 1651 controller->UpdateState(true, events.get()); |
| 1588 EXPECT_TRUE(!controller->HasActiveAnimation()); | 1652 EXPECT_TRUE(!controller->HasActiveAnimation()); |
| 1589 EXPECT_EQ(0.75f, dummy.opacity()); | 1653 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1590 } | 1654 } |
| 1591 | 1655 |
| 1592 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { | 1656 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { |
| 1593 FakeLayerAnimationValueObserver dummy_impl; | 1657 FakeLayerAnimationValueObserver dummy_impl; |
| 1594 scoped_refptr<LayerAnimationController> controller_impl( | 1658 scoped_refptr<LayerAnimationController> controller_impl( |
| 1595 LayerAnimationController::Create(0)); | 1659 LayerAnimationController::Create(0)); |
| 1596 controller_impl->AddValueObserver(&dummy_impl); | 1660 controller_impl->set_value_observer(&dummy_impl); |
| 1661 controller_impl->set_needs_active_value_observations(true); |
| 1597 std::unique_ptr<AnimationEvents> events( | 1662 std::unique_ptr<AnimationEvents> events( |
| 1598 base::WrapUnique(new AnimationEvents)); | 1663 base::WrapUnique(new AnimationEvents)); |
| 1599 FakeLayerAnimationValueObserver dummy; | 1664 FakeLayerAnimationValueObserver dummy; |
| 1600 scoped_refptr<LayerAnimationController> controller( | 1665 scoped_refptr<LayerAnimationController> controller( |
| 1601 LayerAnimationController::Create(0)); | 1666 LayerAnimationController::Create(0)); |
| 1602 controller->AddValueObserver(&dummy); | 1667 controller->set_value_observer(&dummy); |
| 1668 controller->set_needs_active_value_observations(true); |
| 1603 | 1669 |
| 1604 std::unique_ptr<Animation> to_add(CreateAnimation( | 1670 std::unique_ptr<Animation> to_add(CreateAnimation( |
| 1605 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), | 1671 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), |
| 1606 0, TargetProperty::OPACITY)); | 1672 0, TargetProperty::OPACITY)); |
| 1607 to_add->set_needs_synchronized_start_time(true); | 1673 to_add->set_needs_synchronized_start_time(true); |
| 1608 controller->AddAnimation(std::move(to_add)); | 1674 controller->AddAnimation(std::move(to_add)); |
| 1609 | 1675 |
| 1610 controller->Animate(kInitialTickTime); | 1676 controller->Animate(kInitialTickTime); |
| 1611 controller->UpdateState(true, events.get()); | 1677 controller->UpdateState(true, events.get()); |
| 1612 EXPECT_TRUE(controller->HasActiveAnimation()); | 1678 EXPECT_TRUE(controller->HasActiveAnimation()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1624 active_animation->run_state()); | 1690 active_animation->run_state()); |
| 1625 } | 1691 } |
| 1626 | 1692 |
| 1627 // Tests that skipping a call to UpdateState works as expected. | 1693 // Tests that skipping a call to UpdateState works as expected. |
| 1628 TEST(LayerAnimationControllerTest, SkipUpdateState) { | 1694 TEST(LayerAnimationControllerTest, SkipUpdateState) { |
| 1629 std::unique_ptr<AnimationEvents> events( | 1695 std::unique_ptr<AnimationEvents> events( |
| 1630 base::WrapUnique(new AnimationEvents)); | 1696 base::WrapUnique(new AnimationEvents)); |
| 1631 FakeLayerAnimationValueObserver dummy; | 1697 FakeLayerAnimationValueObserver dummy; |
| 1632 scoped_refptr<LayerAnimationController> controller( | 1698 scoped_refptr<LayerAnimationController> controller( |
| 1633 LayerAnimationController::Create(0)); | 1699 LayerAnimationController::Create(0)); |
| 1634 controller->AddValueObserver(&dummy); | 1700 controller->set_value_observer(&dummy); |
| 1701 controller->set_needs_active_value_observations(true); |
| 1635 | 1702 |
| 1636 std::unique_ptr<Animation> first_animation(CreateAnimation( | 1703 std::unique_ptr<Animation> first_animation(CreateAnimation( |
| 1637 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | 1704 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, |
| 1638 TargetProperty::TRANSFORM)); | 1705 TargetProperty::TRANSFORM)); |
| 1639 first_animation->set_is_controlling_instance_for_test(true); | 1706 first_animation->set_is_controlling_instance_for_test(true); |
| 1640 controller->AddAnimation(std::move(first_animation)); | 1707 controller->AddAnimation(std::move(first_animation)); |
| 1641 | 1708 |
| 1642 controller->Animate(kInitialTickTime); | 1709 controller->Animate(kInitialTickTime); |
| 1643 controller->UpdateState(true, events.get()); | 1710 controller->UpdateState(true, events.get()); |
| 1644 | 1711 |
| 1645 std::unique_ptr<Animation> second_animation(CreateAnimation( | 1712 std::unique_ptr<Animation> second_animation(CreateAnimation( |
| 1646 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1713 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1647 2, TargetProperty::OPACITY)); | 1714 2, TargetProperty::OPACITY)); |
| 1648 second_animation->set_is_controlling_instance_for_test(true); | 1715 second_animation->set_is_controlling_instance_for_test(true); |
| 1649 controller->AddAnimation(std::move(second_animation)); | 1716 controller->AddAnimation(std::move(second_animation)); |
| 1650 | 1717 |
| 1651 // Animate but don't UpdateState. | 1718 // Animate but don't UpdateState. |
| 1652 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1719 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1653 | 1720 |
| 1654 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1721 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1655 events.reset(new AnimationEvents); | 1722 events.reset(new AnimationEvents); |
| 1656 controller->UpdateState(true, events.get()); | 1723 controller->UpdateState(true, events.get()); |
| 1657 | 1724 |
| 1658 // Should have one STARTED event and one FINISHED event. | 1725 // Should have one STARTED event and one FINISHED event. |
| 1659 EXPECT_EQ(2u, events->events_.size()); | 1726 EXPECT_EQ(2u, events->events_.size()); |
| 1660 EXPECT_NE(events->events_[0].type, events->events_[1].type); | 1727 EXPECT_NE(events->events_[0].type, events->events_[1].type); |
| 1661 | 1728 |
| 1662 // The float transition should still be at its starting point. | 1729 // The float transition should still be at its starting point. |
| 1663 EXPECT_TRUE(controller->HasActiveAnimation()); | 1730 EXPECT_TRUE(controller->HasActiveAnimation()); |
| 1664 EXPECT_EQ(0.f, dummy.opacity()); | 1731 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1665 | 1732 |
| 1666 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1733 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 1667 controller->UpdateState(true, events.get()); | 1734 controller->UpdateState(true, events.get()); |
| 1668 | 1735 |
| 1669 // The float tranisition should now be done. | 1736 // The float tranisition should now be done. |
| 1670 EXPECT_EQ(1.f, dummy.opacity()); | 1737 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1671 EXPECT_FALSE(controller->HasActiveAnimation()); | 1738 EXPECT_FALSE(controller->HasActiveAnimation()); |
| 1672 } | 1739 } |
| 1673 | 1740 |
| 1674 // Tests that an animation controller with only a pending observer gets ticked | 1741 // Tests that an animation controller with only a pending observer gets ticked |
| 1675 // but doesn't progress animations past the STARTING state. | 1742 // but doesn't progress animations past the STARTING state. |
| 1676 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { | 1743 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { |
| 1677 std::unique_ptr<AnimationEvents> events( | 1744 std::unique_ptr<AnimationEvents> events( |
| 1678 base::WrapUnique(new AnimationEvents)); | 1745 base::WrapUnique(new AnimationEvents)); |
| 1679 FakeLayerAnimationValueObserver dummy; | 1746 FakeLayerAnimationValueObserver dummy; |
| 1680 FakeInactiveLayerAnimationValueObserver pending_dummy; | |
| 1681 scoped_refptr<LayerAnimationController> controller( | 1747 scoped_refptr<LayerAnimationController> controller( |
| 1682 LayerAnimationController::Create(0)); | 1748 LayerAnimationController::Create(0)); |
| 1749 controller->set_value_observer(&dummy); |
| 1683 | 1750 |
| 1684 const int id = 1; | 1751 const int id = 1; |
| 1685 controller->AddAnimation(CreateAnimation( | 1752 controller->AddAnimation(CreateAnimation( |
| 1686 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), | 1753 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), |
| 1687 id, TargetProperty::OPACITY)); | 1754 id, TargetProperty::OPACITY)); |
| 1688 | 1755 |
| 1689 // Without an observer, the animation shouldn't progress to the STARTING | 1756 // Without an observer, the animation shouldn't progress to the STARTING |
| 1690 // state. | 1757 // state. |
| 1691 controller->Animate(kInitialTickTime); | 1758 controller->Animate(kInitialTickTime); |
| 1692 controller->UpdateState(true, events.get()); | 1759 controller->UpdateState(true, events.get()); |
| 1693 EXPECT_EQ(0u, events->events_.size()); | 1760 EXPECT_EQ(0u, events->events_.size()); |
| 1694 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 1761 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 1695 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1762 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 1696 | 1763 |
| 1697 controller->AddValueObserver(&pending_dummy); | 1764 controller->set_needs_pending_value_observations(true); |
| 1698 | 1765 |
| 1699 // With only a pending observer, the animation should progress to the | 1766 // With only a pending observer, the animation should progress to the |
| 1700 // STARTING state and get ticked at its starting point, but should not | 1767 // STARTING state and get ticked at its starting point, but should not |
| 1701 // progress to RUNNING. | 1768 // progress to RUNNING. |
| 1702 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1769 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 1703 controller->UpdateState(true, events.get()); | 1770 controller->UpdateState(true, events.get()); |
| 1704 EXPECT_EQ(0u, events->events_.size()); | 1771 EXPECT_EQ(0u, events->events_.size()); |
| 1705 EXPECT_EQ(Animation::STARTING, | 1772 EXPECT_EQ(Animation::STARTING, |
| 1706 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1773 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 1707 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1774 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::PENDING)); |
| 1708 | 1775 |
| 1709 // Even when already in the STARTING state, the animation should stay | 1776 // Even when already in the STARTING state, the animation should stay |
| 1710 // there, and shouldn't be ticked past its starting point. | 1777 // there, and shouldn't be ticked past its starting point. |
| 1711 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1778 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 1712 controller->UpdateState(true, events.get()); | 1779 controller->UpdateState(true, events.get()); |
| 1713 EXPECT_EQ(0u, events->events_.size()); | 1780 EXPECT_EQ(0u, events->events_.size()); |
| 1714 EXPECT_EQ(Animation::STARTING, | 1781 EXPECT_EQ(Animation::STARTING, |
| 1715 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1782 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 1716 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1783 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::PENDING)); |
| 1717 | 1784 |
| 1718 controller->AddValueObserver(&dummy); | 1785 controller->set_needs_active_value_observations(true); |
| 1719 | 1786 |
| 1720 // Now that an active observer has been added, the animation should still | 1787 // 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. | 1788 // initially tick at its starting point, but should now progress to RUNNING. |
| 1722 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1789 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
| 1723 controller->UpdateState(true, events.get()); | 1790 controller->UpdateState(true, events.get()); |
| 1724 EXPECT_EQ(1u, events->events_.size()); | 1791 EXPECT_EQ(1u, events->events_.size()); |
| 1725 EXPECT_EQ(Animation::RUNNING, | 1792 EXPECT_EQ(Animation::RUNNING, |
| 1726 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1793 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 1727 EXPECT_EQ(0.5f, pending_dummy.opacity()); | 1794 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::PENDING)); |
| 1728 EXPECT_EQ(0.5f, dummy.opacity()); | 1795 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1729 | 1796 |
| 1730 // The animation should now tick past its starting point. | 1797 // The animation should now tick past its starting point. |
| 1731 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); | 1798 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); |
| 1732 EXPECT_NE(0.5f, pending_dummy.opacity()); | 1799 EXPECT_NE(0.5f, dummy.opacity(LayerTreeType::PENDING)); |
| 1733 EXPECT_NE(0.5f, dummy.opacity()); | 1800 EXPECT_NE(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 1734 } | 1801 } |
| 1735 | 1802 |
| 1736 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { | 1803 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { |
| 1737 scoped_refptr<LayerAnimationController> controller_impl( | 1804 scoped_refptr<LayerAnimationController> controller_impl( |
| 1738 LayerAnimationController::Create(0)); | 1805 LayerAnimationController::Create(0)); |
| 1739 | 1806 |
| 1740 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | 1807 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( |
| 1741 KeyframedTransformAnimationCurve::Create()); | 1808 KeyframedTransformAnimationCurve::Create()); |
| 1742 | 1809 |
| 1743 TransformOperations operations1; | 1810 TransformOperations operations1; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1802 controller_impl->AddAnimation(std::move(animation)); | 1869 controller_impl->AddAnimation(std::move(animation)); |
| 1803 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); | 1870 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); |
| 1804 } | 1871 } |
| 1805 | 1872 |
| 1806 // Tests that AbortAnimations aborts all animations targeting the specified | 1873 // Tests that AbortAnimations aborts all animations targeting the specified |
| 1807 // property. | 1874 // property. |
| 1808 TEST(LayerAnimationControllerTest, AbortAnimations) { | 1875 TEST(LayerAnimationControllerTest, AbortAnimations) { |
| 1809 FakeLayerAnimationValueObserver dummy; | 1876 FakeLayerAnimationValueObserver dummy; |
| 1810 scoped_refptr<LayerAnimationController> controller( | 1877 scoped_refptr<LayerAnimationController> controller( |
| 1811 LayerAnimationController::Create(0)); | 1878 LayerAnimationController::Create(0)); |
| 1812 controller->AddValueObserver(&dummy); | 1879 controller->set_value_observer(&dummy); |
| 1880 controller->set_needs_active_value_observations(true); |
| 1813 | 1881 |
| 1814 // Start with several animations, and allow some of them to reach the finished | 1882 // Start with several animations, and allow some of them to reach the finished |
| 1815 // state. | 1883 // state. |
| 1816 controller->AddAnimation(Animation::Create( | 1884 controller->AddAnimation(Animation::Create( |
| 1817 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, 1, | 1885 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, 1, |
| 1818 TargetProperty::TRANSFORM)); | 1886 TargetProperty::TRANSFORM)); |
| 1819 controller->AddAnimation(Animation::Create( | 1887 controller->AddAnimation(Animation::Create( |
| 1820 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1888 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 1821 2, 2, TargetProperty::OPACITY)); | 1889 2, 2, TargetProperty::OPACITY)); |
| 1822 controller->AddAnimation(Animation::Create( | 1890 controller->AddAnimation(Animation::Create( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1849 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(3)->run_state()); | 1917 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(3)->run_state()); |
| 1850 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(4)->run_state()); | 1918 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(4)->run_state()); |
| 1851 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(5)->run_state()); | 1919 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(5)->run_state()); |
| 1852 } | 1920 } |
| 1853 | 1921 |
| 1854 // An animation aborted on the main thread should get deleted on both threads. | 1922 // An animation aborted on the main thread should get deleted on both threads. |
| 1855 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) { | 1923 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) { |
| 1856 FakeLayerAnimationValueObserver dummy_impl; | 1924 FakeLayerAnimationValueObserver dummy_impl; |
| 1857 scoped_refptr<LayerAnimationController> controller_impl( | 1925 scoped_refptr<LayerAnimationController> controller_impl( |
| 1858 LayerAnimationController::Create(0)); | 1926 LayerAnimationController::Create(0)); |
| 1859 controller_impl->AddValueObserver(&dummy_impl); | 1927 controller_impl->set_value_observer(&dummy_impl); |
| 1928 controller_impl->set_needs_active_value_observations(true); |
| 1860 FakeLayerAnimationValueObserver dummy; | 1929 FakeLayerAnimationValueObserver dummy; |
| 1861 scoped_refptr<LayerAnimationController> controller( | 1930 scoped_refptr<LayerAnimationController> controller( |
| 1862 LayerAnimationController::Create(0)); | 1931 LayerAnimationController::Create(0)); |
| 1863 controller->AddValueObserver(&dummy); | 1932 controller->set_value_observer(&dummy); |
| 1933 controller->set_needs_active_value_observations(true); |
| 1864 | 1934 |
| 1865 int animation_id = | 1935 int animation_id = |
| 1866 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); | 1936 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); |
| 1867 | 1937 |
| 1868 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1938 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1869 controller_impl->ActivateAnimations(); | 1939 controller_impl->ActivateAnimations(); |
| 1870 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 1940 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 1871 | 1941 |
| 1872 controller->AbortAnimations(TargetProperty::OPACITY); | 1942 controller->AbortAnimations(TargetProperty::OPACITY); |
| 1873 EXPECT_EQ(Animation::ABORTED, | 1943 EXPECT_EQ(Animation::ABORTED, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1884 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1954 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1885 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | 1955 EXPECT_FALSE(controller->GetAnimationById(animation_id)); |
| 1886 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | 1956 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); |
| 1887 } | 1957 } |
| 1888 | 1958 |
| 1889 // An animation aborted on the impl thread should get deleted on both threads. | 1959 // An animation aborted on the impl thread should get deleted on both threads. |
| 1890 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) { | 1960 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) { |
| 1891 FakeLayerAnimationValueObserver dummy_impl; | 1961 FakeLayerAnimationValueObserver dummy_impl; |
| 1892 scoped_refptr<LayerAnimationController> controller_impl( | 1962 scoped_refptr<LayerAnimationController> controller_impl( |
| 1893 LayerAnimationController::Create(0)); | 1963 LayerAnimationController::Create(0)); |
| 1894 controller_impl->AddValueObserver(&dummy_impl); | 1964 controller_impl->set_value_observer(&dummy_impl); |
| 1965 controller_impl->set_needs_active_value_observations(true); |
| 1895 FakeLayerAnimationValueObserver dummy; | 1966 FakeLayerAnimationValueObserver dummy; |
| 1896 scoped_refptr<LayerAnimationController> controller( | 1967 scoped_refptr<LayerAnimationController> controller( |
| 1897 LayerAnimationController::Create(0)); | 1968 LayerAnimationController::Create(0)); |
| 1898 controller->AddValueObserver(&dummy); | 1969 controller->set_value_observer(&dummy); |
| 1970 controller->set_needs_active_value_observations(true); |
| 1899 FakeAnimationDelegate delegate; | 1971 FakeAnimationDelegate delegate; |
| 1900 controller->set_layer_animation_delegate(&delegate); | 1972 controller->set_layer_animation_delegate(&delegate); |
| 1901 | 1973 |
| 1902 int animation_id = | 1974 int animation_id = |
| 1903 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); | 1975 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); |
| 1904 | 1976 |
| 1905 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1977 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1906 controller_impl->ActivateAnimations(); | 1978 controller_impl->ActivateAnimations(); |
| 1907 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 1979 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 1908 | 1980 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1939 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | 2011 EXPECT_FALSE(controller->GetAnimationById(animation_id)); |
| 1940 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | 2012 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); |
| 1941 } | 2013 } |
| 1942 | 2014 |
| 1943 // Test that an impl-only scroll offset animation that needs to be completed on | 2015 // Test that an impl-only scroll offset animation that needs to be completed on |
| 1944 // the main thread gets deleted. | 2016 // the main thread gets deleted. |
| 1945 TEST(LayerAnimationControllerTest, ImplThreadTakeoverAnimationGetsDeleted) { | 2017 TEST(LayerAnimationControllerTest, ImplThreadTakeoverAnimationGetsDeleted) { |
| 1946 FakeLayerAnimationValueObserver dummy_impl; | 2018 FakeLayerAnimationValueObserver dummy_impl; |
| 1947 scoped_refptr<LayerAnimationController> controller_impl( | 2019 scoped_refptr<LayerAnimationController> controller_impl( |
| 1948 LayerAnimationController::Create(0)); | 2020 LayerAnimationController::Create(0)); |
| 1949 controller_impl->AddValueObserver(&dummy_impl); | 2021 controller_impl->set_value_observer(&dummy_impl); |
| 2022 controller_impl->set_needs_active_value_observations(true); |
| 1950 FakeLayerAnimationValueObserver dummy; | 2023 FakeLayerAnimationValueObserver dummy; |
| 1951 scoped_refptr<LayerAnimationController> controller( | 2024 scoped_refptr<LayerAnimationController> controller( |
| 1952 LayerAnimationController::Create(0)); | 2025 LayerAnimationController::Create(0)); |
| 1953 controller->AddValueObserver(&dummy); | 2026 controller->set_value_observer(&dummy); |
| 2027 controller->set_needs_active_value_observations(true); |
| 1954 FakeAnimationDelegate delegate_impl; | 2028 FakeAnimationDelegate delegate_impl; |
| 1955 controller_impl->set_layer_animation_delegate(&delegate_impl); | 2029 controller_impl->set_layer_animation_delegate(&delegate_impl); |
| 1956 FakeAnimationDelegate delegate; | 2030 FakeAnimationDelegate delegate; |
| 1957 controller->set_layer_animation_delegate(&delegate); | 2031 controller->set_layer_animation_delegate(&delegate); |
| 1958 | 2032 |
| 1959 // Add impl-only scroll offset animation. | 2033 // Add impl-only scroll offset animation. |
| 1960 int animation_id = 1; | 2034 int animation_id = 1; |
| 1961 gfx::ScrollOffset initial_value(100.f, 300.f); | 2035 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 1962 gfx::ScrollOffset target_value(300.f, 200.f); | 2036 gfx::ScrollOffset target_value(300.f, 200.f); |
| 1963 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 2037 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2007 } | 2081 } |
| 2008 | 2082 |
| 2009 // Ensure that we only generate FINISHED events for animations in a group | 2083 // Ensure that we only generate FINISHED events for animations in a group |
| 2010 // once all animations in that group are finished. | 2084 // once all animations in that group are finished. |
| 2011 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { | 2085 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { |
| 2012 std::unique_ptr<AnimationEvents> events( | 2086 std::unique_ptr<AnimationEvents> events( |
| 2013 base::WrapUnique(new AnimationEvents)); | 2087 base::WrapUnique(new AnimationEvents)); |
| 2014 FakeLayerAnimationValueObserver dummy_impl; | 2088 FakeLayerAnimationValueObserver dummy_impl; |
| 2015 scoped_refptr<LayerAnimationController> controller_impl( | 2089 scoped_refptr<LayerAnimationController> controller_impl( |
| 2016 LayerAnimationController::Create(0)); | 2090 LayerAnimationController::Create(0)); |
| 2017 controller_impl->AddValueObserver(&dummy_impl); | 2091 controller_impl->set_value_observer(&dummy_impl); |
| 2092 controller_impl->set_needs_active_value_observations(true); |
| 2018 | 2093 |
| 2019 const int group_id = 1; | 2094 const int group_id = 1; |
| 2020 | 2095 |
| 2021 // Add two animations with the same group id but different durations. | 2096 // Add two animations with the same group id but different durations. |
| 2022 std::unique_ptr<Animation> first_animation(Animation::Create( | 2097 std::unique_ptr<Animation> first_animation(Animation::Create( |
| 2023 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1, | 2098 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1, |
| 2024 group_id, TargetProperty::TRANSFORM)); | 2099 group_id, TargetProperty::TRANSFORM)); |
| 2025 first_animation->set_is_controlling_instance_for_test(true); | 2100 first_animation->set_is_controlling_instance_for_test(true); |
| 2026 controller_impl->AddAnimation(std::move(first_animation)); | 2101 controller_impl->AddAnimation(std::move(first_animation)); |
| 2027 | 2102 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 | 2139 |
| 2065 // Ensure that when a group has a mix of aborted and finished animations, | 2140 // 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 | 2141 // we generate a FINISHED event for the finished animation and an ABORTED |
| 2067 // event for the aborted animation. | 2142 // event for the aborted animation. |
| 2068 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { | 2143 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { |
| 2069 std::unique_ptr<AnimationEvents> events( | 2144 std::unique_ptr<AnimationEvents> events( |
| 2070 base::WrapUnique(new AnimationEvents)); | 2145 base::WrapUnique(new AnimationEvents)); |
| 2071 FakeLayerAnimationValueObserver dummy_impl; | 2146 FakeLayerAnimationValueObserver dummy_impl; |
| 2072 scoped_refptr<LayerAnimationController> controller_impl( | 2147 scoped_refptr<LayerAnimationController> controller_impl( |
| 2073 LayerAnimationController::Create(0)); | 2148 LayerAnimationController::Create(0)); |
| 2074 controller_impl->AddValueObserver(&dummy_impl); | 2149 controller_impl->set_value_observer(&dummy_impl); |
| 2150 controller_impl->set_needs_active_value_observations(true); |
| 2075 | 2151 |
| 2076 // Add two animations with the same group id. | 2152 // Add two animations with the same group id. |
| 2077 std::unique_ptr<Animation> first_animation(CreateAnimation( | 2153 std::unique_ptr<Animation> first_animation(CreateAnimation( |
| 2078 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, | 2154 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, |
| 2079 TargetProperty::TRANSFORM)); | 2155 TargetProperty::TRANSFORM)); |
| 2080 first_animation->set_is_controlling_instance_for_test(true); | 2156 first_animation->set_is_controlling_instance_for_test(true); |
| 2081 controller_impl->AddAnimation(std::move(first_animation)); | 2157 controller_impl->AddAnimation(std::move(first_animation)); |
| 2082 | 2158 |
| 2083 std::unique_ptr<Animation> second_animation(CreateAnimation( | 2159 std::unique_ptr<Animation> second_animation(CreateAnimation( |
| 2084 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 2160 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2554 EXPECT_EQ(6.f, max_scale); | 2630 EXPECT_EQ(6.f, max_scale); |
| 2555 EXPECT_TRUE(controller_impl->MaximumTargetScale( | 2631 EXPECT_TRUE(controller_impl->MaximumTargetScale( |
| 2556 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | 2632 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); |
| 2557 EXPECT_EQ(6.f, max_scale); | 2633 EXPECT_EQ(6.f, max_scale); |
| 2558 } | 2634 } |
| 2559 | 2635 |
| 2560 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { | 2636 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { |
| 2561 std::unique_ptr<AnimationEvents> events( | 2637 std::unique_ptr<AnimationEvents> events( |
| 2562 base::WrapUnique(new AnimationEvents)); | 2638 base::WrapUnique(new AnimationEvents)); |
| 2563 FakeLayerAnimationValueObserver dummy_impl; | 2639 FakeLayerAnimationValueObserver dummy_impl; |
| 2564 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | |
| 2565 scoped_refptr<LayerAnimationController> controller_impl( | 2640 scoped_refptr<LayerAnimationController> controller_impl( |
| 2566 LayerAnimationController::Create(0)); | 2641 LayerAnimationController::Create(0)); |
| 2567 controller_impl->AddValueObserver(&dummy_impl); | 2642 controller_impl->set_value_observer(&dummy_impl); |
| 2568 controller_impl->AddValueObserver(&pending_dummy_impl); | 2643 controller_impl->set_needs_active_value_observations(true); |
| 2644 controller_impl->set_needs_pending_value_observations(true); |
| 2569 FakeLayerAnimationValueObserver dummy; | 2645 FakeLayerAnimationValueObserver dummy; |
| 2570 scoped_refptr<LayerAnimationController> controller( | 2646 scoped_refptr<LayerAnimationController> controller( |
| 2571 LayerAnimationController::Create(0)); | 2647 LayerAnimationController::Create(0)); |
| 2572 controller->AddValueObserver(&dummy); | 2648 controller->set_value_observer(&dummy); |
| 2649 controller->set_needs_active_value_observations(true); |
| 2573 | 2650 |
| 2574 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | 2651 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); |
| 2575 int animation_id = | 2652 int animation_id = |
| 2576 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false); | 2653 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false); |
| 2577 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | 2654 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); |
| 2578 | 2655 |
| 2579 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | 2656 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); |
| 2580 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2657 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2581 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); | 2658 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); |
| 2582 | 2659 |
| 2583 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 2660 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 2584 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 2661 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 2585 controller_impl->GetAnimationById(animation_id)->run_state()); | 2662 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2586 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2663 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2587 ->affects_pending_observers()); | 2664 ->affects_pending_observers()); |
| 2588 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | 2665 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) |
| 2589 ->affects_active_observers()); | 2666 ->affects_active_observers()); |
| 2590 | 2667 |
| 2591 controller_impl->Animate(kInitialTickTime); | 2668 controller_impl->Animate(kInitialTickTime); |
| 2592 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | 2669 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); |
| 2593 controller_impl->UpdateState(true, events.get()); | 2670 controller_impl->UpdateState(true, events.get()); |
| 2594 | 2671 |
| 2595 // Since the animation hasn't been activated, it should still be STARTING | 2672 // Since the animation hasn't been activated, it should still be STARTING |
| 2596 // rather than RUNNING. | 2673 // rather than RUNNING. |
| 2597 EXPECT_EQ(Animation::STARTING, | 2674 EXPECT_EQ(Animation::STARTING, |
| 2598 controller_impl->GetAnimationById(animation_id)->run_state()); | 2675 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2599 | 2676 |
| 2600 // Since the animation hasn't been activated, only the pending observer | 2677 // Since the animation hasn't been activated, only the pending observer |
| 2601 // should have been ticked. | 2678 // should have been ticked. |
| 2602 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2679 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2603 EXPECT_EQ(0.f, dummy_impl.opacity()); | 2680 EXPECT_EQ(0.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2604 | 2681 |
| 2605 controller_impl->ActivateAnimations(); | 2682 controller_impl->ActivateAnimations(); |
| 2606 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2683 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2607 ->affects_pending_observers()); | 2684 ->affects_pending_observers()); |
| 2608 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2685 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2609 ->affects_active_observers()); | 2686 ->affects_active_observers()); |
| 2610 | 2687 |
| 2611 controller_impl->Animate(kInitialTickTime + | 2688 controller_impl->Animate(kInitialTickTime + |
| 2612 TimeDelta::FromMilliseconds(1000)); | 2689 TimeDelta::FromMilliseconds(1000)); |
| 2613 controller_impl->UpdateState(true, events.get()); | 2690 controller_impl->UpdateState(true, events.get()); |
| 2614 | 2691 |
| 2615 // Since the animation has been activated, it should have reached the | 2692 // Since the animation has been activated, it should have reached the |
| 2616 // RUNNING state and the active observer should start to get ticked. | 2693 // RUNNING state and the active observer should start to get ticked. |
| 2617 EXPECT_EQ(Animation::RUNNING, | 2694 EXPECT_EQ(Animation::RUNNING, |
| 2618 controller_impl->GetAnimationById(animation_id)->run_state()); | 2695 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2619 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2696 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2620 EXPECT_EQ(0.5f, dummy_impl.opacity()); | 2697 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2621 } | 2698 } |
| 2622 | 2699 |
| 2623 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { | 2700 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { |
| 2624 std::unique_ptr<AnimationEvents> events( | 2701 std::unique_ptr<AnimationEvents> events( |
| 2625 base::WrapUnique(new AnimationEvents)); | 2702 base::WrapUnique(new AnimationEvents)); |
| 2626 FakeLayerAnimationValueObserver dummy_impl; | 2703 FakeLayerAnimationValueObserver dummy_impl; |
| 2627 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | |
| 2628 scoped_refptr<LayerAnimationController> controller_impl( | 2704 scoped_refptr<LayerAnimationController> controller_impl( |
| 2629 LayerAnimationController::Create(0)); | 2705 LayerAnimationController::Create(0)); |
| 2630 controller_impl->AddValueObserver(&dummy_impl); | 2706 controller_impl->set_value_observer(&dummy_impl); |
| 2631 controller_impl->AddValueObserver(&pending_dummy_impl); | 2707 controller_impl->set_needs_active_value_observations(true); |
| 2708 controller_impl->set_needs_pending_value_observations(true); |
| 2709 |
| 2632 FakeLayerAnimationValueObserver dummy; | 2710 FakeLayerAnimationValueObserver dummy; |
| 2633 scoped_refptr<LayerAnimationController> controller( | 2711 scoped_refptr<LayerAnimationController> controller( |
| 2634 LayerAnimationController::Create(0)); | 2712 LayerAnimationController::Create(0)); |
| 2635 controller->AddValueObserver(&dummy); | 2713 controller->set_value_observer(&dummy); |
| 2714 controller->set_needs_active_value_observations(true); |
| 2636 | 2715 |
| 2637 int animation_id = | 2716 int animation_id = |
| 2638 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); | 2717 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); |
| 2639 | 2718 |
| 2640 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2719 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2641 | 2720 |
| 2642 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 2721 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 2643 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 2722 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 2644 controller_impl->GetAnimationById(animation_id)->run_state()); | 2723 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2645 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2724 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2646 ->affects_pending_observers()); | 2725 ->affects_pending_observers()); |
| 2647 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | 2726 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) |
| 2648 ->affects_active_observers()); | 2727 ->affects_active_observers()); |
| 2649 | 2728 |
| 2650 controller_impl->Animate(kInitialTickTime); | 2729 controller_impl->Animate(kInitialTickTime); |
| 2651 | 2730 |
| 2652 // Since the animation hasn't been activated, only the pending observer | 2731 // Since the animation hasn't been activated, only the pending observer |
| 2653 // should have been ticked. | 2732 // should have been ticked. |
| 2654 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2733 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2655 EXPECT_EQ(0.f, dummy_impl.opacity()); | 2734 EXPECT_EQ(0.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2656 | 2735 |
| 2657 controller_impl->ActivateAnimations(); | 2736 controller_impl->ActivateAnimations(); |
| 2658 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2737 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2659 ->affects_pending_observers()); | 2738 ->affects_pending_observers()); |
| 2660 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2739 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2661 ->affects_active_observers()); | 2740 ->affects_active_observers()); |
| 2662 | 2741 |
| 2663 controller_impl->UpdateState(true, events.get()); | 2742 controller_impl->UpdateState(true, events.get()); |
| 2664 | 2743 |
| 2665 // Since the animation has been activated, it should have reached the | 2744 // Since the animation has been activated, it should have reached the |
| 2666 // RUNNING state. | 2745 // RUNNING state. |
| 2667 EXPECT_EQ(Animation::RUNNING, | 2746 EXPECT_EQ(Animation::RUNNING, |
| 2668 controller_impl->GetAnimationById(animation_id)->run_state()); | 2747 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2669 | 2748 |
| 2670 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2749 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 2671 | 2750 |
| 2672 // Both observers should have been ticked. | 2751 // Both observers should have been ticked. |
| 2673 EXPECT_EQ(0.75f, pending_dummy_impl.opacity()); | 2752 EXPECT_EQ(0.75f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2674 EXPECT_EQ(0.75f, dummy_impl.opacity()); | 2753 EXPECT_EQ(0.75f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2675 } | 2754 } |
| 2676 | 2755 |
| 2677 TEST(LayerAnimationControllerTest, | 2756 TEST(LayerAnimationControllerTest, |
| 2678 ObserverNotifiedWhenTransformIsPotentiallyAnimatingChanges) { | 2757 ObserverNotifiedWhenTransformIsPotentiallyAnimatingChanges) { |
| 2679 AnimationEvents events; | 2758 AnimationEvents events; |
| 2680 FakeLayerAnimationValueObserver active_dummy_impl; | 2759 FakeLayerAnimationValueObserver dummy_impl; |
| 2681 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | |
| 2682 scoped_refptr<LayerAnimationController> controller_impl( | 2760 scoped_refptr<LayerAnimationController> controller_impl( |
| 2683 LayerAnimationController::Create(0)); | 2761 LayerAnimationController::Create(0)); |
| 2684 controller_impl->AddValueObserver(&active_dummy_impl); | 2762 controller_impl->set_value_observer(&dummy_impl); |
| 2685 controller_impl->AddValueObserver(&pending_dummy_impl); | 2763 controller_impl->set_needs_active_value_observations(true); |
| 2764 controller_impl->set_needs_pending_value_observations(true); |
| 2765 |
| 2686 FakeLayerAnimationValueObserver dummy; | 2766 FakeLayerAnimationValueObserver dummy; |
| 2687 scoped_refptr<LayerAnimationController> controller( | 2767 scoped_refptr<LayerAnimationController> controller( |
| 2688 LayerAnimationController::Create(0)); | 2768 LayerAnimationController::Create(0)); |
| 2689 controller->AddValueObserver(&dummy); | 2769 controller->set_value_observer(&dummy); |
| 2770 controller->set_needs_active_value_observations(true); |
| 2690 | 2771 |
| 2691 EXPECT_FALSE(dummy.transform_is_animating()); | 2772 EXPECT_FALSE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2692 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2773 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2693 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2774 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2694 | 2775 |
| 2695 // Case 1: An animation that's allowed to run until its finish point. | 2776 // Case 1: An animation that's allowed to run until its finish point. |
| 2696 AddAnimatedTransformToController(controller.get(), 1.0, 1, 1); | 2777 AddAnimatedTransformToController(controller.get(), 1.0, 1, 1); |
| 2697 EXPECT_TRUE(dummy.transform_is_animating()); | 2778 EXPECT_TRUE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2698 | 2779 |
| 2699 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2780 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2700 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2781 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2701 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2782 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2702 | 2783 |
| 2703 controller_impl->ActivateAnimations(); | 2784 controller_impl->ActivateAnimations(); |
| 2704 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2785 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2705 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2786 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2706 | 2787 |
| 2707 controller_impl->Animate(kInitialTickTime); | 2788 controller_impl->Animate(kInitialTickTime); |
| 2708 controller_impl->UpdateState(true, &events); | 2789 controller_impl->UpdateState(true, &events); |
| 2709 | 2790 |
| 2710 controller->NotifyAnimationStarted(events.events_[0]); | 2791 controller->NotifyAnimationStarted(events.events_[0]); |
| 2711 events.events_.clear(); | 2792 events.events_.clear(); |
| 2712 | 2793 |
| 2713 // Finish the animation. | 2794 // Finish the animation. |
| 2714 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2795 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 2715 controller->UpdateState(true, nullptr); | 2796 controller->UpdateState(true, nullptr); |
| 2716 EXPECT_FALSE(dummy.transform_is_animating()); | 2797 EXPECT_FALSE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2717 | 2798 |
| 2718 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2799 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2719 | 2800 |
| 2720 // controller_impl hasn't yet ticked at/past the end of the animation. | 2801 // controller_impl hasn't yet ticked at/past the end of the animation. |
| 2721 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2802 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2722 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2803 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2723 | 2804 |
| 2724 controller_impl->Animate(kInitialTickTime + | 2805 controller_impl->Animate(kInitialTickTime + |
| 2725 TimeDelta::FromMilliseconds(1000)); | 2806 TimeDelta::FromMilliseconds(1000)); |
| 2726 controller_impl->UpdateState(true, &events); | 2807 controller_impl->UpdateState(true, &events); |
| 2727 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2808 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2728 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2809 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2729 | 2810 |
| 2730 controller->NotifyAnimationFinished(events.events_[0]); | 2811 controller->NotifyAnimationFinished(events.events_[0]); |
| 2731 events.events_.clear(); | 2812 events.events_.clear(); |
| 2732 | 2813 |
| 2733 // Case 2: An animation that's removed before it finishes. | 2814 // Case 2: An animation that's removed before it finishes. |
| 2734 int animation_id = | 2815 int animation_id = |
| 2735 AddAnimatedTransformToController(controller.get(), 10.0, 2, 2); | 2816 AddAnimatedTransformToController(controller.get(), 10.0, 2, 2); |
| 2736 EXPECT_TRUE(dummy.transform_is_animating()); | 2817 EXPECT_TRUE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2737 | 2818 |
| 2738 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2819 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2739 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2820 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2740 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2821 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2741 | 2822 |
| 2742 controller_impl->ActivateAnimations(); | 2823 controller_impl->ActivateAnimations(); |
| 2743 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2824 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2744 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2825 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2745 | 2826 |
| 2746 controller_impl->Animate(kInitialTickTime + | 2827 controller_impl->Animate(kInitialTickTime + |
| 2747 TimeDelta::FromMilliseconds(2000)); | 2828 TimeDelta::FromMilliseconds(2000)); |
| 2748 controller_impl->UpdateState(true, &events); | 2829 controller_impl->UpdateState(true, &events); |
| 2749 | 2830 |
| 2750 controller->NotifyAnimationStarted(events.events_[0]); | 2831 controller->NotifyAnimationStarted(events.events_[0]); |
| 2751 events.events_.clear(); | 2832 events.events_.clear(); |
| 2752 | 2833 |
| 2753 controller->RemoveAnimation(animation_id); | 2834 controller->RemoveAnimation(animation_id); |
| 2754 EXPECT_FALSE(dummy.transform_is_animating()); | 2835 EXPECT_FALSE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2755 | 2836 |
| 2756 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2837 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2757 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2838 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2758 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2839 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2759 | 2840 |
| 2760 controller_impl->ActivateAnimations(); | 2841 controller_impl->ActivateAnimations(); |
| 2761 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2842 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2762 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2843 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2763 | 2844 |
| 2764 // Case 3: An animation that's aborted before it finishes. | 2845 // Case 3: An animation that's aborted before it finishes. |
| 2765 animation_id = AddAnimatedTransformToController(controller.get(), 10.0, 3, 3); | 2846 animation_id = AddAnimatedTransformToController(controller.get(), 10.0, 3, 3); |
| 2766 EXPECT_TRUE(dummy.transform_is_animating()); | 2847 EXPECT_TRUE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2767 | 2848 |
| 2768 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2849 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2769 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2850 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2770 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2851 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2771 | 2852 |
| 2772 controller_impl->ActivateAnimations(); | 2853 controller_impl->ActivateAnimations(); |
| 2773 EXPECT_TRUE(pending_dummy_impl.transform_is_animating()); | 2854 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2774 EXPECT_TRUE(active_dummy_impl.transform_is_animating()); | 2855 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2775 | 2856 |
| 2776 controller_impl->Animate(kInitialTickTime + | 2857 controller_impl->Animate(kInitialTickTime + |
| 2777 TimeDelta::FromMilliseconds(3000)); | 2858 TimeDelta::FromMilliseconds(3000)); |
| 2778 controller_impl->UpdateState(true, &events); | 2859 controller_impl->UpdateState(true, &events); |
| 2779 | 2860 |
| 2780 controller->NotifyAnimationStarted(events.events_[0]); | 2861 controller->NotifyAnimationStarted(events.events_[0]); |
| 2781 events.events_.clear(); | 2862 events.events_.clear(); |
| 2782 | 2863 |
| 2783 controller_impl->AbortAnimations(TargetProperty::TRANSFORM); | 2864 controller_impl->AbortAnimations(TargetProperty::TRANSFORM); |
| 2784 EXPECT_FALSE(pending_dummy_impl.transform_is_animating()); | 2865 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); |
| 2785 EXPECT_FALSE(active_dummy_impl.transform_is_animating()); | 2866 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2786 | 2867 |
| 2787 controller_impl->Animate(kInitialTickTime + | 2868 controller_impl->Animate(kInitialTickTime + |
| 2788 TimeDelta::FromMilliseconds(4000)); | 2869 TimeDelta::FromMilliseconds(4000)); |
| 2789 controller_impl->UpdateState(true, &events); | 2870 controller_impl->UpdateState(true, &events); |
| 2790 | 2871 |
| 2791 controller->NotifyAnimationAborted(events.events_[0]); | 2872 controller->NotifyAnimationAborted(events.events_[0]); |
| 2792 EXPECT_FALSE(dummy.transform_is_animating()); | 2873 EXPECT_FALSE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); |
| 2793 } | 2874 } |
| 2794 | 2875 |
| 2795 TEST(LayerAnimationControllerTest, ClippedOpacityValues) { | 2876 TEST(LayerAnimationControllerTest, ClippedOpacityValues) { |
| 2796 FakeLayerAnimationValueObserver dummy; | 2877 FakeLayerAnimationValueObserver dummy; |
| 2797 scoped_refptr<LayerAnimationController> controller( | 2878 scoped_refptr<LayerAnimationController> controller( |
| 2798 LayerAnimationController::Create(0)); | 2879 LayerAnimationController::Create(0)); |
| 2799 controller->AddValueObserver(&dummy); | 2880 controller->set_value_observer(&dummy); |
| 2881 controller->set_needs_active_value_observations(true); |
| 2800 | 2882 |
| 2801 AddOpacityTransitionToController(controller.get(), 1, 1.f, 2.f, true); | 2883 AddOpacityTransitionToController(controller.get(), 1, 1.f, 2.f, true); |
| 2802 | 2884 |
| 2803 controller->Animate(kInitialTickTime); | 2885 controller->Animate(kInitialTickTime); |
| 2804 EXPECT_EQ(1.f, dummy.opacity()); | 2886 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 2805 | 2887 |
| 2806 // Opacity values are clipped [0,1] | 2888 // Opacity values are clipped [0,1] |
| 2807 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2889 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 2808 EXPECT_EQ(1.f, dummy.opacity()); | 2890 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 2809 } | 2891 } |
| 2810 | 2892 |
| 2811 TEST(LayerAnimationControllerTest, ClippedNegativeOpacityValues) { | 2893 TEST(LayerAnimationControllerTest, ClippedNegativeOpacityValues) { |
| 2812 FakeLayerAnimationValueObserver dummy; | 2894 FakeLayerAnimationValueObserver dummy; |
| 2813 scoped_refptr<LayerAnimationController> controller( | 2895 scoped_refptr<LayerAnimationController> controller( |
| 2814 LayerAnimationController::Create(0)); | 2896 LayerAnimationController::Create(0)); |
| 2815 controller->AddValueObserver(&dummy); | 2897 controller->set_value_observer(&dummy); |
| 2898 controller->set_needs_active_value_observations(true); |
| 2816 | 2899 |
| 2817 AddOpacityTransitionToController(controller.get(), 1, 0.f, -2.f, true); | 2900 AddOpacityTransitionToController(controller.get(), 1, 0.f, -2.f, true); |
| 2818 | 2901 |
| 2819 controller->Animate(kInitialTickTime); | 2902 controller->Animate(kInitialTickTime); |
| 2820 EXPECT_EQ(0.f, dummy.opacity()); | 2903 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 2821 | 2904 |
| 2822 // Opacity values are clipped [0,1] | 2905 // Opacity values are clipped [0,1] |
| 2823 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2906 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 2824 EXPECT_EQ(0.f, dummy.opacity()); | 2907 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 2825 } | 2908 } |
| 2826 | 2909 |
| 2827 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) { | 2910 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) { |
| 2828 std::unique_ptr<AnimationEvents> events( | 2911 std::unique_ptr<AnimationEvents> events( |
| 2829 base::WrapUnique(new AnimationEvents)); | 2912 base::WrapUnique(new AnimationEvents)); |
| 2830 FakeLayerAnimationValueObserver dummy_impl; | 2913 FakeLayerAnimationValueObserver dummy_impl; |
| 2831 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | |
| 2832 scoped_refptr<LayerAnimationController> controller_impl( | 2914 scoped_refptr<LayerAnimationController> controller_impl( |
| 2833 LayerAnimationController::Create(0)); | 2915 LayerAnimationController::Create(0)); |
| 2834 controller_impl->AddValueObserver(&dummy_impl); | 2916 controller_impl->set_value_observer(&dummy_impl); |
| 2835 controller_impl->AddValueObserver(&pending_dummy_impl); | 2917 controller_impl->set_needs_active_value_observations(true); |
| 2918 controller_impl->set_needs_pending_value_observations(true); |
| 2919 |
| 2836 FakeLayerAnimationValueObserver dummy; | 2920 FakeLayerAnimationValueObserver dummy; |
| 2837 scoped_refptr<LayerAnimationController> controller( | 2921 scoped_refptr<LayerAnimationController> controller( |
| 2838 LayerAnimationController::Create(0)); | 2922 LayerAnimationController::Create(0)); |
| 2839 controller->AddValueObserver(&dummy); | 2923 controller->set_value_observer(&dummy); |
| 2924 controller->set_needs_active_value_observations(true); |
| 2840 | 2925 |
| 2841 int animation_id = | 2926 int animation_id = |
| 2842 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); | 2927 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); |
| 2843 | 2928 |
| 2844 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2929 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2845 controller_impl->ActivateAnimations(); | 2930 controller_impl->ActivateAnimations(); |
| 2846 controller_impl->Animate(kInitialTickTime); | 2931 controller_impl->Animate(kInitialTickTime); |
| 2847 controller_impl->UpdateState(true, events.get()); | 2932 controller_impl->UpdateState(true, events.get()); |
| 2848 EXPECT_EQ(Animation::RUNNING, | 2933 EXPECT_EQ(Animation::RUNNING, |
| 2849 controller_impl->GetAnimationById(animation_id)->run_state()); | 2934 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 2850 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2935 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2851 EXPECT_EQ(0.5f, dummy_impl.opacity()); | 2936 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2852 | 2937 |
| 2853 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2938 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2854 ->affects_pending_observers()); | 2939 ->affects_pending_observers()); |
| 2855 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2940 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2856 ->affects_active_observers()); | 2941 ->affects_active_observers()); |
| 2857 | 2942 |
| 2858 // Delete the animation on the main-thread controller. | 2943 // Delete the animation on the main-thread controller. |
| 2859 controller->RemoveAnimation( | 2944 controller->RemoveAnimation( |
| 2860 controller->GetAnimation(TargetProperty::OPACITY)->id()); | 2945 controller->GetAnimation(TargetProperty::OPACITY)->id()); |
| 2861 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2946 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2862 | 2947 |
| 2863 // The animation should no longer affect pending observers. | 2948 // The animation should no longer affect pending observers. |
| 2864 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | 2949 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) |
| 2865 ->affects_pending_observers()); | 2950 ->affects_pending_observers()); |
| 2866 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | 2951 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) |
| 2867 ->affects_active_observers()); | 2952 ->affects_active_observers()); |
| 2868 | 2953 |
| 2869 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2954 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 2870 controller_impl->UpdateState(true, events.get()); | 2955 controller_impl->UpdateState(true, events.get()); |
| 2871 | 2956 |
| 2872 // Only the active observer should have been ticked. | 2957 // Only the active observer should have been ticked. |
| 2873 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); | 2958 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2874 EXPECT_EQ(0.75f, dummy_impl.opacity()); | 2959 EXPECT_EQ(0.75f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2875 | 2960 |
| 2876 controller_impl->ActivateAnimations(); | 2961 controller_impl->ActivateAnimations(); |
| 2877 | 2962 |
| 2878 // Activation should cause the animation to be deleted. | 2963 // Activation should cause the animation to be deleted. |
| 2879 EXPECT_FALSE(controller_impl->has_any_animation()); | 2964 EXPECT_FALSE(controller_impl->has_any_animation()); |
| 2880 } | 2965 } |
| 2881 | 2966 |
| 2882 // Tests that an animation that affects only active observers won't block | 2967 // Tests that an animation that affects only active observers won't block |
| 2883 // an animation that affects only pending observers from starting. | 2968 // an animation that affects only pending observers from starting. |
| 2884 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) { | 2969 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) { |
| 2885 std::unique_ptr<AnimationEvents> events( | 2970 std::unique_ptr<AnimationEvents> events( |
| 2886 base::WrapUnique(new AnimationEvents)); | 2971 base::WrapUnique(new AnimationEvents)); |
| 2887 FakeLayerAnimationValueObserver dummy_impl; | 2972 FakeLayerAnimationValueObserver dummy_impl; |
| 2888 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; | |
| 2889 scoped_refptr<LayerAnimationController> controller_impl( | 2973 scoped_refptr<LayerAnimationController> controller_impl( |
| 2890 LayerAnimationController::Create(0)); | 2974 LayerAnimationController::Create(0)); |
| 2891 controller_impl->AddValueObserver(&dummy_impl); | 2975 controller_impl->set_value_observer(&dummy_impl); |
| 2892 controller_impl->AddValueObserver(&pending_dummy_impl); | 2976 controller_impl->set_needs_active_value_observations(true); |
| 2977 controller_impl->set_needs_pending_value_observations(true); |
| 2978 |
| 2893 FakeLayerAnimationValueObserver dummy; | 2979 FakeLayerAnimationValueObserver dummy; |
| 2894 scoped_refptr<LayerAnimationController> controller( | 2980 scoped_refptr<LayerAnimationController> controller( |
| 2895 LayerAnimationController::Create(0)); | 2981 LayerAnimationController::Create(0)); |
| 2896 controller->AddValueObserver(&dummy); | 2982 controller->set_value_observer(&dummy); |
| 2983 controller->set_needs_active_value_observations(true); |
| 2897 | 2984 |
| 2898 int first_animation_id = | 2985 int first_animation_id = |
| 2899 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true); | 2986 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true); |
| 2900 | 2987 |
| 2901 controller->PushAnimationUpdatesTo(controller_impl.get()); | 2988 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 2902 controller_impl->ActivateAnimations(); | 2989 controller_impl->ActivateAnimations(); |
| 2903 controller_impl->Animate(kInitialTickTime); | 2990 controller_impl->Animate(kInitialTickTime); |
| 2904 controller_impl->UpdateState(true, events.get()); | 2991 controller_impl->UpdateState(true, events.get()); |
| 2905 | 2992 |
| 2906 // Remove the first animation from the main-thread controller, and add a | 2993 // 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 | 3015 // The original animation should still be running, and the new animation |
| 2929 // should be starting. | 3016 // should be starting. |
| 2930 EXPECT_EQ(Animation::RUNNING, | 3017 EXPECT_EQ(Animation::RUNNING, |
| 2931 controller_impl->GetAnimationById(first_animation_id)->run_state()); | 3018 controller_impl->GetAnimationById(first_animation_id)->run_state()); |
| 2932 EXPECT_EQ( | 3019 EXPECT_EQ( |
| 2933 Animation::STARTING, | 3020 Animation::STARTING, |
| 2934 controller_impl->GetAnimationById(second_animation_id)->run_state()); | 3021 controller_impl->GetAnimationById(second_animation_id)->run_state()); |
| 2935 | 3022 |
| 2936 // The active observer should have been ticked by the original animation, | 3023 // The active observer should have been ticked by the original animation, |
| 2937 // and the pending observer should have been ticked by the new animation. | 3024 // and the pending observer should have been ticked by the new animation. |
| 2938 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); | 3025 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2939 EXPECT_EQ(0.5f, dummy_impl.opacity()); | 3026 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2940 | 3027 |
| 2941 controller_impl->ActivateAnimations(); | 3028 controller_impl->ActivateAnimations(); |
| 2942 | 3029 |
| 2943 // The original animation should have been deleted, and the new animation | 3030 // The original animation should have been deleted, and the new animation |
| 2944 // should now affect both observers. | 3031 // should now affect both observers. |
| 2945 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id)); | 3032 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id)); |
| 2946 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) | 3033 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) |
| 2947 ->affects_pending_observers()); | 3034 ->affects_pending_observers()); |
| 2948 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) | 3035 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) |
| 2949 ->affects_active_observers()); | 3036 ->affects_active_observers()); |
| 2950 | 3037 |
| 2951 controller_impl->Animate(kInitialTickTime + | 3038 controller_impl->Animate(kInitialTickTime + |
| 2952 TimeDelta::FromMilliseconds(1000)); | 3039 TimeDelta::FromMilliseconds(1000)); |
| 2953 controller_impl->UpdateState(true, events.get()); | 3040 controller_impl->UpdateState(true, events.get()); |
| 2954 | 3041 |
| 2955 // The new animation should be running, and the active observer should have | 3042 // The new animation should be running, and the active observer should have |
| 2956 // been ticked at the new animation's starting point. | 3043 // been ticked at the new animation's starting point. |
| 2957 EXPECT_EQ( | 3044 EXPECT_EQ( |
| 2958 Animation::RUNNING, | 3045 Animation::RUNNING, |
| 2959 controller_impl->GetAnimationById(second_animation_id)->run_state()); | 3046 controller_impl->GetAnimationById(second_animation_id)->run_state()); |
| 2960 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); | 3047 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::PENDING)); |
| 2961 EXPECT_EQ(1.f, dummy_impl.opacity()); | 3048 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); |
| 2962 } | 3049 } |
| 2963 | 3050 |
| 2964 TEST(LayerAnimationControllerTest, TestIsCurrentlyAnimatingProperty) { | 3051 TEST(LayerAnimationControllerTest, TestIsCurrentlyAnimatingProperty) { |
| 2965 FakeLayerAnimationValueObserver dummy; | 3052 FakeLayerAnimationValueObserver dummy; |
| 2966 scoped_refptr<LayerAnimationController> controller( | 3053 scoped_refptr<LayerAnimationController> controller( |
| 2967 LayerAnimationController::Create(0)); | 3054 LayerAnimationController::Create(0)); |
| 2968 controller->AddValueObserver(&dummy); | 3055 controller->set_value_observer(&dummy); |
| 3056 controller->set_needs_active_value_observations(true); |
| 2969 | 3057 |
| 2970 // Create an animation that initially affects only pending observers. | 3058 // Create an animation that initially affects only pending observers. |
| 2971 std::unique_ptr<Animation> animation(CreateAnimation( | 3059 std::unique_ptr<Animation> animation(CreateAnimation( |
| 2972 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 3060 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 2973 1, TargetProperty::OPACITY)); | 3061 1, TargetProperty::OPACITY)); |
| 2974 animation->set_affects_active_observers(false); | 3062 animation->set_affects_active_observers(false); |
| 2975 | 3063 |
| 2976 controller->AddAnimation(std::move(animation)); | 3064 controller->AddAnimation(std::move(animation)); |
| 2977 controller->Animate(kInitialTickTime); | 3065 controller->Animate(kInitialTickTime); |
| 2978 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | 3066 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3011 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | 3099 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( |
| 3012 TargetProperty::OPACITY, | 3100 TargetProperty::OPACITY, |
| 3013 LayerAnimationController::ObserverType::PENDING)); | 3101 LayerAnimationController::ObserverType::PENDING)); |
| 3014 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | 3102 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( |
| 3015 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 3103 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3016 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3104 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3017 TargetProperty::FILTER, LayerAnimationController::ObserverType::PENDING)); | 3105 TargetProperty::FILTER, LayerAnimationController::ObserverType::PENDING)); |
| 3018 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3106 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3019 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); | 3107 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); |
| 3020 | 3108 |
| 3021 EXPECT_EQ(0.f, dummy.opacity()); | 3109 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 3022 | 3110 |
| 3023 // Tick past the end of the animation. | 3111 // Tick past the end of the animation. |
| 3024 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1100)); | 3112 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1100)); |
| 3025 controller->UpdateState(true, nullptr); | 3113 controller->UpdateState(true, nullptr); |
| 3026 | 3114 |
| 3027 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3115 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3028 TargetProperty::OPACITY, | 3116 TargetProperty::OPACITY, |
| 3029 LayerAnimationController::ObserverType::PENDING)); | 3117 LayerAnimationController::ObserverType::PENDING)); |
| 3030 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3118 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3031 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 3119 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3032 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3120 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3033 TargetProperty::FILTER, LayerAnimationController::ObserverType::PENDING)); | 3121 TargetProperty::FILTER, LayerAnimationController::ObserverType::PENDING)); |
| 3034 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3122 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3035 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); | 3123 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); |
| 3036 | 3124 |
| 3037 EXPECT_EQ(1.f, dummy.opacity()); | 3125 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); |
| 3038 } | 3126 } |
| 3039 | 3127 |
| 3040 TEST(LayerAnimationControllerTest, TestIsAnimatingPropertyTimeOffsetFillMode) { | 3128 TEST(LayerAnimationControllerTest, TestIsAnimatingPropertyTimeOffsetFillMode) { |
| 3041 FakeLayerAnimationValueObserver dummy; | 3129 FakeLayerAnimationValueObserver dummy; |
| 3042 scoped_refptr<LayerAnimationController> controller( | 3130 scoped_refptr<LayerAnimationController> controller( |
| 3043 LayerAnimationController::Create(0)); | 3131 LayerAnimationController::Create(0)); |
| 3044 controller->AddValueObserver(&dummy); | 3132 controller->set_value_observer(&dummy); |
| 3133 controller->set_needs_active_value_observations(true); |
| 3045 | 3134 |
| 3046 // Create an animation that initially affects only pending observers, and has | 3135 // Create an animation that initially affects only pending observers, and has |
| 3047 // a start delay of 2 seconds. | 3136 // a start delay of 2 seconds. |
| 3048 std::unique_ptr<Animation> animation(CreateAnimation( | 3137 std::unique_ptr<Animation> animation(CreateAnimation( |
| 3049 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 3138 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 3050 1, TargetProperty::OPACITY)); | 3139 1, TargetProperty::OPACITY)); |
| 3051 animation->set_fill_mode(Animation::FILL_MODE_NONE); | 3140 animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 3052 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); | 3141 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); |
| 3053 animation->set_affects_active_observers(false); | 3142 animation->set_affects_active_observers(false); |
| 3054 | 3143 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3121 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 3210 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3122 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3211 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3123 TargetProperty::OPACITY, | 3212 TargetProperty::OPACITY, |
| 3124 LayerAnimationController::ObserverType::PENDING)); | 3213 LayerAnimationController::ObserverType::PENDING)); |
| 3125 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3214 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3126 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 3215 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3127 } | 3216 } |
| 3128 | 3217 |
| 3129 } // namespace | 3218 } // namespace |
| 3130 } // namespace cc | 3219 } // namespace cc |
| OLD | NEW |