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