OLD | NEW |
(Empty) | |
| 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_host.h" |
| 8 #include "cc/animation/animation_player.h" |
| 9 #include "cc/test/animation_test_common.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace cc { |
| 14 namespace { |
| 15 |
| 16 TEST(AnimationTimelineTest, SyncPlayersAttachDetach) { |
| 17 scoped_ptr<AnimationHost> host(AnimationHost::Create(false)); |
| 18 scoped_ptr<AnimationHost> host_impl(AnimationHost::Create(true)); |
| 19 |
| 20 const int timeline_id = 1; |
| 21 const int player_id = 1; |
| 22 |
| 23 scoped_refptr<AnimationTimeline> timeline_impl( |
| 24 AnimationTimeline::Create(timeline_id)); |
| 25 scoped_refptr<AnimationTimeline> timeline( |
| 26 AnimationTimeline::Create(timeline_id)); |
| 27 |
| 28 host->AddAnimationTimeline(timeline.get()); |
| 29 EXPECT_TRUE(timeline->animation_host()); |
| 30 |
| 31 host_impl->AddAnimationTimeline(timeline_impl.get()); |
| 32 EXPECT_TRUE(timeline_impl->animation_host()); |
| 33 |
| 34 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(player_id)); |
| 35 timeline->AttachPlayer(player.get()); |
| 36 EXPECT_TRUE(player->animation_timeline()); |
| 37 |
| 38 EXPECT_FALSE(timeline_impl->GetPlayerById(player_id)); |
| 39 |
| 40 timeline->PushPropertiesTo(timeline_impl.get()); |
| 41 |
| 42 scoped_refptr<AnimationPlayer> player_impl = |
| 43 timeline_impl->GetPlayerById(player_id); |
| 44 EXPECT_TRUE(player_impl); |
| 45 EXPECT_EQ(player_impl->id(), player_id); |
| 46 EXPECT_TRUE(player_impl->animation_timeline()); |
| 47 |
| 48 timeline->PushPropertiesTo(timeline_impl.get()); |
| 49 EXPECT_EQ(player_impl, timeline_impl->GetPlayerById(player_id)); |
| 50 |
| 51 timeline->DetachPlayer(player.get()); |
| 52 EXPECT_FALSE(player->animation_timeline()); |
| 53 |
| 54 timeline->PushPropertiesTo(timeline_impl.get()); |
| 55 EXPECT_FALSE(timeline_impl->GetPlayerById(player_id)); |
| 56 |
| 57 EXPECT_FALSE(player_impl->animation_timeline()); |
| 58 } |
| 59 |
| 60 TEST(AnimationTimelineTest, ClearPlayers) { |
| 61 scoped_ptr<AnimationHost> host(AnimationHost::Create(false)); |
| 62 scoped_ptr<AnimationHost> host_impl(AnimationHost::Create(true)); |
| 63 |
| 64 const int timeline_id = 1; |
| 65 const int player_id1 = 1; |
| 66 const int player_id2 = 2; |
| 67 |
| 68 scoped_refptr<AnimationTimeline> timeline_impl( |
| 69 AnimationTimeline::Create(timeline_id)); |
| 70 scoped_refptr<AnimationTimeline> timeline( |
| 71 AnimationTimeline::Create(timeline_id)); |
| 72 |
| 73 host->AddAnimationTimeline(timeline.get()); |
| 74 host_impl->AddAnimationTimeline(timeline_impl.get()); |
| 75 |
| 76 scoped_refptr<AnimationPlayer> player1(AnimationPlayer::Create(player_id1)); |
| 77 timeline->AttachPlayer(player1.get()); |
| 78 scoped_refptr<AnimationPlayer> player2(AnimationPlayer::Create(player_id2)); |
| 79 timeline->AttachPlayer(player2.get()); |
| 80 |
| 81 timeline->PushPropertiesTo(timeline_impl.get()); |
| 82 |
| 83 EXPECT_TRUE(timeline_impl->GetPlayerById(player_id1)); |
| 84 EXPECT_TRUE(timeline_impl->GetPlayerById(player_id2)); |
| 85 |
| 86 timeline->ClearPlayers(); |
| 87 EXPECT_FALSE(timeline->GetPlayerById(player_id1)); |
| 88 EXPECT_FALSE(timeline->GetPlayerById(player_id2)); |
| 89 |
| 90 timeline_impl->ClearPlayers(); |
| 91 EXPECT_FALSE(timeline_impl->GetPlayerById(player_id1)); |
| 92 EXPECT_FALSE(timeline_impl->GetPlayerById(player_id2)); |
| 93 } |
| 94 |
| 95 } // namespace |
| 96 } // namespace cc |
OLD | NEW |