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

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

Issue 2796013003: cc: Push Animation Finished State and Use Finished State for IsCompleted (Closed)
Patch Set: fix all cc unittest Created 3 years, 8 months 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 "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "cc/animation/animation_delegate.h" 8 #include "cc/animation/animation_delegate.h"
9 #include "cc/animation/animation_events.h" 9 #include "cc/animation/animation_events.h"
10 #include "cc/animation/animation_host.h" 10 #include "cc/animation/animation_host.h"
(...skipping 2678 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 // Finish the animation. 2689 // Finish the animation.
2690 player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 2690 player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2691 player_->UpdateState(true, nullptr); 2691 player_->UpdateState(true, nullptr);
2692 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( 2692 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation(
2693 element_id_, ElementListType::ACTIVE)); 2693 element_id_, ElementListType::ACTIVE));
2694 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( 2694 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating(
2695 element_id_, ElementListType::ACTIVE)); 2695 element_id_, ElementListType::ACTIVE));
2696 2696
2697 PushProperties(); 2697 PushProperties();
2698 2698
2699 // animations_impl hasn't yet ticked at/past the end of the animation. 2699 // Finshed animations are pushed, but animations_impl hasn't yet ticked
ajuma 2017/04/11 23:32:02 'Finished'
2700 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2700 // at/past the end of the animation.
2701 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2701 element_id_, ElementListType::PENDING)); 2702 element_id_, ElementListType::PENDING));
2702 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2703 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating(
2703 element_id_, ElementListType::PENDING)); 2704 element_id_, ElementListType::PENDING));
2704 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( 2705 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation(
2705 element_id_, ElementListType::ACTIVE)); 2706 element_id_, ElementListType::ACTIVE));
2706 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( 2707 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating(
2707 element_id_, ElementListType::ACTIVE)); 2708 element_id_, ElementListType::ACTIVE));
2708 2709
2709 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 2710 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2710 player_impl_->UpdateState(true, events.get()); 2711 player_impl_->UpdateState(true, events.get());
2711 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( 2712 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation(
2712 element_id_, ElementListType::PENDING)); 2713 element_id_, ElementListType::PENDING));
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2906 // Finish the animation. 2907 // Finish the animation.
2907 player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 2908 player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2908 player_->UpdateState(true, nullptr); 2909 player_->UpdateState(true, nullptr);
2909 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( 2910 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation(
2910 element_id_, ElementListType::ACTIVE)); 2911 element_id_, ElementListType::ACTIVE));
2911 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, 2912 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_,
2912 ElementListType::ACTIVE)); 2913 ElementListType::ACTIVE));
2913 2914
2914 PushProperties(); 2915 PushProperties();
2915 2916
2916 // animations_impl hasn't yet ticked at/past the end of the animation. 2917 // Finished animations are pushed, but animations_impl hasn't yet ticked
2917 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2918 // at/past the end of the animation.
2919 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
2918 element_id_, ElementListType::PENDING)); 2920 element_id_, ElementListType::PENDING));
2919 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2921 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating(
2920 element_id_, ElementListType::PENDING)); 2922 element_id_, ElementListType::PENDING));
2921 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( 2923 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation(
2922 element_id_, ElementListType::ACTIVE)); 2924 element_id_, ElementListType::ACTIVE));
2923 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( 2925 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating(
2924 element_id_, ElementListType::ACTIVE)); 2926 element_id_, ElementListType::ACTIVE));
2925 2927
2926 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 2928 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
2927 player_impl_->UpdateState(true, events.get()); 2929 player_impl_->UpdateState(true, events.get());
2928 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( 2930 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation(
2929 element_id_, ElementListType::PENDING)); 2931 element_id_, ElementListType::PENDING));
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
3116 // Finish the animation. 3118 // Finish the animation.
3117 player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 3119 player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
3118 player_->UpdateState(true, nullptr); 3120 player_->UpdateState(true, nullptr);
3119 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, 3121 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_,
3120 ElementListType::ACTIVE)); 3122 ElementListType::ACTIVE));
3121 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, 3123 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_,
3122 ElementListType::ACTIVE)); 3124 ElementListType::ACTIVE));
3123 3125
3124 PushProperties(); 3126 PushProperties();
3125 3127
3126 // animations_impl hasn't yet ticked at/past the end of the animation. 3128 // Finished animations are pushed, but animations_impl hasn't yet ticked
3127 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3129 // at/past the end of the animation.
3130 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3128 element_id_, ElementListType::PENDING)); 3131 element_id_, ElementListType::PENDING));
3129 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3132 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating(
3130 element_id_, ElementListType::PENDING)); 3133 element_id_, ElementListType::PENDING));
3131 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( 3134 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation(
3132 element_id_, ElementListType::ACTIVE)); 3135 element_id_, ElementListType::ACTIVE));
3133 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( 3136 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating(
3134 element_id_, ElementListType::ACTIVE)); 3137 element_id_, ElementListType::ACTIVE));
3135 3138
3136 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 3139 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
3137 player_impl_->UpdateState(true, events.get()); 3140 player_impl_->UpdateState(true, events.get());
3138 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( 3141 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation(
3139 element_id_, ElementListType::PENDING)); 3142 element_id_, ElementListType::PENDING));
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
3335 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 3338 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500));
3336 player_impl_->UpdateState(true, events.get()); 3339 player_impl_->UpdateState(true, events.get());
3337 3340
3338 // Only the active observer should have been ticked. 3341 // Only the active observer should have been ticked.
3339 EXPECT_EQ(0.5f, 3342 EXPECT_EQ(0.5f,
3340 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3343 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3341 EXPECT_EQ(0.75f, 3344 EXPECT_EQ(0.75f,
3342 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3345 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
3343 3346
3344 player_impl_->ActivateAnimations(); 3347 player_impl_->ActivateAnimations();
3348 player_impl_->UpdateState(true, events.get());
3345 3349
3346 // Activation should cause the animation to be deleted. 3350 // Activation should cause the animation to be deleted.
ajuma 2017/04/11 23:32:02 This comment needs to be updated.
3347 EXPECT_FALSE(player_impl_->has_any_animation()); 3351 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
3352 player_impl_->GetAnimationById(animation_id)->run_state());
ajuma 2017/04/11 23:32:02 Please also add one more PushProperties() and afte
3348 } 3353 }
3349 3354
3350 // Tests that an animation that affects only active elements won't block 3355 // Tests that an animation that affects only active elements won't block
3351 // an animation that affects only pending elements from starting. 3356 // an animation that affects only pending elements from starting.
3352 TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) { 3357 TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) {
3353 CreateTestLayer(true, true); 3358 CreateTestLayer(true, true);
3354 AttachTimelinePlayerLayer(); 3359 AttachTimelinePlayerLayer();
3355 CreateImplTimelineAndPlayer(); 3360 CreateImplTimelineAndPlayer();
3356 3361
3357 auto events = CreateEventsForTesting(); 3362 auto events = CreateEventsForTesting();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3395 3400
3396 // The active observer should have been ticked by the original animation, 3401 // The active observer should have been ticked by the original animation,
3397 // and the pending observer should have been ticked by the new animation. 3402 // and the pending observer should have been ticked by the new animation.
3398 EXPECT_EQ(1.f, 3403 EXPECT_EQ(1.f,
3399 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3404 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3400 EXPECT_EQ(0.5f, 3405 EXPECT_EQ(0.5f,
3401 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3406 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
3402 3407
3403 player_impl_->ActivateAnimations(); 3408 player_impl_->ActivateAnimations();
3404 3409
3405 // The original animation should have been deleted, and the new animation 3410 // The original animation no longer affect either elements, and the new
3406 // should now affect both elements. 3411 // animation should now affect both elements.
3407 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)); 3412 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)
3413 ->affects_pending_elements());
3414 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)
3415 ->affects_active_elements());
3408 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id) 3416 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id)
3409 ->affects_pending_elements()); 3417 ->affects_pending_elements());
3410 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id) 3418 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id)
3411 ->affects_active_elements()); 3419 ->affects_active_elements());
3412 3420
3413 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 3421 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
3414 player_impl_->UpdateState(true, events.get()); 3422 player_impl_->UpdateState(true, events.get());
3415 3423
3424 // The original animation should be marked for waiting for deletion.
3425 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
3426 player_impl_->GetAnimationById(first_animation_id)->run_state());
3427
3416 // The new animation should be running, and the active observer should have 3428 // The new animation should be running, and the active observer should have
3417 // been ticked at the new animation's starting point. 3429 // been ticked at the new animation's starting point.
3418 EXPECT_EQ(Animation::RUNNING, 3430 EXPECT_EQ(Animation::RUNNING,
3419 player_impl_->GetAnimationById(second_animation_id)->run_state()); 3431 player_impl_->GetAnimationById(second_animation_id)->run_state());
3420 EXPECT_EQ(1.f, 3432 EXPECT_EQ(1.f,
3421 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3433 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3422 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3434 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
3423 } 3435 }
3424 3436
3425 TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) { 3437 TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3583 DestroyTestMainLayer(); 3595 DestroyTestMainLayer();
3584 EXPECT_EQ(0u, host_->ticking_players_for_testing().size()); 3596 EXPECT_EQ(0u, host_->ticking_players_for_testing().size());
3585 3597
3586 PushProperties(); 3598 PushProperties();
3587 EXPECT_EQ(0u, host_->ticking_players_for_testing().size()); 3599 EXPECT_EQ(0u, host_->ticking_players_for_testing().size());
3588 EXPECT_EQ(0u, host_impl_->ticking_players_for_testing().size()); 3600 EXPECT_EQ(0u, host_impl_->ticking_players_for_testing().size());
3589 } 3601 }
3590 3602
3591 } // namespace 3603 } // namespace
3592 } // namespace cc 3604 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698