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

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: clear events before update state in 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 // Finished animations are pushed, but animations_impl hasn't yet ticked
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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3297 3300
3298 TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) { 3301 TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) {
3299 CreateTestLayer(true, true); 3302 CreateTestLayer(true, true);
3300 AttachTimelinePlayerLayer(); 3303 AttachTimelinePlayerLayer();
3301 CreateImplTimelineAndPlayer(); 3304 CreateImplTimelineAndPlayer();
3302 3305
3303 auto events = CreateEventsForTesting(); 3306 auto events = CreateEventsForTesting();
3304 3307
3305 const int animation_id = 3308 const int animation_id =
3306 AddOpacityTransitionToPlayer(player_.get(), 1, 0.5f, 1.f, true); 3309 AddOpacityTransitionToPlayer(player_.get(), 1, 0.5f, 1.f, true);
3307
3308 PushProperties(); 3310 PushProperties();
3309 player_impl_->ActivateAnimations(); 3311 player_impl_->ActivateAnimations();
3310 player_impl_->Tick(kInitialTickTime); 3312 player_impl_->Tick(kInitialTickTime);
3311 player_impl_->UpdateState(true, events.get()); 3313 player_impl_->UpdateState(true, events.get());
3312 EXPECT_EQ(Animation::RUNNING, 3314 EXPECT_EQ(Animation::RUNNING,
3313 player_impl_->GetAnimationById(animation_id)->run_state()); 3315 player_impl_->GetAnimationById(animation_id)->run_state());
3314 EXPECT_EQ(0.5f, 3316 EXPECT_EQ(0.5f,
3315 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3317 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3316 EXPECT_EQ(0.5f, 3318 EXPECT_EQ(0.5f,
3317 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3319 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
(...skipping 17 matching lines...) Expand all
3335 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 3337 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500));
3336 player_impl_->UpdateState(true, events.get()); 3338 player_impl_->UpdateState(true, events.get());
3337 3339
3338 // Only the active observer should have been ticked. 3340 // Only the active observer should have been ticked.
3339 EXPECT_EQ(0.5f, 3341 EXPECT_EQ(0.5f,
3340 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3342 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3341 EXPECT_EQ(0.75f, 3343 EXPECT_EQ(0.75f,
3342 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3344 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
3343 3345
3344 player_impl_->ActivateAnimations(); 3346 player_impl_->ActivateAnimations();
3347 events = CreateEventsForTesting();
3348 player_impl_->UpdateState(true, events.get());
3345 3349
3346 // Activation should cause the animation to be deleted. 3350 // After Activation the animation doesn't affect neither active nor pending
3351 // thread. UpdateState for this animation would put the animation to wait for
3352 // deletion state.
3353 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
3354 player_impl_->GetAnimationById(animation_id)->run_state());
3355 EXPECT_EQ(1u, events->events_.size());
3356
3357 // The animation is finished on impl thread, and main thread will delete it
3358 // during commit.
3359 player_->animation_host()->SetAnimationEvents(std::move(events));
3360 PushProperties();
3347 EXPECT_FALSE(player_impl_->has_any_animation()); 3361 EXPECT_FALSE(player_impl_->has_any_animation());
3348 } 3362 }
3349 3363
3350 // Tests that an animation that affects only active elements won't block 3364 // Tests that an animation that affects only active elements won't block
3351 // an animation that affects only pending elements from starting. 3365 // an animation that affects only pending elements from starting.
3352 TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) { 3366 TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) {
3353 CreateTestLayer(true, true); 3367 CreateTestLayer(true, true);
3354 AttachTimelinePlayerLayer(); 3368 AttachTimelinePlayerLayer();
3355 CreateImplTimelineAndPlayer(); 3369 CreateImplTimelineAndPlayer();
3356 3370
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3395 3409
3396 // The active observer should have been ticked by the original animation, 3410 // The active observer should have been ticked by the original animation,
3397 // and the pending observer should have been ticked by the new animation. 3411 // and the pending observer should have been ticked by the new animation.
3398 EXPECT_EQ(1.f, 3412 EXPECT_EQ(1.f,
3399 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3413 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3400 EXPECT_EQ(0.5f, 3414 EXPECT_EQ(0.5f,
3401 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3415 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
3402 3416
3403 player_impl_->ActivateAnimations(); 3417 player_impl_->ActivateAnimations();
3404 3418
3405 // The original animation should have been deleted, and the new animation 3419 // The original animation no longer affect either elements, and the new
3406 // should now affect both elements. 3420 // animation should now affect both elements.
3407 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)); 3421 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)
3422 ->affects_pending_elements());
3423 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)
3424 ->affects_active_elements());
3408 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id) 3425 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id)
3409 ->affects_pending_elements()); 3426 ->affects_pending_elements());
3410 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id) 3427 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id)
3411 ->affects_active_elements()); 3428 ->affects_active_elements());
3412 3429
3413 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 3430 player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
3414 player_impl_->UpdateState(true, events.get()); 3431 player_impl_->UpdateState(true, events.get());
3415 3432
3433 // The original animation should be marked for waiting for deletion.
3434 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
3435 player_impl_->GetAnimationById(first_animation_id)->run_state());
3436
3416 // The new animation should be running, and the active observer should have 3437 // The new animation should be running, and the active observer should have
3417 // been ticked at the new animation's starting point. 3438 // been ticked at the new animation's starting point.
3418 EXPECT_EQ(Animation::RUNNING, 3439 EXPECT_EQ(Animation::RUNNING,
3419 player_impl_->GetAnimationById(second_animation_id)->run_state()); 3440 player_impl_->GetAnimationById(second_animation_id)->run_state());
3420 EXPECT_EQ(1.f, 3441 EXPECT_EQ(1.f,
3421 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); 3442 client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
3422 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); 3443 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
3423 } 3444 }
3424 3445
3425 TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) { 3446 TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
3605 // Ensure that adding a new animation will correctly update the ticking 3626 // Ensure that adding a new animation will correctly update the ticking
3606 // players list. 3627 // players list.
3607 player_->AddAnimation(CreateAnimation( 3628 player_->AddAnimation(CreateAnimation(
3608 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), 3629 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)),
3609 2, TargetProperty::OPACITY)); 3630 2, TargetProperty::OPACITY));
3610 EXPECT_EQ(1u, host_->ticking_players_for_testing().size()); 3631 EXPECT_EQ(1u, host_->ticking_players_for_testing().size());
3611 } 3632 }
3612 3633
3613 } // namespace 3634 } // namespace
3614 } // namespace cc 3635 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_player_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698