Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: cc/animation/element_animations_unittest.cc

Issue 2538973002: CC Animation: Make AnimationPlayer to be a unit of activation. (Closed)
Patch Set: Move ScrollOffsetAnimationWasInterrupted to AnimationPlayer Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/animation/element_animations.h" 5 #include "cc/animation/element_animations.h"
6 6
7 #include "cc/animation/animation_delegate.h" 7 #include "cc/animation/animation_delegate.h"
8 #include "cc/animation/animation_events.h" 8 #include "cc/animation/animation_events.h"
9 #include "cc/animation/animation_host.h" 9 #include "cc/animation/animation_host.h"
10 #include "cc/animation/animation_id_provider.h" 10 #include "cc/animation/animation_id_provider.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 325
326 PushProperties(); 326 PushProperties();
327 327
328 scoped_refptr<AnimationPlayer> player2_impl = 328 scoped_refptr<AnimationPlayer> player2_impl =
329 timeline_impl_->GetPlayerById(player2_id); 329 timeline_impl_->GetPlayerById(player2_id);
330 DCHECK(player2_impl); 330 DCHECK(player2_impl);
331 331
332 player2_impl->ActivateAnimations(); 332 player2_impl->ActivateAnimations();
333 EXPECT_TRUE(player2_impl->GetAnimationById(animation_id)); 333 EXPECT_TRUE(player2_impl->GetAnimationById(animation_id));
334 334
335 scoped_refptr<ElementAnimations> element_animations_impl = 335 player2_impl->Animate(kInitialTickTime);
336 player2_impl->element_animations();
337
338 element_animations_impl_->Animate(kInitialTickTime);
339 336
340 auto events = CreateEventsForTesting(); 337 auto events = CreateEventsForTesting();
341 element_animations_impl_->UpdateState(true, events.get()); 338 player2_impl->UpdateState(true, events.get());
342 EXPECT_EQ(1u, events->events_.size()); 339 EXPECT_EQ(1u, events->events_.size());
343 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); 340 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
344 341
345 // The actual detachment happens here, inside the callback 342 // The actual detachment happens here, inside the callback
346 player2->NotifyAnimationStarted(events->events_[0]); 343 player2->NotifyAnimationStarted(events->events_[0]);
347 EXPECT_TRUE(delegate.started()); 344 EXPECT_TRUE(delegate.started());
348 } 345 }
349 346
350 // If an animation is started on the impl thread before it is ticked on the main 347 // If an animation is started on the impl thread before it is ticked on the main
351 // thread, we must be sure to respect the synchronized start time. 348 // thread, we must be sure to respect the synchronized start time.
352 TEST_F(ElementAnimationsTest, DoNotClobberStartTimes) { 349 TEST_F(ElementAnimationsTest, DoNotClobberStartTimes) {
353 CreateTestLayer(true, false); 350 CreateTestLayer(true, false);
354 AttachTimelinePlayerLayer(); 351 AttachTimelinePlayerLayer();
355 CreateImplTimelineAndPlayer(); 352 CreateImplTimelineAndPlayer();
356 353
357 EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::OPACITY)); 354 EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::OPACITY));
358 355
359 int animation_id = 356 int animation_id =
360 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); 357 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false);
361 358
362 PushProperties(); 359 PushProperties();
363 player_impl_->ActivateAnimations(); 360 player_impl_->ActivateAnimations();
364 361
365 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); 362 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
366 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 363 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
367 player_impl_->GetAnimationById(animation_id)->run_state()); 364 player_impl_->GetAnimationById(animation_id)->run_state());
368 365
369 auto events = CreateEventsForTesting(); 366 auto events = CreateEventsForTesting();
370 element_animations_impl_->Animate(kInitialTickTime); 367 player_impl_->Animate(kInitialTickTime);
371 element_animations_impl_->UpdateState(true, events.get()); 368 player_impl_->UpdateState(true, events.get());
372 369
373 // Synchronize the start times. 370 // Synchronize the start times.
374 EXPECT_EQ(1u, events->events_.size()); 371 EXPECT_EQ(1u, events->events_.size());
375 player_->NotifyAnimationStarted(events->events_[0]); 372 player_->NotifyAnimationStarted(events->events_[0]);
376 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(), 373 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(),
377 player_impl_->GetAnimationById(animation_id)->start_time()); 374 player_impl_->GetAnimationById(animation_id)->start_time());
378 375
379 // Start the animation on the main thread. Should not affect the start time. 376 // Start the animation on the main thread. Should not affect the start time.
380 element_animations_->Animate(kInitialTickTime + 377 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
381 TimeDelta::FromMilliseconds(500)); 378 player_impl_->UpdateState(true, nullptr);
382 element_animations_->UpdateState(true, nullptr);
383 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(), 379 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(),
384 player_impl_->GetAnimationById(animation_id)->start_time()); 380 player_impl_->GetAnimationById(animation_id)->start_time());
385 } 381 }
386 382
387 TEST_F(ElementAnimationsTest, UseSpecifiedStartTimes) { 383 TEST_F(ElementAnimationsTest, UseSpecifiedStartTimes) {
388 CreateTestLayer(true, false); 384 CreateTestLayer(true, false);
389 AttachTimelinePlayerLayer(); 385 AttachTimelinePlayerLayer();
390 CreateImplTimelineAndPlayer(); 386 CreateImplTimelineAndPlayer();
391 387
392 int animation_id = 388 int animation_id =
393 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); 389 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false);
394 390
395 const TimeTicks start_time = TicksFromSecondsF(123); 391 const TimeTicks start_time = TicksFromSecondsF(123);
396 player_->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); 392 player_->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time);
397 393
398 PushProperties(); 394 PushProperties();
399 player_impl_->ActivateAnimations(); 395 player_impl_->ActivateAnimations();
400 396
401 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); 397 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
402 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 398 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
403 player_impl_->GetAnimationById(animation_id)->run_state()); 399 player_impl_->GetAnimationById(animation_id)->run_state());
404 400
405 auto events = CreateEventsForTesting(); 401 auto events = CreateEventsForTesting();
406 element_animations_impl_->Animate(kInitialTickTime); 402 player_impl_->Animate(kInitialTickTime);
407 element_animations_impl_->UpdateState(true, events.get()); 403 player_impl_->UpdateState(true, events.get());
408 404
409 // Synchronize the start times. 405 // Synchronize the start times.
410 EXPECT_EQ(1u, events->events_.size()); 406 EXPECT_EQ(1u, events->events_.size());
411 player_->NotifyAnimationStarted(events->events_[0]); 407 player_->NotifyAnimationStarted(events->events_[0]);
412 408
413 EXPECT_EQ(start_time, player_->GetAnimationById(animation_id)->start_time()); 409 EXPECT_EQ(start_time, player_->GetAnimationById(animation_id)->start_time());
414 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(), 410 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(),
415 player_impl_->GetAnimationById(animation_id)->start_time()); 411 player_impl_->GetAnimationById(animation_id)->start_time());
416 412
417 // Start the animation on the main thread. Should not affect the start time. 413 // Start the animation on the main thread. Should not affect the start time.
418 element_animations_->Animate(kInitialTickTime + 414 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
419 TimeDelta::FromMilliseconds(500)); 415 player_->UpdateState(true, nullptr);
420 element_animations_->UpdateState(true, nullptr);
421 EXPECT_EQ(start_time, player_->GetAnimationById(animation_id)->start_time()); 416 EXPECT_EQ(start_time, player_->GetAnimationById(animation_id)->start_time());
422 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(), 417 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(),
423 player_impl_->GetAnimationById(animation_id)->start_time()); 418 player_impl_->GetAnimationById(animation_id)->start_time());
424 } 419 }
425 420
426 // Tests that animationss activate and deactivate as expected. 421 // Tests that animationss activate and deactivate as expected.
427 TEST_F(ElementAnimationsTest, Activation) { 422 TEST_F(ElementAnimationsTest, Activation) {
428 CreateTestLayer(true, false); 423 CreateTestLayer(true, false);
429 AttachTimelinePlayerLayer(); 424 AttachTimelinePlayerLayer();
430 CreateImplTimelineAndPlayer(); 425 CreateImplTimelineAndPlayer();
431 426
432 AnimationHost* host = client_.host(); 427 AnimationHost* host = client_.host();
433 AnimationHost* host_impl = client_impl_.host(); 428 AnimationHost* host_impl = client_impl_.host();
434 429
435 auto events = CreateEventsForTesting(); 430 auto events = CreateEventsForTesting();
436 431
437 EXPECT_EQ(1u, host->all_element_animations_for_testing().size()); 432 EXPECT_EQ(1u, host->all_element_animations_for_testing().size());
438 EXPECT_EQ(1u, host_impl->all_element_animations_for_testing().size()); 433 EXPECT_EQ(1u, host_impl->all_element_animations_for_testing().size());
439 434
440 // Initially, both animationss should be inactive. 435 // Initially, both animationss should be inactive.
441 EXPECT_EQ(0u, host->active_element_animations_for_testing().size()); 436 EXPECT_EQ(0u, host->active_players_for_testing().size());
442 EXPECT_EQ(0u, host_impl->active_element_animations_for_testing().size()); 437 EXPECT_EQ(0u, host_impl->active_players_for_testing().size());
443 438
444 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); 439 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false);
445 // The main thread animations should now be active. 440 // The main thread animations should now be active.
446 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); 441 EXPECT_EQ(1u, host->active_players_for_testing().size());
447 442
448 PushProperties(); 443 PushProperties();
449 player_impl_->ActivateAnimations(); 444 player_impl_->ActivateAnimations();
450 // Both animationss should now be active. 445 // Both animationss should now be active.
451 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); 446 EXPECT_EQ(1u, host->active_players_for_testing().size());
452 EXPECT_EQ(1u, host_impl->active_element_animations_for_testing().size()); 447 EXPECT_EQ(1u, host_impl->active_players_for_testing().size());
453 448
454 element_animations_impl_->Animate(kInitialTickTime); 449 player_impl_->Animate(kInitialTickTime);
455 element_animations_impl_->UpdateState(true, events.get()); 450 player_impl_->UpdateState(true, events.get());
456 EXPECT_EQ(1u, events->events_.size()); 451 EXPECT_EQ(1u, events->events_.size());
457 player_->NotifyAnimationStarted(events->events_[0]); 452 player_->NotifyAnimationStarted(events->events_[0]);
458 453
459 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); 454 EXPECT_EQ(1u, host->active_players_for_testing().size());
460 EXPECT_EQ(1u, host_impl->active_element_animations_for_testing().size()); 455 EXPECT_EQ(1u, host_impl->active_players_for_testing().size());
461 456
462 element_animations_->Animate(kInitialTickTime + 457 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
463 TimeDelta::FromMilliseconds(500)); 458 player_->UpdateState(true, nullptr);
464 element_animations_->UpdateState(true, nullptr); 459 EXPECT_EQ(1u, host->active_players_for_testing().size());
465 EXPECT_EQ(1u, host->active_element_animations_for_testing().size());
466 460
467 element_animations_->Animate(kInitialTickTime + 461 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
468 TimeDelta::FromMilliseconds(1000)); 462 player_->UpdateState(true, nullptr);
469 element_animations_->UpdateState(true, nullptr);
470 EXPECT_EQ(Animation::FINISHED, 463 EXPECT_EQ(Animation::FINISHED,
471 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); 464 player_->GetAnimation(TargetProperty::OPACITY)->run_state());
472 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); 465 EXPECT_EQ(1u, host->active_players_for_testing().size());
473 466
474 events = CreateEventsForTesting(); 467 events = CreateEventsForTesting();
475 468
476 element_animations_impl_->Animate(kInitialTickTime + 469 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500));
477 TimeDelta::FromMilliseconds(1500)); 470 player_impl_->UpdateState(true, events.get());
478 element_animations_impl_->UpdateState(true, events.get());
479 471
480 EXPECT_EQ(Animation::WAITING_FOR_DELETION, 472 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
481 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); 473 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state());
482 // The impl thread animations should have de-activated. 474 // The impl thread animations should have de-activated.
483 EXPECT_EQ(0u, host_impl->active_element_animations_for_testing().size()); 475 EXPECT_EQ(0u, host_impl->active_players_for_testing().size());
484 476
485 EXPECT_EQ(1u, events->events_.size()); 477 EXPECT_EQ(1u, events->events_.size());
486 player_->NotifyAnimationFinished(events->events_[0]); 478 player_->NotifyAnimationFinished(events->events_[0]);
487 element_animations_->Animate(kInitialTickTime + 479 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500));
488 TimeDelta::FromMilliseconds(1500)); 480 player_->UpdateState(true, nullptr);
489 element_animations_->UpdateState(true, nullptr);
490 481
491 EXPECT_EQ(Animation::WAITING_FOR_DELETION, 482 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
492 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); 483 player_->GetAnimation(TargetProperty::OPACITY)->run_state());
493 // The main thread animations should have de-activated. 484 // The main thread animations should have de-activated.
494 EXPECT_EQ(0u, host->active_element_animations_for_testing().size()); 485 EXPECT_EQ(0u, host->active_players_for_testing().size());
495 486
496 PushProperties(); 487 PushProperties();
497 player_impl_->ActivateAnimations(); 488 player_impl_->ActivateAnimations();
498 EXPECT_FALSE(player_->has_any_animation()); 489 EXPECT_FALSE(player_->has_any_animation());
499 EXPECT_FALSE(player_impl_->has_any_animation()); 490 EXPECT_FALSE(player_impl_->has_any_animation());
500 EXPECT_EQ(0u, host->active_element_animations_for_testing().size()); 491 EXPECT_EQ(0u, host->active_players_for_testing().size());
501 EXPECT_EQ(0u, host_impl->active_element_animations_for_testing().size()); 492 EXPECT_EQ(0u, host_impl->active_players_for_testing().size());
502 } 493 }
503 494
504 TEST_F(ElementAnimationsTest, SyncPause) { 495 TEST_F(ElementAnimationsTest, SyncPause) {
505 CreateTestLayer(true, false); 496 CreateTestLayer(true, false);
506 AttachTimelinePlayerLayer(); 497 AttachTimelinePlayerLayer();
507 CreateImplTimelineAndPlayer(); 498 CreateImplTimelineAndPlayer();
508 499
509 EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::OPACITY)); 500 EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::OPACITY));
510 501
511 // Two steps, three ranges: [0-1) -> 0.2, [1-2) -> 0.3, [2-3] -> 0.4. 502 // Two steps, three ranges: [0-1) -> 0.2, [1-2) -> 0.3, [2-3] -> 0.4.
512 const double duration = 3.0; 503 const double duration = 3.0;
513 const int animation_id = 504 const int animation_id =
514 AddOpacityStepsToPlayer(player_.get(), duration, 0.2f, 0.4f, 2); 505 AddOpacityStepsToPlayer(player_.get(), duration, 0.2f, 0.4f, 2);
515 506
516 // Set start offset to be at the beginning of the second range. 507 // Set start offset to be at the beginning of the second range.
517 player_->GetAnimationById(animation_id) 508 player_->GetAnimationById(animation_id)
518 ->set_time_offset(TimeDelta::FromSecondsD(1.01)); 509 ->set_time_offset(TimeDelta::FromSecondsD(1.01));
519 510
520 PushProperties(); 511 PushProperties();
521 player_impl_->ActivateAnimations(); 512 player_impl_->ActivateAnimations();
522 513
523 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); 514 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
524 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 515 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
525 player_impl_->GetAnimationById(animation_id)->run_state()); 516 player_impl_->GetAnimationById(animation_id)->run_state());
526 517
527 TimeTicks time = kInitialTickTime; 518 TimeTicks time = kInitialTickTime;
528 519
529 // Start the animations on each animations. 520 // Start the animations on each animations.
530 auto events = CreateEventsForTesting(); 521 auto events = CreateEventsForTesting();
531 element_animations_impl_->Animate(time); 522 player_impl_->Animate(time);
532 element_animations_impl_->UpdateState(true, events.get()); 523 player_impl_->UpdateState(true, events.get());
533 EXPECT_EQ(1u, events->events_.size()); 524 EXPECT_EQ(1u, events->events_.size());
534 525
535 element_animations_->Animate(time); 526 player_->Animate(time);
536 element_animations_->UpdateState(true, nullptr); 527 player_->UpdateState(true, nullptr);
537 player_->NotifyAnimationStarted(events->events_[0]); 528 player_->NotifyAnimationStarted(events->events_[0]);
538 529
539 EXPECT_EQ(Animation::RUNNING, 530 EXPECT_EQ(Animation::RUNNING,
540 player_impl_->GetAnimationById(animation_id)->run_state()); 531 player_impl_->GetAnimationById(animation_id)->run_state());
541 EXPECT_EQ(Animation::RUNNING, 532 EXPECT_EQ(Animation::RUNNING,
542 player_->GetAnimationById(animation_id)->run_state()); 533 player_->GetAnimationById(animation_id)->run_state());
543 534
544 EXPECT_EQ(0.3f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 535 EXPECT_EQ(0.3f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
545 EXPECT_EQ(0.3f, 536 EXPECT_EQ(0.3f,
546 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 537 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
547 538
548 EXPECT_EQ(kInitialTickTime, 539 EXPECT_EQ(kInitialTickTime,
549 player_->GetAnimationById(animation_id)->start_time()); 540 player_->GetAnimationById(animation_id)->start_time());
550 EXPECT_EQ(kInitialTickTime, 541 EXPECT_EQ(kInitialTickTime,
551 player_impl_->GetAnimationById(animation_id)->start_time()); 542 player_impl_->GetAnimationById(animation_id)->start_time());
552 543
553 // Pause the animation at the middle of the second range so the offset 544 // Pause the animation at the middle of the second range so the offset
554 // delays animation until the middle of the third range. 545 // delays animation until the middle of the third range.
555 player_->PauseAnimation(animation_id, 1.5); 546 player_->PauseAnimation(animation_id, 1.5);
556 EXPECT_EQ(Animation::PAUSED, 547 EXPECT_EQ(Animation::PAUSED,
557 player_->GetAnimationById(animation_id)->run_state()); 548 player_->GetAnimationById(animation_id)->run_state());
558 549
559 // The pause run state change should make it to the impl thread animations. 550 // The pause run state change should make it to the impl thread animations.
560 PushProperties(); 551 PushProperties();
561 player_impl_->ActivateAnimations(); 552 player_impl_->ActivateAnimations();
562 553
563 // Advance time so it stays within the first range. 554 // Advance time so it stays within the first range.
564 time += TimeDelta::FromMilliseconds(10); 555 time += TimeDelta::FromMilliseconds(10);
565 element_animations_->Animate(time); 556 player_->Animate(time);
566 element_animations_impl_->Animate(time); 557 player_impl_->Animate(time);
567 558
568 EXPECT_EQ(Animation::PAUSED, 559 EXPECT_EQ(Animation::PAUSED,
569 player_impl_->GetAnimationById(animation_id)->run_state()); 560 player_impl_->GetAnimationById(animation_id)->run_state());
570 561
571 // Opacity value doesn't depend on time if paused at specified time offset. 562 // Opacity value doesn't depend on time if paused at specified time offset.
572 EXPECT_EQ(0.4f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 563 EXPECT_EQ(0.4f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
573 EXPECT_EQ(0.4f, 564 EXPECT_EQ(0.4f,
574 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 565 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
575 } 566 }
576 567
(...skipping 10 matching lines...) Expand all
587 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); 578 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false);
588 579
589 PushProperties(); 580 PushProperties();
590 player_impl_->ActivateAnimations(); 581 player_impl_->ActivateAnimations();
591 582
592 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); 583 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
593 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 584 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
594 player_impl_->GetAnimationById(animation_id)->run_state()); 585 player_impl_->GetAnimationById(animation_id)->run_state());
595 586
596 events = CreateEventsForTesting(); 587 events = CreateEventsForTesting();
597 element_animations_impl_->Animate(kInitialTickTime); 588 player_impl_->Animate(kInitialTickTime);
598 element_animations_impl_->UpdateState(true, events.get()); 589 player_impl_->UpdateState(true, events.get());
599 EXPECT_EQ(1u, events->events_.size()); 590 EXPECT_EQ(1u, events->events_.size());
600 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); 591 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
601 592
602 // Notify main thread animations that the animation has started. 593 // Notify main thread animations that the animation has started.
603 player_->NotifyAnimationStarted(events->events_[0]); 594 player_->NotifyAnimationStarted(events->events_[0]);
604 595
605 // Complete animation on impl thread. 596 // Complete animation on impl thread.
606 events = CreateEventsForTesting(); 597 events = CreateEventsForTesting();
607 element_animations_impl_->Animate(kInitialTickTime + 598 player_impl_->Animate(kInitialTickTime + TimeDelta::FromSeconds(1));
608 TimeDelta::FromSeconds(1)); 599 player_impl_->UpdateState(true, events.get());
609 element_animations_impl_->UpdateState(true, events.get());
610 EXPECT_EQ(1u, events->events_.size()); 600 EXPECT_EQ(1u, events->events_.size());
611 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); 601 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type);
612 602
613 player_->NotifyAnimationFinished(events->events_[0]); 603 player_->NotifyAnimationFinished(events->events_[0]);
614 604
615 element_animations_->Animate(kInitialTickTime + TimeDelta::FromSeconds(2)); 605 player_->Animate(kInitialTickTime + TimeDelta::FromSeconds(2));
616 element_animations_->UpdateState(true, nullptr); 606 player_->UpdateState(true, nullptr);
617 607
618 PushProperties(); 608 PushProperties();
619 player_impl_->ActivateAnimations(); 609 player_impl_->ActivateAnimations();
620 EXPECT_FALSE(player_->GetAnimationById(animation_id)); 610 EXPECT_FALSE(player_->GetAnimationById(animation_id));
621 EXPECT_FALSE(player_impl_->GetAnimationById(animation_id)); 611 EXPECT_FALSE(player_impl_->GetAnimationById(animation_id));
622 } 612 }
623 613
624 // Ensure that a finished animation is eventually deleted by both the 614 // Ensure that a finished animation is eventually deleted by both the
625 // main-thread and the impl-thread animationss. 615 // main-thread and the impl-thread animationss.
626 TEST_F(ElementAnimationsTest, AnimationsAreDeleted) { 616 TEST_F(ElementAnimationsTest, AnimationsAreDeleted) {
627 CreateTestLayer(true, false); 617 CreateTestLayer(true, false);
628 AttachTimelinePlayerLayer(); 618 AttachTimelinePlayerLayer();
629 CreateImplTimelineAndPlayer(); 619 CreateImplTimelineAndPlayer();
630 620
631 auto events = CreateEventsForTesting(); 621 auto events = CreateEventsForTesting();
632 622
633 AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.0f, 1.0f, false); 623 AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.0f, 1.0f, false);
634 element_animations_->Animate(kInitialTickTime); 624 player_->Animate(kInitialTickTime);
635 element_animations_->UpdateState(true, nullptr); 625 player_->UpdateState(true, nullptr);
636 EXPECT_TRUE(player_->needs_push_properties()); 626 EXPECT_TRUE(player_->needs_push_properties());
637 627
638 PushProperties(); 628 PushProperties();
639 EXPECT_FALSE(player_->needs_push_properties()); 629 EXPECT_FALSE(player_->needs_push_properties());
640 630
641 EXPECT_FALSE(host_->needs_push_properties()); 631 EXPECT_FALSE(host_->needs_push_properties());
642 EXPECT_FALSE(host_impl_->needs_push_properties()); 632 EXPECT_FALSE(host_impl_->needs_push_properties());
643 633
644 player_impl_->ActivateAnimations(); 634 player_impl_->ActivateAnimations();
645 635
646 element_animations_impl_->Animate(kInitialTickTime + 636 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
647 TimeDelta::FromMilliseconds(500)); 637 player_impl_->UpdateState(true, events.get());
648 element_animations_impl_->UpdateState(true, events.get());
649 638
650 // There should be a STARTED event for the animation. 639 // There should be a STARTED event for the animation.
651 EXPECT_EQ(1u, events->events_.size()); 640 EXPECT_EQ(1u, events->events_.size());
652 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); 641 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
653 player_->NotifyAnimationStarted(events->events_[0]); 642 player_->NotifyAnimationStarted(events->events_[0]);
654 643
655 element_animations_->Animate(kInitialTickTime + 644 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
656 TimeDelta::FromMilliseconds(1000)); 645 player_->UpdateState(true, nullptr);
657 element_animations_->UpdateState(true, nullptr);
658 646
659 EXPECT_FALSE(host_->needs_push_properties()); 647 EXPECT_FALSE(host_->needs_push_properties());
660 EXPECT_FALSE(host_impl_->needs_push_properties()); 648 EXPECT_FALSE(host_impl_->needs_push_properties());
661 649
662 events = CreateEventsForTesting(); 650 events = CreateEventsForTesting();
663 element_animations_impl_->Animate(kInitialTickTime + 651 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
664 TimeDelta::FromMilliseconds(2000)); 652 player_impl_->UpdateState(true, events.get());
665 element_animations_impl_->UpdateState(true, events.get());
666 653
667 EXPECT_TRUE(host_impl_->needs_push_properties()); 654 EXPECT_TRUE(host_impl_->needs_push_properties());
668 655
669 // There should be a FINISHED event for the animation. 656 // There should be a FINISHED event for the animation.
670 EXPECT_EQ(1u, events->events_.size()); 657 EXPECT_EQ(1u, events->events_.size());
671 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); 658 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type);
672 659
673 // Neither animations should have deleted the animation yet. 660 // Neither animations should have deleted the animation yet.
674 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY)); 661 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY));
675 EXPECT_TRUE(player_impl_->GetAnimation(TargetProperty::OPACITY)); 662 EXPECT_TRUE(player_impl_->GetAnimation(TargetProperty::OPACITY));
676 663
677 player_->NotifyAnimationFinished(events->events_[0]); 664 player_->NotifyAnimationFinished(events->events_[0]);
678 665
679 element_animations_->Animate(kInitialTickTime + 666 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
680 TimeDelta::FromMilliseconds(3000)); 667 player_->UpdateState(true, nullptr);
681 element_animations_->UpdateState(true, nullptr);
682 EXPECT_TRUE(host_->needs_push_properties()); 668 EXPECT_TRUE(host_->needs_push_properties());
683 669
684 PushProperties(); 670 PushProperties();
685 671
686 // Both animationss should now have deleted the animation. The impl animations 672 // Both animationss should now have deleted the animation. The impl animations
687 // should have deleted the animation even though activation has not occurred, 673 // should have deleted the animation even though activation has not occurred,
688 // since the animation was already waiting for deletion when 674 // since the animation was already waiting for deletion when
689 // PushPropertiesTo was called. 675 // PushPropertiesTo was called.
690 EXPECT_FALSE(player_->has_any_animation()); 676 EXPECT_FALSE(player_->has_any_animation());
691 EXPECT_FALSE(player_impl_->has_any_animation()); 677 EXPECT_FALSE(player_impl_->has_any_animation());
(...skipping 24 matching lines...) Expand all
716 702
717 auto events = CreateEventsForTesting(); 703 auto events = CreateEventsForTesting();
718 704
719 std::unique_ptr<Animation> to_add(CreateAnimation( 705 std::unique_ptr<Animation> to_add(CreateAnimation(
720 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 706 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
721 1, TargetProperty::OPACITY)); 707 1, TargetProperty::OPACITY));
722 708
723 EXPECT_FALSE(player_->needs_to_start_animations()); 709 EXPECT_FALSE(player_->needs_to_start_animations());
724 player_->AddAnimation(std::move(to_add)); 710 player_->AddAnimation(std::move(to_add));
725 EXPECT_TRUE(player_->needs_to_start_animations()); 711 EXPECT_TRUE(player_->needs_to_start_animations());
726 element_animations_->Animate(kInitialTickTime); 712 player_->Animate(kInitialTickTime);
727 EXPECT_FALSE(player_->needs_to_start_animations()); 713 EXPECT_FALSE(player_->needs_to_start_animations());
728 element_animations_->UpdateState(true, events.get()); 714 player_->UpdateState(true, events.get());
729 EXPECT_TRUE(player_->HasActiveAnimation()); 715 EXPECT_TRUE(player_->HasActiveAnimation());
730 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 716 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
731 // A non-impl-only animation should not generate property updates. 717 // A non-impl-only animation should not generate property updates.
732 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 718 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
733 EXPECT_FALSE(event); 719 EXPECT_FALSE(event);
734 element_animations_->Animate(kInitialTickTime + 720 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
735 TimeDelta::FromMilliseconds(1000)); 721 player_->UpdateState(true, events.get());
736 element_animations_->UpdateState(true, events.get());
737 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 722 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
738 EXPECT_FALSE(player_->HasActiveAnimation()); 723 EXPECT_FALSE(player_->HasActiveAnimation());
739 event = GetMostRecentPropertyUpdateEvent(events.get()); 724 event = GetMostRecentPropertyUpdateEvent(events.get());
740 EXPECT_FALSE(event); 725 EXPECT_FALSE(event);
741 } 726 }
742 727
743 TEST_F(ElementAnimationsTest, FilterTransition) { 728 TEST_F(ElementAnimationsTest, FilterTransition) {
744 CreateTestLayer(true, false); 729 CreateTestLayer(true, false);
745 AttachTimelinePlayerLayer(); 730 AttachTimelinePlayerLayer();
746 731
747 auto events = CreateEventsForTesting(); 732 auto events = CreateEventsForTesting();
748 733
749 std::unique_ptr<KeyframedFilterAnimationCurve> curve( 734 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
750 KeyframedFilterAnimationCurve::Create()); 735 KeyframedFilterAnimationCurve::Create());
751 736
752 FilterOperations start_filters; 737 FilterOperations start_filters;
753 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); 738 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f));
754 curve->AddKeyframe( 739 curve->AddKeyframe(
755 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); 740 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
756 FilterOperations end_filters; 741 FilterOperations end_filters;
757 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); 742 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
758 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 743 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
759 end_filters, nullptr)); 744 end_filters, nullptr));
760 745
761 std::unique_ptr<Animation> animation( 746 std::unique_ptr<Animation> animation(
762 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); 747 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER));
763 player_->AddAnimation(std::move(animation)); 748 player_->AddAnimation(std::move(animation));
764 749
765 element_animations_->Animate(kInitialTickTime); 750 player_->Animate(kInitialTickTime);
766 element_animations_->UpdateState(true, events.get()); 751 player_->UpdateState(true, events.get());
767 EXPECT_TRUE(player_->HasActiveAnimation()); 752 EXPECT_TRUE(player_->HasActiveAnimation());
768 EXPECT_EQ(start_filters, 753 EXPECT_EQ(start_filters,
769 client_.GetFilters(element_id_, ElementListType::ACTIVE)); 754 client_.GetFilters(element_id_, ElementListType::ACTIVE));
770 // A non-impl-only animation should not generate property updates. 755 // A non-impl-only animation should not generate property updates.
771 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 756 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
772 EXPECT_FALSE(event); 757 EXPECT_FALSE(event);
773 758
774 element_animations_->Animate(kInitialTickTime + 759 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
775 TimeDelta::FromMilliseconds(500)); 760 player_->UpdateState(true, events.get());
776 element_animations_->UpdateState(true, events.get());
777 EXPECT_EQ(1u, 761 EXPECT_EQ(1u,
778 client_.GetFilters(element_id_, ElementListType::ACTIVE).size()); 762 client_.GetFilters(element_id_, ElementListType::ACTIVE).size());
779 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), 763 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f),
780 client_.GetFilters(element_id_, ElementListType::ACTIVE).at(0)); 764 client_.GetFilters(element_id_, ElementListType::ACTIVE).at(0));
781 event = GetMostRecentPropertyUpdateEvent(events.get()); 765 event = GetMostRecentPropertyUpdateEvent(events.get());
782 EXPECT_FALSE(event); 766 EXPECT_FALSE(event);
783 767
784 element_animations_->Animate(kInitialTickTime + 768 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
785 TimeDelta::FromMilliseconds(1000)); 769 player_->UpdateState(true, events.get());
786 element_animations_->UpdateState(true, events.get());
787 EXPECT_EQ(end_filters, 770 EXPECT_EQ(end_filters,
788 client_.GetFilters(element_id_, ElementListType::ACTIVE)); 771 client_.GetFilters(element_id_, ElementListType::ACTIVE));
789 EXPECT_FALSE(player_->HasActiveAnimation()); 772 EXPECT_FALSE(player_->HasActiveAnimation());
790 event = GetMostRecentPropertyUpdateEvent(events.get()); 773 event = GetMostRecentPropertyUpdateEvent(events.get());
791 EXPECT_FALSE(event); 774 EXPECT_FALSE(event);
792 } 775 }
793 776
794 TEST_F(ElementAnimationsTest, ScrollOffsetTransition) { 777 TEST_F(ElementAnimationsTest, ScrollOffsetTransition) {
795 CreateTestLayer(true, false); 778 CreateTestLayer(true, false);
796 AttachTimelinePlayerLayer(); 779 AttachTimelinePlayerLayer();
(...skipping 17 matching lines...) Expand all
814 PushProperties(); 797 PushProperties();
815 player_impl_->ActivateAnimations(); 798 player_impl_->ActivateAnimations();
816 EXPECT_TRUE(player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)); 799 EXPECT_TRUE(player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET));
817 TimeDelta duration = player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET) 800 TimeDelta duration = player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)
818 ->curve() 801 ->curve()
819 ->Duration(); 802 ->Duration();
820 EXPECT_EQ(duration, player_->GetAnimation(TargetProperty::SCROLL_OFFSET) 803 EXPECT_EQ(duration, player_->GetAnimation(TargetProperty::SCROLL_OFFSET)
821 ->curve() 804 ->curve()
822 ->Duration()); 805 ->Duration());
823 806
824 element_animations_->Animate(kInitialTickTime); 807 player_->Animate(kInitialTickTime);
825 element_animations_->UpdateState(true, nullptr); 808 player_->UpdateState(true, nullptr);
826 EXPECT_TRUE(player_->HasActiveAnimation()); 809 EXPECT_TRUE(player_->HasActiveAnimation());
827 EXPECT_EQ(initial_value, 810 EXPECT_EQ(initial_value,
828 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); 811 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
829 812
830 element_animations_impl_->Animate(kInitialTickTime); 813 player_impl_->Animate(kInitialTickTime);
831 element_animations_impl_->UpdateState(true, events.get()); 814 player_impl_->UpdateState(true, events.get());
832 EXPECT_TRUE(player_impl_->HasActiveAnimation()); 815 EXPECT_TRUE(player_impl_->HasActiveAnimation());
833 EXPECT_EQ(initial_value, 816 EXPECT_EQ(initial_value,
834 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); 817 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
835 // Scroll offset animations should not generate property updates. 818 // Scroll offset animations should not generate property updates.
836 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 819 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
837 EXPECT_FALSE(event); 820 EXPECT_FALSE(event);
838 821
839 player_->NotifyAnimationStarted(events->events_[0]); 822 player_->NotifyAnimationStarted(events->events_[0]);
840 element_animations_->Animate(kInitialTickTime + duration / 2); 823 player_->Animate(kInitialTickTime + duration / 2);
841 element_animations_->UpdateState(true, nullptr); 824 player_->UpdateState(true, nullptr);
842 EXPECT_TRUE(player_->HasActiveAnimation()); 825 EXPECT_TRUE(player_->HasActiveAnimation());
843 EXPECT_VECTOR2DF_EQ( 826 EXPECT_VECTOR2DF_EQ(
844 gfx::Vector2dF(200.f, 250.f), 827 gfx::Vector2dF(200.f, 250.f),
845 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); 828 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
846 829
847 element_animations_impl_->Animate(kInitialTickTime + duration / 2); 830 player_impl_->Animate(kInitialTickTime + duration / 2);
848 element_animations_impl_->UpdateState(true, events.get()); 831 player_impl_->UpdateState(true, events.get());
849 EXPECT_VECTOR2DF_EQ( 832 EXPECT_VECTOR2DF_EQ(
850 gfx::Vector2dF(200.f, 250.f), 833 gfx::Vector2dF(200.f, 250.f),
851 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); 834 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
852 event = GetMostRecentPropertyUpdateEvent(events.get()); 835 event = GetMostRecentPropertyUpdateEvent(events.get());
853 EXPECT_FALSE(event); 836 EXPECT_FALSE(event);
854 837
855 element_animations_impl_->Animate(kInitialTickTime + duration); 838 player_impl_->Animate(kInitialTickTime + duration);
856 element_animations_impl_->UpdateState(true, events.get()); 839 player_impl_->UpdateState(true, events.get());
857 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( 840 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset(
858 element_id_, ElementListType::ACTIVE)); 841 element_id_, ElementListType::ACTIVE));
859 EXPECT_FALSE(player_impl_->HasActiveAnimation()); 842 EXPECT_FALSE(player_impl_->HasActiveAnimation());
860 event = GetMostRecentPropertyUpdateEvent(events.get()); 843 event = GetMostRecentPropertyUpdateEvent(events.get());
861 EXPECT_FALSE(event); 844 EXPECT_FALSE(event);
862 845
863 element_animations_->Animate(kInitialTickTime + duration); 846 player_->Animate(kInitialTickTime + duration);
864 element_animations_->UpdateState(true, nullptr); 847 player_->UpdateState(true, nullptr);
865 EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset( 848 EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset(
866 element_id_, ElementListType::ACTIVE)); 849 element_id_, ElementListType::ACTIVE));
867 EXPECT_FALSE(player_->HasActiveAnimation()); 850 EXPECT_FALSE(player_->HasActiveAnimation());
868 } 851 }
869 852
870 TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) { 853 TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) {
871 CreateTestLayer(true, false); 854 CreateTestLayer(true, false);
872 AttachTimelinePlayerLayer(); 855 AttachTimelinePlayerLayer();
873 CreateImplTimelineAndPlayer(); 856 CreateImplTimelineAndPlayer();
874 857
875 auto events = CreateEventsForTesting(); 858 auto events = CreateEventsForTesting();
876 859
877 gfx::ScrollOffset initial_value(100.f, 300.f); 860 gfx::ScrollOffset initial_value(100.f, 300.f);
878 gfx::ScrollOffset target_value(300.f, 200.f); 861 gfx::ScrollOffset target_value(300.f, 200.f);
879 std::unique_ptr<ScrollOffsetAnimationCurve> curve( 862 std::unique_ptr<ScrollOffsetAnimationCurve> curve(
880 ScrollOffsetAnimationCurve::Create( 863 ScrollOffsetAnimationCurve::Create(
881 target_value, CubicBezierTimingFunction::CreatePreset( 864 target_value, CubicBezierTimingFunction::CreatePreset(
882 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); 865 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)));
883 curve->SetInitialValue(initial_value); 866 curve->SetInitialValue(initial_value);
884 double duration_in_seconds = curve->Duration().InSecondsF(); 867 double duration_in_seconds = curve->Duration().InSecondsF();
885 868
886 std::unique_ptr<Animation> animation( 869 std::unique_ptr<Animation> animation(
887 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); 870 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET));
888 animation->set_is_impl_only(true); 871 animation->set_is_impl_only(true);
889 player_impl_->AddAnimation(std::move(animation)); 872 player_impl_->AddAnimation(std::move(animation));
890 873
891 element_animations_impl_->Animate(kInitialTickTime); 874 player_impl_->Animate(kInitialTickTime);
892 element_animations_impl_->UpdateState(true, events.get()); 875 player_impl_->UpdateState(true, events.get());
893 EXPECT_TRUE(player_impl_->HasActiveAnimation()); 876 EXPECT_TRUE(player_impl_->HasActiveAnimation());
894 EXPECT_EQ(initial_value, 877 EXPECT_EQ(initial_value,
895 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); 878 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
896 // Scroll offset animations should not generate property updates. 879 // Scroll offset animations should not generate property updates.
897 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 880 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
898 EXPECT_FALSE(event); 881 EXPECT_FALSE(event);
899 882
900 TimeDelta duration = TimeDelta::FromMicroseconds( 883 TimeDelta duration = TimeDelta::FromMicroseconds(
901 duration_in_seconds * base::Time::kMicrosecondsPerSecond); 884 duration_in_seconds * base::Time::kMicrosecondsPerSecond);
902 885
903 element_animations_impl_->Animate(kInitialTickTime + duration / 2); 886 player_impl_->Animate(kInitialTickTime + duration / 2);
904 element_animations_impl_->UpdateState(true, events.get()); 887 player_impl_->UpdateState(true, events.get());
905 EXPECT_VECTOR2DF_EQ( 888 EXPECT_VECTOR2DF_EQ(
906 gfx::Vector2dF(200.f, 250.f), 889 gfx::Vector2dF(200.f, 250.f),
907 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); 890 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
908 event = GetMostRecentPropertyUpdateEvent(events.get()); 891 event = GetMostRecentPropertyUpdateEvent(events.get());
909 EXPECT_FALSE(event); 892 EXPECT_FALSE(event);
910 893
911 element_animations_impl_->Animate(kInitialTickTime + duration); 894 player_impl_->Animate(kInitialTickTime + duration);
912 element_animations_impl_->UpdateState(true, events.get()); 895 player_impl_->UpdateState(true, events.get());
913 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( 896 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset(
914 element_id_, ElementListType::ACTIVE)); 897 element_id_, ElementListType::ACTIVE));
915 EXPECT_FALSE(player_impl_->HasActiveAnimation()); 898 EXPECT_FALSE(player_impl_->HasActiveAnimation());
916 event = GetMostRecentPropertyUpdateEvent(events.get()); 899 event = GetMostRecentPropertyUpdateEvent(events.get());
917 EXPECT_FALSE(event); 900 EXPECT_FALSE(event);
918 } 901 }
919 902
920 // This test verifies that if an animation is added after a layer is animated, 903 // This test verifies that if an animation is added after a layer is animated,
921 // it doesn't get promoted to be in the RUNNING state. This prevents cases where 904 // it doesn't get promoted to be in the RUNNING state. This prevents cases where
922 // a start time gets set on an animation using the stale value of 905 // a start time gets set on an animation using the stale value of
923 // last_tick_time_. 906 // last_tick_time_.
924 TEST_F(ElementAnimationsTest, UpdateStateWithoutAnimate) { 907 TEST_F(ElementAnimationsTest, UpdateStateWithoutAnimate) {
925 CreateTestLayer(true, false); 908 CreateTestLayer(true, false);
926 AttachTimelinePlayerLayer(); 909 AttachTimelinePlayerLayer();
927 CreateImplTimelineAndPlayer(); 910 CreateImplTimelineAndPlayer();
928 911
929 auto events = CreateEventsForTesting(); 912 auto events = CreateEventsForTesting();
930 913
931 // Add first scroll offset animation. 914 // Add first scroll offset animation.
932 AddScrollOffsetAnimationToPlayer(player_impl_.get(), 915 AddScrollOffsetAnimationToPlayer(player_impl_.get(),
933 gfx::ScrollOffset(100.f, 300.f), 916 gfx::ScrollOffset(100.f, 300.f),
934 gfx::ScrollOffset(100.f, 200.f), true); 917 gfx::ScrollOffset(100.f, 200.f), true);
935 918
936 // Calling UpdateState after Animate should promote the animation to running 919 // Calling UpdateState after Animate should promote the animation to running
937 // state. 920 // state.
938 element_animations_impl_->Animate(kInitialTickTime); 921 player_impl_->Animate(kInitialTickTime);
939 element_animations_impl_->UpdateState(true, events.get()); 922 player_impl_->UpdateState(true, events.get());
940 EXPECT_EQ( 923 EXPECT_EQ(
941 Animation::RUNNING, 924 Animation::RUNNING,
942 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); 925 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state());
943 926
944 element_animations_impl_->Animate(kInitialTickTime + 927 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500));
945 TimeDelta::FromMilliseconds(1500)); 928 player_impl_->UpdateState(true, events.get());
946 element_animations_impl_->UpdateState(true, events.get());
947 EXPECT_EQ( 929 EXPECT_EQ(
948 Animation::WAITING_FOR_DELETION, 930 Animation::WAITING_FOR_DELETION,
949 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); 931 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state());
950 932
951 // Add second scroll offset animation. 933 // Add second scroll offset animation.
952 AddScrollOffsetAnimationToPlayer(player_impl_.get(), 934 AddScrollOffsetAnimationToPlayer(player_impl_.get(),
953 gfx::ScrollOffset(100.f, 200.f), 935 gfx::ScrollOffset(100.f, 200.f),
954 gfx::ScrollOffset(100.f, 100.f), true); 936 gfx::ScrollOffset(100.f, 100.f), true);
955 937
956 // Calling UpdateState without Animate should NOT promote the animation to 938 // Calling UpdateState without Animate should NOT promote the animation to
957 // running state. 939 // running state.
958 element_animations_impl_->UpdateState(true, events.get()); 940 player_impl_->UpdateState(true, events.get());
959 EXPECT_EQ( 941 EXPECT_EQ(
960 Animation::WAITING_FOR_TARGET_AVAILABILITY, 942 Animation::WAITING_FOR_TARGET_AVAILABILITY,
961 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); 943 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state());
962 944
963 element_animations_impl_->Animate(kInitialTickTime + 945 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
964 TimeDelta::FromMilliseconds(2000)); 946 player_impl_->UpdateState(true, events.get());
965 element_animations_impl_->UpdateState(true, events.get());
966 947
967 EXPECT_EQ( 948 EXPECT_EQ(
968 Animation::RUNNING, 949 Animation::RUNNING,
969 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); 950 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state());
970 EXPECT_VECTOR2DF_EQ( 951 EXPECT_VECTOR2DF_EQ(
971 gfx::ScrollOffset(100.f, 200.f), 952 gfx::ScrollOffset(100.f, 200.f),
972 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); 953 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
973 } 954 }
974 955
975 // Ensure that when the impl animations doesn't have a value provider, 956 // Ensure that when the impl animations doesn't have a value provider,
(...skipping 26 matching lines...) Expand all
1002 PushProperties(); 983 PushProperties();
1003 player_impl_->ActivateAnimations(); 984 player_impl_->ActivateAnimations();
1004 EXPECT_TRUE(player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)); 985 EXPECT_TRUE(player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET));
1005 TimeDelta duration = player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET) 986 TimeDelta duration = player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)
1006 ->curve() 987 ->curve()
1007 ->Duration(); 988 ->Duration();
1008 EXPECT_EQ(duration, player_->GetAnimation(TargetProperty::SCROLL_OFFSET) 989 EXPECT_EQ(duration, player_->GetAnimation(TargetProperty::SCROLL_OFFSET)
1009 ->curve() 990 ->curve()
1010 ->Duration()); 991 ->Duration());
1011 992
1012 element_animations_->Animate(kInitialTickTime); 993 player_->Animate(kInitialTickTime);
1013 element_animations_->UpdateState(true, nullptr); 994 player_->UpdateState(true, nullptr);
1014 995
1015 EXPECT_TRUE(player_->HasActiveAnimation()); 996 EXPECT_TRUE(player_->HasActiveAnimation());
1016 EXPECT_EQ(initial_value, 997 EXPECT_EQ(initial_value,
1017 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); 998 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
1018 EXPECT_EQ(gfx::ScrollOffset(), client_impl_.GetScrollOffset( 999 EXPECT_EQ(gfx::ScrollOffset(), client_impl_.GetScrollOffset(
1019 element_id_, ElementListType::PENDING)); 1000 element_id_, ElementListType::PENDING));
1020 1001
1021 element_animations_impl_->Animate(kInitialTickTime); 1002 player_impl_->Animate(kInitialTickTime);
1022 1003
1023 EXPECT_TRUE(player_impl_->HasActiveAnimation()); 1004 EXPECT_TRUE(player_impl_->HasActiveAnimation());
1024 EXPECT_EQ(initial_value, client_impl_.GetScrollOffset( 1005 EXPECT_EQ(initial_value, client_impl_.GetScrollOffset(
1025 element_id_, ElementListType::PENDING)); 1006 element_id_, ElementListType::PENDING));
1026 1007
1027 CreateTestImplLayer(ElementListType::ACTIVE); 1008 CreateTestImplLayer(ElementListType::ACTIVE);
1028 1009
1029 element_animations_impl_->UpdateState(true, events.get()); 1010 player_impl_->UpdateState(true, events.get());
1030 DCHECK_EQ(1UL, events->events_.size()); 1011 DCHECK_EQ(1UL, events->events_.size());
1031 1012
1032 // Scroll offset animations should not generate property updates. 1013 // Scroll offset animations should not generate property updates.
1033 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); 1014 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get());
1034 EXPECT_FALSE(event); 1015 EXPECT_FALSE(event);
1035 1016
1036 player_->NotifyAnimationStarted(events->events_[0]); 1017 player_->NotifyAnimationStarted(events->events_[0]);
1037 element_animations_->Animate(kInitialTickTime + duration / 2); 1018 player_->Animate(kInitialTickTime + duration / 2);
1038 element_animations_->UpdateState(true, nullptr); 1019 player_->UpdateState(true, nullptr);
1039 EXPECT_TRUE(player_->HasActiveAnimation()); 1020 EXPECT_TRUE(player_->HasActiveAnimation());
1040 EXPECT_VECTOR2DF_EQ( 1021 EXPECT_VECTOR2DF_EQ(
1041 gfx::Vector2dF(400.f, 150.f), 1022 gfx::Vector2dF(400.f, 150.f),
1042 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); 1023 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
1043 1024
1044 element_animations_impl_->Animate(kInitialTickTime + duration / 2); 1025 player_impl_->Animate(kInitialTickTime + duration / 2);
1045 element_animations_impl_->UpdateState(true, events.get()); 1026 player_impl_->UpdateState(true, events.get());
1046 EXPECT_VECTOR2DF_EQ( 1027 EXPECT_VECTOR2DF_EQ(
1047 gfx::Vector2dF(400.f, 150.f), 1028 gfx::Vector2dF(400.f, 150.f),
1048 client_impl_.GetScrollOffset(element_id_, ElementListType::PENDING)); 1029 client_impl_.GetScrollOffset(element_id_, ElementListType::PENDING));
1049 event = GetMostRecentPropertyUpdateEvent(events.get()); 1030 event = GetMostRecentPropertyUpdateEvent(events.get());
1050 EXPECT_FALSE(event); 1031 EXPECT_FALSE(event);
1051 1032
1052 element_animations_impl_->Animate(kInitialTickTime + duration); 1033 player_impl_->Animate(kInitialTickTime + duration);
1053 element_animations_impl_->UpdateState(true, events.get()); 1034 player_impl_->UpdateState(true, events.get());
1054 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( 1035 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset(
1055 element_id_, ElementListType::PENDING)); 1036 element_id_, ElementListType::PENDING));
1056 EXPECT_FALSE(player_impl_->HasActiveAnimation()); 1037 EXPECT_FALSE(player_impl_->HasActiveAnimation());
1057 event = GetMostRecentPropertyUpdateEvent(events.get()); 1038 event = GetMostRecentPropertyUpdateEvent(events.get());
1058 EXPECT_FALSE(event); 1039 EXPECT_FALSE(event);
1059 1040
1060 element_animations_->Animate(kInitialTickTime + duration); 1041 player_->Animate(kInitialTickTime + duration);
1061 element_animations_->UpdateState(true, nullptr); 1042 player_->UpdateState(true, nullptr);
1062 EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset( 1043 EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset(
1063 element_id_, ElementListType::ACTIVE)); 1044 element_id_, ElementListType::ACTIVE));
1064 EXPECT_FALSE(player_->HasActiveAnimation()); 1045 EXPECT_FALSE(player_->HasActiveAnimation());
1065 } 1046 }
1066 1047
1067 TEST_F(ElementAnimationsTest, ScrollOffsetRemovalClearsScrollDelta) { 1048 TEST_F(ElementAnimationsTest, ScrollOffsetRemovalClearsScrollDelta) {
1068 CreateTestLayer(true, false); 1049 CreateTestLayer(true, false);
1069 AttachTimelinePlayerLayer(); 1050 AttachTimelinePlayerLayer();
1070 CreateImplTimelineAndPlayer(); 1051 CreateImplTimelineAndPlayer();
1071 1052
1072 auto events = CreateEventsForTesting(); 1053 auto events = CreateEventsForTesting();
1073 1054
1074 // First test the 1-argument version of RemoveAnimation. 1055 // First test the 1-argument version of RemoveAnimation.
1075 gfx::ScrollOffset target_value(300.f, 200.f); 1056 gfx::ScrollOffset target_value(300.f, 200.f);
1076 std::unique_ptr<ScrollOffsetAnimationCurve> curve( 1057 std::unique_ptr<ScrollOffsetAnimationCurve> curve(
1077 ScrollOffsetAnimationCurve::Create( 1058 ScrollOffsetAnimationCurve::Create(
1078 target_value, CubicBezierTimingFunction::CreatePreset( 1059 target_value, CubicBezierTimingFunction::CreatePreset(
1079 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); 1060 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)));
1080 1061
1081 int animation_id = 1; 1062 int animation_id = 1;
1082 std::unique_ptr<Animation> animation(Animation::Create( 1063 std::unique_ptr<Animation> animation(Animation::Create(
1083 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET)); 1064 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET));
1084 animation->set_needs_synchronized_start_time(true); 1065 animation->set_needs_synchronized_start_time(true);
1085 player_->AddAnimation(std::move(animation)); 1066 player_->AddAnimation(std::move(animation));
1086 PushProperties(); 1067 PushProperties();
1087 element_animations_impl_->ActivateAnimations(); 1068 player_impl_->ActivateAnimations();
1088 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); 1069 EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
1089 EXPECT_FALSE( 1070 EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
1090 element_animations_impl_->scroll_offset_animation_was_interrupted());
1091 1071
1092 player_->RemoveAnimation(animation_id); 1072 player_->RemoveAnimation(animation_id);
1093 EXPECT_TRUE(element_animations_->scroll_offset_animation_was_interrupted()); 1073 EXPECT_TRUE(player_->scroll_offset_animation_was_interrupted());
1094 1074
1095 PushProperties(); 1075 PushProperties();
1096 EXPECT_TRUE( 1076 EXPECT_TRUE(player_impl_->scroll_offset_animation_was_interrupted());
1097 element_animations_impl_->scroll_offset_animation_was_interrupted()); 1077 EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
1098 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted());
1099 1078
1100 element_animations_impl_->ActivateAnimations(); 1079 player_impl_->ActivateAnimations();
1101 EXPECT_FALSE( 1080 EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
1102 element_animations_impl_->scroll_offset_animation_was_interrupted());
1103 1081
1104 // Now, test the 2-argument version of RemoveAnimation. 1082 // Now, test the 2-argument version of RemoveAnimation.
1105 curve = ScrollOffsetAnimationCurve::Create( 1083 curve = ScrollOffsetAnimationCurve::Create(
1106 target_value, CubicBezierTimingFunction::CreatePreset( 1084 target_value, CubicBezierTimingFunction::CreatePreset(
1107 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)); 1085 CubicBezierTimingFunction::EaseType::EASE_IN_OUT));
1108 animation = Animation::Create(std::move(curve), animation_id, 0, 1086 animation = Animation::Create(std::move(curve), animation_id, 0,
1109 TargetProperty::SCROLL_OFFSET); 1087 TargetProperty::SCROLL_OFFSET);
1110 animation->set_needs_synchronized_start_time(true); 1088 animation->set_needs_synchronized_start_time(true);
1111 player_->AddAnimation(std::move(animation)); 1089 player_->AddAnimation(std::move(animation));
1112 PushProperties(); 1090 PushProperties();
1113 element_animations_impl_->ActivateAnimations(); 1091 player_impl_->ActivateAnimations();
1114 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); 1092 EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
1115 EXPECT_FALSE( 1093 EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
1116 element_animations_impl_->scroll_offset_animation_was_interrupted());
1117 1094
1118 player_->RemoveAnimation(animation_id); 1095 player_->RemoveAnimation(animation_id);
1119 EXPECT_TRUE(element_animations_->scroll_offset_animation_was_interrupted()); 1096 EXPECT_TRUE(player_->scroll_offset_animation_was_interrupted());
1120 1097
1121 PushProperties(); 1098 PushProperties();
1122 EXPECT_TRUE( 1099 EXPECT_TRUE(player_impl_->scroll_offset_animation_was_interrupted());
1123 element_animations_impl_->scroll_offset_animation_was_interrupted()); 1100 EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
1124 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted());
1125 1101
1126 element_animations_impl_->ActivateAnimations(); 1102 player_impl_->ActivateAnimations();
1127 EXPECT_FALSE( 1103 EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
1128 element_animations_impl_->scroll_offset_animation_was_interrupted());
1129 1104
1130 // Check that removing non-scroll-offset animations does not cause 1105 // Check that removing non-scroll-offset animations does not cause
1131 // scroll_offset_animation_was_interrupted() to get set. 1106 // scroll_offset_animation_was_interrupted() to get set.
1132 animation_id = AddAnimatedTransformToPlayer(player_.get(), 1.0, 1, 2); 1107 animation_id = AddAnimatedTransformToPlayer(player_.get(), 1.0, 1, 2);
1133 PushProperties(); 1108 PushProperties();
1134 element_animations_impl_->ActivateAnimations(); 1109 player_impl_->ActivateAnimations();
1135 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); 1110 EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
1136 EXPECT_FALSE( 1111 EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
1137 element_animations_impl_->scroll_offset_animation_was_interrupted());
1138 1112
1139 player_->RemoveAnimation(animation_id); 1113 player_->RemoveAnimation(animation_id);
1140 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); 1114 EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
1141 1115
1142 PushProperties(); 1116 PushProperties();
1143 EXPECT_FALSE( 1117 EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
1144 element_animations_impl_->scroll_offset_animation_was_interrupted()); 1118 EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
1145 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted());
1146 1119
1147 element_animations_impl_->ActivateAnimations(); 1120 player_impl_->ActivateAnimations();
1148 EXPECT_FALSE( 1121 EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
1149 element_animations_impl_->scroll_offset_animation_was_interrupted());
1150 1122
1151 animation_id = AddAnimatedFilterToPlayer(player_.get(), 1.0, 0.1f, 0.2f); 1123 animation_id = AddAnimatedFilterToPlayer(player_.get(), 1.0, 0.1f, 0.2f);
1152 PushProperties(); 1124 PushProperties();
1153 element_animations_impl_->ActivateAnimations(); 1125 player_impl_->ActivateAnimations();
1154 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); 1126 EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
1155 EXPECT_FALSE( 1127 EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
1156 element_animations_impl_->scroll_offset_animation_was_interrupted());
1157 1128
1158 player_->RemoveAnimation(animation_id); 1129 player_->RemoveAnimation(animation_id);
1159 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); 1130 EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
1160 1131
1161 PushProperties(); 1132 PushProperties();
1162 EXPECT_FALSE( 1133 EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
1163 element_animations_impl_->scroll_offset_animation_was_interrupted()); 1134 EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
1164 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted());
1165 1135
1166 element_animations_impl_->ActivateAnimations(); 1136 player_impl_->ActivateAnimations();
1167 EXPECT_FALSE( 1137 EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
1168 element_animations_impl_->scroll_offset_animation_was_interrupted());
1169 } 1138 }
1170 1139
1171 // Tests that impl-only animations lead to start and finished notifications 1140 // Tests that impl-only animations lead to start and finished notifications
1172 // on the impl thread animations's animation delegate. 1141 // on the impl thread animations's animation delegate.
1173 TEST_F(ElementAnimationsTest, 1142 TEST_F(ElementAnimationsTest,
1174 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { 1143 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) {
1175 CreateTestLayer(true, false); 1144 CreateTestLayer(true, false);
1176 AttachTimelinePlayerLayer(); 1145 AttachTimelinePlayerLayer();
1177 CreateImplTimelineAndPlayer(); 1146 CreateImplTimelineAndPlayer();
1178 1147
(...skipping 11 matching lines...) Expand all
1190 curve->SetInitialValue(initial_value); 1159 curve->SetInitialValue(initial_value);
1191 TimeDelta duration = curve->Duration(); 1160 TimeDelta duration = curve->Duration();
1192 std::unique_ptr<Animation> to_add( 1161 std::unique_ptr<Animation> to_add(
1193 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); 1162 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET));
1194 to_add->set_is_impl_only(true); 1163 to_add->set_is_impl_only(true);
1195 player_impl_->AddAnimation(std::move(to_add)); 1164 player_impl_->AddAnimation(std::move(to_add));
1196 1165
1197 EXPECT_FALSE(delegate.started()); 1166 EXPECT_FALSE(delegate.started());
1198 EXPECT_FALSE(delegate.finished()); 1167 EXPECT_FALSE(delegate.finished());
1199 1168
1200 element_animations_impl_->Animate(kInitialTickTime); 1169 player_impl_->Animate(kInitialTickTime);
1201 element_animations_impl_->UpdateState(true, events.get()); 1170 player_impl_->UpdateState(true, events.get());
1202 1171
1203 EXPECT_TRUE(delegate.started()); 1172 EXPECT_TRUE(delegate.started());
1204 EXPECT_FALSE(delegate.finished()); 1173 EXPECT_FALSE(delegate.finished());
1205 1174
1206 events = CreateEventsForTesting(); 1175 events = CreateEventsForTesting();
1207 element_animations_impl_->Animate(kInitialTickTime + duration); 1176 player_impl_->Animate(kInitialTickTime + duration);
1208 EXPECT_EQ(duration, player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET) 1177 EXPECT_EQ(duration, player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)
1209 ->curve() 1178 ->curve()
1210 ->Duration()); 1179 ->Duration());
1211 element_animations_impl_->UpdateState(true, events.get()); 1180 player_impl_->UpdateState(true, events.get());
1212 1181
1213 EXPECT_TRUE(delegate.started()); 1182 EXPECT_TRUE(delegate.started());
1214 EXPECT_TRUE(delegate.finished()); 1183 EXPECT_TRUE(delegate.finished());
1215 } 1184 }
1216 1185
1217 // Tests that specified start times are sent to the main thread delegate 1186 // Tests that specified start times are sent to the main thread delegate
1218 TEST_F(ElementAnimationsTest, SpecifiedStartTimesAreSentToMainThreadDelegate) { 1187 TEST_F(ElementAnimationsTest, SpecifiedStartTimesAreSentToMainThreadDelegate) {
1219 CreateTestLayer(true, false); 1188 CreateTestLayer(true, false);
1220 AttachTimelinePlayerLayer(); 1189 AttachTimelinePlayerLayer();
1221 CreateImplTimelineAndPlayer(); 1190 CreateImplTimelineAndPlayer();
1222 1191
1223 TestAnimationDelegate delegate; 1192 TestAnimationDelegate delegate;
1224 player_->set_animation_delegate(&delegate); 1193 player_->set_animation_delegate(&delegate);
1225 1194
1226 int animation_id = 1195 int animation_id =
1227 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); 1196 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false);
1228 1197
1229 const TimeTicks start_time = TicksFromSecondsF(123); 1198 const TimeTicks start_time = TicksFromSecondsF(123);
1230 player_->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); 1199 player_->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time);
1231 1200
1232 PushProperties(); 1201 PushProperties();
1233 player_impl_->ActivateAnimations(); 1202 player_impl_->ActivateAnimations();
1234 1203
1235 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); 1204 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
1236 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 1205 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1237 player_impl_->GetAnimationById(animation_id)->run_state()); 1206 player_impl_->GetAnimationById(animation_id)->run_state());
1238 1207
1239 auto events = CreateEventsForTesting(); 1208 auto events = CreateEventsForTesting();
1240 element_animations_impl_->Animate(kInitialTickTime); 1209 player_impl_->Animate(kInitialTickTime);
1241 element_animations_impl_->UpdateState(true, events.get()); 1210 player_impl_->UpdateState(true, events.get());
1242 1211
1243 // Synchronize the start times. 1212 // Synchronize the start times.
1244 EXPECT_EQ(1u, events->events_.size()); 1213 EXPECT_EQ(1u, events->events_.size());
1245 player_->NotifyAnimationStarted(events->events_[0]); 1214 player_->NotifyAnimationStarted(events->events_[0]);
1246 1215
1247 // Validate start time on the main thread delegate. 1216 // Validate start time on the main thread delegate.
1248 EXPECT_EQ(start_time, delegate.start_time()); 1217 EXPECT_EQ(start_time, delegate.start_time());
1249 } 1218 }
1250 1219
1251 // Tests animations that are waiting for a synchronized start time do not 1220 // Tests animations that are waiting for a synchronized start time do not
1252 // finish. 1221 // finish.
1253 TEST_F(ElementAnimationsTest, 1222 TEST_F(ElementAnimationsTest,
1254 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { 1223 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) {
1255 CreateTestLayer(false, false); 1224 CreateTestLayer(false, false);
1256 AttachTimelinePlayerLayer(); 1225 AttachTimelinePlayerLayer();
1257 1226
1258 auto events = CreateEventsForTesting(); 1227 auto events = CreateEventsForTesting();
1259 1228
1260 std::unique_ptr<Animation> to_add(CreateAnimation( 1229 std::unique_ptr<Animation> to_add(CreateAnimation(
1261 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1230 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1262 1, TargetProperty::OPACITY)); 1231 1, TargetProperty::OPACITY));
1263 to_add->set_needs_synchronized_start_time(true); 1232 to_add->set_needs_synchronized_start_time(true);
1264 1233
1265 // We should pause at the first keyframe indefinitely waiting for that 1234 // We should pause at the first keyframe indefinitely waiting for that
1266 // animation to start. 1235 // animation to start.
1267 player_->AddAnimation(std::move(to_add)); 1236 player_->AddAnimation(std::move(to_add));
1268 element_animations_->Animate(kInitialTickTime); 1237 player_->Animate(kInitialTickTime);
1269 element_animations_->UpdateState(true, events.get()); 1238 player_->UpdateState(true, events.get());
1270 EXPECT_TRUE(player_->HasActiveAnimation()); 1239 EXPECT_TRUE(player_->HasActiveAnimation());
1271 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1240 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1272 element_animations_->Animate(kInitialTickTime + 1241 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1273 TimeDelta::FromMilliseconds(1000)); 1242 player_->UpdateState(true, events.get());
1274 element_animations_->UpdateState(true, events.get());
1275 EXPECT_TRUE(player_->HasActiveAnimation()); 1243 EXPECT_TRUE(player_->HasActiveAnimation());
1276 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1244 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1277 element_animations_->Animate(kInitialTickTime + 1245 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1278 TimeDelta::FromMilliseconds(2000)); 1246 player_->UpdateState(true, events.get());
1279 element_animations_->UpdateState(true, events.get());
1280 EXPECT_TRUE(player_->HasActiveAnimation()); 1247 EXPECT_TRUE(player_->HasActiveAnimation());
1281 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1248 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1282 1249
1283 // Send the synchronized start time. 1250 // Send the synchronized start time.
1284 player_->NotifyAnimationStarted(AnimationEvent( 1251 player_->NotifyAnimationStarted(AnimationEvent(
1285 AnimationEvent::STARTED, ElementId(), 1, TargetProperty::OPACITY, 1252 AnimationEvent::STARTED, ElementId(), 1, TargetProperty::OPACITY,
1286 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); 1253 kInitialTickTime + TimeDelta::FromMilliseconds(2000)));
1287 element_animations_->Animate(kInitialTickTime + 1254 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000));
1288 TimeDelta::FromMilliseconds(5000)); 1255 player_->UpdateState(true, events.get());
1289 element_animations_->UpdateState(true, events.get());
1290 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1256 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1291 EXPECT_FALSE(player_->HasActiveAnimation()); 1257 EXPECT_FALSE(player_->HasActiveAnimation());
1292 } 1258 }
1293 1259
1294 // Tests that two queued animations affecting the same property run in sequence. 1260 // Tests that two queued animations affecting the same property run in sequence.
1295 TEST_F(ElementAnimationsTest, TrivialQueuing) { 1261 TEST_F(ElementAnimationsTest, TrivialQueuing) {
1296 CreateTestLayer(false, false); 1262 CreateTestLayer(false, false);
1297 AttachTimelinePlayerLayer(); 1263 AttachTimelinePlayerLayer();
1298 1264
1299 auto events = CreateEventsForTesting(); 1265 auto events = CreateEventsForTesting();
1300 1266
1301 EXPECT_FALSE(player_->needs_to_start_animations()); 1267 EXPECT_FALSE(player_->needs_to_start_animations());
1302 1268
1303 player_->AddAnimation(CreateAnimation( 1269 player_->AddAnimation(CreateAnimation(
1304 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1270 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1305 1, TargetProperty::OPACITY)); 1271 1, TargetProperty::OPACITY));
1306 player_->AddAnimation(CreateAnimation( 1272 player_->AddAnimation(CreateAnimation(
1307 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), 1273 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)),
1308 2, TargetProperty::OPACITY)); 1274 2, TargetProperty::OPACITY));
1309 1275
1310 EXPECT_TRUE(player_->needs_to_start_animations()); 1276 EXPECT_TRUE(player_->needs_to_start_animations());
1311 1277
1312 element_animations_->Animate(kInitialTickTime); 1278 player_->Animate(kInitialTickTime);
1313 1279
1314 // The second animation still needs to be started. 1280 // The second animation still needs to be started.
1315 EXPECT_TRUE(player_->needs_to_start_animations()); 1281 EXPECT_TRUE(player_->needs_to_start_animations());
1316 1282
1317 element_animations_->UpdateState(true, events.get()); 1283 player_->UpdateState(true, events.get());
1318 EXPECT_TRUE(player_->HasActiveAnimation()); 1284 EXPECT_TRUE(player_->HasActiveAnimation());
1319 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1285 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1320 1286
1321 element_animations_->Animate(kInitialTickTime + 1287 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1322 TimeDelta::FromMilliseconds(1000));
1323 EXPECT_TRUE(player_->needs_to_start_animations()); 1288 EXPECT_TRUE(player_->needs_to_start_animations());
1324 element_animations_->UpdateState(true, events.get()); 1289 player_->UpdateState(true, events.get());
1325 EXPECT_FALSE(player_->needs_to_start_animations()); 1290 EXPECT_FALSE(player_->needs_to_start_animations());
1326 1291
1327 EXPECT_TRUE(player_->HasActiveAnimation()); 1292 EXPECT_TRUE(player_->HasActiveAnimation());
1328 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1293 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1329 element_animations_->Animate(kInitialTickTime + 1294 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1330 TimeDelta::FromMilliseconds(2000)); 1295 player_->UpdateState(true, events.get());
1331 element_animations_->UpdateState(true, events.get());
1332 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1296 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1333 EXPECT_FALSE(player_->HasActiveAnimation()); 1297 EXPECT_FALSE(player_->HasActiveAnimation());
1334 } 1298 }
1335 1299
1336 // Tests interrupting a transition with another transition. 1300 // Tests interrupting a transition with another transition.
1337 TEST_F(ElementAnimationsTest, Interrupt) { 1301 TEST_F(ElementAnimationsTest, Interrupt) {
1338 CreateTestLayer(false, false); 1302 CreateTestLayer(false, false);
1339 AttachTimelinePlayerLayer(); 1303 AttachTimelinePlayerLayer();
1340 1304
1341 auto events = CreateEventsForTesting(); 1305 auto events = CreateEventsForTesting();
1342 1306
1343 player_->AddAnimation(CreateAnimation( 1307 player_->AddAnimation(CreateAnimation(
1344 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1308 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1345 1, TargetProperty::OPACITY)); 1309 1, TargetProperty::OPACITY));
1346 element_animations_->Animate(kInitialTickTime); 1310 player_->Animate(kInitialTickTime);
1347 element_animations_->UpdateState(true, events.get()); 1311 player_->UpdateState(true, events.get());
1348 EXPECT_TRUE(player_->HasActiveAnimation()); 1312 EXPECT_TRUE(player_->HasActiveAnimation());
1349 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1313 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1350 1314
1351 std::unique_ptr<Animation> to_add(CreateAnimation( 1315 std::unique_ptr<Animation> to_add(CreateAnimation(
1352 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), 1316 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)),
1353 2, TargetProperty::OPACITY)); 1317 2, TargetProperty::OPACITY));
1354 player_->AbortAnimations(TargetProperty::OPACITY, false); 1318 player_->AbortAnimations(TargetProperty::OPACITY, false);
1355 player_->AddAnimation(std::move(to_add)); 1319 player_->AddAnimation(std::move(to_add));
1356 1320
1357 // Since the previous animation was aborted, the new animation should start 1321 // Since the previous animation was aborted, the new animation should start
1358 // right in this call to animate. 1322 // right in this call to animate.
1359 element_animations_->Animate(kInitialTickTime + 1323 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
1360 TimeDelta::FromMilliseconds(500)); 1324 player_->UpdateState(true, events.get());
1361 element_animations_->UpdateState(true, events.get());
1362 EXPECT_TRUE(player_->HasActiveAnimation()); 1325 EXPECT_TRUE(player_->HasActiveAnimation());
1363 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1326 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1364 element_animations_->Animate(kInitialTickTime + 1327 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500));
1365 TimeDelta::FromMilliseconds(1500)); 1328 player_->UpdateState(true, events.get());
1366 element_animations_->UpdateState(true, events.get());
1367 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1329 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1368 EXPECT_FALSE(player_->HasActiveAnimation()); 1330 EXPECT_FALSE(player_->HasActiveAnimation());
1369 } 1331 }
1370 1332
1371 // Tests scheduling two animations to run together when only one property is 1333 // Tests scheduling two animations to run together when only one property is
1372 // free. 1334 // free.
1373 TEST_F(ElementAnimationsTest, ScheduleTogetherWhenAPropertyIsBlocked) { 1335 TEST_F(ElementAnimationsTest, ScheduleTogetherWhenAPropertyIsBlocked) {
1374 CreateTestLayer(false, false); 1336 CreateTestLayer(false, false);
1375 AttachTimelinePlayerLayer(); 1337 AttachTimelinePlayerLayer();
1376 1338
1377 auto events = CreateEventsForTesting(); 1339 auto events = CreateEventsForTesting();
1378 1340
1379 player_->AddAnimation(CreateAnimation( 1341 player_->AddAnimation(CreateAnimation(
1380 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1342 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1,
1381 TargetProperty::TRANSFORM)); 1343 TargetProperty::TRANSFORM));
1382 player_->AddAnimation(CreateAnimation( 1344 player_->AddAnimation(CreateAnimation(
1383 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, 1345 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2,
1384 TargetProperty::TRANSFORM)); 1346 TargetProperty::TRANSFORM));
1385 player_->AddAnimation(CreateAnimation( 1347 player_->AddAnimation(CreateAnimation(
1386 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1348 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1387 2, TargetProperty::OPACITY)); 1349 2, TargetProperty::OPACITY));
1388 1350
1389 element_animations_->Animate(kInitialTickTime); 1351 player_->Animate(kInitialTickTime);
1390 element_animations_->UpdateState(true, events.get()); 1352 player_->UpdateState(true, events.get());
1391 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1353 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1392 EXPECT_TRUE(player_->HasActiveAnimation()); 1354 EXPECT_TRUE(player_->HasActiveAnimation());
1393 element_animations_->Animate(kInitialTickTime + 1355 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1394 TimeDelta::FromMilliseconds(1000)); 1356 player_->UpdateState(true, events.get());
1395 element_animations_->UpdateState(true, events.get());
1396 // Should not have started the float transition yet. 1357 // Should not have started the float transition yet.
1397 EXPECT_TRUE(player_->HasActiveAnimation()); 1358 EXPECT_TRUE(player_->HasActiveAnimation());
1398 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1359 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1399 // The float animation should have started at time 1 and should be done. 1360 // The float animation should have started at time 1 and should be done.
1400 element_animations_->Animate(kInitialTickTime + 1361 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1401 TimeDelta::FromMilliseconds(2000)); 1362 player_->UpdateState(true, events.get());
1402 element_animations_->UpdateState(true, events.get());
1403 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1363 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1404 EXPECT_FALSE(player_->HasActiveAnimation()); 1364 EXPECT_FALSE(player_->HasActiveAnimation());
1405 } 1365 }
1406 1366
1407 // Tests scheduling two animations to run together with different lengths and 1367 // Tests scheduling two animations to run together with different lengths and
1408 // another animation queued to start when the shorter animation finishes (should 1368 // another animation queued to start when the shorter animation finishes (should
1409 // wait for both to finish). 1369 // wait for both to finish).
1410 TEST_F(ElementAnimationsTest, ScheduleTogetherWithAnAnimWaiting) { 1370 TEST_F(ElementAnimationsTest, ScheduleTogetherWithAnAnimWaiting) {
1411 CreateTestLayer(false, false); 1371 CreateTestLayer(false, false);
1412 AttachTimelinePlayerLayer(); 1372 AttachTimelinePlayerLayer();
1413 1373
1414 auto events = CreateEventsForTesting(); 1374 auto events = CreateEventsForTesting();
1415 1375
1416 player_->AddAnimation(CreateAnimation( 1376 player_->AddAnimation(CreateAnimation(
1417 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, 1377 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1,
1418 TargetProperty::TRANSFORM)); 1378 TargetProperty::TRANSFORM));
1419 player_->AddAnimation(CreateAnimation( 1379 player_->AddAnimation(CreateAnimation(
1420 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1380 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1421 1, TargetProperty::OPACITY)); 1381 1, TargetProperty::OPACITY));
1422 player_->AddAnimation(CreateAnimation( 1382 player_->AddAnimation(CreateAnimation(
1423 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), 1383 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)),
1424 2, TargetProperty::OPACITY)); 1384 2, TargetProperty::OPACITY));
1425 1385
1426 // Animations with id 1 should both start now. 1386 // Animations with id 1 should both start now.
1427 element_animations_->Animate(kInitialTickTime); 1387 player_->Animate(kInitialTickTime);
1428 element_animations_->UpdateState(true, events.get()); 1388 player_->UpdateState(true, events.get());
1429 EXPECT_TRUE(player_->HasActiveAnimation()); 1389 EXPECT_TRUE(player_->HasActiveAnimation());
1430 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1390 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1431 // The opacity animation should have finished at time 1, but the group 1391 // The opacity animation should have finished at time 1, but the group
1432 // of animations with id 1 don't finish until time 2 because of the length 1392 // of animations with id 1 don't finish until time 2 because of the length
1433 // of the transform animation. 1393 // of the transform animation.
1434 element_animations_->Animate(kInitialTickTime + 1394 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1435 TimeDelta::FromMilliseconds(2000)); 1395 player_->UpdateState(true, events.get());
1436 element_animations_->UpdateState(true, events.get());
1437 // Should not have started the float transition yet. 1396 // Should not have started the float transition yet.
1438 EXPECT_TRUE(player_->HasActiveAnimation()); 1397 EXPECT_TRUE(player_->HasActiveAnimation());
1439 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1398 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1440 1399
1441 // The second opacity animation should start at time 2 and should be done by 1400 // The second opacity animation should start at time 2 and should be done by
1442 // time 3. 1401 // time 3.
1443 element_animations_->Animate(kInitialTickTime + 1402 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1444 TimeDelta::FromMilliseconds(3000)); 1403 player_->UpdateState(true, events.get());
1445 element_animations_->UpdateState(true, events.get());
1446 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1404 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1447 EXPECT_FALSE(player_->HasActiveAnimation()); 1405 EXPECT_FALSE(player_->HasActiveAnimation());
1448 } 1406 }
1449 1407
1450 // Test that a looping animation loops and for the correct number of iterations. 1408 // Test that a looping animation loops and for the correct number of iterations.
1451 TEST_F(ElementAnimationsTest, TrivialLooping) { 1409 TEST_F(ElementAnimationsTest, TrivialLooping) {
1452 CreateTestLayer(false, false); 1410 CreateTestLayer(false, false);
1453 AttachTimelinePlayerLayer(); 1411 AttachTimelinePlayerLayer();
1454 1412
1455 auto events = CreateEventsForTesting(); 1413 auto events = CreateEventsForTesting();
1456 1414
1457 std::unique_ptr<Animation> to_add(CreateAnimation( 1415 std::unique_ptr<Animation> to_add(CreateAnimation(
1458 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1416 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1459 1, TargetProperty::OPACITY)); 1417 1, TargetProperty::OPACITY));
1460 to_add->set_iterations(3); 1418 to_add->set_iterations(3);
1461 player_->AddAnimation(std::move(to_add)); 1419 player_->AddAnimation(std::move(to_add));
1462 1420
1463 element_animations_->Animate(kInitialTickTime); 1421 player_->Animate(kInitialTickTime);
1464 element_animations_->UpdateState(true, events.get()); 1422 player_->UpdateState(true, events.get());
1465 EXPECT_TRUE(player_->HasActiveAnimation()); 1423 EXPECT_TRUE(player_->HasActiveAnimation());
1466 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1424 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1467 element_animations_->Animate(kInitialTickTime + 1425 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250));
1468 TimeDelta::FromMilliseconds(1250)); 1426 player_->UpdateState(true, events.get());
1469 element_animations_->UpdateState(true, events.get());
1470 EXPECT_TRUE(player_->HasActiveAnimation()); 1427 EXPECT_TRUE(player_->HasActiveAnimation());
1471 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1428 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1472 element_animations_->Animate(kInitialTickTime + 1429 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750));
1473 TimeDelta::FromMilliseconds(1750)); 1430 player_->UpdateState(true, events.get());
1474 element_animations_->UpdateState(true, events.get());
1475 EXPECT_TRUE(player_->HasActiveAnimation()); 1431 EXPECT_TRUE(player_->HasActiveAnimation());
1476 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1432 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1477 element_animations_->Animate(kInitialTickTime + 1433 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2250));
1478 TimeDelta::FromMilliseconds(2250)); 1434 player_->UpdateState(true, events.get());
1479 element_animations_->UpdateState(true, events.get());
1480 EXPECT_TRUE(player_->HasActiveAnimation()); 1435 EXPECT_TRUE(player_->HasActiveAnimation());
1481 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1436 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1482 element_animations_->Animate(kInitialTickTime + 1437 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2750));
1483 TimeDelta::FromMilliseconds(2750)); 1438 player_->UpdateState(true, events.get());
1484 element_animations_->UpdateState(true, events.get());
1485 EXPECT_TRUE(player_->HasActiveAnimation()); 1439 EXPECT_TRUE(player_->HasActiveAnimation());
1486 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1440 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1487 element_animations_->Animate(kInitialTickTime + 1441 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1488 TimeDelta::FromMilliseconds(3000)); 1442 player_->UpdateState(true, events.get());
1489 element_animations_->UpdateState(true, events.get());
1490 EXPECT_FALSE(player_->HasActiveAnimation()); 1443 EXPECT_FALSE(player_->HasActiveAnimation());
1491 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1444 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1492 1445
1493 // Just be extra sure. 1446 // Just be extra sure.
1494 element_animations_->Animate(kInitialTickTime + 1447 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000));
1495 TimeDelta::FromMilliseconds(4000)); 1448 player_->UpdateState(true, events.get());
1496 element_animations_->UpdateState(true, events.get());
1497 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1449 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1498 } 1450 }
1499 1451
1500 // Test that an infinitely looping animation does indeed go until aborted. 1452 // Test that an infinitely looping animation does indeed go until aborted.
1501 TEST_F(ElementAnimationsTest, InfiniteLooping) { 1453 TEST_F(ElementAnimationsTest, InfiniteLooping) {
1502 CreateTestLayer(false, false); 1454 CreateTestLayer(false, false);
1503 AttachTimelinePlayerLayer(); 1455 AttachTimelinePlayerLayer();
1504 1456
1505 auto events = CreateEventsForTesting(); 1457 auto events = CreateEventsForTesting();
1506 1458
1507 std::unique_ptr<Animation> to_add(CreateAnimation( 1459 std::unique_ptr<Animation> to_add(CreateAnimation(
1508 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1460 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1509 1, TargetProperty::OPACITY)); 1461 1, TargetProperty::OPACITY));
1510 to_add->set_iterations(-1); 1462 to_add->set_iterations(-1);
1511 player_->AddAnimation(std::move(to_add)); 1463 player_->AddAnimation(std::move(to_add));
1512 1464
1513 element_animations_->Animate(kInitialTickTime); 1465 player_->Animate(kInitialTickTime);
1514 element_animations_->UpdateState(true, events.get()); 1466 player_->UpdateState(true, events.get());
1515 EXPECT_TRUE(player_->HasActiveAnimation()); 1467 EXPECT_TRUE(player_->HasActiveAnimation());
1516 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1468 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1517 element_animations_->Animate(kInitialTickTime + 1469 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250));
1518 TimeDelta::FromMilliseconds(1250)); 1470 player_->UpdateState(true, events.get());
1519 element_animations_->UpdateState(true, events.get());
1520 EXPECT_TRUE(player_->HasActiveAnimation()); 1471 EXPECT_TRUE(player_->HasActiveAnimation());
1521 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1472 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1522 element_animations_->Animate(kInitialTickTime + 1473 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750));
1523 TimeDelta::FromMilliseconds(1750)); 1474 player_->UpdateState(true, events.get());
1524 element_animations_->UpdateState(true, events.get());
1525 EXPECT_TRUE(player_->HasActiveAnimation()); 1475 EXPECT_TRUE(player_->HasActiveAnimation());
1526 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1476 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1527 1477
1528 element_animations_->Animate(kInitialTickTime + 1478 player_->Animate(kInitialTickTime +
1529 TimeDelta::FromMilliseconds(1073741824250)); 1479 TimeDelta::FromMilliseconds(1073741824250));
1530 element_animations_->UpdateState(true, events.get()); 1480 player_->UpdateState(true, events.get());
1531 EXPECT_TRUE(player_->HasActiveAnimation()); 1481 EXPECT_TRUE(player_->HasActiveAnimation());
1532 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1482 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1533 element_animations_->Animate(kInitialTickTime + 1483 player_->Animate(kInitialTickTime +
1534 TimeDelta::FromMilliseconds(1073741824750)); 1484 TimeDelta::FromMilliseconds(1073741824750));
1535 element_animations_->UpdateState(true, events.get()); 1485 player_->UpdateState(true, events.get());
1536 EXPECT_TRUE(player_->HasActiveAnimation()); 1486 EXPECT_TRUE(player_->HasActiveAnimation());
1537 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1487 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1538 1488
1539 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY)); 1489 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY));
1540 player_->GetAnimation(TargetProperty::OPACITY) 1490 player_->GetAnimation(TargetProperty::OPACITY)
1541 ->SetRunState(Animation::ABORTED, 1491 ->SetRunState(Animation::ABORTED,
1542 kInitialTickTime + TimeDelta::FromMilliseconds(750)); 1492 kInitialTickTime + TimeDelta::FromMilliseconds(750));
1543 EXPECT_FALSE(player_->HasActiveAnimation()); 1493 EXPECT_FALSE(player_->HasActiveAnimation());
1544 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1494 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1545 } 1495 }
1546 1496
1547 // Test that pausing and resuming work as expected. 1497 // Test that pausing and resuming work as expected.
1548 TEST_F(ElementAnimationsTest, PauseResume) { 1498 TEST_F(ElementAnimationsTest, PauseResume) {
1549 CreateTestLayer(false, false); 1499 CreateTestLayer(false, false);
1550 AttachTimelinePlayerLayer(); 1500 AttachTimelinePlayerLayer();
1551 1501
1552 auto events = CreateEventsForTesting(); 1502 auto events = CreateEventsForTesting();
1553 1503
1554 player_->AddAnimation(CreateAnimation( 1504 player_->AddAnimation(CreateAnimation(
1555 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1505 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1556 1, TargetProperty::OPACITY)); 1506 1, TargetProperty::OPACITY));
1557 1507
1558 element_animations_->Animate(kInitialTickTime); 1508 player_->Animate(kInitialTickTime);
1559 element_animations_->UpdateState(true, events.get()); 1509 player_->UpdateState(true, events.get());
1560 EXPECT_TRUE(player_->HasActiveAnimation()); 1510 EXPECT_TRUE(player_->HasActiveAnimation());
1561 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1511 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1562 element_animations_->Animate(kInitialTickTime + 1512 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
1563 TimeDelta::FromMilliseconds(500)); 1513 player_->UpdateState(true, events.get());
1564 element_animations_->UpdateState(true, events.get());
1565 EXPECT_TRUE(player_->HasActiveAnimation()); 1514 EXPECT_TRUE(player_->HasActiveAnimation());
1566 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1515 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1567 1516
1568 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY)); 1517 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY));
1569 player_->GetAnimation(TargetProperty::OPACITY) 1518 player_->GetAnimation(TargetProperty::OPACITY)
1570 ->SetRunState(Animation::PAUSED, 1519 ->SetRunState(Animation::PAUSED,
1571 kInitialTickTime + TimeDelta::FromMilliseconds(500)); 1520 kInitialTickTime + TimeDelta::FromMilliseconds(500));
1572 1521
1573 element_animations_->Animate(kInitialTickTime + 1522 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000));
1574 TimeDelta::FromMilliseconds(1024000)); 1523 player_->UpdateState(true, events.get());
1575 element_animations_->UpdateState(true, events.get());
1576 EXPECT_TRUE(player_->HasActiveAnimation()); 1524 EXPECT_TRUE(player_->HasActiveAnimation());
1577 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1525 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1578 1526
1579 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY)); 1527 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY));
1580 player_->GetAnimation(TargetProperty::OPACITY) 1528 player_->GetAnimation(TargetProperty::OPACITY)
1581 ->SetRunState(Animation::RUNNING, 1529 ->SetRunState(Animation::RUNNING,
1582 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); 1530 kInitialTickTime + TimeDelta::FromMilliseconds(1024000));
1583 element_animations_->Animate(kInitialTickTime + 1531 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250));
1584 TimeDelta::FromMilliseconds(1024250)); 1532 player_->UpdateState(true, events.get());
1585 element_animations_->UpdateState(true, events.get());
1586 EXPECT_TRUE(player_->HasActiveAnimation()); 1533 EXPECT_TRUE(player_->HasActiveAnimation());
1587 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1534 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1588 1535
1589 element_animations_->Animate(kInitialTickTime + 1536 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500));
1590 TimeDelta::FromMilliseconds(1024500)); 1537 player_->UpdateState(true, events.get());
1591 element_animations_->UpdateState(true, events.get());
1592 EXPECT_FALSE(player_->HasActiveAnimation()); 1538 EXPECT_FALSE(player_->HasActiveAnimation());
1593 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1539 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1594 } 1540 }
1595 1541
1596 TEST_F(ElementAnimationsTest, AbortAGroupedAnimation) { 1542 TEST_F(ElementAnimationsTest, AbortAGroupedAnimation) {
1597 CreateTestLayer(false, false); 1543 CreateTestLayer(false, false);
1598 AttachTimelinePlayerLayer(); 1544 AttachTimelinePlayerLayer();
1599 1545
1600 auto events = CreateEventsForTesting(); 1546 auto events = CreateEventsForTesting();
1601 1547
1602 const int animation_id = 2; 1548 const int animation_id = 2;
1603 player_->AddAnimation(Animation::Create( 1549 player_->AddAnimation(Animation::Create(
1604 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, 1550 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1,
1605 TargetProperty::TRANSFORM)); 1551 TargetProperty::TRANSFORM));
1606 player_->AddAnimation(Animation::Create( 1552 player_->AddAnimation(Animation::Create(
1607 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), 1553 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)),
1608 animation_id, 1, TargetProperty::OPACITY)); 1554 animation_id, 1, TargetProperty::OPACITY));
1609 player_->AddAnimation(Animation::Create( 1555 player_->AddAnimation(Animation::Create(
1610 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), 1556 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)),
1611 3, 2, TargetProperty::OPACITY)); 1557 3, 2, TargetProperty::OPACITY));
1612 1558
1613 element_animations_->Animate(kInitialTickTime); 1559 player_->Animate(kInitialTickTime);
1614 element_animations_->UpdateState(true, events.get()); 1560 player_->UpdateState(true, events.get());
1615 EXPECT_TRUE(player_->HasActiveAnimation()); 1561 EXPECT_TRUE(player_->HasActiveAnimation());
1616 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1562 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1617 element_animations_->Animate(kInitialTickTime + 1563 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1618 TimeDelta::FromMilliseconds(1000)); 1564 player_->UpdateState(true, events.get());
1619 element_animations_->UpdateState(true, events.get());
1620 EXPECT_TRUE(player_->HasActiveAnimation()); 1565 EXPECT_TRUE(player_->HasActiveAnimation());
1621 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1566 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1622 1567
1623 EXPECT_TRUE(player_->GetAnimationById(animation_id)); 1568 EXPECT_TRUE(player_->GetAnimationById(animation_id));
1624 player_->GetAnimationById(animation_id) 1569 player_->GetAnimationById(animation_id)
1625 ->SetRunState(Animation::ABORTED, 1570 ->SetRunState(Animation::ABORTED,
1626 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1571 kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1627 element_animations_->Animate(kInitialTickTime + 1572 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1628 TimeDelta::FromMilliseconds(1000)); 1573 player_->UpdateState(true, events.get());
1629 element_animations_->UpdateState(true, events.get());
1630 EXPECT_TRUE(player_->HasActiveAnimation()); 1574 EXPECT_TRUE(player_->HasActiveAnimation());
1631 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1575 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1632 element_animations_->Animate(kInitialTickTime + 1576 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1633 TimeDelta::FromMilliseconds(2000)); 1577 player_->UpdateState(true, events.get());
1634 element_animations_->UpdateState(true, events.get());
1635 EXPECT_TRUE(!player_->HasActiveAnimation()); 1578 EXPECT_TRUE(!player_->HasActiveAnimation());
1636 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1579 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1637 } 1580 }
1638 1581
1639 TEST_F(ElementAnimationsTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { 1582 TEST_F(ElementAnimationsTest, PushUpdatesWhenSynchronizedStartTimeNeeded) {
1640 CreateTestLayer(true, false); 1583 CreateTestLayer(true, false);
1641 AttachTimelinePlayerLayer(); 1584 AttachTimelinePlayerLayer();
1642 CreateImplTimelineAndPlayer(); 1585 CreateImplTimelineAndPlayer();
1643 1586
1644 auto events = CreateEventsForTesting(); 1587 auto events = CreateEventsForTesting();
1645 1588
1646 std::unique_ptr<Animation> to_add(CreateAnimation( 1589 std::unique_ptr<Animation> to_add(CreateAnimation(
1647 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), 1590 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)),
1648 0, TargetProperty::OPACITY)); 1591 0, TargetProperty::OPACITY));
1649 to_add->set_needs_synchronized_start_time(true); 1592 to_add->set_needs_synchronized_start_time(true);
1650 player_->AddAnimation(std::move(to_add)); 1593 player_->AddAnimation(std::move(to_add));
1651 1594
1652 element_animations_->Animate(kInitialTickTime); 1595 player_->Animate(kInitialTickTime);
1653 element_animations_->UpdateState(true, events.get()); 1596 player_->UpdateState(true, events.get());
1654 EXPECT_TRUE(player_->HasActiveAnimation()); 1597 EXPECT_TRUE(player_->HasActiveAnimation());
1655 Animation* active_animation = player_->GetAnimation(TargetProperty::OPACITY); 1598 Animation* active_animation = player_->GetAnimation(TargetProperty::OPACITY);
1656 EXPECT_TRUE(active_animation); 1599 EXPECT_TRUE(active_animation);
1657 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); 1600 EXPECT_TRUE(active_animation->needs_synchronized_start_time());
1658 1601
1659 EXPECT_TRUE(player_->needs_push_properties()); 1602 EXPECT_TRUE(player_->needs_push_properties());
1660 PushProperties(); 1603 PushProperties();
1661 player_impl_->ActivateAnimations(); 1604 player_impl_->ActivateAnimations();
1662 1605
1663 active_animation = player_impl_->GetAnimation(TargetProperty::OPACITY); 1606 active_animation = player_impl_->GetAnimation(TargetProperty::OPACITY);
1664 EXPECT_TRUE(active_animation); 1607 EXPECT_TRUE(active_animation);
1665 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 1608 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1666 active_animation->run_state()); 1609 active_animation->run_state());
1667 } 1610 }
1668 1611
1669 // Tests that skipping a call to UpdateState works as expected. 1612 // Tests that skipping a call to UpdateState works as expected.
1670 TEST_F(ElementAnimationsTest, SkipUpdateState) { 1613 TEST_F(ElementAnimationsTest, SkipUpdateState) {
1671 CreateTestLayer(true, false); 1614 CreateTestLayer(true, false);
1672 AttachTimelinePlayerLayer(); 1615 AttachTimelinePlayerLayer();
1673 1616
1674 auto events = CreateEventsForTesting(); 1617 auto events = CreateEventsForTesting();
1675 1618
1676 std::unique_ptr<Animation> first_animation(CreateAnimation( 1619 std::unique_ptr<Animation> first_animation(CreateAnimation(
1677 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1620 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1,
1678 TargetProperty::TRANSFORM)); 1621 TargetProperty::TRANSFORM));
1679 first_animation->set_is_controlling_instance_for_test(true); 1622 first_animation->set_is_controlling_instance_for_test(true);
1680 player_->AddAnimation(std::move(first_animation)); 1623 player_->AddAnimation(std::move(first_animation));
1681 1624
1682 element_animations_->Animate(kInitialTickTime); 1625 player_->Animate(kInitialTickTime);
1683 element_animations_->UpdateState(true, events.get()); 1626 player_->UpdateState(true, events.get());
1684 1627
1685 std::unique_ptr<Animation> second_animation(CreateAnimation( 1628 std::unique_ptr<Animation> second_animation(CreateAnimation(
1686 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1629 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1687 2, TargetProperty::OPACITY)); 1630 2, TargetProperty::OPACITY));
1688 second_animation->set_is_controlling_instance_for_test(true); 1631 second_animation->set_is_controlling_instance_for_test(true);
1689 player_->AddAnimation(std::move(second_animation)); 1632 player_->AddAnimation(std::move(second_animation));
1690 1633
1691 // Animate but don't UpdateState. 1634 // Animate but don't UpdateState.
1692 element_animations_->Animate(kInitialTickTime + 1635 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1693 TimeDelta::FromMilliseconds(1000));
1694 1636
1695 element_animations_->Animate(kInitialTickTime + 1637 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1696 TimeDelta::FromMilliseconds(2000));
1697 events = CreateEventsForTesting(); 1638 events = CreateEventsForTesting();
1698 element_animations_->UpdateState(true, events.get()); 1639 player_->UpdateState(true, events.get());
1699 1640
1700 // Should have one STARTED event and one FINISHED event. 1641 // Should have one STARTED event and one FINISHED event.
1701 EXPECT_EQ(2u, events->events_.size()); 1642 EXPECT_EQ(2u, events->events_.size());
1702 EXPECT_NE(events->events_[0].type, events->events_[1].type); 1643 EXPECT_NE(events->events_[0].type, events->events_[1].type);
1703 1644
1704 // The float transition should still be at its starting point. 1645 // The float transition should still be at its starting point.
1705 EXPECT_TRUE(player_->HasActiveAnimation()); 1646 EXPECT_TRUE(player_->HasActiveAnimation());
1706 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1647 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1707 1648
1708 element_animations_->Animate(kInitialTickTime + 1649 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1709 TimeDelta::FromMilliseconds(3000)); 1650 player_->UpdateState(true, events.get());
1710 element_animations_->UpdateState(true, events.get());
1711 1651
1712 // The float tranisition should now be done. 1652 // The float tranisition should now be done.
1713 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1653 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
1714 EXPECT_FALSE(player_->HasActiveAnimation()); 1654 EXPECT_FALSE(player_->HasActiveAnimation());
1715 } 1655 }
1716 1656
1717 // Tests that an animation animations with only a pending observer gets ticked 1657 // Tests that an animation animations with only a pending observer gets ticked
1718 // but doesn't progress animations past the STARTING state. 1658 // but doesn't progress animations past the STARTING state.
1719 TEST_F(ElementAnimationsTest, InactiveObserverGetsTicked) { 1659 TEST_F(ElementAnimationsTest, InactiveObserverGetsTicked) {
1720 AttachTimelinePlayerLayer(); 1660 AttachTimelinePlayerLayer();
1721 CreateImplTimelineAndPlayer(); 1661 CreateImplTimelineAndPlayer();
1722 1662
1723 auto events = CreateEventsForTesting(); 1663 auto events = CreateEventsForTesting();
1724 1664
1725 const int id = 1; 1665 const int id = 1;
1726 player_impl_->AddAnimation(CreateAnimation( 1666 player_impl_->AddAnimation(CreateAnimation(
1727 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), 1667 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)),
1728 id, TargetProperty::OPACITY)); 1668 id, TargetProperty::OPACITY));
1729 1669
1730 // Without an observer, the animation shouldn't progress to the STARTING 1670 // Without an observer, the animation shouldn't progress to the STARTING
1731 // state. 1671 // state.
1732 element_animations_impl_->Animate(kInitialTickTime); 1672 player_impl_->Animate(kInitialTickTime);
1733 element_animations_impl_->UpdateState(true, events.get()); 1673 player_impl_->UpdateState(true, events.get());
1734 EXPECT_EQ(0u, events->events_.size()); 1674 EXPECT_EQ(0u, events->events_.size());
1735 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 1675 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1736 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); 1676 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state());
1737 1677
1738 CreateTestImplLayer(ElementListType::PENDING); 1678 CreateTestImplLayer(ElementListType::PENDING);
1739 1679
1740 // With only a pending observer, the animation should progress to the 1680 // With only a pending observer, the animation should progress to the
1741 // STARTING state and get ticked at its starting point, but should not 1681 // STARTING state and get ticked at its starting point, but should not
1742 // progress to RUNNING. 1682 // progress to RUNNING.
1743 element_animations_impl_->Animate(kInitialTickTime + 1683 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1744 TimeDelta::FromMilliseconds(1000)); 1684 player_impl_->UpdateState(true, events.get());
1745 element_animations_impl_->UpdateState(true, events.get());
1746 EXPECT_EQ(0u, events->events_.size()); 1685 EXPECT_EQ(0u, events->events_.size());
1747 EXPECT_EQ(Animation::STARTING, 1686 EXPECT_EQ(Animation::STARTING,
1748 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); 1687 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state());
1749 EXPECT_EQ(0.5f, 1688 EXPECT_EQ(0.5f,
1750 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 1689 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
1751 1690
1752 // Even when already in the STARTING state, the animation should stay 1691 // Even when already in the STARTING state, the animation should stay
1753 // there, and shouldn't be ticked past its starting point. 1692 // there, and shouldn't be ticked past its starting point.
1754 element_animations_impl_->Animate(kInitialTickTime + 1693 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1755 TimeDelta::FromMilliseconds(2000)); 1694 player_impl_->UpdateState(true, events.get());
1756 element_animations_impl_->UpdateState(true, events.get());
1757 EXPECT_EQ(0u, events->events_.size()); 1695 EXPECT_EQ(0u, events->events_.size());
1758 EXPECT_EQ(Animation::STARTING, 1696 EXPECT_EQ(Animation::STARTING,
1759 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); 1697 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state());
1760 EXPECT_EQ(0.5f, 1698 EXPECT_EQ(0.5f,
1761 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 1699 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
1762 1700
1763 CreateTestImplLayer(ElementListType::ACTIVE); 1701 CreateTestImplLayer(ElementListType::ACTIVE);
1764 1702
1765 // Now that an active observer has been added, the animation should still 1703 // Now that an active observer has been added, the animation should still
1766 // initially tick at its starting point, but should now progress to RUNNING. 1704 // initially tick at its starting point, but should now progress to RUNNING.
1767 element_animations_impl_->Animate(kInitialTickTime + 1705 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1768 TimeDelta::FromMilliseconds(3000)); 1706 player_impl_->UpdateState(true, events.get());
1769 element_animations_impl_->UpdateState(true, events.get());
1770 EXPECT_EQ(1u, events->events_.size()); 1707 EXPECT_EQ(1u, events->events_.size());
1771 EXPECT_EQ(Animation::RUNNING, 1708 EXPECT_EQ(Animation::RUNNING,
1772 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); 1709 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state());
1773 EXPECT_EQ(0.5f, 1710 EXPECT_EQ(0.5f,
1774 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 1711 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
1775 EXPECT_EQ(0.5f, 1712 EXPECT_EQ(0.5f,
1776 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1713 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
1777 1714
1778 // The animation should now tick past its starting point. 1715 // The animation should now tick past its starting point.
1779 element_animations_impl_->Animate(kInitialTickTime + 1716 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500));
1780 TimeDelta::FromMilliseconds(3500));
1781 EXPECT_NE(0.5f, 1717 EXPECT_NE(0.5f,
1782 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 1718 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
1783 EXPECT_NE(0.5f, 1719 EXPECT_NE(0.5f,
1784 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 1720 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
1785 } 1721 }
1786 1722
1787 TEST_F(ElementAnimationsTest, TransformAnimationBounds) { 1723 TEST_F(ElementAnimationsTest, TransformAnimationBounds) {
1788 AttachTimelinePlayerLayer(); 1724 AttachTimelinePlayerLayer();
1789 CreateImplTimelineAndPlayer(); 1725 CreateImplTimelineAndPlayer();
1790 1726
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 player_->AddAnimation(Animation::Create( 1807 player_->AddAnimation(Animation::Create(
1872 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 3, 3, 1808 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 3, 3,
1873 TargetProperty::TRANSFORM)); 1809 TargetProperty::TRANSFORM));
1874 player_->AddAnimation(Animation::Create( 1810 player_->AddAnimation(Animation::Create(
1875 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 4, 4, 1811 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 4, 4,
1876 TargetProperty::TRANSFORM)); 1812 TargetProperty::TRANSFORM));
1877 player_->AddAnimation(Animation::Create( 1813 player_->AddAnimation(Animation::Create(
1878 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 1814 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1879 5, 5, TargetProperty::OPACITY)); 1815 5, 5, TargetProperty::OPACITY));
1880 1816
1881 element_animations_->Animate(kInitialTickTime); 1817 player_->Animate(kInitialTickTime);
1882 element_animations_->UpdateState(true, nullptr); 1818 player_->UpdateState(true, nullptr);
1883 element_animations_->Animate(kInitialTickTime + 1819 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1884 TimeDelta::FromMilliseconds(1000)); 1820 player_->UpdateState(true, nullptr);
1885 element_animations_->UpdateState(true, nullptr);
1886 1821
1887 EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(1)->run_state()); 1822 EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(1)->run_state());
1888 EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(2)->run_state()); 1823 EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(2)->run_state());
1889 EXPECT_EQ(Animation::RUNNING, player_->GetAnimationById(3)->run_state()); 1824 EXPECT_EQ(Animation::RUNNING, player_->GetAnimationById(3)->run_state());
1890 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 1825 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1891 player_->GetAnimationById(4)->run_state()); 1826 player_->GetAnimationById(4)->run_state());
1892 EXPECT_EQ(Animation::RUNNING, player_->GetAnimationById(5)->run_state()); 1827 EXPECT_EQ(Animation::RUNNING, player_->GetAnimationById(5)->run_state());
1893 1828
1894 player_->AbortAnimations(TargetProperty::TRANSFORM, false); 1829 player_->AbortAnimations(TargetProperty::TRANSFORM, false);
1895 1830
(...skipping 20 matching lines...) Expand all
1916 player_impl_->ActivateAnimations(); 1851 player_impl_->ActivateAnimations();
1917 1852
1918 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); 1853 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
1919 EXPECT_FALSE(host_->needs_push_properties()); 1854 EXPECT_FALSE(host_->needs_push_properties());
1920 1855
1921 player_->AbortAnimations(TargetProperty::OPACITY, false); 1856 player_->AbortAnimations(TargetProperty::OPACITY, false);
1922 EXPECT_EQ(Animation::ABORTED, 1857 EXPECT_EQ(Animation::ABORTED,
1923 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); 1858 player_->GetAnimation(TargetProperty::OPACITY)->run_state());
1924 EXPECT_TRUE(host_->needs_push_properties()); 1859 EXPECT_TRUE(host_->needs_push_properties());
1925 1860
1926 element_animations_->Animate(kInitialTickTime); 1861 player_->Animate(kInitialTickTime);
1927 element_animations_->UpdateState(true, nullptr); 1862 player_->UpdateState(true, nullptr);
1928 EXPECT_EQ(Animation::ABORTED, 1863 EXPECT_EQ(Animation::ABORTED,
1929 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); 1864 player_->GetAnimation(TargetProperty::OPACITY)->run_state());
1930 1865
1931 EXPECT_TRUE(player_->needs_push_properties()); 1866 EXPECT_TRUE(player_->needs_push_properties());
1932 EXPECT_TRUE(player_->needs_push_properties()); 1867 EXPECT_TRUE(player_->needs_push_properties());
1933 EXPECT_TRUE(host_->needs_push_properties()); 1868 EXPECT_TRUE(host_->needs_push_properties());
1934 1869
1935 PushProperties(); 1870 PushProperties();
1936 EXPECT_FALSE(host_->needs_push_properties()); 1871 EXPECT_FALSE(host_->needs_push_properties());
1937 EXPECT_FALSE(player_->needs_push_properties()); 1872 EXPECT_FALSE(player_->needs_push_properties());
(...skipping 20 matching lines...) Expand all
1958 player_impl_->ActivateAnimations(); 1893 player_impl_->ActivateAnimations();
1959 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); 1894 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
1960 1895
1961 player_impl_->AbortAnimations(TargetProperty::OPACITY, false); 1896 player_impl_->AbortAnimations(TargetProperty::OPACITY, false);
1962 EXPECT_EQ(Animation::ABORTED, 1897 EXPECT_EQ(Animation::ABORTED,
1963 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); 1898 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state());
1964 EXPECT_TRUE(host_impl_->needs_push_properties()); 1899 EXPECT_TRUE(host_impl_->needs_push_properties());
1965 EXPECT_TRUE(player_impl_->needs_push_properties()); 1900 EXPECT_TRUE(player_impl_->needs_push_properties());
1966 1901
1967 auto events = CreateEventsForTesting(); 1902 auto events = CreateEventsForTesting();
1968 element_animations_impl_->Animate(kInitialTickTime); 1903 player_impl_->Animate(kInitialTickTime);
1969 element_animations_impl_->UpdateState(true, events.get()); 1904 player_impl_->UpdateState(true, events.get());
1970 EXPECT_TRUE(host_impl_->needs_push_properties()); 1905 EXPECT_TRUE(host_impl_->needs_push_properties());
1971 EXPECT_EQ(1u, events->events_.size()); 1906 EXPECT_EQ(1u, events->events_.size());
1972 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[0].type); 1907 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[0].type);
1973 EXPECT_EQ(Animation::WAITING_FOR_DELETION, 1908 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
1974 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); 1909 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state());
1975 1910
1976 player_->NotifyAnimationAborted(events->events_[0]); 1911 player_->NotifyAnimationAborted(events->events_[0]);
1977 EXPECT_EQ(Animation::ABORTED, 1912 EXPECT_EQ(Animation::ABORTED,
1978 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); 1913 player_->GetAnimation(TargetProperty::OPACITY)->run_state());
1979 EXPECT_TRUE(delegate.aborted()); 1914 EXPECT_TRUE(delegate.aborted());
1980 1915
1981 element_animations_->Animate(kInitialTickTime + 1916 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
1982 TimeDelta::FromMilliseconds(500)); 1917 player_->UpdateState(true, nullptr);
1983 element_animations_->UpdateState(true, nullptr);
1984 EXPECT_TRUE(host_->needs_push_properties()); 1918 EXPECT_TRUE(host_->needs_push_properties());
1985 EXPECT_EQ(Animation::WAITING_FOR_DELETION, 1919 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
1986 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); 1920 player_->GetAnimation(TargetProperty::OPACITY)->run_state());
1987 1921
1988 PushProperties(); 1922 PushProperties();
1989 1923
1990 player_impl_->ActivateAnimations(); 1924 player_impl_->ActivateAnimations();
1991 EXPECT_FALSE(player_->GetAnimationById(animation_id)); 1925 EXPECT_FALSE(player_->GetAnimationById(animation_id));
1992 EXPECT_FALSE(player_impl_->GetAnimationById(animation_id)); 1926 EXPECT_FALSE(player_impl_->GetAnimationById(animation_id));
1993 } 1927 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 player_impl_->ActivateAnimations(); 1959 player_impl_->ActivateAnimations();
2026 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); 1960 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
2027 1961
2028 player_impl_->AbortAnimations(TargetProperty::SCROLL_OFFSET, true); 1962 player_impl_->AbortAnimations(TargetProperty::SCROLL_OFFSET, true);
2029 EXPECT_TRUE(host_impl_->needs_push_properties()); 1963 EXPECT_TRUE(host_impl_->needs_push_properties());
2030 EXPECT_EQ( 1964 EXPECT_EQ(
2031 Animation::ABORTED_BUT_NEEDS_COMPLETION, 1965 Animation::ABORTED_BUT_NEEDS_COMPLETION,
2032 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); 1966 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state());
2033 1967
2034 auto events = CreateEventsForTesting(); 1968 auto events = CreateEventsForTesting();
2035 element_animations_impl_->Animate(kInitialTickTime); 1969 player_impl_->Animate(kInitialTickTime);
2036 element_animations_impl_->UpdateState(true, events.get()); 1970 player_impl_->UpdateState(true, events.get());
2037 EXPECT_TRUE(delegate_impl.finished()); 1971 EXPECT_TRUE(delegate_impl.finished());
2038 EXPECT_TRUE(host_impl_->needs_push_properties()); 1972 EXPECT_TRUE(host_impl_->needs_push_properties());
2039 EXPECT_EQ(1u, events->events_.size()); 1973 EXPECT_EQ(1u, events->events_.size());
2040 EXPECT_EQ(AnimationEvent::TAKEOVER, events->events_[0].type); 1974 EXPECT_EQ(AnimationEvent::TAKEOVER, events->events_[0].type);
2041 EXPECT_EQ(123, events->events_[0].animation_start_time); 1975 EXPECT_EQ(123, events->events_[0].animation_start_time);
2042 EXPECT_EQ( 1976 EXPECT_EQ(
2043 target_value, 1977 target_value,
2044 events->events_[0].curve->ToScrollOffsetAnimationCurve()->target_value()); 1978 events->events_[0].curve->ToScrollOffsetAnimationCurve()->target_value());
2045 EXPECT_EQ( 1979 EXPECT_EQ(
2046 Animation::WAITING_FOR_DELETION, 1980 Animation::WAITING_FOR_DELETION,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 group_id, TargetProperty::TRANSFORM)); 2014 group_id, TargetProperty::TRANSFORM));
2081 first_animation->set_is_controlling_instance_for_test(true); 2015 first_animation->set_is_controlling_instance_for_test(true);
2082 player_impl_->AddAnimation(std::move(first_animation)); 2016 player_impl_->AddAnimation(std::move(first_animation));
2083 2017
2084 std::unique_ptr<Animation> second_animation(Animation::Create( 2018 std::unique_ptr<Animation> second_animation(Animation::Create(
2085 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 2019 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
2086 2, group_id, TargetProperty::OPACITY)); 2020 2, group_id, TargetProperty::OPACITY));
2087 second_animation->set_is_controlling_instance_for_test(true); 2021 second_animation->set_is_controlling_instance_for_test(true);
2088 player_impl_->AddAnimation(std::move(second_animation)); 2022 player_impl_->AddAnimation(std::move(second_animation));
2089 2023
2090 element_animations_impl_->Animate(kInitialTickTime); 2024 player_impl_->Animate(kInitialTickTime);
2091 element_animations_impl_->UpdateState(true, events.get()); 2025 player_impl_->UpdateState(true, events.get());
2092 2026
2093 // Both animations should have started. 2027 // Both animations should have started.
2094 EXPECT_EQ(2u, events->events_.size()); 2028 EXPECT_EQ(2u, events->events_.size());
2095 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); 2029 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
2096 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); 2030 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type);
2097 2031
2098 events = CreateEventsForTesting(); 2032 events = CreateEventsForTesting();
2099 element_animations_impl_->Animate(kInitialTickTime + 2033 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2100 TimeDelta::FromMilliseconds(1000)); 2034 player_impl_->UpdateState(true, events.get());
2101 element_animations_impl_->UpdateState(true, events.get());
2102 2035
2103 // The opacity animation should be finished, but should not have generated 2036 // The opacity animation should be finished, but should not have generated
2104 // a FINISHED event yet. 2037 // a FINISHED event yet.
2105 EXPECT_EQ(0u, events->events_.size()); 2038 EXPECT_EQ(0u, events->events_.size());
2106 EXPECT_EQ(Animation::FINISHED, 2039 EXPECT_EQ(Animation::FINISHED,
2107 player_impl_->GetAnimationById(2)->run_state()); 2040 player_impl_->GetAnimationById(2)->run_state());
2108 EXPECT_EQ(Animation::RUNNING, player_impl_->GetAnimationById(1)->run_state()); 2041 EXPECT_EQ(Animation::RUNNING, player_impl_->GetAnimationById(1)->run_state());
2109 2042
2110 element_animations_impl_->Animate(kInitialTickTime + 2043 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
2111 TimeDelta::FromMilliseconds(2000)); 2044 player_impl_->UpdateState(true, events.get());
2112 element_animations_impl_->UpdateState(true, events.get());
2113 2045
2114 // Both animations should have generated FINISHED events. 2046 // Both animations should have generated FINISHED events.
2115 EXPECT_EQ(2u, events->events_.size()); 2047 EXPECT_EQ(2u, events->events_.size());
2116 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); 2048 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type);
2117 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[1].type); 2049 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[1].type);
2118 } 2050 }
2119 2051
2120 // Ensure that when a group has a mix of aborted and finished animations, 2052 // Ensure that when a group has a mix of aborted and finished animations,
2121 // we generate a FINISHED event for the finished animation and an ABORTED 2053 // we generate a FINISHED event for the finished animation and an ABORTED
2122 // event for the aborted animation. 2054 // event for the aborted animation.
(...skipping 10 matching lines...) Expand all
2133 TargetProperty::TRANSFORM)); 2065 TargetProperty::TRANSFORM));
2134 first_animation->set_is_controlling_instance_for_test(true); 2066 first_animation->set_is_controlling_instance_for_test(true);
2135 player_impl_->AddAnimation(std::move(first_animation)); 2067 player_impl_->AddAnimation(std::move(first_animation));
2136 2068
2137 std::unique_ptr<Animation> second_animation(CreateAnimation( 2069 std::unique_ptr<Animation> second_animation(CreateAnimation(
2138 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 2070 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
2139 1, TargetProperty::OPACITY)); 2071 1, TargetProperty::OPACITY));
2140 second_animation->set_is_controlling_instance_for_test(true); 2072 second_animation->set_is_controlling_instance_for_test(true);
2141 player_impl_->AddAnimation(std::move(second_animation)); 2073 player_impl_->AddAnimation(std::move(second_animation));
2142 2074
2143 element_animations_impl_->Animate(kInitialTickTime); 2075 player_impl_->Animate(kInitialTickTime);
2144 element_animations_impl_->UpdateState(true, events.get()); 2076 player_impl_->UpdateState(true, events.get());
2145 2077
2146 // Both animations should have started. 2078 // Both animations should have started.
2147 EXPECT_EQ(2u, events->events_.size()); 2079 EXPECT_EQ(2u, events->events_.size());
2148 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); 2080 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
2149 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); 2081 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type);
2150 2082
2151 player_impl_->AbortAnimations(TargetProperty::OPACITY, false); 2083 player_impl_->AbortAnimations(TargetProperty::OPACITY, false);
2152 2084
2153 events = CreateEventsForTesting(); 2085 events = CreateEventsForTesting();
2154 element_animations_impl_->Animate(kInitialTickTime + 2086 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2155 TimeDelta::FromMilliseconds(1000)); 2087 player_impl_->UpdateState(true, events.get());
2156 element_animations_impl_->UpdateState(true, events.get());
2157 2088
2158 // We should have exactly 2 events: a FINISHED event for the tranform 2089 // We should have exactly 2 events: a FINISHED event for the tranform
2159 // animation, and an ABORTED event for the opacity animation. 2090 // animation, and an ABORTED event for the opacity animation.
2160 EXPECT_EQ(2u, events->events_.size()); 2091 EXPECT_EQ(2u, events->events_.size());
2161 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); 2092 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type);
2162 EXPECT_EQ(TargetProperty::TRANSFORM, events->events_[0].target_property); 2093 EXPECT_EQ(TargetProperty::TRANSFORM, events->events_[0].target_property);
2163 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[1].type); 2094 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[1].type);
2164 EXPECT_EQ(TargetProperty::OPACITY, events->events_[1].target_property); 2095 EXPECT_EQ(TargetProperty::OPACITY, events->events_[1].target_property);
2165 } 2096 }
2166 2097
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
2579 EXPECT_TRUE(player_impl_->needs_to_start_animations()); 2510 EXPECT_TRUE(player_impl_->needs_to_start_animations());
2580 2511
2581 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); 2512 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
2582 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 2513 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
2583 player_impl_->GetAnimationById(animation_id)->run_state()); 2514 player_impl_->GetAnimationById(animation_id)->run_state());
2584 EXPECT_TRUE( 2515 EXPECT_TRUE(
2585 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); 2516 player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
2586 EXPECT_FALSE( 2517 EXPECT_FALSE(
2587 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); 2518 player_impl_->GetAnimationById(animation_id)->affects_active_elements());
2588 2519
2589 element_animations_impl_->Animate(kInitialTickTime); 2520 player_impl_->Animate(kInitialTickTime);
2590 EXPECT_FALSE(player_impl_->needs_to_start_animations()); 2521 EXPECT_FALSE(player_impl_->needs_to_start_animations());
2591 element_animations_impl_->UpdateState(true, events.get()); 2522 player_impl_->UpdateState(true, events.get());
2592 2523
2593 // Since the animation hasn't been activated, it should still be STARTING 2524 // Since the animation hasn't been activated, it should still be STARTING
2594 // rather than RUNNING. 2525 // rather than RUNNING.
2595 EXPECT_EQ(Animation::STARTING, 2526 EXPECT_EQ(Animation::STARTING,
2596 player_impl_->GetAnimationById(animation_id)->run_state()); 2527 player_impl_->GetAnimationById(animation_id)->run_state());
2597 2528
2598 // Since the animation hasn't been activated, only the pending observer 2529 // Since the animation hasn't been activated, only the pending observer
2599 // should have been ticked. 2530 // should have been ticked.
2600 EXPECT_EQ(0.5f, 2531 EXPECT_EQ(0.5f,
2601 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 2532 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
2602 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 2533 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
2603 2534
2604 player_impl_->ActivateAnimations(); 2535 player_impl_->ActivateAnimations();
2605 EXPECT_TRUE( 2536 EXPECT_TRUE(
2606 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); 2537 player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
2607 EXPECT_TRUE( 2538 EXPECT_TRUE(
2608 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); 2539 player_impl_->GetAnimationById(animation_id)->affects_active_elements());
2609 2540
2610 element_animations_impl_->Animate(kInitialTickTime + 2541 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2611 TimeDelta::FromMilliseconds(1000)); 2542 player_impl_->UpdateState(true, events.get());
2612 element_animations_impl_->UpdateState(true, events.get());
2613 2543
2614 // Since the animation has been activated, it should have reached the 2544 // Since the animation has been activated, it should have reached the
2615 // RUNNING state and the active observer should start to get ticked. 2545 // RUNNING state and the active observer should start to get ticked.
2616 EXPECT_EQ(Animation::RUNNING, 2546 EXPECT_EQ(Animation::RUNNING,
2617 player_impl_->GetAnimationById(animation_id)->run_state()); 2547 player_impl_->GetAnimationById(animation_id)->run_state());
2618 EXPECT_EQ(0.5f, 2548 EXPECT_EQ(0.5f,
2619 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 2549 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
2620 EXPECT_EQ(0.5f, 2550 EXPECT_EQ(0.5f,
2621 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 2551 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
2622 } 2552 }
(...skipping 11 matching lines...) Expand all
2634 PushProperties(); 2564 PushProperties();
2635 2565
2636 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); 2566 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
2637 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 2567 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
2638 player_impl_->GetAnimationById(animation_id)->run_state()); 2568 player_impl_->GetAnimationById(animation_id)->run_state());
2639 EXPECT_TRUE( 2569 EXPECT_TRUE(
2640 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); 2570 player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
2641 EXPECT_FALSE( 2571 EXPECT_FALSE(
2642 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); 2572 player_impl_->GetAnimationById(animation_id)->affects_active_elements());
2643 2573
2644 element_animations_impl_->Animate(kInitialTickTime); 2574 player_impl_->Animate(kInitialTickTime);
2645 2575
2646 // Since the animation hasn't been activated, only the pending observer 2576 // Since the animation hasn't been activated, only the pending observer
2647 // should have been ticked. 2577 // should have been ticked.
2648 EXPECT_EQ(0.5f, 2578 EXPECT_EQ(0.5f,
2649 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 2579 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
2650 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 2580 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
2651 2581
2652 player_impl_->ActivateAnimations(); 2582 player_impl_->ActivateAnimations();
2653 EXPECT_TRUE( 2583 EXPECT_TRUE(
2654 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); 2584 player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
2655 EXPECT_TRUE( 2585 EXPECT_TRUE(
2656 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); 2586 player_impl_->GetAnimationById(animation_id)->affects_active_elements());
2657 2587
2658 element_animations_impl_->UpdateState(true, events.get()); 2588 player_impl_->UpdateState(true, events.get());
2659 2589
2660 // Since the animation has been activated, it should have reached the 2590 // Since the animation has been activated, it should have reached the
2661 // RUNNING state. 2591 // RUNNING state.
2662 EXPECT_EQ(Animation::RUNNING, 2592 EXPECT_EQ(Animation::RUNNING,
2663 player_impl_->GetAnimationById(animation_id)->run_state()); 2593 player_impl_->GetAnimationById(animation_id)->run_state());
2664 2594
2665 element_animations_impl_->Animate(kInitialTickTime + 2595 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
2666 TimeDelta::FromMilliseconds(500));
2667 2596
2668 // Both elements should have been ticked. 2597 // Both elements should have been ticked.
2669 EXPECT_EQ(0.75f, 2598 EXPECT_EQ(0.75f,
2670 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 2599 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
2671 EXPECT_EQ(0.75f, 2600 EXPECT_EQ(0.75f,
2672 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 2601 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
2673 } 2602 }
2674 2603
2675 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenTransformAnimationChanges) { 2604 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenTransformAnimationChanges) {
2676 CreateTestLayer(true, true); 2605 CreateTestLayer(true, true);
(...skipping 25 matching lines...) Expand all
2702 PushProperties(); 2631 PushProperties();
2703 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2632 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2704 element_id_, ElementListType::PENDING)); 2633 element_id_, ElementListType::PENDING));
2705 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2634 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2706 element_id_, ElementListType::PENDING)); 2635 element_id_, ElementListType::PENDING));
2707 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2636 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2708 element_id_, ElementListType::ACTIVE)); 2637 element_id_, ElementListType::ACTIVE));
2709 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2638 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2710 element_id_, ElementListType::ACTIVE)); 2639 element_id_, ElementListType::ACTIVE));
2711 2640
2712 element_animations_impl_->ActivateAnimations(); 2641 player_impl_->ActivateAnimations();
2713 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2642 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2714 element_id_, ElementListType::PENDING)); 2643 element_id_, ElementListType::PENDING));
2715 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2644 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2716 element_id_, ElementListType::PENDING)); 2645 element_id_, ElementListType::PENDING));
2717 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2646 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2718 element_id_, ElementListType::ACTIVE)); 2647 element_id_, ElementListType::ACTIVE));
2719 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2648 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2720 element_id_, ElementListType::ACTIVE)); 2649 element_id_, ElementListType::ACTIVE));
2721 2650
2722 element_animations_impl_->Animate(kInitialTickTime); 2651 player_impl_->Animate(kInitialTickTime);
2723 element_animations_impl_->UpdateState(true, events.get()); 2652 player_impl_->UpdateState(true, events.get());
2724 2653
2725 player_->NotifyAnimationStarted(events->events_[0]); 2654 player_->NotifyAnimationStarted(events->events_[0]);
2726 events->events_.clear(); 2655 events->events_.clear();
2727 2656
2728 // Finish the animation. 2657 // Finish the animation.
2729 element_animations_->Animate(kInitialTickTime + 2658 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2730 TimeDelta::FromMilliseconds(1000)); 2659 player_->UpdateState(true, nullptr);
2731 element_animations_->UpdateState(true, nullptr);
2732 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( 2660 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation(
2733 element_id_, ElementListType::ACTIVE)); 2661 element_id_, ElementListType::ACTIVE));
2734 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( 2662 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating(
2735 element_id_, ElementListType::ACTIVE)); 2663 element_id_, ElementListType::ACTIVE));
2736 2664
2737 PushProperties(); 2665 PushProperties();
2738 2666
2739 // animations_impl hasn't yet ticked at/past the end of the animation. 2667 // animations_impl hasn't yet ticked at/past the end of the animation.
2740 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2668 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2741 element_id_, ElementListType::PENDING)); 2669 element_id_, ElementListType::PENDING));
2742 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2670 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2743 element_id_, ElementListType::PENDING)); 2671 element_id_, ElementListType::PENDING));
2744 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2672 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2745 element_id_, ElementListType::ACTIVE)); 2673 element_id_, ElementListType::ACTIVE));
2746 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2674 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2747 element_id_, ElementListType::ACTIVE)); 2675 element_id_, ElementListType::ACTIVE));
2748 2676
2749 element_animations_impl_->Animate(kInitialTickTime + 2677 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2750 TimeDelta::FromMilliseconds(1000)); 2678 player_impl_->UpdateState(true, events.get());
2751 element_animations_impl_->UpdateState(true, events.get());
2752 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2679 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2753 element_id_, ElementListType::PENDING)); 2680 element_id_, ElementListType::PENDING));
2754 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2681 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2755 element_id_, ElementListType::PENDING)); 2682 element_id_, ElementListType::PENDING));
2756 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2683 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2757 element_id_, ElementListType::ACTIVE)); 2684 element_id_, ElementListType::ACTIVE));
2758 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2685 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2759 element_id_, ElementListType::ACTIVE)); 2686 element_id_, ElementListType::ACTIVE));
2760 2687
2761 // Case 2: An animation that's removed before it finishes. 2688 // Case 2: An animation that's removed before it finishes.
(...skipping 11 matching lines...) Expand all
2773 PushProperties(); 2700 PushProperties();
2774 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2701 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2775 element_id_, ElementListType::PENDING)); 2702 element_id_, ElementListType::PENDING));
2776 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2703 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2777 element_id_, ElementListType::PENDING)); 2704 element_id_, ElementListType::PENDING));
2778 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2705 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2779 element_id_, ElementListType::ACTIVE)); 2706 element_id_, ElementListType::ACTIVE));
2780 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2707 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2781 element_id_, ElementListType::ACTIVE)); 2708 element_id_, ElementListType::ACTIVE));
2782 2709
2783 element_animations_impl_->ActivateAnimations(); 2710 player_impl_->ActivateAnimations();
2784 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2711 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2785 element_id_, ElementListType::ACTIVE)); 2712 element_id_, ElementListType::ACTIVE));
2786 // animation1 is in effect currently and animation2 isn't. As the element has 2713 // animation1 is in effect currently and animation2 isn't. As the element has
2787 // atleast one animation that's in effect currently, client should be notified 2714 // atleast one animation that's in effect currently, client should be notified
2788 // that the transform is currently animating. 2715 // that the transform is currently animating.
2789 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2716 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2790 element_id_, ElementListType::ACTIVE)); 2717 element_id_, ElementListType::ACTIVE));
2791 2718
2792 element_animations_impl_->Animate(kInitialTickTime + 2719 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
2793 TimeDelta::FromMilliseconds(2000)); 2720 player_impl_->UpdateState(true, events.get());
2794 element_animations_impl_->UpdateState(true, events.get());
2795 2721
2796 player_->NotifyAnimationStarted(events->events_[0]); 2722 player_->NotifyAnimationStarted(events->events_[0]);
2797 events->events_.clear(); 2723 events->events_.clear();
2798 2724
2799 player_->RemoveAnimation(animation_id); 2725 player_->RemoveAnimation(animation_id);
2800 player_->RemoveAnimation(animation2_id); 2726 player_->RemoveAnimation(animation2_id);
2801 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( 2727 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation(
2802 element_id_, ElementListType::ACTIVE)); 2728 element_id_, ElementListType::ACTIVE));
2803 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( 2729 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating(
2804 element_id_, ElementListType::ACTIVE)); 2730 element_id_, ElementListType::ACTIVE));
2805 2731
2806 PushProperties(); 2732 PushProperties();
2807 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2733 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2808 element_id_, ElementListType::PENDING)); 2734 element_id_, ElementListType::PENDING));
2809 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2735 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2810 element_id_, ElementListType::PENDING)); 2736 element_id_, ElementListType::PENDING));
2811 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2737 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2812 element_id_, ElementListType::ACTIVE)); 2738 element_id_, ElementListType::ACTIVE));
2813 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2739 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2814 element_id_, ElementListType::ACTIVE)); 2740 element_id_, ElementListType::ACTIVE));
2815 2741
2816 element_animations_impl_->ActivateAnimations(); 2742 player_impl_->ActivateAnimations();
2817 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2743 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2818 element_id_, ElementListType::ACTIVE)); 2744 element_id_, ElementListType::ACTIVE));
2819 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2745 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2820 element_id_, ElementListType::ACTIVE)); 2746 element_id_, ElementListType::ACTIVE));
2821 2747
2822 // Case 3: An animation that's aborted before it finishes. 2748 // Case 3: An animation that's aborted before it finishes.
2823 animation_id = AddAnimatedTransformToPlayer(player_.get(), 10.0, 3, 3); 2749 animation_id = AddAnimatedTransformToPlayer(player_.get(), 10.0, 3, 3);
2824 EXPECT_TRUE(client_.GetHasPotentialTransformAnimation( 2750 EXPECT_TRUE(client_.GetHasPotentialTransformAnimation(
2825 element_id_, ElementListType::ACTIVE)); 2751 element_id_, ElementListType::ACTIVE));
2826 EXPECT_TRUE(client_.GetTransformIsCurrentlyAnimating( 2752 EXPECT_TRUE(client_.GetTransformIsCurrentlyAnimating(
2827 element_id_, ElementListType::ACTIVE)); 2753 element_id_, ElementListType::ACTIVE));
2828 2754
2829 PushProperties(); 2755 PushProperties();
2830 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2756 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2831 element_id_, ElementListType::PENDING)); 2757 element_id_, ElementListType::PENDING));
2832 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2758 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2833 element_id_, ElementListType::PENDING)); 2759 element_id_, ElementListType::PENDING));
2834 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2760 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2835 element_id_, ElementListType::ACTIVE)); 2761 element_id_, ElementListType::ACTIVE));
2836 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2762 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2837 element_id_, ElementListType::ACTIVE)); 2763 element_id_, ElementListType::ACTIVE));
2838 2764
2839 element_animations_impl_->ActivateAnimations(); 2765 player_impl_->ActivateAnimations();
2840 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2766 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2841 element_id_, ElementListType::ACTIVE)); 2767 element_id_, ElementListType::ACTIVE));
2842 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2768 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2843 element_id_, ElementListType::ACTIVE)); 2769 element_id_, ElementListType::ACTIVE));
2844 2770
2845 element_animations_impl_->Animate(kInitialTickTime + 2771 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
2846 TimeDelta::FromMilliseconds(2000)); 2772 player_impl_->UpdateState(true, events.get());
2847 element_animations_impl_->UpdateState(true, events.get());
2848 2773
2849 player_->NotifyAnimationStarted(events->events_[0]); 2774 player_->NotifyAnimationStarted(events->events_[0]);
2850 events->events_.clear(); 2775 events->events_.clear();
2851 2776
2852 player_impl_->AbortAnimations(TargetProperty::TRANSFORM, false); 2777 player_impl_->AbortAnimations(TargetProperty::TRANSFORM, false);
2853 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2778 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2854 element_id_, ElementListType::PENDING)); 2779 element_id_, ElementListType::PENDING));
2855 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2780 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2856 element_id_, ElementListType::PENDING)); 2781 element_id_, ElementListType::PENDING));
2857 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2782 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2858 element_id_, ElementListType::ACTIVE)); 2783 element_id_, ElementListType::ACTIVE));
2859 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2784 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2860 element_id_, ElementListType::ACTIVE)); 2785 element_id_, ElementListType::ACTIVE));
2861 2786
2862 element_animations_impl_->Animate(kInitialTickTime + 2787 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000));
2863 TimeDelta::FromMilliseconds(4000)); 2788 player_impl_->UpdateState(true, events.get());
2864 element_animations_impl_->UpdateState(true, events.get());
2865 2789
2866 element_animations_->NotifyAnimationAborted(events->events_[0]); 2790 element_animations_->NotifyAnimationAborted(events->events_[0]);
2867 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( 2791 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation(
2868 element_id_, ElementListType::ACTIVE)); 2792 element_id_, ElementListType::ACTIVE));
2869 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( 2793 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating(
2870 element_id_, ElementListType::ACTIVE)); 2794 element_id_, ElementListType::ACTIVE));
2871 2795
2872 // Case 4 : An animation that's not in effect. 2796 // Case 4 : An animation that's not in effect.
2873 animation_id = AddAnimatedTransformToPlayer(player_.get(), 1.0, 1, 6); 2797 animation_id = AddAnimatedTransformToPlayer(player_.get(), 1.0, 1, 6);
2874 player_->GetAnimationById(animation_id) 2798 player_->GetAnimationById(animation_id)
2875 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); 2799 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000));
2876 player_->GetAnimationById(animation_id) 2800 player_->GetAnimationById(animation_id)
2877 ->set_fill_mode(Animation::FillMode::NONE); 2801 ->set_fill_mode(Animation::FillMode::NONE);
2878 2802
2879 PushProperties(); 2803 PushProperties();
2880 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2804 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2881 element_id_, ElementListType::PENDING)); 2805 element_id_, ElementListType::PENDING));
2882 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2806 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2883 element_id_, ElementListType::PENDING)); 2807 element_id_, ElementListType::PENDING));
2884 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2808 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2885 element_id_, ElementListType::ACTIVE)); 2809 element_id_, ElementListType::ACTIVE));
2886 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2810 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2887 element_id_, ElementListType::ACTIVE)); 2811 element_id_, ElementListType::ACTIVE));
2888 2812
2889 element_animations_impl_->ActivateAnimations(); 2813 player_impl_->ActivateAnimations();
2890 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2814 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2891 element_id_, ElementListType::ACTIVE)); 2815 element_id_, ElementListType::ACTIVE));
2892 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( 2816 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2893 element_id_, ElementListType::ACTIVE)); 2817 element_id_, ElementListType::ACTIVE));
2894 } 2818 }
2895 2819
2896 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenOpacityAnimationChanges) { 2820 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenOpacityAnimationChanges) {
2897 CreateTestLayer(true, true); 2821 CreateTestLayer(true, true);
2898 AttachTimelinePlayerLayer(); 2822 AttachTimelinePlayerLayer();
2899 CreateImplTimelineAndPlayer(); 2823 CreateImplTimelineAndPlayer();
(...skipping 24 matching lines...) Expand all
2924 PushProperties(); 2848 PushProperties();
2925 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2849 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2926 element_id_, ElementListType::PENDING)); 2850 element_id_, ElementListType::PENDING));
2927 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2851 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2928 element_id_, ElementListType::PENDING)); 2852 element_id_, ElementListType::PENDING));
2929 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 2853 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
2930 element_id_, ElementListType::ACTIVE)); 2854 element_id_, ElementListType::ACTIVE));
2931 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 2855 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
2932 element_id_, ElementListType::ACTIVE)); 2856 element_id_, ElementListType::ACTIVE));
2933 2857
2934 element_animations_impl_->ActivateAnimations(); 2858 player_impl_->ActivateAnimations();
2935 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2859 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2936 element_id_, ElementListType::PENDING)); 2860 element_id_, ElementListType::PENDING));
2937 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2861 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2938 element_id_, ElementListType::PENDING)); 2862 element_id_, ElementListType::PENDING));
2939 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2863 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2940 element_id_, ElementListType::ACTIVE)); 2864 element_id_, ElementListType::ACTIVE));
2941 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2865 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2942 element_id_, ElementListType::ACTIVE)); 2866 element_id_, ElementListType::ACTIVE));
2943 2867
2944 element_animations_impl_->Animate(kInitialTickTime); 2868 player_impl_->Animate(kInitialTickTime);
2945 element_animations_impl_->UpdateState(true, events.get()); 2869 player_impl_->UpdateState(true, events.get());
2946 2870
2947 player_->NotifyAnimationStarted(events->events_[0]); 2871 player_->NotifyAnimationStarted(events->events_[0]);
2948 events->events_.clear(); 2872 events->events_.clear();
2949 2873
2950 // Finish the animation. 2874 // Finish the animation.
2951 element_animations_->Animate(kInitialTickTime + 2875 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2952 TimeDelta::FromMilliseconds(1000)); 2876 player_->UpdateState(true, nullptr);
2953 element_animations_->UpdateState(true, nullptr);
2954 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( 2877 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
2955 element_id_, ElementListType::ACTIVE)); 2878 element_id_, ElementListType::ACTIVE));
2956 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, 2879 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
2957 ElementListType::ACTIVE)); 2880 ElementListType::ACTIVE));
2958 2881
2959 PushProperties(); 2882 PushProperties();
2960 2883
2961 // animations_impl hasn't yet ticked at/past the end of the animation. 2884 // animations_impl hasn't yet ticked at/past the end of the animation.
2962 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2885 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2963 element_id_, ElementListType::PENDING)); 2886 element_id_, ElementListType::PENDING));
2964 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2887 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2965 element_id_, ElementListType::PENDING)); 2888 element_id_, ElementListType::PENDING));
2966 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2889 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2967 element_id_, ElementListType::ACTIVE)); 2890 element_id_, ElementListType::ACTIVE));
2968 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2891 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2969 element_id_, ElementListType::ACTIVE)); 2892 element_id_, ElementListType::ACTIVE));
2970 2893
2971 element_animations_impl_->Animate(kInitialTickTime + 2894 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2972 TimeDelta::FromMilliseconds(1000)); 2895 player_impl_->UpdateState(true, events.get());
2973 element_animations_impl_->UpdateState(true, events.get());
2974 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 2896 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
2975 element_id_, ElementListType::PENDING)); 2897 element_id_, ElementListType::PENDING));
2976 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 2898 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
2977 element_id_, ElementListType::PENDING)); 2899 element_id_, ElementListType::PENDING));
2978 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 2900 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
2979 element_id_, ElementListType::ACTIVE)); 2901 element_id_, ElementListType::ACTIVE));
2980 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 2902 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
2981 element_id_, ElementListType::ACTIVE)); 2903 element_id_, ElementListType::ACTIVE));
2982 2904
2983 // Case 2: An animation that's removed before it finishes. 2905 // Case 2: An animation that's removed before it finishes.
2984 int animation_id = AddOpacityTransitionToPlayer( 2906 int animation_id = AddOpacityTransitionToPlayer(
2985 player_.get(), 10.0, 0.f, 1.f, false /*use_timing_function*/); 2907 player_.get(), 10.0, 0.f, 1.f, false /*use_timing_function*/);
2986 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_, 2908 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_,
2987 ElementListType::ACTIVE)); 2909 ElementListType::ACTIVE));
2988 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_, 2910 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
2989 ElementListType::ACTIVE)); 2911 ElementListType::ACTIVE));
2990 2912
2991 PushProperties(); 2913 PushProperties();
2992 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2914 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2993 element_id_, ElementListType::PENDING)); 2915 element_id_, ElementListType::PENDING));
2994 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2916 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2995 element_id_, ElementListType::PENDING)); 2917 element_id_, ElementListType::PENDING));
2996 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 2918 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
2997 element_id_, ElementListType::ACTIVE)); 2919 element_id_, ElementListType::ACTIVE));
2998 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 2920 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
2999 element_id_, ElementListType::ACTIVE)); 2921 element_id_, ElementListType::ACTIVE));
3000 2922
3001 element_animations_impl_->ActivateAnimations(); 2923 player_impl_->ActivateAnimations();
3002 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2924 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3003 element_id_, ElementListType::ACTIVE)); 2925 element_id_, ElementListType::ACTIVE));
3004 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2926 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
3005 element_id_, ElementListType::ACTIVE)); 2927 element_id_, ElementListType::ACTIVE));
3006 2928
3007 element_animations_impl_->Animate(kInitialTickTime + 2929 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
3008 TimeDelta::FromMilliseconds(2000)); 2930 player_impl_->UpdateState(true, events.get());
3009 element_animations_impl_->UpdateState(true, events.get());
3010 2931
3011 player_->NotifyAnimationStarted(events->events_[0]); 2932 player_->NotifyAnimationStarted(events->events_[0]);
3012 events->events_.clear(); 2933 events->events_.clear();
3013 2934
3014 player_->RemoveAnimation(animation_id); 2935 player_->RemoveAnimation(animation_id);
3015 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( 2936 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
3016 element_id_, ElementListType::ACTIVE)); 2937 element_id_, ElementListType::ACTIVE));
3017 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, 2938 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
3018 ElementListType::ACTIVE)); 2939 ElementListType::ACTIVE));
3019 2940
3020 PushProperties(); 2941 PushProperties();
3021 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 2942 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3022 element_id_, ElementListType::PENDING)); 2943 element_id_, ElementListType::PENDING));
3023 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 2944 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3024 element_id_, ElementListType::PENDING)); 2945 element_id_, ElementListType::PENDING));
3025 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2946 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3026 element_id_, ElementListType::ACTIVE)); 2947 element_id_, ElementListType::ACTIVE));
3027 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2948 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
3028 element_id_, ElementListType::ACTIVE)); 2949 element_id_, ElementListType::ACTIVE));
3029 2950
3030 element_animations_impl_->ActivateAnimations(); 2951 player_impl_->ActivateAnimations();
3031 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 2952 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3032 element_id_, ElementListType::ACTIVE)); 2953 element_id_, ElementListType::ACTIVE));
3033 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 2954 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3034 element_id_, ElementListType::ACTIVE)); 2955 element_id_, ElementListType::ACTIVE));
3035 2956
3036 // Case 3: An animation that's aborted before it finishes. 2957 // Case 3: An animation that's aborted before it finishes.
3037 animation_id = AddOpacityTransitionToPlayer(player_.get(), 10.0, 0.f, 0.5f, 2958 animation_id = AddOpacityTransitionToPlayer(player_.get(), 10.0, 0.f, 0.5f,
3038 false /*use_timing_function*/); 2959 false /*use_timing_function*/);
3039 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_, 2960 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_,
3040 ElementListType::ACTIVE)); 2961 ElementListType::ACTIVE));
3041 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_, 2962 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
3042 ElementListType::ACTIVE)); 2963 ElementListType::ACTIVE));
3043 2964
3044 PushProperties(); 2965 PushProperties();
3045 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2966 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3046 element_id_, ElementListType::PENDING)); 2967 element_id_, ElementListType::PENDING));
3047 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2968 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
3048 element_id_, ElementListType::PENDING)); 2969 element_id_, ElementListType::PENDING));
3049 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 2970 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3050 element_id_, ElementListType::ACTIVE)); 2971 element_id_, ElementListType::ACTIVE));
3051 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 2972 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3052 element_id_, ElementListType::ACTIVE)); 2973 element_id_, ElementListType::ACTIVE));
3053 2974
3054 element_animations_impl_->ActivateAnimations(); 2975 player_impl_->ActivateAnimations();
3055 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2976 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3056 element_id_, ElementListType::ACTIVE)); 2977 element_id_, ElementListType::ACTIVE));
3057 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2978 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
3058 element_id_, ElementListType::ACTIVE)); 2979 element_id_, ElementListType::ACTIVE));
3059 2980
3060 element_animations_impl_->Animate(kInitialTickTime + 2981 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
3061 TimeDelta::FromMilliseconds(2000)); 2982 player_impl_->UpdateState(true, events.get());
3062 element_animations_impl_->UpdateState(true, events.get());
3063 2983
3064 player_->NotifyAnimationStarted(events->events_[0]); 2984 player_->NotifyAnimationStarted(events->events_[0]);
3065 events->events_.clear(); 2985 events->events_.clear();
3066 2986
3067 player_impl_->AbortAnimations(TargetProperty::OPACITY, false); 2987 player_impl_->AbortAnimations(TargetProperty::OPACITY, false);
3068 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 2988 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3069 element_id_, ElementListType::PENDING)); 2989 element_id_, ElementListType::PENDING));
3070 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 2990 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3071 element_id_, ElementListType::PENDING)); 2991 element_id_, ElementListType::PENDING));
3072 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 2992 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3073 element_id_, ElementListType::ACTIVE)); 2993 element_id_, ElementListType::ACTIVE));
3074 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 2994 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3075 element_id_, ElementListType::ACTIVE)); 2995 element_id_, ElementListType::ACTIVE));
3076 2996
3077 element_animations_impl_->Animate(kInitialTickTime + 2997 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000));
3078 TimeDelta::FromMilliseconds(4000)); 2998 player_impl_->UpdateState(true, events.get());
3079 element_animations_impl_->UpdateState(true, events.get());
3080 2999
3081 element_animations_->NotifyAnimationAborted(events->events_[0]); 3000 element_animations_->NotifyAnimationAborted(events->events_[0]);
3082 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( 3001 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
3083 element_id_, ElementListType::ACTIVE)); 3002 element_id_, ElementListType::ACTIVE));
3084 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, 3003 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
3085 ElementListType::ACTIVE)); 3004 ElementListType::ACTIVE));
3086 3005
3087 // Case 4 : An animation that's not in effect. 3006 // Case 4 : An animation that's not in effect.
3088 animation_id = AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.f, 0.5f, 3007 animation_id = AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.f, 0.5f,
3089 false /*use_timing_function*/); 3008 false /*use_timing_function*/);
3090 player_->GetAnimationById(animation_id) 3009 player_->GetAnimationById(animation_id)
3091 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); 3010 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000));
3092 player_->GetAnimationById(animation_id) 3011 player_->GetAnimationById(animation_id)
3093 ->set_fill_mode(Animation::FillMode::NONE); 3012 ->set_fill_mode(Animation::FillMode::NONE);
3094 3013
3095 PushProperties(); 3014 PushProperties();
3096 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 3015 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3097 element_id_, ElementListType::PENDING)); 3016 element_id_, ElementListType::PENDING));
3098 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 3017 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3099 element_id_, ElementListType::PENDING)); 3018 element_id_, ElementListType::PENDING));
3100 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 3019 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
3101 element_id_, ElementListType::ACTIVE)); 3020 element_id_, ElementListType::ACTIVE));
3102 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 3021 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3103 element_id_, ElementListType::ACTIVE)); 3022 element_id_, ElementListType::ACTIVE));
3104 3023
3105 element_animations_impl_->ActivateAnimations(); 3024 player_impl_->ActivateAnimations();
3106 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 3025 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
3107 element_id_, ElementListType::ACTIVE)); 3026 element_id_, ElementListType::ACTIVE));
3108 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( 3027 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
3109 element_id_, ElementListType::ACTIVE)); 3028 element_id_, ElementListType::ACTIVE));
3110 } 3029 }
3111 3030
3112 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenFilterAnimationChanges) { 3031 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenFilterAnimationChanges) {
3113 CreateTestLayer(true, true); 3032 CreateTestLayer(true, true);
3114 AttachTimelinePlayerLayer(); 3033 AttachTimelinePlayerLayer();
3115 CreateImplTimelineAndPlayer(); 3034 CreateImplTimelineAndPlayer();
(...skipping 23 matching lines...) Expand all
3139 PushProperties(); 3058 PushProperties();
3140 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3059 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3141 element_id_, ElementListType::PENDING)); 3060 element_id_, ElementListType::PENDING));
3142 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3061 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3143 element_id_, ElementListType::PENDING)); 3062 element_id_, ElementListType::PENDING));
3144 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3063 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3145 element_id_, ElementListType::ACTIVE)); 3064 element_id_, ElementListType::ACTIVE));
3146 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3065 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3147 element_id_, ElementListType::ACTIVE)); 3066 element_id_, ElementListType::ACTIVE));
3148 3067
3149 element_animations_impl_->ActivateAnimations(); 3068 player_impl_->ActivateAnimations();
3150 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3069 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3151 element_id_, ElementListType::PENDING)); 3070 element_id_, ElementListType::PENDING));
3152 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3071 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3153 element_id_, ElementListType::PENDING)); 3072 element_id_, ElementListType::PENDING));
3154 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3073 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3155 element_id_, ElementListType::ACTIVE)); 3074 element_id_, ElementListType::ACTIVE));
3156 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3075 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3157 element_id_, ElementListType::ACTIVE)); 3076 element_id_, ElementListType::ACTIVE));
3158 3077
3159 element_animations_impl_->Animate(kInitialTickTime); 3078 player_impl_->Animate(kInitialTickTime);
3160 element_animations_impl_->UpdateState(true, events.get()); 3079 player_impl_->UpdateState(true, events.get());
3161 3080
3162 player_->NotifyAnimationStarted(events->events_[0]); 3081 player_->NotifyAnimationStarted(events->events_[0]);
3163 events->events_.clear(); 3082 events->events_.clear();
3164 3083
3165 // Finish the animation. 3084 // Finish the animation.
3166 element_animations_->Animate(kInitialTickTime + 3085 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
3167 TimeDelta::FromMilliseconds(1000)); 3086 player_->UpdateState(true, nullptr);
3168 element_animations_->UpdateState(true, nullptr);
3169 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, 3087 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_,
3170 ElementListType::ACTIVE)); 3088 ElementListType::ACTIVE));
3171 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, 3089 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_,
3172 ElementListType::ACTIVE)); 3090 ElementListType::ACTIVE));
3173 3091
3174 PushProperties(); 3092 PushProperties();
3175 3093
3176 // animations_impl hasn't yet ticked at/past the end of the animation. 3094 // animations_impl hasn't yet ticked at/past the end of the animation.
3177 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3095 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3178 element_id_, ElementListType::PENDING)); 3096 element_id_, ElementListType::PENDING));
3179 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3097 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3180 element_id_, ElementListType::PENDING)); 3098 element_id_, ElementListType::PENDING));
3181 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3099 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3182 element_id_, ElementListType::ACTIVE)); 3100 element_id_, ElementListType::ACTIVE));
3183 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3101 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3184 element_id_, ElementListType::ACTIVE)); 3102 element_id_, ElementListType::ACTIVE));
3185 3103
3186 element_animations_impl_->Animate(kInitialTickTime + 3104 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
3187 TimeDelta::FromMilliseconds(1000)); 3105 player_impl_->UpdateState(true, events.get());
3188 element_animations_impl_->UpdateState(true, events.get());
3189 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3106 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3190 element_id_, ElementListType::PENDING)); 3107 element_id_, ElementListType::PENDING));
3191 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3108 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3192 element_id_, ElementListType::PENDING)); 3109 element_id_, ElementListType::PENDING));
3193 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3110 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3194 element_id_, ElementListType::ACTIVE)); 3111 element_id_, ElementListType::ACTIVE));
3195 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3112 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3196 element_id_, ElementListType::ACTIVE)); 3113 element_id_, ElementListType::ACTIVE));
3197 3114
3198 // Case 2: An animation that's removed before it finishes. 3115 // Case 2: An animation that's removed before it finishes.
3199 int animation_id = AddAnimatedFilterToPlayer(player_.get(), 10.0, 0.f, 1.f); 3116 int animation_id = AddAnimatedFilterToPlayer(player_.get(), 10.0, 0.f, 1.f);
3200 EXPECT_TRUE(client_.GetHasPotentialFilterAnimation(element_id_, 3117 EXPECT_TRUE(client_.GetHasPotentialFilterAnimation(element_id_,
3201 ElementListType::ACTIVE)); 3118 ElementListType::ACTIVE));
3202 EXPECT_TRUE(client_.GetFilterIsCurrentlyAnimating(element_id_, 3119 EXPECT_TRUE(client_.GetFilterIsCurrentlyAnimating(element_id_,
3203 ElementListType::ACTIVE)); 3120 ElementListType::ACTIVE));
3204 3121
3205 PushProperties(); 3122 PushProperties();
3206 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3123 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3207 element_id_, ElementListType::PENDING)); 3124 element_id_, ElementListType::PENDING));
3208 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3125 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3209 element_id_, ElementListType::PENDING)); 3126 element_id_, ElementListType::PENDING));
3210 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3127 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3211 element_id_, ElementListType::ACTIVE)); 3128 element_id_, ElementListType::ACTIVE));
3212 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3129 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3213 element_id_, ElementListType::ACTIVE)); 3130 element_id_, ElementListType::ACTIVE));
3214 3131
3215 element_animations_impl_->ActivateAnimations(); 3132 player_impl_->ActivateAnimations();
3216 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3133 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3217 element_id_, ElementListType::ACTIVE)); 3134 element_id_, ElementListType::ACTIVE));
3218 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3135 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3219 element_id_, ElementListType::ACTIVE)); 3136 element_id_, ElementListType::ACTIVE));
3220 3137
3221 element_animations_impl_->Animate(kInitialTickTime + 3138 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
3222 TimeDelta::FromMilliseconds(2000)); 3139 player_impl_->UpdateState(true, events.get());
3223 element_animations_impl_->UpdateState(true, events.get());
3224 3140
3225 player_->NotifyAnimationStarted(events->events_[0]); 3141 player_->NotifyAnimationStarted(events->events_[0]);
3226 events->events_.clear(); 3142 events->events_.clear();
3227 3143
3228 player_->RemoveAnimation(animation_id); 3144 player_->RemoveAnimation(animation_id);
3229 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, 3145 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_,
3230 ElementListType::ACTIVE)); 3146 ElementListType::ACTIVE));
3231 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, 3147 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_,
3232 ElementListType::ACTIVE)); 3148 ElementListType::ACTIVE));
3233 3149
3234 PushProperties(); 3150 PushProperties();
3235 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3151 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3236 element_id_, ElementListType::PENDING)); 3152 element_id_, ElementListType::PENDING));
3237 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3153 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3238 element_id_, ElementListType::PENDING)); 3154 element_id_, ElementListType::PENDING));
3239 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3155 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3240 element_id_, ElementListType::ACTIVE)); 3156 element_id_, ElementListType::ACTIVE));
3241 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3157 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3242 element_id_, ElementListType::ACTIVE)); 3158 element_id_, ElementListType::ACTIVE));
3243 3159
3244 element_animations_impl_->ActivateAnimations(); 3160 player_impl_->ActivateAnimations();
3245 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3161 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3246 element_id_, ElementListType::ACTIVE)); 3162 element_id_, ElementListType::ACTIVE));
3247 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3163 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3248 element_id_, ElementListType::ACTIVE)); 3164 element_id_, ElementListType::ACTIVE));
3249 3165
3250 // Case 3: An animation that's aborted before it finishes. 3166 // Case 3: An animation that's aborted before it finishes.
3251 animation_id = AddAnimatedFilterToPlayer(player_.get(), 10.0, 0.f, 0.5f); 3167 animation_id = AddAnimatedFilterToPlayer(player_.get(), 10.0, 0.f, 0.5f);
3252 EXPECT_TRUE(client_.GetHasPotentialFilterAnimation(element_id_, 3168 EXPECT_TRUE(client_.GetHasPotentialFilterAnimation(element_id_,
3253 ElementListType::ACTIVE)); 3169 ElementListType::ACTIVE));
3254 EXPECT_TRUE(client_.GetFilterIsCurrentlyAnimating(element_id_, 3170 EXPECT_TRUE(client_.GetFilterIsCurrentlyAnimating(element_id_,
3255 ElementListType::ACTIVE)); 3171 ElementListType::ACTIVE));
3256 3172
3257 PushProperties(); 3173 PushProperties();
3258 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3174 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3259 element_id_, ElementListType::PENDING)); 3175 element_id_, ElementListType::PENDING));
3260 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3176 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3261 element_id_, ElementListType::PENDING)); 3177 element_id_, ElementListType::PENDING));
3262 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3178 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3263 element_id_, ElementListType::ACTIVE)); 3179 element_id_, ElementListType::ACTIVE));
3264 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3180 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3265 element_id_, ElementListType::ACTIVE)); 3181 element_id_, ElementListType::ACTIVE));
3266 3182
3267 element_animations_impl_->ActivateAnimations(); 3183 player_impl_->ActivateAnimations();
3268 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3184 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3269 element_id_, ElementListType::ACTIVE)); 3185 element_id_, ElementListType::ACTIVE));
3270 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3186 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3271 element_id_, ElementListType::ACTIVE)); 3187 element_id_, ElementListType::ACTIVE));
3272 3188
3273 element_animations_impl_->Animate(kInitialTickTime + 3189 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
3274 TimeDelta::FromMilliseconds(2000)); 3190 player_impl_->UpdateState(true, events.get());
3275 element_animations_impl_->UpdateState(true, events.get());
3276 3191
3277 player_->NotifyAnimationStarted(events->events_[0]); 3192 player_->NotifyAnimationStarted(events->events_[0]);
3278 events->events_.clear(); 3193 events->events_.clear();
3279 3194
3280 player_impl_->AbortAnimations(TargetProperty::FILTER, false); 3195 player_impl_->AbortAnimations(TargetProperty::FILTER, false);
3281 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3196 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3282 element_id_, ElementListType::PENDING)); 3197 element_id_, ElementListType::PENDING));
3283 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3198 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3284 element_id_, ElementListType::PENDING)); 3199 element_id_, ElementListType::PENDING));
3285 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3200 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3286 element_id_, ElementListType::ACTIVE)); 3201 element_id_, ElementListType::ACTIVE));
3287 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3202 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3288 element_id_, ElementListType::ACTIVE)); 3203 element_id_, ElementListType::ACTIVE));
3289 3204
3290 element_animations_impl_->Animate(kInitialTickTime + 3205 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000));
3291 TimeDelta::FromMilliseconds(4000)); 3206 player_impl_->UpdateState(true, events.get());
3292 element_animations_impl_->UpdateState(true, events.get());
3293 3207
3294 element_animations_->NotifyAnimationAborted(events->events_[0]); 3208 element_animations_->NotifyAnimationAborted(events->events_[0]);
3295 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, 3209 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_,
3296 ElementListType::ACTIVE)); 3210 ElementListType::ACTIVE));
3297 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, 3211 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_,
3298 ElementListType::ACTIVE)); 3212 ElementListType::ACTIVE));
3299 3213
3300 // Case 4 : An animation that's not in effect. 3214 // Case 4 : An animation that's not in effect.
3301 animation_id = AddAnimatedFilterToPlayer(player_.get(), 1.0, 0.f, 0.5f); 3215 animation_id = AddAnimatedFilterToPlayer(player_.get(), 1.0, 0.f, 0.5f);
3302 player_->GetAnimationById(animation_id) 3216 player_->GetAnimationById(animation_id)
3303 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); 3217 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000));
3304 player_->GetAnimationById(animation_id) 3218 player_->GetAnimationById(animation_id)
3305 ->set_fill_mode(Animation::FillMode::NONE); 3219 ->set_fill_mode(Animation::FillMode::NONE);
3306 3220
3307 PushProperties(); 3221 PushProperties();
3308 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3222 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3309 element_id_, ElementListType::PENDING)); 3223 element_id_, ElementListType::PENDING));
3310 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3224 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3311 element_id_, ElementListType::PENDING)); 3225 element_id_, ElementListType::PENDING));
3312 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3226 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3313 element_id_, ElementListType::ACTIVE)); 3227 element_id_, ElementListType::ACTIVE));
3314 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3228 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3315 element_id_, ElementListType::ACTIVE)); 3229 element_id_, ElementListType::ACTIVE));
3316 3230
3317 element_animations_impl_->ActivateAnimations(); 3231 player_impl_->ActivateAnimations();
3318 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3232 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3319 element_id_, ElementListType::ACTIVE)); 3233 element_id_, ElementListType::ACTIVE));
3320 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( 3234 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3321 element_id_, ElementListType::ACTIVE)); 3235 element_id_, ElementListType::ACTIVE));
3322 } 3236 }
3323 3237
3324 TEST_F(ElementAnimationsTest, ClippedOpacityValues) { 3238 TEST_F(ElementAnimationsTest, ClippedOpacityValues) {
3325 CreateTestLayer(false, false); 3239 CreateTestLayer(false, false);
3326 AttachTimelinePlayerLayer(); 3240 AttachTimelinePlayerLayer();
3327 3241
3328 AddOpacityTransitionToPlayer(player_.get(), 1, 1.f, 2.f, true); 3242 AddOpacityTransitionToPlayer(player_.get(), 1, 1.f, 2.f, true);
3329 3243
3330 element_animations_->Animate(kInitialTickTime); 3244 player_->Animate(kInitialTickTime);
3331 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3245 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
3332 3246
3333 // Opacity values are clipped [0,1] 3247 // Opacity values are clipped [0,1]
3334 element_animations_->Animate(kInitialTickTime + 3248 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
3335 TimeDelta::FromMilliseconds(1000));
3336 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3249 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
3337 } 3250 }
3338 3251
3339 TEST_F(ElementAnimationsTest, ClippedNegativeOpacityValues) { 3252 TEST_F(ElementAnimationsTest, ClippedNegativeOpacityValues) {
3340 CreateTestLayer(false, false); 3253 CreateTestLayer(false, false);
3341 AttachTimelinePlayerLayer(); 3254 AttachTimelinePlayerLayer();
3342 3255
3343 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, -2.f, true); 3256 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, -2.f, true);
3344 3257
3345 element_animations_->Animate(kInitialTickTime); 3258 player_->Animate(kInitialTickTime);
3346 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3259 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
3347 3260
3348 // Opacity values are clipped [0,1] 3261 // Opacity values are clipped [0,1]
3349 element_animations_->Animate(kInitialTickTime + 3262 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
3350 TimeDelta::FromMilliseconds(1000));
3351 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3263 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
3352 } 3264 }
3353 3265
3354 TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) { 3266 TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) {
3355 CreateTestLayer(true, true); 3267 CreateTestLayer(true, true);
3356 AttachTimelinePlayerLayer(); 3268 AttachTimelinePlayerLayer();
3357 CreateImplTimelineAndPlayer(); 3269 CreateImplTimelineAndPlayer();
3358 3270
3359 auto events = CreateEventsForTesting(); 3271 auto events = CreateEventsForTesting();
3360 3272
3361 const int animation_id = 3273 const int animation_id =
3362 AddOpacityTransitionToPlayer(player_.get(), 1, 0.5f, 1.f, true); 3274 AddOpacityTransitionToPlayer(player_.get(), 1, 0.5f, 1.f, true);
3363 3275
3364 PushProperties(); 3276 PushProperties();
3365 player_impl_->ActivateAnimations(); 3277 player_impl_->ActivateAnimations();
3366 element_animations_impl_->Animate(kInitialTickTime); 3278 player_impl_->Animate(kInitialTickTime);
3367 element_animations_impl_->UpdateState(true, events.get()); 3279 player_impl_->UpdateState(true, events.get());
3368 EXPECT_EQ(Animation::RUNNING, 3280 EXPECT_EQ(Animation::RUNNING,
3369 player_impl_->GetAnimationById(animation_id)->run_state()); 3281 player_impl_->GetAnimationById(animation_id)->run_state());
3370 EXPECT_EQ(0.5f, 3282 EXPECT_EQ(0.5f,
3371 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3283 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3372 EXPECT_EQ(0.5f, 3284 EXPECT_EQ(0.5f,
3373 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3285 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
3374 3286
3375 EXPECT_TRUE( 3287 EXPECT_TRUE(
3376 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); 3288 player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
3377 EXPECT_TRUE( 3289 EXPECT_TRUE(
3378 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); 3290 player_impl_->GetAnimationById(animation_id)->affects_active_elements());
3379 3291
3380 // Delete the animation on the main-thread animations. 3292 // Delete the animation on the main-thread animations.
3381 player_->RemoveAnimation( 3293 player_->RemoveAnimation(
3382 player_->GetAnimation(TargetProperty::OPACITY)->id()); 3294 player_->GetAnimation(TargetProperty::OPACITY)->id());
3383 PushProperties(); 3295 PushProperties();
3384 3296
3385 // The animation should no longer affect pending elements. 3297 // The animation should no longer affect pending elements.
3386 EXPECT_FALSE( 3298 EXPECT_FALSE(
3387 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); 3299 player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
3388 EXPECT_TRUE( 3300 EXPECT_TRUE(
3389 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); 3301 player_impl_->GetAnimationById(animation_id)->affects_active_elements());
3390 3302
3391 element_animations_impl_->Animate(kInitialTickTime + 3303 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
3392 TimeDelta::FromMilliseconds(500)); 3304 player_impl_->UpdateState(true, events.get());
3393 element_animations_impl_->UpdateState(true, events.get());
3394 3305
3395 // Only the active observer should have been ticked. 3306 // Only the active observer should have been ticked.
3396 EXPECT_EQ(0.5f, 3307 EXPECT_EQ(0.5f,
3397 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3308 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3398 EXPECT_EQ(0.75f, 3309 EXPECT_EQ(0.75f,
3399 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3310 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
3400 3311
3401 player_impl_->ActivateAnimations(); 3312 player_impl_->ActivateAnimations();
3402 3313
3403 // Activation should cause the animation to be deleted. 3314 // Activation should cause the animation to be deleted.
3404 EXPECT_FALSE(player_impl_->has_any_animation()); 3315 EXPECT_FALSE(player_impl_->has_any_animation());
3405 } 3316 }
3406 3317
3407 // Tests that an animation that affects only active elements won't block 3318 // Tests that an animation that affects only active elements won't block
3408 // an animation that affects only pending elements from starting. 3319 // an animation that affects only pending elements from starting.
3409 TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) { 3320 TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) {
3410 CreateTestLayer(true, true); 3321 CreateTestLayer(true, true);
3411 AttachTimelinePlayerLayer(); 3322 AttachTimelinePlayerLayer();
3412 CreateImplTimelineAndPlayer(); 3323 CreateImplTimelineAndPlayer();
3413 3324
3414 auto events = CreateEventsForTesting(); 3325 auto events = CreateEventsForTesting();
3415 3326
3416 const int first_animation_id = 3327 const int first_animation_id =
3417 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, 1.f, true); 3328 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, 1.f, true);
3418 3329
3419 PushProperties(); 3330 PushProperties();
3420 player_impl_->ActivateAnimations(); 3331 player_impl_->ActivateAnimations();
3421 element_animations_impl_->Animate(kInitialTickTime); 3332 player_impl_->Animate(kInitialTickTime);
3422 element_animations_impl_->UpdateState(true, events.get()); 3333 player_impl_->UpdateState(true, events.get());
3423 3334
3424 // Remove the first animation from the main-thread animations, and add a 3335 // Remove the first animation from the main-thread animations, and add a
3425 // new animation affecting the same property. 3336 // new animation affecting the same property.
3426 player_->RemoveAnimation( 3337 player_->RemoveAnimation(
3427 player_->GetAnimation(TargetProperty::OPACITY)->id()); 3338 player_->GetAnimation(TargetProperty::OPACITY)->id());
3428 const int second_animation_id = 3339 const int second_animation_id =
3429 AddOpacityTransitionToPlayer(player_.get(), 1, 1.f, 0.5f, true); 3340 AddOpacityTransitionToPlayer(player_.get(), 1, 1.f, 0.5f, true);
3430 PushProperties(); 3341 PushProperties();
3431 3342
3432 // The original animation should only affect active elements, and the new 3343 // The original animation should only affect active elements, and the new
3433 // animation should only affect pending elements. 3344 // animation should only affect pending elements.
3434 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id) 3345 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)
3435 ->affects_pending_elements()); 3346 ->affects_pending_elements());
3436 EXPECT_TRUE(player_impl_->GetAnimationById(first_animation_id) 3347 EXPECT_TRUE(player_impl_->GetAnimationById(first_animation_id)
3437 ->affects_active_elements()); 3348 ->affects_active_elements());
3438 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id) 3349 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id)
3439 ->affects_pending_elements()); 3350 ->affects_pending_elements());
3440 EXPECT_FALSE(player_impl_->GetAnimationById(second_animation_id) 3351 EXPECT_FALSE(player_impl_->GetAnimationById(second_animation_id)
3441 ->affects_active_elements()); 3352 ->affects_active_elements());
3442 3353
3443 element_animations_impl_->Animate(kInitialTickTime + 3354 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
3444 TimeDelta::FromMilliseconds(500)); 3355 player_impl_->UpdateState(true, events.get());
3445 element_animations_impl_->UpdateState(true, events.get());
3446 3356
3447 // The original animation should still be running, and the new animation 3357 // The original animation should still be running, and the new animation
3448 // should be starting. 3358 // should be starting.
3449 EXPECT_EQ(Animation::RUNNING, 3359 EXPECT_EQ(Animation::RUNNING,
3450 player_impl_->GetAnimationById(first_animation_id)->run_state()); 3360 player_impl_->GetAnimationById(first_animation_id)->run_state());
3451 EXPECT_EQ(Animation::STARTING, 3361 EXPECT_EQ(Animation::STARTING,
3452 player_impl_->GetAnimationById(second_animation_id)->run_state()); 3362 player_impl_->GetAnimationById(second_animation_id)->run_state());
3453 3363
3454 // The active observer should have been ticked by the original animation, 3364 // The active observer should have been ticked by the original animation,
3455 // and the pending observer should have been ticked by the new animation. 3365 // and the pending observer should have been ticked by the new animation.
3456 EXPECT_EQ(1.f, 3366 EXPECT_EQ(1.f,
3457 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3367 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3458 EXPECT_EQ(0.5f, 3368 EXPECT_EQ(0.5f,
3459 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3369 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
3460 3370
3461 player_impl_->ActivateAnimations(); 3371 player_impl_->ActivateAnimations();
3462 3372
3463 // The original animation should have been deleted, and the new animation 3373 // The original animation should have been deleted, and the new animation
3464 // should now affect both elements. 3374 // should now affect both elements.
3465 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)); 3375 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id));
3466 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id) 3376 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id)
3467 ->affects_pending_elements()); 3377 ->affects_pending_elements());
3468 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id) 3378 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id)
3469 ->affects_active_elements()); 3379 ->affects_active_elements());
3470 3380
3471 element_animations_impl_->Animate(kInitialTickTime + 3381 player_impl_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
3472 TimeDelta::FromMilliseconds(1000)); 3382 player_impl_->UpdateState(true, events.get());
3473 element_animations_impl_->UpdateState(true, events.get());
3474 3383
3475 // The new animation should be running, and the active observer should have 3384 // The new animation should be running, and the active observer should have
3476 // been ticked at the new animation's starting point. 3385 // been ticked at the new animation's starting point.
3477 EXPECT_EQ(Animation::RUNNING, 3386 EXPECT_EQ(Animation::RUNNING,
3478 player_impl_->GetAnimationById(second_animation_id)->run_state()); 3387 player_impl_->GetAnimationById(second_animation_id)->run_state());
3479 EXPECT_EQ(1.f, 3388 EXPECT_EQ(1.f,
3480 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3389 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3481 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3390 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
3482 } 3391 }
3483 3392
3484 TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) { 3393 TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) {
3485 CreateTestLayer(false, false); 3394 CreateTestLayer(false, false);
3486 AttachTimelinePlayerLayer(); 3395 AttachTimelinePlayerLayer();
3487 3396
3488 // Create an animation that initially affects only pending elements. 3397 // Create an animation that initially affects only pending elements.
3489 std::unique_ptr<Animation> animation(CreateAnimation( 3398 std::unique_ptr<Animation> animation(CreateAnimation(
3490 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 3399 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
3491 1, TargetProperty::OPACITY)); 3400 1, TargetProperty::OPACITY));
3492 animation->set_affects_active_elements(false); 3401 animation->set_affects_active_elements(false);
3493 3402
3494 player_->AddAnimation(std::move(animation)); 3403 player_->AddAnimation(std::move(animation));
3495 element_animations_->Animate(kInitialTickTime); 3404 player_->Animate(kInitialTickTime);
3496 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3405 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3497 ElementListType::PENDING)); 3406 ElementListType::PENDING));
3498 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3407 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3499 ElementListType::ACTIVE)); 3408 ElementListType::ACTIVE));
3500 element_animations_->UpdateState(true, nullptr); 3409 player_->UpdateState(true, nullptr);
3501 EXPECT_TRUE(player_->HasActiveAnimation()); 3410 EXPECT_TRUE(player_->HasActiveAnimation());
3502 3411
3503 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3412 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3504 ElementListType::PENDING)); 3413 ElementListType::PENDING));
3505 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3414 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3506 ElementListType::ACTIVE)); 3415 ElementListType::ACTIVE));
3507 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, 3416 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
3508 ElementListType::PENDING)); 3417 ElementListType::PENDING));
3509 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, 3418 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
3510 ElementListType::ACTIVE)); 3419 ElementListType::ACTIVE));
3511 3420
3512 player_->ActivateAnimations(); 3421 player_->ActivateAnimations();
3513 3422
3514 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3423 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3515 ElementListType::PENDING)); 3424 ElementListType::PENDING));
3516 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3425 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3517 ElementListType::ACTIVE)); 3426 ElementListType::ACTIVE));
3518 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, 3427 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
3519 ElementListType::PENDING)); 3428 ElementListType::PENDING));
3520 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, 3429 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
3521 ElementListType::ACTIVE)); 3430 ElementListType::ACTIVE));
3522 3431
3523 element_animations_->Animate(kInitialTickTime + 3432 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(10));
3524 TimeDelta::FromMilliseconds(10)); 3433 player_->UpdateState(true, nullptr);
3525 element_animations_->UpdateState(true, nullptr);
3526 3434
3527 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3435 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3528 ElementListType::PENDING)); 3436 ElementListType::PENDING));
3529 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3437 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3530 ElementListType::ACTIVE)); 3438 ElementListType::ACTIVE));
3531 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, 3439 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
3532 ElementListType::PENDING)); 3440 ElementListType::PENDING));
3533 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, 3441 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
3534 ElementListType::ACTIVE)); 3442 ElementListType::ACTIVE));
3535 3443
3536 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3444 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
3537 3445
3538 // Tick past the end of the animation. 3446 // Tick past the end of the animation.
3539 element_animations_->Animate(kInitialTickTime + 3447 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1100));
3540 TimeDelta::FromMilliseconds(1100)); 3448 player_->UpdateState(true, nullptr);
3541 element_animations_->UpdateState(true, nullptr);
3542 3449
3543 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3450 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3544 ElementListType::PENDING)); 3451 ElementListType::PENDING));
3545 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3452 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3546 ElementListType::ACTIVE)); 3453 ElementListType::ACTIVE));
3547 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, 3454 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
3548 ElementListType::PENDING)); 3455 ElementListType::PENDING));
3549 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, 3456 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
3550 ElementListType::ACTIVE)); 3457 ElementListType::ACTIVE));
3551 3458
3552 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3459 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
3553 } 3460 }
3554 3461
3555 TEST_F(ElementAnimationsTest, TestIsAnimatingPropertyTimeOffsetFillMode) { 3462 TEST_F(ElementAnimationsTest, TestIsAnimatingPropertyTimeOffsetFillMode) {
3556 CreateTestLayer(false, false); 3463 CreateTestLayer(false, false);
3557 AttachTimelinePlayerLayer(); 3464 AttachTimelinePlayerLayer();
3558 3465
3559 // Create an animation that initially affects only pending elements, and has 3466 // Create an animation that initially affects only pending elements, and has
3560 // a start delay of 2 seconds. 3467 // a start delay of 2 seconds.
3561 std::unique_ptr<Animation> animation(CreateAnimation( 3468 std::unique_ptr<Animation> animation(CreateAnimation(
3562 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), 3469 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
3563 1, TargetProperty::OPACITY)); 3470 1, TargetProperty::OPACITY));
3564 animation->set_fill_mode(Animation::FillMode::NONE); 3471 animation->set_fill_mode(Animation::FillMode::NONE);
3565 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); 3472 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000));
3566 animation->set_affects_active_elements(false); 3473 animation->set_affects_active_elements(false);
3567 3474
3568 player_->AddAnimation(std::move(animation)); 3475 player_->AddAnimation(std::move(animation));
3569 3476
3570 element_animations_->Animate(kInitialTickTime); 3477 player_->Animate(kInitialTickTime);
3571 3478
3572 // Since the animation has a start delay, the elements it affects have a 3479 // Since the animation has a start delay, the elements it affects have a
3573 // potentially running transform animation but aren't currently animating 3480 // potentially running transform animation but aren't currently animating
3574 // transform. 3481 // transform.
3575 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty( 3482 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(
3576 TargetProperty::OPACITY, ElementListType::PENDING)); 3483 TargetProperty::OPACITY, ElementListType::PENDING));
3577 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( 3484 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
3578 TargetProperty::OPACITY, ElementListType::ACTIVE)); 3485 TargetProperty::OPACITY, ElementListType::ACTIVE));
3579 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3486 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3580 ElementListType::PENDING)); 3487 ElementListType::PENDING));
(...skipping 14 matching lines...) Expand all
3595 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3502 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3596 ElementListType::PENDING)); 3503 ElementListType::PENDING));
3597 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3504 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3598 ElementListType::ACTIVE)); 3505 ElementListType::ACTIVE));
3599 EXPECT_TRUE(player_->HasActiveAnimation()); 3506 EXPECT_TRUE(player_->HasActiveAnimation());
3600 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( 3507 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
3601 TargetProperty::FILTER, ElementListType::PENDING)); 3508 TargetProperty::FILTER, ElementListType::PENDING));
3602 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( 3509 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
3603 TargetProperty::FILTER, ElementListType::ACTIVE)); 3510 TargetProperty::FILTER, ElementListType::ACTIVE));
3604 3511
3605 element_animations_->UpdateState(true, nullptr); 3512 player_->UpdateState(true, nullptr);
3606 3513
3607 // Tick past the start delay. 3514 // Tick past the start delay.
3608 element_animations_->Animate(kInitialTickTime + 3515 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
3609 TimeDelta::FromMilliseconds(2000)); 3516 player_->UpdateState(true, nullptr);
3610 element_animations_->UpdateState(true, nullptr);
3611 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty( 3517 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(
3612 TargetProperty::OPACITY, ElementListType::PENDING)); 3518 TargetProperty::OPACITY, ElementListType::PENDING));
3613 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(TargetProperty::OPACITY, 3519 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(TargetProperty::OPACITY,
3614 ElementListType::ACTIVE)); 3520 ElementListType::ACTIVE));
3615 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3521 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3616 ElementListType::PENDING)); 3522 ElementListType::PENDING));
3617 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3523 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3618 ElementListType::ACTIVE)); 3524 ElementListType::ACTIVE));
3619 3525
3620 // After the animaton finishes, the elements it affects have neither a 3526 // After the animaton finishes, the elements it affects have neither a
3621 // potentially running transform animation nor a currently running transform 3527 // potentially running transform animation nor a currently running transform
3622 // animation. 3528 // animation.
3623 element_animations_->Animate(kInitialTickTime + 3529 player_->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000));
3624 TimeDelta::FromMilliseconds(4000)); 3530 player_->UpdateState(true, nullptr);
3625 element_animations_->UpdateState(true, nullptr);
3626 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( 3531 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
3627 TargetProperty::OPACITY, ElementListType::PENDING)); 3532 TargetProperty::OPACITY, ElementListType::PENDING));
3628 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( 3533 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
3629 TargetProperty::OPACITY, ElementListType::ACTIVE)); 3534 TargetProperty::OPACITY, ElementListType::ACTIVE));
3630 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3535 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3631 ElementListType::PENDING)); 3536 ElementListType::PENDING));
3632 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, 3537 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
3633 ElementListType::ACTIVE)); 3538 ElementListType::ACTIVE));
3634 } 3539 }
3635 3540
3636 TEST_F(ElementAnimationsTest, DestroyTestMainLayerBeforePushProperties) { 3541 TEST_F(ElementAnimationsTest, DestroyTestMainLayerBeforePushProperties) {
3637 CreateTestLayer(false, false); 3542 CreateTestLayer(false, false);
3638 AttachTimelinePlayerLayer(); 3543 AttachTimelinePlayerLayer();
3639 EXPECT_EQ(0u, host_->active_element_animations_for_testing().size()); 3544 EXPECT_EQ(0u, host_->active_players_for_testing().size());
3640 3545
3641 player_->AddAnimation(CreateAnimation( 3546 player_->AddAnimation(CreateAnimation(
3642 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), 3547 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)),
3643 2, TargetProperty::OPACITY)); 3548 2, TargetProperty::OPACITY));
3644 EXPECT_EQ(1u, host_->active_element_animations_for_testing().size()); 3549 EXPECT_EQ(1u, host_->active_players_for_testing().size());
3645 3550
3646 DestroyTestMainLayer(); 3551 DestroyTestMainLayer();
3647 EXPECT_EQ(0u, host_->active_element_animations_for_testing().size()); 3552 EXPECT_EQ(0u, host_->active_players_for_testing().size());
3648 3553
3649 PushProperties(); 3554 PushProperties();
3650 EXPECT_EQ(0u, host_->active_element_animations_for_testing().size()); 3555 EXPECT_EQ(0u, host_->active_players_for_testing().size());
3651 EXPECT_EQ(0u, host_impl_->active_element_animations_for_testing().size()); 3556 EXPECT_EQ(0u, host_impl_->active_players_for_testing().size());
3652 } 3557 }
3653 3558
3654 } // namespace 3559 } // namespace
3655 } // namespace cc 3560 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698