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/element_animations.h" |
| 6 |
| 7 #include "cc/animation/animation_delegate.h" |
| 8 #include "cc/animation/animation_host.h" |
| 9 #include "cc/animation/animation_id_provider.h" |
| 10 #include "cc/animation/animation_player.h" |
| 11 #include "cc/animation/animation_registrar.h" |
| 12 #include "cc/animation/animation_timeline.h" |
| 13 #include "cc/test/animation_test_common.h" |
| 14 #include "cc/test/animation_timelines_test_common.h" |
| 15 |
| 16 namespace cc { |
| 17 namespace { |
| 18 |
| 19 class ElementAnimationsTest : public AnimationTimelinesTest { |
| 20 public: |
| 21 ElementAnimationsTest() {} |
| 22 ~ElementAnimationsTest() override {} |
| 23 }; |
| 24 |
| 25 // See animation_player_unittest.cc for integration with AnimationPlayer. |
| 26 |
| 27 TEST_F(ElementAnimationsTest, AttachToLayerInActiveTree) { |
| 28 // Set up the layer which is in active tree for main thread and not |
| 29 // yet passed onto the impl thread. |
| 30 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 31 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING); |
| 32 |
| 33 EXPECT_TRUE(client_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE)); |
| 34 EXPECT_FALSE(client_.IsLayerInTree(layer_id_, LayerTreeType::PENDING)); |
| 35 |
| 36 host_->AddAnimationTimeline(timeline_); |
| 37 |
| 38 timeline_->AttachPlayer(player_); |
| 39 player_->AttachLayer(layer_id_); |
| 40 |
| 41 ElementAnimations* element_animations = player_->element_animations(); |
| 42 EXPECT_TRUE(element_animations); |
| 43 |
| 44 EXPECT_TRUE(element_animations->has_active_value_observer_for_testing()); |
| 45 EXPECT_FALSE(element_animations->has_pending_value_observer_for_testing()); |
| 46 |
| 47 host_->PushPropertiesTo(host_impl_); |
| 48 |
| 49 GetImplTimelineAndPlayerByID(); |
| 50 |
| 51 ElementAnimations* element_animations_impl = |
| 52 player_impl_->element_animations(); |
| 53 EXPECT_TRUE(element_animations_impl); |
| 54 |
| 55 EXPECT_FALSE( |
| 56 element_animations_impl->has_active_value_observer_for_testing()); |
| 57 EXPECT_TRUE( |
| 58 element_animations_impl->has_pending_value_observer_for_testing()); |
| 59 |
| 60 // Create the layer in the impl active tree. |
| 61 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 62 EXPECT_TRUE(element_animations_impl->has_active_value_observer_for_testing()); |
| 63 EXPECT_TRUE( |
| 64 element_animations_impl->has_pending_value_observer_for_testing()); |
| 65 |
| 66 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE)); |
| 67 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::PENDING)); |
| 68 |
| 69 // kill layer on main thread. |
| 70 client_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 71 EXPECT_EQ(element_animations, player_->element_animations()); |
| 72 EXPECT_FALSE(element_animations->has_active_value_observer_for_testing()); |
| 73 EXPECT_FALSE(element_animations->has_pending_value_observer_for_testing()); |
| 74 |
| 75 // Sync doesn't detach LayerImpl. |
| 76 host_->PushPropertiesTo(host_impl_); |
| 77 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
| 78 EXPECT_TRUE(element_animations_impl->has_active_value_observer_for_testing()); |
| 79 EXPECT_TRUE( |
| 80 element_animations_impl->has_pending_value_observer_for_testing()); |
| 81 |
| 82 // Kill layer on impl thread in pending tree. |
| 83 client_impl_.UnregisterLayer(layer_id_, LayerTreeType::PENDING); |
| 84 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
| 85 EXPECT_TRUE(element_animations_impl->has_active_value_observer_for_testing()); |
| 86 EXPECT_FALSE( |
| 87 element_animations_impl->has_pending_value_observer_for_testing()); |
| 88 |
| 89 // Kill layer on impl thread in active tree. |
| 90 client_impl_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 91 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
| 92 EXPECT_FALSE( |
| 93 element_animations_impl->has_active_value_observer_for_testing()); |
| 94 EXPECT_FALSE( |
| 95 element_animations_impl->has_pending_value_observer_for_testing()); |
| 96 |
| 97 // Sync doesn't change anything. |
| 98 host_->PushPropertiesTo(host_impl_); |
| 99 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
| 100 EXPECT_FALSE( |
| 101 element_animations_impl->has_active_value_observer_for_testing()); |
| 102 EXPECT_FALSE( |
| 103 element_animations_impl->has_pending_value_observer_for_testing()); |
| 104 |
| 105 player_->DetachLayer(); |
| 106 EXPECT_FALSE(player_->element_animations()); |
| 107 |
| 108 // Release ptrs now to test the order of destruction. |
| 109 ReleaseRefPtrs(); |
| 110 } |
| 111 |
| 112 TEST_F(ElementAnimationsTest, AttachToNotYetCreatedLayer) { |
| 113 host_->AddAnimationTimeline(timeline_); |
| 114 timeline_->AttachPlayer(player_); |
| 115 |
| 116 host_->PushPropertiesTo(host_impl_); |
| 117 |
| 118 GetImplTimelineAndPlayerByID(); |
| 119 |
| 120 player_->AttachLayer(layer_id_); |
| 121 |
| 122 ElementAnimations* element_animations = player_->element_animations(); |
| 123 EXPECT_TRUE(element_animations); |
| 124 |
| 125 EXPECT_FALSE(element_animations->has_active_value_observer_for_testing()); |
| 126 EXPECT_FALSE(element_animations->has_pending_value_observer_for_testing()); |
| 127 |
| 128 host_->PushPropertiesTo(host_impl_); |
| 129 |
| 130 ElementAnimations* element_animations_impl = |
| 131 player_impl_->element_animations(); |
| 132 EXPECT_TRUE(element_animations_impl); |
| 133 |
| 134 EXPECT_FALSE( |
| 135 element_animations_impl->has_active_value_observer_for_testing()); |
| 136 EXPECT_FALSE( |
| 137 element_animations_impl->has_pending_value_observer_for_testing()); |
| 138 |
| 139 // Create layer. |
| 140 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 141 EXPECT_TRUE(element_animations->has_active_value_observer_for_testing()); |
| 142 EXPECT_FALSE(element_animations->has_pending_value_observer_for_testing()); |
| 143 |
| 144 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING); |
| 145 EXPECT_FALSE( |
| 146 element_animations_impl->has_active_value_observer_for_testing()); |
| 147 EXPECT_TRUE( |
| 148 element_animations_impl->has_pending_value_observer_for_testing()); |
| 149 |
| 150 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 151 EXPECT_TRUE(element_animations_impl->has_active_value_observer_for_testing()); |
| 152 EXPECT_TRUE( |
| 153 element_animations_impl->has_pending_value_observer_for_testing()); |
| 154 } |
| 155 |
| 156 TEST_F(ElementAnimationsTest, AddRemovePlayers) { |
| 157 host_->AddAnimationTimeline(timeline_); |
| 158 timeline_->AttachPlayer(player_); |
| 159 player_->AttachLayer(layer_id_); |
| 160 |
| 161 ElementAnimations* element_animations = player_->element_animations(); |
| 162 EXPECT_TRUE(element_animations); |
| 163 |
| 164 scoped_refptr<AnimationPlayer> player1 = |
| 165 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 166 scoped_refptr<AnimationPlayer> player2 = |
| 167 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 168 |
| 169 timeline_->AttachPlayer(player1); |
| 170 timeline_->AttachPlayer(player2); |
| 171 |
| 172 // Attach players to the same layer. |
| 173 player1->AttachLayer(layer_id_); |
| 174 player2->AttachLayer(layer_id_); |
| 175 |
| 176 EXPECT_EQ(element_animations, player1->element_animations()); |
| 177 EXPECT_EQ(element_animations, player2->element_animations()); |
| 178 |
| 179 host_->PushPropertiesTo(host_impl_); |
| 180 GetImplTimelineAndPlayerByID(); |
| 181 |
| 182 ElementAnimations* element_animations_impl = |
| 183 player_impl_->element_animations(); |
| 184 EXPECT_TRUE(element_animations_impl); |
| 185 |
| 186 int list_size_before = 0; |
| 187 for (const ElementAnimations::PlayersListNode* node = |
| 188 element_animations_impl->players_list().head(); |
| 189 node != element_animations_impl->players_list().end(); |
| 190 node = node->next()) { |
| 191 const AnimationPlayer* player_impl = node->value(); |
| 192 EXPECT_TRUE(timeline_->GetPlayerById(player_impl->id())); |
| 193 ++list_size_before; |
| 194 } |
| 195 EXPECT_EQ(3, list_size_before); |
| 196 |
| 197 player2->DetachLayer(); |
| 198 EXPECT_FALSE(player2->element_animations()); |
| 199 EXPECT_EQ(element_animations, player_->element_animations()); |
| 200 EXPECT_EQ(element_animations, player1->element_animations()); |
| 201 |
| 202 host_->PushPropertiesTo(host_impl_); |
| 203 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
| 204 |
| 205 int list_size_after = 0; |
| 206 for (const ElementAnimations::PlayersListNode* node = |
| 207 element_animations_impl->players_list().head(); |
| 208 node != element_animations_impl->players_list().end(); |
| 209 node = node->next()) { |
| 210 const AnimationPlayer* player_impl = node->value(); |
| 211 EXPECT_TRUE(timeline_->GetPlayerById(player_impl->id())); |
| 212 ++list_size_after; |
| 213 } |
| 214 EXPECT_EQ(2, list_size_after); |
| 215 } |
| 216 |
| 217 } // namespace |
| 218 } // namespace cc |
OLD | NEW |