| OLD | NEW |
| 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 "cc/animation/animation_delegate.h" | 7 #include "cc/animation/animation_delegate.h" |
| 8 #include "cc/animation/animation_host.h" | 8 #include "cc/animation/animation_host.h" |
| 9 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
| 10 #include "cc/animation/animation_player.h" | 10 #include "cc/animation/animation_player.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 EXPECT_FALSE(client_.IsLayerInTree(layer_id_, LayerTreeType::PENDING)); | 33 EXPECT_FALSE(client_.IsLayerInTree(layer_id_, LayerTreeType::PENDING)); |
| 34 | 34 |
| 35 host_->AddAnimationTimeline(timeline_); | 35 host_->AddAnimationTimeline(timeline_); |
| 36 | 36 |
| 37 timeline_->AttachPlayer(player_); | 37 timeline_->AttachPlayer(player_); |
| 38 player_->AttachLayer(layer_id_); | 38 player_->AttachLayer(layer_id_); |
| 39 | 39 |
| 40 ElementAnimations* element_animations = player_->element_animations(); | 40 ElementAnimations* element_animations = player_->element_animations(); |
| 41 EXPECT_TRUE(element_animations); | 41 EXPECT_TRUE(element_animations); |
| 42 | 42 |
| 43 EXPECT_TRUE(element_animations->has_active_value_observer_for_testing()); | 43 EXPECT_TRUE(element_animations->needs_active_value_observations()); |
| 44 EXPECT_FALSE(element_animations->has_pending_value_observer_for_testing()); | 44 EXPECT_FALSE(element_animations->needs_pending_value_observations()); |
| 45 | 45 |
| 46 host_->PushPropertiesTo(host_impl_); | 46 host_->PushPropertiesTo(host_impl_); |
| 47 | 47 |
| 48 GetImplTimelineAndPlayerByID(); | 48 GetImplTimelineAndPlayerByID(); |
| 49 | 49 |
| 50 ElementAnimations* element_animations_impl = | 50 ElementAnimations* element_animations_impl = |
| 51 player_impl_->element_animations(); | 51 player_impl_->element_animations(); |
| 52 EXPECT_TRUE(element_animations_impl); | 52 EXPECT_TRUE(element_animations_impl); |
| 53 | 53 |
| 54 EXPECT_FALSE( | 54 EXPECT_FALSE(element_animations_impl->needs_active_value_observations()); |
| 55 element_animations_impl->has_active_value_observer_for_testing()); | 55 EXPECT_TRUE(element_animations_impl->needs_pending_value_observations()); |
| 56 EXPECT_TRUE( | |
| 57 element_animations_impl->has_pending_value_observer_for_testing()); | |
| 58 | 56 |
| 59 // Create the layer in the impl active tree. | 57 // Create the layer in the impl active tree. |
| 60 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); | 58 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 61 EXPECT_TRUE(element_animations_impl->has_active_value_observer_for_testing()); | 59 EXPECT_TRUE(element_animations_impl->needs_active_value_observations()); |
| 62 EXPECT_TRUE( | 60 EXPECT_TRUE(element_animations_impl->needs_pending_value_observations()); |
| 63 element_animations_impl->has_pending_value_observer_for_testing()); | |
| 64 | 61 |
| 65 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE)); | 62 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE)); |
| 66 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::PENDING)); | 63 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::PENDING)); |
| 67 | 64 |
| 68 // kill layer on main thread. | 65 // kill layer on main thread. |
| 69 client_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE); | 66 client_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 70 EXPECT_EQ(element_animations, player_->element_animations()); | 67 EXPECT_EQ(element_animations, player_->element_animations()); |
| 71 EXPECT_FALSE(element_animations->has_active_value_observer_for_testing()); | 68 EXPECT_FALSE(element_animations->needs_active_value_observations()); |
| 72 EXPECT_FALSE(element_animations->has_pending_value_observer_for_testing()); | 69 EXPECT_FALSE(element_animations->needs_pending_value_observations()); |
| 73 | 70 |
| 74 // Sync doesn't detach LayerImpl. | 71 // Sync doesn't detach LayerImpl. |
| 75 host_->PushPropertiesTo(host_impl_); | 72 host_->PushPropertiesTo(host_impl_); |
| 76 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 73 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
| 77 EXPECT_TRUE(element_animations_impl->has_active_value_observer_for_testing()); | 74 EXPECT_TRUE(element_animations_impl->needs_active_value_observations()); |
| 78 EXPECT_TRUE( | 75 EXPECT_TRUE(element_animations_impl->needs_pending_value_observations()); |
| 79 element_animations_impl->has_pending_value_observer_for_testing()); | |
| 80 | 76 |
| 81 // Kill layer on impl thread in pending tree. | 77 // Kill layer on impl thread in pending tree. |
| 82 client_impl_.UnregisterLayer(layer_id_, LayerTreeType::PENDING); | 78 client_impl_.UnregisterLayer(layer_id_, LayerTreeType::PENDING); |
| 83 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 79 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
| 84 EXPECT_TRUE(element_animations_impl->has_active_value_observer_for_testing()); | 80 EXPECT_TRUE(element_animations_impl->needs_active_value_observations()); |
| 85 EXPECT_FALSE( | 81 EXPECT_FALSE(element_animations_impl->needs_pending_value_observations()); |
| 86 element_animations_impl->has_pending_value_observer_for_testing()); | |
| 87 | 82 |
| 88 // Kill layer on impl thread in active tree. | 83 // Kill layer on impl thread in active tree. |
| 89 client_impl_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE); | 84 client_impl_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 90 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 85 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
| 91 EXPECT_FALSE( | 86 EXPECT_FALSE(element_animations_impl->needs_active_value_observations()); |
| 92 element_animations_impl->has_active_value_observer_for_testing()); | 87 EXPECT_FALSE(element_animations_impl->needs_pending_value_observations()); |
| 93 EXPECT_FALSE( | |
| 94 element_animations_impl->has_pending_value_observer_for_testing()); | |
| 95 | 88 |
| 96 // Sync doesn't change anything. | 89 // Sync doesn't change anything. |
| 97 host_->PushPropertiesTo(host_impl_); | 90 host_->PushPropertiesTo(host_impl_); |
| 98 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 91 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
| 99 EXPECT_FALSE( | 92 EXPECT_FALSE(element_animations_impl->needs_active_value_observations()); |
| 100 element_animations_impl->has_active_value_observer_for_testing()); | 93 EXPECT_FALSE(element_animations_impl->needs_pending_value_observations()); |
| 101 EXPECT_FALSE( | |
| 102 element_animations_impl->has_pending_value_observer_for_testing()); | |
| 103 | 94 |
| 104 player_->DetachLayer(); | 95 player_->DetachLayer(); |
| 105 EXPECT_FALSE(player_->element_animations()); | 96 EXPECT_FALSE(player_->element_animations()); |
| 106 | 97 |
| 107 // Release ptrs now to test the order of destruction. | 98 // Release ptrs now to test the order of destruction. |
| 108 ReleaseRefPtrs(); | 99 ReleaseRefPtrs(); |
| 109 } | 100 } |
| 110 | 101 |
| 111 TEST_F(ElementAnimationsTest, AttachToNotYetCreatedLayer) { | 102 TEST_F(ElementAnimationsTest, AttachToNotYetCreatedLayer) { |
| 112 host_->AddAnimationTimeline(timeline_); | 103 host_->AddAnimationTimeline(timeline_); |
| 113 timeline_->AttachPlayer(player_); | 104 timeline_->AttachPlayer(player_); |
| 114 | 105 |
| 115 host_->PushPropertiesTo(host_impl_); | 106 host_->PushPropertiesTo(host_impl_); |
| 116 | 107 |
| 117 GetImplTimelineAndPlayerByID(); | 108 GetImplTimelineAndPlayerByID(); |
| 118 | 109 |
| 119 player_->AttachLayer(layer_id_); | 110 player_->AttachLayer(layer_id_); |
| 120 | 111 |
| 121 ElementAnimations* element_animations = player_->element_animations(); | 112 ElementAnimations* element_animations = player_->element_animations(); |
| 122 EXPECT_TRUE(element_animations); | 113 EXPECT_TRUE(element_animations); |
| 123 | 114 |
| 124 EXPECT_FALSE(element_animations->has_active_value_observer_for_testing()); | 115 EXPECT_FALSE(element_animations->needs_active_value_observations()); |
| 125 EXPECT_FALSE(element_animations->has_pending_value_observer_for_testing()); | 116 EXPECT_FALSE(element_animations->needs_pending_value_observations()); |
| 126 | 117 |
| 127 host_->PushPropertiesTo(host_impl_); | 118 host_->PushPropertiesTo(host_impl_); |
| 128 | 119 |
| 129 ElementAnimations* element_animations_impl = | 120 ElementAnimations* element_animations_impl = |
| 130 player_impl_->element_animations(); | 121 player_impl_->element_animations(); |
| 131 EXPECT_TRUE(element_animations_impl); | 122 EXPECT_TRUE(element_animations_impl); |
| 132 | 123 |
| 133 EXPECT_FALSE( | 124 EXPECT_FALSE(element_animations_impl->needs_active_value_observations()); |
| 134 element_animations_impl->has_active_value_observer_for_testing()); | 125 EXPECT_FALSE(element_animations_impl->needs_pending_value_observations()); |
| 135 EXPECT_FALSE( | |
| 136 element_animations_impl->has_pending_value_observer_for_testing()); | |
| 137 | 126 |
| 138 // Create layer. | 127 // Create layer. |
| 139 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); | 128 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 140 EXPECT_TRUE(element_animations->has_active_value_observer_for_testing()); | 129 EXPECT_TRUE(element_animations->needs_active_value_observations()); |
| 141 EXPECT_FALSE(element_animations->has_pending_value_observer_for_testing()); | 130 EXPECT_FALSE(element_animations->needs_pending_value_observations()); |
| 142 | 131 |
| 143 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING); | 132 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING); |
| 144 EXPECT_FALSE( | 133 EXPECT_FALSE(element_animations_impl->needs_active_value_observations()); |
| 145 element_animations_impl->has_active_value_observer_for_testing()); | 134 EXPECT_TRUE(element_animations_impl->needs_pending_value_observations()); |
| 146 EXPECT_TRUE( | |
| 147 element_animations_impl->has_pending_value_observer_for_testing()); | |
| 148 | 135 |
| 149 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); | 136 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 150 EXPECT_TRUE(element_animations_impl->has_active_value_observer_for_testing()); | 137 EXPECT_TRUE(element_animations_impl->needs_active_value_observations()); |
| 151 EXPECT_TRUE( | 138 EXPECT_TRUE(element_animations_impl->needs_pending_value_observations()); |
| 152 element_animations_impl->has_pending_value_observer_for_testing()); | |
| 153 } | 139 } |
| 154 | 140 |
| 155 TEST_F(ElementAnimationsTest, AddRemovePlayers) { | 141 TEST_F(ElementAnimationsTest, AddRemovePlayers) { |
| 156 host_->AddAnimationTimeline(timeline_); | 142 host_->AddAnimationTimeline(timeline_); |
| 157 timeline_->AttachPlayer(player_); | 143 timeline_->AttachPlayer(player_); |
| 158 player_->AttachLayer(layer_id_); | 144 player_->AttachLayer(layer_id_); |
| 159 | 145 |
| 160 ElementAnimations* element_animations = player_->element_animations(); | 146 ElementAnimations* element_animations = player_->element_animations(); |
| 161 EXPECT_TRUE(element_animations); | 147 EXPECT_TRUE(element_animations); |
| 162 | 148 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 node = node->next()) { | 194 node = node->next()) { |
| 209 const AnimationPlayer* player_impl = node->value(); | 195 const AnimationPlayer* player_impl = node->value(); |
| 210 EXPECT_TRUE(timeline_->GetPlayerById(player_impl->id())); | 196 EXPECT_TRUE(timeline_->GetPlayerById(player_impl->id())); |
| 211 ++list_size_after; | 197 ++list_size_after; |
| 212 } | 198 } |
| 213 EXPECT_EQ(2, list_size_after); | 199 EXPECT_EQ(2, list_size_after); |
| 214 } | 200 } |
| 215 | 201 |
| 216 } // namespace | 202 } // namespace |
| 217 } // namespace cc | 203 } // namespace cc |
| OLD | NEW |