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 3 // found in the LICENSE file. 4 5 #include "cc/animation/animation_timeline.h" 6 7 #include "cc/animation/animation.h" 8 #include "cc/animation/animation_host.h" 9 #include "cc/animation/animation_id_provider.h" 10 #include "cc/test/animation_test_common.h" 11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gtest/include/gtest/gtest.h" 13 14 namespace cc { 15 namespace { 16 TEST(AnimationTimelineTest,SyncAnimationsAttachDetach)17TEST(AnimationTimelineTest, SyncAnimationsAttachDetach) { 18 std::unique_ptr<AnimationHost> host( 19 AnimationHost::CreateForTesting(ThreadInstance::MAIN)); 20 std::unique_ptr<AnimationHost> host_impl( 21 AnimationHost::CreateForTesting(ThreadInstance::IMPL)); 22 23 const int timeline_id = AnimationIdProvider::NextTimelineId(); 24 const int animation_id = AnimationIdProvider::NextAnimationId(); 25 26 scoped_refptr<AnimationTimeline> timeline_impl( 27 AnimationTimeline::Create(timeline_id)); 28 scoped_refptr<AnimationTimeline> timeline( 29 AnimationTimeline::Create(timeline_id)); 30 31 host->AddAnimationTimeline(timeline.get()); 32 EXPECT_TRUE(timeline->animation_host()); 33 34 host_impl->AddAnimationTimeline(timeline_impl.get()); 35 EXPECT_TRUE(timeline_impl->animation_host()); 36 37 scoped_refptr<Animation> animation(Animation::Create(animation_id)); 38 timeline->AttachAnimation(animation.get()); 39 EXPECT_TRUE(animation->animation_timeline()); 40 41 EXPECT_FALSE(timeline_impl->GetAnimationById(animation_id)); 42 43 timeline->PushPropertiesTo(timeline_impl.get()); 44 45 scoped_refptr<Animation> animation_impl = 46 timeline_impl->GetAnimationById(animation_id); 47 EXPECT_TRUE(animation_impl); 48 EXPECT_EQ(animation_impl->id(), animation_id); 49 EXPECT_TRUE(animation_impl->animation_timeline()); 50 51 timeline->PushPropertiesTo(timeline_impl.get()); 52 EXPECT_EQ(animation_impl, timeline_impl->GetAnimationById(animation_id)); 53 54 timeline->DetachAnimation(animation.get()); 55 EXPECT_FALSE(animation->animation_timeline()); 56 57 timeline->PushPropertiesTo(timeline_impl.get()); 58 EXPECT_FALSE(timeline_impl->GetAnimationById(animation_id)); 59 60 EXPECT_FALSE(animation_impl->animation_timeline()); 61 } 62 TEST(AnimationTimelineTest,ClearAnimations)63TEST(AnimationTimelineTest, ClearAnimations) { 64 std::unique_ptr<AnimationHost> host( 65 AnimationHost::CreateForTesting(ThreadInstance::MAIN)); 66 std::unique_ptr<AnimationHost> host_impl( 67 AnimationHost::CreateForTesting(ThreadInstance::IMPL)); 68 69 const int timeline_id = AnimationIdProvider::NextTimelineId(); 70 const int animation_id1 = AnimationIdProvider::NextAnimationId(); 71 const int animation_id2 = AnimationIdProvider::NextAnimationId(); 72 73 scoped_refptr<AnimationTimeline> timeline_impl( 74 AnimationTimeline::Create(timeline_id)); 75 scoped_refptr<AnimationTimeline> timeline( 76 AnimationTimeline::Create(timeline_id)); 77 78 host->AddAnimationTimeline(timeline.get()); 79 host_impl->AddAnimationTimeline(timeline_impl.get()); 80 81 scoped_refptr<Animation> animation1(Animation::Create(animation_id1)); 82 timeline->AttachAnimation(animation1.get()); 83 scoped_refptr<Animation> animation2(Animation::Create(animation_id2)); 84 timeline->AttachAnimation(animation2.get()); 85 86 timeline->PushPropertiesTo(timeline_impl.get()); 87 88 EXPECT_TRUE(timeline_impl->GetAnimationById(animation_id1)); 89 EXPECT_TRUE(timeline_impl->GetAnimationById(animation_id2)); 90 91 timeline->ClearAnimations(); 92 EXPECT_FALSE(timeline->GetAnimationById(animation_id1)); 93 EXPECT_FALSE(timeline->GetAnimationById(animation_id2)); 94 95 timeline_impl->ClearAnimations(); 96 EXPECT_FALSE(timeline_impl->GetAnimationById(animation_id1)); 97 EXPECT_FALSE(timeline_impl->GetAnimationById(animation_id2)); 98 } 99 100 } // namespace 101 } // namespace cc 102