Implements RLZTrackerDelegate on iOS.
[chromium-blink-merge.git] / cc / animation / element_animations_unittest.cc
blobb676906c3c8b8166149e15b2d6d1aec531f58c74
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.
5 #include "cc/animation/element_animations.h"
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"
16 namespace cc {
17 namespace {
19 class ElementAnimationsTest : public AnimationTimelinesTest {
20 public:
21 ElementAnimationsTest() {}
22 ~ElementAnimationsTest() override {}
25 // See animation_player_unittest.cc for integration with AnimationPlayer.
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);
33 EXPECT_TRUE(client_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE));
34 EXPECT_FALSE(client_.IsLayerInTree(layer_id_, LayerTreeType::PENDING));
36 host_->AddAnimationTimeline(timeline_);
38 timeline_->AttachPlayer(player_);
39 player_->AttachLayer(layer_id_);
41 ElementAnimations* element_animations = player_->element_animations();
42 EXPECT_TRUE(element_animations);
44 EXPECT_TRUE(element_animations->has_active_value_observer_for_testing());
45 EXPECT_FALSE(element_animations->has_pending_value_observer_for_testing());
47 host_->PushPropertiesTo(host_impl_);
49 GetImplTimelineAndPlayerByID();
51 ElementAnimations* element_animations_impl =
52 player_impl_->element_animations();
53 EXPECT_TRUE(element_animations_impl);
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());
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());
66 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE));
67 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::PENDING));
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());
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());
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());
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());
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());
105 player_->DetachLayer();
106 EXPECT_FALSE(player_->element_animations());
108 // Release ptrs now to test the order of destruction.
109 ReleaseRefPtrs();
112 TEST_F(ElementAnimationsTest, AttachToNotYetCreatedLayer) {
113 host_->AddAnimationTimeline(timeline_);
114 timeline_->AttachPlayer(player_);
116 host_->PushPropertiesTo(host_impl_);
118 GetImplTimelineAndPlayerByID();
120 player_->AttachLayer(layer_id_);
122 ElementAnimations* element_animations = player_->element_animations();
123 EXPECT_TRUE(element_animations);
125 EXPECT_FALSE(element_animations->has_active_value_observer_for_testing());
126 EXPECT_FALSE(element_animations->has_pending_value_observer_for_testing());
128 host_->PushPropertiesTo(host_impl_);
130 ElementAnimations* element_animations_impl =
131 player_impl_->element_animations();
132 EXPECT_TRUE(element_animations_impl);
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());
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());
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());
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());
156 TEST_F(ElementAnimationsTest, AddRemovePlayers) {
157 host_->AddAnimationTimeline(timeline_);
158 timeline_->AttachPlayer(player_);
159 player_->AttachLayer(layer_id_);
161 ElementAnimations* element_animations = player_->element_animations();
162 EXPECT_TRUE(element_animations);
164 scoped_refptr<AnimationPlayer> player1 =
165 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
166 scoped_refptr<AnimationPlayer> player2 =
167 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
169 timeline_->AttachPlayer(player1);
170 timeline_->AttachPlayer(player2);
172 // Attach players to the same layer.
173 player1->AttachLayer(layer_id_);
174 player2->AttachLayer(layer_id_);
176 EXPECT_EQ(element_animations, player1->element_animations());
177 EXPECT_EQ(element_animations, player2->element_animations());
179 host_->PushPropertiesTo(host_impl_);
180 GetImplTimelineAndPlayerByID();
182 ElementAnimations* element_animations_impl =
183 player_impl_->element_animations();
184 EXPECT_TRUE(element_animations_impl);
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;
195 EXPECT_EQ(3, list_size_before);
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());
202 host_->PushPropertiesTo(host_impl_);
203 EXPECT_EQ(element_animations_impl, player_impl_->element_animations());
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;
214 EXPECT_EQ(2, list_size_after);
217 } // namespace
218 } // namespace cc