| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/animation/layer_animation_controller.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "cc/animation/animation.h" | |
| 11 #include "cc/animation/animation_curve.h" | |
| 12 #include "cc/animation/animation_delegate.h" | |
| 13 #include "cc/animation/animation_events.h" | |
| 14 #include "cc/animation/animation_host.h" | |
| 15 #include "cc/animation/keyframed_animation_curve.h" | |
| 16 #include "cc/animation/scroll_offset_animation_curve.h" | |
| 17 #include "cc/animation/transform_operations.h" | |
| 18 #include "cc/test/animation_test_common.h" | |
| 19 #include "testing/gmock/include/gmock/gmock.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | |
| 21 #include "ui/gfx/geometry/box_f.h" | |
| 22 #include "ui/gfx/transform.h" | |
| 23 | |
| 24 namespace cc { | |
| 25 namespace { | |
| 26 | |
| 27 using base::TimeDelta; | |
| 28 using base::TimeTicks; | |
| 29 | |
| 30 static base::TimeTicks TicksFromSecondsF(double seconds) { | |
| 31 return base::TimeTicks::FromInternalValue(seconds * | |
| 32 base::Time::kMicrosecondsPerSecond); | |
| 33 } | |
| 34 | |
| 35 // A LayerAnimationController cannot be ticked at 0.0, since an animation | |
| 36 // with start time 0.0 is treated as an animation whose start time has | |
| 37 // not yet been set. | |
| 38 const TimeTicks kInitialTickTime = TicksFromSecondsF(1.0); | |
| 39 | |
| 40 std::unique_ptr<Animation> CreateAnimation( | |
| 41 std::unique_ptr<AnimationCurve> curve, | |
| 42 int group_id, | |
| 43 TargetProperty::Type property) { | |
| 44 return Animation::Create(std::move(curve), 0, group_id, property); | |
| 45 } | |
| 46 | |
| 47 TEST(LayerAnimationControllerTest, SyncNewAnimation) { | |
| 48 FakeLayerAnimationValueObserver dummy_impl; | |
| 49 scoped_refptr<LayerAnimationController> controller_impl( | |
| 50 LayerAnimationController::Create(0)); | |
| 51 controller_impl->set_value_observer(&dummy_impl); | |
| 52 controller_impl->set_needs_active_value_observations(true); | |
| 53 | |
| 54 FakeLayerAnimationValueObserver dummy; | |
| 55 scoped_refptr<LayerAnimationController> controller( | |
| 56 LayerAnimationController::Create(0)); | |
| 57 controller->set_value_observer(&dummy); | |
| 58 controller_impl->set_needs_active_value_observations(true); | |
| 59 | |
| 60 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); | |
| 61 | |
| 62 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | |
| 63 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | |
| 64 | |
| 65 int animation_id = | |
| 66 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | |
| 67 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | |
| 68 | |
| 69 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 70 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); | |
| 71 controller_impl->ActivateAnimations(); | |
| 72 | |
| 73 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 74 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 75 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 76 } | |
| 77 | |
| 78 TEST(LayerAnimationControllerTest, | |
| 79 SyncScrollOffsetAnimationRespectsHasSetInitialValue) { | |
| 80 FakeLayerAnimationValueObserver dummy_impl; | |
| 81 FakeLayerAnimationValueProvider dummy_provider_impl; | |
| 82 scoped_refptr<LayerAnimationController> controller_impl( | |
| 83 LayerAnimationController::Create(0)); | |
| 84 controller_impl->set_value_observer(&dummy_impl); | |
| 85 controller_impl->set_needs_active_value_observations(true); | |
| 86 controller_impl->set_value_provider(&dummy_provider_impl); | |
| 87 | |
| 88 FakeLayerAnimationValueObserver dummy; | |
| 89 FakeLayerAnimationValueProvider dummy_provider; | |
| 90 scoped_refptr<LayerAnimationController> controller( | |
| 91 LayerAnimationController::Create(0)); | |
| 92 controller->set_value_observer(&dummy); | |
| 93 controller->set_needs_active_value_observations(true); | |
| 94 controller->set_value_provider(&dummy_provider); | |
| 95 | |
| 96 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); | |
| 97 | |
| 98 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | |
| 99 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | |
| 100 | |
| 101 gfx::ScrollOffset initial_value(100.f, 300.f); | |
| 102 gfx::ScrollOffset provider_initial_value(150.f, 300.f); | |
| 103 gfx::ScrollOffset target_value(300.f, 200.f); | |
| 104 | |
| 105 dummy_provider_impl.set_scroll_offset(provider_initial_value); | |
| 106 | |
| 107 // Animation with initial value set. | |
| 108 std::unique_ptr<ScrollOffsetAnimationCurve> curve_fixed( | |
| 109 ScrollOffsetAnimationCurve::Create(target_value, | |
| 110 EaseInOutTimingFunction::Create())); | |
| 111 curve_fixed->SetInitialValue(initial_value); | |
| 112 std::unique_ptr<Animation> animation_fixed( | |
| 113 Animation::Create(std::move(curve_fixed), 1 /* animation_id */, 0, | |
| 114 TargetProperty::SCROLL_OFFSET)); | |
| 115 controller->AddAnimation(std::move(animation_fixed)); | |
| 116 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 117 EXPECT_VECTOR2DF_EQ(initial_value, controller_impl->GetAnimationById(1) | |
| 118 ->curve() | |
| 119 ->ToScrollOffsetAnimationCurve() | |
| 120 ->GetValue(base::TimeDelta())); | |
| 121 | |
| 122 // Animation without initial value set. | |
| 123 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | |
| 124 ScrollOffsetAnimationCurve::Create(target_value, | |
| 125 EaseInOutTimingFunction::Create())); | |
| 126 std::unique_ptr<Animation> animation( | |
| 127 Animation::Create(std::move(curve), 2 /* animation id */, 0, | |
| 128 TargetProperty::SCROLL_OFFSET)); | |
| 129 controller->AddAnimation(std::move(animation)); | |
| 130 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 131 EXPECT_VECTOR2DF_EQ(provider_initial_value, | |
| 132 controller_impl->GetAnimationById(2) | |
| 133 ->curve() | |
| 134 ->ToScrollOffsetAnimationCurve() | |
| 135 ->GetValue(base::TimeDelta())); | |
| 136 } | |
| 137 | |
| 138 // If an animation is started on the impl thread before it is ticked on the main | |
| 139 // thread, we must be sure to respect the synchronized start time. | |
| 140 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) { | |
| 141 FakeLayerAnimationValueObserver dummy_impl; | |
| 142 scoped_refptr<LayerAnimationController> controller_impl( | |
| 143 LayerAnimationController::Create(0)); | |
| 144 controller_impl->set_value_observer(&dummy_impl); | |
| 145 controller_impl->set_needs_active_value_observations(true); | |
| 146 | |
| 147 FakeLayerAnimationValueObserver dummy; | |
| 148 scoped_refptr<LayerAnimationController> controller( | |
| 149 LayerAnimationController::Create(0)); | |
| 150 controller->set_value_observer(&dummy); | |
| 151 controller->set_needs_active_value_observations(true); | |
| 152 | |
| 153 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); | |
| 154 | |
| 155 int animation_id = | |
| 156 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | |
| 157 | |
| 158 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 159 controller_impl->ActivateAnimations(); | |
| 160 | |
| 161 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 162 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 163 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 164 | |
| 165 AnimationEvents events; | |
| 166 controller_impl->Animate(kInitialTickTime); | |
| 167 controller_impl->UpdateState(true, &events); | |
| 168 | |
| 169 // Synchronize the start times. | |
| 170 EXPECT_EQ(1u, events.events_.size()); | |
| 171 controller->NotifyAnimationStarted(events.events_[0]); | |
| 172 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | |
| 173 controller_impl->GetAnimationById(animation_id)->start_time()); | |
| 174 | |
| 175 // Start the animation on the main thread. Should not affect the start time. | |
| 176 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 177 controller->UpdateState(true, nullptr); | |
| 178 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | |
| 179 controller_impl->GetAnimationById(animation_id)->start_time()); | |
| 180 } | |
| 181 | |
| 182 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) { | |
| 183 FakeLayerAnimationValueObserver dummy_impl; | |
| 184 scoped_refptr<LayerAnimationController> controller_impl( | |
| 185 LayerAnimationController::Create(0)); | |
| 186 controller_impl->set_value_observer(&dummy_impl); | |
| 187 controller_impl->set_needs_active_value_observations(true); | |
| 188 | |
| 189 FakeLayerAnimationValueObserver dummy; | |
| 190 scoped_refptr<LayerAnimationController> controller( | |
| 191 LayerAnimationController::Create(0)); | |
| 192 controller->set_value_observer(&dummy); | |
| 193 controller->set_needs_active_value_observations(true); | |
| 194 | |
| 195 int animation_id = | |
| 196 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | |
| 197 | |
| 198 const TimeTicks start_time = TicksFromSecondsF(123); | |
| 199 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); | |
| 200 | |
| 201 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 202 controller_impl->ActivateAnimations(); | |
| 203 | |
| 204 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 205 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 206 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 207 | |
| 208 AnimationEvents events; | |
| 209 controller_impl->Animate(kInitialTickTime); | |
| 210 controller_impl->UpdateState(true, &events); | |
| 211 | |
| 212 // Synchronize the start times. | |
| 213 EXPECT_EQ(1u, events.events_.size()); | |
| 214 controller->NotifyAnimationStarted(events.events_[0]); | |
| 215 | |
| 216 EXPECT_EQ(start_time, | |
| 217 controller->GetAnimationById(animation_id)->start_time()); | |
| 218 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | |
| 219 controller_impl->GetAnimationById(animation_id)->start_time()); | |
| 220 | |
| 221 // Start the animation on the main thread. Should not affect the start time. | |
| 222 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 223 controller->UpdateState(true, nullptr); | |
| 224 EXPECT_EQ(start_time, | |
| 225 controller->GetAnimationById(animation_id)->start_time()); | |
| 226 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | |
| 227 controller_impl->GetAnimationById(animation_id)->start_time()); | |
| 228 } | |
| 229 | |
| 230 // Tests that controllers activate and deactivate as expected. | |
| 231 TEST(LayerAnimationControllerTest, Activation) { | |
| 232 std::unique_ptr<AnimationHost> host = | |
| 233 AnimationHost::Create(ThreadInstance::MAIN); | |
| 234 std::unique_ptr<AnimationHost> host_impl = | |
| 235 AnimationHost::Create(ThreadInstance::IMPL); | |
| 236 | |
| 237 FakeLayerAnimationValueObserver dummy_impl; | |
| 238 scoped_refptr<LayerAnimationController> controller_impl( | |
| 239 LayerAnimationController::Create(0)); | |
| 240 controller_impl->set_value_observer(&dummy_impl); | |
| 241 controller_impl->set_needs_active_value_observations(true); | |
| 242 | |
| 243 FakeLayerAnimationValueObserver dummy; | |
| 244 scoped_refptr<LayerAnimationController> controller( | |
| 245 LayerAnimationController::Create(0)); | |
| 246 controller->set_value_observer(&dummy); | |
| 247 controller->set_needs_active_value_observations(true); | |
| 248 | |
| 249 std::unique_ptr<AnimationEvents> events = host->CreateEvents(); | |
| 250 | |
| 251 controller->SetAnimationHost(host.get()); | |
| 252 controller_impl->SetAnimationHost(host_impl.get()); | |
| 253 EXPECT_EQ(1u, host->all_animation_controllers_for_testing().size()); | |
| 254 EXPECT_EQ(1u, host_impl->all_animation_controllers_for_testing().size()); | |
| 255 | |
| 256 // Initially, both controllers should be inactive. | |
| 257 EXPECT_EQ(0u, host->active_animation_controllers_for_testing().size()); | |
| 258 EXPECT_EQ(0u, host_impl->active_animation_controllers_for_testing().size()); | |
| 259 | |
| 260 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | |
| 261 // The main thread controller should now be active. | |
| 262 EXPECT_EQ(1u, host->active_animation_controllers_for_testing().size()); | |
| 263 | |
| 264 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 265 controller_impl->ActivateAnimations(); | |
| 266 // Both controllers should now be active. | |
| 267 EXPECT_EQ(1u, host->active_animation_controllers_for_testing().size()); | |
| 268 EXPECT_EQ(1u, host_impl->active_animation_controllers_for_testing().size()); | |
| 269 | |
| 270 controller_impl->Animate(kInitialTickTime); | |
| 271 controller_impl->UpdateState(true, events.get()); | |
| 272 EXPECT_EQ(1u, events->events_.size()); | |
| 273 controller->NotifyAnimationStarted(events->events_[0]); | |
| 274 | |
| 275 EXPECT_EQ(1u, host->active_animation_controllers_for_testing().size()); | |
| 276 EXPECT_EQ(1u, host_impl->active_animation_controllers_for_testing().size()); | |
| 277 | |
| 278 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 279 controller->UpdateState(true, nullptr); | |
| 280 EXPECT_EQ(1u, host->active_animation_controllers_for_testing().size()); | |
| 281 | |
| 282 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 283 controller->UpdateState(true, nullptr); | |
| 284 EXPECT_EQ(Animation::FINISHED, | |
| 285 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 286 EXPECT_EQ(1u, host->active_animation_controllers_for_testing().size()); | |
| 287 | |
| 288 events.reset(new AnimationEvents); | |
| 289 controller_impl->Animate(kInitialTickTime + | |
| 290 TimeDelta::FromMilliseconds(1500)); | |
| 291 controller_impl->UpdateState(true, events.get()); | |
| 292 | |
| 293 EXPECT_EQ( | |
| 294 Animation::WAITING_FOR_DELETION, | |
| 295 controller_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 296 // The impl thread controller should have de-activated. | |
| 297 EXPECT_EQ(0u, host_impl->active_animation_controllers_for_testing().size()); | |
| 298 | |
| 299 EXPECT_EQ(1u, events->events_.size()); | |
| 300 controller->NotifyAnimationFinished(events->events_[0]); | |
| 301 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | |
| 302 controller->UpdateState(true, nullptr); | |
| 303 | |
| 304 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | |
| 305 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 306 // The main thread controller should have de-activated. | |
| 307 EXPECT_EQ(0u, host->active_animation_controllers_for_testing().size()); | |
| 308 | |
| 309 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 310 controller_impl->ActivateAnimations(); | |
| 311 EXPECT_FALSE(controller->has_any_animation()); | |
| 312 EXPECT_FALSE(controller_impl->has_any_animation()); | |
| 313 EXPECT_EQ(0u, host->active_animation_controllers_for_testing().size()); | |
| 314 EXPECT_EQ(0u, host_impl->active_animation_controllers_for_testing().size()); | |
| 315 | |
| 316 controller->SetAnimationHost(nullptr); | |
| 317 controller_impl->SetAnimationHost(nullptr); | |
| 318 } | |
| 319 | |
| 320 TEST(LayerAnimationControllerTest, SyncPause) { | |
| 321 FakeLayerAnimationValueObserver dummy_impl; | |
| 322 scoped_refptr<LayerAnimationController> controller_impl( | |
| 323 LayerAnimationController::Create(0)); | |
| 324 controller_impl->set_value_observer(&dummy_impl); | |
| 325 controller_impl->set_needs_active_value_observations(true); | |
| 326 | |
| 327 FakeLayerAnimationValueObserver dummy; | |
| 328 scoped_refptr<LayerAnimationController> controller( | |
| 329 LayerAnimationController::Create(0)); | |
| 330 controller->set_value_observer(&dummy); | |
| 331 controller->set_needs_active_value_observations(true); | |
| 332 | |
| 333 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); | |
| 334 | |
| 335 // Two steps, three ranges: [0-1) -> 0.2, [1-2) -> 0.3, [2-3] -> 0.4. | |
| 336 const double duration = 3.0; | |
| 337 const int animation_id = | |
| 338 AddOpacityStepsToController(controller.get(), duration, 0.2f, 0.4f, 2); | |
| 339 | |
| 340 // Set start offset to be at the beginning of the second range. | |
| 341 controller->GetAnimationById(animation_id) | |
| 342 ->set_time_offset(TimeDelta::FromSecondsD(1.01)); | |
| 343 | |
| 344 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 345 controller_impl->ActivateAnimations(); | |
| 346 | |
| 347 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 348 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 349 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 350 | |
| 351 TimeTicks time = kInitialTickTime; | |
| 352 | |
| 353 // Start the animations on each controller. | |
| 354 AnimationEvents events; | |
| 355 controller_impl->Animate(time); | |
| 356 controller_impl->UpdateState(true, &events); | |
| 357 EXPECT_EQ(1u, events.events_.size()); | |
| 358 | |
| 359 controller->Animate(time); | |
| 360 controller->UpdateState(true, nullptr); | |
| 361 controller->NotifyAnimationStarted(events.events_[0]); | |
| 362 | |
| 363 EXPECT_EQ(Animation::RUNNING, | |
| 364 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 365 EXPECT_EQ(Animation::RUNNING, | |
| 366 controller->GetAnimationById(animation_id)->run_state()); | |
| 367 | |
| 368 EXPECT_EQ(0.3f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 369 EXPECT_EQ(0.3f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 370 | |
| 371 EXPECT_EQ(kInitialTickTime, | |
| 372 controller->GetAnimationById(animation_id)->start_time()); | |
| 373 EXPECT_EQ(kInitialTickTime, | |
| 374 controller_impl->GetAnimationById(animation_id)->start_time()); | |
| 375 | |
| 376 // Pause the animation at the middle of the second range so the offset | |
| 377 // delays animation until the middle of the third range. | |
| 378 controller->PauseAnimation(animation_id, TimeDelta::FromSecondsD(1.5)); | |
| 379 EXPECT_EQ(Animation::PAUSED, | |
| 380 controller->GetAnimationById(animation_id)->run_state()); | |
| 381 | |
| 382 // The pause run state change should make it to the impl thread controller. | |
| 383 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 384 controller_impl->ActivateAnimations(); | |
| 385 | |
| 386 // Advance time so it stays within the first range. | |
| 387 time += TimeDelta::FromMilliseconds(10); | |
| 388 controller->Animate(time); | |
| 389 controller_impl->Animate(time); | |
| 390 | |
| 391 EXPECT_EQ(Animation::PAUSED, | |
| 392 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 393 | |
| 394 // Opacity value doesn't depend on time if paused at specified time offset. | |
| 395 EXPECT_EQ(0.4f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 396 EXPECT_EQ(0.4f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 397 } | |
| 398 | |
| 399 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { | |
| 400 FakeLayerAnimationValueObserver dummy_impl; | |
| 401 scoped_refptr<LayerAnimationController> controller_impl( | |
| 402 LayerAnimationController::Create(0)); | |
| 403 controller_impl->set_value_observer(&dummy_impl); | |
| 404 controller_impl->set_needs_active_value_observations(true); | |
| 405 | |
| 406 FakeLayerAnimationValueObserver dummy; | |
| 407 scoped_refptr<LayerAnimationController> controller( | |
| 408 LayerAnimationController::Create(0)); | |
| 409 controller->set_value_observer(&dummy); | |
| 410 controller->set_needs_active_value_observations(true); | |
| 411 | |
| 412 std::unique_ptr<AnimationEvents> events( | |
| 413 base::WrapUnique(new AnimationEvents)); | |
| 414 | |
| 415 EXPECT_FALSE(controller_impl->GetAnimation(TargetProperty::OPACITY)); | |
| 416 | |
| 417 int animation_id = | |
| 418 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | |
| 419 | |
| 420 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 421 controller_impl->ActivateAnimations(); | |
| 422 | |
| 423 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 424 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 425 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 426 | |
| 427 events.reset(new AnimationEvents); | |
| 428 controller_impl->Animate(kInitialTickTime); | |
| 429 controller_impl->UpdateState(true, events.get()); | |
| 430 EXPECT_EQ(1u, events->events_.size()); | |
| 431 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); | |
| 432 | |
| 433 // Notify main thread controller that the animation has started. | |
| 434 controller->NotifyAnimationStarted(events->events_[0]); | |
| 435 | |
| 436 // Complete animation on impl thread. | |
| 437 events.reset(new AnimationEvents); | |
| 438 controller_impl->Animate(kInitialTickTime + TimeDelta::FromSeconds(1)); | |
| 439 controller_impl->UpdateState(true, events.get()); | |
| 440 EXPECT_EQ(1u, events->events_.size()); | |
| 441 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); | |
| 442 | |
| 443 controller->NotifyAnimationFinished(events->events_[0]); | |
| 444 | |
| 445 controller->Animate(kInitialTickTime + TimeDelta::FromSeconds(2)); | |
| 446 controller->UpdateState(true, nullptr); | |
| 447 | |
| 448 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 449 controller_impl->ActivateAnimations(); | |
| 450 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | |
| 451 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | |
| 452 } | |
| 453 | |
| 454 // Ensure that a finished animation is eventually deleted by both the | |
| 455 // main-thread and the impl-thread controllers. | |
| 456 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) { | |
| 457 FakeLayerAnimationValueObserver dummy; | |
| 458 FakeLayerAnimationValueObserver dummy_impl; | |
| 459 std::unique_ptr<AnimationEvents> events( | |
| 460 base::WrapUnique(new AnimationEvents)); | |
| 461 scoped_refptr<LayerAnimationController> controller( | |
| 462 LayerAnimationController::Create(0)); | |
| 463 scoped_refptr<LayerAnimationController> controller_impl( | |
| 464 LayerAnimationController::Create(0)); | |
| 465 controller->set_value_observer(&dummy); | |
| 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); | |
| 469 | |
| 470 AddOpacityTransitionToController(controller.get(), 1.0, 0.0f, 1.0f, false); | |
| 471 controller->Animate(kInitialTickTime); | |
| 472 controller->UpdateState(true, nullptr); | |
| 473 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 474 controller_impl->ActivateAnimations(); | |
| 475 | |
| 476 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 477 controller_impl->UpdateState(true, events.get()); | |
| 478 | |
| 479 // There should be a STARTED event for the animation. | |
| 480 EXPECT_EQ(1u, events->events_.size()); | |
| 481 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); | |
| 482 controller->NotifyAnimationStarted(events->events_[0]); | |
| 483 | |
| 484 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 485 controller->UpdateState(true, nullptr); | |
| 486 | |
| 487 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | |
| 488 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | |
| 489 | |
| 490 events.reset(new AnimationEvents); | |
| 491 controller_impl->Animate(kInitialTickTime + | |
| 492 TimeDelta::FromMilliseconds(2000)); | |
| 493 controller_impl->UpdateState(true, events.get()); | |
| 494 | |
| 495 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | |
| 496 | |
| 497 // There should be a FINISHED event for the animation. | |
| 498 EXPECT_EQ(1u, events->events_.size()); | |
| 499 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); | |
| 500 | |
| 501 // Neither controller should have deleted the animation yet. | |
| 502 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); | |
| 503 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::OPACITY)); | |
| 504 | |
| 505 controller->NotifyAnimationFinished(events->events_[0]); | |
| 506 | |
| 507 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | |
| 508 controller->UpdateState(true, nullptr); | |
| 509 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | |
| 510 | |
| 511 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 512 | |
| 513 // Both controllers should now have deleted the animation. The impl controller | |
| 514 // should have deleted the animation even though activation has not occurred, | |
| 515 // since the animation was already waiting for deletion when | |
| 516 // PushAnimationUpdatesTo was called. | |
| 517 EXPECT_FALSE(controller->has_any_animation()); | |
| 518 EXPECT_FALSE(controller_impl->has_any_animation()); | |
| 519 } | |
| 520 | |
| 521 // Tests that transitioning opacity from 0 to 1 works as expected. | |
| 522 | |
| 523 static const AnimationEvent* GetMostRecentPropertyUpdateEvent( | |
| 524 const AnimationEvents* events) { | |
| 525 const AnimationEvent* event = 0; | |
| 526 for (size_t i = 0; i < events->events_.size(); ++i) | |
| 527 if (events->events_[i].type == AnimationEvent::PROPERTY_UPDATE) | |
| 528 event = &events->events_[i]; | |
| 529 | |
| 530 return event; | |
| 531 } | |
| 532 | |
| 533 TEST(LayerAnimationControllerTest, TrivialTransition) { | |
| 534 std::unique_ptr<AnimationEvents> events( | |
| 535 base::WrapUnique(new AnimationEvents)); | |
| 536 FakeLayerAnimationValueObserver dummy; | |
| 537 scoped_refptr<LayerAnimationController> controller( | |
| 538 LayerAnimationController::Create(0)); | |
| 539 controller->set_value_observer(&dummy); | |
| 540 controller->set_needs_active_value_observations(true); | |
| 541 | |
| 542 std::unique_ptr<Animation> to_add(CreateAnimation( | |
| 543 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 544 1, TargetProperty::OPACITY)); | |
| 545 | |
| 546 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | |
| 547 controller->AddAnimation(std::move(to_add)); | |
| 548 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | |
| 549 controller->Animate(kInitialTickTime); | |
| 550 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | |
| 551 controller->UpdateState(true, events.get()); | |
| 552 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 553 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 554 // A non-impl-only animation should not generate property updates. | |
| 555 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 556 EXPECT_FALSE(event); | |
| 557 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 558 controller->UpdateState(true, events.get()); | |
| 559 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 560 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 561 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 562 EXPECT_FALSE(event); | |
| 563 } | |
| 564 | |
| 565 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { | |
| 566 std::unique_ptr<AnimationEvents> events( | |
| 567 base::WrapUnique(new AnimationEvents)); | |
| 568 FakeLayerAnimationValueObserver dummy_impl; | |
| 569 scoped_refptr<LayerAnimationController> controller_impl( | |
| 570 LayerAnimationController::Create(0)); | |
| 571 controller_impl->set_value_observer(&dummy_impl); | |
| 572 controller_impl->set_needs_active_value_observations(true); | |
| 573 | |
| 574 std::unique_ptr<Animation> to_add(CreateAnimation( | |
| 575 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 576 1, TargetProperty::OPACITY)); | |
| 577 to_add->set_is_impl_only(true); | |
| 578 | |
| 579 controller_impl->AddAnimation(std::move(to_add)); | |
| 580 controller_impl->Animate(kInitialTickTime); | |
| 581 controller_impl->UpdateState(true, events.get()); | |
| 582 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | |
| 583 EXPECT_EQ(0.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 584 EXPECT_EQ(1u, events->events_.size()); | |
| 585 const AnimationEvent* start_opacity_event = | |
| 586 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 587 EXPECT_EQ(0.f, start_opacity_event->opacity); | |
| 588 | |
| 589 controller_impl->Animate(kInitialTickTime + | |
| 590 TimeDelta::FromMilliseconds(1000)); | |
| 591 controller_impl->UpdateState(true, events.get()); | |
| 592 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 593 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | |
| 594 EXPECT_EQ(2u, events->events_.size()); | |
| 595 const AnimationEvent* end_opacity_event = | |
| 596 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 597 EXPECT_EQ(1.f, end_opacity_event->opacity); | |
| 598 } | |
| 599 | |
| 600 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { | |
| 601 std::unique_ptr<AnimationEvents> events( | |
| 602 base::WrapUnique(new AnimationEvents)); | |
| 603 FakeLayerAnimationValueObserver dummy_impl; | |
| 604 scoped_refptr<LayerAnimationController> controller_impl( | |
| 605 LayerAnimationController::Create(0)); | |
| 606 controller_impl->set_value_observer(&dummy_impl); | |
| 607 controller_impl->set_needs_active_value_observations(true); | |
| 608 | |
| 609 // Choose different values for x and y to avoid coincidental values in the | |
| 610 // observed transforms. | |
| 611 const float delta_x = 3; | |
| 612 const float delta_y = 4; | |
| 613 | |
| 614 std::unique_ptr<KeyframedTransformAnimationCurve> curve( | |
| 615 KeyframedTransformAnimationCurve::Create()); | |
| 616 | |
| 617 // Create simple TRANSFORM animation. | |
| 618 TransformOperations operations; | |
| 619 curve->AddKeyframe( | |
| 620 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr)); | |
| 621 operations.AppendTranslate(delta_x, delta_y, 0); | |
| 622 curve->AddKeyframe(TransformKeyframe::Create( | |
| 623 base::TimeDelta::FromSecondsD(1.0), operations, nullptr)); | |
| 624 | |
| 625 std::unique_ptr<Animation> animation( | |
| 626 Animation::Create(std::move(curve), 1, 0, TargetProperty::TRANSFORM)); | |
| 627 animation->set_is_impl_only(true); | |
| 628 controller_impl->AddAnimation(std::move(animation)); | |
| 629 | |
| 630 // Run animation. | |
| 631 controller_impl->Animate(kInitialTickTime); | |
| 632 controller_impl->UpdateState(true, events.get()); | |
| 633 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | |
| 634 EXPECT_EQ(gfx::Transform(), dummy_impl.transform(LayerTreeType::ACTIVE)); | |
| 635 EXPECT_EQ(1u, events->events_.size()); | |
| 636 const AnimationEvent* start_transform_event = | |
| 637 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 638 ASSERT_TRUE(start_transform_event); | |
| 639 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); | |
| 640 EXPECT_TRUE(start_transform_event->is_impl_only); | |
| 641 | |
| 642 gfx::Transform expected_transform; | |
| 643 expected_transform.Translate(delta_x, delta_y); | |
| 644 | |
| 645 controller_impl->Animate(kInitialTickTime + | |
| 646 TimeDelta::FromMilliseconds(1000)); | |
| 647 controller_impl->UpdateState(true, events.get()); | |
| 648 EXPECT_EQ(expected_transform, dummy_impl.transform(LayerTreeType::ACTIVE)); | |
| 649 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | |
| 650 EXPECT_EQ(2u, events->events_.size()); | |
| 651 const AnimationEvent* end_transform_event = | |
| 652 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 653 EXPECT_EQ(expected_transform, end_transform_event->transform); | |
| 654 EXPECT_TRUE(end_transform_event->is_impl_only); | |
| 655 } | |
| 656 | |
| 657 TEST(LayerAnimationControllerTest, FilterTransition) { | |
| 658 std::unique_ptr<AnimationEvents> events( | |
| 659 base::WrapUnique(new AnimationEvents)); | |
| 660 FakeLayerAnimationValueObserver dummy; | |
| 661 scoped_refptr<LayerAnimationController> controller( | |
| 662 LayerAnimationController::Create(0)); | |
| 663 controller->set_value_observer(&dummy); | |
| 664 controller->set_needs_active_value_observations(true); | |
| 665 | |
| 666 std::unique_ptr<KeyframedFilterAnimationCurve> curve( | |
| 667 KeyframedFilterAnimationCurve::Create()); | |
| 668 | |
| 669 FilterOperations start_filters; | |
| 670 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); | |
| 671 curve->AddKeyframe( | |
| 672 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); | |
| 673 FilterOperations end_filters; | |
| 674 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | |
| 675 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | |
| 676 end_filters, nullptr)); | |
| 677 | |
| 678 std::unique_ptr<Animation> animation( | |
| 679 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); | |
| 680 controller->AddAnimation(std::move(animation)); | |
| 681 | |
| 682 controller->Animate(kInitialTickTime); | |
| 683 controller->UpdateState(true, events.get()); | |
| 684 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 685 EXPECT_EQ(start_filters, dummy.filters(LayerTreeType::ACTIVE)); | |
| 686 // A non-impl-only animation should not generate property updates. | |
| 687 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 688 EXPECT_FALSE(event); | |
| 689 | |
| 690 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 691 controller->UpdateState(true, events.get()); | |
| 692 EXPECT_EQ(1u, dummy.filters(LayerTreeType::ACTIVE).size()); | |
| 693 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), | |
| 694 dummy.filters(LayerTreeType::ACTIVE).at(0)); | |
| 695 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 696 EXPECT_FALSE(event); | |
| 697 | |
| 698 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 699 controller->UpdateState(true, events.get()); | |
| 700 EXPECT_EQ(end_filters, dummy.filters(LayerTreeType::ACTIVE)); | |
| 701 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 702 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 703 EXPECT_FALSE(event); | |
| 704 } | |
| 705 | |
| 706 TEST(LayerAnimationControllerTest, FilterTransitionOnImplOnly) { | |
| 707 std::unique_ptr<AnimationEvents> events( | |
| 708 base::WrapUnique(new AnimationEvents)); | |
| 709 FakeLayerAnimationValueObserver dummy_impl; | |
| 710 scoped_refptr<LayerAnimationController> controller_impl( | |
| 711 LayerAnimationController::Create(0)); | |
| 712 controller_impl->set_value_observer(&dummy_impl); | |
| 713 controller_impl->set_needs_active_value_observations(true); | |
| 714 | |
| 715 std::unique_ptr<KeyframedFilterAnimationCurve> curve( | |
| 716 KeyframedFilterAnimationCurve::Create()); | |
| 717 | |
| 718 // Create simple FILTER animation. | |
| 719 FilterOperations start_filters; | |
| 720 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); | |
| 721 curve->AddKeyframe( | |
| 722 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); | |
| 723 FilterOperations end_filters; | |
| 724 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | |
| 725 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | |
| 726 end_filters, nullptr)); | |
| 727 | |
| 728 std::unique_ptr<Animation> animation( | |
| 729 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); | |
| 730 animation->set_is_impl_only(true); | |
| 731 controller_impl->AddAnimation(std::move(animation)); | |
| 732 | |
| 733 // Run animation. | |
| 734 controller_impl->Animate(kInitialTickTime); | |
| 735 controller_impl->UpdateState(true, events.get()); | |
| 736 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | |
| 737 EXPECT_EQ(start_filters, dummy_impl.filters(LayerTreeType::ACTIVE)); | |
| 738 EXPECT_EQ(1u, events->events_.size()); | |
| 739 const AnimationEvent* start_filter_event = | |
| 740 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 741 EXPECT_TRUE(start_filter_event); | |
| 742 EXPECT_EQ(start_filters, start_filter_event->filters); | |
| 743 EXPECT_TRUE(start_filter_event->is_impl_only); | |
| 744 | |
| 745 controller_impl->Animate(kInitialTickTime + | |
| 746 TimeDelta::FromMilliseconds(1000)); | |
| 747 controller_impl->UpdateState(true, events.get()); | |
| 748 EXPECT_EQ(end_filters, dummy_impl.filters(LayerTreeType::ACTIVE)); | |
| 749 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | |
| 750 EXPECT_EQ(2u, events->events_.size()); | |
| 751 const AnimationEvent* end_filter_event = | |
| 752 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 753 EXPECT_TRUE(end_filter_event); | |
| 754 EXPECT_EQ(end_filters, end_filter_event->filters); | |
| 755 EXPECT_TRUE(end_filter_event->is_impl_only); | |
| 756 } | |
| 757 | |
| 758 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) { | |
| 759 FakeLayerAnimationValueObserver dummy_impl; | |
| 760 FakeLayerAnimationValueProvider dummy_provider_impl; | |
| 761 scoped_refptr<LayerAnimationController> controller_impl( | |
| 762 LayerAnimationController::Create(0)); | |
| 763 controller_impl->set_value_observer(&dummy_impl); | |
| 764 controller_impl->set_needs_active_value_observations(true); | |
| 765 | |
| 766 controller_impl->set_value_provider(&dummy_provider_impl); | |
| 767 std::unique_ptr<AnimationEvents> events( | |
| 768 base::WrapUnique(new AnimationEvents)); | |
| 769 FakeLayerAnimationValueObserver dummy; | |
| 770 FakeLayerAnimationValueProvider dummy_provider; | |
| 771 scoped_refptr<LayerAnimationController> controller( | |
| 772 LayerAnimationController::Create(0)); | |
| 773 controller->set_value_observer(&dummy); | |
| 774 controller->set_needs_active_value_observations(true); | |
| 775 controller->set_value_provider(&dummy_provider); | |
| 776 | |
| 777 gfx::ScrollOffset initial_value(100.f, 300.f); | |
| 778 gfx::ScrollOffset target_value(300.f, 200.f); | |
| 779 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | |
| 780 ScrollOffsetAnimationCurve::Create(target_value, | |
| 781 EaseInOutTimingFunction::Create())); | |
| 782 | |
| 783 std::unique_ptr<Animation> animation( | |
| 784 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | |
| 785 animation->set_needs_synchronized_start_time(true); | |
| 786 controller->AddAnimation(std::move(animation)); | |
| 787 | |
| 788 dummy_provider_impl.set_scroll_offset(initial_value); | |
| 789 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 790 controller_impl->ActivateAnimations(); | |
| 791 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); | |
| 792 TimeDelta duration = | |
| 793 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | |
| 794 ->curve() | |
| 795 ->Duration(); | |
| 796 EXPECT_EQ(duration, controller->GetAnimation(TargetProperty::SCROLL_OFFSET) | |
| 797 ->curve() | |
| 798 ->Duration()); | |
| 799 | |
| 800 controller->Animate(kInitialTickTime); | |
| 801 controller->UpdateState(true, nullptr); | |
| 802 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 803 EXPECT_EQ(initial_value, dummy.scroll_offset(LayerTreeType::ACTIVE)); | |
| 804 | |
| 805 controller_impl->Animate(kInitialTickTime); | |
| 806 controller_impl->UpdateState(true, events.get()); | |
| 807 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | |
| 808 EXPECT_EQ(initial_value, dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); | |
| 809 // Scroll offset animations should not generate property updates. | |
| 810 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 811 EXPECT_FALSE(event); | |
| 812 | |
| 813 controller->NotifyAnimationStarted(events->events_[0]); | |
| 814 controller->Animate(kInitialTickTime + duration / 2); | |
| 815 controller->UpdateState(true, nullptr); | |
| 816 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 817 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | |
| 818 dummy.scroll_offset(LayerTreeType::ACTIVE)); | |
| 819 | |
| 820 controller_impl->Animate(kInitialTickTime + duration / 2); | |
| 821 controller_impl->UpdateState(true, events.get()); | |
| 822 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | |
| 823 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); | |
| 824 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 825 EXPECT_FALSE(event); | |
| 826 | |
| 827 controller_impl->Animate(kInitialTickTime + duration); | |
| 828 controller_impl->UpdateState(true, events.get()); | |
| 829 EXPECT_VECTOR2DF_EQ(target_value, | |
| 830 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); | |
| 831 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | |
| 832 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 833 EXPECT_FALSE(event); | |
| 834 | |
| 835 controller->Animate(kInitialTickTime + duration); | |
| 836 controller->UpdateState(true, nullptr); | |
| 837 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset(LayerTreeType::ACTIVE)); | |
| 838 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 839 } | |
| 840 | |
| 841 // Ensure that when the impl controller doesn't have a value provider, | |
| 842 // the main-thread controller's value provider is used to obtain the intial | |
| 843 // scroll offset. | |
| 844 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { | |
| 845 FakeLayerAnimationValueObserver dummy_impl; | |
| 846 scoped_refptr<LayerAnimationController> controller_impl( | |
| 847 LayerAnimationController::Create(0)); | |
| 848 controller_impl->set_value_observer(&dummy_impl); | |
| 849 controller_impl->set_needs_active_value_observations(true); | |
| 850 | |
| 851 std::unique_ptr<AnimationEvents> events( | |
| 852 base::WrapUnique(new AnimationEvents)); | |
| 853 FakeLayerAnimationValueObserver dummy; | |
| 854 FakeLayerAnimationValueProvider dummy_provider; | |
| 855 scoped_refptr<LayerAnimationController> controller( | |
| 856 LayerAnimationController::Create(0)); | |
| 857 controller->set_value_observer(&dummy); | |
| 858 controller->set_needs_active_value_observations(true); | |
| 859 controller->set_value_provider(&dummy_provider); | |
| 860 | |
| 861 gfx::ScrollOffset initial_value(500.f, 100.f); | |
| 862 gfx::ScrollOffset target_value(300.f, 200.f); | |
| 863 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | |
| 864 ScrollOffsetAnimationCurve::Create(target_value, | |
| 865 EaseInOutTimingFunction::Create())); | |
| 866 | |
| 867 std::unique_ptr<Animation> animation( | |
| 868 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | |
| 869 animation->set_needs_synchronized_start_time(true); | |
| 870 controller->AddAnimation(std::move(animation)); | |
| 871 | |
| 872 dummy_provider.set_scroll_offset(initial_value); | |
| 873 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 874 controller_impl->ActivateAnimations(); | |
| 875 EXPECT_TRUE(controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); | |
| 876 TimeDelta duration = | |
| 877 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | |
| 878 ->curve() | |
| 879 ->Duration(); | |
| 880 EXPECT_EQ(duration, controller->GetAnimation(TargetProperty::SCROLL_OFFSET) | |
| 881 ->curve() | |
| 882 ->Duration()); | |
| 883 | |
| 884 controller->Animate(kInitialTickTime); | |
| 885 controller->UpdateState(true, nullptr); | |
| 886 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 887 EXPECT_EQ(initial_value, dummy.scroll_offset(LayerTreeType::ACTIVE)); | |
| 888 | |
| 889 controller_impl->Animate(kInitialTickTime); | |
| 890 controller_impl->UpdateState(true, events.get()); | |
| 891 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | |
| 892 EXPECT_EQ(initial_value, dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); | |
| 893 // Scroll offset animations should not generate property updates. | |
| 894 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 895 EXPECT_FALSE(event); | |
| 896 | |
| 897 controller->NotifyAnimationStarted(events->events_[0]); | |
| 898 controller->Animate(kInitialTickTime + duration / 2); | |
| 899 controller->UpdateState(true, nullptr); | |
| 900 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 901 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), | |
| 902 dummy.scroll_offset(LayerTreeType::ACTIVE)); | |
| 903 | |
| 904 controller_impl->Animate(kInitialTickTime + duration / 2); | |
| 905 controller_impl->UpdateState(true, events.get()); | |
| 906 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), | |
| 907 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); | |
| 908 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 909 EXPECT_FALSE(event); | |
| 910 | |
| 911 controller_impl->Animate(kInitialTickTime + duration); | |
| 912 controller_impl->UpdateState(true, events.get()); | |
| 913 EXPECT_VECTOR2DF_EQ(target_value, | |
| 914 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); | |
| 915 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | |
| 916 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 917 EXPECT_FALSE(event); | |
| 918 | |
| 919 controller->Animate(kInitialTickTime + duration); | |
| 920 controller->UpdateState(true, nullptr); | |
| 921 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset(LayerTreeType::ACTIVE)); | |
| 922 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 923 } | |
| 924 | |
| 925 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { | |
| 926 FakeLayerAnimationValueObserver dummy_impl; | |
| 927 scoped_refptr<LayerAnimationController> controller_impl( | |
| 928 LayerAnimationController::Create(0)); | |
| 929 controller_impl->set_value_observer(&dummy_impl); | |
| 930 controller_impl->set_needs_active_value_observations(true); | |
| 931 std::unique_ptr<AnimationEvents> events( | |
| 932 base::WrapUnique(new AnimationEvents)); | |
| 933 | |
| 934 gfx::ScrollOffset initial_value(100.f, 300.f); | |
| 935 gfx::ScrollOffset target_value(300.f, 200.f); | |
| 936 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | |
| 937 ScrollOffsetAnimationCurve::Create(target_value, | |
| 938 EaseInOutTimingFunction::Create())); | |
| 939 curve->SetInitialValue(initial_value); | |
| 940 double duration_in_seconds = curve->Duration().InSecondsF(); | |
| 941 | |
| 942 std::unique_ptr<Animation> animation( | |
| 943 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | |
| 944 animation->set_is_impl_only(true); | |
| 945 controller_impl->AddAnimation(std::move(animation)); | |
| 946 | |
| 947 controller_impl->Animate(kInitialTickTime); | |
| 948 controller_impl->UpdateState(true, events.get()); | |
| 949 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | |
| 950 EXPECT_EQ(initial_value, dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); | |
| 951 // Scroll offset animations should not generate property updates. | |
| 952 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 953 EXPECT_FALSE(event); | |
| 954 | |
| 955 TimeDelta duration = TimeDelta::FromMicroseconds( | |
| 956 duration_in_seconds * base::Time::kMicrosecondsPerSecond); | |
| 957 | |
| 958 controller_impl->Animate(kInitialTickTime + duration / 2); | |
| 959 controller_impl->UpdateState(true, events.get()); | |
| 960 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | |
| 961 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); | |
| 962 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 963 EXPECT_FALSE(event); | |
| 964 | |
| 965 controller_impl->Animate(kInitialTickTime + duration); | |
| 966 controller_impl->UpdateState(true, events.get()); | |
| 967 EXPECT_VECTOR2DF_EQ(target_value, | |
| 968 dummy_impl.scroll_offset(LayerTreeType::ACTIVE)); | |
| 969 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | |
| 970 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
| 971 EXPECT_FALSE(event); | |
| 972 } | |
| 973 | |
| 974 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalClearsScrollDelta) { | |
| 975 FakeLayerAnimationValueObserver dummy_impl; | |
| 976 FakeLayerAnimationValueProvider dummy_provider_impl; | |
| 977 scoped_refptr<LayerAnimationController> controller_impl( | |
| 978 LayerAnimationController::Create(0)); | |
| 979 controller_impl->set_value_observer(&dummy_impl); | |
| 980 controller_impl->set_needs_active_value_observations(true); | |
| 981 controller_impl->set_value_provider(&dummy_provider_impl); | |
| 982 std::unique_ptr<AnimationEvents> events( | |
| 983 base::WrapUnique(new AnimationEvents)); | |
| 984 FakeLayerAnimationValueObserver dummy; | |
| 985 FakeLayerAnimationValueProvider dummy_provider; | |
| 986 scoped_refptr<LayerAnimationController> controller( | |
| 987 LayerAnimationController::Create(0)); | |
| 988 controller->set_value_observer(&dummy); | |
| 989 controller->set_needs_active_value_observations(true); | |
| 990 controller->set_value_provider(&dummy_provider); | |
| 991 | |
| 992 // First test the 1-argument version of RemoveAnimation. | |
| 993 gfx::ScrollOffset target_value(300.f, 200.f); | |
| 994 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | |
| 995 ScrollOffsetAnimationCurve::Create(target_value, | |
| 996 EaseInOutTimingFunction::Create())); | |
| 997 | |
| 998 int animation_id = 1; | |
| 999 std::unique_ptr<Animation> animation(Animation::Create( | |
| 1000 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET)); | |
| 1001 animation->set_needs_synchronized_start_time(true); | |
| 1002 controller->AddAnimation(std::move(animation)); | |
| 1003 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1004 controller_impl->ActivateAnimations(); | |
| 1005 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | |
| 1006 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1007 | |
| 1008 controller->RemoveAnimation(animation_id); | |
| 1009 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted()); | |
| 1010 | |
| 1011 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1012 EXPECT_TRUE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1013 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | |
| 1014 | |
| 1015 controller_impl->ActivateAnimations(); | |
| 1016 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1017 | |
| 1018 // Now, test the 2-argument version of RemoveAnimation. | |
| 1019 curve = ScrollOffsetAnimationCurve::Create(target_value, | |
| 1020 EaseInOutTimingFunction::Create()); | |
| 1021 animation = Animation::Create(std::move(curve), animation_id, 0, | |
| 1022 TargetProperty::SCROLL_OFFSET); | |
| 1023 animation->set_needs_synchronized_start_time(true); | |
| 1024 controller->AddAnimation(std::move(animation)); | |
| 1025 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1026 controller_impl->ActivateAnimations(); | |
| 1027 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | |
| 1028 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1029 | |
| 1030 controller->RemoveAnimation(animation_id); | |
| 1031 EXPECT_TRUE(controller->scroll_offset_animation_was_interrupted()); | |
| 1032 | |
| 1033 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1034 EXPECT_TRUE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1035 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | |
| 1036 | |
| 1037 controller_impl->ActivateAnimations(); | |
| 1038 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1039 | |
| 1040 // Check that removing non-scroll-offset animations does not cause | |
| 1041 // scroll_offset_animation_was_interrupted() to get set. | |
| 1042 animation_id = AddAnimatedTransformToController(controller.get(), 1.0, 1, 2); | |
| 1043 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1044 controller_impl->ActivateAnimations(); | |
| 1045 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | |
| 1046 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1047 | |
| 1048 controller->RemoveAnimation(animation_id); | |
| 1049 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | |
| 1050 | |
| 1051 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1052 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1053 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | |
| 1054 | |
| 1055 controller_impl->ActivateAnimations(); | |
| 1056 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1057 | |
| 1058 animation_id = | |
| 1059 AddAnimatedFilterToController(controller.get(), 1.0, 0.1f, 0.2f); | |
| 1060 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1061 controller_impl->ActivateAnimations(); | |
| 1062 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | |
| 1063 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1064 | |
| 1065 controller->RemoveAnimation(animation_id); | |
| 1066 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | |
| 1067 | |
| 1068 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1069 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1070 EXPECT_FALSE(controller->scroll_offset_animation_was_interrupted()); | |
| 1071 | |
| 1072 controller_impl->ActivateAnimations(); | |
| 1073 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | |
| 1074 } | |
| 1075 | |
| 1076 class FakeAnimationDelegate : public AnimationDelegate { | |
| 1077 public: | |
| 1078 FakeAnimationDelegate() | |
| 1079 : started_(false), | |
| 1080 finished_(false), | |
| 1081 aborted_(false), | |
| 1082 takeover_(false), | |
| 1083 start_time_(base::TimeTicks()) {} | |
| 1084 | |
| 1085 void NotifyAnimationStarted(TimeTicks monotonic_time, | |
| 1086 TargetProperty::Type target_property, | |
| 1087 int group) override { | |
| 1088 started_ = true; | |
| 1089 start_time_ = monotonic_time; | |
| 1090 } | |
| 1091 | |
| 1092 void NotifyAnimationFinished(TimeTicks monotonic_time, | |
| 1093 TargetProperty::Type target_property, | |
| 1094 int group) override { | |
| 1095 finished_ = true; | |
| 1096 } | |
| 1097 | |
| 1098 void NotifyAnimationAborted(TimeTicks monotonic_time, | |
| 1099 TargetProperty::Type target_property, | |
| 1100 int group) override { | |
| 1101 aborted_ = true; | |
| 1102 } | |
| 1103 | |
| 1104 void NotifyAnimationTakeover(base::TimeTicks monotonic_time, | |
| 1105 TargetProperty::Type target_property, | |
| 1106 double animation_start_time, | |
| 1107 std::unique_ptr<AnimationCurve> curve) override { | |
| 1108 takeover_ = true; | |
| 1109 } | |
| 1110 | |
| 1111 bool started() { return started_; } | |
| 1112 | |
| 1113 bool finished() { return finished_; } | |
| 1114 | |
| 1115 bool aborted() { return aborted_; } | |
| 1116 | |
| 1117 bool takeover() { return takeover_; } | |
| 1118 | |
| 1119 TimeTicks start_time() { return start_time_; } | |
| 1120 | |
| 1121 private: | |
| 1122 bool started_; | |
| 1123 bool finished_; | |
| 1124 bool aborted_; | |
| 1125 bool takeover_; | |
| 1126 TimeTicks start_time_; | |
| 1127 }; | |
| 1128 | |
| 1129 // Tests that impl-only animations lead to start and finished notifications | |
| 1130 // on the impl thread controller's animation delegate. | |
| 1131 TEST(LayerAnimationControllerTest, | |
| 1132 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { | |
| 1133 FakeLayerAnimationValueObserver dummy_impl; | |
| 1134 scoped_refptr<LayerAnimationController> controller_impl( | |
| 1135 LayerAnimationController::Create(0)); | |
| 1136 controller_impl->set_value_observer(&dummy_impl); | |
| 1137 controller_impl->set_needs_active_value_observations(true); | |
| 1138 | |
| 1139 std::unique_ptr<AnimationEvents> events( | |
| 1140 base::WrapUnique(new AnimationEvents)); | |
| 1141 FakeAnimationDelegate delegate; | |
| 1142 controller_impl->set_layer_animation_delegate(&delegate); | |
| 1143 | |
| 1144 std::unique_ptr<Animation> to_add(CreateAnimation( | |
| 1145 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1146 1, TargetProperty::OPACITY)); | |
| 1147 to_add->set_is_impl_only(true); | |
| 1148 controller_impl->AddAnimation(std::move(to_add)); | |
| 1149 | |
| 1150 EXPECT_FALSE(delegate.started()); | |
| 1151 EXPECT_FALSE(delegate.finished()); | |
| 1152 | |
| 1153 controller_impl->Animate(kInitialTickTime); | |
| 1154 controller_impl->UpdateState(true, events.get()); | |
| 1155 | |
| 1156 EXPECT_TRUE(delegate.started()); | |
| 1157 EXPECT_FALSE(delegate.finished()); | |
| 1158 | |
| 1159 events.reset(new AnimationEvents); | |
| 1160 controller_impl->Animate(kInitialTickTime + | |
| 1161 TimeDelta::FromMilliseconds(1000)); | |
| 1162 controller_impl->UpdateState(true, events.get()); | |
| 1163 | |
| 1164 EXPECT_TRUE(delegate.started()); | |
| 1165 EXPECT_TRUE(delegate.finished()); | |
| 1166 } | |
| 1167 | |
| 1168 // Tests that specified start times are sent to the main thread delegate | |
| 1169 TEST(LayerAnimationControllerTest, | |
| 1170 SpecifiedStartTimesAreSentToMainThreadDelegate) { | |
| 1171 FakeLayerAnimationValueObserver dummy_impl; | |
| 1172 scoped_refptr<LayerAnimationController> controller_impl( | |
| 1173 LayerAnimationController::Create(0)); | |
| 1174 controller_impl->set_value_observer(&dummy_impl); | |
| 1175 controller_impl->set_needs_active_value_observations(true); | |
| 1176 | |
| 1177 FakeLayerAnimationValueObserver dummy; | |
| 1178 scoped_refptr<LayerAnimationController> controller( | |
| 1179 LayerAnimationController::Create(0)); | |
| 1180 controller->set_value_observer(&dummy); | |
| 1181 controller->set_needs_active_value_observations(true); | |
| 1182 | |
| 1183 FakeAnimationDelegate delegate; | |
| 1184 controller->set_layer_animation_delegate(&delegate); | |
| 1185 | |
| 1186 int animation_id = | |
| 1187 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | |
| 1188 | |
| 1189 const TimeTicks start_time = TicksFromSecondsF(123); | |
| 1190 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); | |
| 1191 | |
| 1192 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1193 controller_impl->ActivateAnimations(); | |
| 1194 | |
| 1195 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 1196 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 1197 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 1198 | |
| 1199 AnimationEvents events; | |
| 1200 controller_impl->Animate(kInitialTickTime); | |
| 1201 controller_impl->UpdateState(true, &events); | |
| 1202 | |
| 1203 // Synchronize the start times. | |
| 1204 EXPECT_EQ(1u, events.events_.size()); | |
| 1205 controller->NotifyAnimationStarted(events.events_[0]); | |
| 1206 | |
| 1207 // Validate start time on the main thread delegate. | |
| 1208 EXPECT_EQ(start_time, delegate.start_time()); | |
| 1209 } | |
| 1210 | |
| 1211 // Tests animations that are waiting for a synchronized start time do not | |
| 1212 // finish. | |
| 1213 TEST(LayerAnimationControllerTest, | |
| 1214 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { | |
| 1215 std::unique_ptr<AnimationEvents> events( | |
| 1216 base::WrapUnique(new AnimationEvents)); | |
| 1217 FakeLayerAnimationValueObserver dummy; | |
| 1218 scoped_refptr<LayerAnimationController> controller( | |
| 1219 LayerAnimationController::Create(0)); | |
| 1220 controller->set_value_observer(&dummy); | |
| 1221 controller->set_needs_active_value_observations(true); | |
| 1222 | |
| 1223 std::unique_ptr<Animation> to_add(CreateAnimation( | |
| 1224 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1225 1, TargetProperty::OPACITY)); | |
| 1226 to_add->set_needs_synchronized_start_time(true); | |
| 1227 | |
| 1228 // We should pause at the first keyframe indefinitely waiting for that | |
| 1229 // animation to start. | |
| 1230 controller->AddAnimation(std::move(to_add)); | |
| 1231 controller->Animate(kInitialTickTime); | |
| 1232 controller->UpdateState(true, events.get()); | |
| 1233 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1234 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1235 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 1236 controller->UpdateState(true, events.get()); | |
| 1237 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1238 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1239 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | |
| 1240 controller->UpdateState(true, events.get()); | |
| 1241 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1242 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1243 | |
| 1244 // Send the synchronized start time. | |
| 1245 controller->NotifyAnimationStarted( | |
| 1246 AnimationEvent(AnimationEvent::STARTED, 0, 1, TargetProperty::OPACITY, | |
| 1247 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); | |
| 1248 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); | |
| 1249 controller->UpdateState(true, events.get()); | |
| 1250 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1251 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 1252 } | |
| 1253 | |
| 1254 // Tests that two queued animations affecting the same property run in sequence. | |
| 1255 TEST(LayerAnimationControllerTest, TrivialQueuing) { | |
| 1256 std::unique_ptr<AnimationEvents> events( | |
| 1257 base::WrapUnique(new AnimationEvents)); | |
| 1258 FakeLayerAnimationValueObserver dummy; | |
| 1259 scoped_refptr<LayerAnimationController> controller( | |
| 1260 LayerAnimationController::Create(0)); | |
| 1261 controller->set_value_observer(&dummy); | |
| 1262 controller->set_needs_active_value_observations(true); | |
| 1263 | |
| 1264 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | |
| 1265 | |
| 1266 controller->AddAnimation(CreateAnimation( | |
| 1267 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1268 1, TargetProperty::OPACITY)); | |
| 1269 controller->AddAnimation(CreateAnimation( | |
| 1270 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | |
| 1271 2, TargetProperty::OPACITY)); | |
| 1272 | |
| 1273 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | |
| 1274 | |
| 1275 controller->Animate(kInitialTickTime); | |
| 1276 | |
| 1277 // The second animation still needs to be started. | |
| 1278 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | |
| 1279 | |
| 1280 controller->UpdateState(true, events.get()); | |
| 1281 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1282 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1283 | |
| 1284 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 1285 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | |
| 1286 controller->UpdateState(true, events.get()); | |
| 1287 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | |
| 1288 | |
| 1289 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1290 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1291 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | |
| 1292 controller->UpdateState(true, events.get()); | |
| 1293 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1294 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 1295 } | |
| 1296 | |
| 1297 // Tests interrupting a transition with another transition. | |
| 1298 TEST(LayerAnimationControllerTest, Interrupt) { | |
| 1299 std::unique_ptr<AnimationEvents> events( | |
| 1300 base::WrapUnique(new AnimationEvents)); | |
| 1301 FakeLayerAnimationValueObserver dummy; | |
| 1302 scoped_refptr<LayerAnimationController> controller( | |
| 1303 LayerAnimationController::Create(0)); | |
| 1304 controller->set_value_observer(&dummy); | |
| 1305 controller->set_needs_active_value_observations(true); | |
| 1306 | |
| 1307 controller->AddAnimation(CreateAnimation( | |
| 1308 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1309 1, TargetProperty::OPACITY)); | |
| 1310 controller->Animate(kInitialTickTime); | |
| 1311 controller->UpdateState(true, events.get()); | |
| 1312 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1313 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1314 | |
| 1315 std::unique_ptr<Animation> to_add(CreateAnimation( | |
| 1316 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | |
| 1317 2, TargetProperty::OPACITY)); | |
| 1318 controller->AbortAnimations(TargetProperty::OPACITY); | |
| 1319 controller->AddAnimation(std::move(to_add)); | |
| 1320 | |
| 1321 // Since the previous animation was aborted, the new animation should start | |
| 1322 // right in this call to animate. | |
| 1323 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 1324 controller->UpdateState(true, events.get()); | |
| 1325 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1326 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1327 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | |
| 1328 controller->UpdateState(true, events.get()); | |
| 1329 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1330 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 1331 } | |
| 1332 | |
| 1333 // Tests scheduling two animations to run together when only one property is | |
| 1334 // free. | |
| 1335 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { | |
| 1336 std::unique_ptr<AnimationEvents> events( | |
| 1337 base::WrapUnique(new AnimationEvents)); | |
| 1338 FakeLayerAnimationValueObserver dummy; | |
| 1339 scoped_refptr<LayerAnimationController> controller( | |
| 1340 LayerAnimationController::Create(0)); | |
| 1341 controller->set_value_observer(&dummy); | |
| 1342 controller->set_needs_active_value_observations(true); | |
| 1343 | |
| 1344 controller->AddAnimation(CreateAnimation( | |
| 1345 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | |
| 1346 TargetProperty::TRANSFORM)); | |
| 1347 controller->AddAnimation(CreateAnimation( | |
| 1348 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, | |
| 1349 TargetProperty::TRANSFORM)); | |
| 1350 controller->AddAnimation(CreateAnimation( | |
| 1351 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1352 2, TargetProperty::OPACITY)); | |
| 1353 | |
| 1354 controller->Animate(kInitialTickTime); | |
| 1355 controller->UpdateState(true, events.get()); | |
| 1356 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1357 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1358 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 1359 controller->UpdateState(true, events.get()); | |
| 1360 // Should not have started the float transition yet. | |
| 1361 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1362 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1363 // The float animation should have started at time 1 and should be done. | |
| 1364 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | |
| 1365 controller->UpdateState(true, events.get()); | |
| 1366 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1367 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 1368 } | |
| 1369 | |
| 1370 // Tests scheduling two animations to run together with different lengths and | |
| 1371 // another animation queued to start when the shorter animation finishes (should | |
| 1372 // wait for both to finish). | |
| 1373 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { | |
| 1374 std::unique_ptr<AnimationEvents> events( | |
| 1375 base::WrapUnique(new AnimationEvents)); | |
| 1376 FakeLayerAnimationValueObserver dummy; | |
| 1377 scoped_refptr<LayerAnimationController> controller( | |
| 1378 LayerAnimationController::Create(0)); | |
| 1379 controller->set_value_observer(&dummy); | |
| 1380 controller->set_needs_active_value_observations(true); | |
| 1381 | |
| 1382 controller->AddAnimation(CreateAnimation( | |
| 1383 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, | |
| 1384 TargetProperty::TRANSFORM)); | |
| 1385 controller->AddAnimation(CreateAnimation( | |
| 1386 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1387 1, TargetProperty::OPACITY)); | |
| 1388 controller->AddAnimation(CreateAnimation( | |
| 1389 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | |
| 1390 2, TargetProperty::OPACITY)); | |
| 1391 | |
| 1392 // Animations with id 1 should both start now. | |
| 1393 controller->Animate(kInitialTickTime); | |
| 1394 controller->UpdateState(true, events.get()); | |
| 1395 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1396 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1397 // The opacity animation should have finished at time 1, but the group | |
| 1398 // of animations with id 1 don't finish until time 2 because of the length | |
| 1399 // of the transform animation. | |
| 1400 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | |
| 1401 controller->UpdateState(true, events.get()); | |
| 1402 // Should not have started the float transition yet. | |
| 1403 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1404 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1405 | |
| 1406 // The second opacity animation should start at time 2 and should be done by | |
| 1407 // time 3. | |
| 1408 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | |
| 1409 controller->UpdateState(true, events.get()); | |
| 1410 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1411 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 1412 } | |
| 1413 | |
| 1414 // Test that a looping animation loops and for the correct number of iterations. | |
| 1415 TEST(LayerAnimationControllerTest, TrivialLooping) { | |
| 1416 std::unique_ptr<AnimationEvents> events( | |
| 1417 base::WrapUnique(new AnimationEvents)); | |
| 1418 FakeLayerAnimationValueObserver dummy; | |
| 1419 scoped_refptr<LayerAnimationController> controller( | |
| 1420 LayerAnimationController::Create(0)); | |
| 1421 controller->set_value_observer(&dummy); | |
| 1422 controller->set_needs_active_value_observations(true); | |
| 1423 | |
| 1424 std::unique_ptr<Animation> to_add(CreateAnimation( | |
| 1425 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1426 1, TargetProperty::OPACITY)); | |
| 1427 to_add->set_iterations(3); | |
| 1428 controller->AddAnimation(std::move(to_add)); | |
| 1429 | |
| 1430 controller->Animate(kInitialTickTime); | |
| 1431 controller->UpdateState(true, events.get()); | |
| 1432 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1433 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1434 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); | |
| 1435 controller->UpdateState(true, events.get()); | |
| 1436 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1437 EXPECT_EQ(0.25f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1438 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); | |
| 1439 controller->UpdateState(true, events.get()); | |
| 1440 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1441 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1442 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2250)); | |
| 1443 controller->UpdateState(true, events.get()); | |
| 1444 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1445 EXPECT_EQ(0.25f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1446 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2750)); | |
| 1447 controller->UpdateState(true, events.get()); | |
| 1448 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1449 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1450 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | |
| 1451 controller->UpdateState(true, events.get()); | |
| 1452 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 1453 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1454 | |
| 1455 // Just be extra sure. | |
| 1456 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); | |
| 1457 controller->UpdateState(true, events.get()); | |
| 1458 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1459 } | |
| 1460 | |
| 1461 // Test that an infinitely looping animation does indeed go until aborted. | |
| 1462 TEST(LayerAnimationControllerTest, InfiniteLooping) { | |
| 1463 std::unique_ptr<AnimationEvents> events( | |
| 1464 base::WrapUnique(new AnimationEvents)); | |
| 1465 FakeLayerAnimationValueObserver dummy; | |
| 1466 scoped_refptr<LayerAnimationController> controller( | |
| 1467 LayerAnimationController::Create(0)); | |
| 1468 controller->set_value_observer(&dummy); | |
| 1469 controller->set_needs_active_value_observations(true); | |
| 1470 | |
| 1471 std::unique_ptr<Animation> to_add(CreateAnimation( | |
| 1472 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1473 1, TargetProperty::OPACITY)); | |
| 1474 to_add->set_iterations(-1); | |
| 1475 controller->AddAnimation(std::move(to_add)); | |
| 1476 | |
| 1477 controller->Animate(kInitialTickTime); | |
| 1478 controller->UpdateState(true, events.get()); | |
| 1479 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1480 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1481 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); | |
| 1482 controller->UpdateState(true, events.get()); | |
| 1483 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1484 EXPECT_EQ(0.25f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1485 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); | |
| 1486 controller->UpdateState(true, events.get()); | |
| 1487 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1488 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1489 | |
| 1490 controller->Animate(kInitialTickTime + | |
| 1491 TimeDelta::FromMilliseconds(1073741824250)); | |
| 1492 controller->UpdateState(true, events.get()); | |
| 1493 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1494 EXPECT_EQ(0.25f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1495 controller->Animate(kInitialTickTime + | |
| 1496 TimeDelta::FromMilliseconds(1073741824750)); | |
| 1497 controller->UpdateState(true, events.get()); | |
| 1498 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1499 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1500 | |
| 1501 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); | |
| 1502 controller->GetAnimation(TargetProperty::OPACITY) | |
| 1503 ->SetRunState(Animation::ABORTED, | |
| 1504 kInitialTickTime + TimeDelta::FromMilliseconds(750)); | |
| 1505 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 1506 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1507 } | |
| 1508 | |
| 1509 // Test that pausing and resuming work as expected. | |
| 1510 TEST(LayerAnimationControllerTest, PauseResume) { | |
| 1511 std::unique_ptr<AnimationEvents> events( | |
| 1512 base::WrapUnique(new AnimationEvents)); | |
| 1513 FakeLayerAnimationValueObserver dummy; | |
| 1514 scoped_refptr<LayerAnimationController> controller( | |
| 1515 LayerAnimationController::Create(0)); | |
| 1516 controller->set_value_observer(&dummy); | |
| 1517 controller->set_needs_active_value_observations(true); | |
| 1518 | |
| 1519 controller->AddAnimation(CreateAnimation( | |
| 1520 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1521 1, TargetProperty::OPACITY)); | |
| 1522 | |
| 1523 controller->Animate(kInitialTickTime); | |
| 1524 controller->UpdateState(true, events.get()); | |
| 1525 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1526 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1527 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 1528 controller->UpdateState(true, events.get()); | |
| 1529 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1530 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1531 | |
| 1532 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); | |
| 1533 controller->GetAnimation(TargetProperty::OPACITY) | |
| 1534 ->SetRunState(Animation::PAUSED, | |
| 1535 kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 1536 | |
| 1537 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); | |
| 1538 controller->UpdateState(true, events.get()); | |
| 1539 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1540 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1541 | |
| 1542 EXPECT_TRUE(controller->GetAnimation(TargetProperty::OPACITY)); | |
| 1543 controller->GetAnimation(TargetProperty::OPACITY) | |
| 1544 ->SetRunState(Animation::RUNNING, | |
| 1545 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); | |
| 1546 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250)); | |
| 1547 controller->UpdateState(true, events.get()); | |
| 1548 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1549 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1550 | |
| 1551 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); | |
| 1552 controller->UpdateState(true, events.get()); | |
| 1553 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 1554 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1555 } | |
| 1556 | |
| 1557 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { | |
| 1558 std::unique_ptr<AnimationEvents> events( | |
| 1559 base::WrapUnique(new AnimationEvents)); | |
| 1560 FakeLayerAnimationValueObserver dummy; | |
| 1561 scoped_refptr<LayerAnimationController> controller( | |
| 1562 LayerAnimationController::Create(0)); | |
| 1563 controller->set_value_observer(&dummy); | |
| 1564 controller->set_needs_active_value_observations(true); | |
| 1565 | |
| 1566 const int animation_id = 2; | |
| 1567 controller->AddAnimation(Animation::Create( | |
| 1568 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, | |
| 1569 TargetProperty::TRANSFORM)); | |
| 1570 controller->AddAnimation(Animation::Create( | |
| 1571 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), | |
| 1572 animation_id, 1, TargetProperty::OPACITY)); | |
| 1573 controller->AddAnimation(Animation::Create( | |
| 1574 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), | |
| 1575 3, 2, TargetProperty::OPACITY)); | |
| 1576 | |
| 1577 controller->Animate(kInitialTickTime); | |
| 1578 controller->UpdateState(true, events.get()); | |
| 1579 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1580 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1581 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 1582 controller->UpdateState(true, events.get()); | |
| 1583 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1584 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1585 | |
| 1586 EXPECT_TRUE(controller->GetAnimationById(animation_id)); | |
| 1587 controller->GetAnimationById(animation_id) | |
| 1588 ->SetRunState(Animation::ABORTED, | |
| 1589 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 1590 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 1591 controller->UpdateState(true, events.get()); | |
| 1592 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1593 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1594 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | |
| 1595 controller->UpdateState(true, events.get()); | |
| 1596 EXPECT_TRUE(!controller->HasActiveAnimation()); | |
| 1597 EXPECT_EQ(0.75f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1598 } | |
| 1599 | |
| 1600 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { | |
| 1601 FakeLayerAnimationValueObserver dummy_impl; | |
| 1602 scoped_refptr<LayerAnimationController> controller_impl( | |
| 1603 LayerAnimationController::Create(0)); | |
| 1604 controller_impl->set_value_observer(&dummy_impl); | |
| 1605 controller_impl->set_needs_active_value_observations(true); | |
| 1606 std::unique_ptr<AnimationEvents> events( | |
| 1607 base::WrapUnique(new AnimationEvents)); | |
| 1608 FakeLayerAnimationValueObserver dummy; | |
| 1609 scoped_refptr<LayerAnimationController> controller( | |
| 1610 LayerAnimationController::Create(0)); | |
| 1611 controller->set_value_observer(&dummy); | |
| 1612 controller->set_needs_active_value_observations(true); | |
| 1613 | |
| 1614 std::unique_ptr<Animation> to_add(CreateAnimation( | |
| 1615 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), | |
| 1616 0, TargetProperty::OPACITY)); | |
| 1617 to_add->set_needs_synchronized_start_time(true); | |
| 1618 controller->AddAnimation(std::move(to_add)); | |
| 1619 | |
| 1620 controller->Animate(kInitialTickTime); | |
| 1621 controller->UpdateState(true, events.get()); | |
| 1622 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1623 Animation* active_animation = | |
| 1624 controller->GetAnimation(TargetProperty::OPACITY); | |
| 1625 EXPECT_TRUE(active_animation); | |
| 1626 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); | |
| 1627 | |
| 1628 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1629 controller_impl->ActivateAnimations(); | |
| 1630 | |
| 1631 active_animation = controller_impl->GetAnimation(TargetProperty::OPACITY); | |
| 1632 EXPECT_TRUE(active_animation); | |
| 1633 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 1634 active_animation->run_state()); | |
| 1635 } | |
| 1636 | |
| 1637 // Tests that skipping a call to UpdateState works as expected. | |
| 1638 TEST(LayerAnimationControllerTest, SkipUpdateState) { | |
| 1639 std::unique_ptr<AnimationEvents> events( | |
| 1640 base::WrapUnique(new AnimationEvents)); | |
| 1641 FakeLayerAnimationValueObserver dummy; | |
| 1642 scoped_refptr<LayerAnimationController> controller( | |
| 1643 LayerAnimationController::Create(0)); | |
| 1644 controller->set_value_observer(&dummy); | |
| 1645 controller->set_needs_active_value_observations(true); | |
| 1646 | |
| 1647 std::unique_ptr<Animation> first_animation(CreateAnimation( | |
| 1648 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | |
| 1649 TargetProperty::TRANSFORM)); | |
| 1650 first_animation->set_is_controlling_instance_for_test(true); | |
| 1651 controller->AddAnimation(std::move(first_animation)); | |
| 1652 | |
| 1653 controller->Animate(kInitialTickTime); | |
| 1654 controller->UpdateState(true, events.get()); | |
| 1655 | |
| 1656 std::unique_ptr<Animation> second_animation(CreateAnimation( | |
| 1657 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1658 2, TargetProperty::OPACITY)); | |
| 1659 second_animation->set_is_controlling_instance_for_test(true); | |
| 1660 controller->AddAnimation(std::move(second_animation)); | |
| 1661 | |
| 1662 // Animate but don't UpdateState. | |
| 1663 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 1664 | |
| 1665 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | |
| 1666 events.reset(new AnimationEvents); | |
| 1667 controller->UpdateState(true, events.get()); | |
| 1668 | |
| 1669 // Should have one STARTED event and one FINISHED event. | |
| 1670 EXPECT_EQ(2u, events->events_.size()); | |
| 1671 EXPECT_NE(events->events_[0].type, events->events_[1].type); | |
| 1672 | |
| 1673 // The float transition should still be at its starting point. | |
| 1674 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 1675 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1676 | |
| 1677 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | |
| 1678 controller->UpdateState(true, events.get()); | |
| 1679 | |
| 1680 // The float tranisition should now be done. | |
| 1681 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1682 EXPECT_FALSE(controller->HasActiveAnimation()); | |
| 1683 } | |
| 1684 | |
| 1685 // Tests that an animation controller with only a pending observer gets ticked | |
| 1686 // but doesn't progress animations past the STARTING state. | |
| 1687 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { | |
| 1688 std::unique_ptr<AnimationEvents> events( | |
| 1689 base::WrapUnique(new AnimationEvents)); | |
| 1690 FakeLayerAnimationValueObserver dummy; | |
| 1691 scoped_refptr<LayerAnimationController> controller( | |
| 1692 LayerAnimationController::Create(0)); | |
| 1693 controller->set_value_observer(&dummy); | |
| 1694 | |
| 1695 const int id = 1; | |
| 1696 controller->AddAnimation(CreateAnimation( | |
| 1697 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), | |
| 1698 id, TargetProperty::OPACITY)); | |
| 1699 | |
| 1700 // Without an observer, the animation shouldn't progress to the STARTING | |
| 1701 // state. | |
| 1702 controller->Animate(kInitialTickTime); | |
| 1703 controller->UpdateState(true, events.get()); | |
| 1704 EXPECT_EQ(0u, events->events_.size()); | |
| 1705 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 1706 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 1707 | |
| 1708 controller->set_needs_pending_value_observations(true); | |
| 1709 | |
| 1710 // With only a pending observer, the animation should progress to the | |
| 1711 // STARTING state and get ticked at its starting point, but should not | |
| 1712 // progress to RUNNING. | |
| 1713 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 1714 controller->UpdateState(true, events.get()); | |
| 1715 EXPECT_EQ(0u, events->events_.size()); | |
| 1716 EXPECT_EQ(Animation::STARTING, | |
| 1717 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 1718 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::PENDING)); | |
| 1719 | |
| 1720 // Even when already in the STARTING state, the animation should stay | |
| 1721 // there, and shouldn't be ticked past its starting point. | |
| 1722 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | |
| 1723 controller->UpdateState(true, events.get()); | |
| 1724 EXPECT_EQ(0u, events->events_.size()); | |
| 1725 EXPECT_EQ(Animation::STARTING, | |
| 1726 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 1727 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::PENDING)); | |
| 1728 | |
| 1729 controller->set_needs_active_value_observations(true); | |
| 1730 | |
| 1731 // Now that an active observer has been added, the animation should still | |
| 1732 // initially tick at its starting point, but should now progress to RUNNING. | |
| 1733 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | |
| 1734 controller->UpdateState(true, events.get()); | |
| 1735 EXPECT_EQ(1u, events->events_.size()); | |
| 1736 EXPECT_EQ(Animation::RUNNING, | |
| 1737 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 1738 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::PENDING)); | |
| 1739 EXPECT_EQ(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1740 | |
| 1741 // The animation should now tick past its starting point. | |
| 1742 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); | |
| 1743 EXPECT_NE(0.5f, dummy.opacity(LayerTreeType::PENDING)); | |
| 1744 EXPECT_NE(0.5f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 1745 } | |
| 1746 | |
| 1747 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { | |
| 1748 scoped_refptr<LayerAnimationController> controller_impl( | |
| 1749 LayerAnimationController::Create(0)); | |
| 1750 | |
| 1751 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | |
| 1752 KeyframedTransformAnimationCurve::Create()); | |
| 1753 | |
| 1754 TransformOperations operations1; | |
| 1755 curve1->AddKeyframe( | |
| 1756 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | |
| 1757 operations1.AppendTranslate(10.0, 15.0, 0.0); | |
| 1758 curve1->AddKeyframe(TransformKeyframe::Create( | |
| 1759 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | |
| 1760 | |
| 1761 std::unique_ptr<Animation> animation( | |
| 1762 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); | |
| 1763 controller_impl->AddAnimation(std::move(animation)); | |
| 1764 | |
| 1765 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( | |
| 1766 KeyframedTransformAnimationCurve::Create()); | |
| 1767 | |
| 1768 TransformOperations operations2; | |
| 1769 curve2->AddKeyframe( | |
| 1770 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | |
| 1771 operations2.AppendScale(2.0, 3.0, 4.0); | |
| 1772 curve2->AddKeyframe(TransformKeyframe::Create( | |
| 1773 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | |
| 1774 | |
| 1775 animation = | |
| 1776 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); | |
| 1777 controller_impl->AddAnimation(std::move(animation)); | |
| 1778 | |
| 1779 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f); | |
| 1780 gfx::BoxF bounds; | |
| 1781 | |
| 1782 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); | |
| 1783 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(), | |
| 1784 bounds.ToString()); | |
| 1785 | |
| 1786 controller_impl->GetAnimationById(1) | |
| 1787 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); | |
| 1788 | |
| 1789 // Only the unfinished animation should affect the animated bounds. | |
| 1790 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); | |
| 1791 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(), | |
| 1792 bounds.ToString()); | |
| 1793 | |
| 1794 controller_impl->GetAnimationById(2) | |
| 1795 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); | |
| 1796 | |
| 1797 // There are no longer any running animations. | |
| 1798 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds()); | |
| 1799 | |
| 1800 // Add an animation whose bounds we don't yet support computing. | |
| 1801 std::unique_ptr<KeyframedTransformAnimationCurve> curve3( | |
| 1802 KeyframedTransformAnimationCurve::Create()); | |
| 1803 TransformOperations operations3; | |
| 1804 gfx::Transform transform3; | |
| 1805 transform3.Scale3d(1.0, 2.0, 3.0); | |
| 1806 curve3->AddKeyframe( | |
| 1807 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); | |
| 1808 operations3.AppendMatrix(transform3); | |
| 1809 curve3->AddKeyframe(TransformKeyframe::Create( | |
| 1810 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); | |
| 1811 animation = | |
| 1812 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM); | |
| 1813 controller_impl->AddAnimation(std::move(animation)); | |
| 1814 EXPECT_FALSE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); | |
| 1815 } | |
| 1816 | |
| 1817 // Tests that AbortAnimations aborts all animations targeting the specified | |
| 1818 // property. | |
| 1819 TEST(LayerAnimationControllerTest, AbortAnimations) { | |
| 1820 FakeLayerAnimationValueObserver dummy; | |
| 1821 scoped_refptr<LayerAnimationController> controller( | |
| 1822 LayerAnimationController::Create(0)); | |
| 1823 controller->set_value_observer(&dummy); | |
| 1824 controller->set_needs_active_value_observations(true); | |
| 1825 | |
| 1826 // Start with several animations, and allow some of them to reach the finished | |
| 1827 // state. | |
| 1828 controller->AddAnimation(Animation::Create( | |
| 1829 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, 1, | |
| 1830 TargetProperty::TRANSFORM)); | |
| 1831 controller->AddAnimation(Animation::Create( | |
| 1832 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1833 2, 2, TargetProperty::OPACITY)); | |
| 1834 controller->AddAnimation(Animation::Create( | |
| 1835 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 3, 3, | |
| 1836 TargetProperty::TRANSFORM)); | |
| 1837 controller->AddAnimation(Animation::Create( | |
| 1838 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 4, 4, | |
| 1839 TargetProperty::TRANSFORM)); | |
| 1840 controller->AddAnimation(Animation::Create( | |
| 1841 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 1842 5, 5, TargetProperty::OPACITY)); | |
| 1843 | |
| 1844 controller->Animate(kInitialTickTime); | |
| 1845 controller->UpdateState(true, nullptr); | |
| 1846 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 1847 controller->UpdateState(true, nullptr); | |
| 1848 | |
| 1849 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(1)->run_state()); | |
| 1850 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(2)->run_state()); | |
| 1851 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(3)->run_state()); | |
| 1852 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 1853 controller->GetAnimationById(4)->run_state()); | |
| 1854 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(5)->run_state()); | |
| 1855 | |
| 1856 controller->AbortAnimations(TargetProperty::TRANSFORM); | |
| 1857 | |
| 1858 // Only un-finished TRANSFORM animations should have been aborted. | |
| 1859 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(1)->run_state()); | |
| 1860 EXPECT_EQ(Animation::FINISHED, controller->GetAnimationById(2)->run_state()); | |
| 1861 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(3)->run_state()); | |
| 1862 EXPECT_EQ(Animation::ABORTED, controller->GetAnimationById(4)->run_state()); | |
| 1863 EXPECT_EQ(Animation::RUNNING, controller->GetAnimationById(5)->run_state()); | |
| 1864 } | |
| 1865 | |
| 1866 // An animation aborted on the main thread should get deleted on both threads. | |
| 1867 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) { | |
| 1868 FakeLayerAnimationValueObserver dummy_impl; | |
| 1869 scoped_refptr<LayerAnimationController> controller_impl( | |
| 1870 LayerAnimationController::Create(0)); | |
| 1871 controller_impl->set_value_observer(&dummy_impl); | |
| 1872 controller_impl->set_needs_active_value_observations(true); | |
| 1873 FakeLayerAnimationValueObserver dummy; | |
| 1874 scoped_refptr<LayerAnimationController> controller( | |
| 1875 LayerAnimationController::Create(0)); | |
| 1876 controller->set_value_observer(&dummy); | |
| 1877 controller->set_needs_active_value_observations(true); | |
| 1878 | |
| 1879 int animation_id = | |
| 1880 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); | |
| 1881 | |
| 1882 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1883 controller_impl->ActivateAnimations(); | |
| 1884 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 1885 | |
| 1886 controller->AbortAnimations(TargetProperty::OPACITY); | |
| 1887 EXPECT_EQ(Animation::ABORTED, | |
| 1888 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 1889 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | |
| 1890 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | |
| 1891 | |
| 1892 controller->Animate(kInitialTickTime); | |
| 1893 controller->UpdateState(true, nullptr); | |
| 1894 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | |
| 1895 EXPECT_EQ(Animation::ABORTED, | |
| 1896 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 1897 | |
| 1898 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1899 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | |
| 1900 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | |
| 1901 } | |
| 1902 | |
| 1903 // An animation aborted on the impl thread should get deleted on both threads. | |
| 1904 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) { | |
| 1905 FakeLayerAnimationValueObserver dummy_impl; | |
| 1906 scoped_refptr<LayerAnimationController> controller_impl( | |
| 1907 LayerAnimationController::Create(0)); | |
| 1908 controller_impl->set_value_observer(&dummy_impl); | |
| 1909 controller_impl->set_needs_active_value_observations(true); | |
| 1910 FakeLayerAnimationValueObserver dummy; | |
| 1911 scoped_refptr<LayerAnimationController> controller( | |
| 1912 LayerAnimationController::Create(0)); | |
| 1913 controller->set_value_observer(&dummy); | |
| 1914 controller->set_needs_active_value_observations(true); | |
| 1915 FakeAnimationDelegate delegate; | |
| 1916 controller->set_layer_animation_delegate(&delegate); | |
| 1917 | |
| 1918 int animation_id = | |
| 1919 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); | |
| 1920 | |
| 1921 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1922 controller_impl->ActivateAnimations(); | |
| 1923 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 1924 | |
| 1925 controller_impl->AbortAnimations(TargetProperty::OPACITY); | |
| 1926 EXPECT_EQ( | |
| 1927 Animation::ABORTED, | |
| 1928 controller_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 1929 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | |
| 1930 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | |
| 1931 | |
| 1932 AnimationEvents events; | |
| 1933 controller_impl->Animate(kInitialTickTime); | |
| 1934 controller_impl->UpdateState(true, &events); | |
| 1935 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | |
| 1936 EXPECT_EQ(1u, events.events_.size()); | |
| 1937 EXPECT_EQ(AnimationEvent::ABORTED, events.events_[0].type); | |
| 1938 EXPECT_EQ( | |
| 1939 Animation::WAITING_FOR_DELETION, | |
| 1940 controller_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 1941 | |
| 1942 controller->NotifyAnimationAborted(events.events_[0]); | |
| 1943 EXPECT_EQ(Animation::ABORTED, | |
| 1944 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 1945 EXPECT_TRUE(delegate.aborted()); | |
| 1946 | |
| 1947 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 1948 controller->UpdateState(true, nullptr); | |
| 1949 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | |
| 1950 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | |
| 1951 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
| 1952 | |
| 1953 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1954 controller_impl->ActivateAnimations(); | |
| 1955 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | |
| 1956 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | |
| 1957 } | |
| 1958 | |
| 1959 // Test that an impl-only scroll offset animation that needs to be completed on | |
| 1960 // the main thread gets deleted. | |
| 1961 TEST(LayerAnimationControllerTest, ImplThreadTakeoverAnimationGetsDeleted) { | |
| 1962 FakeLayerAnimationValueObserver dummy_impl; | |
| 1963 scoped_refptr<LayerAnimationController> controller_impl( | |
| 1964 LayerAnimationController::Create(0)); | |
| 1965 controller_impl->set_value_observer(&dummy_impl); | |
| 1966 controller_impl->set_needs_active_value_observations(true); | |
| 1967 FakeLayerAnimationValueObserver dummy; | |
| 1968 scoped_refptr<LayerAnimationController> controller( | |
| 1969 LayerAnimationController::Create(0)); | |
| 1970 controller->set_value_observer(&dummy); | |
| 1971 controller->set_needs_active_value_observations(true); | |
| 1972 FakeAnimationDelegate delegate_impl; | |
| 1973 controller_impl->set_layer_animation_delegate(&delegate_impl); | |
| 1974 FakeAnimationDelegate delegate; | |
| 1975 controller->set_layer_animation_delegate(&delegate); | |
| 1976 | |
| 1977 // Add impl-only scroll offset animation. | |
| 1978 int animation_id = 1; | |
| 1979 gfx::ScrollOffset initial_value(100.f, 300.f); | |
| 1980 gfx::ScrollOffset target_value(300.f, 200.f); | |
| 1981 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | |
| 1982 ScrollOffsetAnimationCurve::Create(target_value, | |
| 1983 EaseInOutTimingFunction::Create())); | |
| 1984 curve->SetInitialValue(initial_value); | |
| 1985 std::unique_ptr<Animation> animation(Animation::Create( | |
| 1986 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET)); | |
| 1987 animation->set_start_time(TicksFromSecondsF(123)); | |
| 1988 animation->set_is_impl_only(true); | |
| 1989 controller_impl->AddAnimation(std::move(animation)); | |
| 1990 | |
| 1991 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1992 controller_impl->ActivateAnimations(); | |
| 1993 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 1994 | |
| 1995 controller_impl->AbortAnimations(TargetProperty::SCROLL_OFFSET, | |
| 1996 true /* needs_completion*/); | |
| 1997 EXPECT_EQ(Animation::ABORTED_BUT_NEEDS_COMPLETION, | |
| 1998 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | |
| 1999 ->run_state()); | |
| 2000 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | |
| 2001 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | |
| 2002 | |
| 2003 AnimationEvents events; | |
| 2004 controller_impl->Animate(kInitialTickTime); | |
| 2005 controller_impl->UpdateState(true, &events); | |
| 2006 EXPECT_TRUE(delegate_impl.finished()); | |
| 2007 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | |
| 2008 EXPECT_EQ(1u, events.events_.size()); | |
| 2009 EXPECT_EQ(AnimationEvent::TAKEOVER, events.events_[0].type); | |
| 2010 EXPECT_EQ(123, events.events_[0].animation_start_time); | |
| 2011 EXPECT_EQ( | |
| 2012 target_value, | |
| 2013 events.events_[0].curve->ToScrollOffsetAnimationCurve()->target_value()); | |
| 2014 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | |
| 2015 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | |
| 2016 ->run_state()); | |
| 2017 | |
| 2018 controller->NotifyAnimationTakeover(events.events_[0]); | |
| 2019 EXPECT_TRUE(delegate.takeover()); | |
| 2020 | |
| 2021 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2022 controller_impl->ActivateAnimations(); | |
| 2023 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | |
| 2024 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | |
| 2025 } | |
| 2026 | |
| 2027 // Ensure that we only generate FINISHED events for animations in a group | |
| 2028 // once all animations in that group are finished. | |
| 2029 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { | |
| 2030 std::unique_ptr<AnimationEvents> events( | |
| 2031 base::WrapUnique(new AnimationEvents)); | |
| 2032 FakeLayerAnimationValueObserver dummy_impl; | |
| 2033 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2034 LayerAnimationController::Create(0)); | |
| 2035 controller_impl->set_value_observer(&dummy_impl); | |
| 2036 controller_impl->set_needs_active_value_observations(true); | |
| 2037 | |
| 2038 const int group_id = 1; | |
| 2039 | |
| 2040 // Add two animations with the same group id but different durations. | |
| 2041 std::unique_ptr<Animation> first_animation(Animation::Create( | |
| 2042 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1, | |
| 2043 group_id, TargetProperty::TRANSFORM)); | |
| 2044 first_animation->set_is_controlling_instance_for_test(true); | |
| 2045 controller_impl->AddAnimation(std::move(first_animation)); | |
| 2046 | |
| 2047 std::unique_ptr<Animation> second_animation(Animation::Create( | |
| 2048 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 2049 2, group_id, TargetProperty::OPACITY)); | |
| 2050 second_animation->set_is_controlling_instance_for_test(true); | |
| 2051 controller_impl->AddAnimation(std::move(second_animation)); | |
| 2052 | |
| 2053 controller_impl->Animate(kInitialTickTime); | |
| 2054 controller_impl->UpdateState(true, events.get()); | |
| 2055 | |
| 2056 // Both animations should have started. | |
| 2057 EXPECT_EQ(2u, events->events_.size()); | |
| 2058 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); | |
| 2059 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); | |
| 2060 | |
| 2061 events.reset(new AnimationEvents); | |
| 2062 controller_impl->Animate(kInitialTickTime + | |
| 2063 TimeDelta::FromMilliseconds(1000)); | |
| 2064 controller_impl->UpdateState(true, events.get()); | |
| 2065 | |
| 2066 // The opacity animation should be finished, but should not have generated | |
| 2067 // a FINISHED event yet. | |
| 2068 EXPECT_EQ(0u, events->events_.size()); | |
| 2069 EXPECT_EQ(Animation::FINISHED, | |
| 2070 controller_impl->GetAnimationById(2)->run_state()); | |
| 2071 EXPECT_EQ(Animation::RUNNING, | |
| 2072 controller_impl->GetAnimationById(1)->run_state()); | |
| 2073 | |
| 2074 controller_impl->Animate(kInitialTickTime + | |
| 2075 TimeDelta::FromMilliseconds(2000)); | |
| 2076 controller_impl->UpdateState(true, events.get()); | |
| 2077 | |
| 2078 // Both animations should have generated FINISHED events. | |
| 2079 EXPECT_EQ(2u, events->events_.size()); | |
| 2080 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); | |
| 2081 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[1].type); | |
| 2082 } | |
| 2083 | |
| 2084 // Ensure that when a group has a mix of aborted and finished animations, | |
| 2085 // we generate a FINISHED event for the finished animation and an ABORTED | |
| 2086 // event for the aborted animation. | |
| 2087 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) { | |
| 2088 std::unique_ptr<AnimationEvents> events( | |
| 2089 base::WrapUnique(new AnimationEvents)); | |
| 2090 FakeLayerAnimationValueObserver dummy_impl; | |
| 2091 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2092 LayerAnimationController::Create(0)); | |
| 2093 controller_impl->set_value_observer(&dummy_impl); | |
| 2094 controller_impl->set_needs_active_value_observations(true); | |
| 2095 | |
| 2096 // Add two animations with the same group id. | |
| 2097 std::unique_ptr<Animation> first_animation(CreateAnimation( | |
| 2098 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, | |
| 2099 TargetProperty::TRANSFORM)); | |
| 2100 first_animation->set_is_controlling_instance_for_test(true); | |
| 2101 controller_impl->AddAnimation(std::move(first_animation)); | |
| 2102 | |
| 2103 std::unique_ptr<Animation> second_animation(CreateAnimation( | |
| 2104 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 2105 1, TargetProperty::OPACITY)); | |
| 2106 second_animation->set_is_controlling_instance_for_test(true); | |
| 2107 controller_impl->AddAnimation(std::move(second_animation)); | |
| 2108 | |
| 2109 controller_impl->Animate(kInitialTickTime); | |
| 2110 controller_impl->UpdateState(true, events.get()); | |
| 2111 | |
| 2112 // Both animations should have started. | |
| 2113 EXPECT_EQ(2u, events->events_.size()); | |
| 2114 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); | |
| 2115 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); | |
| 2116 | |
| 2117 controller_impl->AbortAnimations(TargetProperty::OPACITY); | |
| 2118 | |
| 2119 events.reset(new AnimationEvents); | |
| 2120 controller_impl->Animate(kInitialTickTime + | |
| 2121 TimeDelta::FromMilliseconds(1000)); | |
| 2122 controller_impl->UpdateState(true, events.get()); | |
| 2123 | |
| 2124 // We should have exactly 2 events: a FINISHED event for the tranform | |
| 2125 // animation, and an ABORTED event for the opacity animation. | |
| 2126 EXPECT_EQ(2u, events->events_.size()); | |
| 2127 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); | |
| 2128 EXPECT_EQ(TargetProperty::TRANSFORM, events->events_[0].target_property); | |
| 2129 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[1].type); | |
| 2130 EXPECT_EQ(TargetProperty::OPACITY, events->events_[1].target_property); | |
| 2131 } | |
| 2132 | |
| 2133 TEST(LayerAnimationControllerTest, HasAnimationThatAffectsScale) { | |
| 2134 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2135 LayerAnimationController::Create(0)); | |
| 2136 | |
| 2137 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); | |
| 2138 | |
| 2139 controller_impl->AddAnimation(CreateAnimation( | |
| 2140 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 2141 1, TargetProperty::OPACITY)); | |
| 2142 | |
| 2143 // Opacity animations don't affect scale. | |
| 2144 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); | |
| 2145 | |
| 2146 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | |
| 2147 KeyframedTransformAnimationCurve::Create()); | |
| 2148 | |
| 2149 TransformOperations operations1; | |
| 2150 curve1->AddKeyframe( | |
| 2151 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | |
| 2152 operations1.AppendTranslate(10.0, 15.0, 0.0); | |
| 2153 curve1->AddKeyframe(TransformKeyframe::Create( | |
| 2154 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | |
| 2155 | |
| 2156 std::unique_ptr<Animation> animation( | |
| 2157 Animation::Create(std::move(curve1), 2, 2, TargetProperty::TRANSFORM)); | |
| 2158 controller_impl->AddAnimation(std::move(animation)); | |
| 2159 | |
| 2160 // Translations don't affect scale. | |
| 2161 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); | |
| 2162 | |
| 2163 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( | |
| 2164 KeyframedTransformAnimationCurve::Create()); | |
| 2165 | |
| 2166 TransformOperations operations2; | |
| 2167 curve2->AddKeyframe( | |
| 2168 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | |
| 2169 operations2.AppendScale(2.0, 3.0, 4.0); | |
| 2170 curve2->AddKeyframe(TransformKeyframe::Create( | |
| 2171 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | |
| 2172 | |
| 2173 animation = | |
| 2174 Animation::Create(std::move(curve2), 3, 3, TargetProperty::TRANSFORM); | |
| 2175 controller_impl->AddAnimation(std::move(animation)); | |
| 2176 | |
| 2177 EXPECT_TRUE(controller_impl->HasAnimationThatAffectsScale()); | |
| 2178 | |
| 2179 controller_impl->GetAnimationById(3) | |
| 2180 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); | |
| 2181 | |
| 2182 // Only unfinished animations should be considered by | |
| 2183 // HasAnimationThatAffectsScale. | |
| 2184 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); | |
| 2185 } | |
| 2186 | |
| 2187 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) { | |
| 2188 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2189 LayerAnimationController::Create(0)); | |
| 2190 | |
| 2191 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( | |
| 2192 LayerAnimationController::ObserverType::ACTIVE)); | |
| 2193 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( | |
| 2194 LayerAnimationController::ObserverType::PENDING)); | |
| 2195 | |
| 2196 controller_impl->AddAnimation(CreateAnimation( | |
| 2197 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 2198 1, TargetProperty::OPACITY)); | |
| 2199 | |
| 2200 // Opacity animations aren't non-translation transforms. | |
| 2201 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( | |
| 2202 LayerAnimationController::ObserverType::ACTIVE)); | |
| 2203 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( | |
| 2204 LayerAnimationController::ObserverType::PENDING)); | |
| 2205 | |
| 2206 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | |
| 2207 KeyframedTransformAnimationCurve::Create()); | |
| 2208 | |
| 2209 TransformOperations operations1; | |
| 2210 curve1->AddKeyframe( | |
| 2211 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | |
| 2212 operations1.AppendTranslate(10.0, 15.0, 0.0); | |
| 2213 curve1->AddKeyframe(TransformKeyframe::Create( | |
| 2214 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | |
| 2215 | |
| 2216 std::unique_ptr<Animation> animation( | |
| 2217 Animation::Create(std::move(curve1), 2, 2, TargetProperty::TRANSFORM)); | |
| 2218 controller_impl->AddAnimation(std::move(animation)); | |
| 2219 | |
| 2220 // The only transform animation we've added is a translation. | |
| 2221 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( | |
| 2222 LayerAnimationController::ObserverType::ACTIVE)); | |
| 2223 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( | |
| 2224 LayerAnimationController::ObserverType::PENDING)); | |
| 2225 | |
| 2226 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( | |
| 2227 KeyframedTransformAnimationCurve::Create()); | |
| 2228 | |
| 2229 TransformOperations operations2; | |
| 2230 curve2->AddKeyframe( | |
| 2231 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | |
| 2232 operations2.AppendScale(2.0, 3.0, 4.0); | |
| 2233 curve2->AddKeyframe(TransformKeyframe::Create( | |
| 2234 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | |
| 2235 | |
| 2236 animation = | |
| 2237 Animation::Create(std::move(curve2), 3, 3, TargetProperty::TRANSFORM); | |
| 2238 animation->set_affects_active_observers(false); | |
| 2239 controller_impl->AddAnimation(std::move(animation)); | |
| 2240 | |
| 2241 // A scale animation is not a translation. | |
| 2242 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms( | |
| 2243 LayerAnimationController::ObserverType::PENDING)); | |
| 2244 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( | |
| 2245 LayerAnimationController::ObserverType::ACTIVE)); | |
| 2246 | |
| 2247 controller_impl->ActivateAnimations(); | |
| 2248 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms( | |
| 2249 LayerAnimationController::ObserverType::PENDING)); | |
| 2250 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms( | |
| 2251 LayerAnimationController::ObserverType::ACTIVE)); | |
| 2252 | |
| 2253 controller_impl->GetAnimationById(3)->set_affects_pending_observers(false); | |
| 2254 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( | |
| 2255 LayerAnimationController::ObserverType::PENDING)); | |
| 2256 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms( | |
| 2257 LayerAnimationController::ObserverType::ACTIVE)); | |
| 2258 | |
| 2259 controller_impl->GetAnimationById(3) | |
| 2260 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); | |
| 2261 | |
| 2262 // Only unfinished animations should be considered by | |
| 2263 // HasOnlyTranslationTransforms. | |
| 2264 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( | |
| 2265 LayerAnimationController::ObserverType::PENDING)); | |
| 2266 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms( | |
| 2267 LayerAnimationController::ObserverType::ACTIVE)); | |
| 2268 } | |
| 2269 | |
| 2270 TEST(LayerAnimationControllerTest, AnimationStartScale) { | |
| 2271 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2272 LayerAnimationController::Create(0)); | |
| 2273 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | |
| 2274 KeyframedTransformAnimationCurve::Create()); | |
| 2275 | |
| 2276 TransformOperations operations1; | |
| 2277 operations1.AppendScale(2.0, 3.0, 4.0); | |
| 2278 curve1->AddKeyframe( | |
| 2279 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | |
| 2280 TransformOperations operations2; | |
| 2281 curve1->AddKeyframe(TransformKeyframe::Create( | |
| 2282 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | |
| 2283 std::unique_ptr<Animation> animation( | |
| 2284 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); | |
| 2285 animation->set_affects_active_observers(false); | |
| 2286 controller_impl->AddAnimation(std::move(animation)); | |
| 2287 | |
| 2288 float start_scale = 0.f; | |
| 2289 EXPECT_TRUE(controller_impl->AnimationStartScale( | |
| 2290 LayerAnimationController::ObserverType::PENDING, &start_scale)); | |
| 2291 EXPECT_EQ(4.f, start_scale); | |
| 2292 EXPECT_TRUE(controller_impl->AnimationStartScale( | |
| 2293 LayerAnimationController::ObserverType::ACTIVE, &start_scale)); | |
| 2294 EXPECT_EQ(0.f, start_scale); | |
| 2295 | |
| 2296 controller_impl->ActivateAnimations(); | |
| 2297 EXPECT_TRUE(controller_impl->AnimationStartScale( | |
| 2298 LayerAnimationController::ObserverType::PENDING, &start_scale)); | |
| 2299 EXPECT_EQ(4.f, start_scale); | |
| 2300 EXPECT_TRUE(controller_impl->AnimationStartScale( | |
| 2301 LayerAnimationController::ObserverType::ACTIVE, &start_scale)); | |
| 2302 EXPECT_EQ(4.f, start_scale); | |
| 2303 | |
| 2304 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( | |
| 2305 KeyframedTransformAnimationCurve::Create()); | |
| 2306 | |
| 2307 TransformOperations operations3; | |
| 2308 curve2->AddKeyframe( | |
| 2309 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); | |
| 2310 operations3.AppendScale(6.0, 5.0, 4.0); | |
| 2311 curve2->AddKeyframe(TransformKeyframe::Create( | |
| 2312 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); | |
| 2313 | |
| 2314 controller_impl->RemoveAnimation(1); | |
| 2315 animation = | |
| 2316 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); | |
| 2317 | |
| 2318 // Reverse Direction | |
| 2319 animation->set_direction(Animation::DIRECTION_REVERSE); | |
| 2320 animation->set_affects_active_observers(false); | |
| 2321 controller_impl->AddAnimation(std::move(animation)); | |
| 2322 | |
| 2323 std::unique_ptr<KeyframedTransformAnimationCurve> curve3( | |
| 2324 KeyframedTransformAnimationCurve::Create()); | |
| 2325 | |
| 2326 TransformOperations operations4; | |
| 2327 operations4.AppendScale(5.0, 3.0, 1.0); | |
| 2328 curve3->AddKeyframe( | |
| 2329 TransformKeyframe::Create(base::TimeDelta(), operations4, nullptr)); | |
| 2330 TransformOperations operations5; | |
| 2331 curve3->AddKeyframe(TransformKeyframe::Create( | |
| 2332 base::TimeDelta::FromSecondsD(1.0), operations5, nullptr)); | |
| 2333 | |
| 2334 animation = | |
| 2335 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM); | |
| 2336 animation->set_affects_active_observers(false); | |
| 2337 controller_impl->AddAnimation(std::move(animation)); | |
| 2338 | |
| 2339 EXPECT_TRUE(controller_impl->AnimationStartScale( | |
| 2340 LayerAnimationController::ObserverType::PENDING, &start_scale)); | |
| 2341 EXPECT_EQ(6.f, start_scale); | |
| 2342 EXPECT_TRUE(controller_impl->AnimationStartScale( | |
| 2343 LayerAnimationController::ObserverType::ACTIVE, &start_scale)); | |
| 2344 EXPECT_EQ(0.f, start_scale); | |
| 2345 | |
| 2346 controller_impl->ActivateAnimations(); | |
| 2347 EXPECT_TRUE(controller_impl->AnimationStartScale( | |
| 2348 LayerAnimationController::ObserverType::PENDING, &start_scale)); | |
| 2349 EXPECT_EQ(6.f, start_scale); | |
| 2350 EXPECT_TRUE(controller_impl->AnimationStartScale( | |
| 2351 LayerAnimationController::ObserverType::ACTIVE, &start_scale)); | |
| 2352 EXPECT_EQ(6.f, start_scale); | |
| 2353 | |
| 2354 controller_impl->GetAnimationById(2) | |
| 2355 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); | |
| 2356 | |
| 2357 // Only unfinished animations should be considered by | |
| 2358 // AnimationStartScale. | |
| 2359 EXPECT_TRUE(controller_impl->AnimationStartScale( | |
| 2360 LayerAnimationController::ObserverType::PENDING, &start_scale)); | |
| 2361 EXPECT_EQ(5.f, start_scale); | |
| 2362 EXPECT_TRUE(controller_impl->AnimationStartScale( | |
| 2363 LayerAnimationController::ObserverType::ACTIVE, &start_scale)); | |
| 2364 EXPECT_EQ(5.f, start_scale); | |
| 2365 } | |
| 2366 | |
| 2367 TEST(LayerAnimationControllerTest, MaximumTargetScale) { | |
| 2368 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2369 LayerAnimationController::Create(0)); | |
| 2370 | |
| 2371 float max_scale = 0.f; | |
| 2372 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2373 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2374 EXPECT_EQ(0.f, max_scale); | |
| 2375 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2376 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2377 EXPECT_EQ(0.f, max_scale); | |
| 2378 | |
| 2379 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | |
| 2380 KeyframedTransformAnimationCurve::Create()); | |
| 2381 | |
| 2382 TransformOperations operations1; | |
| 2383 curve1->AddKeyframe( | |
| 2384 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | |
| 2385 operations1.AppendScale(2.0, 3.0, 4.0); | |
| 2386 curve1->AddKeyframe(TransformKeyframe::Create( | |
| 2387 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | |
| 2388 | |
| 2389 std::unique_ptr<Animation> animation( | |
| 2390 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); | |
| 2391 animation->set_affects_active_observers(false); | |
| 2392 controller_impl->AddAnimation(std::move(animation)); | |
| 2393 | |
| 2394 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2395 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2396 EXPECT_EQ(4.f, max_scale); | |
| 2397 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2398 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2399 EXPECT_EQ(0.f, max_scale); | |
| 2400 | |
| 2401 controller_impl->ActivateAnimations(); | |
| 2402 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2403 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2404 EXPECT_EQ(4.f, max_scale); | |
| 2405 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2406 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2407 EXPECT_EQ(4.f, max_scale); | |
| 2408 | |
| 2409 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( | |
| 2410 KeyframedTransformAnimationCurve::Create()); | |
| 2411 | |
| 2412 TransformOperations operations2; | |
| 2413 curve2->AddKeyframe( | |
| 2414 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | |
| 2415 operations2.AppendScale(6.0, 5.0, 4.0); | |
| 2416 curve2->AddKeyframe(TransformKeyframe::Create( | |
| 2417 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | |
| 2418 | |
| 2419 animation = | |
| 2420 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); | |
| 2421 animation->set_affects_active_observers(false); | |
| 2422 controller_impl->AddAnimation(std::move(animation)); | |
| 2423 | |
| 2424 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2425 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2426 EXPECT_EQ(6.f, max_scale); | |
| 2427 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2428 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2429 EXPECT_EQ(4.f, max_scale); | |
| 2430 | |
| 2431 controller_impl->ActivateAnimations(); | |
| 2432 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2433 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2434 EXPECT_EQ(6.f, max_scale); | |
| 2435 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2436 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2437 EXPECT_EQ(6.f, max_scale); | |
| 2438 | |
| 2439 std::unique_ptr<KeyframedTransformAnimationCurve> curve3( | |
| 2440 KeyframedTransformAnimationCurve::Create()); | |
| 2441 | |
| 2442 TransformOperations operations3; | |
| 2443 curve3->AddKeyframe( | |
| 2444 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); | |
| 2445 operations3.AppendPerspective(6.0); | |
| 2446 curve3->AddKeyframe(TransformKeyframe::Create( | |
| 2447 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); | |
| 2448 | |
| 2449 animation = | |
| 2450 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM); | |
| 2451 animation->set_affects_active_observers(false); | |
| 2452 controller_impl->AddAnimation(std::move(animation)); | |
| 2453 | |
| 2454 EXPECT_FALSE(controller_impl->MaximumTargetScale( | |
| 2455 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2456 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2457 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2458 EXPECT_EQ(6.f, max_scale); | |
| 2459 | |
| 2460 controller_impl->ActivateAnimations(); | |
| 2461 EXPECT_FALSE(controller_impl->MaximumTargetScale( | |
| 2462 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2463 EXPECT_FALSE(controller_impl->MaximumTargetScale( | |
| 2464 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2465 | |
| 2466 controller_impl->GetAnimationById(3) | |
| 2467 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); | |
| 2468 controller_impl->GetAnimationById(2) | |
| 2469 ->SetRunState(Animation::FINISHED, TicksFromSecondsF(0.0)); | |
| 2470 | |
| 2471 // Only unfinished animations should be considered by | |
| 2472 // MaximumTargetScale. | |
| 2473 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2474 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2475 EXPECT_EQ(4.f, max_scale); | |
| 2476 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2477 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2478 EXPECT_EQ(4.f, max_scale); | |
| 2479 } | |
| 2480 | |
| 2481 TEST(LayerAnimationControllerTest, MaximumTargetScaleWithDirection) { | |
| 2482 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2483 LayerAnimationController::Create(0)); | |
| 2484 | |
| 2485 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | |
| 2486 KeyframedTransformAnimationCurve::Create()); | |
| 2487 TransformOperations operations1; | |
| 2488 operations1.AppendScale(1.0, 2.0, 3.0); | |
| 2489 curve1->AddKeyframe( | |
| 2490 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | |
| 2491 TransformOperations operations2; | |
| 2492 operations2.AppendScale(4.0, 5.0, 6.0); | |
| 2493 curve1->AddKeyframe(TransformKeyframe::Create( | |
| 2494 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | |
| 2495 | |
| 2496 std::unique_ptr<Animation> animation_owned( | |
| 2497 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); | |
| 2498 Animation* animation = animation_owned.get(); | |
| 2499 controller_impl->AddAnimation(std::move(animation_owned)); | |
| 2500 | |
| 2501 float max_scale = 0.f; | |
| 2502 | |
| 2503 EXPECT_GT(animation->playback_rate(), 0.0); | |
| 2504 | |
| 2505 // NORMAL direction with positive playback rate. | |
| 2506 animation->set_direction(Animation::DIRECTION_NORMAL); | |
| 2507 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2508 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2509 EXPECT_EQ(6.f, max_scale); | |
| 2510 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2511 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2512 EXPECT_EQ(6.f, max_scale); | |
| 2513 | |
| 2514 // ALTERNATE direction with positive playback rate. | |
| 2515 animation->set_direction(Animation::DIRECTION_ALTERNATE); | |
| 2516 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2517 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2518 EXPECT_EQ(6.f, max_scale); | |
| 2519 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2520 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2521 EXPECT_EQ(6.f, max_scale); | |
| 2522 | |
| 2523 // REVERSE direction with positive playback rate. | |
| 2524 animation->set_direction(Animation::DIRECTION_REVERSE); | |
| 2525 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2526 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2527 EXPECT_EQ(3.f, max_scale); | |
| 2528 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2529 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2530 EXPECT_EQ(3.f, max_scale); | |
| 2531 | |
| 2532 // ALTERNATE reverse direction. | |
| 2533 animation->set_direction(Animation::DIRECTION_REVERSE); | |
| 2534 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2535 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2536 EXPECT_EQ(3.f, max_scale); | |
| 2537 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2538 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2539 EXPECT_EQ(3.f, max_scale); | |
| 2540 | |
| 2541 animation->set_playback_rate(-1.0); | |
| 2542 | |
| 2543 // NORMAL direction with negative playback rate. | |
| 2544 animation->set_direction(Animation::DIRECTION_NORMAL); | |
| 2545 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2546 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2547 EXPECT_EQ(3.f, max_scale); | |
| 2548 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2549 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2550 EXPECT_EQ(3.f, max_scale); | |
| 2551 | |
| 2552 // ALTERNATE direction with negative playback rate. | |
| 2553 animation->set_direction(Animation::DIRECTION_ALTERNATE); | |
| 2554 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2555 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2556 EXPECT_EQ(3.f, max_scale); | |
| 2557 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2558 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2559 EXPECT_EQ(3.f, max_scale); | |
| 2560 | |
| 2561 // REVERSE direction with negative playback rate. | |
| 2562 animation->set_direction(Animation::DIRECTION_REVERSE); | |
| 2563 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2564 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2565 EXPECT_EQ(6.f, max_scale); | |
| 2566 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2567 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2568 EXPECT_EQ(6.f, max_scale); | |
| 2569 | |
| 2570 // ALTERNATE reverse direction with negative playback rate. | |
| 2571 animation->set_direction(Animation::DIRECTION_REVERSE); | |
| 2572 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2573 LayerAnimationController::ObserverType::PENDING, &max_scale)); | |
| 2574 EXPECT_EQ(6.f, max_scale); | |
| 2575 EXPECT_TRUE(controller_impl->MaximumTargetScale( | |
| 2576 LayerAnimationController::ObserverType::ACTIVE, &max_scale)); | |
| 2577 EXPECT_EQ(6.f, max_scale); | |
| 2578 } | |
| 2579 | |
| 2580 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { | |
| 2581 std::unique_ptr<AnimationEvents> events( | |
| 2582 base::WrapUnique(new AnimationEvents)); | |
| 2583 FakeLayerAnimationValueObserver dummy_impl; | |
| 2584 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2585 LayerAnimationController::Create(0)); | |
| 2586 controller_impl->set_value_observer(&dummy_impl); | |
| 2587 controller_impl->set_needs_active_value_observations(true); | |
| 2588 controller_impl->set_needs_pending_value_observations(true); | |
| 2589 FakeLayerAnimationValueObserver dummy; | |
| 2590 scoped_refptr<LayerAnimationController> controller( | |
| 2591 LayerAnimationController::Create(0)); | |
| 2592 controller->set_value_observer(&dummy); | |
| 2593 controller->set_needs_active_value_observations(true); | |
| 2594 | |
| 2595 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); | |
| 2596 int animation_id = | |
| 2597 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false); | |
| 2598 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); | |
| 2599 | |
| 2600 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | |
| 2601 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2602 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); | |
| 2603 | |
| 2604 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 2605 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 2606 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 2607 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | |
| 2608 ->affects_pending_observers()); | |
| 2609 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | |
| 2610 ->affects_active_observers()); | |
| 2611 | |
| 2612 controller_impl->Animate(kInitialTickTime); | |
| 2613 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); | |
| 2614 controller_impl->UpdateState(true, events.get()); | |
| 2615 | |
| 2616 // Since the animation hasn't been activated, it should still be STARTING | |
| 2617 // rather than RUNNING. | |
| 2618 EXPECT_EQ(Animation::STARTING, | |
| 2619 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 2620 | |
| 2621 // Since the animation hasn't been activated, only the pending observer | |
| 2622 // should have been ticked. | |
| 2623 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); | |
| 2624 EXPECT_EQ(0.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 2625 | |
| 2626 controller_impl->ActivateAnimations(); | |
| 2627 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | |
| 2628 ->affects_pending_observers()); | |
| 2629 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | |
| 2630 ->affects_active_observers()); | |
| 2631 | |
| 2632 controller_impl->Animate(kInitialTickTime + | |
| 2633 TimeDelta::FromMilliseconds(1000)); | |
| 2634 controller_impl->UpdateState(true, events.get()); | |
| 2635 | |
| 2636 // Since the animation has been activated, it should have reached the | |
| 2637 // RUNNING state and the active observer should start to get ticked. | |
| 2638 EXPECT_EQ(Animation::RUNNING, | |
| 2639 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 2640 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); | |
| 2641 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 2642 } | |
| 2643 | |
| 2644 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { | |
| 2645 std::unique_ptr<AnimationEvents> events( | |
| 2646 base::WrapUnique(new AnimationEvents)); | |
| 2647 FakeLayerAnimationValueObserver dummy_impl; | |
| 2648 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2649 LayerAnimationController::Create(0)); | |
| 2650 controller_impl->set_value_observer(&dummy_impl); | |
| 2651 controller_impl->set_needs_active_value_observations(true); | |
| 2652 controller_impl->set_needs_pending_value_observations(true); | |
| 2653 | |
| 2654 FakeLayerAnimationValueObserver dummy; | |
| 2655 scoped_refptr<LayerAnimationController> controller( | |
| 2656 LayerAnimationController::Create(0)); | |
| 2657 controller->set_value_observer(&dummy); | |
| 2658 controller->set_needs_active_value_observations(true); | |
| 2659 | |
| 2660 int animation_id = | |
| 2661 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); | |
| 2662 | |
| 2663 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2664 | |
| 2665 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 2666 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | |
| 2667 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 2668 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | |
| 2669 ->affects_pending_observers()); | |
| 2670 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | |
| 2671 ->affects_active_observers()); | |
| 2672 | |
| 2673 controller_impl->Animate(kInitialTickTime); | |
| 2674 | |
| 2675 // Since the animation hasn't been activated, only the pending observer | |
| 2676 // should have been ticked. | |
| 2677 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); | |
| 2678 EXPECT_EQ(0.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 2679 | |
| 2680 controller_impl->ActivateAnimations(); | |
| 2681 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | |
| 2682 ->affects_pending_observers()); | |
| 2683 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | |
| 2684 ->affects_active_observers()); | |
| 2685 | |
| 2686 controller_impl->UpdateState(true, events.get()); | |
| 2687 | |
| 2688 // Since the animation has been activated, it should have reached the | |
| 2689 // RUNNING state. | |
| 2690 EXPECT_EQ(Animation::RUNNING, | |
| 2691 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 2692 | |
| 2693 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 2694 | |
| 2695 // Both observers should have been ticked. | |
| 2696 EXPECT_EQ(0.75f, dummy_impl.opacity(LayerTreeType::PENDING)); | |
| 2697 EXPECT_EQ(0.75f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 2698 } | |
| 2699 | |
| 2700 TEST(LayerAnimationControllerTest, | |
| 2701 ObserverNotifiedWhenTransformIsPotentiallyAnimatingChanges) { | |
| 2702 AnimationEvents events; | |
| 2703 FakeLayerAnimationValueObserver dummy_impl; | |
| 2704 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2705 LayerAnimationController::Create(0)); | |
| 2706 controller_impl->set_value_observer(&dummy_impl); | |
| 2707 controller_impl->set_needs_active_value_observations(true); | |
| 2708 controller_impl->set_needs_pending_value_observations(true); | |
| 2709 | |
| 2710 FakeLayerAnimationValueObserver dummy; | |
| 2711 scoped_refptr<LayerAnimationController> controller( | |
| 2712 LayerAnimationController::Create(0)); | |
| 2713 controller->set_value_observer(&dummy); | |
| 2714 controller->set_needs_active_value_observations(true); | |
| 2715 | |
| 2716 EXPECT_FALSE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2717 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2718 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2719 | |
| 2720 // Case 1: An animation that's allowed to run until its finish point. | |
| 2721 AddAnimatedTransformToController(controller.get(), 1.0, 1, 1); | |
| 2722 EXPECT_TRUE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2723 | |
| 2724 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2725 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2726 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2727 | |
| 2728 controller_impl->ActivateAnimations(); | |
| 2729 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2730 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2731 | |
| 2732 controller_impl->Animate(kInitialTickTime); | |
| 2733 controller_impl->UpdateState(true, &events); | |
| 2734 | |
| 2735 controller->NotifyAnimationStarted(events.events_[0]); | |
| 2736 events.events_.clear(); | |
| 2737 | |
| 2738 // Finish the animation. | |
| 2739 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 2740 controller->UpdateState(true, nullptr); | |
| 2741 EXPECT_FALSE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2742 | |
| 2743 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2744 | |
| 2745 // controller_impl hasn't yet ticked at/past the end of the animation. | |
| 2746 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2747 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2748 | |
| 2749 controller_impl->Animate(kInitialTickTime + | |
| 2750 TimeDelta::FromMilliseconds(1000)); | |
| 2751 controller_impl->UpdateState(true, &events); | |
| 2752 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2753 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2754 | |
| 2755 controller->NotifyAnimationFinished(events.events_[0]); | |
| 2756 events.events_.clear(); | |
| 2757 | |
| 2758 // Case 2: An animation that's removed before it finishes. | |
| 2759 int animation_id = | |
| 2760 AddAnimatedTransformToController(controller.get(), 10.0, 2, 2); | |
| 2761 EXPECT_TRUE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2762 | |
| 2763 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2764 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2765 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2766 | |
| 2767 controller_impl->ActivateAnimations(); | |
| 2768 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2769 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2770 | |
| 2771 controller_impl->Animate(kInitialTickTime + | |
| 2772 TimeDelta::FromMilliseconds(2000)); | |
| 2773 controller_impl->UpdateState(true, &events); | |
| 2774 | |
| 2775 controller->NotifyAnimationStarted(events.events_[0]); | |
| 2776 events.events_.clear(); | |
| 2777 | |
| 2778 controller->RemoveAnimation(animation_id); | |
| 2779 EXPECT_FALSE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2780 | |
| 2781 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2782 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2783 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2784 | |
| 2785 controller_impl->ActivateAnimations(); | |
| 2786 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2787 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2788 | |
| 2789 // Case 3: An animation that's aborted before it finishes. | |
| 2790 animation_id = AddAnimatedTransformToController(controller.get(), 10.0, 3, 3); | |
| 2791 EXPECT_TRUE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2792 | |
| 2793 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2794 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2795 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2796 | |
| 2797 controller_impl->ActivateAnimations(); | |
| 2798 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2799 EXPECT_TRUE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2800 | |
| 2801 controller_impl->Animate(kInitialTickTime + | |
| 2802 TimeDelta::FromMilliseconds(3000)); | |
| 2803 controller_impl->UpdateState(true, &events); | |
| 2804 | |
| 2805 controller->NotifyAnimationStarted(events.events_[0]); | |
| 2806 events.events_.clear(); | |
| 2807 | |
| 2808 controller_impl->AbortAnimations(TargetProperty::TRANSFORM); | |
| 2809 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::PENDING)); | |
| 2810 EXPECT_FALSE(dummy_impl.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2811 | |
| 2812 controller_impl->Animate(kInitialTickTime + | |
| 2813 TimeDelta::FromMilliseconds(4000)); | |
| 2814 controller_impl->UpdateState(true, &events); | |
| 2815 | |
| 2816 controller->NotifyAnimationAborted(events.events_[0]); | |
| 2817 EXPECT_FALSE(dummy.transform_is_animating(LayerTreeType::ACTIVE)); | |
| 2818 } | |
| 2819 | |
| 2820 TEST(LayerAnimationControllerTest, ClippedOpacityValues) { | |
| 2821 FakeLayerAnimationValueObserver dummy; | |
| 2822 scoped_refptr<LayerAnimationController> controller( | |
| 2823 LayerAnimationController::Create(0)); | |
| 2824 controller->set_value_observer(&dummy); | |
| 2825 controller->set_needs_active_value_observations(true); | |
| 2826 | |
| 2827 AddOpacityTransitionToController(controller.get(), 1, 1.f, 2.f, true); | |
| 2828 | |
| 2829 controller->Animate(kInitialTickTime); | |
| 2830 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 2831 | |
| 2832 // Opacity values are clipped [0,1] | |
| 2833 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 2834 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 2835 } | |
| 2836 | |
| 2837 TEST(LayerAnimationControllerTest, ClippedNegativeOpacityValues) { | |
| 2838 FakeLayerAnimationValueObserver dummy; | |
| 2839 scoped_refptr<LayerAnimationController> controller( | |
| 2840 LayerAnimationController::Create(0)); | |
| 2841 controller->set_value_observer(&dummy); | |
| 2842 controller->set_needs_active_value_observations(true); | |
| 2843 | |
| 2844 AddOpacityTransitionToController(controller.get(), 1, 0.f, -2.f, true); | |
| 2845 | |
| 2846 controller->Animate(kInitialTickTime); | |
| 2847 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 2848 | |
| 2849 // Opacity values are clipped [0,1] | |
| 2850 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | |
| 2851 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 2852 } | |
| 2853 | |
| 2854 TEST(LayerAnimationControllerTest, PushedDeletedAnimationWaitsForActivation) { | |
| 2855 std::unique_ptr<AnimationEvents> events( | |
| 2856 base::WrapUnique(new AnimationEvents)); | |
| 2857 FakeLayerAnimationValueObserver dummy_impl; | |
| 2858 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2859 LayerAnimationController::Create(0)); | |
| 2860 controller_impl->set_value_observer(&dummy_impl); | |
| 2861 controller_impl->set_needs_active_value_observations(true); | |
| 2862 controller_impl->set_needs_pending_value_observations(true); | |
| 2863 | |
| 2864 FakeLayerAnimationValueObserver dummy; | |
| 2865 scoped_refptr<LayerAnimationController> controller( | |
| 2866 LayerAnimationController::Create(0)); | |
| 2867 controller->set_value_observer(&dummy); | |
| 2868 controller->set_needs_active_value_observations(true); | |
| 2869 | |
| 2870 int animation_id = | |
| 2871 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); | |
| 2872 | |
| 2873 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2874 controller_impl->ActivateAnimations(); | |
| 2875 controller_impl->Animate(kInitialTickTime); | |
| 2876 controller_impl->UpdateState(true, events.get()); | |
| 2877 EXPECT_EQ(Animation::RUNNING, | |
| 2878 controller_impl->GetAnimationById(animation_id)->run_state()); | |
| 2879 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); | |
| 2880 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 2881 | |
| 2882 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | |
| 2883 ->affects_pending_observers()); | |
| 2884 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | |
| 2885 ->affects_active_observers()); | |
| 2886 | |
| 2887 // Delete the animation on the main-thread controller. | |
| 2888 controller->RemoveAnimation( | |
| 2889 controller->GetAnimation(TargetProperty::OPACITY)->id()); | |
| 2890 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2891 | |
| 2892 // The animation should no longer affect pending observers. | |
| 2893 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id) | |
| 2894 ->affects_pending_observers()); | |
| 2895 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id) | |
| 2896 ->affects_active_observers()); | |
| 2897 | |
| 2898 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 2899 controller_impl->UpdateState(true, events.get()); | |
| 2900 | |
| 2901 // Only the active observer should have been ticked. | |
| 2902 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::PENDING)); | |
| 2903 EXPECT_EQ(0.75f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 2904 | |
| 2905 controller_impl->ActivateAnimations(); | |
| 2906 | |
| 2907 // Activation should cause the animation to be deleted. | |
| 2908 EXPECT_FALSE(controller_impl->has_any_animation()); | |
| 2909 } | |
| 2910 | |
| 2911 // Tests that an animation that affects only active observers won't block | |
| 2912 // an animation that affects only pending observers from starting. | |
| 2913 TEST(LayerAnimationControllerTest, StartAnimationsAffectingDifferentObservers) { | |
| 2914 std::unique_ptr<AnimationEvents> events( | |
| 2915 base::WrapUnique(new AnimationEvents)); | |
| 2916 FakeLayerAnimationValueObserver dummy_impl; | |
| 2917 scoped_refptr<LayerAnimationController> controller_impl( | |
| 2918 LayerAnimationController::Create(0)); | |
| 2919 controller_impl->set_value_observer(&dummy_impl); | |
| 2920 controller_impl->set_needs_active_value_observations(true); | |
| 2921 controller_impl->set_needs_pending_value_observations(true); | |
| 2922 | |
| 2923 FakeLayerAnimationValueObserver dummy; | |
| 2924 scoped_refptr<LayerAnimationController> controller( | |
| 2925 LayerAnimationController::Create(0)); | |
| 2926 controller->set_value_observer(&dummy); | |
| 2927 controller->set_needs_active_value_observations(true); | |
| 2928 | |
| 2929 int first_animation_id = | |
| 2930 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true); | |
| 2931 | |
| 2932 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2933 controller_impl->ActivateAnimations(); | |
| 2934 controller_impl->Animate(kInitialTickTime); | |
| 2935 controller_impl->UpdateState(true, events.get()); | |
| 2936 | |
| 2937 // Remove the first animation from the main-thread controller, and add a | |
| 2938 // new animation affecting the same property. | |
| 2939 controller->RemoveAnimation( | |
| 2940 controller->GetAnimation(TargetProperty::OPACITY)->id()); | |
| 2941 int second_animation_id = | |
| 2942 AddOpacityTransitionToController(controller.get(), 1, 1.f, 0.5f, true); | |
| 2943 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 2944 | |
| 2945 // The original animation should only affect active observers, and the new | |
| 2946 // animation should only affect pending observers. | |
| 2947 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id) | |
| 2948 ->affects_pending_observers()); | |
| 2949 EXPECT_TRUE(controller_impl->GetAnimationById(first_animation_id) | |
| 2950 ->affects_active_observers()); | |
| 2951 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) | |
| 2952 ->affects_pending_observers()); | |
| 2953 EXPECT_FALSE(controller_impl->GetAnimationById(second_animation_id) | |
| 2954 ->affects_active_observers()); | |
| 2955 | |
| 2956 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | |
| 2957 controller_impl->UpdateState(true, events.get()); | |
| 2958 | |
| 2959 // The original animation should still be running, and the new animation | |
| 2960 // should be starting. | |
| 2961 EXPECT_EQ(Animation::RUNNING, | |
| 2962 controller_impl->GetAnimationById(first_animation_id)->run_state()); | |
| 2963 EXPECT_EQ( | |
| 2964 Animation::STARTING, | |
| 2965 controller_impl->GetAnimationById(second_animation_id)->run_state()); | |
| 2966 | |
| 2967 // The active observer should have been ticked by the original animation, | |
| 2968 // and the pending observer should have been ticked by the new animation. | |
| 2969 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::PENDING)); | |
| 2970 EXPECT_EQ(0.5f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 2971 | |
| 2972 controller_impl->ActivateAnimations(); | |
| 2973 | |
| 2974 // The original animation should have been deleted, and the new animation | |
| 2975 // should now affect both observers. | |
| 2976 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id)); | |
| 2977 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) | |
| 2978 ->affects_pending_observers()); | |
| 2979 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id) | |
| 2980 ->affects_active_observers()); | |
| 2981 | |
| 2982 controller_impl->Animate(kInitialTickTime + | |
| 2983 TimeDelta::FromMilliseconds(1000)); | |
| 2984 controller_impl->UpdateState(true, events.get()); | |
| 2985 | |
| 2986 // The new animation should be running, and the active observer should have | |
| 2987 // been ticked at the new animation's starting point. | |
| 2988 EXPECT_EQ( | |
| 2989 Animation::RUNNING, | |
| 2990 controller_impl->GetAnimationById(second_animation_id)->run_state()); | |
| 2991 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::PENDING)); | |
| 2992 EXPECT_EQ(1.f, dummy_impl.opacity(LayerTreeType::ACTIVE)); | |
| 2993 } | |
| 2994 | |
| 2995 TEST(LayerAnimationControllerTest, TestIsCurrentlyAnimatingProperty) { | |
| 2996 FakeLayerAnimationValueObserver dummy; | |
| 2997 scoped_refptr<LayerAnimationController> controller( | |
| 2998 LayerAnimationController::Create(0)); | |
| 2999 controller->set_value_observer(&dummy); | |
| 3000 controller->set_needs_active_value_observations(true); | |
| 3001 | |
| 3002 // Create an animation that initially affects only pending observers. | |
| 3003 std::unique_ptr<Animation> animation(CreateAnimation( | |
| 3004 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 3005 1, TargetProperty::OPACITY)); | |
| 3006 animation->set_affects_active_observers(false); | |
| 3007 | |
| 3008 controller->AddAnimation(std::move(animation)); | |
| 3009 controller->Animate(kInitialTickTime); | |
| 3010 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | |
| 3011 TargetProperty::OPACITY, | |
| 3012 LayerAnimationController::ObserverType::PENDING)); | |
| 3013 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3014 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3015 controller->UpdateState(true, nullptr); | |
| 3016 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 3017 | |
| 3018 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | |
| 3019 TargetProperty::OPACITY, | |
| 3020 LayerAnimationController::ObserverType::PENDING)); | |
| 3021 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3022 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3023 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3024 TargetProperty::FILTER, LayerAnimationController::ObserverType::PENDING)); | |
| 3025 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3026 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3027 | |
| 3028 controller->ActivateAnimations(); | |
| 3029 | |
| 3030 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | |
| 3031 TargetProperty::OPACITY, | |
| 3032 LayerAnimationController::ObserverType::PENDING)); | |
| 3033 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | |
| 3034 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3035 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3036 TargetProperty::FILTER, LayerAnimationController::ObserverType::PENDING)); | |
| 3037 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3038 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3039 | |
| 3040 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(10)); | |
| 3041 controller->UpdateState(true, nullptr); | |
| 3042 | |
| 3043 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | |
| 3044 TargetProperty::OPACITY, | |
| 3045 LayerAnimationController::ObserverType::PENDING)); | |
| 3046 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | |
| 3047 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3048 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3049 TargetProperty::FILTER, LayerAnimationController::ObserverType::PENDING)); | |
| 3050 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3051 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3052 | |
| 3053 EXPECT_EQ(0.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 3054 | |
| 3055 // Tick past the end of the animation. | |
| 3056 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1100)); | |
| 3057 controller->UpdateState(true, nullptr); | |
| 3058 | |
| 3059 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3060 TargetProperty::OPACITY, | |
| 3061 LayerAnimationController::ObserverType::PENDING)); | |
| 3062 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3063 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3064 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3065 TargetProperty::FILTER, LayerAnimationController::ObserverType::PENDING)); | |
| 3066 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3067 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3068 | |
| 3069 EXPECT_EQ(1.f, dummy.opacity(LayerTreeType::ACTIVE)); | |
| 3070 } | |
| 3071 | |
| 3072 TEST(LayerAnimationControllerTest, TestIsAnimatingPropertyTimeOffsetFillMode) { | |
| 3073 FakeLayerAnimationValueObserver dummy; | |
| 3074 scoped_refptr<LayerAnimationController> controller( | |
| 3075 LayerAnimationController::Create(0)); | |
| 3076 controller->set_value_observer(&dummy); | |
| 3077 controller->set_needs_active_value_observations(true); | |
| 3078 | |
| 3079 // Create an animation that initially affects only pending observers, and has | |
| 3080 // a start delay of 2 seconds. | |
| 3081 std::unique_ptr<Animation> animation(CreateAnimation( | |
| 3082 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 3083 1, TargetProperty::OPACITY)); | |
| 3084 animation->set_fill_mode(Animation::FILL_MODE_NONE); | |
| 3085 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); | |
| 3086 animation->set_affects_active_observers(false); | |
| 3087 | |
| 3088 controller->AddAnimation(std::move(animation)); | |
| 3089 | |
| 3090 controller->Animate(kInitialTickTime); | |
| 3091 | |
| 3092 // Since the animation has a start delay, the observers it affects have a | |
| 3093 // potentially running transform animation but aren't currently animating | |
| 3094 // transform. | |
| 3095 EXPECT_TRUE(controller->IsPotentiallyAnimatingProperty( | |
| 3096 TargetProperty::OPACITY, | |
| 3097 LayerAnimationController::ObserverType::PENDING)); | |
| 3098 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty( | |
| 3099 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3100 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3101 TargetProperty::OPACITY, | |
| 3102 LayerAnimationController::ObserverType::PENDING)); | |
| 3103 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3104 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3105 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 3106 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty( | |
| 3107 TargetProperty::FILTER, LayerAnimationController::ObserverType::PENDING)); | |
| 3108 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty( | |
| 3109 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3110 | |
| 3111 controller->ActivateAnimations(); | |
| 3112 | |
| 3113 EXPECT_TRUE(controller->IsPotentiallyAnimatingProperty( | |
| 3114 TargetProperty::OPACITY, | |
| 3115 LayerAnimationController::ObserverType::PENDING)); | |
| 3116 EXPECT_TRUE(controller->IsPotentiallyAnimatingProperty( | |
| 3117 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3118 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3119 TargetProperty::OPACITY, | |
| 3120 LayerAnimationController::ObserverType::PENDING)); | |
| 3121 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3122 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3123 EXPECT_TRUE(controller->HasActiveAnimation()); | |
| 3124 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty( | |
| 3125 TargetProperty::FILTER, LayerAnimationController::ObserverType::PENDING)); | |
| 3126 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty( | |
| 3127 TargetProperty::FILTER, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3128 | |
| 3129 controller->UpdateState(true, nullptr); | |
| 3130 | |
| 3131 // Tick past the start delay. | |
| 3132 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | |
| 3133 controller->UpdateState(true, nullptr); | |
| 3134 EXPECT_TRUE(controller->IsPotentiallyAnimatingProperty( | |
| 3135 TargetProperty::OPACITY, | |
| 3136 LayerAnimationController::ObserverType::PENDING)); | |
| 3137 EXPECT_TRUE(controller->IsPotentiallyAnimatingProperty( | |
| 3138 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3139 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | |
| 3140 TargetProperty::OPACITY, | |
| 3141 LayerAnimationController::ObserverType::PENDING)); | |
| 3142 EXPECT_TRUE(controller->IsCurrentlyAnimatingProperty( | |
| 3143 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3144 | |
| 3145 // After the animaton finishes, the observers it affects have neither a | |
| 3146 // potentially running transform animation nor a currently running transform | |
| 3147 // animation. | |
| 3148 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); | |
| 3149 controller->UpdateState(true, nullptr); | |
| 3150 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty( | |
| 3151 TargetProperty::OPACITY, | |
| 3152 LayerAnimationController::ObserverType::PENDING)); | |
| 3153 EXPECT_FALSE(controller->IsPotentiallyAnimatingProperty( | |
| 3154 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3155 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3156 TargetProperty::OPACITY, | |
| 3157 LayerAnimationController::ObserverType::PENDING)); | |
| 3158 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | |
| 3159 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | |
| 3160 } | |
| 3161 | |
| 3162 } // namespace | |
| 3163 } // namespace cc | |
| OLD | NEW |