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_events.h" |
8 #include "cc/animation/animation_host.h" | 9 #include "cc/animation/animation_host.h" |
9 #include "cc/animation/animation_id_provider.h" | 10 #include "cc/animation/animation_id_provider.h" |
10 #include "cc/animation/animation_player.h" | 11 #include "cc/animation/animation_player.h" |
11 #include "cc/animation/animation_timeline.h" | 12 #include "cc/animation/animation_timeline.h" |
12 #include "cc/animation/keyframed_animation_curve.h" | 13 #include "cc/animation/keyframed_animation_curve.h" |
13 #include "cc/animation/scroll_offset_animation_curve.h" | 14 #include "cc/animation/scroll_offset_animation_curve.h" |
14 #include "cc/animation/transform_operations.h" | 15 #include "cc/animation/transform_operations.h" |
15 #include "cc/test/animation_test_common.h" | 16 #include "cc/test/animation_test_common.h" |
16 #include "cc/test/animation_timelines_test_common.h" | 17 #include "cc/test/animation_timelines_test_common.h" |
17 #include "ui/gfx/geometry/box_f.h" | 18 #include "ui/gfx/geometry/box_f.h" |
(...skipping 24 matching lines...) Expand all Loading... |
42 | 43 |
43 TEST_F(ElementAnimationsTest, AttachToLayerInActiveTree) { | 44 TEST_F(ElementAnimationsTest, AttachToLayerInActiveTree) { |
44 // Set up the layer which is in active tree for main thread and not | 45 // Set up the layer which is in active tree for main thread and not |
45 // yet passed onto the impl thread. | 46 // yet passed onto the impl thread. |
46 client_.RegisterElement(element_id_, ElementListType::ACTIVE); | 47 client_.RegisterElement(element_id_, ElementListType::ACTIVE); |
47 client_impl_.RegisterElement(element_id_, ElementListType::PENDING); | 48 client_impl_.RegisterElement(element_id_, ElementListType::PENDING); |
48 | 49 |
49 EXPECT_TRUE(client_.IsElementInList(element_id_, ElementListType::ACTIVE)); | 50 EXPECT_TRUE(client_.IsElementInList(element_id_, ElementListType::ACTIVE)); |
50 EXPECT_FALSE(client_.IsElementInList(element_id_, ElementListType::PENDING)); | 51 EXPECT_FALSE(client_.IsElementInList(element_id_, ElementListType::PENDING)); |
51 | 52 |
52 host_->AddAnimationTimeline(timeline_); | 53 AttachTimelinePlayerLayer(); |
53 | 54 |
54 timeline_->AttachPlayer(player_); | 55 EXPECT_TRUE(element_animations_->has_element_in_active_list()); |
55 player_->AttachElement(element_id_); | 56 EXPECT_FALSE(element_animations_->has_element_in_pending_list()); |
56 | |
57 scoped_refptr<ElementAnimations> element_animations = | |
58 player_->element_animations(); | |
59 EXPECT_TRUE(element_animations); | |
60 | |
61 EXPECT_TRUE(element_animations->has_element_in_active_list()); | |
62 EXPECT_FALSE(element_animations->has_element_in_pending_list()); | |
63 | 57 |
64 PushProperties(); | 58 PushProperties(); |
65 | 59 |
66 GetImplTimelineAndPlayerByID(); | 60 GetImplTimelineAndPlayerByID(); |
67 | 61 |
68 scoped_refptr<ElementAnimations> element_animations_impl = | 62 EXPECT_FALSE(element_animations_impl_->has_element_in_active_list()); |
69 player_impl_->element_animations(); | 63 EXPECT_TRUE(element_animations_impl_->has_element_in_pending_list()); |
70 EXPECT_TRUE(element_animations_impl); | |
71 | |
72 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); | |
73 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); | |
74 | 64 |
75 // Create the layer in the impl active tree. | 65 // Create the layer in the impl active tree. |
76 client_impl_.RegisterElement(element_id_, ElementListType::ACTIVE); | 66 client_impl_.RegisterElement(element_id_, ElementListType::ACTIVE); |
77 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); | 67 EXPECT_TRUE(element_animations_impl_->has_element_in_active_list()); |
78 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); | 68 EXPECT_TRUE(element_animations_impl_->has_element_in_pending_list()); |
79 | 69 |
80 EXPECT_TRUE( | 70 EXPECT_TRUE( |
81 client_impl_.IsElementInList(element_id_, ElementListType::ACTIVE)); | 71 client_impl_.IsElementInList(element_id_, ElementListType::ACTIVE)); |
82 EXPECT_TRUE( | 72 EXPECT_TRUE( |
83 client_impl_.IsElementInList(element_id_, ElementListType::PENDING)); | 73 client_impl_.IsElementInList(element_id_, ElementListType::PENDING)); |
84 | 74 |
85 // kill layer on main thread. | 75 // kill layer on main thread. |
86 client_.UnregisterElement(element_id_, ElementListType::ACTIVE); | 76 client_.UnregisterElement(element_id_, ElementListType::ACTIVE); |
87 EXPECT_EQ(element_animations, player_->element_animations()); | 77 EXPECT_EQ(element_animations_, player_->element_animations()); |
88 EXPECT_FALSE(element_animations->has_element_in_active_list()); | 78 EXPECT_FALSE(element_animations_->has_element_in_active_list()); |
89 EXPECT_FALSE(element_animations->has_element_in_pending_list()); | 79 EXPECT_FALSE(element_animations_->has_element_in_pending_list()); |
90 | 80 |
91 // Sync doesn't detach LayerImpl. | 81 // Sync doesn't detach LayerImpl. |
92 PushProperties(); | 82 PushProperties(); |
93 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 83 EXPECT_EQ(element_animations_impl_, player_impl_->element_animations()); |
94 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); | 84 EXPECT_TRUE(element_animations_impl_->has_element_in_active_list()); |
95 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); | 85 EXPECT_TRUE(element_animations_impl_->has_element_in_pending_list()); |
96 | 86 |
97 // Kill layer on impl thread in pending tree. | 87 // Kill layer on impl thread in pending tree. |
98 client_impl_.UnregisterElement(element_id_, ElementListType::PENDING); | 88 client_impl_.UnregisterElement(element_id_, ElementListType::PENDING); |
99 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 89 EXPECT_EQ(element_animations_impl_, player_impl_->element_animations()); |
100 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); | 90 EXPECT_TRUE(element_animations_impl_->has_element_in_active_list()); |
101 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); | 91 EXPECT_FALSE(element_animations_impl_->has_element_in_pending_list()); |
102 | 92 |
103 // Kill layer on impl thread in active tree. | 93 // Kill layer on impl thread in active tree. |
104 client_impl_.UnregisterElement(element_id_, ElementListType::ACTIVE); | 94 client_impl_.UnregisterElement(element_id_, ElementListType::ACTIVE); |
105 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 95 EXPECT_EQ(element_animations_impl_, player_impl_->element_animations()); |
106 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); | 96 EXPECT_FALSE(element_animations_impl_->has_element_in_active_list()); |
107 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); | 97 EXPECT_FALSE(element_animations_impl_->has_element_in_pending_list()); |
108 | 98 |
109 // Sync doesn't change anything. | 99 // Sync doesn't change anything. |
110 PushProperties(); | 100 PushProperties(); |
111 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 101 EXPECT_EQ(element_animations_impl_, player_impl_->element_animations()); |
112 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); | 102 EXPECT_FALSE(element_animations_impl_->has_element_in_active_list()); |
113 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); | 103 EXPECT_FALSE(element_animations_impl_->has_element_in_pending_list()); |
114 | 104 |
115 player_->DetachElement(); | 105 player_->DetachElement(); |
116 EXPECT_FALSE(player_->element_animations()); | 106 EXPECT_FALSE(player_->element_animations()); |
117 | 107 |
118 // Release ptrs now to test the order of destruction. | 108 // Release ptrs now to test the order of destruction. |
119 ReleaseRefPtrs(); | 109 ReleaseRefPtrs(); |
120 } | 110 } |
121 | 111 |
122 TEST_F(ElementAnimationsTest, AttachToNotYetCreatedLayer) { | 112 TEST_F(ElementAnimationsTest, AttachToNotYetCreatedLayer) { |
123 host_->AddAnimationTimeline(timeline_); | 113 host_->AddAnimationTimeline(timeline_); |
124 timeline_->AttachPlayer(player_); | 114 timeline_->AttachPlayer(player_); |
125 | 115 |
126 PushProperties(); | 116 PushProperties(); |
127 GetImplTimelineAndPlayerByID(); | 117 GetImplTimelineAndPlayerByID(); |
128 | 118 |
| 119 // Perform attachment separately. |
129 player_->AttachElement(element_id_); | 120 player_->AttachElement(element_id_); |
| 121 element_animations_ = player_->element_animations(); |
130 | 122 |
131 scoped_refptr<ElementAnimations> element_animations = | 123 EXPECT_FALSE(element_animations_->has_element_in_active_list()); |
132 player_->element_animations(); | 124 EXPECT_FALSE(element_animations_->has_element_in_pending_list()); |
133 EXPECT_TRUE(element_animations); | |
134 | |
135 EXPECT_FALSE(element_animations->has_element_in_active_list()); | |
136 EXPECT_FALSE(element_animations->has_element_in_pending_list()); | |
137 | 125 |
138 PushProperties(); | 126 PushProperties(); |
| 127 element_animations_impl_ = player_impl_->element_animations(); |
139 | 128 |
140 scoped_refptr<ElementAnimations> element_animations_impl = | 129 EXPECT_FALSE(element_animations_impl_->has_element_in_active_list()); |
141 player_impl_->element_animations(); | 130 EXPECT_FALSE(element_animations_impl_->has_element_in_pending_list()); |
142 EXPECT_TRUE(element_animations_impl); | |
143 | |
144 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); | |
145 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); | |
146 | 131 |
147 // Create layer. | 132 // Create layer. |
148 client_.RegisterElement(element_id_, ElementListType::ACTIVE); | 133 client_.RegisterElement(element_id_, ElementListType::ACTIVE); |
149 EXPECT_TRUE(element_animations->has_element_in_active_list()); | 134 EXPECT_TRUE(element_animations_->has_element_in_active_list()); |
150 EXPECT_FALSE(element_animations->has_element_in_pending_list()); | 135 EXPECT_FALSE(element_animations_->has_element_in_pending_list()); |
151 | 136 |
152 client_impl_.RegisterElement(element_id_, ElementListType::PENDING); | 137 client_impl_.RegisterElement(element_id_, ElementListType::PENDING); |
153 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); | 138 EXPECT_FALSE(element_animations_impl_->has_element_in_active_list()); |
154 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); | 139 EXPECT_TRUE(element_animations_impl_->has_element_in_pending_list()); |
155 | 140 |
156 client_impl_.RegisterElement(element_id_, ElementListType::ACTIVE); | 141 client_impl_.RegisterElement(element_id_, ElementListType::ACTIVE); |
157 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); | 142 EXPECT_TRUE(element_animations_impl_->has_element_in_active_list()); |
158 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); | 143 EXPECT_TRUE(element_animations_impl_->has_element_in_pending_list()); |
159 } | 144 } |
160 | 145 |
161 TEST_F(ElementAnimationsTest, AddRemovePlayers) { | 146 TEST_F(ElementAnimationsTest, AddRemovePlayers) { |
162 host_->AddAnimationTimeline(timeline_); | 147 host_->AddAnimationTimeline(timeline_); |
163 timeline_->AttachPlayer(player_); | 148 timeline_->AttachPlayer(player_); |
164 player_->AttachElement(element_id_); | 149 player_->AttachElement(element_id_); |
165 | 150 |
166 scoped_refptr<ElementAnimations> element_animations = | 151 scoped_refptr<ElementAnimations> element_animations = |
167 player_->element_animations(); | 152 player_->element_animations(); |
168 EXPECT_TRUE(element_animations); | 153 EXPECT_TRUE(element_animations); |
(...skipping 15 matching lines...) Expand all Loading... |
184 | 169 |
185 PushProperties(); | 170 PushProperties(); |
186 GetImplTimelineAndPlayerByID(); | 171 GetImplTimelineAndPlayerByID(); |
187 | 172 |
188 scoped_refptr<ElementAnimations> element_animations_impl = | 173 scoped_refptr<ElementAnimations> element_animations_impl = |
189 player_impl_->element_animations(); | 174 player_impl_->element_animations(); |
190 EXPECT_TRUE(element_animations_impl); | 175 EXPECT_TRUE(element_animations_impl); |
191 | 176 |
192 int list_size_before = 0; | 177 int list_size_before = 0; |
193 ElementAnimations::PlayersList::Iterator it( | 178 ElementAnimations::PlayersList::Iterator it( |
194 &element_animations_impl->players_list()); | 179 &element_animations_impl_->players_list()); |
195 AnimationPlayer* player; | 180 AnimationPlayer* player; |
196 while ((player = it.GetNext()) != nullptr) { | 181 while ((player = it.GetNext()) != nullptr) { |
197 EXPECT_TRUE(timeline_->GetPlayerById(player->id())); | 182 EXPECT_TRUE(timeline_->GetPlayerById(player->id())); |
198 ++list_size_before; | 183 ++list_size_before; |
199 } | 184 } |
200 EXPECT_EQ(3, list_size_before); | 185 EXPECT_EQ(3, list_size_before); |
201 | 186 |
202 player2->DetachElement(); | 187 player2->DetachElement(); |
203 EXPECT_FALSE(player2->element_animations()); | 188 EXPECT_FALSE(player2->element_animations()); |
204 EXPECT_EQ(element_animations, player_->element_animations()); | 189 EXPECT_EQ(element_animations, player_->element_animations()); |
205 EXPECT_EQ(element_animations, player1->element_animations()); | 190 EXPECT_EQ(element_animations, player1->element_animations()); |
206 | 191 |
207 PushProperties(); | 192 PushProperties(); |
208 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 193 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
209 | 194 |
210 int list_size_after = 0; | 195 int list_size_after = 0; |
211 it = ElementAnimations::PlayersList::Iterator( | 196 it = ElementAnimations::PlayersList::Iterator( |
212 &element_animations_impl->players_list()); | 197 &element_animations_impl_->players_list()); |
213 while ((player = it.GetNext()) != nullptr) { | 198 while ((player = it.GetNext()) != nullptr) { |
214 EXPECT_TRUE(timeline_->GetPlayerById(player->id())); | 199 EXPECT_TRUE(timeline_->GetPlayerById(player->id())); |
215 ++list_size_after; | 200 ++list_size_after; |
216 } | 201 } |
217 EXPECT_EQ(2, list_size_after); | 202 EXPECT_EQ(2, list_size_after); |
218 } | 203 } |
219 | 204 |
220 TEST_F(ElementAnimationsTest, SyncNewAnimation) { | 205 TEST_F(ElementAnimationsTest, SyncNewAnimation) { |
221 CreateTestLayer(true, false); | 206 CreateTestLayer(true, false); |
222 AttachTimelinePlayerLayer(); | 207 AttachTimelinePlayerLayer(); |
223 CreateImplTimelineAndPlayer(); | 208 CreateImplTimelineAndPlayer(); |
224 | 209 |
225 scoped_refptr<ElementAnimations> animations = element_animations(); | 210 EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::OPACITY)); |
226 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
227 | 211 |
228 EXPECT_FALSE(animations_impl->GetAnimation(TargetProperty::OPACITY)); | 212 EXPECT_FALSE(player_->needs_to_start_animations()); |
229 | 213 EXPECT_FALSE(player_impl_->needs_to_start_animations()); |
230 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); | |
231 EXPECT_FALSE(animations_impl->needs_to_start_animations_for_testing()); | |
232 | 214 |
233 int animation_id = | 215 int animation_id = |
234 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); | 216 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); |
235 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); | 217 EXPECT_TRUE(player_->needs_to_start_animations()); |
236 | 218 |
237 PushProperties(); | 219 PushProperties(); |
238 EXPECT_TRUE(animations_impl->needs_to_start_animations_for_testing()); | 220 EXPECT_TRUE(player_impl_->needs_to_start_animations()); |
239 animations_impl->ActivateAnimations(); | 221 player_impl_->ActivateAnimations(); |
240 | 222 |
241 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 223 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
242 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 224 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
243 animations_impl->GetAnimationById(animation_id)->run_state()); | 225 player_impl_->GetAnimationById(animation_id)->run_state()); |
244 } | 226 } |
245 | 227 |
246 TEST_F(ElementAnimationsTest, | 228 TEST_F(ElementAnimationsTest, |
247 SyncScrollOffsetAnimationRespectsHasSetInitialValue) { | 229 SyncScrollOffsetAnimationRespectsHasSetInitialValue) { |
248 CreateTestLayer(true, false); | 230 CreateTestLayer(true, false); |
249 AttachTimelinePlayerLayer(); | 231 AttachTimelinePlayerLayer(); |
250 CreateImplTimelineAndPlayer(); | 232 CreateImplTimelineAndPlayer(); |
251 | 233 |
252 scoped_refptr<ElementAnimations> animations = element_animations(); | 234 EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)); |
253 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
254 | 235 |
255 EXPECT_FALSE(animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); | 236 EXPECT_FALSE(player_->needs_to_start_animations()); |
256 | 237 EXPECT_FALSE(player_impl_->needs_to_start_animations()); |
257 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); | |
258 EXPECT_FALSE(animations_impl->needs_to_start_animations_for_testing()); | |
259 | 238 |
260 gfx::ScrollOffset initial_value(100.f, 300.f); | 239 gfx::ScrollOffset initial_value(100.f, 300.f); |
261 gfx::ScrollOffset provider_initial_value(150.f, 300.f); | 240 gfx::ScrollOffset provider_initial_value(150.f, 300.f); |
262 gfx::ScrollOffset target_value(300.f, 200.f); | 241 gfx::ScrollOffset target_value(300.f, 200.f); |
263 | 242 |
264 client_impl_.SetScrollOffsetForAnimation(provider_initial_value); | 243 client_impl_.SetScrollOffsetForAnimation(provider_initial_value); |
265 | 244 |
266 // Animation with initial value set. | 245 // Animation with initial value set. |
267 std::unique_ptr<ScrollOffsetAnimationCurve> curve_fixed( | 246 std::unique_ptr<ScrollOffsetAnimationCurve> curve_fixed( |
268 ScrollOffsetAnimationCurve::Create( | 247 ScrollOffsetAnimationCurve::Create( |
269 target_value, CubicBezierTimingFunction::CreatePreset( | 248 target_value, CubicBezierTimingFunction::CreatePreset( |
270 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); | 249 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); |
271 curve_fixed->SetInitialValue(initial_value); | 250 curve_fixed->SetInitialValue(initial_value); |
272 const int animation1_id = 1; | 251 const int animation1_id = 1; |
273 std::unique_ptr<Animation> animation_fixed(Animation::Create( | 252 std::unique_ptr<Animation> animation_fixed(Animation::Create( |
274 std::move(curve_fixed), animation1_id, 0, TargetProperty::SCROLL_OFFSET)); | 253 std::move(curve_fixed), animation1_id, 0, TargetProperty::SCROLL_OFFSET)); |
275 animations->AddAnimation(std::move(animation_fixed)); | 254 player_->AddAnimation(std::move(animation_fixed)); |
276 PushProperties(); | 255 PushProperties(); |
277 EXPECT_VECTOR2DF_EQ(initial_value, | 256 EXPECT_VECTOR2DF_EQ(initial_value, |
278 animations_impl->GetAnimationById(animation1_id) | 257 player_impl_->GetAnimationById(animation1_id) |
279 ->curve() | 258 ->curve() |
280 ->ToScrollOffsetAnimationCurve() | 259 ->ToScrollOffsetAnimationCurve() |
281 ->GetValue(base::TimeDelta())); | 260 ->GetValue(base::TimeDelta())); |
282 | 261 |
283 // Animation without initial value set. | 262 // Animation without initial value set. |
284 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 263 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
285 ScrollOffsetAnimationCurve::Create( | 264 ScrollOffsetAnimationCurve::Create( |
286 target_value, CubicBezierTimingFunction::CreatePreset( | 265 target_value, CubicBezierTimingFunction::CreatePreset( |
287 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); | 266 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); |
288 const int animation2_id = 2; | 267 const int animation2_id = 2; |
289 std::unique_ptr<Animation> animation(Animation::Create( | 268 std::unique_ptr<Animation> animation(Animation::Create( |
290 std::move(curve), animation2_id, 0, TargetProperty::SCROLL_OFFSET)); | 269 std::move(curve), animation2_id, 0, TargetProperty::SCROLL_OFFSET)); |
291 animations->AddAnimation(std::move(animation)); | 270 player_->AddAnimation(std::move(animation)); |
292 PushProperties(); | 271 PushProperties(); |
293 EXPECT_VECTOR2DF_EQ(provider_initial_value, | 272 EXPECT_VECTOR2DF_EQ(provider_initial_value, |
294 animations_impl->GetAnimationById(animation2_id) | 273 player_impl_->GetAnimationById(animation2_id) |
295 ->curve() | 274 ->curve() |
296 ->ToScrollOffsetAnimationCurve() | 275 ->ToScrollOffsetAnimationCurve() |
297 ->GetValue(base::TimeDelta())); | 276 ->GetValue(base::TimeDelta())); |
298 } | 277 } |
299 | 278 |
300 class TestAnimationDelegateThatDestroysPlayer : public TestAnimationDelegate { | 279 class TestAnimationDelegateThatDestroysPlayer : public TestAnimationDelegate { |
301 public: | 280 public: |
302 TestAnimationDelegateThatDestroysPlayer() {} | 281 TestAnimationDelegateThatDestroysPlayer() {} |
303 | 282 |
304 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 283 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
(...skipping 18 matching lines...) Expand all Loading... |
323 }; | 302 }; |
324 | 303 |
325 // Test that we don't crash if a player is deleted while ElementAnimations is | 304 // Test that we don't crash if a player is deleted while ElementAnimations is |
326 // iterating through the list of players (see crbug.com/631052). This test | 305 // iterating through the list of players (see crbug.com/631052). This test |
327 // passes if it doesn't crash. | 306 // passes if it doesn't crash. |
328 TEST_F(ElementAnimationsTest, AddedPlayerIsDestroyed) { | 307 TEST_F(ElementAnimationsTest, AddedPlayerIsDestroyed) { |
329 CreateTestLayer(true, false); | 308 CreateTestLayer(true, false); |
330 AttachTimelinePlayerLayer(); | 309 AttachTimelinePlayerLayer(); |
331 CreateImplTimelineAndPlayer(); | 310 CreateImplTimelineAndPlayer(); |
332 | 311 |
333 scoped_refptr<ElementAnimations> animations = element_animations(); | |
334 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
335 | |
336 TestAnimationDelegateThatDestroysPlayer delegate; | 312 TestAnimationDelegateThatDestroysPlayer delegate; |
337 | 313 |
338 scoped_refptr<AnimationPlayer> player2 = | 314 const int player2_id = AnimationIdProvider::NextPlayerId(); |
339 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); | 315 scoped_refptr<AnimationPlayer> player2 = AnimationPlayer::Create(player2_id); |
340 delegate.setTimelineAndPlayer(timeline_, player2); | 316 delegate.setTimelineAndPlayer(timeline_, player2); |
341 | 317 |
342 timeline_->AttachPlayer(player2); | 318 timeline_->AttachPlayer(player2); |
343 player2->AttachElement(element_id_); | 319 player2->AttachElement(element_id_); |
344 player2->set_animation_delegate(&delegate); | 320 player2->set_animation_delegate(&delegate); |
345 | 321 |
346 int animation_id = | 322 int animation_id = |
347 AddOpacityTransitionToPlayer(player2.get(), 1.0, 0.f, 1.f, false); | 323 AddOpacityTransitionToPlayer(player2.get(), 1.0, 0.f, 1.f, false); |
348 | 324 |
349 PushProperties(); | 325 PushProperties(); |
350 | 326 |
351 animations_impl->ActivateAnimations(); | 327 scoped_refptr<AnimationPlayer> player2_impl = |
352 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 328 timeline_impl_->GetPlayerById(player2_id); |
| 329 DCHECK(player2_impl); |
353 | 330 |
354 animations_impl->Animate(kInitialTickTime); | 331 player2_impl->ActivateAnimations(); |
| 332 EXPECT_TRUE(player2_impl->GetAnimationById(animation_id)); |
| 333 |
| 334 scoped_refptr<ElementAnimations> element_animations_impl = |
| 335 player2_impl->element_animations(); |
| 336 |
| 337 element_animations_impl_->Animate(kInitialTickTime); |
355 | 338 |
356 auto events = host_impl_->CreateEvents(); | 339 auto events = host_impl_->CreateEvents(); |
357 animations_impl->UpdateState(true, events.get()); | 340 element_animations_impl_->UpdateState(true, events.get()); |
358 EXPECT_EQ(1u, events->events_.size()); | 341 EXPECT_EQ(1u, events->events_.size()); |
359 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); | 342 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); |
360 | 343 |
361 // The actual detachment happens here, inside the callback | 344 // The actual detachment happens here, inside the callback |
362 animations->NotifyAnimationStarted(events->events_[0]); | 345 player2->NotifyAnimationStarted(events->events_[0]); |
363 EXPECT_TRUE(delegate.started()); | 346 EXPECT_TRUE(delegate.started()); |
364 } | 347 } |
365 | 348 |
366 // If an animation is started on the impl thread before it is ticked on the main | 349 // If an animation is started on the impl thread before it is ticked on the main |
367 // thread, we must be sure to respect the synchronized start time. | 350 // thread, we must be sure to respect the synchronized start time. |
368 TEST_F(ElementAnimationsTest, DoNotClobberStartTimes) { | 351 TEST_F(ElementAnimationsTest, DoNotClobberStartTimes) { |
369 CreateTestLayer(true, false); | 352 CreateTestLayer(true, false); |
370 AttachTimelinePlayerLayer(); | 353 AttachTimelinePlayerLayer(); |
371 CreateImplTimelineAndPlayer(); | 354 CreateImplTimelineAndPlayer(); |
372 | 355 |
373 scoped_refptr<ElementAnimations> animations = element_animations(); | 356 EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::OPACITY)); |
374 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
375 | |
376 EXPECT_FALSE(animations_impl->GetAnimation(TargetProperty::OPACITY)); | |
377 | 357 |
378 int animation_id = | 358 int animation_id = |
379 AddOpacityTransitionToElementAnimations(animations.get(), 1, 0, 1, false); | 359 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); |
380 | 360 |
381 PushProperties(); | 361 PushProperties(); |
382 animations_impl->ActivateAnimations(); | 362 player_impl_->ActivateAnimations(); |
383 | 363 |
384 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 364 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
385 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 365 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
386 animations_impl->GetAnimationById(animation_id)->run_state()); | 366 player_impl_->GetAnimationById(animation_id)->run_state()); |
387 | 367 |
388 auto events = host_impl_->CreateEvents(); | 368 auto events = host_impl_->CreateEvents(); |
389 animations_impl->Animate(kInitialTickTime); | 369 element_animations_impl_->Animate(kInitialTickTime); |
390 animations_impl->UpdateState(true, events.get()); | 370 element_animations_impl_->UpdateState(true, events.get()); |
391 | 371 |
392 // Synchronize the start times. | 372 // Synchronize the start times. |
393 EXPECT_EQ(1u, events->events_.size()); | 373 EXPECT_EQ(1u, events->events_.size()); |
394 animations->NotifyAnimationStarted(events->events_[0]); | 374 player_->NotifyAnimationStarted(events->events_[0]); |
395 EXPECT_EQ(animations->GetAnimationById(animation_id)->start_time(), | 375 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(), |
396 animations_impl->GetAnimationById(animation_id)->start_time()); | 376 player_impl_->GetAnimationById(animation_id)->start_time()); |
397 | 377 |
398 // Start the animation on the main thread. Should not affect the start time. | 378 // Start the animation on the main thread. Should not affect the start time. |
399 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 379 element_animations_->Animate(kInitialTickTime + |
400 animations->UpdateState(true, nullptr); | 380 TimeDelta::FromMilliseconds(500)); |
401 EXPECT_EQ(animations->GetAnimationById(animation_id)->start_time(), | 381 element_animations_->UpdateState(true, nullptr); |
402 animations_impl->GetAnimationById(animation_id)->start_time()); | 382 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(), |
| 383 player_impl_->GetAnimationById(animation_id)->start_time()); |
403 } | 384 } |
404 | 385 |
405 TEST_F(ElementAnimationsTest, UseSpecifiedStartTimes) { | 386 TEST_F(ElementAnimationsTest, UseSpecifiedStartTimes) { |
406 CreateTestLayer(true, false); | 387 CreateTestLayer(true, false); |
407 AttachTimelinePlayerLayer(); | 388 AttachTimelinePlayerLayer(); |
408 CreateImplTimelineAndPlayer(); | 389 CreateImplTimelineAndPlayer(); |
409 | 390 |
410 scoped_refptr<ElementAnimations> animations = element_animations(); | |
411 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
412 | |
413 int animation_id = | 391 int animation_id = |
414 AddOpacityTransitionToElementAnimations(animations.get(), 1, 0, 1, false); | 392 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); |
415 | 393 |
416 const TimeTicks start_time = TicksFromSecondsF(123); | 394 const TimeTicks start_time = TicksFromSecondsF(123); |
417 animations->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); | 395 player_->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); |
418 | 396 |
419 PushProperties(); | 397 PushProperties(); |
420 animations_impl->ActivateAnimations(); | 398 player_impl_->ActivateAnimations(); |
421 | 399 |
422 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 400 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
423 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 401 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
424 animations_impl->GetAnimationById(animation_id)->run_state()); | 402 player_impl_->GetAnimationById(animation_id)->run_state()); |
425 | 403 |
426 auto events = host_impl_->CreateEvents(); | 404 auto events = host_impl_->CreateEvents(); |
427 animations_impl->Animate(kInitialTickTime); | 405 element_animations_impl_->Animate(kInitialTickTime); |
428 animations_impl->UpdateState(true, events.get()); | 406 element_animations_impl_->UpdateState(true, events.get()); |
429 | 407 |
430 // Synchronize the start times. | 408 // Synchronize the start times. |
431 EXPECT_EQ(1u, events->events_.size()); | 409 EXPECT_EQ(1u, events->events_.size()); |
432 animations->NotifyAnimationStarted(events->events_[0]); | 410 player_->NotifyAnimationStarted(events->events_[0]); |
433 | 411 |
434 EXPECT_EQ(start_time, | 412 EXPECT_EQ(start_time, player_->GetAnimationById(animation_id)->start_time()); |
435 animations->GetAnimationById(animation_id)->start_time()); | 413 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(), |
436 EXPECT_EQ(animations->GetAnimationById(animation_id)->start_time(), | 414 player_impl_->GetAnimationById(animation_id)->start_time()); |
437 animations_impl->GetAnimationById(animation_id)->start_time()); | |
438 | 415 |
439 // Start the animation on the main thread. Should not affect the start time. | 416 // Start the animation on the main thread. Should not affect the start time. |
440 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 417 element_animations_->Animate(kInitialTickTime + |
441 animations->UpdateState(true, nullptr); | 418 TimeDelta::FromMilliseconds(500)); |
442 EXPECT_EQ(start_time, | 419 element_animations_->UpdateState(true, nullptr); |
443 animations->GetAnimationById(animation_id)->start_time()); | 420 EXPECT_EQ(start_time, player_->GetAnimationById(animation_id)->start_time()); |
444 EXPECT_EQ(animations->GetAnimationById(animation_id)->start_time(), | 421 EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(), |
445 animations_impl->GetAnimationById(animation_id)->start_time()); | 422 player_impl_->GetAnimationById(animation_id)->start_time()); |
446 } | 423 } |
447 | 424 |
448 // Tests that animationss activate and deactivate as expected. | 425 // Tests that animationss activate and deactivate as expected. |
449 TEST_F(ElementAnimationsTest, Activation) { | 426 TEST_F(ElementAnimationsTest, Activation) { |
450 CreateTestLayer(true, false); | 427 CreateTestLayer(true, false); |
451 AttachTimelinePlayerLayer(); | 428 AttachTimelinePlayerLayer(); |
452 CreateImplTimelineAndPlayer(); | 429 CreateImplTimelineAndPlayer(); |
453 | 430 |
454 scoped_refptr<ElementAnimations> animations = element_animations(); | |
455 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
456 | |
457 AnimationHost* host = client_.host(); | 431 AnimationHost* host = client_.host(); |
458 AnimationHost* host_impl = client_impl_.host(); | 432 AnimationHost* host_impl = client_impl_.host(); |
459 | 433 |
460 auto events = host_impl_->CreateEvents(); | 434 auto events = host_impl_->CreateEvents(); |
461 | 435 |
462 EXPECT_EQ(1u, host->all_element_animations_for_testing().size()); | 436 EXPECT_EQ(1u, host->all_element_animations_for_testing().size()); |
463 EXPECT_EQ(1u, host_impl->all_element_animations_for_testing().size()); | 437 EXPECT_EQ(1u, host_impl->all_element_animations_for_testing().size()); |
464 | 438 |
465 // Initially, both animationss should be inactive. | 439 // Initially, both animationss should be inactive. |
466 EXPECT_EQ(0u, host->active_element_animations_for_testing().size()); | 440 EXPECT_EQ(0u, host->active_element_animations_for_testing().size()); |
467 EXPECT_EQ(0u, host_impl->active_element_animations_for_testing().size()); | 441 EXPECT_EQ(0u, host_impl->active_element_animations_for_testing().size()); |
468 | 442 |
469 AddOpacityTransitionToElementAnimations(animations.get(), 1, 0, 1, false); | 443 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); |
470 // The main thread animations should now be active. | 444 // The main thread animations should now be active. |
471 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); | 445 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); |
472 | 446 |
473 PushProperties(); | 447 PushProperties(); |
474 animations_impl->ActivateAnimations(); | 448 player_impl_->ActivateAnimations(); |
475 // Both animationss should now be active. | 449 // Both animationss should now be active. |
476 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); | 450 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); |
477 EXPECT_EQ(1u, host_impl->active_element_animations_for_testing().size()); | 451 EXPECT_EQ(1u, host_impl->active_element_animations_for_testing().size()); |
478 | 452 |
479 animations_impl->Animate(kInitialTickTime); | 453 element_animations_impl_->Animate(kInitialTickTime); |
480 animations_impl->UpdateState(true, events.get()); | 454 element_animations_impl_->UpdateState(true, events.get()); |
481 EXPECT_EQ(1u, events->events_.size()); | 455 EXPECT_EQ(1u, events->events_.size()); |
482 animations->NotifyAnimationStarted(events->events_[0]); | 456 player_->NotifyAnimationStarted(events->events_[0]); |
483 | 457 |
484 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); | 458 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); |
485 EXPECT_EQ(1u, host_impl->active_element_animations_for_testing().size()); | 459 EXPECT_EQ(1u, host_impl->active_element_animations_for_testing().size()); |
486 | 460 |
487 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 461 element_animations_->Animate(kInitialTickTime + |
488 animations->UpdateState(true, nullptr); | 462 TimeDelta::FromMilliseconds(500)); |
| 463 element_animations_->UpdateState(true, nullptr); |
489 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); | 464 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); |
490 | 465 |
491 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 466 element_animations_->Animate(kInitialTickTime + |
492 animations->UpdateState(true, nullptr); | 467 TimeDelta::FromMilliseconds(1000)); |
| 468 element_animations_->UpdateState(true, nullptr); |
493 EXPECT_EQ(Animation::FINISHED, | 469 EXPECT_EQ(Animation::FINISHED, |
494 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 470 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
495 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); | 471 EXPECT_EQ(1u, host->active_element_animations_for_testing().size()); |
496 | 472 |
497 events = host_impl_->CreateEvents(); | 473 events = host_impl_->CreateEvents(); |
498 | 474 |
499 animations_impl->Animate(kInitialTickTime + | 475 element_animations_impl_->Animate(kInitialTickTime + |
500 TimeDelta::FromMilliseconds(1500)); | 476 TimeDelta::FromMilliseconds(1500)); |
501 animations_impl->UpdateState(true, events.get()); | 477 element_animations_impl_->UpdateState(true, events.get()); |
502 | 478 |
503 EXPECT_EQ( | 479 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
504 Animation::WAITING_FOR_DELETION, | 480 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
505 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
506 // The impl thread animations should have de-activated. | 481 // The impl thread animations should have de-activated. |
507 EXPECT_EQ(0u, host_impl->active_element_animations_for_testing().size()); | 482 EXPECT_EQ(0u, host_impl->active_element_animations_for_testing().size()); |
508 | 483 |
509 EXPECT_EQ(1u, events->events_.size()); | 484 EXPECT_EQ(1u, events->events_.size()); |
510 animations->NotifyAnimationFinished(events->events_[0]); | 485 player_->NotifyAnimationFinished(events->events_[0]); |
511 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | 486 element_animations_->Animate(kInitialTickTime + |
512 animations->UpdateState(true, nullptr); | 487 TimeDelta::FromMilliseconds(1500)); |
| 488 element_animations_->UpdateState(true, nullptr); |
513 | 489 |
514 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | 490 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
515 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 491 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
516 // The main thread animations should have de-activated. | 492 // The main thread animations should have de-activated. |
517 EXPECT_EQ(0u, host->active_element_animations_for_testing().size()); | 493 EXPECT_EQ(0u, host->active_element_animations_for_testing().size()); |
518 | 494 |
519 PushProperties(); | 495 PushProperties(); |
520 animations_impl->ActivateAnimations(); | 496 player_impl_->ActivateAnimations(); |
521 EXPECT_FALSE(animations->HasAnyAnimation()); | 497 EXPECT_FALSE(player_->has_any_animation()); |
522 EXPECT_FALSE(animations_impl->HasAnyAnimation()); | 498 EXPECT_FALSE(player_impl_->has_any_animation()); |
523 EXPECT_EQ(0u, host->active_element_animations_for_testing().size()); | 499 EXPECT_EQ(0u, host->active_element_animations_for_testing().size()); |
524 EXPECT_EQ(0u, host_impl->active_element_animations_for_testing().size()); | 500 EXPECT_EQ(0u, host_impl->active_element_animations_for_testing().size()); |
525 } | 501 } |
526 | 502 |
527 TEST_F(ElementAnimationsTest, SyncPause) { | 503 TEST_F(ElementAnimationsTest, SyncPause) { |
528 CreateTestLayer(true, false); | 504 CreateTestLayer(true, false); |
529 AttachTimelinePlayerLayer(); | 505 AttachTimelinePlayerLayer(); |
530 CreateImplTimelineAndPlayer(); | 506 CreateImplTimelineAndPlayer(); |
531 | 507 |
532 scoped_refptr<ElementAnimations> animations = element_animations(); | 508 EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::OPACITY)); |
533 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
534 | |
535 EXPECT_FALSE(animations_impl->GetAnimation(TargetProperty::OPACITY)); | |
536 | 509 |
537 // Two steps, three ranges: [0-1) -> 0.2, [1-2) -> 0.3, [2-3] -> 0.4. | 510 // Two steps, three ranges: [0-1) -> 0.2, [1-2) -> 0.3, [2-3] -> 0.4. |
538 const double duration = 3.0; | 511 const double duration = 3.0; |
539 const int animation_id = AddOpacityStepsToElementAnimations( | 512 const int animation_id = |
540 animations.get(), duration, 0.2f, 0.4f, 2); | 513 AddOpacityStepsToPlayer(player_.get(), duration, 0.2f, 0.4f, 2); |
541 | 514 |
542 // Set start offset to be at the beginning of the second range. | 515 // Set start offset to be at the beginning of the second range. |
543 animations->GetAnimationById(animation_id) | 516 player_->GetAnimationById(animation_id) |
544 ->set_time_offset(TimeDelta::FromSecondsD(1.01)); | 517 ->set_time_offset(TimeDelta::FromSecondsD(1.01)); |
545 | 518 |
546 PushProperties(); | 519 PushProperties(); |
547 animations_impl->ActivateAnimations(); | 520 player_impl_->ActivateAnimations(); |
548 | 521 |
549 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 522 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
550 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 523 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
551 animations_impl->GetAnimationById(animation_id)->run_state()); | 524 player_impl_->GetAnimationById(animation_id)->run_state()); |
552 | 525 |
553 TimeTicks time = kInitialTickTime; | 526 TimeTicks time = kInitialTickTime; |
554 | 527 |
555 // Start the animations on each animations. | 528 // Start the animations on each animations. |
556 auto events = host_impl_->CreateEvents(); | 529 auto events = host_impl_->CreateEvents(); |
557 animations_impl->Animate(time); | 530 element_animations_impl_->Animate(time); |
558 animations_impl->UpdateState(true, events.get()); | 531 element_animations_impl_->UpdateState(true, events.get()); |
559 EXPECT_EQ(1u, events->events_.size()); | 532 EXPECT_EQ(1u, events->events_.size()); |
560 | 533 |
561 animations->Animate(time); | 534 element_animations_->Animate(time); |
562 animations->UpdateState(true, nullptr); | 535 element_animations_->UpdateState(true, nullptr); |
563 animations->NotifyAnimationStarted(events->events_[0]); | 536 player_->NotifyAnimationStarted(events->events_[0]); |
564 | 537 |
565 EXPECT_EQ(Animation::RUNNING, | 538 EXPECT_EQ(Animation::RUNNING, |
566 animations_impl->GetAnimationById(animation_id)->run_state()); | 539 player_impl_->GetAnimationById(animation_id)->run_state()); |
567 EXPECT_EQ(Animation::RUNNING, | 540 EXPECT_EQ(Animation::RUNNING, |
568 animations->GetAnimationById(animation_id)->run_state()); | 541 player_->GetAnimationById(animation_id)->run_state()); |
569 | 542 |
570 EXPECT_EQ(0.3f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 543 EXPECT_EQ(0.3f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
571 EXPECT_EQ(0.3f, | 544 EXPECT_EQ(0.3f, |
572 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 545 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
573 | 546 |
574 EXPECT_EQ(kInitialTickTime, | 547 EXPECT_EQ(kInitialTickTime, |
575 animations->GetAnimationById(animation_id)->start_time()); | 548 player_->GetAnimationById(animation_id)->start_time()); |
576 EXPECT_EQ(kInitialTickTime, | 549 EXPECT_EQ(kInitialTickTime, |
577 animations_impl->GetAnimationById(animation_id)->start_time()); | 550 player_impl_->GetAnimationById(animation_id)->start_time()); |
578 | 551 |
579 // Pause the animation at the middle of the second range so the offset | 552 // Pause the animation at the middle of the second range so the offset |
580 // delays animation until the middle of the third range. | 553 // delays animation until the middle of the third range. |
581 animations->PauseAnimation(animation_id, TimeDelta::FromSecondsD(1.5)); | 554 player_->PauseAnimation(animation_id, 1.5); |
582 EXPECT_EQ(Animation::PAUSED, | 555 EXPECT_EQ(Animation::PAUSED, |
583 animations->GetAnimationById(animation_id)->run_state()); | 556 player_->GetAnimationById(animation_id)->run_state()); |
584 | 557 |
585 // The pause run state change should make it to the impl thread animations. | 558 // The pause run state change should make it to the impl thread animations. |
586 PushProperties(); | 559 PushProperties(); |
587 animations_impl->ActivateAnimations(); | 560 player_impl_->ActivateAnimations(); |
588 | 561 |
589 // Advance time so it stays within the first range. | 562 // Advance time so it stays within the first range. |
590 time += TimeDelta::FromMilliseconds(10); | 563 time += TimeDelta::FromMilliseconds(10); |
591 animations->Animate(time); | 564 element_animations_->Animate(time); |
592 animations_impl->Animate(time); | 565 element_animations_impl_->Animate(time); |
593 | 566 |
594 EXPECT_EQ(Animation::PAUSED, | 567 EXPECT_EQ(Animation::PAUSED, |
595 animations_impl->GetAnimationById(animation_id)->run_state()); | 568 player_impl_->GetAnimationById(animation_id)->run_state()); |
596 | 569 |
597 // Opacity value doesn't depend on time if paused at specified time offset. | 570 // Opacity value doesn't depend on time if paused at specified time offset. |
598 EXPECT_EQ(0.4f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 571 EXPECT_EQ(0.4f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
599 EXPECT_EQ(0.4f, | 572 EXPECT_EQ(0.4f, |
600 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 573 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
601 } | 574 } |
602 | 575 |
603 TEST_F(ElementAnimationsTest, DoNotSyncFinishedAnimation) { | 576 TEST_F(ElementAnimationsTest, DoNotSyncFinishedAnimation) { |
604 CreateTestLayer(true, false); | 577 CreateTestLayer(true, false); |
605 AttachTimelinePlayerLayer(); | 578 AttachTimelinePlayerLayer(); |
606 CreateImplTimelineAndPlayer(); | 579 CreateImplTimelineAndPlayer(); |
607 | 580 |
608 scoped_refptr<ElementAnimations> animations = element_animations(); | |
609 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
610 | |
611 auto events = host_impl_->CreateEvents(); | 581 auto events = host_impl_->CreateEvents(); |
612 | 582 |
613 EXPECT_FALSE(animations_impl->GetAnimation(TargetProperty::OPACITY)); | 583 EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::OPACITY)); |
614 | 584 |
615 int animation_id = | 585 int animation_id = |
616 AddOpacityTransitionToElementAnimations(animations.get(), 1, 0, 1, false); | 586 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); |
617 | 587 |
618 PushProperties(); | 588 PushProperties(); |
619 animations_impl->ActivateAnimations(); | 589 player_impl_->ActivateAnimations(); |
620 | 590 |
621 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 591 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
622 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 592 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
623 animations_impl->GetAnimationById(animation_id)->run_state()); | 593 player_impl_->GetAnimationById(animation_id)->run_state()); |
624 | 594 |
625 events = host_impl_->CreateEvents(); | 595 events = host_impl_->CreateEvents(); |
626 animations_impl->Animate(kInitialTickTime); | 596 element_animations_impl_->Animate(kInitialTickTime); |
627 animations_impl->UpdateState(true, events.get()); | 597 element_animations_impl_->UpdateState(true, events.get()); |
628 EXPECT_EQ(1u, events->events_.size()); | 598 EXPECT_EQ(1u, events->events_.size()); |
629 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); | 599 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); |
630 | 600 |
631 // Notify main thread animations that the animation has started. | 601 // Notify main thread animations that the animation has started. |
632 animations->NotifyAnimationStarted(events->events_[0]); | 602 player_->NotifyAnimationStarted(events->events_[0]); |
633 | 603 |
634 // Complete animation on impl thread. | 604 // Complete animation on impl thread. |
635 events = host_impl_->CreateEvents(); | 605 events = host_impl_->CreateEvents(); |
636 animations_impl->Animate(kInitialTickTime + TimeDelta::FromSeconds(1)); | 606 element_animations_impl_->Animate(kInitialTickTime + |
637 animations_impl->UpdateState(true, events.get()); | 607 TimeDelta::FromSeconds(1)); |
| 608 element_animations_impl_->UpdateState(true, events.get()); |
638 EXPECT_EQ(1u, events->events_.size()); | 609 EXPECT_EQ(1u, events->events_.size()); |
639 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); | 610 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); |
640 | 611 |
641 animations->NotifyAnimationFinished(events->events_[0]); | 612 player_->NotifyAnimationFinished(events->events_[0]); |
642 | 613 |
643 animations->Animate(kInitialTickTime + TimeDelta::FromSeconds(2)); | 614 element_animations_->Animate(kInitialTickTime + TimeDelta::FromSeconds(2)); |
644 animations->UpdateState(true, nullptr); | 615 element_animations_->UpdateState(true, nullptr); |
645 | 616 |
646 PushProperties(); | 617 PushProperties(); |
647 animations_impl->ActivateAnimations(); | 618 player_impl_->ActivateAnimations(); |
648 EXPECT_FALSE(animations->GetAnimationById(animation_id)); | 619 EXPECT_FALSE(player_->GetAnimationById(animation_id)); |
649 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id)); | 620 EXPECT_FALSE(player_impl_->GetAnimationById(animation_id)); |
650 } | 621 } |
651 | 622 |
652 // Ensure that a finished animation is eventually deleted by both the | 623 // Ensure that a finished animation is eventually deleted by both the |
653 // main-thread and the impl-thread animationss. | 624 // main-thread and the impl-thread animationss. |
654 TEST_F(ElementAnimationsTest, AnimationsAreDeleted) { | 625 TEST_F(ElementAnimationsTest, AnimationsAreDeleted) { |
655 CreateTestLayer(true, false); | 626 CreateTestLayer(true, false); |
656 AttachTimelinePlayerLayer(); | 627 AttachTimelinePlayerLayer(); |
657 CreateImplTimelineAndPlayer(); | 628 CreateImplTimelineAndPlayer(); |
658 | 629 |
659 scoped_refptr<ElementAnimations> animations = element_animations(); | |
660 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
661 | |
662 auto events = host_impl_->CreateEvents(); | 630 auto events = host_impl_->CreateEvents(); |
663 | 631 |
664 AddOpacityTransitionToElementAnimations(animations.get(), 1.0, 0.0f, 1.0f, | 632 AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.0f, 1.0f, false); |
665 false); | 633 element_animations_->Animate(kInitialTickTime); |
666 animations->Animate(kInitialTickTime); | 634 element_animations_->UpdateState(true, nullptr); |
667 animations->UpdateState(true, nullptr); | 635 EXPECT_TRUE(player_->needs_push_properties()); |
668 EXPECT_TRUE(animations->needs_push_properties()); | |
669 | 636 |
670 PushProperties(); | 637 PushProperties(); |
671 EXPECT_FALSE(animations->needs_push_properties()); | 638 EXPECT_FALSE(player_->needs_push_properties()); |
672 | 639 |
673 EXPECT_FALSE(host_->needs_push_properties()); | 640 EXPECT_FALSE(host_->needs_push_properties()); |
674 EXPECT_FALSE(host_impl_->needs_push_properties()); | 641 EXPECT_FALSE(host_impl_->needs_push_properties()); |
675 | 642 |
676 animations_impl->ActivateAnimations(); | 643 player_impl_->ActivateAnimations(); |
677 | 644 |
678 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 645 element_animations_impl_->Animate(kInitialTickTime + |
679 animations_impl->UpdateState(true, events.get()); | 646 TimeDelta::FromMilliseconds(500)); |
| 647 element_animations_impl_->UpdateState(true, events.get()); |
680 | 648 |
681 // There should be a STARTED event for the animation. | 649 // There should be a STARTED event for the animation. |
682 EXPECT_EQ(1u, events->events_.size()); | 650 EXPECT_EQ(1u, events->events_.size()); |
683 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); | 651 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); |
684 animations->NotifyAnimationStarted(events->events_[0]); | 652 player_->NotifyAnimationStarted(events->events_[0]); |
685 | 653 |
686 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 654 element_animations_->Animate(kInitialTickTime + |
687 animations->UpdateState(true, nullptr); | 655 TimeDelta::FromMilliseconds(1000)); |
| 656 element_animations_->UpdateState(true, nullptr); |
688 | 657 |
689 EXPECT_FALSE(host_->needs_push_properties()); | 658 EXPECT_FALSE(host_->needs_push_properties()); |
690 EXPECT_FALSE(host_impl_->needs_push_properties()); | 659 EXPECT_FALSE(host_impl_->needs_push_properties()); |
691 | 660 |
692 events = host_impl_->CreateEvents(); | 661 events = host_impl_->CreateEvents(); |
693 animations_impl->Animate(kInitialTickTime + | 662 element_animations_impl_->Animate(kInitialTickTime + |
694 TimeDelta::FromMilliseconds(2000)); | 663 TimeDelta::FromMilliseconds(2000)); |
695 animations_impl->UpdateState(true, events.get()); | 664 element_animations_impl_->UpdateState(true, events.get()); |
696 | 665 |
697 EXPECT_TRUE(host_impl_->needs_push_properties()); | 666 EXPECT_TRUE(host_impl_->needs_push_properties()); |
698 | 667 |
699 // There should be a FINISHED event for the animation. | 668 // There should be a FINISHED event for the animation. |
700 EXPECT_EQ(1u, events->events_.size()); | 669 EXPECT_EQ(1u, events->events_.size()); |
701 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); | 670 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); |
702 | 671 |
703 // Neither animations should have deleted the animation yet. | 672 // Neither animations should have deleted the animation yet. |
704 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); | 673 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY)); |
705 EXPECT_TRUE(animations_impl->GetAnimation(TargetProperty::OPACITY)); | 674 EXPECT_TRUE(player_impl_->GetAnimation(TargetProperty::OPACITY)); |
706 | 675 |
707 animations->NotifyAnimationFinished(events->events_[0]); | 676 player_->NotifyAnimationFinished(events->events_[0]); |
708 | 677 |
709 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 678 element_animations_->Animate(kInitialTickTime + |
710 animations->UpdateState(true, nullptr); | 679 TimeDelta::FromMilliseconds(3000)); |
| 680 element_animations_->UpdateState(true, nullptr); |
711 EXPECT_TRUE(host_->needs_push_properties()); | 681 EXPECT_TRUE(host_->needs_push_properties()); |
712 | 682 |
713 PushProperties(); | 683 PushProperties(); |
714 | 684 |
715 // Both animationss should now have deleted the animation. The impl animations | 685 // Both animationss should now have deleted the animation. The impl animations |
716 // should have deleted the animation even though activation has not occurred, | 686 // should have deleted the animation even though activation has not occurred, |
717 // since the animation was already waiting for deletion when | 687 // since the animation was already waiting for deletion when |
718 // PushPropertiesTo was called. | 688 // PushPropertiesTo was called. |
719 EXPECT_FALSE(animations->HasAnyAnimation()); | 689 EXPECT_FALSE(player_->has_any_animation()); |
720 EXPECT_FALSE(animations_impl->HasAnyAnimation()); | 690 EXPECT_FALSE(player_impl_->has_any_animation()); |
721 } | 691 } |
722 | 692 |
723 // Tests that transitioning opacity from 0 to 1 works as expected. | 693 // Tests that transitioning opacity from 0 to 1 works as expected. |
724 | 694 |
725 static std::unique_ptr<Animation> CreateAnimation( | 695 static std::unique_ptr<Animation> CreateAnimation( |
726 std::unique_ptr<AnimationCurve> curve, | 696 std::unique_ptr<AnimationCurve> curve, |
727 int group_id, | 697 int group_id, |
728 TargetProperty::Type property) { | 698 TargetProperty::Type property) { |
729 return Animation::Create(std::move(curve), 0, group_id, property); | 699 return Animation::Create(std::move(curve), 0, group_id, property); |
730 } | 700 } |
731 | 701 |
732 static const AnimationEvent* GetMostRecentPropertyUpdateEvent( | 702 static const AnimationEvent* GetMostRecentPropertyUpdateEvent( |
733 const AnimationEvents* events) { | 703 const AnimationEvents* events) { |
734 const AnimationEvent* event = 0; | 704 const AnimationEvent* event = 0; |
735 for (size_t i = 0; i < events->events_.size(); ++i) | 705 for (size_t i = 0; i < events->events_.size(); ++i) |
736 if (events->events_[i].type == AnimationEvent::PROPERTY_UPDATE) | 706 if (events->events_[i].type == AnimationEvent::PROPERTY_UPDATE) |
737 event = &events->events_[i]; | 707 event = &events->events_[i]; |
738 | 708 |
739 return event; | 709 return event; |
740 } | 710 } |
741 | 711 |
742 TEST_F(ElementAnimationsTest, TrivialTransition) { | 712 TEST_F(ElementAnimationsTest, TrivialTransition) { |
743 CreateTestLayer(true, false); | 713 CreateTestLayer(true, false); |
744 AttachTimelinePlayerLayer(); | 714 AttachTimelinePlayerLayer(); |
745 | 715 |
746 scoped_refptr<ElementAnimations> animations = element_animations(); | |
747 | |
748 auto events = host_impl_->CreateEvents(); | 716 auto events = host_impl_->CreateEvents(); |
749 | 717 |
750 std::unique_ptr<Animation> to_add(CreateAnimation( | 718 std::unique_ptr<Animation> to_add(CreateAnimation( |
751 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 719 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
752 1, TargetProperty::OPACITY)); | 720 1, TargetProperty::OPACITY)); |
753 | 721 |
754 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); | 722 EXPECT_FALSE(player_->needs_to_start_animations()); |
755 animations->AddAnimation(std::move(to_add)); | 723 player_->AddAnimation(std::move(to_add)); |
756 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); | 724 EXPECT_TRUE(player_->needs_to_start_animations()); |
757 animations->Animate(kInitialTickTime); | 725 element_animations_->Animate(kInitialTickTime); |
758 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); | 726 EXPECT_FALSE(player_->needs_to_start_animations()); |
759 animations->UpdateState(true, events.get()); | 727 element_animations_->UpdateState(true, events.get()); |
760 EXPECT_TRUE(animations->HasActiveAnimation()); | 728 EXPECT_TRUE(player_->HasActiveAnimation()); |
761 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 729 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
762 // A non-impl-only animation should not generate property updates. | 730 // A non-impl-only animation should not generate property updates. |
763 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 731 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
764 EXPECT_FALSE(event); | 732 EXPECT_FALSE(event); |
765 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 733 element_animations_->Animate(kInitialTickTime + |
766 animations->UpdateState(true, events.get()); | 734 TimeDelta::FromMilliseconds(1000)); |
| 735 element_animations_->UpdateState(true, events.get()); |
767 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 736 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
768 EXPECT_FALSE(animations->HasActiveAnimation()); | 737 EXPECT_FALSE(player_->HasActiveAnimation()); |
769 event = GetMostRecentPropertyUpdateEvent(events.get()); | 738 event = GetMostRecentPropertyUpdateEvent(events.get()); |
770 EXPECT_FALSE(event); | 739 EXPECT_FALSE(event); |
771 } | 740 } |
772 | 741 |
773 TEST_F(ElementAnimationsTest, FilterTransition) { | 742 TEST_F(ElementAnimationsTest, FilterTransition) { |
774 CreateTestLayer(true, false); | 743 CreateTestLayer(true, false); |
775 AttachTimelinePlayerLayer(); | 744 AttachTimelinePlayerLayer(); |
776 | 745 |
777 scoped_refptr<ElementAnimations> animations = element_animations(); | |
778 | |
779 auto events = host_impl_->CreateEvents(); | 746 auto events = host_impl_->CreateEvents(); |
780 | 747 |
781 std::unique_ptr<KeyframedFilterAnimationCurve> curve( | 748 std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
782 KeyframedFilterAnimationCurve::Create()); | 749 KeyframedFilterAnimationCurve::Create()); |
783 | 750 |
784 FilterOperations start_filters; | 751 FilterOperations start_filters; |
785 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); | 752 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); |
786 curve->AddKeyframe( | 753 curve->AddKeyframe( |
787 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); | 754 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
788 FilterOperations end_filters; | 755 FilterOperations end_filters; |
789 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 756 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
790 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 757 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
791 end_filters, nullptr)); | 758 end_filters, nullptr)); |
792 | 759 |
793 std::unique_ptr<Animation> animation( | 760 std::unique_ptr<Animation> animation( |
794 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); | 761 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); |
795 animations->AddAnimation(std::move(animation)); | 762 player_->AddAnimation(std::move(animation)); |
796 | 763 |
797 animations->Animate(kInitialTickTime); | 764 element_animations_->Animate(kInitialTickTime); |
798 animations->UpdateState(true, events.get()); | 765 element_animations_->UpdateState(true, events.get()); |
799 EXPECT_TRUE(animations->HasActiveAnimation()); | 766 EXPECT_TRUE(player_->HasActiveAnimation()); |
800 EXPECT_EQ(start_filters, | 767 EXPECT_EQ(start_filters, |
801 client_.GetFilters(element_id_, ElementListType::ACTIVE)); | 768 client_.GetFilters(element_id_, ElementListType::ACTIVE)); |
802 // A non-impl-only animation should not generate property updates. | 769 // A non-impl-only animation should not generate property updates. |
803 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 770 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
804 EXPECT_FALSE(event); | 771 EXPECT_FALSE(event); |
805 | 772 |
806 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 773 element_animations_->Animate(kInitialTickTime + |
807 animations->UpdateState(true, events.get()); | 774 TimeDelta::FromMilliseconds(500)); |
| 775 element_animations_->UpdateState(true, events.get()); |
808 EXPECT_EQ(1u, | 776 EXPECT_EQ(1u, |
809 client_.GetFilters(element_id_, ElementListType::ACTIVE).size()); | 777 client_.GetFilters(element_id_, ElementListType::ACTIVE).size()); |
810 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), | 778 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), |
811 client_.GetFilters(element_id_, ElementListType::ACTIVE).at(0)); | 779 client_.GetFilters(element_id_, ElementListType::ACTIVE).at(0)); |
812 event = GetMostRecentPropertyUpdateEvent(events.get()); | 780 event = GetMostRecentPropertyUpdateEvent(events.get()); |
813 EXPECT_FALSE(event); | 781 EXPECT_FALSE(event); |
814 | 782 |
815 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 783 element_animations_->Animate(kInitialTickTime + |
816 animations->UpdateState(true, events.get()); | 784 TimeDelta::FromMilliseconds(1000)); |
| 785 element_animations_->UpdateState(true, events.get()); |
817 EXPECT_EQ(end_filters, | 786 EXPECT_EQ(end_filters, |
818 client_.GetFilters(element_id_, ElementListType::ACTIVE)); | 787 client_.GetFilters(element_id_, ElementListType::ACTIVE)); |
819 EXPECT_FALSE(animations->HasActiveAnimation()); | 788 EXPECT_FALSE(player_->HasActiveAnimation()); |
820 event = GetMostRecentPropertyUpdateEvent(events.get()); | 789 event = GetMostRecentPropertyUpdateEvent(events.get()); |
821 EXPECT_FALSE(event); | 790 EXPECT_FALSE(event); |
822 } | 791 } |
823 | 792 |
824 TEST_F(ElementAnimationsTest, ScrollOffsetTransition) { | 793 TEST_F(ElementAnimationsTest, ScrollOffsetTransition) { |
825 CreateTestLayer(true, false); | 794 CreateTestLayer(true, false); |
826 AttachTimelinePlayerLayer(); | 795 AttachTimelinePlayerLayer(); |
827 CreateImplTimelineAndPlayer(); | 796 CreateImplTimelineAndPlayer(); |
828 | 797 |
829 scoped_refptr<ElementAnimations> animations = element_animations(); | |
830 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
831 | |
832 auto events = host_impl_->CreateEvents(); | 798 auto events = host_impl_->CreateEvents(); |
833 | 799 |
834 gfx::ScrollOffset initial_value(100.f, 300.f); | 800 gfx::ScrollOffset initial_value(100.f, 300.f); |
835 gfx::ScrollOffset target_value(300.f, 200.f); | 801 gfx::ScrollOffset target_value(300.f, 200.f); |
836 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 802 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
837 ScrollOffsetAnimationCurve::Create( | 803 ScrollOffsetAnimationCurve::Create( |
838 target_value, CubicBezierTimingFunction::CreatePreset( | 804 target_value, CubicBezierTimingFunction::CreatePreset( |
839 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); | 805 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); |
840 | 806 |
841 std::unique_ptr<Animation> animation( | 807 std::unique_ptr<Animation> animation( |
842 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 808 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
843 animation->set_needs_synchronized_start_time(true); | 809 animation->set_needs_synchronized_start_time(true); |
844 animations->AddAnimation(std::move(animation)); | 810 player_->AddAnimation(std::move(animation)); |
845 | 811 |
846 client_impl_.SetScrollOffsetForAnimation(initial_value); | 812 client_impl_.SetScrollOffsetForAnimation(initial_value); |
847 PushProperties(); | 813 PushProperties(); |
848 animations_impl->ActivateAnimations(); | 814 player_impl_->ActivateAnimations(); |
849 EXPECT_TRUE(animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); | 815 EXPECT_TRUE(player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)); |
850 TimeDelta duration = | 816 TimeDelta duration = player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET) |
851 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 817 ->curve() |
852 ->curve() | 818 ->Duration(); |
853 ->Duration(); | 819 EXPECT_EQ(duration, player_->GetAnimation(TargetProperty::SCROLL_OFFSET) |
854 EXPECT_EQ(duration, animations->GetAnimation(TargetProperty::SCROLL_OFFSET) | |
855 ->curve() | 820 ->curve() |
856 ->Duration()); | 821 ->Duration()); |
857 | 822 |
858 animations->Animate(kInitialTickTime); | 823 element_animations_->Animate(kInitialTickTime); |
859 animations->UpdateState(true, nullptr); | 824 element_animations_->UpdateState(true, nullptr); |
860 EXPECT_TRUE(animations->HasActiveAnimation()); | 825 EXPECT_TRUE(player_->HasActiveAnimation()); |
861 EXPECT_EQ(initial_value, | 826 EXPECT_EQ(initial_value, |
862 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); | 827 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); |
863 | 828 |
864 animations_impl->Animate(kInitialTickTime); | 829 element_animations_impl_->Animate(kInitialTickTime); |
865 animations_impl->UpdateState(true, events.get()); | 830 element_animations_impl_->UpdateState(true, events.get()); |
866 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | 831 EXPECT_TRUE(player_impl_->HasActiveAnimation()); |
867 EXPECT_EQ(initial_value, | 832 EXPECT_EQ(initial_value, |
868 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); | 833 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); |
869 // Scroll offset animations should not generate property updates. | 834 // Scroll offset animations should not generate property updates. |
870 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 835 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
871 EXPECT_FALSE(event); | 836 EXPECT_FALSE(event); |
872 | 837 |
873 animations->NotifyAnimationStarted(events->events_[0]); | 838 player_->NotifyAnimationStarted(events->events_[0]); |
874 animations->Animate(kInitialTickTime + duration / 2); | 839 element_animations_->Animate(kInitialTickTime + duration / 2); |
875 animations->UpdateState(true, nullptr); | 840 element_animations_->UpdateState(true, nullptr); |
876 EXPECT_TRUE(animations->HasActiveAnimation()); | 841 EXPECT_TRUE(player_->HasActiveAnimation()); |
877 EXPECT_VECTOR2DF_EQ( | 842 EXPECT_VECTOR2DF_EQ( |
878 gfx::Vector2dF(200.f, 250.f), | 843 gfx::Vector2dF(200.f, 250.f), |
879 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); | 844 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); |
880 | 845 |
881 animations_impl->Animate(kInitialTickTime + duration / 2); | 846 element_animations_impl_->Animate(kInitialTickTime + duration / 2); |
882 animations_impl->UpdateState(true, events.get()); | 847 element_animations_impl_->UpdateState(true, events.get()); |
883 EXPECT_VECTOR2DF_EQ( | 848 EXPECT_VECTOR2DF_EQ( |
884 gfx::Vector2dF(200.f, 250.f), | 849 gfx::Vector2dF(200.f, 250.f), |
885 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); | 850 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); |
886 event = GetMostRecentPropertyUpdateEvent(events.get()); | 851 event = GetMostRecentPropertyUpdateEvent(events.get()); |
887 EXPECT_FALSE(event); | 852 EXPECT_FALSE(event); |
888 | 853 |
889 animations_impl->Animate(kInitialTickTime + duration); | 854 element_animations_impl_->Animate(kInitialTickTime + duration); |
890 animations_impl->UpdateState(true, events.get()); | 855 element_animations_impl_->UpdateState(true, events.get()); |
891 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( | 856 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( |
892 element_id_, ElementListType::ACTIVE)); | 857 element_id_, ElementListType::ACTIVE)); |
893 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | 858 EXPECT_FALSE(player_impl_->HasActiveAnimation()); |
894 event = GetMostRecentPropertyUpdateEvent(events.get()); | 859 event = GetMostRecentPropertyUpdateEvent(events.get()); |
895 EXPECT_FALSE(event); | 860 EXPECT_FALSE(event); |
896 | 861 |
897 animations->Animate(kInitialTickTime + duration); | 862 element_animations_->Animate(kInitialTickTime + duration); |
898 animations->UpdateState(true, nullptr); | 863 element_animations_->UpdateState(true, nullptr); |
899 EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset( | 864 EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset( |
900 element_id_, ElementListType::ACTIVE)); | 865 element_id_, ElementListType::ACTIVE)); |
901 EXPECT_FALSE(animations->HasActiveAnimation()); | 866 EXPECT_FALSE(player_->HasActiveAnimation()); |
902 } | 867 } |
903 | 868 |
904 TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) { | 869 TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) { |
905 CreateTestLayer(true, false); | 870 CreateTestLayer(true, false); |
906 AttachTimelinePlayerLayer(); | 871 AttachTimelinePlayerLayer(); |
907 CreateImplTimelineAndPlayer(); | 872 CreateImplTimelineAndPlayer(); |
908 | 873 |
909 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
910 | |
911 auto events = host_impl_->CreateEvents(); | 874 auto events = host_impl_->CreateEvents(); |
912 | 875 |
913 gfx::ScrollOffset initial_value(100.f, 300.f); | 876 gfx::ScrollOffset initial_value(100.f, 300.f); |
914 gfx::ScrollOffset target_value(300.f, 200.f); | 877 gfx::ScrollOffset target_value(300.f, 200.f); |
915 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 878 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
916 ScrollOffsetAnimationCurve::Create( | 879 ScrollOffsetAnimationCurve::Create( |
917 target_value, CubicBezierTimingFunction::CreatePreset( | 880 target_value, CubicBezierTimingFunction::CreatePreset( |
918 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); | 881 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); |
919 curve->SetInitialValue(initial_value); | 882 curve->SetInitialValue(initial_value); |
920 double duration_in_seconds = curve->Duration().InSecondsF(); | 883 double duration_in_seconds = curve->Duration().InSecondsF(); |
921 | 884 |
922 std::unique_ptr<Animation> animation( | 885 std::unique_ptr<Animation> animation( |
923 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 886 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
924 animation->set_is_impl_only(true); | 887 animation->set_is_impl_only(true); |
925 animations_impl->AddAnimation(std::move(animation)); | 888 player_impl_->AddAnimation(std::move(animation)); |
926 | 889 |
927 animations_impl->Animate(kInitialTickTime); | 890 element_animations_impl_->Animate(kInitialTickTime); |
928 animations_impl->UpdateState(true, events.get()); | 891 element_animations_impl_->UpdateState(true, events.get()); |
929 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | 892 EXPECT_TRUE(player_impl_->HasActiveAnimation()); |
930 EXPECT_EQ(initial_value, | 893 EXPECT_EQ(initial_value, |
931 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); | 894 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); |
932 // Scroll offset animations should not generate property updates. | 895 // Scroll offset animations should not generate property updates. |
933 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 896 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
934 EXPECT_FALSE(event); | 897 EXPECT_FALSE(event); |
935 | 898 |
936 TimeDelta duration = TimeDelta::FromMicroseconds( | 899 TimeDelta duration = TimeDelta::FromMicroseconds( |
937 duration_in_seconds * base::Time::kMicrosecondsPerSecond); | 900 duration_in_seconds * base::Time::kMicrosecondsPerSecond); |
938 | 901 |
939 animations_impl->Animate(kInitialTickTime + duration / 2); | 902 element_animations_impl_->Animate(kInitialTickTime + duration / 2); |
940 animations_impl->UpdateState(true, events.get()); | 903 element_animations_impl_->UpdateState(true, events.get()); |
941 EXPECT_VECTOR2DF_EQ( | 904 EXPECT_VECTOR2DF_EQ( |
942 gfx::Vector2dF(200.f, 250.f), | 905 gfx::Vector2dF(200.f, 250.f), |
943 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); | 906 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); |
944 event = GetMostRecentPropertyUpdateEvent(events.get()); | 907 event = GetMostRecentPropertyUpdateEvent(events.get()); |
945 EXPECT_FALSE(event); | 908 EXPECT_FALSE(event); |
946 | 909 |
947 animations_impl->Animate(kInitialTickTime + duration); | 910 element_animations_impl_->Animate(kInitialTickTime + duration); |
948 animations_impl->UpdateState(true, events.get()); | 911 element_animations_impl_->UpdateState(true, events.get()); |
949 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( | 912 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( |
950 element_id_, ElementListType::ACTIVE)); | 913 element_id_, ElementListType::ACTIVE)); |
951 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | 914 EXPECT_FALSE(player_impl_->HasActiveAnimation()); |
952 event = GetMostRecentPropertyUpdateEvent(events.get()); | 915 event = GetMostRecentPropertyUpdateEvent(events.get()); |
953 EXPECT_FALSE(event); | 916 EXPECT_FALSE(event); |
954 } | 917 } |
955 | 918 |
956 // This test verifies that if an animation is added after a layer is animated, | 919 // This test verifies that if an animation is added after a layer is animated, |
957 // it doesn't get promoted to be in the RUNNING state. This prevents cases where | 920 // it doesn't get promoted to be in the RUNNING state. This prevents cases where |
958 // a start time gets set on an animation using the stale value of | 921 // a start time gets set on an animation using the stale value of |
959 // last_tick_time_. | 922 // last_tick_time_. |
960 TEST_F(ElementAnimationsTest, UpdateStateWithoutAnimate) { | 923 TEST_F(ElementAnimationsTest, UpdateStateWithoutAnimate) { |
961 CreateTestLayer(true, false); | 924 CreateTestLayer(true, false); |
962 AttachTimelinePlayerLayer(); | 925 AttachTimelinePlayerLayer(); |
963 CreateImplTimelineAndPlayer(); | 926 CreateImplTimelineAndPlayer(); |
964 | 927 |
965 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
966 | |
967 auto events = host_impl_->CreateEvents(); | 928 auto events = host_impl_->CreateEvents(); |
968 | 929 |
969 // Add first scroll offset animation. | 930 // Add first scroll offset animation. |
970 AddScrollOffsetAnimationToElementAnimations( | 931 AddScrollOffsetAnimationToPlayer(player_impl_.get(), |
971 animations_impl.get(), gfx::ScrollOffset(100.f, 300.f), | 932 gfx::ScrollOffset(100.f, 300.f), |
972 gfx::ScrollOffset(100.f, 200.f), true); | 933 gfx::ScrollOffset(100.f, 200.f), true); |
973 | 934 |
974 // Calling UpdateState after Animate should promote the animation to running | 935 // Calling UpdateState after Animate should promote the animation to running |
975 // state. | 936 // state. |
976 animations_impl->Animate(kInitialTickTime); | 937 element_animations_impl_->Animate(kInitialTickTime); |
977 animations_impl->UpdateState(true, events.get()); | 938 element_animations_impl_->UpdateState(true, events.get()); |
978 EXPECT_EQ(Animation::RUNNING, | 939 EXPECT_EQ( |
979 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 940 Animation::RUNNING, |
980 ->run_state()); | 941 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); |
981 | 942 |
982 animations_impl->Animate(kInitialTickTime + | 943 element_animations_impl_->Animate(kInitialTickTime + |
983 TimeDelta::FromMilliseconds(1500)); | 944 TimeDelta::FromMilliseconds(1500)); |
984 animations_impl->UpdateState(true, events.get()); | 945 element_animations_impl_->UpdateState(true, events.get()); |
985 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | 946 EXPECT_EQ( |
986 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 947 Animation::WAITING_FOR_DELETION, |
987 ->run_state()); | 948 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); |
988 | 949 |
989 // Add second scroll offset animation. | 950 // Add second scroll offset animation. |
990 AddScrollOffsetAnimationToElementAnimations( | 951 AddScrollOffsetAnimationToPlayer(player_impl_.get(), |
991 animations_impl.get(), gfx::ScrollOffset(100.f, 200.f), | 952 gfx::ScrollOffset(100.f, 200.f), |
992 gfx::ScrollOffset(100.f, 100.f), true); | 953 gfx::ScrollOffset(100.f, 100.f), true); |
993 | 954 |
994 // Calling UpdateState without Animate should NOT promote the animation to | 955 // Calling UpdateState without Animate should NOT promote the animation to |
995 // running state. | 956 // running state. |
996 animations_impl->UpdateState(true, events.get()); | 957 element_animations_impl_->UpdateState(true, events.get()); |
997 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 958 EXPECT_EQ( |
998 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 959 Animation::WAITING_FOR_TARGET_AVAILABILITY, |
999 ->run_state()); | 960 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); |
1000 | 961 |
1001 animations_impl->Animate(kInitialTickTime + | 962 element_animations_impl_->Animate(kInitialTickTime + |
1002 TimeDelta::FromMilliseconds(2000)); | 963 TimeDelta::FromMilliseconds(2000)); |
1003 animations_impl->UpdateState(true, events.get()); | 964 element_animations_impl_->UpdateState(true, events.get()); |
1004 | 965 |
1005 EXPECT_EQ(Animation::RUNNING, | 966 EXPECT_EQ( |
1006 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 967 Animation::RUNNING, |
1007 ->run_state()); | 968 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); |
1008 EXPECT_VECTOR2DF_EQ( | 969 EXPECT_VECTOR2DF_EQ( |
1009 gfx::ScrollOffset(100.f, 200.f), | 970 gfx::ScrollOffset(100.f, 200.f), |
1010 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); | 971 client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); |
1011 } | 972 } |
1012 | 973 |
1013 // Ensure that when the impl animations doesn't have a value provider, | 974 // Ensure that when the impl animations doesn't have a value provider, |
1014 // the main-thread animations's value provider is used to obtain the intial | 975 // the main-thread animations's value provider is used to obtain the intial |
1015 // scroll offset. | 976 // scroll offset. |
1016 TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) { | 977 TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) { |
1017 CreateTestLayer(false, false); | 978 CreateTestLayer(false, false); |
1018 CreateTestImplLayer(ElementListType::PENDING); | 979 CreateTestImplLayer(ElementListType::PENDING); |
1019 AttachTimelinePlayerLayer(); | 980 AttachTimelinePlayerLayer(); |
1020 CreateImplTimelineAndPlayer(); | 981 CreateImplTimelineAndPlayer(); |
1021 | 982 |
1022 scoped_refptr<ElementAnimations> animations = element_animations(); | 983 EXPECT_TRUE(element_animations_impl_->has_element_in_pending_list()); |
1023 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 984 EXPECT_FALSE(element_animations_impl_->has_element_in_active_list()); |
1024 | |
1025 EXPECT_TRUE(animations_impl->has_element_in_pending_list()); | |
1026 EXPECT_FALSE(animations_impl->has_element_in_active_list()); | |
1027 | 985 |
1028 auto events = host_impl_->CreateEvents(); | 986 auto events = host_impl_->CreateEvents(); |
1029 | 987 |
1030 gfx::ScrollOffset initial_value(500.f, 100.f); | 988 gfx::ScrollOffset initial_value(500.f, 100.f); |
1031 gfx::ScrollOffset target_value(300.f, 200.f); | 989 gfx::ScrollOffset target_value(300.f, 200.f); |
1032 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 990 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
1033 ScrollOffsetAnimationCurve::Create( | 991 ScrollOffsetAnimationCurve::Create( |
1034 target_value, CubicBezierTimingFunction::CreatePreset( | 992 target_value, CubicBezierTimingFunction::CreatePreset( |
1035 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); | 993 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); |
1036 | 994 |
1037 std::unique_ptr<Animation> animation( | 995 std::unique_ptr<Animation> animation( |
1038 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 996 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
1039 animation->set_needs_synchronized_start_time(true); | 997 animation->set_needs_synchronized_start_time(true); |
1040 animations->AddAnimation(std::move(animation)); | 998 player_->AddAnimation(std::move(animation)); |
1041 | 999 |
1042 client_.SetScrollOffsetForAnimation(initial_value); | 1000 client_.SetScrollOffsetForAnimation(initial_value); |
1043 PushProperties(); | 1001 PushProperties(); |
1044 animations_impl->ActivateAnimations(); | 1002 player_impl_->ActivateAnimations(); |
1045 EXPECT_TRUE(animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)); | 1003 EXPECT_TRUE(player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)); |
1046 TimeDelta duration = | 1004 TimeDelta duration = player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET) |
1047 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 1005 ->curve() |
1048 ->curve() | 1006 ->Duration(); |
1049 ->Duration(); | 1007 EXPECT_EQ(duration, player_->GetAnimation(TargetProperty::SCROLL_OFFSET) |
1050 EXPECT_EQ(duration, animations->GetAnimation(TargetProperty::SCROLL_OFFSET) | |
1051 ->curve() | 1008 ->curve() |
1052 ->Duration()); | 1009 ->Duration()); |
1053 | 1010 |
1054 animations->Animate(kInitialTickTime); | 1011 element_animations_->Animate(kInitialTickTime); |
1055 animations->UpdateState(true, nullptr); | 1012 element_animations_->UpdateState(true, nullptr); |
1056 | 1013 |
1057 EXPECT_TRUE(animations->HasActiveAnimation()); | 1014 EXPECT_TRUE(player_->HasActiveAnimation()); |
1058 EXPECT_EQ(initial_value, | 1015 EXPECT_EQ(initial_value, |
1059 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); | 1016 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); |
1060 EXPECT_EQ(gfx::ScrollOffset(), client_impl_.GetScrollOffset( | 1017 EXPECT_EQ(gfx::ScrollOffset(), client_impl_.GetScrollOffset( |
1061 element_id_, ElementListType::PENDING)); | 1018 element_id_, ElementListType::PENDING)); |
1062 | 1019 |
1063 animations_impl->Animate(kInitialTickTime); | 1020 element_animations_impl_->Animate(kInitialTickTime); |
1064 | 1021 |
1065 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | 1022 EXPECT_TRUE(player_impl_->HasActiveAnimation()); |
1066 EXPECT_EQ(initial_value, client_impl_.GetScrollOffset( | 1023 EXPECT_EQ(initial_value, client_impl_.GetScrollOffset( |
1067 element_id_, ElementListType::PENDING)); | 1024 element_id_, ElementListType::PENDING)); |
1068 | 1025 |
1069 CreateTestImplLayer(ElementListType::ACTIVE); | 1026 CreateTestImplLayer(ElementListType::ACTIVE); |
1070 | 1027 |
1071 animations_impl->UpdateState(true, events.get()); | 1028 element_animations_impl_->UpdateState(true, events.get()); |
1072 DCHECK_EQ(1UL, events->events_.size()); | 1029 DCHECK_EQ(1UL, events->events_.size()); |
1073 | 1030 |
1074 // Scroll offset animations should not generate property updates. | 1031 // Scroll offset animations should not generate property updates. |
1075 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 1032 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
1076 EXPECT_FALSE(event); | 1033 EXPECT_FALSE(event); |
1077 | 1034 |
1078 animations->NotifyAnimationStarted(events->events_[0]); | 1035 player_->NotifyAnimationStarted(events->events_[0]); |
1079 animations->Animate(kInitialTickTime + duration / 2); | 1036 element_animations_->Animate(kInitialTickTime + duration / 2); |
1080 animations->UpdateState(true, nullptr); | 1037 element_animations_->UpdateState(true, nullptr); |
1081 EXPECT_TRUE(animations->HasActiveAnimation()); | 1038 EXPECT_TRUE(player_->HasActiveAnimation()); |
1082 EXPECT_VECTOR2DF_EQ( | 1039 EXPECT_VECTOR2DF_EQ( |
1083 gfx::Vector2dF(400.f, 150.f), | 1040 gfx::Vector2dF(400.f, 150.f), |
1084 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); | 1041 client_.GetScrollOffset(element_id_, ElementListType::ACTIVE)); |
1085 | 1042 |
1086 animations_impl->Animate(kInitialTickTime + duration / 2); | 1043 element_animations_impl_->Animate(kInitialTickTime + duration / 2); |
1087 animations_impl->UpdateState(true, events.get()); | 1044 element_animations_impl_->UpdateState(true, events.get()); |
1088 EXPECT_VECTOR2DF_EQ( | 1045 EXPECT_VECTOR2DF_EQ( |
1089 gfx::Vector2dF(400.f, 150.f), | 1046 gfx::Vector2dF(400.f, 150.f), |
1090 client_impl_.GetScrollOffset(element_id_, ElementListType::PENDING)); | 1047 client_impl_.GetScrollOffset(element_id_, ElementListType::PENDING)); |
1091 event = GetMostRecentPropertyUpdateEvent(events.get()); | 1048 event = GetMostRecentPropertyUpdateEvent(events.get()); |
1092 EXPECT_FALSE(event); | 1049 EXPECT_FALSE(event); |
1093 | 1050 |
1094 animations_impl->Animate(kInitialTickTime + duration); | 1051 element_animations_impl_->Animate(kInitialTickTime + duration); |
1095 animations_impl->UpdateState(true, events.get()); | 1052 element_animations_impl_->UpdateState(true, events.get()); |
1096 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( | 1053 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( |
1097 element_id_, ElementListType::PENDING)); | 1054 element_id_, ElementListType::PENDING)); |
1098 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | 1055 EXPECT_FALSE(player_impl_->HasActiveAnimation()); |
1099 event = GetMostRecentPropertyUpdateEvent(events.get()); | 1056 event = GetMostRecentPropertyUpdateEvent(events.get()); |
1100 EXPECT_FALSE(event); | 1057 EXPECT_FALSE(event); |
1101 | 1058 |
1102 animations->Animate(kInitialTickTime + duration); | 1059 element_animations_->Animate(kInitialTickTime + duration); |
1103 animations->UpdateState(true, nullptr); | 1060 element_animations_->UpdateState(true, nullptr); |
1104 EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset( | 1061 EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset( |
1105 element_id_, ElementListType::ACTIVE)); | 1062 element_id_, ElementListType::ACTIVE)); |
1106 EXPECT_FALSE(animations->HasActiveAnimation()); | 1063 EXPECT_FALSE(player_->HasActiveAnimation()); |
1107 } | 1064 } |
1108 | 1065 |
1109 TEST_F(ElementAnimationsTest, ScrollOffsetRemovalClearsScrollDelta) { | 1066 TEST_F(ElementAnimationsTest, ScrollOffsetRemovalClearsScrollDelta) { |
1110 CreateTestLayer(true, false); | 1067 CreateTestLayer(true, false); |
1111 AttachTimelinePlayerLayer(); | 1068 AttachTimelinePlayerLayer(); |
1112 CreateImplTimelineAndPlayer(); | 1069 CreateImplTimelineAndPlayer(); |
1113 | 1070 |
1114 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1115 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
1116 | |
1117 auto events = host_impl_->CreateEvents(); | 1071 auto events = host_impl_->CreateEvents(); |
1118 | 1072 |
1119 // First test the 1-argument version of RemoveAnimation. | 1073 // First test the 1-argument version of RemoveAnimation. |
1120 gfx::ScrollOffset target_value(300.f, 200.f); | 1074 gfx::ScrollOffset target_value(300.f, 200.f); |
1121 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 1075 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
1122 ScrollOffsetAnimationCurve::Create( | 1076 ScrollOffsetAnimationCurve::Create( |
1123 target_value, CubicBezierTimingFunction::CreatePreset( | 1077 target_value, CubicBezierTimingFunction::CreatePreset( |
1124 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); | 1078 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); |
1125 | 1079 |
1126 int animation_id = 1; | 1080 int animation_id = 1; |
1127 std::unique_ptr<Animation> animation(Animation::Create( | 1081 std::unique_ptr<Animation> animation(Animation::Create( |
1128 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET)); | 1082 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET)); |
1129 animation->set_needs_synchronized_start_time(true); | 1083 animation->set_needs_synchronized_start_time(true); |
1130 animations->AddAnimation(std::move(animation)); | 1084 player_->AddAnimation(std::move(animation)); |
1131 PushProperties(); | 1085 PushProperties(); |
1132 animations_impl->ActivateAnimations(); | 1086 element_animations_impl_->ActivateAnimations(); |
1133 EXPECT_FALSE(animations->scroll_offset_animation_was_interrupted()); | 1087 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); |
1134 EXPECT_FALSE(animations_impl->scroll_offset_animation_was_interrupted()); | 1088 EXPECT_FALSE( |
| 1089 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
1135 | 1090 |
1136 animations->RemoveAnimation(animation_id); | 1091 player_->RemoveAnimation(animation_id); |
1137 EXPECT_TRUE(animations->scroll_offset_animation_was_interrupted()); | 1092 EXPECT_TRUE(element_animations_->scroll_offset_animation_was_interrupted()); |
1138 | 1093 |
1139 PushProperties(); | 1094 PushProperties(); |
1140 EXPECT_TRUE(animations_impl->scroll_offset_animation_was_interrupted()); | 1095 EXPECT_TRUE( |
1141 EXPECT_FALSE(animations->scroll_offset_animation_was_interrupted()); | 1096 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
| 1097 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); |
1142 | 1098 |
1143 animations_impl->ActivateAnimations(); | 1099 element_animations_impl_->ActivateAnimations(); |
1144 EXPECT_FALSE(animations_impl->scroll_offset_animation_was_interrupted()); | 1100 EXPECT_FALSE( |
| 1101 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
1145 | 1102 |
1146 // Now, test the 2-argument version of RemoveAnimation. | 1103 // Now, test the 2-argument version of RemoveAnimation. |
1147 curve = ScrollOffsetAnimationCurve::Create( | 1104 curve = ScrollOffsetAnimationCurve::Create( |
1148 target_value, CubicBezierTimingFunction::CreatePreset( | 1105 target_value, CubicBezierTimingFunction::CreatePreset( |
1149 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)); | 1106 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)); |
1150 animation = Animation::Create(std::move(curve), animation_id, 0, | 1107 animation = Animation::Create(std::move(curve), animation_id, 0, |
1151 TargetProperty::SCROLL_OFFSET); | 1108 TargetProperty::SCROLL_OFFSET); |
1152 animation->set_needs_synchronized_start_time(true); | 1109 animation->set_needs_synchronized_start_time(true); |
1153 animations->AddAnimation(std::move(animation)); | 1110 player_->AddAnimation(std::move(animation)); |
1154 PushProperties(); | 1111 PushProperties(); |
1155 animations_impl->ActivateAnimations(); | 1112 element_animations_impl_->ActivateAnimations(); |
1156 EXPECT_FALSE(animations->scroll_offset_animation_was_interrupted()); | 1113 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); |
1157 EXPECT_FALSE(animations_impl->scroll_offset_animation_was_interrupted()); | 1114 EXPECT_FALSE( |
| 1115 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
1158 | 1116 |
1159 animations->RemoveAnimation(animation_id); | 1117 player_->RemoveAnimation(animation_id); |
1160 EXPECT_TRUE(animations->scroll_offset_animation_was_interrupted()); | 1118 EXPECT_TRUE(element_animations_->scroll_offset_animation_was_interrupted()); |
1161 | 1119 |
1162 PushProperties(); | 1120 PushProperties(); |
1163 EXPECT_TRUE(animations_impl->scroll_offset_animation_was_interrupted()); | 1121 EXPECT_TRUE( |
1164 EXPECT_FALSE(animations->scroll_offset_animation_was_interrupted()); | 1122 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
| 1123 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); |
1165 | 1124 |
1166 animations_impl->ActivateAnimations(); | 1125 element_animations_impl_->ActivateAnimations(); |
1167 EXPECT_FALSE(animations_impl->scroll_offset_animation_was_interrupted()); | 1126 EXPECT_FALSE( |
| 1127 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
1168 | 1128 |
1169 // Check that removing non-scroll-offset animations does not cause | 1129 // Check that removing non-scroll-offset animations does not cause |
1170 // scroll_offset_animation_was_interrupted() to get set. | 1130 // scroll_offset_animation_was_interrupted() to get set. |
1171 animation_id = | 1131 animation_id = AddAnimatedTransformToPlayer(player_.get(), 1.0, 1, 2); |
1172 AddAnimatedTransformToElementAnimations(animations.get(), 1.0, 1, 2); | |
1173 PushProperties(); | 1132 PushProperties(); |
1174 animations_impl->ActivateAnimations(); | 1133 element_animations_impl_->ActivateAnimations(); |
1175 EXPECT_FALSE(animations->scroll_offset_animation_was_interrupted()); | 1134 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); |
1176 EXPECT_FALSE(animations_impl->scroll_offset_animation_was_interrupted()); | 1135 EXPECT_FALSE( |
| 1136 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
1177 | 1137 |
1178 animations->RemoveAnimation(animation_id); | 1138 player_->RemoveAnimation(animation_id); |
1179 EXPECT_FALSE(animations->scroll_offset_animation_was_interrupted()); | 1139 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); |
1180 | 1140 |
1181 PushProperties(); | 1141 PushProperties(); |
1182 EXPECT_FALSE(animations_impl->scroll_offset_animation_was_interrupted()); | 1142 EXPECT_FALSE( |
1183 EXPECT_FALSE(animations->scroll_offset_animation_was_interrupted()); | 1143 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
| 1144 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); |
1184 | 1145 |
1185 animations_impl->ActivateAnimations(); | 1146 element_animations_impl_->ActivateAnimations(); |
1186 EXPECT_FALSE(animations_impl->scroll_offset_animation_was_interrupted()); | 1147 EXPECT_FALSE( |
| 1148 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
1187 | 1149 |
1188 animation_id = | 1150 animation_id = AddAnimatedFilterToPlayer(player_.get(), 1.0, 0.1f, 0.2f); |
1189 AddAnimatedFilterToElementAnimations(animations.get(), 1.0, 0.1f, 0.2f); | |
1190 PushProperties(); | 1151 PushProperties(); |
1191 animations_impl->ActivateAnimations(); | 1152 element_animations_impl_->ActivateAnimations(); |
1192 EXPECT_FALSE(animations->scroll_offset_animation_was_interrupted()); | 1153 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); |
1193 EXPECT_FALSE(animations_impl->scroll_offset_animation_was_interrupted()); | 1154 EXPECT_FALSE( |
| 1155 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
1194 | 1156 |
1195 animations->RemoveAnimation(animation_id); | 1157 player_->RemoveAnimation(animation_id); |
1196 EXPECT_FALSE(animations->scroll_offset_animation_was_interrupted()); | 1158 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); |
1197 | 1159 |
1198 PushProperties(); | 1160 PushProperties(); |
1199 EXPECT_FALSE(animations_impl->scroll_offset_animation_was_interrupted()); | 1161 EXPECT_FALSE( |
1200 EXPECT_FALSE(animations->scroll_offset_animation_was_interrupted()); | 1162 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
| 1163 EXPECT_FALSE(element_animations_->scroll_offset_animation_was_interrupted()); |
1201 | 1164 |
1202 animations_impl->ActivateAnimations(); | 1165 element_animations_impl_->ActivateAnimations(); |
1203 EXPECT_FALSE(animations_impl->scroll_offset_animation_was_interrupted()); | 1166 EXPECT_FALSE( |
| 1167 element_animations_impl_->scroll_offset_animation_was_interrupted()); |
1204 } | 1168 } |
1205 | 1169 |
1206 // Tests that impl-only animations lead to start and finished notifications | 1170 // Tests that impl-only animations lead to start and finished notifications |
1207 // on the impl thread animations's animation delegate. | 1171 // on the impl thread animations's animation delegate. |
1208 TEST_F(ElementAnimationsTest, | 1172 TEST_F(ElementAnimationsTest, |
1209 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { | 1173 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { |
1210 CreateTestLayer(true, false); | 1174 CreateTestLayer(true, false); |
1211 AttachTimelinePlayerLayer(); | 1175 AttachTimelinePlayerLayer(); |
1212 CreateImplTimelineAndPlayer(); | 1176 CreateImplTimelineAndPlayer(); |
1213 | 1177 |
1214 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1215 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
1216 | |
1217 auto events = host_impl_->CreateEvents(); | 1178 auto events = host_impl_->CreateEvents(); |
1218 | 1179 |
1219 TestAnimationDelegate delegate; | 1180 TestAnimationDelegate delegate; |
1220 player_impl_->set_animation_delegate(&delegate); | 1181 player_impl_->set_animation_delegate(&delegate); |
1221 | 1182 |
1222 gfx::ScrollOffset initial_value(100.f, 300.f); | 1183 gfx::ScrollOffset initial_value(100.f, 300.f); |
1223 gfx::ScrollOffset target_value(300.f, 200.f); | 1184 gfx::ScrollOffset target_value(300.f, 200.f); |
1224 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 1185 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
1225 ScrollOffsetAnimationCurve::Create( | 1186 ScrollOffsetAnimationCurve::Create( |
1226 target_value, CubicBezierTimingFunction::CreatePreset( | 1187 target_value, CubicBezierTimingFunction::CreatePreset( |
1227 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); | 1188 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); |
1228 curve->SetInitialValue(initial_value); | 1189 curve->SetInitialValue(initial_value); |
1229 TimeDelta duration = curve->Duration(); | 1190 TimeDelta duration = curve->Duration(); |
1230 std::unique_ptr<Animation> to_add( | 1191 std::unique_ptr<Animation> to_add( |
1231 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 1192 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
1232 to_add->set_is_impl_only(true); | 1193 to_add->set_is_impl_only(true); |
1233 animations_impl->AddAnimation(std::move(to_add)); | 1194 player_impl_->AddAnimation(std::move(to_add)); |
1234 | 1195 |
1235 EXPECT_FALSE(delegate.started()); | 1196 EXPECT_FALSE(delegate.started()); |
1236 EXPECT_FALSE(delegate.finished()); | 1197 EXPECT_FALSE(delegate.finished()); |
1237 | 1198 |
1238 animations_impl->Animate(kInitialTickTime); | 1199 element_animations_impl_->Animate(kInitialTickTime); |
1239 animations_impl->UpdateState(true, events.get()); | 1200 element_animations_impl_->UpdateState(true, events.get()); |
1240 | 1201 |
1241 EXPECT_TRUE(delegate.started()); | 1202 EXPECT_TRUE(delegate.started()); |
1242 EXPECT_FALSE(delegate.finished()); | 1203 EXPECT_FALSE(delegate.finished()); |
1243 | 1204 |
1244 events = host_impl_->CreateEvents(); | 1205 events = host_impl_->CreateEvents(); |
1245 animations_impl->Animate(kInitialTickTime + duration); | 1206 element_animations_impl_->Animate(kInitialTickTime + duration); |
1246 EXPECT_EQ(duration, | 1207 EXPECT_EQ(duration, player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET) |
1247 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 1208 ->curve() |
1248 ->curve() | 1209 ->Duration()); |
1249 ->Duration()); | 1210 element_animations_impl_->UpdateState(true, events.get()); |
1250 animations_impl->UpdateState(true, events.get()); | |
1251 | 1211 |
1252 EXPECT_TRUE(delegate.started()); | 1212 EXPECT_TRUE(delegate.started()); |
1253 EXPECT_TRUE(delegate.finished()); | 1213 EXPECT_TRUE(delegate.finished()); |
1254 } | 1214 } |
1255 | 1215 |
1256 // Tests that specified start times are sent to the main thread delegate | 1216 // Tests that specified start times are sent to the main thread delegate |
1257 TEST_F(ElementAnimationsTest, SpecifiedStartTimesAreSentToMainThreadDelegate) { | 1217 TEST_F(ElementAnimationsTest, SpecifiedStartTimesAreSentToMainThreadDelegate) { |
1258 CreateTestLayer(true, false); | 1218 CreateTestLayer(true, false); |
1259 AttachTimelinePlayerLayer(); | 1219 AttachTimelinePlayerLayer(); |
1260 CreateImplTimelineAndPlayer(); | 1220 CreateImplTimelineAndPlayer(); |
1261 | 1221 |
1262 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1263 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
1264 | |
1265 TestAnimationDelegate delegate; | 1222 TestAnimationDelegate delegate; |
1266 player_->set_animation_delegate(&delegate); | 1223 player_->set_animation_delegate(&delegate); |
1267 | 1224 |
1268 int animation_id = | 1225 int animation_id = |
1269 AddOpacityTransitionToElementAnimations(animations.get(), 1, 0, 1, false); | 1226 AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false); |
1270 | 1227 |
1271 const TimeTicks start_time = TicksFromSecondsF(123); | 1228 const TimeTicks start_time = TicksFromSecondsF(123); |
1272 animations->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); | 1229 player_->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time); |
1273 | 1230 |
1274 PushProperties(); | 1231 PushProperties(); |
1275 animations_impl->ActivateAnimations(); | 1232 player_impl_->ActivateAnimations(); |
1276 | 1233 |
1277 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 1234 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
1278 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 1235 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
1279 animations_impl->GetAnimationById(animation_id)->run_state()); | 1236 player_impl_->GetAnimationById(animation_id)->run_state()); |
1280 | 1237 |
1281 auto events = host_impl_->CreateEvents(); | 1238 auto events = host_impl_->CreateEvents(); |
1282 animations_impl->Animate(kInitialTickTime); | 1239 element_animations_impl_->Animate(kInitialTickTime); |
1283 animations_impl->UpdateState(true, events.get()); | 1240 element_animations_impl_->UpdateState(true, events.get()); |
1284 | 1241 |
1285 // Synchronize the start times. | 1242 // Synchronize the start times. |
1286 EXPECT_EQ(1u, events->events_.size()); | 1243 EXPECT_EQ(1u, events->events_.size()); |
1287 animations->NotifyAnimationStarted(events->events_[0]); | 1244 player_->NotifyAnimationStarted(events->events_[0]); |
1288 | 1245 |
1289 // Validate start time on the main thread delegate. | 1246 // Validate start time on the main thread delegate. |
1290 EXPECT_EQ(start_time, delegate.start_time()); | 1247 EXPECT_EQ(start_time, delegate.start_time()); |
1291 } | 1248 } |
1292 | 1249 |
1293 // Tests animations that are waiting for a synchronized start time do not | 1250 // Tests animations that are waiting for a synchronized start time do not |
1294 // finish. | 1251 // finish. |
1295 TEST_F(ElementAnimationsTest, | 1252 TEST_F(ElementAnimationsTest, |
1296 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { | 1253 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { |
1297 CreateTestLayer(false, false); | 1254 CreateTestLayer(false, false); |
1298 AttachTimelinePlayerLayer(); | 1255 AttachTimelinePlayerLayer(); |
1299 | 1256 |
1300 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1301 | |
1302 auto events = host_impl_->CreateEvents(); | 1257 auto events = host_impl_->CreateEvents(); |
1303 | 1258 |
1304 std::unique_ptr<Animation> to_add(CreateAnimation( | 1259 std::unique_ptr<Animation> to_add(CreateAnimation( |
1305 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1260 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1306 1, TargetProperty::OPACITY)); | 1261 1, TargetProperty::OPACITY)); |
1307 to_add->set_needs_synchronized_start_time(true); | 1262 to_add->set_needs_synchronized_start_time(true); |
1308 | 1263 |
1309 // We should pause at the first keyframe indefinitely waiting for that | 1264 // We should pause at the first keyframe indefinitely waiting for that |
1310 // animation to start. | 1265 // animation to start. |
1311 animations->AddAnimation(std::move(to_add)); | 1266 player_->AddAnimation(std::move(to_add)); |
1312 animations->Animate(kInitialTickTime); | 1267 element_animations_->Animate(kInitialTickTime); |
1313 animations->UpdateState(true, events.get()); | 1268 element_animations_->UpdateState(true, events.get()); |
1314 EXPECT_TRUE(animations->HasActiveAnimation()); | 1269 EXPECT_TRUE(player_->HasActiveAnimation()); |
1315 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1270 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1316 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1271 element_animations_->Animate(kInitialTickTime + |
1317 animations->UpdateState(true, events.get()); | 1272 TimeDelta::FromMilliseconds(1000)); |
1318 EXPECT_TRUE(animations->HasActiveAnimation()); | 1273 element_animations_->UpdateState(true, events.get()); |
| 1274 EXPECT_TRUE(player_->HasActiveAnimation()); |
1319 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1275 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1320 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1276 element_animations_->Animate(kInitialTickTime + |
1321 animations->UpdateState(true, events.get()); | 1277 TimeDelta::FromMilliseconds(2000)); |
1322 EXPECT_TRUE(animations->HasActiveAnimation()); | 1278 element_animations_->UpdateState(true, events.get()); |
| 1279 EXPECT_TRUE(player_->HasActiveAnimation()); |
1323 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1280 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1324 | 1281 |
1325 // Send the synchronized start time. | 1282 // Send the synchronized start time. |
1326 animations->NotifyAnimationStarted(AnimationEvent( | 1283 player_->NotifyAnimationStarted(AnimationEvent( |
1327 AnimationEvent::STARTED, ElementId(), 1, TargetProperty::OPACITY, | 1284 AnimationEvent::STARTED, ElementId(), 1, TargetProperty::OPACITY, |
1328 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); | 1285 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); |
1329 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); | 1286 element_animations_->Animate(kInitialTickTime + |
1330 animations->UpdateState(true, events.get()); | 1287 TimeDelta::FromMilliseconds(5000)); |
| 1288 element_animations_->UpdateState(true, events.get()); |
1331 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1289 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1332 EXPECT_FALSE(animations->HasActiveAnimation()); | 1290 EXPECT_FALSE(player_->HasActiveAnimation()); |
1333 } | 1291 } |
1334 | 1292 |
1335 // Tests that two queued animations affecting the same property run in sequence. | 1293 // Tests that two queued animations affecting the same property run in sequence. |
1336 TEST_F(ElementAnimationsTest, TrivialQueuing) { | 1294 TEST_F(ElementAnimationsTest, TrivialQueuing) { |
1337 CreateTestLayer(false, false); | 1295 CreateTestLayer(false, false); |
1338 AttachTimelinePlayerLayer(); | 1296 AttachTimelinePlayerLayer(); |
1339 | 1297 |
1340 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1341 | |
1342 auto events = host_impl_->CreateEvents(); | 1298 auto events = host_impl_->CreateEvents(); |
1343 | 1299 |
1344 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); | 1300 EXPECT_FALSE(player_->needs_to_start_animations()); |
1345 | 1301 |
1346 animations->AddAnimation(CreateAnimation( | 1302 player_->AddAnimation(CreateAnimation( |
1347 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1303 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1348 1, TargetProperty::OPACITY)); | 1304 1, TargetProperty::OPACITY)); |
1349 animations->AddAnimation(CreateAnimation( | 1305 player_->AddAnimation(CreateAnimation( |
1350 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1306 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
1351 2, TargetProperty::OPACITY)); | 1307 2, TargetProperty::OPACITY)); |
1352 | 1308 |
1353 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); | 1309 EXPECT_TRUE(player_->needs_to_start_animations()); |
1354 | 1310 |
1355 animations->Animate(kInitialTickTime); | 1311 element_animations_->Animate(kInitialTickTime); |
1356 | 1312 |
1357 // The second animation still needs to be started. | 1313 // The second animation still needs to be started. |
1358 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); | 1314 EXPECT_TRUE(player_->needs_to_start_animations()); |
1359 | 1315 |
1360 animations->UpdateState(true, events.get()); | 1316 element_animations_->UpdateState(true, events.get()); |
1361 EXPECT_TRUE(animations->HasActiveAnimation()); | 1317 EXPECT_TRUE(player_->HasActiveAnimation()); |
1362 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1318 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1363 | 1319 |
1364 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1320 element_animations_->Animate(kInitialTickTime + |
1365 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); | 1321 TimeDelta::FromMilliseconds(1000)); |
1366 animations->UpdateState(true, events.get()); | 1322 EXPECT_TRUE(player_->needs_to_start_animations()); |
1367 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); | 1323 element_animations_->UpdateState(true, events.get()); |
| 1324 EXPECT_FALSE(player_->needs_to_start_animations()); |
1368 | 1325 |
1369 EXPECT_TRUE(animations->HasActiveAnimation()); | 1326 EXPECT_TRUE(player_->HasActiveAnimation()); |
1370 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1327 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1371 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1328 element_animations_->Animate(kInitialTickTime + |
1372 animations->UpdateState(true, events.get()); | 1329 TimeDelta::FromMilliseconds(2000)); |
| 1330 element_animations_->UpdateState(true, events.get()); |
1373 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1331 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1374 EXPECT_FALSE(animations->HasActiveAnimation()); | 1332 EXPECT_FALSE(player_->HasActiveAnimation()); |
1375 } | 1333 } |
1376 | 1334 |
1377 // Tests interrupting a transition with another transition. | 1335 // Tests interrupting a transition with another transition. |
1378 TEST_F(ElementAnimationsTest, Interrupt) { | 1336 TEST_F(ElementAnimationsTest, Interrupt) { |
1379 CreateTestLayer(false, false); | 1337 CreateTestLayer(false, false); |
1380 AttachTimelinePlayerLayer(); | 1338 AttachTimelinePlayerLayer(); |
1381 | 1339 |
1382 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1383 | |
1384 auto events = host_impl_->CreateEvents(); | 1340 auto events = host_impl_->CreateEvents(); |
1385 | 1341 |
1386 animations->AddAnimation(CreateAnimation( | 1342 player_->AddAnimation(CreateAnimation( |
1387 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1343 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1388 1, TargetProperty::OPACITY)); | 1344 1, TargetProperty::OPACITY)); |
1389 animations->Animate(kInitialTickTime); | 1345 element_animations_->Animate(kInitialTickTime); |
1390 animations->UpdateState(true, events.get()); | 1346 element_animations_->UpdateState(true, events.get()); |
1391 EXPECT_TRUE(animations->HasActiveAnimation()); | 1347 EXPECT_TRUE(player_->HasActiveAnimation()); |
1392 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1348 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1393 | 1349 |
1394 std::unique_ptr<Animation> to_add(CreateAnimation( | 1350 std::unique_ptr<Animation> to_add(CreateAnimation( |
1395 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1351 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
1396 2, TargetProperty::OPACITY)); | 1352 2, TargetProperty::OPACITY)); |
1397 animations->AbortAnimations(TargetProperty::OPACITY); | 1353 player_->AbortAnimations(TargetProperty::OPACITY, false); |
1398 animations->AddAnimation(std::move(to_add)); | 1354 player_->AddAnimation(std::move(to_add)); |
1399 | 1355 |
1400 // Since the previous animation was aborted, the new animation should start | 1356 // Since the previous animation was aborted, the new animation should start |
1401 // right in this call to animate. | 1357 // right in this call to animate. |
1402 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1358 element_animations_->Animate(kInitialTickTime + |
1403 animations->UpdateState(true, events.get()); | 1359 TimeDelta::FromMilliseconds(500)); |
1404 EXPECT_TRUE(animations->HasActiveAnimation()); | 1360 element_animations_->UpdateState(true, events.get()); |
| 1361 EXPECT_TRUE(player_->HasActiveAnimation()); |
1405 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1362 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1406 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | 1363 element_animations_->Animate(kInitialTickTime + |
1407 animations->UpdateState(true, events.get()); | 1364 TimeDelta::FromMilliseconds(1500)); |
| 1365 element_animations_->UpdateState(true, events.get()); |
1408 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1366 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1409 EXPECT_FALSE(animations->HasActiveAnimation()); | 1367 EXPECT_FALSE(player_->HasActiveAnimation()); |
1410 } | 1368 } |
1411 | 1369 |
1412 // Tests scheduling two animations to run together when only one property is | 1370 // Tests scheduling two animations to run together when only one property is |
1413 // free. | 1371 // free. |
1414 TEST_F(ElementAnimationsTest, ScheduleTogetherWhenAPropertyIsBlocked) { | 1372 TEST_F(ElementAnimationsTest, ScheduleTogetherWhenAPropertyIsBlocked) { |
1415 CreateTestLayer(false, false); | 1373 CreateTestLayer(false, false); |
1416 AttachTimelinePlayerLayer(); | 1374 AttachTimelinePlayerLayer(); |
1417 | 1375 |
1418 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1419 | |
1420 auto events = host_impl_->CreateEvents(); | 1376 auto events = host_impl_->CreateEvents(); |
1421 | 1377 |
1422 animations->AddAnimation(CreateAnimation( | 1378 player_->AddAnimation(CreateAnimation( |
1423 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | 1379 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, |
1424 TargetProperty::TRANSFORM)); | 1380 TargetProperty::TRANSFORM)); |
1425 animations->AddAnimation(CreateAnimation( | 1381 player_->AddAnimation(CreateAnimation( |
1426 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, | 1382 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, |
1427 TargetProperty::TRANSFORM)); | 1383 TargetProperty::TRANSFORM)); |
1428 animations->AddAnimation(CreateAnimation( | 1384 player_->AddAnimation(CreateAnimation( |
1429 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1385 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1430 2, TargetProperty::OPACITY)); | 1386 2, TargetProperty::OPACITY)); |
1431 | 1387 |
1432 animations->Animate(kInitialTickTime); | 1388 element_animations_->Animate(kInitialTickTime); |
1433 animations->UpdateState(true, events.get()); | 1389 element_animations_->UpdateState(true, events.get()); |
1434 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1390 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1435 EXPECT_TRUE(animations->HasActiveAnimation()); | 1391 EXPECT_TRUE(player_->HasActiveAnimation()); |
1436 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1392 element_animations_->Animate(kInitialTickTime + |
1437 animations->UpdateState(true, events.get()); | 1393 TimeDelta::FromMilliseconds(1000)); |
| 1394 element_animations_->UpdateState(true, events.get()); |
1438 // Should not have started the float transition yet. | 1395 // Should not have started the float transition yet. |
1439 EXPECT_TRUE(animations->HasActiveAnimation()); | 1396 EXPECT_TRUE(player_->HasActiveAnimation()); |
1440 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1397 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1441 // The float animation should have started at time 1 and should be done. | 1398 // The float animation should have started at time 1 and should be done. |
1442 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1399 element_animations_->Animate(kInitialTickTime + |
1443 animations->UpdateState(true, events.get()); | 1400 TimeDelta::FromMilliseconds(2000)); |
| 1401 element_animations_->UpdateState(true, events.get()); |
1444 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1402 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1445 EXPECT_FALSE(animations->HasActiveAnimation()); | 1403 EXPECT_FALSE(player_->HasActiveAnimation()); |
1446 } | 1404 } |
1447 | 1405 |
1448 // Tests scheduling two animations to run together with different lengths and | 1406 // Tests scheduling two animations to run together with different lengths and |
1449 // another animation queued to start when the shorter animation finishes (should | 1407 // another animation queued to start when the shorter animation finishes (should |
1450 // wait for both to finish). | 1408 // wait for both to finish). |
1451 TEST_F(ElementAnimationsTest, ScheduleTogetherWithAnAnimWaiting) { | 1409 TEST_F(ElementAnimationsTest, ScheduleTogetherWithAnAnimWaiting) { |
1452 CreateTestLayer(false, false); | 1410 CreateTestLayer(false, false); |
1453 AttachTimelinePlayerLayer(); | 1411 AttachTimelinePlayerLayer(); |
1454 | 1412 |
1455 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1456 | |
1457 auto events = host_impl_->CreateEvents(); | 1413 auto events = host_impl_->CreateEvents(); |
1458 | 1414 |
1459 animations->AddAnimation(CreateAnimation( | 1415 player_->AddAnimation(CreateAnimation( |
1460 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, | 1416 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, |
1461 TargetProperty::TRANSFORM)); | 1417 TargetProperty::TRANSFORM)); |
1462 animations->AddAnimation(CreateAnimation( | 1418 player_->AddAnimation(CreateAnimation( |
1463 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1419 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1464 1, TargetProperty::OPACITY)); | 1420 1, TargetProperty::OPACITY)); |
1465 animations->AddAnimation(CreateAnimation( | 1421 player_->AddAnimation(CreateAnimation( |
1466 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1422 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
1467 2, TargetProperty::OPACITY)); | 1423 2, TargetProperty::OPACITY)); |
1468 | 1424 |
1469 // Animations with id 1 should both start now. | 1425 // Animations with id 1 should both start now. |
1470 animations->Animate(kInitialTickTime); | 1426 element_animations_->Animate(kInitialTickTime); |
1471 animations->UpdateState(true, events.get()); | 1427 element_animations_->UpdateState(true, events.get()); |
1472 EXPECT_TRUE(animations->HasActiveAnimation()); | 1428 EXPECT_TRUE(player_->HasActiveAnimation()); |
1473 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1429 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1474 // The opacity animation should have finished at time 1, but the group | 1430 // The opacity animation should have finished at time 1, but the group |
1475 // of animations with id 1 don't finish until time 2 because of the length | 1431 // of animations with id 1 don't finish until time 2 because of the length |
1476 // of the transform animation. | 1432 // of the transform animation. |
1477 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1433 element_animations_->Animate(kInitialTickTime + |
1478 animations->UpdateState(true, events.get()); | 1434 TimeDelta::FromMilliseconds(2000)); |
| 1435 element_animations_->UpdateState(true, events.get()); |
1479 // Should not have started the float transition yet. | 1436 // Should not have started the float transition yet. |
1480 EXPECT_TRUE(animations->HasActiveAnimation()); | 1437 EXPECT_TRUE(player_->HasActiveAnimation()); |
1481 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1438 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1482 | 1439 |
1483 // The second opacity animation should start at time 2 and should be done by | 1440 // The second opacity animation should start at time 2 and should be done by |
1484 // time 3. | 1441 // time 3. |
1485 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1442 element_animations_->Animate(kInitialTickTime + |
1486 animations->UpdateState(true, events.get()); | 1443 TimeDelta::FromMilliseconds(3000)); |
| 1444 element_animations_->UpdateState(true, events.get()); |
1487 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1445 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1488 EXPECT_FALSE(animations->HasActiveAnimation()); | 1446 EXPECT_FALSE(player_->HasActiveAnimation()); |
1489 } | 1447 } |
1490 | 1448 |
1491 // Test that a looping animation loops and for the correct number of iterations. | 1449 // Test that a looping animation loops and for the correct number of iterations. |
1492 TEST_F(ElementAnimationsTest, TrivialLooping) { | 1450 TEST_F(ElementAnimationsTest, TrivialLooping) { |
1493 CreateTestLayer(false, false); | 1451 CreateTestLayer(false, false); |
1494 AttachTimelinePlayerLayer(); | 1452 AttachTimelinePlayerLayer(); |
1495 | 1453 |
1496 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1497 | |
1498 auto events = host_impl_->CreateEvents(); | 1454 auto events = host_impl_->CreateEvents(); |
1499 | 1455 |
1500 std::unique_ptr<Animation> to_add(CreateAnimation( | 1456 std::unique_ptr<Animation> to_add(CreateAnimation( |
1501 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1457 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1502 1, TargetProperty::OPACITY)); | 1458 1, TargetProperty::OPACITY)); |
1503 to_add->set_iterations(3); | 1459 to_add->set_iterations(3); |
1504 animations->AddAnimation(std::move(to_add)); | 1460 player_->AddAnimation(std::move(to_add)); |
1505 | 1461 |
1506 animations->Animate(kInitialTickTime); | 1462 element_animations_->Animate(kInitialTickTime); |
1507 animations->UpdateState(true, events.get()); | 1463 element_animations_->UpdateState(true, events.get()); |
1508 EXPECT_TRUE(animations->HasActiveAnimation()); | 1464 EXPECT_TRUE(player_->HasActiveAnimation()); |
1509 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1465 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1510 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); | 1466 element_animations_->Animate(kInitialTickTime + |
1511 animations->UpdateState(true, events.get()); | 1467 TimeDelta::FromMilliseconds(1250)); |
1512 EXPECT_TRUE(animations->HasActiveAnimation()); | 1468 element_animations_->UpdateState(true, events.get()); |
| 1469 EXPECT_TRUE(player_->HasActiveAnimation()); |
1513 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1470 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1514 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); | 1471 element_animations_->Animate(kInitialTickTime + |
1515 animations->UpdateState(true, events.get()); | 1472 TimeDelta::FromMilliseconds(1750)); |
1516 EXPECT_TRUE(animations->HasActiveAnimation()); | 1473 element_animations_->UpdateState(true, events.get()); |
| 1474 EXPECT_TRUE(player_->HasActiveAnimation()); |
1517 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1475 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1518 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2250)); | 1476 element_animations_->Animate(kInitialTickTime + |
1519 animations->UpdateState(true, events.get()); | 1477 TimeDelta::FromMilliseconds(2250)); |
1520 EXPECT_TRUE(animations->HasActiveAnimation()); | 1478 element_animations_->UpdateState(true, events.get()); |
| 1479 EXPECT_TRUE(player_->HasActiveAnimation()); |
1521 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1480 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1522 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2750)); | 1481 element_animations_->Animate(kInitialTickTime + |
1523 animations->UpdateState(true, events.get()); | 1482 TimeDelta::FromMilliseconds(2750)); |
1524 EXPECT_TRUE(animations->HasActiveAnimation()); | 1483 element_animations_->UpdateState(true, events.get()); |
| 1484 EXPECT_TRUE(player_->HasActiveAnimation()); |
1525 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1485 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1526 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1486 element_animations_->Animate(kInitialTickTime + |
1527 animations->UpdateState(true, events.get()); | 1487 TimeDelta::FromMilliseconds(3000)); |
1528 EXPECT_FALSE(animations->HasActiveAnimation()); | 1488 element_animations_->UpdateState(true, events.get()); |
| 1489 EXPECT_FALSE(player_->HasActiveAnimation()); |
1529 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1490 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1530 | 1491 |
1531 // Just be extra sure. | 1492 // Just be extra sure. |
1532 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); | 1493 element_animations_->Animate(kInitialTickTime + |
1533 animations->UpdateState(true, events.get()); | 1494 TimeDelta::FromMilliseconds(4000)); |
| 1495 element_animations_->UpdateState(true, events.get()); |
1534 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1496 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1535 } | 1497 } |
1536 | 1498 |
1537 // Test that an infinitely looping animation does indeed go until aborted. | 1499 // Test that an infinitely looping animation does indeed go until aborted. |
1538 TEST_F(ElementAnimationsTest, InfiniteLooping) { | 1500 TEST_F(ElementAnimationsTest, InfiniteLooping) { |
1539 CreateTestLayer(false, false); | 1501 CreateTestLayer(false, false); |
1540 AttachTimelinePlayerLayer(); | 1502 AttachTimelinePlayerLayer(); |
1541 | 1503 |
1542 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1543 | |
1544 auto events = host_impl_->CreateEvents(); | 1504 auto events = host_impl_->CreateEvents(); |
1545 | 1505 |
1546 std::unique_ptr<Animation> to_add(CreateAnimation( | 1506 std::unique_ptr<Animation> to_add(CreateAnimation( |
1547 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1507 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1548 1, TargetProperty::OPACITY)); | 1508 1, TargetProperty::OPACITY)); |
1549 to_add->set_iterations(-1); | 1509 to_add->set_iterations(-1); |
1550 animations->AddAnimation(std::move(to_add)); | 1510 player_->AddAnimation(std::move(to_add)); |
1551 | 1511 |
1552 animations->Animate(kInitialTickTime); | 1512 element_animations_->Animate(kInitialTickTime); |
1553 animations->UpdateState(true, events.get()); | 1513 element_animations_->UpdateState(true, events.get()); |
1554 EXPECT_TRUE(animations->HasActiveAnimation()); | 1514 EXPECT_TRUE(player_->HasActiveAnimation()); |
1555 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1515 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1556 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); | 1516 element_animations_->Animate(kInitialTickTime + |
1557 animations->UpdateState(true, events.get()); | 1517 TimeDelta::FromMilliseconds(1250)); |
1558 EXPECT_TRUE(animations->HasActiveAnimation()); | 1518 element_animations_->UpdateState(true, events.get()); |
| 1519 EXPECT_TRUE(player_->HasActiveAnimation()); |
1559 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1520 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1560 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); | 1521 element_animations_->Animate(kInitialTickTime + |
1561 animations->UpdateState(true, events.get()); | 1522 TimeDelta::FromMilliseconds(1750)); |
1562 EXPECT_TRUE(animations->HasActiveAnimation()); | 1523 element_animations_->UpdateState(true, events.get()); |
| 1524 EXPECT_TRUE(player_->HasActiveAnimation()); |
1563 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1525 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1564 | 1526 |
1565 animations->Animate(kInitialTickTime + | 1527 element_animations_->Animate(kInitialTickTime + |
1566 TimeDelta::FromMilliseconds(1073741824250)); | 1528 TimeDelta::FromMilliseconds(1073741824250)); |
1567 animations->UpdateState(true, events.get()); | 1529 element_animations_->UpdateState(true, events.get()); |
1568 EXPECT_TRUE(animations->HasActiveAnimation()); | 1530 EXPECT_TRUE(player_->HasActiveAnimation()); |
1569 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1531 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1570 animations->Animate(kInitialTickTime + | 1532 element_animations_->Animate(kInitialTickTime + |
1571 TimeDelta::FromMilliseconds(1073741824750)); | 1533 TimeDelta::FromMilliseconds(1073741824750)); |
1572 animations->UpdateState(true, events.get()); | 1534 element_animations_->UpdateState(true, events.get()); |
1573 EXPECT_TRUE(animations->HasActiveAnimation()); | 1535 EXPECT_TRUE(player_->HasActiveAnimation()); |
1574 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1536 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1575 | 1537 |
1576 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); | 1538 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY)); |
1577 animations->GetAnimation(TargetProperty::OPACITY) | 1539 player_->GetAnimation(TargetProperty::OPACITY) |
1578 ->SetRunState(Animation::ABORTED, | 1540 ->SetRunState(Animation::ABORTED, |
1579 kInitialTickTime + TimeDelta::FromMilliseconds(750)); | 1541 kInitialTickTime + TimeDelta::FromMilliseconds(750)); |
1580 EXPECT_FALSE(animations->HasActiveAnimation()); | 1542 EXPECT_FALSE(player_->HasActiveAnimation()); |
1581 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1543 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1582 } | 1544 } |
1583 | 1545 |
1584 // Test that pausing and resuming work as expected. | 1546 // Test that pausing and resuming work as expected. |
1585 TEST_F(ElementAnimationsTest, PauseResume) { | 1547 TEST_F(ElementAnimationsTest, PauseResume) { |
1586 CreateTestLayer(false, false); | 1548 CreateTestLayer(false, false); |
1587 AttachTimelinePlayerLayer(); | 1549 AttachTimelinePlayerLayer(); |
1588 | 1550 |
1589 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1590 | |
1591 auto events = host_impl_->CreateEvents(); | 1551 auto events = host_impl_->CreateEvents(); |
1592 | 1552 |
1593 animations->AddAnimation(CreateAnimation( | 1553 player_->AddAnimation(CreateAnimation( |
1594 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1554 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1595 1, TargetProperty::OPACITY)); | 1555 1, TargetProperty::OPACITY)); |
1596 | 1556 |
1597 animations->Animate(kInitialTickTime); | 1557 element_animations_->Animate(kInitialTickTime); |
1598 animations->UpdateState(true, events.get()); | 1558 element_animations_->UpdateState(true, events.get()); |
1599 EXPECT_TRUE(animations->HasActiveAnimation()); | 1559 EXPECT_TRUE(player_->HasActiveAnimation()); |
1600 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1560 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1601 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1561 element_animations_->Animate(kInitialTickTime + |
1602 animations->UpdateState(true, events.get()); | 1562 TimeDelta::FromMilliseconds(500)); |
1603 EXPECT_TRUE(animations->HasActiveAnimation()); | 1563 element_animations_->UpdateState(true, events.get()); |
| 1564 EXPECT_TRUE(player_->HasActiveAnimation()); |
1604 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1565 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1605 | 1566 |
1606 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); | 1567 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY)); |
1607 animations->GetAnimation(TargetProperty::OPACITY) | 1568 player_->GetAnimation(TargetProperty::OPACITY) |
1608 ->SetRunState(Animation::PAUSED, | 1569 ->SetRunState(Animation::PAUSED, |
1609 kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1570 kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
1610 | 1571 |
1611 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); | 1572 element_animations_->Animate(kInitialTickTime + |
1612 animations->UpdateState(true, events.get()); | 1573 TimeDelta::FromMilliseconds(1024000)); |
1613 EXPECT_TRUE(animations->HasActiveAnimation()); | 1574 element_animations_->UpdateState(true, events.get()); |
| 1575 EXPECT_TRUE(player_->HasActiveAnimation()); |
1614 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1576 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1615 | 1577 |
1616 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); | 1578 EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY)); |
1617 animations->GetAnimation(TargetProperty::OPACITY) | 1579 player_->GetAnimation(TargetProperty::OPACITY) |
1618 ->SetRunState(Animation::RUNNING, | 1580 ->SetRunState(Animation::RUNNING, |
1619 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); | 1581 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); |
1620 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250)); | 1582 element_animations_->Animate(kInitialTickTime + |
1621 animations->UpdateState(true, events.get()); | 1583 TimeDelta::FromMilliseconds(1024250)); |
1622 EXPECT_TRUE(animations->HasActiveAnimation()); | 1584 element_animations_->UpdateState(true, events.get()); |
| 1585 EXPECT_TRUE(player_->HasActiveAnimation()); |
1623 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1586 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1624 | 1587 |
1625 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); | 1588 element_animations_->Animate(kInitialTickTime + |
1626 animations->UpdateState(true, events.get()); | 1589 TimeDelta::FromMilliseconds(1024500)); |
1627 EXPECT_FALSE(animations->HasActiveAnimation()); | 1590 element_animations_->UpdateState(true, events.get()); |
| 1591 EXPECT_FALSE(player_->HasActiveAnimation()); |
1628 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1592 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1629 } | 1593 } |
1630 | 1594 |
1631 TEST_F(ElementAnimationsTest, AbortAGroupedAnimation) { | 1595 TEST_F(ElementAnimationsTest, AbortAGroupedAnimation) { |
1632 CreateTestLayer(false, false); | 1596 CreateTestLayer(false, false); |
1633 AttachTimelinePlayerLayer(); | 1597 AttachTimelinePlayerLayer(); |
1634 | 1598 |
1635 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1636 | |
1637 auto events = host_impl_->CreateEvents(); | 1599 auto events = host_impl_->CreateEvents(); |
1638 | 1600 |
1639 const int animation_id = 2; | 1601 const int animation_id = 2; |
1640 animations->AddAnimation(Animation::Create( | 1602 player_->AddAnimation(Animation::Create( |
1641 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, | 1603 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, |
1642 TargetProperty::TRANSFORM)); | 1604 TargetProperty::TRANSFORM)); |
1643 animations->AddAnimation(Animation::Create( | 1605 player_->AddAnimation(Animation::Create( |
1644 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), | 1606 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), |
1645 animation_id, 1, TargetProperty::OPACITY)); | 1607 animation_id, 1, TargetProperty::OPACITY)); |
1646 animations->AddAnimation(Animation::Create( | 1608 player_->AddAnimation(Animation::Create( |
1647 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), | 1609 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), |
1648 3, 2, TargetProperty::OPACITY)); | 1610 3, 2, TargetProperty::OPACITY)); |
1649 | 1611 |
1650 animations->Animate(kInitialTickTime); | 1612 element_animations_->Animate(kInitialTickTime); |
1651 animations->UpdateState(true, events.get()); | 1613 element_animations_->UpdateState(true, events.get()); |
1652 EXPECT_TRUE(animations->HasActiveAnimation()); | 1614 EXPECT_TRUE(player_->HasActiveAnimation()); |
1653 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1615 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1654 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1616 element_animations_->Animate(kInitialTickTime + |
1655 animations->UpdateState(true, events.get()); | 1617 TimeDelta::FromMilliseconds(1000)); |
1656 EXPECT_TRUE(animations->HasActiveAnimation()); | 1618 element_animations_->UpdateState(true, events.get()); |
| 1619 EXPECT_TRUE(player_->HasActiveAnimation()); |
1657 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1620 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1658 | 1621 |
1659 EXPECT_TRUE(animations->GetAnimationById(animation_id)); | 1622 EXPECT_TRUE(player_->GetAnimationById(animation_id)); |
1660 animations->GetAnimationById(animation_id) | 1623 player_->GetAnimationById(animation_id) |
1661 ->SetRunState(Animation::ABORTED, | 1624 ->SetRunState(Animation::ABORTED, |
1662 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1625 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1663 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1626 element_animations_->Animate(kInitialTickTime + |
1664 animations->UpdateState(true, events.get()); | 1627 TimeDelta::FromMilliseconds(1000)); |
1665 EXPECT_TRUE(animations->HasActiveAnimation()); | 1628 element_animations_->UpdateState(true, events.get()); |
| 1629 EXPECT_TRUE(player_->HasActiveAnimation()); |
1666 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1630 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1667 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1631 element_animations_->Animate(kInitialTickTime + |
1668 animations->UpdateState(true, events.get()); | 1632 TimeDelta::FromMilliseconds(2000)); |
1669 EXPECT_TRUE(!animations->HasActiveAnimation()); | 1633 element_animations_->UpdateState(true, events.get()); |
| 1634 EXPECT_TRUE(!player_->HasActiveAnimation()); |
1670 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1635 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1671 } | 1636 } |
1672 | 1637 |
1673 TEST_F(ElementAnimationsTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { | 1638 TEST_F(ElementAnimationsTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { |
1674 CreateTestLayer(true, false); | 1639 CreateTestLayer(true, false); |
1675 AttachTimelinePlayerLayer(); | 1640 AttachTimelinePlayerLayer(); |
1676 CreateImplTimelineAndPlayer(); | 1641 CreateImplTimelineAndPlayer(); |
1677 | 1642 |
1678 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1679 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
1680 | |
1681 auto events = host_impl_->CreateEvents(); | 1643 auto events = host_impl_->CreateEvents(); |
1682 | 1644 |
1683 std::unique_ptr<Animation> to_add(CreateAnimation( | 1645 std::unique_ptr<Animation> to_add(CreateAnimation( |
1684 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), | 1646 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), |
1685 0, TargetProperty::OPACITY)); | 1647 0, TargetProperty::OPACITY)); |
1686 to_add->set_needs_synchronized_start_time(true); | 1648 to_add->set_needs_synchronized_start_time(true); |
1687 animations->AddAnimation(std::move(to_add)); | 1649 player_->AddAnimation(std::move(to_add)); |
1688 | 1650 |
1689 animations->Animate(kInitialTickTime); | 1651 element_animations_->Animate(kInitialTickTime); |
1690 animations->UpdateState(true, events.get()); | 1652 element_animations_->UpdateState(true, events.get()); |
1691 EXPECT_TRUE(animations->HasActiveAnimation()); | 1653 EXPECT_TRUE(player_->HasActiveAnimation()); |
1692 Animation* active_animation = | 1654 Animation* active_animation = player_->GetAnimation(TargetProperty::OPACITY); |
1693 animations->GetAnimation(TargetProperty::OPACITY); | |
1694 EXPECT_TRUE(active_animation); | 1655 EXPECT_TRUE(active_animation); |
1695 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); | 1656 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); |
1696 | 1657 |
1697 EXPECT_TRUE(animations->needs_push_properties()); | 1658 EXPECT_TRUE(player_->needs_push_properties()); |
1698 PushProperties(); | 1659 PushProperties(); |
1699 animations_impl->ActivateAnimations(); | 1660 player_impl_->ActivateAnimations(); |
1700 | 1661 |
1701 active_animation = animations_impl->GetAnimation(TargetProperty::OPACITY); | 1662 active_animation = player_impl_->GetAnimation(TargetProperty::OPACITY); |
1702 EXPECT_TRUE(active_animation); | 1663 EXPECT_TRUE(active_animation); |
1703 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 1664 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
1704 active_animation->run_state()); | 1665 active_animation->run_state()); |
1705 } | 1666 } |
1706 | 1667 |
1707 // Tests that skipping a call to UpdateState works as expected. | 1668 // Tests that skipping a call to UpdateState works as expected. |
1708 TEST_F(ElementAnimationsTest, SkipUpdateState) { | 1669 TEST_F(ElementAnimationsTest, SkipUpdateState) { |
1709 CreateTestLayer(true, false); | 1670 CreateTestLayer(true, false); |
1710 AttachTimelinePlayerLayer(); | 1671 AttachTimelinePlayerLayer(); |
1711 | 1672 |
1712 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1713 | |
1714 auto events = host_impl_->CreateEvents(); | 1673 auto events = host_impl_->CreateEvents(); |
1715 | 1674 |
1716 std::unique_ptr<Animation> first_animation(CreateAnimation( | 1675 std::unique_ptr<Animation> first_animation(CreateAnimation( |
1717 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | 1676 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, |
1718 TargetProperty::TRANSFORM)); | 1677 TargetProperty::TRANSFORM)); |
1719 first_animation->set_is_controlling_instance_for_test(true); | 1678 first_animation->set_is_controlling_instance_for_test(true); |
1720 animations->AddAnimation(std::move(first_animation)); | 1679 player_->AddAnimation(std::move(first_animation)); |
1721 | 1680 |
1722 animations->Animate(kInitialTickTime); | 1681 element_animations_->Animate(kInitialTickTime); |
1723 animations->UpdateState(true, events.get()); | 1682 element_animations_->UpdateState(true, events.get()); |
1724 | 1683 |
1725 std::unique_ptr<Animation> second_animation(CreateAnimation( | 1684 std::unique_ptr<Animation> second_animation(CreateAnimation( |
1726 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1685 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1727 2, TargetProperty::OPACITY)); | 1686 2, TargetProperty::OPACITY)); |
1728 second_animation->set_is_controlling_instance_for_test(true); | 1687 second_animation->set_is_controlling_instance_for_test(true); |
1729 animations->AddAnimation(std::move(second_animation)); | 1688 player_->AddAnimation(std::move(second_animation)); |
1730 | 1689 |
1731 // Animate but don't UpdateState. | 1690 // Animate but don't UpdateState. |
1732 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1691 element_animations_->Animate(kInitialTickTime + |
| 1692 TimeDelta::FromMilliseconds(1000)); |
1733 | 1693 |
1734 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1694 element_animations_->Animate(kInitialTickTime + |
| 1695 TimeDelta::FromMilliseconds(2000)); |
1735 events = host_impl_->CreateEvents(); | 1696 events = host_impl_->CreateEvents(); |
1736 animations->UpdateState(true, events.get()); | 1697 element_animations_->UpdateState(true, events.get()); |
1737 | 1698 |
1738 // Should have one STARTED event and one FINISHED event. | 1699 // Should have one STARTED event and one FINISHED event. |
1739 EXPECT_EQ(2u, events->events_.size()); | 1700 EXPECT_EQ(2u, events->events_.size()); |
1740 EXPECT_NE(events->events_[0].type, events->events_[1].type); | 1701 EXPECT_NE(events->events_[0].type, events->events_[1].type); |
1741 | 1702 |
1742 // The float transition should still be at its starting point. | 1703 // The float transition should still be at its starting point. |
1743 EXPECT_TRUE(animations->HasActiveAnimation()); | 1704 EXPECT_TRUE(player_->HasActiveAnimation()); |
1744 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1705 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1745 | 1706 |
1746 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1707 element_animations_->Animate(kInitialTickTime + |
1747 animations->UpdateState(true, events.get()); | 1708 TimeDelta::FromMilliseconds(3000)); |
| 1709 element_animations_->UpdateState(true, events.get()); |
1748 | 1710 |
1749 // The float tranisition should now be done. | 1711 // The float tranisition should now be done. |
1750 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1712 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1751 EXPECT_FALSE(animations->HasActiveAnimation()); | 1713 EXPECT_FALSE(player_->HasActiveAnimation()); |
1752 } | 1714 } |
1753 | 1715 |
1754 // Tests that an animation animations with only a pending observer gets ticked | 1716 // Tests that an animation animations with only a pending observer gets ticked |
1755 // but doesn't progress animations past the STARTING state. | 1717 // but doesn't progress animations past the STARTING state. |
1756 TEST_F(ElementAnimationsTest, InactiveObserverGetsTicked) { | 1718 TEST_F(ElementAnimationsTest, InactiveObserverGetsTicked) { |
1757 AttachTimelinePlayerLayer(); | 1719 AttachTimelinePlayerLayer(); |
1758 CreateImplTimelineAndPlayer(); | 1720 CreateImplTimelineAndPlayer(); |
1759 | 1721 |
1760 scoped_refptr<ElementAnimations> animations = element_animations_impl(); | |
1761 | |
1762 auto events = host_impl_->CreateEvents(); | 1722 auto events = host_impl_->CreateEvents(); |
1763 | 1723 |
1764 const int id = 1; | 1724 const int id = 1; |
1765 animations->AddAnimation(CreateAnimation( | 1725 player_impl_->AddAnimation(CreateAnimation( |
1766 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), | 1726 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.5f, 1.f)), |
1767 id, TargetProperty::OPACITY)); | 1727 id, TargetProperty::OPACITY)); |
1768 | 1728 |
1769 // Without an observer, the animation shouldn't progress to the STARTING | 1729 // Without an observer, the animation shouldn't progress to the STARTING |
1770 // state. | 1730 // state. |
1771 animations->Animate(kInitialTickTime); | 1731 element_animations_impl_->Animate(kInitialTickTime); |
1772 animations->UpdateState(true, events.get()); | 1732 element_animations_impl_->UpdateState(true, events.get()); |
1773 EXPECT_EQ(0u, events->events_.size()); | 1733 EXPECT_EQ(0u, events->events_.size()); |
1774 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 1734 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
1775 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1735 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
1776 | 1736 |
1777 CreateTestImplLayer(ElementListType::PENDING); | 1737 CreateTestImplLayer(ElementListType::PENDING); |
1778 | 1738 |
1779 // With only a pending observer, the animation should progress to the | 1739 // With only a pending observer, the animation should progress to the |
1780 // STARTING state and get ticked at its starting point, but should not | 1740 // STARTING state and get ticked at its starting point, but should not |
1781 // progress to RUNNING. | 1741 // progress to RUNNING. |
1782 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1742 element_animations_impl_->Animate(kInitialTickTime + |
1783 animations->UpdateState(true, events.get()); | 1743 TimeDelta::FromMilliseconds(1000)); |
| 1744 element_animations_impl_->UpdateState(true, events.get()); |
1784 EXPECT_EQ(0u, events->events_.size()); | 1745 EXPECT_EQ(0u, events->events_.size()); |
1785 EXPECT_EQ(Animation::STARTING, | 1746 EXPECT_EQ(Animation::STARTING, |
1786 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1747 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
1787 EXPECT_EQ(0.5f, | 1748 EXPECT_EQ(0.5f, |
1788 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 1749 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
1789 | 1750 |
1790 // Even when already in the STARTING state, the animation should stay | 1751 // Even when already in the STARTING state, the animation should stay |
1791 // there, and shouldn't be ticked past its starting point. | 1752 // there, and shouldn't be ticked past its starting point. |
1792 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1753 element_animations_impl_->Animate(kInitialTickTime + |
1793 animations->UpdateState(true, events.get()); | 1754 TimeDelta::FromMilliseconds(2000)); |
| 1755 element_animations_impl_->UpdateState(true, events.get()); |
1794 EXPECT_EQ(0u, events->events_.size()); | 1756 EXPECT_EQ(0u, events->events_.size()); |
1795 EXPECT_EQ(Animation::STARTING, | 1757 EXPECT_EQ(Animation::STARTING, |
1796 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1758 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
1797 EXPECT_EQ(0.5f, | 1759 EXPECT_EQ(0.5f, |
1798 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 1760 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
1799 | 1761 |
1800 CreateTestImplLayer(ElementListType::ACTIVE); | 1762 CreateTestImplLayer(ElementListType::ACTIVE); |
1801 | 1763 |
1802 // Now that an active observer has been added, the animation should still | 1764 // Now that an active observer has been added, the animation should still |
1803 // initially tick at its starting point, but should now progress to RUNNING. | 1765 // initially tick at its starting point, but should now progress to RUNNING. |
1804 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1766 element_animations_impl_->Animate(kInitialTickTime + |
1805 animations->UpdateState(true, events.get()); | 1767 TimeDelta::FromMilliseconds(3000)); |
| 1768 element_animations_impl_->UpdateState(true, events.get()); |
1806 EXPECT_EQ(1u, events->events_.size()); | 1769 EXPECT_EQ(1u, events->events_.size()); |
1807 EXPECT_EQ(Animation::RUNNING, | 1770 EXPECT_EQ(Animation::RUNNING, |
1808 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1771 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
1809 EXPECT_EQ(0.5f, | 1772 EXPECT_EQ(0.5f, |
1810 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 1773 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
1811 EXPECT_EQ(0.5f, | 1774 EXPECT_EQ(0.5f, |
1812 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1775 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1813 | 1776 |
1814 // The animation should now tick past its starting point. | 1777 // The animation should now tick past its starting point. |
1815 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); | 1778 element_animations_impl_->Animate(kInitialTickTime + |
| 1779 TimeDelta::FromMilliseconds(3500)); |
1816 EXPECT_NE(0.5f, | 1780 EXPECT_NE(0.5f, |
1817 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 1781 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
1818 EXPECT_NE(0.5f, | 1782 EXPECT_NE(0.5f, |
1819 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 1783 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
1820 } | 1784 } |
1821 | 1785 |
1822 TEST_F(ElementAnimationsTest, TransformAnimationBounds) { | 1786 TEST_F(ElementAnimationsTest, TransformAnimationBounds) { |
1823 AttachTimelinePlayerLayer(); | 1787 AttachTimelinePlayerLayer(); |
1824 CreateImplTimelineAndPlayer(); | 1788 CreateImplTimelineAndPlayer(); |
1825 | 1789 |
1826 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
1827 | |
1828 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | 1790 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( |
1829 KeyframedTransformAnimationCurve::Create()); | 1791 KeyframedTransformAnimationCurve::Create()); |
1830 | 1792 |
1831 TransformOperations operations1; | 1793 TransformOperations operations1; |
1832 curve1->AddKeyframe( | 1794 curve1->AddKeyframe( |
1833 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 1795 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
1834 operations1.AppendTranslate(10.0, 15.0, 0.0); | 1796 operations1.AppendTranslate(10.0, 15.0, 0.0); |
1835 curve1->AddKeyframe(TransformKeyframe::Create( | 1797 curve1->AddKeyframe(TransformKeyframe::Create( |
1836 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | 1798 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); |
1837 | 1799 |
1838 std::unique_ptr<Animation> animation( | 1800 std::unique_ptr<Animation> animation( |
1839 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); | 1801 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); |
1840 animations_impl->AddAnimation(std::move(animation)); | 1802 player_impl_->AddAnimation(std::move(animation)); |
1841 | 1803 |
1842 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( | 1804 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( |
1843 KeyframedTransformAnimationCurve::Create()); | 1805 KeyframedTransformAnimationCurve::Create()); |
1844 | 1806 |
1845 TransformOperations operations2; | 1807 TransformOperations operations2; |
1846 curve2->AddKeyframe( | 1808 curve2->AddKeyframe( |
1847 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | 1809 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); |
1848 operations2.AppendScale(2.0, 3.0, 4.0); | 1810 operations2.AppendScale(2.0, 3.0, 4.0); |
1849 curve2->AddKeyframe(TransformKeyframe::Create( | 1811 curve2->AddKeyframe(TransformKeyframe::Create( |
1850 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 1812 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
1851 | 1813 |
1852 animation = | 1814 animation = |
1853 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); | 1815 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); |
1854 animations_impl->AddAnimation(std::move(animation)); | 1816 player_impl_->AddAnimation(std::move(animation)); |
1855 | 1817 |
1856 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f); | 1818 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f); |
1857 gfx::BoxF bounds; | 1819 gfx::BoxF bounds; |
1858 | 1820 |
1859 EXPECT_TRUE(animations_impl->TransformAnimationBoundsForBox(box, &bounds)); | 1821 EXPECT_TRUE(player_impl_->TransformAnimationBoundsForBox(box, &bounds)); |
1860 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(), | 1822 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(), |
1861 bounds.ToString()); | 1823 bounds.ToString()); |
1862 | 1824 |
1863 animations_impl->GetAnimationById(1)->SetRunState(Animation::FINISHED, | 1825 player_impl_->GetAnimationById(1)->SetRunState(Animation::FINISHED, |
1864 TicksFromSecondsF(0.0)); | 1826 TicksFromSecondsF(0.0)); |
1865 | 1827 |
1866 // Only the unfinished animation should affect the animated bounds. | 1828 // Only the unfinished animation should affect the animated bounds. |
1867 EXPECT_TRUE(animations_impl->TransformAnimationBoundsForBox(box, &bounds)); | 1829 EXPECT_TRUE(player_impl_->TransformAnimationBoundsForBox(box, &bounds)); |
1868 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(), | 1830 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(), |
1869 bounds.ToString()); | 1831 bounds.ToString()); |
1870 | 1832 |
1871 animations_impl->GetAnimationById(2)->SetRunState(Animation::FINISHED, | 1833 player_impl_->GetAnimationById(2)->SetRunState(Animation::FINISHED, |
1872 TicksFromSecondsF(0.0)); | 1834 TicksFromSecondsF(0.0)); |
1873 | 1835 |
1874 // There are no longer any running animations. | 1836 // There are no longer any running animations. |
1875 EXPECT_FALSE(animations_impl->HasTransformAnimationThatInflatesBounds()); | 1837 EXPECT_FALSE(player_impl_->HasTransformAnimationThatInflatesBounds()); |
1876 | 1838 |
1877 // Add an animation whose bounds we don't yet support computing. | 1839 // Add an animation whose bounds we don't yet support computing. |
1878 std::unique_ptr<KeyframedTransformAnimationCurve> curve3( | 1840 std::unique_ptr<KeyframedTransformAnimationCurve> curve3( |
1879 KeyframedTransformAnimationCurve::Create()); | 1841 KeyframedTransformAnimationCurve::Create()); |
1880 TransformOperations operations3; | 1842 TransformOperations operations3; |
1881 gfx::Transform transform3; | 1843 gfx::Transform transform3; |
1882 transform3.Scale3d(1.0, 2.0, 3.0); | 1844 transform3.Scale3d(1.0, 2.0, 3.0); |
1883 curve3->AddKeyframe( | 1845 curve3->AddKeyframe( |
1884 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); | 1846 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); |
1885 operations3.AppendMatrix(transform3); | 1847 operations3.AppendMatrix(transform3); |
1886 curve3->AddKeyframe(TransformKeyframe::Create( | 1848 curve3->AddKeyframe(TransformKeyframe::Create( |
1887 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); | 1849 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); |
1888 animation = | 1850 animation = |
1889 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM); | 1851 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM); |
1890 animations_impl->AddAnimation(std::move(animation)); | 1852 player_impl_->AddAnimation(std::move(animation)); |
1891 EXPECT_FALSE(animations_impl->TransformAnimationBoundsForBox(box, &bounds)); | 1853 EXPECT_FALSE(player_impl_->TransformAnimationBoundsForBox(box, &bounds)); |
1892 } | 1854 } |
1893 | 1855 |
1894 // Tests that AbortAnimations aborts all animations targeting the specified | 1856 // Tests that AbortAnimations aborts all animations targeting the specified |
1895 // property. | 1857 // property. |
1896 TEST_F(ElementAnimationsTest, AbortAnimations) { | 1858 TEST_F(ElementAnimationsTest, AbortAnimations) { |
1897 CreateTestLayer(false, false); | 1859 CreateTestLayer(false, false); |
1898 AttachTimelinePlayerLayer(); | 1860 AttachTimelinePlayerLayer(); |
1899 | 1861 |
1900 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1901 | |
1902 // Start with several animations, and allow some of them to reach the finished | 1862 // Start with several animations, and allow some of them to reach the finished |
1903 // state. | 1863 // state. |
1904 animations->AddAnimation(Animation::Create( | 1864 player_->AddAnimation(Animation::Create( |
1905 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, 1, | 1865 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, 1, |
1906 TargetProperty::TRANSFORM)); | 1866 TargetProperty::TRANSFORM)); |
1907 animations->AddAnimation(Animation::Create( | 1867 player_->AddAnimation(Animation::Create( |
1908 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1868 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1909 2, 2, TargetProperty::OPACITY)); | 1869 2, 2, TargetProperty::OPACITY)); |
1910 animations->AddAnimation(Animation::Create( | 1870 player_->AddAnimation(Animation::Create( |
1911 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 3, 3, | 1871 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 3, 3, |
1912 TargetProperty::TRANSFORM)); | 1872 TargetProperty::TRANSFORM)); |
1913 animations->AddAnimation(Animation::Create( | 1873 player_->AddAnimation(Animation::Create( |
1914 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 4, 4, | 1874 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 4, 4, |
1915 TargetProperty::TRANSFORM)); | 1875 TargetProperty::TRANSFORM)); |
1916 animations->AddAnimation(Animation::Create( | 1876 player_->AddAnimation(Animation::Create( |
1917 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1877 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1918 5, 5, TargetProperty::OPACITY)); | 1878 5, 5, TargetProperty::OPACITY)); |
1919 | 1879 |
1920 animations->Animate(kInitialTickTime); | 1880 element_animations_->Animate(kInitialTickTime); |
1921 animations->UpdateState(true, nullptr); | 1881 element_animations_->UpdateState(true, nullptr); |
1922 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1882 element_animations_->Animate(kInitialTickTime + |
1923 animations->UpdateState(true, nullptr); | 1883 TimeDelta::FromMilliseconds(1000)); |
| 1884 element_animations_->UpdateState(true, nullptr); |
1924 | 1885 |
1925 EXPECT_EQ(Animation::FINISHED, animations->GetAnimationById(1)->run_state()); | 1886 EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(1)->run_state()); |
1926 EXPECT_EQ(Animation::FINISHED, animations->GetAnimationById(2)->run_state()); | 1887 EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(2)->run_state()); |
1927 EXPECT_EQ(Animation::RUNNING, animations->GetAnimationById(3)->run_state()); | 1888 EXPECT_EQ(Animation::RUNNING, player_->GetAnimationById(3)->run_state()); |
1928 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 1889 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
1929 animations->GetAnimationById(4)->run_state()); | 1890 player_->GetAnimationById(4)->run_state()); |
1930 EXPECT_EQ(Animation::RUNNING, animations->GetAnimationById(5)->run_state()); | 1891 EXPECT_EQ(Animation::RUNNING, player_->GetAnimationById(5)->run_state()); |
1931 | 1892 |
1932 animations->AbortAnimations(TargetProperty::TRANSFORM); | 1893 player_->AbortAnimations(TargetProperty::TRANSFORM, false); |
1933 | 1894 |
1934 // Only un-finished TRANSFORM animations should have been aborted. | 1895 // Only un-finished TRANSFORM animations should have been aborted. |
1935 EXPECT_EQ(Animation::FINISHED, animations->GetAnimationById(1)->run_state()); | 1896 EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(1)->run_state()); |
1936 EXPECT_EQ(Animation::FINISHED, animations->GetAnimationById(2)->run_state()); | 1897 EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(2)->run_state()); |
1937 EXPECT_EQ(Animation::ABORTED, animations->GetAnimationById(3)->run_state()); | 1898 EXPECT_EQ(Animation::ABORTED, player_->GetAnimationById(3)->run_state()); |
1938 EXPECT_EQ(Animation::ABORTED, animations->GetAnimationById(4)->run_state()); | 1899 EXPECT_EQ(Animation::ABORTED, player_->GetAnimationById(4)->run_state()); |
1939 EXPECT_EQ(Animation::RUNNING, animations->GetAnimationById(5)->run_state()); | 1900 EXPECT_EQ(Animation::RUNNING, player_->GetAnimationById(5)->run_state()); |
1940 } | 1901 } |
1941 | 1902 |
1942 // An animation aborted on the main thread should get deleted on both threads. | 1903 // An animation aborted on the main thread should get deleted on both threads. |
1943 TEST_F(ElementAnimationsTest, MainThreadAbortedAnimationGetsDeleted) { | 1904 TEST_F(ElementAnimationsTest, MainThreadAbortedAnimationGetsDeleted) { |
1944 CreateTestLayer(true, false); | 1905 CreateTestLayer(true, false); |
1945 AttachTimelinePlayerLayer(); | 1906 AttachTimelinePlayerLayer(); |
1946 CreateImplTimelineAndPlayer(); | 1907 CreateImplTimelineAndPlayer(); |
1947 | 1908 |
1948 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1949 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
1950 | |
1951 int animation_id = | 1909 int animation_id = |
1952 AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.f, 1.f, false); | 1910 AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.f, 1.f, false); |
1953 EXPECT_TRUE(host_->needs_push_properties()); | 1911 EXPECT_TRUE(host_->needs_push_properties()); |
1954 | 1912 |
1955 PushProperties(); | 1913 PushProperties(); |
1956 | 1914 |
1957 animations_impl->ActivateAnimations(); | 1915 player_impl_->ActivateAnimations(); |
1958 | 1916 |
1959 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 1917 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
1960 EXPECT_FALSE(host_->needs_push_properties()); | 1918 EXPECT_FALSE(host_->needs_push_properties()); |
1961 | 1919 |
1962 animations->AbortAnimations(TargetProperty::OPACITY); | 1920 player_->AbortAnimations(TargetProperty::OPACITY, false); |
1963 EXPECT_EQ(Animation::ABORTED, | 1921 EXPECT_EQ(Animation::ABORTED, |
1964 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1922 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
1965 EXPECT_TRUE(host_->needs_push_properties()); | 1923 EXPECT_TRUE(host_->needs_push_properties()); |
1966 | 1924 |
1967 animations->Animate(kInitialTickTime); | 1925 element_animations_->Animate(kInitialTickTime); |
1968 animations->UpdateState(true, nullptr); | 1926 element_animations_->UpdateState(true, nullptr); |
1969 EXPECT_EQ(Animation::ABORTED, | 1927 EXPECT_EQ(Animation::ABORTED, |
1970 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1928 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
1971 | 1929 |
1972 EXPECT_TRUE(animations->needs_push_properties()); | 1930 EXPECT_TRUE(player_->needs_push_properties()); |
1973 EXPECT_TRUE(player_->needs_push_properties()); | 1931 EXPECT_TRUE(player_->needs_push_properties()); |
1974 EXPECT_TRUE(host_->needs_push_properties()); | 1932 EXPECT_TRUE(host_->needs_push_properties()); |
1975 | 1933 |
1976 PushProperties(); | 1934 PushProperties(); |
1977 EXPECT_FALSE(host_->needs_push_properties()); | 1935 EXPECT_FALSE(host_->needs_push_properties()); |
1978 EXPECT_FALSE(player_->needs_push_properties()); | 1936 EXPECT_FALSE(player_->needs_push_properties()); |
1979 | 1937 |
1980 EXPECT_FALSE(animations->GetAnimationById(animation_id)); | 1938 EXPECT_FALSE(player_->GetAnimationById(animation_id)); |
1981 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id)); | 1939 EXPECT_FALSE(player_impl_->GetAnimationById(animation_id)); |
1982 } | 1940 } |
1983 | 1941 |
1984 // An animation aborted on the impl thread should get deleted on both threads. | 1942 // An animation aborted on the impl thread should get deleted on both threads. |
1985 TEST_F(ElementAnimationsTest, ImplThreadAbortedAnimationGetsDeleted) { | 1943 TEST_F(ElementAnimationsTest, ImplThreadAbortedAnimationGetsDeleted) { |
1986 CreateTestLayer(true, false); | 1944 CreateTestLayer(true, false); |
1987 AttachTimelinePlayerLayer(); | 1945 AttachTimelinePlayerLayer(); |
1988 CreateImplTimelineAndPlayer(); | 1946 CreateImplTimelineAndPlayer(); |
1989 | 1947 |
1990 scoped_refptr<ElementAnimations> animations = element_animations(); | |
1991 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
1992 | |
1993 TestAnimationDelegate delegate; | 1948 TestAnimationDelegate delegate; |
1994 player_->set_animation_delegate(&delegate); | 1949 player_->set_animation_delegate(&delegate); |
1995 | 1950 |
1996 int animation_id = AddOpacityTransitionToElementAnimations( | 1951 int animation_id = |
1997 animations.get(), 1.0, 0.f, 1.f, false); | 1952 AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.f, 1.f, false); |
1998 | 1953 |
1999 PushProperties(); | 1954 PushProperties(); |
2000 EXPECT_FALSE(host_->needs_push_properties()); | 1955 EXPECT_FALSE(host_->needs_push_properties()); |
2001 | 1956 |
2002 animations_impl->ActivateAnimations(); | 1957 player_impl_->ActivateAnimations(); |
2003 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 1958 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
2004 | 1959 |
2005 animations_impl->AbortAnimations(TargetProperty::OPACITY); | 1960 player_impl_->AbortAnimations(TargetProperty::OPACITY, false); |
2006 EXPECT_EQ( | 1961 EXPECT_EQ(Animation::ABORTED, |
2007 Animation::ABORTED, | 1962 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
2008 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
2009 EXPECT_TRUE(host_impl_->needs_push_properties()); | 1963 EXPECT_TRUE(host_impl_->needs_push_properties()); |
2010 EXPECT_TRUE(player_impl_->needs_push_properties()); | 1964 EXPECT_TRUE(player_impl_->needs_push_properties()); |
2011 | 1965 |
2012 auto events = host_impl_->CreateEvents(); | 1966 auto events = host_impl_->CreateEvents(); |
2013 animations_impl->Animate(kInitialTickTime); | 1967 element_animations_impl_->Animate(kInitialTickTime); |
2014 animations_impl->UpdateState(true, events.get()); | 1968 element_animations_impl_->UpdateState(true, events.get()); |
2015 EXPECT_TRUE(host_impl_->needs_push_properties()); | 1969 EXPECT_TRUE(host_impl_->needs_push_properties()); |
2016 EXPECT_EQ(1u, events->events_.size()); | 1970 EXPECT_EQ(1u, events->events_.size()); |
2017 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[0].type); | 1971 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[0].type); |
2018 EXPECT_EQ( | 1972 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
2019 Animation::WAITING_FOR_DELETION, | 1973 player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
2020 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); | |
2021 | 1974 |
2022 animations->NotifyAnimationAborted(events->events_[0]); | 1975 player_->NotifyAnimationAborted(events->events_[0]); |
2023 EXPECT_EQ(Animation::ABORTED, | 1976 EXPECT_EQ(Animation::ABORTED, |
2024 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1977 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
2025 EXPECT_TRUE(delegate.aborted()); | 1978 EXPECT_TRUE(delegate.aborted()); |
2026 | 1979 |
2027 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1980 element_animations_->Animate(kInitialTickTime + |
2028 animations->UpdateState(true, nullptr); | 1981 TimeDelta::FromMilliseconds(500)); |
| 1982 element_animations_->UpdateState(true, nullptr); |
2029 EXPECT_TRUE(host_->needs_push_properties()); | 1983 EXPECT_TRUE(host_->needs_push_properties()); |
2030 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | 1984 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
2031 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1985 player_->GetAnimation(TargetProperty::OPACITY)->run_state()); |
2032 | 1986 |
2033 PushProperties(); | 1987 PushProperties(); |
2034 | 1988 |
2035 animations_impl->ActivateAnimations(); | 1989 player_impl_->ActivateAnimations(); |
2036 EXPECT_FALSE(animations->GetAnimationById(animation_id)); | 1990 EXPECT_FALSE(player_->GetAnimationById(animation_id)); |
2037 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id)); | 1991 EXPECT_FALSE(player_impl_->GetAnimationById(animation_id)); |
2038 } | 1992 } |
2039 | 1993 |
2040 // Test that an impl-only scroll offset animation that needs to be completed on | 1994 // Test that an impl-only scroll offset animation that needs to be completed on |
2041 // the main thread gets deleted. | 1995 // the main thread gets deleted. |
2042 TEST_F(ElementAnimationsTest, ImplThreadTakeoverAnimationGetsDeleted) { | 1996 TEST_F(ElementAnimationsTest, ImplThreadTakeoverAnimationGetsDeleted) { |
2043 CreateTestLayer(true, false); | 1997 CreateTestLayer(true, false); |
2044 AttachTimelinePlayerLayer(); | 1998 AttachTimelinePlayerLayer(); |
2045 CreateImplTimelineAndPlayer(); | 1999 CreateImplTimelineAndPlayer(); |
2046 | 2000 |
2047 scoped_refptr<ElementAnimations> animations = element_animations(); | |
2048 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
2049 | |
2050 TestAnimationDelegate delegate_impl; | 2001 TestAnimationDelegate delegate_impl; |
2051 player_impl_->set_animation_delegate(&delegate_impl); | 2002 player_impl_->set_animation_delegate(&delegate_impl); |
2052 TestAnimationDelegate delegate; | 2003 TestAnimationDelegate delegate; |
2053 player_->set_animation_delegate(&delegate); | 2004 player_->set_animation_delegate(&delegate); |
2054 | 2005 |
2055 // Add impl-only scroll offset animation. | 2006 // Add impl-only scroll offset animation. |
2056 const int animation_id = 1; | 2007 const int animation_id = 1; |
2057 gfx::ScrollOffset initial_value(100.f, 300.f); | 2008 gfx::ScrollOffset initial_value(100.f, 300.f); |
2058 gfx::ScrollOffset target_value(300.f, 200.f); | 2009 gfx::ScrollOffset target_value(300.f, 200.f); |
2059 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 2010 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
2060 ScrollOffsetAnimationCurve::Create( | 2011 ScrollOffsetAnimationCurve::Create( |
2061 target_value, CubicBezierTimingFunction::CreatePreset( | 2012 target_value, CubicBezierTimingFunction::CreatePreset( |
2062 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); | 2013 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); |
2063 curve->SetInitialValue(initial_value); | 2014 curve->SetInitialValue(initial_value); |
2064 std::unique_ptr<Animation> animation(Animation::Create( | 2015 std::unique_ptr<Animation> animation(Animation::Create( |
2065 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET)); | 2016 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET)); |
2066 animation->set_start_time(TicksFromSecondsF(123)); | 2017 animation->set_start_time(TicksFromSecondsF(123)); |
2067 animation->set_is_impl_only(true); | 2018 animation->set_is_impl_only(true); |
2068 animations_impl->AddAnimation(std::move(animation)); | 2019 player_impl_->AddAnimation(std::move(animation)); |
2069 | 2020 |
2070 PushProperties(); | 2021 PushProperties(); |
2071 EXPECT_FALSE(host_->needs_push_properties()); | 2022 EXPECT_FALSE(host_->needs_push_properties()); |
2072 | 2023 |
2073 animations_impl->ActivateAnimations(); | 2024 player_impl_->ActivateAnimations(); |
2074 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 2025 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
2075 | 2026 |
2076 const bool needs_completion = true; | 2027 player_impl_->AbortAnimations(TargetProperty::SCROLL_OFFSET, true); |
2077 animations_impl->AbortAnimations(TargetProperty::SCROLL_OFFSET, | |
2078 needs_completion); | |
2079 EXPECT_TRUE(host_impl_->needs_push_properties()); | 2028 EXPECT_TRUE(host_impl_->needs_push_properties()); |
2080 EXPECT_EQ(Animation::ABORTED_BUT_NEEDS_COMPLETION, | 2029 EXPECT_EQ( |
2081 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 2030 Animation::ABORTED_BUT_NEEDS_COMPLETION, |
2082 ->run_state()); | 2031 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); |
2083 | 2032 |
2084 auto events = host_impl_->CreateEvents(); | 2033 auto events = host_impl_->CreateEvents(); |
2085 animations_impl->Animate(kInitialTickTime); | 2034 element_animations_impl_->Animate(kInitialTickTime); |
2086 animations_impl->UpdateState(true, events.get()); | 2035 element_animations_impl_->UpdateState(true, events.get()); |
2087 EXPECT_TRUE(delegate_impl.finished()); | 2036 EXPECT_TRUE(delegate_impl.finished()); |
2088 EXPECT_TRUE(host_impl_->needs_push_properties()); | 2037 EXPECT_TRUE(host_impl_->needs_push_properties()); |
2089 EXPECT_EQ(1u, events->events_.size()); | 2038 EXPECT_EQ(1u, events->events_.size()); |
2090 EXPECT_EQ(AnimationEvent::TAKEOVER, events->events_[0].type); | 2039 EXPECT_EQ(AnimationEvent::TAKEOVER, events->events_[0].type); |
2091 EXPECT_EQ(123, events->events_[0].animation_start_time); | 2040 EXPECT_EQ(123, events->events_[0].animation_start_time); |
2092 EXPECT_EQ( | 2041 EXPECT_EQ( |
2093 target_value, | 2042 target_value, |
2094 events->events_[0].curve->ToScrollOffsetAnimationCurve()->target_value()); | 2043 events->events_[0].curve->ToScrollOffsetAnimationCurve()->target_value()); |
2095 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | 2044 EXPECT_EQ( |
2096 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | 2045 Animation::WAITING_FOR_DELETION, |
2097 ->run_state()); | 2046 player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET)->run_state()); |
2098 | 2047 |
2099 // MT receives the event to take over. | 2048 // MT receives the event to take over. |
2100 animations->NotifyAnimationTakeover(events->events_[0]); | 2049 player_->NotifyAnimationTakeover(events->events_[0]); |
2101 EXPECT_TRUE(delegate.takeover()); | 2050 EXPECT_TRUE(delegate.takeover()); |
2102 | 2051 |
2103 // AnimationPlayer::NotifyAnimationTakeover requests SetNeedsPushProperties | 2052 // AnimationPlayer::NotifyAnimationTakeover requests SetNeedsPushProperties |
2104 // to purge CT animations marked for deletion. | 2053 // to purge CT animations marked for deletion. |
2105 EXPECT_TRUE(animations->needs_push_properties()); | 2054 EXPECT_TRUE(player_->needs_push_properties()); |
2106 | 2055 |
2107 // ElementAnimations::PurgeAnimationsMarkedForDeletion call happens only in | 2056 // ElementAnimations::PurgeAnimationsMarkedForDeletion call happens only in |
2108 // ElementAnimations::PushPropertiesTo. | 2057 // ElementAnimations::PushPropertiesTo. |
2109 PushProperties(); | 2058 PushProperties(); |
2110 | 2059 |
2111 animations_impl->ActivateAnimations(); | 2060 player_impl_->ActivateAnimations(); |
2112 EXPECT_FALSE(animations->GetAnimationById(animation_id)); | 2061 EXPECT_FALSE(player_->GetAnimationById(animation_id)); |
2113 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id)); | 2062 EXPECT_FALSE(player_impl_->GetAnimationById(animation_id)); |
2114 } | 2063 } |
2115 | 2064 |
2116 // Ensure that we only generate FINISHED events for animations in a group | 2065 // Ensure that we only generate FINISHED events for animations in a group |
2117 // once all animations in that group are finished. | 2066 // once all animations in that group are finished. |
2118 TEST_F(ElementAnimationsTest, FinishedEventsForGroup) { | 2067 TEST_F(ElementAnimationsTest, FinishedEventsForGroup) { |
2119 CreateTestLayer(true, false); | 2068 CreateTestLayer(true, false); |
2120 AttachTimelinePlayerLayer(); | 2069 AttachTimelinePlayerLayer(); |
2121 CreateImplTimelineAndPlayer(); | 2070 CreateImplTimelineAndPlayer(); |
2122 | 2071 |
2123 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
2124 | |
2125 auto events = host_impl_->CreateEvents(); | 2072 auto events = host_impl_->CreateEvents(); |
2126 | 2073 |
2127 const int group_id = 1; | 2074 const int group_id = 1; |
2128 | 2075 |
2129 // Add two animations with the same group id but different durations. | 2076 // Add two animations with the same group id but different durations. |
2130 std::unique_ptr<Animation> first_animation(Animation::Create( | 2077 std::unique_ptr<Animation> first_animation(Animation::Create( |
2131 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1, | 2078 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2.0)), 1, |
2132 group_id, TargetProperty::TRANSFORM)); | 2079 group_id, TargetProperty::TRANSFORM)); |
2133 first_animation->set_is_controlling_instance_for_test(true); | 2080 first_animation->set_is_controlling_instance_for_test(true); |
2134 animations_impl->AddAnimation(std::move(first_animation)); | 2081 player_impl_->AddAnimation(std::move(first_animation)); |
2135 | 2082 |
2136 std::unique_ptr<Animation> second_animation(Animation::Create( | 2083 std::unique_ptr<Animation> second_animation(Animation::Create( |
2137 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 2084 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
2138 2, group_id, TargetProperty::OPACITY)); | 2085 2, group_id, TargetProperty::OPACITY)); |
2139 second_animation->set_is_controlling_instance_for_test(true); | 2086 second_animation->set_is_controlling_instance_for_test(true); |
2140 animations_impl->AddAnimation(std::move(second_animation)); | 2087 player_impl_->AddAnimation(std::move(second_animation)); |
2141 | 2088 |
2142 animations_impl->Animate(kInitialTickTime); | 2089 element_animations_impl_->Animate(kInitialTickTime); |
2143 animations_impl->UpdateState(true, events.get()); | 2090 element_animations_impl_->UpdateState(true, events.get()); |
2144 | 2091 |
2145 // Both animations should have started. | 2092 // Both animations should have started. |
2146 EXPECT_EQ(2u, events->events_.size()); | 2093 EXPECT_EQ(2u, events->events_.size()); |
2147 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); | 2094 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); |
2148 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); | 2095 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); |
2149 | 2096 |
2150 events = host_impl_->CreateEvents(); | 2097 events = host_impl_->CreateEvents(); |
2151 animations_impl->Animate(kInitialTickTime + | 2098 element_animations_impl_->Animate(kInitialTickTime + |
2152 TimeDelta::FromMilliseconds(1000)); | 2099 TimeDelta::FromMilliseconds(1000)); |
2153 animations_impl->UpdateState(true, events.get()); | 2100 element_animations_impl_->UpdateState(true, events.get()); |
2154 | 2101 |
2155 // The opacity animation should be finished, but should not have generated | 2102 // The opacity animation should be finished, but should not have generated |
2156 // a FINISHED event yet. | 2103 // a FINISHED event yet. |
2157 EXPECT_EQ(0u, events->events_.size()); | 2104 EXPECT_EQ(0u, events->events_.size()); |
2158 EXPECT_EQ(Animation::FINISHED, | 2105 EXPECT_EQ(Animation::FINISHED, |
2159 animations_impl->GetAnimationById(2)->run_state()); | 2106 player_impl_->GetAnimationById(2)->run_state()); |
2160 EXPECT_EQ(Animation::RUNNING, | 2107 EXPECT_EQ(Animation::RUNNING, player_impl_->GetAnimationById(1)->run_state()); |
2161 animations_impl->GetAnimationById(1)->run_state()); | |
2162 | 2108 |
2163 animations_impl->Animate(kInitialTickTime + | 2109 element_animations_impl_->Animate(kInitialTickTime + |
2164 TimeDelta::FromMilliseconds(2000)); | 2110 TimeDelta::FromMilliseconds(2000)); |
2165 animations_impl->UpdateState(true, events.get()); | 2111 element_animations_impl_->UpdateState(true, events.get()); |
2166 | 2112 |
2167 // Both animations should have generated FINISHED events. | 2113 // Both animations should have generated FINISHED events. |
2168 EXPECT_EQ(2u, events->events_.size()); | 2114 EXPECT_EQ(2u, events->events_.size()); |
2169 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); | 2115 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); |
2170 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[1].type); | 2116 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[1].type); |
2171 } | 2117 } |
2172 | 2118 |
2173 // Ensure that when a group has a mix of aborted and finished animations, | 2119 // Ensure that when a group has a mix of aborted and finished animations, |
2174 // we generate a FINISHED event for the finished animation and an ABORTED | 2120 // we generate a FINISHED event for the finished animation and an ABORTED |
2175 // event for the aborted animation. | 2121 // event for the aborted animation. |
2176 TEST_F(ElementAnimationsTest, FinishedAndAbortedEventsForGroup) { | 2122 TEST_F(ElementAnimationsTest, FinishedAndAbortedEventsForGroup) { |
2177 CreateTestLayer(true, false); | 2123 CreateTestLayer(true, false); |
2178 AttachTimelinePlayerLayer(); | 2124 AttachTimelinePlayerLayer(); |
2179 CreateImplTimelineAndPlayer(); | 2125 CreateImplTimelineAndPlayer(); |
2180 | 2126 |
2181 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
2182 | |
2183 auto events = host_impl_->CreateEvents(); | 2127 auto events = host_impl_->CreateEvents(); |
2184 | 2128 |
2185 // Add two animations with the same group id. | 2129 // Add two animations with the same group id. |
2186 std::unique_ptr<Animation> first_animation(CreateAnimation( | 2130 std::unique_ptr<Animation> first_animation(CreateAnimation( |
2187 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, | 2131 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 1, |
2188 TargetProperty::TRANSFORM)); | 2132 TargetProperty::TRANSFORM)); |
2189 first_animation->set_is_controlling_instance_for_test(true); | 2133 first_animation->set_is_controlling_instance_for_test(true); |
2190 animations_impl->AddAnimation(std::move(first_animation)); | 2134 player_impl_->AddAnimation(std::move(first_animation)); |
2191 | 2135 |
2192 std::unique_ptr<Animation> second_animation(CreateAnimation( | 2136 std::unique_ptr<Animation> second_animation(CreateAnimation( |
2193 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 2137 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
2194 1, TargetProperty::OPACITY)); | 2138 1, TargetProperty::OPACITY)); |
2195 second_animation->set_is_controlling_instance_for_test(true); | 2139 second_animation->set_is_controlling_instance_for_test(true); |
2196 animations_impl->AddAnimation(std::move(second_animation)); | 2140 player_impl_->AddAnimation(std::move(second_animation)); |
2197 | 2141 |
2198 animations_impl->Animate(kInitialTickTime); | 2142 element_animations_impl_->Animate(kInitialTickTime); |
2199 animations_impl->UpdateState(true, events.get()); | 2143 element_animations_impl_->UpdateState(true, events.get()); |
2200 | 2144 |
2201 // Both animations should have started. | 2145 // Both animations should have started. |
2202 EXPECT_EQ(2u, events->events_.size()); | 2146 EXPECT_EQ(2u, events->events_.size()); |
2203 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); | 2147 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); |
2204 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); | 2148 EXPECT_EQ(AnimationEvent::STARTED, events->events_[1].type); |
2205 | 2149 |
2206 animations_impl->AbortAnimations(TargetProperty::OPACITY); | 2150 player_impl_->AbortAnimations(TargetProperty::OPACITY, false); |
2207 | 2151 |
2208 events = host_impl_->CreateEvents(); | 2152 events = host_impl_->CreateEvents(); |
2209 animations_impl->Animate(kInitialTickTime + | 2153 element_animations_impl_->Animate(kInitialTickTime + |
2210 TimeDelta::FromMilliseconds(1000)); | 2154 TimeDelta::FromMilliseconds(1000)); |
2211 animations_impl->UpdateState(true, events.get()); | 2155 element_animations_impl_->UpdateState(true, events.get()); |
2212 | 2156 |
2213 // We should have exactly 2 events: a FINISHED event for the tranform | 2157 // We should have exactly 2 events: a FINISHED event for the tranform |
2214 // animation, and an ABORTED event for the opacity animation. | 2158 // animation, and an ABORTED event for the opacity animation. |
2215 EXPECT_EQ(2u, events->events_.size()); | 2159 EXPECT_EQ(2u, events->events_.size()); |
2216 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); | 2160 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); |
2217 EXPECT_EQ(TargetProperty::TRANSFORM, events->events_[0].target_property); | 2161 EXPECT_EQ(TargetProperty::TRANSFORM, events->events_[0].target_property); |
2218 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[1].type); | 2162 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[1].type); |
2219 EXPECT_EQ(TargetProperty::OPACITY, events->events_[1].target_property); | 2163 EXPECT_EQ(TargetProperty::OPACITY, events->events_[1].target_property); |
2220 } | 2164 } |
2221 | 2165 |
2222 TEST_F(ElementAnimationsTest, HasOnlyTranslationTransforms) { | 2166 TEST_F(ElementAnimationsTest, HasOnlyTranslationTransforms) { |
2223 CreateTestLayer(true, false); | 2167 CreateTestLayer(true, false); |
2224 AttachTimelinePlayerLayer(); | 2168 AttachTimelinePlayerLayer(); |
2225 CreateImplTimelineAndPlayer(); | 2169 CreateImplTimelineAndPlayer(); |
2226 | 2170 |
2227 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 2171 EXPECT_TRUE( |
| 2172 player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); |
| 2173 EXPECT_TRUE( |
| 2174 player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING)); |
2228 | 2175 |
2229 EXPECT_TRUE( | 2176 player_impl_->AddAnimation(CreateAnimation( |
2230 animations_impl->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); | |
2231 EXPECT_TRUE( | |
2232 animations_impl->HasOnlyTranslationTransforms(ElementListType::PENDING)); | |
2233 | |
2234 animations_impl->AddAnimation(CreateAnimation( | |
2235 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 2177 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
2236 1, TargetProperty::OPACITY)); | 2178 1, TargetProperty::OPACITY)); |
2237 | 2179 |
2238 // Opacity animations aren't non-translation transforms. | 2180 // Opacity animations aren't non-translation transforms. |
2239 EXPECT_TRUE( | 2181 EXPECT_TRUE( |
2240 animations_impl->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); | 2182 player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); |
2241 EXPECT_TRUE( | 2183 EXPECT_TRUE( |
2242 animations_impl->HasOnlyTranslationTransforms(ElementListType::PENDING)); | 2184 player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING)); |
2243 | 2185 |
2244 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | 2186 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( |
2245 KeyframedTransformAnimationCurve::Create()); | 2187 KeyframedTransformAnimationCurve::Create()); |
2246 | 2188 |
2247 TransformOperations operations1; | 2189 TransformOperations operations1; |
2248 curve1->AddKeyframe( | 2190 curve1->AddKeyframe( |
2249 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 2191 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
2250 operations1.AppendTranslate(10.0, 15.0, 0.0); | 2192 operations1.AppendTranslate(10.0, 15.0, 0.0); |
2251 curve1->AddKeyframe(TransformKeyframe::Create( | 2193 curve1->AddKeyframe(TransformKeyframe::Create( |
2252 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | 2194 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); |
2253 | 2195 |
2254 std::unique_ptr<Animation> animation( | 2196 std::unique_ptr<Animation> animation( |
2255 Animation::Create(std::move(curve1), 2, 2, TargetProperty::TRANSFORM)); | 2197 Animation::Create(std::move(curve1), 2, 2, TargetProperty::TRANSFORM)); |
2256 animations_impl->AddAnimation(std::move(animation)); | 2198 player_impl_->AddAnimation(std::move(animation)); |
2257 | 2199 |
2258 // The only transform animation we've added is a translation. | 2200 // The only transform animation we've added is a translation. |
2259 EXPECT_TRUE( | 2201 EXPECT_TRUE( |
2260 animations_impl->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); | 2202 player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); |
2261 EXPECT_TRUE( | 2203 EXPECT_TRUE( |
2262 animations_impl->HasOnlyTranslationTransforms(ElementListType::PENDING)); | 2204 player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING)); |
2263 | 2205 |
2264 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( | 2206 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( |
2265 KeyframedTransformAnimationCurve::Create()); | 2207 KeyframedTransformAnimationCurve::Create()); |
2266 | 2208 |
2267 TransformOperations operations2; | 2209 TransformOperations operations2; |
2268 curve2->AddKeyframe( | 2210 curve2->AddKeyframe( |
2269 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | 2211 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); |
2270 operations2.AppendScale(2.0, 3.0, 4.0); | 2212 operations2.AppendScale(2.0, 3.0, 4.0); |
2271 curve2->AddKeyframe(TransformKeyframe::Create( | 2213 curve2->AddKeyframe(TransformKeyframe::Create( |
2272 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 2214 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
2273 | 2215 |
2274 animation = | 2216 animation = |
2275 Animation::Create(std::move(curve2), 3, 3, TargetProperty::TRANSFORM); | 2217 Animation::Create(std::move(curve2), 3, 3, TargetProperty::TRANSFORM); |
2276 animation->set_affects_active_elements(false); | 2218 animation->set_affects_active_elements(false); |
2277 animations_impl->AddAnimation(std::move(animation)); | 2219 player_impl_->AddAnimation(std::move(animation)); |
2278 | 2220 |
2279 // A scale animation is not a translation. | 2221 // A scale animation is not a translation. |
2280 EXPECT_FALSE( | 2222 EXPECT_FALSE( |
2281 animations_impl->HasOnlyTranslationTransforms(ElementListType::PENDING)); | 2223 player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING)); |
2282 EXPECT_TRUE( | 2224 EXPECT_TRUE( |
2283 animations_impl->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); | 2225 player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); |
2284 | 2226 |
2285 animations_impl->ActivateAnimations(); | 2227 player_impl_->ActivateAnimations(); |
2286 EXPECT_FALSE( | 2228 EXPECT_FALSE( |
2287 animations_impl->HasOnlyTranslationTransforms(ElementListType::PENDING)); | 2229 player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING)); |
2288 EXPECT_FALSE( | 2230 EXPECT_FALSE( |
2289 animations_impl->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); | 2231 player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); |
2290 | 2232 |
2291 animations_impl->GetAnimationById(3)->set_affects_pending_elements(false); | 2233 player_impl_->GetAnimationById(3)->set_affects_pending_elements(false); |
2292 EXPECT_TRUE( | 2234 EXPECT_TRUE( |
2293 animations_impl->HasOnlyTranslationTransforms(ElementListType::PENDING)); | 2235 player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING)); |
2294 EXPECT_FALSE( | 2236 EXPECT_FALSE( |
2295 animations_impl->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); | 2237 player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); |
2296 | 2238 |
2297 animations_impl->GetAnimationById(3)->SetRunState(Animation::FINISHED, | 2239 player_impl_->GetAnimationById(3)->SetRunState(Animation::FINISHED, |
2298 TicksFromSecondsF(0.0)); | 2240 TicksFromSecondsF(0.0)); |
2299 | 2241 |
2300 // Only unfinished animations should be considered by | 2242 // Only unfinished animations should be considered by |
2301 // HasOnlyTranslationTransforms. | 2243 // HasOnlyTranslationTransforms. |
2302 EXPECT_TRUE( | 2244 EXPECT_TRUE( |
2303 animations_impl->HasOnlyTranslationTransforms(ElementListType::PENDING)); | 2245 player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING)); |
2304 EXPECT_TRUE( | 2246 EXPECT_TRUE( |
2305 animations_impl->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); | 2247 player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE)); |
2306 } | 2248 } |
2307 | 2249 |
2308 TEST_F(ElementAnimationsTest, AnimationStartScale) { | 2250 TEST_F(ElementAnimationsTest, AnimationStartScale) { |
2309 CreateTestLayer(true, false); | 2251 CreateTestLayer(true, false); |
2310 AttachTimelinePlayerLayer(); | 2252 AttachTimelinePlayerLayer(); |
2311 CreateImplTimelineAndPlayer(); | 2253 CreateImplTimelineAndPlayer(); |
2312 | 2254 |
2313 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
2314 | |
2315 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | 2255 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( |
2316 KeyframedTransformAnimationCurve::Create()); | 2256 KeyframedTransformAnimationCurve::Create()); |
2317 | 2257 |
2318 TransformOperations operations1; | 2258 TransformOperations operations1; |
2319 operations1.AppendScale(2.0, 3.0, 4.0); | 2259 operations1.AppendScale(2.0, 3.0, 4.0); |
2320 curve1->AddKeyframe( | 2260 curve1->AddKeyframe( |
2321 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 2261 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
2322 TransformOperations operations2; | 2262 TransformOperations operations2; |
2323 curve1->AddKeyframe(TransformKeyframe::Create( | 2263 curve1->AddKeyframe(TransformKeyframe::Create( |
2324 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 2264 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
2325 std::unique_ptr<Animation> animation( | 2265 std::unique_ptr<Animation> animation( |
2326 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); | 2266 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); |
2327 animation->set_affects_active_elements(false); | 2267 animation->set_affects_active_elements(false); |
2328 animations_impl->AddAnimation(std::move(animation)); | 2268 player_impl_->AddAnimation(std::move(animation)); |
2329 | 2269 |
2330 float start_scale = 0.f; | 2270 float start_scale = 0.f; |
2331 EXPECT_TRUE(animations_impl->AnimationStartScale(ElementListType::PENDING, | 2271 EXPECT_TRUE(player_impl_->AnimationStartScale(ElementListType::PENDING, |
2332 &start_scale)); | 2272 &start_scale)); |
2333 EXPECT_EQ(4.f, start_scale); | 2273 EXPECT_EQ(4.f, start_scale); |
2334 EXPECT_TRUE(animations_impl->AnimationStartScale(ElementListType::ACTIVE, | 2274 EXPECT_TRUE( |
2335 &start_scale)); | 2275 player_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale)); |
2336 EXPECT_EQ(0.f, start_scale); | 2276 EXPECT_EQ(0.f, start_scale); |
2337 | 2277 |
2338 animations_impl->ActivateAnimations(); | 2278 player_impl_->ActivateAnimations(); |
2339 EXPECT_TRUE(animations_impl->AnimationStartScale(ElementListType::PENDING, | 2279 EXPECT_TRUE(player_impl_->AnimationStartScale(ElementListType::PENDING, |
2340 &start_scale)); | 2280 &start_scale)); |
2341 EXPECT_EQ(4.f, start_scale); | 2281 EXPECT_EQ(4.f, start_scale); |
2342 EXPECT_TRUE(animations_impl->AnimationStartScale(ElementListType::ACTIVE, | 2282 EXPECT_TRUE( |
2343 &start_scale)); | 2283 player_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale)); |
2344 EXPECT_EQ(4.f, start_scale); | 2284 EXPECT_EQ(4.f, start_scale); |
2345 | 2285 |
2346 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( | 2286 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( |
2347 KeyframedTransformAnimationCurve::Create()); | 2287 KeyframedTransformAnimationCurve::Create()); |
2348 | 2288 |
2349 TransformOperations operations3; | 2289 TransformOperations operations3; |
2350 curve2->AddKeyframe( | 2290 curve2->AddKeyframe( |
2351 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); | 2291 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); |
2352 operations3.AppendScale(6.0, 5.0, 4.0); | 2292 operations3.AppendScale(6.0, 5.0, 4.0); |
2353 curve2->AddKeyframe(TransformKeyframe::Create( | 2293 curve2->AddKeyframe(TransformKeyframe::Create( |
2354 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); | 2294 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); |
2355 | 2295 |
2356 animations_impl->RemoveAnimation(1); | 2296 player_impl_->RemoveAnimation(1); |
2357 animation = | 2297 animation = |
2358 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); | 2298 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); |
2359 | 2299 |
2360 // Reverse Direction | 2300 // Reverse Direction |
2361 animation->set_direction(Animation::Direction::REVERSE); | 2301 animation->set_direction(Animation::Direction::REVERSE); |
2362 animation->set_affects_active_elements(false); | 2302 animation->set_affects_active_elements(false); |
2363 animations_impl->AddAnimation(std::move(animation)); | 2303 player_impl_->AddAnimation(std::move(animation)); |
2364 | 2304 |
2365 std::unique_ptr<KeyframedTransformAnimationCurve> curve3( | 2305 std::unique_ptr<KeyframedTransformAnimationCurve> curve3( |
2366 KeyframedTransformAnimationCurve::Create()); | 2306 KeyframedTransformAnimationCurve::Create()); |
2367 | 2307 |
2368 TransformOperations operations4; | 2308 TransformOperations operations4; |
2369 operations4.AppendScale(5.0, 3.0, 1.0); | 2309 operations4.AppendScale(5.0, 3.0, 1.0); |
2370 curve3->AddKeyframe( | 2310 curve3->AddKeyframe( |
2371 TransformKeyframe::Create(base::TimeDelta(), operations4, nullptr)); | 2311 TransformKeyframe::Create(base::TimeDelta(), operations4, nullptr)); |
2372 TransformOperations operations5; | 2312 TransformOperations operations5; |
2373 curve3->AddKeyframe(TransformKeyframe::Create( | 2313 curve3->AddKeyframe(TransformKeyframe::Create( |
2374 base::TimeDelta::FromSecondsD(1.0), operations5, nullptr)); | 2314 base::TimeDelta::FromSecondsD(1.0), operations5, nullptr)); |
2375 | 2315 |
2376 animation = | 2316 animation = |
2377 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM); | 2317 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM); |
2378 animation->set_affects_active_elements(false); | 2318 animation->set_affects_active_elements(false); |
2379 animations_impl->AddAnimation(std::move(animation)); | 2319 player_impl_->AddAnimation(std::move(animation)); |
2380 | 2320 |
2381 EXPECT_TRUE(animations_impl->AnimationStartScale(ElementListType::PENDING, | 2321 EXPECT_TRUE(player_impl_->AnimationStartScale(ElementListType::PENDING, |
2382 &start_scale)); | 2322 &start_scale)); |
2383 EXPECT_EQ(6.f, start_scale); | 2323 EXPECT_EQ(6.f, start_scale); |
2384 EXPECT_TRUE(animations_impl->AnimationStartScale(ElementListType::ACTIVE, | 2324 EXPECT_TRUE( |
2385 &start_scale)); | 2325 player_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale)); |
2386 EXPECT_EQ(0.f, start_scale); | 2326 EXPECT_EQ(0.f, start_scale); |
2387 | 2327 |
2388 animations_impl->ActivateAnimations(); | 2328 player_impl_->ActivateAnimations(); |
2389 EXPECT_TRUE(animations_impl->AnimationStartScale(ElementListType::PENDING, | 2329 EXPECT_TRUE(player_impl_->AnimationStartScale(ElementListType::PENDING, |
2390 &start_scale)); | 2330 &start_scale)); |
2391 EXPECT_EQ(6.f, start_scale); | 2331 EXPECT_EQ(6.f, start_scale); |
2392 EXPECT_TRUE(animations_impl->AnimationStartScale(ElementListType::ACTIVE, | 2332 EXPECT_TRUE( |
2393 &start_scale)); | 2333 player_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale)); |
2394 EXPECT_EQ(6.f, start_scale); | 2334 EXPECT_EQ(6.f, start_scale); |
2395 | 2335 |
2396 animations_impl->GetAnimationById(2)->SetRunState(Animation::FINISHED, | 2336 player_impl_->GetAnimationById(2)->SetRunState(Animation::FINISHED, |
2397 TicksFromSecondsF(0.0)); | 2337 TicksFromSecondsF(0.0)); |
2398 | 2338 |
2399 // Only unfinished animations should be considered by | 2339 // Only unfinished animations should be considered by |
2400 // AnimationStartScale. | 2340 // AnimationStartScale. |
2401 EXPECT_TRUE(animations_impl->AnimationStartScale(ElementListType::PENDING, | 2341 EXPECT_TRUE(player_impl_->AnimationStartScale(ElementListType::PENDING, |
2402 &start_scale)); | 2342 &start_scale)); |
2403 EXPECT_EQ(5.f, start_scale); | 2343 EXPECT_EQ(5.f, start_scale); |
2404 EXPECT_TRUE(animations_impl->AnimationStartScale(ElementListType::ACTIVE, | 2344 EXPECT_TRUE( |
2405 &start_scale)); | 2345 player_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale)); |
2406 EXPECT_EQ(5.f, start_scale); | 2346 EXPECT_EQ(5.f, start_scale); |
2407 } | 2347 } |
2408 | 2348 |
2409 TEST_F(ElementAnimationsTest, MaximumTargetScale) { | 2349 TEST_F(ElementAnimationsTest, MaximumTargetScale) { |
2410 CreateTestLayer(true, false); | 2350 CreateTestLayer(true, false); |
2411 AttachTimelinePlayerLayer(); | 2351 AttachTimelinePlayerLayer(); |
2412 CreateImplTimelineAndPlayer(); | 2352 CreateImplTimelineAndPlayer(); |
2413 | 2353 |
2414 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
2415 | |
2416 float max_scale = 0.f; | 2354 float max_scale = 0.f; |
2417 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2355 EXPECT_TRUE( |
2418 &max_scale)); | 2356 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2419 EXPECT_EQ(0.f, max_scale); | 2357 EXPECT_EQ(0.f, max_scale); |
2420 EXPECT_TRUE( | 2358 EXPECT_TRUE( |
2421 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2359 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2422 EXPECT_EQ(0.f, max_scale); | 2360 EXPECT_EQ(0.f, max_scale); |
2423 | 2361 |
2424 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | 2362 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( |
2425 KeyframedTransformAnimationCurve::Create()); | 2363 KeyframedTransformAnimationCurve::Create()); |
2426 | 2364 |
2427 TransformOperations operations1; | 2365 TransformOperations operations1; |
2428 curve1->AddKeyframe( | 2366 curve1->AddKeyframe( |
2429 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 2367 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
2430 operations1.AppendScale(2.0, 3.0, 4.0); | 2368 operations1.AppendScale(2.0, 3.0, 4.0); |
2431 curve1->AddKeyframe(TransformKeyframe::Create( | 2369 curve1->AddKeyframe(TransformKeyframe::Create( |
2432 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); | 2370 base::TimeDelta::FromSecondsD(1.0), operations1, nullptr)); |
2433 | 2371 |
2434 std::unique_ptr<Animation> animation( | 2372 std::unique_ptr<Animation> animation( |
2435 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); | 2373 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); |
2436 animation->set_affects_active_elements(false); | 2374 animation->set_affects_active_elements(false); |
2437 animations_impl->AddAnimation(std::move(animation)); | 2375 player_impl_->AddAnimation(std::move(animation)); |
2438 | 2376 |
2439 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2377 EXPECT_TRUE( |
2440 &max_scale)); | 2378 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2441 EXPECT_EQ(4.f, max_scale); | 2379 EXPECT_EQ(4.f, max_scale); |
2442 EXPECT_TRUE( | 2380 EXPECT_TRUE( |
2443 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2381 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2444 EXPECT_EQ(0.f, max_scale); | 2382 EXPECT_EQ(0.f, max_scale); |
2445 | 2383 |
2446 animations_impl->ActivateAnimations(); | 2384 player_impl_->ActivateAnimations(); |
2447 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2385 EXPECT_TRUE( |
2448 &max_scale)); | 2386 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2449 EXPECT_EQ(4.f, max_scale); | 2387 EXPECT_EQ(4.f, max_scale); |
2450 EXPECT_TRUE( | 2388 EXPECT_TRUE( |
2451 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2389 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2452 EXPECT_EQ(4.f, max_scale); | 2390 EXPECT_EQ(4.f, max_scale); |
2453 | 2391 |
2454 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( | 2392 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( |
2455 KeyframedTransformAnimationCurve::Create()); | 2393 KeyframedTransformAnimationCurve::Create()); |
2456 | 2394 |
2457 TransformOperations operations2; | 2395 TransformOperations operations2; |
2458 curve2->AddKeyframe( | 2396 curve2->AddKeyframe( |
2459 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); | 2397 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); |
2460 operations2.AppendScale(6.0, 5.0, 4.0); | 2398 operations2.AppendScale(6.0, 5.0, 4.0); |
2461 curve2->AddKeyframe(TransformKeyframe::Create( | 2399 curve2->AddKeyframe(TransformKeyframe::Create( |
2462 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 2400 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
2463 | 2401 |
2464 animation = | 2402 animation = |
2465 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); | 2403 Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM); |
2466 animation->set_affects_active_elements(false); | 2404 animation->set_affects_active_elements(false); |
2467 animations_impl->AddAnimation(std::move(animation)); | 2405 player_impl_->AddAnimation(std::move(animation)); |
2468 | 2406 |
2469 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2407 EXPECT_TRUE( |
2470 &max_scale)); | 2408 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2471 EXPECT_EQ(6.f, max_scale); | 2409 EXPECT_EQ(6.f, max_scale); |
2472 EXPECT_TRUE( | 2410 EXPECT_TRUE( |
2473 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2411 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2474 EXPECT_EQ(4.f, max_scale); | 2412 EXPECT_EQ(4.f, max_scale); |
2475 | 2413 |
2476 animations_impl->ActivateAnimations(); | 2414 player_impl_->ActivateAnimations(); |
2477 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2415 EXPECT_TRUE( |
2478 &max_scale)); | 2416 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2479 EXPECT_EQ(6.f, max_scale); | 2417 EXPECT_EQ(6.f, max_scale); |
2480 EXPECT_TRUE( | 2418 EXPECT_TRUE( |
2481 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2419 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2482 EXPECT_EQ(6.f, max_scale); | 2420 EXPECT_EQ(6.f, max_scale); |
2483 | 2421 |
2484 std::unique_ptr<KeyframedTransformAnimationCurve> curve3( | 2422 std::unique_ptr<KeyframedTransformAnimationCurve> curve3( |
2485 KeyframedTransformAnimationCurve::Create()); | 2423 KeyframedTransformAnimationCurve::Create()); |
2486 | 2424 |
2487 TransformOperations operations3; | 2425 TransformOperations operations3; |
2488 curve3->AddKeyframe( | 2426 curve3->AddKeyframe( |
2489 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); | 2427 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); |
2490 operations3.AppendPerspective(6.0); | 2428 operations3.AppendPerspective(6.0); |
2491 curve3->AddKeyframe(TransformKeyframe::Create( | 2429 curve3->AddKeyframe(TransformKeyframe::Create( |
2492 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); | 2430 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); |
2493 | 2431 |
2494 animation = | 2432 animation = |
2495 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM); | 2433 Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM); |
2496 animation->set_affects_active_elements(false); | 2434 animation->set_affects_active_elements(false); |
2497 animations_impl->AddAnimation(std::move(animation)); | 2435 player_impl_->AddAnimation(std::move(animation)); |
2498 | 2436 |
2499 EXPECT_FALSE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2437 EXPECT_FALSE( |
2500 &max_scale)); | 2438 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2501 EXPECT_TRUE( | 2439 EXPECT_TRUE( |
2502 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2440 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2503 EXPECT_EQ(6.f, max_scale); | 2441 EXPECT_EQ(6.f, max_scale); |
2504 | 2442 |
2505 animations_impl->ActivateAnimations(); | 2443 player_impl_->ActivateAnimations(); |
2506 EXPECT_FALSE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | |
2507 &max_scale)); | |
2508 EXPECT_FALSE( | 2444 EXPECT_FALSE( |
2509 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2445 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
| 2446 EXPECT_FALSE( |
| 2447 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2510 | 2448 |
2511 animations_impl->GetAnimationById(3)->SetRunState(Animation::FINISHED, | 2449 player_impl_->GetAnimationById(3)->SetRunState(Animation::FINISHED, |
2512 TicksFromSecondsF(0.0)); | 2450 TicksFromSecondsF(0.0)); |
2513 animations_impl->GetAnimationById(2)->SetRunState(Animation::FINISHED, | 2451 player_impl_->GetAnimationById(2)->SetRunState(Animation::FINISHED, |
2514 TicksFromSecondsF(0.0)); | 2452 TicksFromSecondsF(0.0)); |
2515 | 2453 |
2516 // Only unfinished animations should be considered by | 2454 // Only unfinished animations should be considered by |
2517 // MaximumTargetScale. | 2455 // MaximumTargetScale. |
2518 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2456 EXPECT_TRUE( |
2519 &max_scale)); | 2457 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2520 EXPECT_EQ(4.f, max_scale); | 2458 EXPECT_EQ(4.f, max_scale); |
2521 EXPECT_TRUE( | 2459 EXPECT_TRUE( |
2522 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2460 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2523 EXPECT_EQ(4.f, max_scale); | 2461 EXPECT_EQ(4.f, max_scale); |
2524 } | 2462 } |
2525 | 2463 |
2526 TEST_F(ElementAnimationsTest, MaximumTargetScaleWithDirection) { | 2464 TEST_F(ElementAnimationsTest, MaximumTargetScaleWithDirection) { |
2527 CreateTestLayer(true, false); | 2465 CreateTestLayer(true, false); |
2528 AttachTimelinePlayerLayer(); | 2466 AttachTimelinePlayerLayer(); |
2529 CreateImplTimelineAndPlayer(); | 2467 CreateImplTimelineAndPlayer(); |
2530 | 2468 |
2531 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
2532 | |
2533 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | 2469 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( |
2534 KeyframedTransformAnimationCurve::Create()); | 2470 KeyframedTransformAnimationCurve::Create()); |
2535 TransformOperations operations1; | 2471 TransformOperations operations1; |
2536 operations1.AppendScale(1.0, 2.0, 3.0); | 2472 operations1.AppendScale(1.0, 2.0, 3.0); |
2537 curve1->AddKeyframe( | 2473 curve1->AddKeyframe( |
2538 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 2474 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
2539 TransformOperations operations2; | 2475 TransformOperations operations2; |
2540 operations2.AppendScale(4.0, 5.0, 6.0); | 2476 operations2.AppendScale(4.0, 5.0, 6.0); |
2541 curve1->AddKeyframe(TransformKeyframe::Create( | 2477 curve1->AddKeyframe(TransformKeyframe::Create( |
2542 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 2478 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
2543 | 2479 |
2544 std::unique_ptr<Animation> animation_owned( | 2480 std::unique_ptr<Animation> animation_owned( |
2545 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); | 2481 Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM)); |
2546 Animation* animation = animation_owned.get(); | 2482 Animation* animation = animation_owned.get(); |
2547 animations_impl->AddAnimation(std::move(animation_owned)); | 2483 player_impl_->AddAnimation(std::move(animation_owned)); |
2548 | 2484 |
2549 float max_scale = 0.f; | 2485 float max_scale = 0.f; |
2550 | 2486 |
2551 EXPECT_GT(animation->playback_rate(), 0.0); | 2487 EXPECT_GT(animation->playback_rate(), 0.0); |
2552 | 2488 |
2553 // NORMAL direction with positive playback rate. | 2489 // NORMAL direction with positive playback rate. |
2554 animation->set_direction(Animation::Direction::NORMAL); | 2490 animation->set_direction(Animation::Direction::NORMAL); |
2555 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2491 EXPECT_TRUE( |
2556 &max_scale)); | 2492 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2557 EXPECT_EQ(6.f, max_scale); | 2493 EXPECT_EQ(6.f, max_scale); |
2558 EXPECT_TRUE( | 2494 EXPECT_TRUE( |
2559 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2495 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2560 EXPECT_EQ(6.f, max_scale); | 2496 EXPECT_EQ(6.f, max_scale); |
2561 | 2497 |
2562 // ALTERNATE direction with positive playback rate. | 2498 // ALTERNATE direction with positive playback rate. |
2563 animation->set_direction(Animation::Direction::ALTERNATE_NORMAL); | 2499 animation->set_direction(Animation::Direction::ALTERNATE_NORMAL); |
2564 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2500 EXPECT_TRUE( |
2565 &max_scale)); | 2501 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2566 EXPECT_EQ(6.f, max_scale); | 2502 EXPECT_EQ(6.f, max_scale); |
2567 EXPECT_TRUE( | 2503 EXPECT_TRUE( |
2568 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2504 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2569 EXPECT_EQ(6.f, max_scale); | 2505 EXPECT_EQ(6.f, max_scale); |
2570 | 2506 |
2571 // REVERSE direction with positive playback rate. | 2507 // REVERSE direction with positive playback rate. |
2572 animation->set_direction(Animation::Direction::REVERSE); | 2508 animation->set_direction(Animation::Direction::REVERSE); |
2573 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2509 EXPECT_TRUE( |
2574 &max_scale)); | 2510 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2575 EXPECT_EQ(3.f, max_scale); | 2511 EXPECT_EQ(3.f, max_scale); |
2576 EXPECT_TRUE( | 2512 EXPECT_TRUE( |
2577 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2513 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2578 EXPECT_EQ(3.f, max_scale); | 2514 EXPECT_EQ(3.f, max_scale); |
2579 | 2515 |
2580 // ALTERNATE reverse direction. | 2516 // ALTERNATE reverse direction. |
2581 animation->set_direction(Animation::Direction::REVERSE); | 2517 animation->set_direction(Animation::Direction::REVERSE); |
2582 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2518 EXPECT_TRUE( |
2583 &max_scale)); | 2519 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2584 EXPECT_EQ(3.f, max_scale); | 2520 EXPECT_EQ(3.f, max_scale); |
2585 EXPECT_TRUE( | 2521 EXPECT_TRUE( |
2586 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2522 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2587 EXPECT_EQ(3.f, max_scale); | 2523 EXPECT_EQ(3.f, max_scale); |
2588 | 2524 |
2589 animation->set_playback_rate(-1.0); | 2525 animation->set_playback_rate(-1.0); |
2590 | 2526 |
2591 // NORMAL direction with negative playback rate. | 2527 // NORMAL direction with negative playback rate. |
2592 animation->set_direction(Animation::Direction::NORMAL); | 2528 animation->set_direction(Animation::Direction::NORMAL); |
2593 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2529 EXPECT_TRUE( |
2594 &max_scale)); | 2530 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2595 EXPECT_EQ(3.f, max_scale); | 2531 EXPECT_EQ(3.f, max_scale); |
2596 EXPECT_TRUE( | 2532 EXPECT_TRUE( |
2597 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2533 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2598 EXPECT_EQ(3.f, max_scale); | 2534 EXPECT_EQ(3.f, max_scale); |
2599 | 2535 |
2600 // ALTERNATE direction with negative playback rate. | 2536 // ALTERNATE direction with negative playback rate. |
2601 animation->set_direction(Animation::Direction::ALTERNATE_NORMAL); | 2537 animation->set_direction(Animation::Direction::ALTERNATE_NORMAL); |
2602 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2538 EXPECT_TRUE( |
2603 &max_scale)); | 2539 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2604 EXPECT_EQ(3.f, max_scale); | 2540 EXPECT_EQ(3.f, max_scale); |
2605 EXPECT_TRUE( | 2541 EXPECT_TRUE( |
2606 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2542 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2607 EXPECT_EQ(3.f, max_scale); | 2543 EXPECT_EQ(3.f, max_scale); |
2608 | 2544 |
2609 // REVERSE direction with negative playback rate. | 2545 // REVERSE direction with negative playback rate. |
2610 animation->set_direction(Animation::Direction::REVERSE); | 2546 animation->set_direction(Animation::Direction::REVERSE); |
2611 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2547 EXPECT_TRUE( |
2612 &max_scale)); | 2548 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2613 EXPECT_EQ(6.f, max_scale); | 2549 EXPECT_EQ(6.f, max_scale); |
2614 EXPECT_TRUE( | 2550 EXPECT_TRUE( |
2615 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2551 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2616 EXPECT_EQ(6.f, max_scale); | 2552 EXPECT_EQ(6.f, max_scale); |
2617 | 2553 |
2618 // ALTERNATE reverse direction with negative playback rate. | 2554 // ALTERNATE reverse direction with negative playback rate. |
2619 animation->set_direction(Animation::Direction::REVERSE); | 2555 animation->set_direction(Animation::Direction::REVERSE); |
2620 EXPECT_TRUE(animations_impl->MaximumTargetScale(ElementListType::PENDING, | 2556 EXPECT_TRUE( |
2621 &max_scale)); | 2557 player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale)); |
2622 EXPECT_EQ(6.f, max_scale); | 2558 EXPECT_EQ(6.f, max_scale); |
2623 EXPECT_TRUE( | 2559 EXPECT_TRUE( |
2624 animations_impl->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); | 2560 player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale)); |
2625 EXPECT_EQ(6.f, max_scale); | 2561 EXPECT_EQ(6.f, max_scale); |
2626 } | 2562 } |
2627 | 2563 |
2628 TEST_F(ElementAnimationsTest, NewlyPushedAnimationWaitsForActivation) { | 2564 TEST_F(ElementAnimationsTest, NewlyPushedAnimationWaitsForActivation) { |
2629 CreateTestLayer(true, true); | 2565 CreateTestLayer(true, true); |
2630 AttachTimelinePlayerLayer(); | 2566 AttachTimelinePlayerLayer(); |
2631 CreateImplTimelineAndPlayer(); | 2567 CreateImplTimelineAndPlayer(); |
2632 | 2568 |
2633 scoped_refptr<ElementAnimations> animations = element_animations(); | |
2634 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
2635 | |
2636 auto events = host_impl_->CreateEvents(); | 2569 auto events = host_impl_->CreateEvents(); |
2637 | 2570 |
2638 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); | 2571 EXPECT_FALSE(player_->needs_to_start_animations()); |
2639 int animation_id = AddOpacityTransitionToElementAnimations( | 2572 int animation_id = |
2640 animations.get(), 1, 0.5f, 1.f, false); | 2573 AddOpacityTransitionToPlayer(player_.get(), 1, 0.5f, 1.f, false); |
2641 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); | 2574 EXPECT_TRUE(player_->needs_to_start_animations()); |
2642 | 2575 |
2643 EXPECT_FALSE(animations_impl->needs_to_start_animations_for_testing()); | 2576 EXPECT_FALSE(player_impl_->needs_to_start_animations()); |
2644 PushProperties(); | 2577 PushProperties(); |
2645 EXPECT_TRUE(animations_impl->needs_to_start_animations_for_testing()); | 2578 EXPECT_TRUE(player_impl_->needs_to_start_animations()); |
2646 | 2579 |
2647 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 2580 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
2648 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 2581 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
2649 animations_impl->GetAnimationById(animation_id)->run_state()); | 2582 player_impl_->GetAnimationById(animation_id)->run_state()); |
2650 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2583 EXPECT_TRUE( |
2651 ->affects_pending_elements()); | 2584 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); |
2652 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id) | 2585 EXPECT_FALSE( |
2653 ->affects_active_elements()); | 2586 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); |
2654 | 2587 |
2655 animations_impl->Animate(kInitialTickTime); | 2588 element_animations_impl_->Animate(kInitialTickTime); |
2656 EXPECT_FALSE(animations_impl->needs_to_start_animations_for_testing()); | 2589 EXPECT_FALSE(player_impl_->needs_to_start_animations()); |
2657 animations_impl->UpdateState(true, events.get()); | 2590 element_animations_impl_->UpdateState(true, events.get()); |
2658 | 2591 |
2659 // Since the animation hasn't been activated, it should still be STARTING | 2592 // Since the animation hasn't been activated, it should still be STARTING |
2660 // rather than RUNNING. | 2593 // rather than RUNNING. |
2661 EXPECT_EQ(Animation::STARTING, | 2594 EXPECT_EQ(Animation::STARTING, |
2662 animations_impl->GetAnimationById(animation_id)->run_state()); | 2595 player_impl_->GetAnimationById(animation_id)->run_state()); |
2663 | 2596 |
2664 // Since the animation hasn't been activated, only the pending observer | 2597 // Since the animation hasn't been activated, only the pending observer |
2665 // should have been ticked. | 2598 // should have been ticked. |
2666 EXPECT_EQ(0.5f, | 2599 EXPECT_EQ(0.5f, |
2667 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 2600 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
2668 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 2601 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
2669 | 2602 |
2670 animations_impl->ActivateAnimations(); | 2603 player_impl_->ActivateAnimations(); |
2671 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2604 EXPECT_TRUE( |
2672 ->affects_pending_elements()); | 2605 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); |
2673 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2606 EXPECT_TRUE( |
2674 ->affects_active_elements()); | 2607 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); |
2675 | 2608 |
2676 animations_impl->Animate(kInitialTickTime + | 2609 element_animations_impl_->Animate(kInitialTickTime + |
2677 TimeDelta::FromMilliseconds(1000)); | 2610 TimeDelta::FromMilliseconds(1000)); |
2678 animations_impl->UpdateState(true, events.get()); | 2611 element_animations_impl_->UpdateState(true, events.get()); |
2679 | 2612 |
2680 // Since the animation has been activated, it should have reached the | 2613 // Since the animation has been activated, it should have reached the |
2681 // RUNNING state and the active observer should start to get ticked. | 2614 // RUNNING state and the active observer should start to get ticked. |
2682 EXPECT_EQ(Animation::RUNNING, | 2615 EXPECT_EQ(Animation::RUNNING, |
2683 animations_impl->GetAnimationById(animation_id)->run_state()); | 2616 player_impl_->GetAnimationById(animation_id)->run_state()); |
2684 EXPECT_EQ(0.5f, | 2617 EXPECT_EQ(0.5f, |
2685 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 2618 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
2686 EXPECT_EQ(0.5f, | 2619 EXPECT_EQ(0.5f, |
2687 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 2620 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
2688 } | 2621 } |
2689 | 2622 |
2690 TEST_F(ElementAnimationsTest, ActivationBetweenAnimateAndUpdateState) { | 2623 TEST_F(ElementAnimationsTest, ActivationBetweenAnimateAndUpdateState) { |
2691 CreateTestLayer(true, true); | 2624 CreateTestLayer(true, true); |
2692 AttachTimelinePlayerLayer(); | 2625 AttachTimelinePlayerLayer(); |
2693 CreateImplTimelineAndPlayer(); | 2626 CreateImplTimelineAndPlayer(); |
2694 | 2627 |
2695 scoped_refptr<ElementAnimations> animations = element_animations(); | |
2696 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
2697 | |
2698 auto events = host_impl_->CreateEvents(); | 2628 auto events = host_impl_->CreateEvents(); |
2699 | 2629 |
2700 const int animation_id = AddOpacityTransitionToElementAnimations( | 2630 const int animation_id = |
2701 animations.get(), 1, 0.5f, 1.f, true); | 2631 AddOpacityTransitionToPlayer(player_.get(), 1, 0.5f, 1.f, true); |
2702 | 2632 |
2703 PushProperties(); | 2633 PushProperties(); |
2704 | 2634 |
2705 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 2635 EXPECT_TRUE(player_impl_->GetAnimationById(animation_id)); |
2706 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 2636 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
2707 animations_impl->GetAnimationById(animation_id)->run_state()); | 2637 player_impl_->GetAnimationById(animation_id)->run_state()); |
2708 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2638 EXPECT_TRUE( |
2709 ->affects_pending_elements()); | 2639 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); |
2710 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id) | 2640 EXPECT_FALSE( |
2711 ->affects_active_elements()); | 2641 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); |
2712 | 2642 |
2713 animations_impl->Animate(kInitialTickTime); | 2643 element_animations_impl_->Animate(kInitialTickTime); |
2714 | 2644 |
2715 // Since the animation hasn't been activated, only the pending observer | 2645 // Since the animation hasn't been activated, only the pending observer |
2716 // should have been ticked. | 2646 // should have been ticked. |
2717 EXPECT_EQ(0.5f, | 2647 EXPECT_EQ(0.5f, |
2718 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 2648 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
2719 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 2649 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
2720 | 2650 |
2721 animations_impl->ActivateAnimations(); | 2651 player_impl_->ActivateAnimations(); |
2722 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2652 EXPECT_TRUE( |
2723 ->affects_pending_elements()); | 2653 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); |
2724 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2654 EXPECT_TRUE( |
2725 ->affects_active_elements()); | 2655 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); |
2726 | 2656 |
2727 animations_impl->UpdateState(true, events.get()); | 2657 element_animations_impl_->UpdateState(true, events.get()); |
2728 | 2658 |
2729 // Since the animation has been activated, it should have reached the | 2659 // Since the animation has been activated, it should have reached the |
2730 // RUNNING state. | 2660 // RUNNING state. |
2731 EXPECT_EQ(Animation::RUNNING, | 2661 EXPECT_EQ(Animation::RUNNING, |
2732 animations_impl->GetAnimationById(animation_id)->run_state()); | 2662 player_impl_->GetAnimationById(animation_id)->run_state()); |
2733 | 2663 |
2734 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2664 element_animations_impl_->Animate(kInitialTickTime + |
| 2665 TimeDelta::FromMilliseconds(500)); |
2735 | 2666 |
2736 // Both elements should have been ticked. | 2667 // Both elements should have been ticked. |
2737 EXPECT_EQ(0.75f, | 2668 EXPECT_EQ(0.75f, |
2738 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 2669 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
2739 EXPECT_EQ(0.75f, | 2670 EXPECT_EQ(0.75f, |
2740 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 2671 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
2741 } | 2672 } |
2742 | 2673 |
2743 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenTransformAnimationChanges) { | 2674 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenTransformAnimationChanges) { |
2744 CreateTestLayer(true, true); | 2675 CreateTestLayer(true, true); |
2745 AttachTimelinePlayerLayer(); | 2676 AttachTimelinePlayerLayer(); |
2746 CreateImplTimelineAndPlayer(); | 2677 CreateImplTimelineAndPlayer(); |
2747 | 2678 |
2748 scoped_refptr<ElementAnimations> animations = element_animations(); | |
2749 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
2750 | |
2751 auto events = host_impl_->CreateEvents(); | 2679 auto events = host_impl_->CreateEvents(); |
2752 | 2680 |
2753 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( | 2681 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( |
2754 element_id_, ElementListType::ACTIVE)); | 2682 element_id_, ElementListType::ACTIVE)); |
2755 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( | 2683 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( |
2756 element_id_, ElementListType::ACTIVE)); | 2684 element_id_, ElementListType::ACTIVE)); |
2757 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2685 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2758 element_id_, ElementListType::PENDING)); | 2686 element_id_, ElementListType::PENDING)); |
2759 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2687 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2760 element_id_, ElementListType::PENDING)); | 2688 element_id_, ElementListType::PENDING)); |
2761 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2689 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2762 element_id_, ElementListType::ACTIVE)); | 2690 element_id_, ElementListType::ACTIVE)); |
2763 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2691 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2764 element_id_, ElementListType::ACTIVE)); | 2692 element_id_, ElementListType::ACTIVE)); |
2765 | 2693 |
2766 // Case 1: An animation that's allowed to run until its finish point. | 2694 // Case 1: An animation that's allowed to run until its finish point. |
2767 AddAnimatedTransformToElementAnimations(animations.get(), 1.0, 1, 1); | 2695 AddAnimatedTransformToPlayer(player_.get(), 1.0, 1, 1); |
2768 EXPECT_TRUE(client_.GetHasPotentialTransformAnimation( | 2696 EXPECT_TRUE(client_.GetHasPotentialTransformAnimation( |
2769 element_id_, ElementListType::ACTIVE)); | 2697 element_id_, ElementListType::ACTIVE)); |
2770 EXPECT_TRUE(client_.GetTransformIsCurrentlyAnimating( | 2698 EXPECT_TRUE(client_.GetTransformIsCurrentlyAnimating( |
2771 element_id_, ElementListType::ACTIVE)); | 2699 element_id_, ElementListType::ACTIVE)); |
2772 | 2700 |
2773 PushProperties(); | 2701 PushProperties(); |
2774 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2702 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2775 element_id_, ElementListType::PENDING)); | 2703 element_id_, ElementListType::PENDING)); |
2776 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( | 2704 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( |
2777 element_id_, ElementListType::PENDING)); | 2705 element_id_, ElementListType::PENDING)); |
2778 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2706 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2779 element_id_, ElementListType::ACTIVE)); | 2707 element_id_, ElementListType::ACTIVE)); |
2780 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2708 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2781 element_id_, ElementListType::ACTIVE)); | 2709 element_id_, ElementListType::ACTIVE)); |
2782 | 2710 |
2783 animations_impl->ActivateAnimations(); | 2711 element_animations_impl_->ActivateAnimations(); |
2784 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2712 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2785 element_id_, ElementListType::PENDING)); | 2713 element_id_, ElementListType::PENDING)); |
2786 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( | 2714 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( |
2787 element_id_, ElementListType::PENDING)); | 2715 element_id_, ElementListType::PENDING)); |
2788 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2716 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2789 element_id_, ElementListType::ACTIVE)); | 2717 element_id_, ElementListType::ACTIVE)); |
2790 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( | 2718 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( |
2791 element_id_, ElementListType::ACTIVE)); | 2719 element_id_, ElementListType::ACTIVE)); |
2792 | 2720 |
2793 animations_impl->Animate(kInitialTickTime); | 2721 element_animations_impl_->Animate(kInitialTickTime); |
2794 animations_impl->UpdateState(true, events.get()); | 2722 element_animations_impl_->UpdateState(true, events.get()); |
2795 | 2723 |
2796 animations->NotifyAnimationStarted(events->events_[0]); | 2724 player_->NotifyAnimationStarted(events->events_[0]); |
2797 events->events_.clear(); | 2725 events->events_.clear(); |
2798 | 2726 |
2799 // Finish the animation. | 2727 // Finish the animation. |
2800 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2728 element_animations_->Animate(kInitialTickTime + |
2801 animations->UpdateState(true, nullptr); | 2729 TimeDelta::FromMilliseconds(1000)); |
| 2730 element_animations_->UpdateState(true, nullptr); |
2802 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( | 2731 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( |
2803 element_id_, ElementListType::ACTIVE)); | 2732 element_id_, ElementListType::ACTIVE)); |
2804 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( | 2733 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( |
2805 element_id_, ElementListType::ACTIVE)); | 2734 element_id_, ElementListType::ACTIVE)); |
2806 | 2735 |
2807 PushProperties(); | 2736 PushProperties(); |
2808 | 2737 |
2809 // animations_impl hasn't yet ticked at/past the end of the animation. | 2738 // animations_impl hasn't yet ticked at/past the end of the animation. |
2810 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2739 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2811 element_id_, ElementListType::PENDING)); | 2740 element_id_, ElementListType::PENDING)); |
2812 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( | 2741 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( |
2813 element_id_, ElementListType::PENDING)); | 2742 element_id_, ElementListType::PENDING)); |
2814 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2743 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2815 element_id_, ElementListType::ACTIVE)); | 2744 element_id_, ElementListType::ACTIVE)); |
2816 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( | 2745 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( |
2817 element_id_, ElementListType::ACTIVE)); | 2746 element_id_, ElementListType::ACTIVE)); |
2818 | 2747 |
2819 animations_impl->Animate(kInitialTickTime + | 2748 element_animations_impl_->Animate(kInitialTickTime + |
2820 TimeDelta::FromMilliseconds(1000)); | 2749 TimeDelta::FromMilliseconds(1000)); |
2821 animations_impl->UpdateState(true, events.get()); | 2750 element_animations_impl_->UpdateState(true, events.get()); |
2822 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2751 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2823 element_id_, ElementListType::PENDING)); | 2752 element_id_, ElementListType::PENDING)); |
2824 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2753 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2825 element_id_, ElementListType::PENDING)); | 2754 element_id_, ElementListType::PENDING)); |
2826 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2755 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2827 element_id_, ElementListType::ACTIVE)); | 2756 element_id_, ElementListType::ACTIVE)); |
2828 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2757 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2829 element_id_, ElementListType::ACTIVE)); | 2758 element_id_, ElementListType::ACTIVE)); |
2830 | 2759 |
2831 // Case 2: An animation that's removed before it finishes. | 2760 // Case 2: An animation that's removed before it finishes. |
2832 int animation_id = | 2761 int animation_id = AddAnimatedTransformToPlayer(player_.get(), 10.0, 2, 2); |
2833 AddAnimatedTransformToElementAnimations(animations.get(), 10.0, 2, 2); | 2762 int animation2_id = AddAnimatedTransformToPlayer(player_.get(), 10.0, 2, 1); |
2834 int animation2_id = | 2763 player_->GetAnimationById(animation2_id) |
2835 AddAnimatedTransformToElementAnimations(animations.get(), 10.0, 2, 1); | |
2836 animations->GetAnimationById(animation2_id) | |
2837 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); | 2764 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); |
2838 animations->GetAnimationById(animation2_id) | 2765 player_->GetAnimationById(animation2_id) |
2839 ->set_fill_mode(Animation::FillMode::NONE); | 2766 ->set_fill_mode(Animation::FillMode::NONE); |
2840 EXPECT_TRUE(client_.GetHasPotentialTransformAnimation( | 2767 EXPECT_TRUE(client_.GetHasPotentialTransformAnimation( |
2841 element_id_, ElementListType::ACTIVE)); | 2768 element_id_, ElementListType::ACTIVE)); |
2842 EXPECT_TRUE(client_.GetTransformIsCurrentlyAnimating( | 2769 EXPECT_TRUE(client_.GetTransformIsCurrentlyAnimating( |
2843 element_id_, ElementListType::ACTIVE)); | 2770 element_id_, ElementListType::ACTIVE)); |
2844 | 2771 |
2845 PushProperties(); | 2772 PushProperties(); |
2846 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2773 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2847 element_id_, ElementListType::PENDING)); | 2774 element_id_, ElementListType::PENDING)); |
2848 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( | 2775 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( |
2849 element_id_, ElementListType::PENDING)); | 2776 element_id_, ElementListType::PENDING)); |
2850 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2777 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2851 element_id_, ElementListType::ACTIVE)); | 2778 element_id_, ElementListType::ACTIVE)); |
2852 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2779 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2853 element_id_, ElementListType::ACTIVE)); | 2780 element_id_, ElementListType::ACTIVE)); |
2854 | 2781 |
2855 animations_impl->ActivateAnimations(); | 2782 element_animations_impl_->ActivateAnimations(); |
2856 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2783 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2857 element_id_, ElementListType::ACTIVE)); | 2784 element_id_, ElementListType::ACTIVE)); |
2858 // animation1 is in effect currently and animation2 isn't. As the element has | 2785 // animation1 is in effect currently and animation2 isn't. As the element has |
2859 // atleast one animation that's in effect currently, client should be notified | 2786 // atleast one animation that's in effect currently, client should be notified |
2860 // that the transform is currently animating. | 2787 // that the transform is currently animating. |
2861 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( | 2788 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( |
2862 element_id_, ElementListType::ACTIVE)); | 2789 element_id_, ElementListType::ACTIVE)); |
2863 | 2790 |
2864 animations_impl->Animate(kInitialTickTime + | 2791 element_animations_impl_->Animate(kInitialTickTime + |
2865 TimeDelta::FromMilliseconds(2000)); | 2792 TimeDelta::FromMilliseconds(2000)); |
2866 animations_impl->UpdateState(true, events.get()); | 2793 element_animations_impl_->UpdateState(true, events.get()); |
2867 | 2794 |
2868 animations->NotifyAnimationStarted(events->events_[0]); | 2795 player_->NotifyAnimationStarted(events->events_[0]); |
2869 events->events_.clear(); | 2796 events->events_.clear(); |
2870 | 2797 |
2871 animations->RemoveAnimation(animation_id); | 2798 player_->RemoveAnimation(animation_id); |
2872 animations->RemoveAnimation(animation2_id); | 2799 player_->RemoveAnimation(animation2_id); |
2873 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( | 2800 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( |
2874 element_id_, ElementListType::ACTIVE)); | 2801 element_id_, ElementListType::ACTIVE)); |
2875 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( | 2802 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( |
2876 element_id_, ElementListType::ACTIVE)); | 2803 element_id_, ElementListType::ACTIVE)); |
2877 | 2804 |
2878 PushProperties(); | 2805 PushProperties(); |
2879 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2806 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2880 element_id_, ElementListType::PENDING)); | 2807 element_id_, ElementListType::PENDING)); |
2881 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2808 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2882 element_id_, ElementListType::PENDING)); | 2809 element_id_, ElementListType::PENDING)); |
2883 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2810 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2884 element_id_, ElementListType::ACTIVE)); | 2811 element_id_, ElementListType::ACTIVE)); |
2885 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( | 2812 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( |
2886 element_id_, ElementListType::ACTIVE)); | 2813 element_id_, ElementListType::ACTIVE)); |
2887 | 2814 |
2888 animations_impl->ActivateAnimations(); | 2815 element_animations_impl_->ActivateAnimations(); |
2889 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2816 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2890 element_id_, ElementListType::ACTIVE)); | 2817 element_id_, ElementListType::ACTIVE)); |
2891 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2818 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2892 element_id_, ElementListType::ACTIVE)); | 2819 element_id_, ElementListType::ACTIVE)); |
2893 | 2820 |
2894 // Case 3: An animation that's aborted before it finishes. | 2821 // Case 3: An animation that's aborted before it finishes. |
2895 animation_id = | 2822 animation_id = AddAnimatedTransformToPlayer(player_.get(), 10.0, 3, 3); |
2896 AddAnimatedTransformToElementAnimations(animations.get(), 10.0, 3, 3); | |
2897 EXPECT_TRUE(client_.GetHasPotentialTransformAnimation( | 2823 EXPECT_TRUE(client_.GetHasPotentialTransformAnimation( |
2898 element_id_, ElementListType::ACTIVE)); | 2824 element_id_, ElementListType::ACTIVE)); |
2899 EXPECT_TRUE(client_.GetTransformIsCurrentlyAnimating( | 2825 EXPECT_TRUE(client_.GetTransformIsCurrentlyAnimating( |
2900 element_id_, ElementListType::ACTIVE)); | 2826 element_id_, ElementListType::ACTIVE)); |
2901 | 2827 |
2902 PushProperties(); | 2828 PushProperties(); |
2903 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2829 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2904 element_id_, ElementListType::PENDING)); | 2830 element_id_, ElementListType::PENDING)); |
2905 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( | 2831 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( |
2906 element_id_, ElementListType::PENDING)); | 2832 element_id_, ElementListType::PENDING)); |
2907 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2833 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2908 element_id_, ElementListType::ACTIVE)); | 2834 element_id_, ElementListType::ACTIVE)); |
2909 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2835 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2910 element_id_, ElementListType::ACTIVE)); | 2836 element_id_, ElementListType::ACTIVE)); |
2911 | 2837 |
2912 animations_impl->ActivateAnimations(); | 2838 element_animations_impl_->ActivateAnimations(); |
2913 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2839 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2914 element_id_, ElementListType::ACTIVE)); | 2840 element_id_, ElementListType::ACTIVE)); |
2915 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( | 2841 EXPECT_TRUE(client_impl_.GetTransformIsCurrentlyAnimating( |
2916 element_id_, ElementListType::ACTIVE)); | 2842 element_id_, ElementListType::ACTIVE)); |
2917 | 2843 |
2918 animations_impl->Animate(kInitialTickTime + | 2844 element_animations_impl_->Animate(kInitialTickTime + |
2919 TimeDelta::FromMilliseconds(2000)); | 2845 TimeDelta::FromMilliseconds(2000)); |
2920 animations_impl->UpdateState(true, events.get()); | 2846 element_animations_impl_->UpdateState(true, events.get()); |
2921 | 2847 |
2922 animations->NotifyAnimationStarted(events->events_[0]); | 2848 player_->NotifyAnimationStarted(events->events_[0]); |
2923 events->events_.clear(); | 2849 events->events_.clear(); |
2924 | 2850 |
2925 animations_impl->AbortAnimations(TargetProperty::TRANSFORM); | 2851 player_impl_->AbortAnimations(TargetProperty::TRANSFORM, false); |
2926 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2852 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2927 element_id_, ElementListType::PENDING)); | 2853 element_id_, ElementListType::PENDING)); |
2928 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2854 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2929 element_id_, ElementListType::PENDING)); | 2855 element_id_, ElementListType::PENDING)); |
2930 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2856 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2931 element_id_, ElementListType::ACTIVE)); | 2857 element_id_, ElementListType::ACTIVE)); |
2932 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2858 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2933 element_id_, ElementListType::ACTIVE)); | 2859 element_id_, ElementListType::ACTIVE)); |
2934 | 2860 |
2935 animations_impl->Animate(kInitialTickTime + | 2861 element_animations_impl_->Animate(kInitialTickTime + |
2936 TimeDelta::FromMilliseconds(4000)); | 2862 TimeDelta::FromMilliseconds(4000)); |
2937 animations_impl->UpdateState(true, events.get()); | 2863 element_animations_impl_->UpdateState(true, events.get()); |
2938 | 2864 |
2939 animations->NotifyAnimationAborted(events->events_[0]); | 2865 element_animations_->NotifyAnimationAborted(events->events_[0]); |
2940 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( | 2866 EXPECT_FALSE(client_.GetHasPotentialTransformAnimation( |
2941 element_id_, ElementListType::ACTIVE)); | 2867 element_id_, ElementListType::ACTIVE)); |
2942 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( | 2868 EXPECT_FALSE(client_.GetTransformIsCurrentlyAnimating( |
2943 element_id_, ElementListType::ACTIVE)); | 2869 element_id_, ElementListType::ACTIVE)); |
2944 | 2870 |
2945 // Case 4 : An animation that's not in effect. | 2871 // Case 4 : An animation that's not in effect. |
2946 animation_id = | 2872 animation_id = AddAnimatedTransformToPlayer(player_.get(), 1.0, 1, 6); |
2947 AddAnimatedTransformToElementAnimations(animations.get(), 1.0, 1, 6); | 2873 player_->GetAnimationById(animation_id) |
2948 animations->GetAnimationById(animation_id) | |
2949 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); | 2874 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); |
2950 animations->GetAnimationById(animation_id) | 2875 player_->GetAnimationById(animation_id) |
2951 ->set_fill_mode(Animation::FillMode::NONE); | 2876 ->set_fill_mode(Animation::FillMode::NONE); |
2952 | 2877 |
2953 PushProperties(); | 2878 PushProperties(); |
2954 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2879 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2955 element_id_, ElementListType::PENDING)); | 2880 element_id_, ElementListType::PENDING)); |
2956 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2881 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2957 element_id_, ElementListType::PENDING)); | 2882 element_id_, ElementListType::PENDING)); |
2958 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( | 2883 EXPECT_FALSE(client_impl_.GetHasPotentialTransformAnimation( |
2959 element_id_, ElementListType::ACTIVE)); | 2884 element_id_, ElementListType::ACTIVE)); |
2960 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2885 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2961 element_id_, ElementListType::ACTIVE)); | 2886 element_id_, ElementListType::ACTIVE)); |
2962 | 2887 |
2963 animations_impl->ActivateAnimations(); | 2888 element_animations_impl_->ActivateAnimations(); |
2964 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( | 2889 EXPECT_TRUE(client_impl_.GetHasPotentialTransformAnimation( |
2965 element_id_, ElementListType::ACTIVE)); | 2890 element_id_, ElementListType::ACTIVE)); |
2966 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( | 2891 EXPECT_FALSE(client_impl_.GetTransformIsCurrentlyAnimating( |
2967 element_id_, ElementListType::ACTIVE)); | 2892 element_id_, ElementListType::ACTIVE)); |
2968 } | 2893 } |
2969 | 2894 |
2970 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenOpacityAnimationChanges) { | 2895 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenOpacityAnimationChanges) { |
2971 CreateTestLayer(true, true); | 2896 CreateTestLayer(true, true); |
2972 AttachTimelinePlayerLayer(); | 2897 AttachTimelinePlayerLayer(); |
2973 CreateImplTimelineAndPlayer(); | 2898 CreateImplTimelineAndPlayer(); |
2974 | 2899 |
2975 scoped_refptr<ElementAnimations> animations = element_animations(); | |
2976 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
2977 | |
2978 auto events = host_impl_->CreateEvents(); | 2900 auto events = host_impl_->CreateEvents(); |
2979 | 2901 |
2980 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( | 2902 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( |
2981 element_id_, ElementListType::ACTIVE)); | 2903 element_id_, ElementListType::ACTIVE)); |
2982 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, | 2904 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, |
2983 ElementListType::ACTIVE)); | 2905 ElementListType::ACTIVE)); |
2984 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 2906 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
2985 element_id_, ElementListType::PENDING)); | 2907 element_id_, ElementListType::PENDING)); |
2986 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2908 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
2987 element_id_, ElementListType::PENDING)); | 2909 element_id_, ElementListType::PENDING)); |
2988 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 2910 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
2989 element_id_, ElementListType::ACTIVE)); | 2911 element_id_, ElementListType::ACTIVE)); |
2990 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2912 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
2991 element_id_, ElementListType::ACTIVE)); | 2913 element_id_, ElementListType::ACTIVE)); |
2992 | 2914 |
2993 // Case 1: An animation that's allowed to run until its finish point. | 2915 // Case 1: An animation that's allowed to run until its finish point. |
2994 AddOpacityTransitionToElementAnimations(animations.get(), 1.0, 0.f, 1.f, | 2916 AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.f, 1.f, |
2995 false /*use_timing_function*/); | 2917 false /*use_timing_function*/); |
2996 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_, | 2918 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_, |
2997 ElementListType::ACTIVE)); | 2919 ElementListType::ACTIVE)); |
2998 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_, | 2920 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_, |
2999 ElementListType::ACTIVE)); | 2921 ElementListType::ACTIVE)); |
3000 | 2922 |
3001 PushProperties(); | 2923 PushProperties(); |
3002 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 2924 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3003 element_id_, ElementListType::PENDING)); | 2925 element_id_, ElementListType::PENDING)); |
3004 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2926 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3005 element_id_, ElementListType::PENDING)); | 2927 element_id_, ElementListType::PENDING)); |
3006 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 2928 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
3007 element_id_, ElementListType::ACTIVE)); | 2929 element_id_, ElementListType::ACTIVE)); |
3008 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2930 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3009 element_id_, ElementListType::ACTIVE)); | 2931 element_id_, ElementListType::ACTIVE)); |
3010 | 2932 |
3011 animations_impl->ActivateAnimations(); | 2933 element_animations_impl_->ActivateAnimations(); |
3012 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 2934 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3013 element_id_, ElementListType::PENDING)); | 2935 element_id_, ElementListType::PENDING)); |
3014 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2936 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3015 element_id_, ElementListType::PENDING)); | 2937 element_id_, ElementListType::PENDING)); |
3016 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 2938 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3017 element_id_, ElementListType::ACTIVE)); | 2939 element_id_, ElementListType::ACTIVE)); |
3018 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2940 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3019 element_id_, ElementListType::ACTIVE)); | 2941 element_id_, ElementListType::ACTIVE)); |
3020 | 2942 |
3021 animations_impl->Animate(kInitialTickTime); | 2943 element_animations_impl_->Animate(kInitialTickTime); |
3022 animations_impl->UpdateState(true, events.get()); | 2944 element_animations_impl_->UpdateState(true, events.get()); |
3023 | 2945 |
3024 animations->NotifyAnimationStarted(events->events_[0]); | 2946 player_->NotifyAnimationStarted(events->events_[0]); |
3025 events->events_.clear(); | 2947 events->events_.clear(); |
3026 | 2948 |
3027 // Finish the animation. | 2949 // Finish the animation. |
3028 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2950 element_animations_->Animate(kInitialTickTime + |
3029 animations->UpdateState(true, nullptr); | 2951 TimeDelta::FromMilliseconds(1000)); |
| 2952 element_animations_->UpdateState(true, nullptr); |
3030 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( | 2953 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( |
3031 element_id_, ElementListType::ACTIVE)); | 2954 element_id_, ElementListType::ACTIVE)); |
3032 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, | 2955 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, |
3033 ElementListType::ACTIVE)); | 2956 ElementListType::ACTIVE)); |
3034 | 2957 |
3035 PushProperties(); | 2958 PushProperties(); |
3036 | 2959 |
3037 // animations_impl hasn't yet ticked at/past the end of the animation. | 2960 // animations_impl hasn't yet ticked at/past the end of the animation. |
3038 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 2961 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3039 element_id_, ElementListType::PENDING)); | 2962 element_id_, ElementListType::PENDING)); |
3040 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2963 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3041 element_id_, ElementListType::PENDING)); | 2964 element_id_, ElementListType::PENDING)); |
3042 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 2965 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3043 element_id_, ElementListType::ACTIVE)); | 2966 element_id_, ElementListType::ACTIVE)); |
3044 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2967 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3045 element_id_, ElementListType::ACTIVE)); | 2968 element_id_, ElementListType::ACTIVE)); |
3046 | 2969 |
3047 animations_impl->Animate(kInitialTickTime + | 2970 element_animations_impl_->Animate(kInitialTickTime + |
3048 TimeDelta::FromMilliseconds(1000)); | 2971 TimeDelta::FromMilliseconds(1000)); |
3049 animations_impl->UpdateState(true, events.get()); | 2972 element_animations_impl_->UpdateState(true, events.get()); |
3050 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 2973 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
3051 element_id_, ElementListType::PENDING)); | 2974 element_id_, ElementListType::PENDING)); |
3052 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2975 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3053 element_id_, ElementListType::PENDING)); | 2976 element_id_, ElementListType::PENDING)); |
3054 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 2977 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
3055 element_id_, ElementListType::ACTIVE)); | 2978 element_id_, ElementListType::ACTIVE)); |
3056 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2979 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3057 element_id_, ElementListType::ACTIVE)); | 2980 element_id_, ElementListType::ACTIVE)); |
3058 | 2981 |
3059 // Case 2: An animation that's removed before it finishes. | 2982 // Case 2: An animation that's removed before it finishes. |
3060 int animation_id = AddOpacityTransitionToElementAnimations( | 2983 int animation_id = AddOpacityTransitionToPlayer( |
3061 animations.get(), 10.0, 0.f, 1.f, false /*use_timing_function*/); | 2984 player_.get(), 10.0, 0.f, 1.f, false /*use_timing_function*/); |
3062 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_, | 2985 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_, |
3063 ElementListType::ACTIVE)); | 2986 ElementListType::ACTIVE)); |
3064 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_, | 2987 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_, |
3065 ElementListType::ACTIVE)); | 2988 ElementListType::ACTIVE)); |
3066 | 2989 |
3067 PushProperties(); | 2990 PushProperties(); |
3068 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 2991 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3069 element_id_, ElementListType::PENDING)); | 2992 element_id_, ElementListType::PENDING)); |
3070 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2993 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3071 element_id_, ElementListType::PENDING)); | 2994 element_id_, ElementListType::PENDING)); |
3072 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 2995 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
3073 element_id_, ElementListType::ACTIVE)); | 2996 element_id_, ElementListType::ACTIVE)); |
3074 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 2997 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3075 element_id_, ElementListType::ACTIVE)); | 2998 element_id_, ElementListType::ACTIVE)); |
3076 | 2999 |
3077 animations_impl->ActivateAnimations(); | 3000 element_animations_impl_->ActivateAnimations(); |
3078 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 3001 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3079 element_id_, ElementListType::ACTIVE)); | 3002 element_id_, ElementListType::ACTIVE)); |
3080 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3003 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3081 element_id_, ElementListType::ACTIVE)); | 3004 element_id_, ElementListType::ACTIVE)); |
3082 | 3005 |
3083 animations_impl->Animate(kInitialTickTime + | 3006 element_animations_impl_->Animate(kInitialTickTime + |
3084 TimeDelta::FromMilliseconds(2000)); | 3007 TimeDelta::FromMilliseconds(2000)); |
3085 animations_impl->UpdateState(true, events.get()); | 3008 element_animations_impl_->UpdateState(true, events.get()); |
3086 | 3009 |
3087 animations->NotifyAnimationStarted(events->events_[0]); | 3010 player_->NotifyAnimationStarted(events->events_[0]); |
3088 events->events_.clear(); | 3011 events->events_.clear(); |
3089 | 3012 |
3090 animations->RemoveAnimation(animation_id); | 3013 player_->RemoveAnimation(animation_id); |
3091 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( | 3014 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( |
3092 element_id_, ElementListType::ACTIVE)); | 3015 element_id_, ElementListType::ACTIVE)); |
3093 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, | 3016 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, |
3094 ElementListType::ACTIVE)); | 3017 ElementListType::ACTIVE)); |
3095 | 3018 |
3096 PushProperties(); | 3019 PushProperties(); |
3097 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 3020 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
3098 element_id_, ElementListType::PENDING)); | 3021 element_id_, ElementListType::PENDING)); |
3099 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3022 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3100 element_id_, ElementListType::PENDING)); | 3023 element_id_, ElementListType::PENDING)); |
3101 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 3024 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3102 element_id_, ElementListType::ACTIVE)); | 3025 element_id_, ElementListType::ACTIVE)); |
3103 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3026 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3104 element_id_, ElementListType::ACTIVE)); | 3027 element_id_, ElementListType::ACTIVE)); |
3105 | 3028 |
3106 animations_impl->ActivateAnimations(); | 3029 element_animations_impl_->ActivateAnimations(); |
3107 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 3030 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
3108 element_id_, ElementListType::ACTIVE)); | 3031 element_id_, ElementListType::ACTIVE)); |
3109 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3032 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3110 element_id_, ElementListType::ACTIVE)); | 3033 element_id_, ElementListType::ACTIVE)); |
3111 | 3034 |
3112 // Case 3: An animation that's aborted before it finishes. | 3035 // Case 3: An animation that's aborted before it finishes. |
3113 animation_id = AddOpacityTransitionToElementAnimations( | 3036 animation_id = AddOpacityTransitionToPlayer(player_.get(), 10.0, 0.f, 0.5f, |
3114 animations.get(), 10.0, 0.f, 0.5f, false /*use_timing_function*/); | 3037 false /*use_timing_function*/); |
3115 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_, | 3038 EXPECT_TRUE(client_.GetHasPotentialOpacityAnimation(element_id_, |
3116 ElementListType::ACTIVE)); | 3039 ElementListType::ACTIVE)); |
3117 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_, | 3040 EXPECT_TRUE(client_.GetOpacityIsCurrentlyAnimating(element_id_, |
3118 ElementListType::ACTIVE)); | 3041 ElementListType::ACTIVE)); |
3119 | 3042 |
3120 PushProperties(); | 3043 PushProperties(); |
3121 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 3044 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3122 element_id_, ElementListType::PENDING)); | 3045 element_id_, ElementListType::PENDING)); |
3123 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3046 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3124 element_id_, ElementListType::PENDING)); | 3047 element_id_, ElementListType::PENDING)); |
3125 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 3048 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
3126 element_id_, ElementListType::ACTIVE)); | 3049 element_id_, ElementListType::ACTIVE)); |
3127 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3050 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3128 element_id_, ElementListType::ACTIVE)); | 3051 element_id_, ElementListType::ACTIVE)); |
3129 | 3052 |
3130 animations_impl->ActivateAnimations(); | 3053 element_animations_impl_->ActivateAnimations(); |
3131 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 3054 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3132 element_id_, ElementListType::ACTIVE)); | 3055 element_id_, ElementListType::ACTIVE)); |
3133 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3056 EXPECT_TRUE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3134 element_id_, ElementListType::ACTIVE)); | 3057 element_id_, ElementListType::ACTIVE)); |
3135 | 3058 |
3136 animations_impl->Animate(kInitialTickTime + | 3059 element_animations_impl_->Animate(kInitialTickTime + |
3137 TimeDelta::FromMilliseconds(2000)); | 3060 TimeDelta::FromMilliseconds(2000)); |
3138 animations_impl->UpdateState(true, events.get()); | 3061 element_animations_impl_->UpdateState(true, events.get()); |
3139 | 3062 |
3140 animations->NotifyAnimationStarted(events->events_[0]); | 3063 player_->NotifyAnimationStarted(events->events_[0]); |
3141 events->events_.clear(); | 3064 events->events_.clear(); |
3142 | 3065 |
3143 animations_impl->AbortAnimations(TargetProperty::OPACITY); | 3066 player_impl_->AbortAnimations(TargetProperty::OPACITY, false); |
3144 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 3067 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
3145 element_id_, ElementListType::PENDING)); | 3068 element_id_, ElementListType::PENDING)); |
3146 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3069 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3147 element_id_, ElementListType::PENDING)); | 3070 element_id_, ElementListType::PENDING)); |
3148 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 3071 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
3149 element_id_, ElementListType::ACTIVE)); | 3072 element_id_, ElementListType::ACTIVE)); |
3150 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3073 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3151 element_id_, ElementListType::ACTIVE)); | 3074 element_id_, ElementListType::ACTIVE)); |
3152 | 3075 |
3153 animations_impl->Animate(kInitialTickTime + | 3076 element_animations_impl_->Animate(kInitialTickTime + |
3154 TimeDelta::FromMilliseconds(4000)); | 3077 TimeDelta::FromMilliseconds(4000)); |
3155 animations_impl->UpdateState(true, events.get()); | 3078 element_animations_impl_->UpdateState(true, events.get()); |
3156 | 3079 |
3157 animations->NotifyAnimationAborted(events->events_[0]); | 3080 element_animations_->NotifyAnimationAborted(events->events_[0]); |
3158 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( | 3081 EXPECT_FALSE(client_.GetHasPotentialOpacityAnimation( |
3159 element_id_, ElementListType::ACTIVE)); | 3082 element_id_, ElementListType::ACTIVE)); |
3160 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, | 3083 EXPECT_FALSE(client_.GetOpacityIsCurrentlyAnimating(element_id_, |
3161 ElementListType::ACTIVE)); | 3084 ElementListType::ACTIVE)); |
3162 | 3085 |
3163 // Case 4 : An animation that's not in effect. | 3086 // Case 4 : An animation that's not in effect. |
3164 animation_id = AddOpacityTransitionToElementAnimations( | 3087 animation_id = AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.f, 0.5f, |
3165 animations.get(), 1.0, 0.f, 0.5f, false /*use_timing_function*/); | 3088 false /*use_timing_function*/); |
3166 animations->GetAnimationById(animation_id) | 3089 player_->GetAnimationById(animation_id) |
3167 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); | 3090 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); |
3168 animations->GetAnimationById(animation_id) | 3091 player_->GetAnimationById(animation_id) |
3169 ->set_fill_mode(Animation::FillMode::NONE); | 3092 ->set_fill_mode(Animation::FillMode::NONE); |
3170 | 3093 |
3171 PushProperties(); | 3094 PushProperties(); |
3172 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 3095 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3173 element_id_, ElementListType::PENDING)); | 3096 element_id_, ElementListType::PENDING)); |
3174 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3097 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3175 element_id_, ElementListType::PENDING)); | 3098 element_id_, ElementListType::PENDING)); |
3176 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( | 3099 EXPECT_FALSE(client_impl_.GetHasPotentialOpacityAnimation( |
3177 element_id_, ElementListType::ACTIVE)); | 3100 element_id_, ElementListType::ACTIVE)); |
3178 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3101 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3179 element_id_, ElementListType::ACTIVE)); | 3102 element_id_, ElementListType::ACTIVE)); |
3180 | 3103 |
3181 animations_impl->ActivateAnimations(); | 3104 element_animations_impl_->ActivateAnimations(); |
3182 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( | 3105 EXPECT_TRUE(client_impl_.GetHasPotentialOpacityAnimation( |
3183 element_id_, ElementListType::ACTIVE)); | 3106 element_id_, ElementListType::ACTIVE)); |
3184 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( | 3107 EXPECT_FALSE(client_impl_.GetOpacityIsCurrentlyAnimating( |
3185 element_id_, ElementListType::ACTIVE)); | 3108 element_id_, ElementListType::ACTIVE)); |
3186 } | 3109 } |
3187 | 3110 |
3188 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenFilterAnimationChanges) { | 3111 TEST_F(ElementAnimationsTest, ObserverNotifiedWhenFilterAnimationChanges) { |
3189 CreateTestLayer(true, true); | 3112 CreateTestLayer(true, true); |
3190 AttachTimelinePlayerLayer(); | 3113 AttachTimelinePlayerLayer(); |
3191 CreateImplTimelineAndPlayer(); | 3114 CreateImplTimelineAndPlayer(); |
3192 | 3115 |
3193 scoped_refptr<ElementAnimations> animations = element_animations(); | |
3194 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
3195 | |
3196 auto events = host_impl_->CreateEvents(); | 3116 auto events = host_impl_->CreateEvents(); |
3197 | 3117 |
3198 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, | 3118 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, |
3199 ElementListType::ACTIVE)); | 3119 ElementListType::ACTIVE)); |
3200 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, | 3120 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, |
3201 ElementListType::ACTIVE)); | 3121 ElementListType::ACTIVE)); |
3202 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3122 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3203 element_id_, ElementListType::PENDING)); | 3123 element_id_, ElementListType::PENDING)); |
3204 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3124 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3205 element_id_, ElementListType::PENDING)); | 3125 element_id_, ElementListType::PENDING)); |
3206 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3126 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3207 element_id_, ElementListType::ACTIVE)); | 3127 element_id_, ElementListType::ACTIVE)); |
3208 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3128 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3209 element_id_, ElementListType::ACTIVE)); | 3129 element_id_, ElementListType::ACTIVE)); |
3210 | 3130 |
3211 // Case 1: An animation that's allowed to run until its finish point. | 3131 // Case 1: An animation that's allowed to run until its finish point. |
3212 AddAnimatedFilterToElementAnimations(animations.get(), 1.0, 0.f, 1.f); | 3132 AddAnimatedFilterToPlayer(player_.get(), 1.0, 0.f, 1.f); |
3213 EXPECT_TRUE(client_.GetHasPotentialFilterAnimation(element_id_, | 3133 EXPECT_TRUE(client_.GetHasPotentialFilterAnimation(element_id_, |
3214 ElementListType::ACTIVE)); | 3134 ElementListType::ACTIVE)); |
3215 EXPECT_TRUE(client_.GetFilterIsCurrentlyAnimating(element_id_, | 3135 EXPECT_TRUE(client_.GetFilterIsCurrentlyAnimating(element_id_, |
3216 ElementListType::ACTIVE)); | 3136 ElementListType::ACTIVE)); |
3217 | 3137 |
3218 PushProperties(); | 3138 PushProperties(); |
3219 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3139 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3220 element_id_, ElementListType::PENDING)); | 3140 element_id_, ElementListType::PENDING)); |
3221 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( | 3141 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( |
3222 element_id_, ElementListType::PENDING)); | 3142 element_id_, ElementListType::PENDING)); |
3223 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3143 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3224 element_id_, ElementListType::ACTIVE)); | 3144 element_id_, ElementListType::ACTIVE)); |
3225 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3145 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3226 element_id_, ElementListType::ACTIVE)); | 3146 element_id_, ElementListType::ACTIVE)); |
3227 | 3147 |
3228 animations_impl->ActivateAnimations(); | 3148 element_animations_impl_->ActivateAnimations(); |
3229 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3149 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3230 element_id_, ElementListType::PENDING)); | 3150 element_id_, ElementListType::PENDING)); |
3231 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( | 3151 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( |
3232 element_id_, ElementListType::PENDING)); | 3152 element_id_, ElementListType::PENDING)); |
3233 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3153 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3234 element_id_, ElementListType::ACTIVE)); | 3154 element_id_, ElementListType::ACTIVE)); |
3235 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( | 3155 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( |
3236 element_id_, ElementListType::ACTIVE)); | 3156 element_id_, ElementListType::ACTIVE)); |
3237 | 3157 |
3238 animations_impl->Animate(kInitialTickTime); | 3158 element_animations_impl_->Animate(kInitialTickTime); |
3239 animations_impl->UpdateState(true, events.get()); | 3159 element_animations_impl_->UpdateState(true, events.get()); |
3240 | 3160 |
3241 animations->NotifyAnimationStarted(events->events_[0]); | 3161 player_->NotifyAnimationStarted(events->events_[0]); |
3242 events->events_.clear(); | 3162 events->events_.clear(); |
3243 | 3163 |
3244 // Finish the animation. | 3164 // Finish the animation. |
3245 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 3165 element_animations_->Animate(kInitialTickTime + |
3246 animations->UpdateState(true, nullptr); | 3166 TimeDelta::FromMilliseconds(1000)); |
| 3167 element_animations_->UpdateState(true, nullptr); |
3247 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, | 3168 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, |
3248 ElementListType::ACTIVE)); | 3169 ElementListType::ACTIVE)); |
3249 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, | 3170 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, |
3250 ElementListType::ACTIVE)); | 3171 ElementListType::ACTIVE)); |
3251 | 3172 |
3252 PushProperties(); | 3173 PushProperties(); |
3253 | 3174 |
3254 // animations_impl hasn't yet ticked at/past the end of the animation. | 3175 // animations_impl hasn't yet ticked at/past the end of the animation. |
3255 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3176 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3256 element_id_, ElementListType::PENDING)); | 3177 element_id_, ElementListType::PENDING)); |
3257 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( | 3178 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( |
3258 element_id_, ElementListType::PENDING)); | 3179 element_id_, ElementListType::PENDING)); |
3259 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3180 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3260 element_id_, ElementListType::ACTIVE)); | 3181 element_id_, ElementListType::ACTIVE)); |
3261 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( | 3182 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( |
3262 element_id_, ElementListType::ACTIVE)); | 3183 element_id_, ElementListType::ACTIVE)); |
3263 | 3184 |
3264 animations_impl->Animate(kInitialTickTime + | 3185 element_animations_impl_->Animate(kInitialTickTime + |
3265 TimeDelta::FromMilliseconds(1000)); | 3186 TimeDelta::FromMilliseconds(1000)); |
3266 animations_impl->UpdateState(true, events.get()); | 3187 element_animations_impl_->UpdateState(true, events.get()); |
3267 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3188 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3268 element_id_, ElementListType::PENDING)); | 3189 element_id_, ElementListType::PENDING)); |
3269 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3190 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3270 element_id_, ElementListType::PENDING)); | 3191 element_id_, ElementListType::PENDING)); |
3271 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3192 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3272 element_id_, ElementListType::ACTIVE)); | 3193 element_id_, ElementListType::ACTIVE)); |
3273 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3194 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3274 element_id_, ElementListType::ACTIVE)); | 3195 element_id_, ElementListType::ACTIVE)); |
3275 | 3196 |
3276 // Case 2: An animation that's removed before it finishes. | 3197 // Case 2: An animation that's removed before it finishes. |
3277 int animation_id = | 3198 int animation_id = AddAnimatedFilterToPlayer(player_.get(), 10.0, 0.f, 1.f); |
3278 AddAnimatedFilterToElementAnimations(animations.get(), 10.0, 0.f, 1.f); | |
3279 EXPECT_TRUE(client_.GetHasPotentialFilterAnimation(element_id_, | 3199 EXPECT_TRUE(client_.GetHasPotentialFilterAnimation(element_id_, |
3280 ElementListType::ACTIVE)); | 3200 ElementListType::ACTIVE)); |
3281 EXPECT_TRUE(client_.GetFilterIsCurrentlyAnimating(element_id_, | 3201 EXPECT_TRUE(client_.GetFilterIsCurrentlyAnimating(element_id_, |
3282 ElementListType::ACTIVE)); | 3202 ElementListType::ACTIVE)); |
3283 | 3203 |
3284 PushProperties(); | 3204 PushProperties(); |
3285 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3205 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3286 element_id_, ElementListType::PENDING)); | 3206 element_id_, ElementListType::PENDING)); |
3287 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( | 3207 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( |
3288 element_id_, ElementListType::PENDING)); | 3208 element_id_, ElementListType::PENDING)); |
3289 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3209 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3290 element_id_, ElementListType::ACTIVE)); | 3210 element_id_, ElementListType::ACTIVE)); |
3291 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3211 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3292 element_id_, ElementListType::ACTIVE)); | 3212 element_id_, ElementListType::ACTIVE)); |
3293 | 3213 |
3294 animations_impl->ActivateAnimations(); | 3214 element_animations_impl_->ActivateAnimations(); |
3295 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3215 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3296 element_id_, ElementListType::ACTIVE)); | 3216 element_id_, ElementListType::ACTIVE)); |
3297 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( | 3217 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( |
3298 element_id_, ElementListType::ACTIVE)); | 3218 element_id_, ElementListType::ACTIVE)); |
3299 | 3219 |
3300 animations_impl->Animate(kInitialTickTime + | 3220 element_animations_impl_->Animate(kInitialTickTime + |
3301 TimeDelta::FromMilliseconds(2000)); | 3221 TimeDelta::FromMilliseconds(2000)); |
3302 animations_impl->UpdateState(true, events.get()); | 3222 element_animations_impl_->UpdateState(true, events.get()); |
3303 | 3223 |
3304 animations->NotifyAnimationStarted(events->events_[0]); | 3224 player_->NotifyAnimationStarted(events->events_[0]); |
3305 events->events_.clear(); | 3225 events->events_.clear(); |
3306 | 3226 |
3307 animations->RemoveAnimation(animation_id); | 3227 player_->RemoveAnimation(animation_id); |
3308 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, | 3228 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, |
3309 ElementListType::ACTIVE)); | 3229 ElementListType::ACTIVE)); |
3310 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, | 3230 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, |
3311 ElementListType::ACTIVE)); | 3231 ElementListType::ACTIVE)); |
3312 | 3232 |
3313 PushProperties(); | 3233 PushProperties(); |
3314 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3234 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3315 element_id_, ElementListType::PENDING)); | 3235 element_id_, ElementListType::PENDING)); |
3316 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3236 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3317 element_id_, ElementListType::PENDING)); | 3237 element_id_, ElementListType::PENDING)); |
3318 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3238 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3319 element_id_, ElementListType::ACTIVE)); | 3239 element_id_, ElementListType::ACTIVE)); |
3320 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( | 3240 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( |
3321 element_id_, ElementListType::ACTIVE)); | 3241 element_id_, ElementListType::ACTIVE)); |
3322 | 3242 |
3323 animations_impl->ActivateAnimations(); | 3243 element_animations_impl_->ActivateAnimations(); |
3324 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3244 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3325 element_id_, ElementListType::ACTIVE)); | 3245 element_id_, ElementListType::ACTIVE)); |
3326 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3246 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3327 element_id_, ElementListType::ACTIVE)); | 3247 element_id_, ElementListType::ACTIVE)); |
3328 | 3248 |
3329 // Case 3: An animation that's aborted before it finishes. | 3249 // Case 3: An animation that's aborted before it finishes. |
3330 animation_id = | 3250 animation_id = AddAnimatedFilterToPlayer(player_.get(), 10.0, 0.f, 0.5f); |
3331 AddAnimatedFilterToElementAnimations(animations.get(), 10.0, 0.f, 0.5f); | |
3332 EXPECT_TRUE(client_.GetHasPotentialFilterAnimation(element_id_, | 3251 EXPECT_TRUE(client_.GetHasPotentialFilterAnimation(element_id_, |
3333 ElementListType::ACTIVE)); | 3252 ElementListType::ACTIVE)); |
3334 EXPECT_TRUE(client_.GetFilterIsCurrentlyAnimating(element_id_, | 3253 EXPECT_TRUE(client_.GetFilterIsCurrentlyAnimating(element_id_, |
3335 ElementListType::ACTIVE)); | 3254 ElementListType::ACTIVE)); |
3336 | 3255 |
3337 PushProperties(); | 3256 PushProperties(); |
3338 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3257 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3339 element_id_, ElementListType::PENDING)); | 3258 element_id_, ElementListType::PENDING)); |
3340 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( | 3259 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( |
3341 element_id_, ElementListType::PENDING)); | 3260 element_id_, ElementListType::PENDING)); |
3342 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3261 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3343 element_id_, ElementListType::ACTIVE)); | 3262 element_id_, ElementListType::ACTIVE)); |
3344 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3263 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3345 element_id_, ElementListType::ACTIVE)); | 3264 element_id_, ElementListType::ACTIVE)); |
3346 | 3265 |
3347 animations_impl->ActivateAnimations(); | 3266 element_animations_impl_->ActivateAnimations(); |
3348 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3267 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3349 element_id_, ElementListType::ACTIVE)); | 3268 element_id_, ElementListType::ACTIVE)); |
3350 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( | 3269 EXPECT_TRUE(client_impl_.GetFilterIsCurrentlyAnimating( |
3351 element_id_, ElementListType::ACTIVE)); | 3270 element_id_, ElementListType::ACTIVE)); |
3352 | 3271 |
3353 animations_impl->Animate(kInitialTickTime + | 3272 element_animations_impl_->Animate(kInitialTickTime + |
3354 TimeDelta::FromMilliseconds(2000)); | 3273 TimeDelta::FromMilliseconds(2000)); |
3355 animations_impl->UpdateState(true, events.get()); | 3274 element_animations_impl_->UpdateState(true, events.get()); |
3356 | 3275 |
3357 animations->NotifyAnimationStarted(events->events_[0]); | 3276 player_->NotifyAnimationStarted(events->events_[0]); |
3358 events->events_.clear(); | 3277 events->events_.clear(); |
3359 | 3278 |
3360 animations_impl->AbortAnimations(TargetProperty::FILTER); | 3279 player_impl_->AbortAnimations(TargetProperty::FILTER, false); |
3361 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3280 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3362 element_id_, ElementListType::PENDING)); | 3281 element_id_, ElementListType::PENDING)); |
3363 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3282 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3364 element_id_, ElementListType::PENDING)); | 3283 element_id_, ElementListType::PENDING)); |
3365 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3284 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3366 element_id_, ElementListType::ACTIVE)); | 3285 element_id_, ElementListType::ACTIVE)); |
3367 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3286 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3368 element_id_, ElementListType::ACTIVE)); | 3287 element_id_, ElementListType::ACTIVE)); |
3369 | 3288 |
3370 animations_impl->Animate(kInitialTickTime + | 3289 element_animations_impl_->Animate(kInitialTickTime + |
3371 TimeDelta::FromMilliseconds(4000)); | 3290 TimeDelta::FromMilliseconds(4000)); |
3372 animations_impl->UpdateState(true, events.get()); | 3291 element_animations_impl_->UpdateState(true, events.get()); |
3373 | 3292 |
3374 animations->NotifyAnimationAborted(events->events_[0]); | 3293 element_animations_->NotifyAnimationAborted(events->events_[0]); |
3375 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, | 3294 EXPECT_FALSE(client_.GetHasPotentialFilterAnimation(element_id_, |
3376 ElementListType::ACTIVE)); | 3295 ElementListType::ACTIVE)); |
3377 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, | 3296 EXPECT_FALSE(client_.GetFilterIsCurrentlyAnimating(element_id_, |
3378 ElementListType::ACTIVE)); | 3297 ElementListType::ACTIVE)); |
3379 | 3298 |
3380 // Case 4 : An animation that's not in effect. | 3299 // Case 4 : An animation that's not in effect. |
3381 animation_id = | 3300 animation_id = AddAnimatedFilterToPlayer(player_.get(), 1.0, 0.f, 0.5f); |
3382 AddAnimatedFilterToElementAnimations(animations.get(), 1.0, 0.f, 0.5f); | 3301 player_->GetAnimationById(animation_id) |
3383 animations->GetAnimationById(animation_id) | |
3384 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); | 3302 ->set_time_offset(base::TimeDelta::FromMilliseconds(-10000)); |
3385 animations->GetAnimationById(animation_id) | 3303 player_->GetAnimationById(animation_id) |
3386 ->set_fill_mode(Animation::FillMode::NONE); | 3304 ->set_fill_mode(Animation::FillMode::NONE); |
3387 | 3305 |
3388 PushProperties(); | 3306 PushProperties(); |
3389 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3307 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3390 element_id_, ElementListType::PENDING)); | 3308 element_id_, ElementListType::PENDING)); |
3391 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3309 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3392 element_id_, ElementListType::PENDING)); | 3310 element_id_, ElementListType::PENDING)); |
3393 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( | 3311 EXPECT_FALSE(client_impl_.GetHasPotentialFilterAnimation( |
3394 element_id_, ElementListType::ACTIVE)); | 3312 element_id_, ElementListType::ACTIVE)); |
3395 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3313 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3396 element_id_, ElementListType::ACTIVE)); | 3314 element_id_, ElementListType::ACTIVE)); |
3397 | 3315 |
3398 animations_impl->ActivateAnimations(); | 3316 element_animations_impl_->ActivateAnimations(); |
3399 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( | 3317 EXPECT_TRUE(client_impl_.GetHasPotentialFilterAnimation( |
3400 element_id_, ElementListType::ACTIVE)); | 3318 element_id_, ElementListType::ACTIVE)); |
3401 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( | 3319 EXPECT_FALSE(client_impl_.GetFilterIsCurrentlyAnimating( |
3402 element_id_, ElementListType::ACTIVE)); | 3320 element_id_, ElementListType::ACTIVE)); |
3403 } | 3321 } |
3404 | 3322 |
3405 TEST_F(ElementAnimationsTest, ClippedOpacityValues) { | 3323 TEST_F(ElementAnimationsTest, ClippedOpacityValues) { |
3406 CreateTestLayer(false, false); | 3324 CreateTestLayer(false, false); |
3407 AttachTimelinePlayerLayer(); | 3325 AttachTimelinePlayerLayer(); |
3408 | 3326 |
3409 scoped_refptr<ElementAnimations> animations = element_animations(); | 3327 AddOpacityTransitionToPlayer(player_.get(), 1, 1.f, 2.f, true); |
3410 | 3328 |
3411 AddOpacityTransitionToElementAnimations(animations.get(), 1, 1.f, 2.f, true); | 3329 element_animations_->Animate(kInitialTickTime); |
3412 | |
3413 animations->Animate(kInitialTickTime); | |
3414 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 3330 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
3415 | 3331 |
3416 // Opacity values are clipped [0,1] | 3332 // Opacity values are clipped [0,1] |
3417 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 3333 element_animations_->Animate(kInitialTickTime + |
| 3334 TimeDelta::FromMilliseconds(1000)); |
3418 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 3335 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
3419 } | 3336 } |
3420 | 3337 |
3421 TEST_F(ElementAnimationsTest, ClippedNegativeOpacityValues) { | 3338 TEST_F(ElementAnimationsTest, ClippedNegativeOpacityValues) { |
3422 CreateTestLayer(false, false); | 3339 CreateTestLayer(false, false); |
3423 AttachTimelinePlayerLayer(); | 3340 AttachTimelinePlayerLayer(); |
3424 | 3341 |
3425 scoped_refptr<ElementAnimations> animations = element_animations(); | 3342 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, -2.f, true); |
3426 | 3343 |
3427 AddOpacityTransitionToElementAnimations(animations.get(), 1, 0.f, -2.f, true); | 3344 element_animations_->Animate(kInitialTickTime); |
3428 | |
3429 animations->Animate(kInitialTickTime); | |
3430 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 3345 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
3431 | 3346 |
3432 // Opacity values are clipped [0,1] | 3347 // Opacity values are clipped [0,1] |
3433 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 3348 element_animations_->Animate(kInitialTickTime + |
| 3349 TimeDelta::FromMilliseconds(1000)); |
3434 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 3350 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
3435 } | 3351 } |
3436 | 3352 |
3437 TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) { | 3353 TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) { |
3438 CreateTestLayer(true, true); | 3354 CreateTestLayer(true, true); |
3439 AttachTimelinePlayerLayer(); | 3355 AttachTimelinePlayerLayer(); |
3440 CreateImplTimelineAndPlayer(); | 3356 CreateImplTimelineAndPlayer(); |
3441 | 3357 |
3442 scoped_refptr<ElementAnimations> animations = element_animations(); | |
3443 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
3444 | |
3445 auto events = host_impl_->CreateEvents(); | 3358 auto events = host_impl_->CreateEvents(); |
3446 | 3359 |
3447 const int animation_id = AddOpacityTransitionToElementAnimations( | 3360 const int animation_id = |
3448 animations.get(), 1, 0.5f, 1.f, true); | 3361 AddOpacityTransitionToPlayer(player_.get(), 1, 0.5f, 1.f, true); |
3449 | 3362 |
3450 PushProperties(); | 3363 PushProperties(); |
3451 animations_impl->ActivateAnimations(); | 3364 player_impl_->ActivateAnimations(); |
3452 animations_impl->Animate(kInitialTickTime); | 3365 element_animations_impl_->Animate(kInitialTickTime); |
3453 animations_impl->UpdateState(true, events.get()); | 3366 element_animations_impl_->UpdateState(true, events.get()); |
3454 EXPECT_EQ(Animation::RUNNING, | 3367 EXPECT_EQ(Animation::RUNNING, |
3455 animations_impl->GetAnimationById(animation_id)->run_state()); | 3368 player_impl_->GetAnimationById(animation_id)->run_state()); |
3456 EXPECT_EQ(0.5f, | 3369 EXPECT_EQ(0.5f, |
3457 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 3370 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
3458 EXPECT_EQ(0.5f, | 3371 EXPECT_EQ(0.5f, |
3459 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 3372 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
3460 | 3373 |
3461 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 3374 EXPECT_TRUE( |
3462 ->affects_pending_elements()); | 3375 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); |
3463 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 3376 EXPECT_TRUE( |
3464 ->affects_active_elements()); | 3377 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); |
3465 | 3378 |
3466 // Delete the animation on the main-thread animations. | 3379 // Delete the animation on the main-thread animations. |
3467 animations->RemoveAnimation( | 3380 player_->RemoveAnimation( |
3468 animations->GetAnimation(TargetProperty::OPACITY)->id()); | 3381 player_->GetAnimation(TargetProperty::OPACITY)->id()); |
3469 PushProperties(); | 3382 PushProperties(); |
3470 | 3383 |
3471 // The animation should no longer affect pending elements. | 3384 // The animation should no longer affect pending elements. |
3472 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id) | 3385 EXPECT_FALSE( |
3473 ->affects_pending_elements()); | 3386 player_impl_->GetAnimationById(animation_id)->affects_pending_elements()); |
3474 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 3387 EXPECT_TRUE( |
3475 ->affects_active_elements()); | 3388 player_impl_->GetAnimationById(animation_id)->affects_active_elements()); |
3476 | 3389 |
3477 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 3390 element_animations_impl_->Animate(kInitialTickTime + |
3478 animations_impl->UpdateState(true, events.get()); | 3391 TimeDelta::FromMilliseconds(500)); |
| 3392 element_animations_impl_->UpdateState(true, events.get()); |
3479 | 3393 |
3480 // Only the active observer should have been ticked. | 3394 // Only the active observer should have been ticked. |
3481 EXPECT_EQ(0.5f, | 3395 EXPECT_EQ(0.5f, |
3482 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 3396 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
3483 EXPECT_EQ(0.75f, | 3397 EXPECT_EQ(0.75f, |
3484 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 3398 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
3485 | 3399 |
3486 animations_impl->ActivateAnimations(); | 3400 player_impl_->ActivateAnimations(); |
3487 | 3401 |
3488 // Activation should cause the animation to be deleted. | 3402 // Activation should cause the animation to be deleted. |
3489 EXPECT_FALSE(animations_impl->HasAnyAnimation()); | 3403 EXPECT_FALSE(player_impl_->has_any_animation()); |
3490 } | 3404 } |
3491 | 3405 |
3492 // Tests that an animation that affects only active elements won't block | 3406 // Tests that an animation that affects only active elements won't block |
3493 // an animation that affects only pending elements from starting. | 3407 // an animation that affects only pending elements from starting. |
3494 TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) { | 3408 TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) { |
3495 CreateTestLayer(true, true); | 3409 CreateTestLayer(true, true); |
3496 AttachTimelinePlayerLayer(); | 3410 AttachTimelinePlayerLayer(); |
3497 CreateImplTimelineAndPlayer(); | 3411 CreateImplTimelineAndPlayer(); |
3498 | 3412 |
3499 scoped_refptr<ElementAnimations> animations = element_animations(); | |
3500 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
3501 | |
3502 auto events = host_impl_->CreateEvents(); | 3413 auto events = host_impl_->CreateEvents(); |
3503 | 3414 |
3504 const int first_animation_id = AddOpacityTransitionToElementAnimations( | 3415 const int first_animation_id = |
3505 animations.get(), 1, 0.f, 1.f, true); | 3416 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, 1.f, true); |
3506 | 3417 |
3507 PushProperties(); | 3418 PushProperties(); |
3508 animations_impl->ActivateAnimations(); | 3419 player_impl_->ActivateAnimations(); |
3509 animations_impl->Animate(kInitialTickTime); | 3420 element_animations_impl_->Animate(kInitialTickTime); |
3510 animations_impl->UpdateState(true, events.get()); | 3421 element_animations_impl_->UpdateState(true, events.get()); |
3511 | 3422 |
3512 // Remove the first animation from the main-thread animations, and add a | 3423 // Remove the first animation from the main-thread animations, and add a |
3513 // new animation affecting the same property. | 3424 // new animation affecting the same property. |
3514 animations->RemoveAnimation( | 3425 player_->RemoveAnimation( |
3515 animations->GetAnimation(TargetProperty::OPACITY)->id()); | 3426 player_->GetAnimation(TargetProperty::OPACITY)->id()); |
3516 const int second_animation_id = AddOpacityTransitionToElementAnimations( | 3427 const int second_animation_id = |
3517 animations.get(), 1, 1.f, 0.5f, true); | 3428 AddOpacityTransitionToPlayer(player_.get(), 1, 1.f, 0.5f, true); |
3518 PushProperties(); | 3429 PushProperties(); |
3519 | 3430 |
3520 // The original animation should only affect active elements, and the new | 3431 // The original animation should only affect active elements, and the new |
3521 // animation should only affect pending elements. | 3432 // animation should only affect pending elements. |
3522 EXPECT_FALSE(animations_impl->GetAnimationById(first_animation_id) | 3433 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id) |
3523 ->affects_pending_elements()); | 3434 ->affects_pending_elements()); |
3524 EXPECT_TRUE(animations_impl->GetAnimationById(first_animation_id) | 3435 EXPECT_TRUE(player_impl_->GetAnimationById(first_animation_id) |
3525 ->affects_active_elements()); | 3436 ->affects_active_elements()); |
3526 EXPECT_TRUE(animations_impl->GetAnimationById(second_animation_id) | 3437 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id) |
3527 ->affects_pending_elements()); | 3438 ->affects_pending_elements()); |
3528 EXPECT_FALSE(animations_impl->GetAnimationById(second_animation_id) | 3439 EXPECT_FALSE(player_impl_->GetAnimationById(second_animation_id) |
3529 ->affects_active_elements()); | 3440 ->affects_active_elements()); |
3530 | 3441 |
3531 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 3442 element_animations_impl_->Animate(kInitialTickTime + |
3532 animations_impl->UpdateState(true, events.get()); | 3443 TimeDelta::FromMilliseconds(500)); |
| 3444 element_animations_impl_->UpdateState(true, events.get()); |
3533 | 3445 |
3534 // The original animation should still be running, and the new animation | 3446 // The original animation should still be running, and the new animation |
3535 // should be starting. | 3447 // should be starting. |
3536 EXPECT_EQ(Animation::RUNNING, | 3448 EXPECT_EQ(Animation::RUNNING, |
3537 animations_impl->GetAnimationById(first_animation_id)->run_state()); | 3449 player_impl_->GetAnimationById(first_animation_id)->run_state()); |
3538 EXPECT_EQ( | 3450 EXPECT_EQ(Animation::STARTING, |
3539 Animation::STARTING, | 3451 player_impl_->GetAnimationById(second_animation_id)->run_state()); |
3540 animations_impl->GetAnimationById(second_animation_id)->run_state()); | |
3541 | 3452 |
3542 // The active observer should have been ticked by the original animation, | 3453 // The active observer should have been ticked by the original animation, |
3543 // and the pending observer should have been ticked by the new animation. | 3454 // and the pending observer should have been ticked by the new animation. |
3544 EXPECT_EQ(1.f, | 3455 EXPECT_EQ(1.f, |
3545 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 3456 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
3546 EXPECT_EQ(0.5f, | 3457 EXPECT_EQ(0.5f, |
3547 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 3458 client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
3548 | 3459 |
3549 animations_impl->ActivateAnimations(); | 3460 player_impl_->ActivateAnimations(); |
3550 | 3461 |
3551 // The original animation should have been deleted, and the new animation | 3462 // The original animation should have been deleted, and the new animation |
3552 // should now affect both elements. | 3463 // should now affect both elements. |
3553 EXPECT_FALSE(animations_impl->GetAnimationById(first_animation_id)); | 3464 EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)); |
3554 EXPECT_TRUE(animations_impl->GetAnimationById(second_animation_id) | 3465 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id) |
3555 ->affects_pending_elements()); | 3466 ->affects_pending_elements()); |
3556 EXPECT_TRUE(animations_impl->GetAnimationById(second_animation_id) | 3467 EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id) |
3557 ->affects_active_elements()); | 3468 ->affects_active_elements()); |
3558 | 3469 |
3559 animations_impl->Animate(kInitialTickTime + | 3470 element_animations_impl_->Animate(kInitialTickTime + |
3560 TimeDelta::FromMilliseconds(1000)); | 3471 TimeDelta::FromMilliseconds(1000)); |
3561 animations_impl->UpdateState(true, events.get()); | 3472 element_animations_impl_->UpdateState(true, events.get()); |
3562 | 3473 |
3563 // The new animation should be running, and the active observer should have | 3474 // The new animation should be running, and the active observer should have |
3564 // been ticked at the new animation's starting point. | 3475 // been ticked at the new animation's starting point. |
3565 EXPECT_EQ( | 3476 EXPECT_EQ(Animation::RUNNING, |
3566 Animation::RUNNING, | 3477 player_impl_->GetAnimationById(second_animation_id)->run_state()); |
3567 animations_impl->GetAnimationById(second_animation_id)->run_state()); | |
3568 EXPECT_EQ(1.f, | 3478 EXPECT_EQ(1.f, |
3569 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); | 3479 client_impl_.GetOpacity(element_id_, ElementListType::PENDING)); |
3570 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 3480 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
3571 } | 3481 } |
3572 | 3482 |
3573 TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) { | 3483 TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) { |
3574 CreateTestLayer(false, false); | 3484 CreateTestLayer(false, false); |
3575 AttachTimelinePlayerLayer(); | 3485 AttachTimelinePlayerLayer(); |
3576 | 3486 |
3577 scoped_refptr<ElementAnimations> animations = element_animations(); | |
3578 | |
3579 // Create an animation that initially affects only pending elements. | 3487 // Create an animation that initially affects only pending elements. |
3580 std::unique_ptr<Animation> animation(CreateAnimation( | 3488 std::unique_ptr<Animation> animation(CreateAnimation( |
3581 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 3489 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
3582 1, TargetProperty::OPACITY)); | 3490 1, TargetProperty::OPACITY)); |
3583 animation->set_affects_active_elements(false); | 3491 animation->set_affects_active_elements(false); |
3584 | 3492 |
3585 animations->AddAnimation(std::move(animation)); | 3493 player_->AddAnimation(std::move(animation)); |
3586 animations->Animate(kInitialTickTime); | 3494 element_animations_->Animate(kInitialTickTime); |
3587 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty( | 3495 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3588 TargetProperty::OPACITY, ElementListType::PENDING)); | 3496 ElementListType::PENDING)); |
3589 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3497 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3590 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3498 ElementListType::ACTIVE)); |
3591 animations->UpdateState(true, nullptr); | 3499 element_animations_->UpdateState(true, nullptr); |
3592 EXPECT_TRUE(animations->HasActiveAnimation()); | 3500 EXPECT_TRUE(player_->HasActiveAnimation()); |
3593 | 3501 |
3594 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty( | 3502 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3595 TargetProperty::OPACITY, ElementListType::PENDING)); | 3503 ElementListType::PENDING)); |
3596 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3504 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3597 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3505 ElementListType::ACTIVE)); |
3598 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3506 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, |
3599 TargetProperty::FILTER, ElementListType::PENDING)); | 3507 ElementListType::PENDING)); |
3600 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3508 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, |
3601 TargetProperty::FILTER, ElementListType::ACTIVE)); | 3509 ElementListType::ACTIVE)); |
3602 | 3510 |
3603 animations->ActivateAnimations(); | 3511 player_->ActivateAnimations(); |
3604 | 3512 |
3605 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty( | 3513 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3606 TargetProperty::OPACITY, ElementListType::PENDING)); | 3514 ElementListType::PENDING)); |
3607 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty( | 3515 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3608 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3516 ElementListType::ACTIVE)); |
3609 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3517 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, |
3610 TargetProperty::FILTER, ElementListType::PENDING)); | 3518 ElementListType::PENDING)); |
3611 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3519 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, |
3612 TargetProperty::FILTER, ElementListType::ACTIVE)); | 3520 ElementListType::ACTIVE)); |
3613 | 3521 |
3614 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(10)); | 3522 element_animations_->Animate(kInitialTickTime + |
3615 animations->UpdateState(true, nullptr); | 3523 TimeDelta::FromMilliseconds(10)); |
| 3524 element_animations_->UpdateState(true, nullptr); |
3616 | 3525 |
3617 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty( | 3526 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3618 TargetProperty::OPACITY, ElementListType::PENDING)); | 3527 ElementListType::PENDING)); |
3619 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty( | 3528 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3620 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3529 ElementListType::ACTIVE)); |
3621 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3530 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, |
3622 TargetProperty::FILTER, ElementListType::PENDING)); | 3531 ElementListType::PENDING)); |
3623 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3532 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, |
3624 TargetProperty::FILTER, ElementListType::ACTIVE)); | 3533 ElementListType::ACTIVE)); |
3625 | 3534 |
3626 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 3535 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
3627 | 3536 |
3628 // Tick past the end of the animation. | 3537 // Tick past the end of the animation. |
3629 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1100)); | 3538 element_animations_->Animate(kInitialTickTime + |
3630 animations->UpdateState(true, nullptr); | 3539 TimeDelta::FromMilliseconds(1100)); |
| 3540 element_animations_->UpdateState(true, nullptr); |
3631 | 3541 |
3632 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3542 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3633 TargetProperty::OPACITY, ElementListType::PENDING)); | 3543 ElementListType::PENDING)); |
3634 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3544 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3635 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3545 ElementListType::ACTIVE)); |
3636 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3546 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, |
3637 TargetProperty::FILTER, ElementListType::PENDING)); | 3547 ElementListType::PENDING)); |
3638 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3548 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, |
3639 TargetProperty::FILTER, ElementListType::ACTIVE)); | 3549 ElementListType::ACTIVE)); |
3640 | 3550 |
3641 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 3551 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
3642 } | 3552 } |
3643 | 3553 |
3644 TEST_F(ElementAnimationsTest, TestIsAnimatingPropertyTimeOffsetFillMode) { | 3554 TEST_F(ElementAnimationsTest, TestIsAnimatingPropertyTimeOffsetFillMode) { |
3645 CreateTestLayer(false, false); | 3555 CreateTestLayer(false, false); |
3646 AttachTimelinePlayerLayer(); | 3556 AttachTimelinePlayerLayer(); |
3647 | 3557 |
3648 scoped_refptr<ElementAnimations> animations = element_animations(); | |
3649 | |
3650 // Create an animation that initially affects only pending elements, and has | 3558 // Create an animation that initially affects only pending elements, and has |
3651 // a start delay of 2 seconds. | 3559 // a start delay of 2 seconds. |
3652 std::unique_ptr<Animation> animation(CreateAnimation( | 3560 std::unique_ptr<Animation> animation(CreateAnimation( |
3653 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 3561 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
3654 1, TargetProperty::OPACITY)); | 3562 1, TargetProperty::OPACITY)); |
3655 animation->set_fill_mode(Animation::FillMode::NONE); | 3563 animation->set_fill_mode(Animation::FillMode::NONE); |
3656 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); | 3564 animation->set_time_offset(TimeDelta::FromMilliseconds(-2000)); |
3657 animation->set_affects_active_elements(false); | 3565 animation->set_affects_active_elements(false); |
3658 | 3566 |
3659 animations->AddAnimation(std::move(animation)); | 3567 player_->AddAnimation(std::move(animation)); |
3660 | 3568 |
3661 animations->Animate(kInitialTickTime); | 3569 element_animations_->Animate(kInitialTickTime); |
3662 | 3570 |
3663 // Since the animation has a start delay, the elements it affects have a | 3571 // Since the animation has a start delay, the elements it affects have a |
3664 // potentially running transform animation but aren't currently animating | 3572 // potentially running transform animation but aren't currently animating |
3665 // transform. | 3573 // transform. |
3666 EXPECT_TRUE(animations->IsPotentiallyAnimatingProperty( | 3574 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty( |
3667 TargetProperty::OPACITY, ElementListType::PENDING)); | 3575 TargetProperty::OPACITY, ElementListType::PENDING)); |
3668 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( | 3576 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( |
3669 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3577 TargetProperty::OPACITY, ElementListType::ACTIVE)); |
3670 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3578 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3671 TargetProperty::OPACITY, ElementListType::PENDING)); | 3579 ElementListType::PENDING)); |
3672 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3580 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3673 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3581 ElementListType::ACTIVE)); |
3674 EXPECT_TRUE(animations->HasActiveAnimation()); | 3582 EXPECT_TRUE(player_->HasActiveAnimation()); |
3675 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( | 3583 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( |
3676 TargetProperty::FILTER, ElementListType::PENDING)); | 3584 TargetProperty::FILTER, ElementListType::PENDING)); |
3677 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( | 3585 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( |
3678 TargetProperty::FILTER, ElementListType::ACTIVE)); | 3586 TargetProperty::FILTER, ElementListType::ACTIVE)); |
3679 | 3587 |
3680 animations->ActivateAnimations(); | 3588 player_->ActivateAnimations(); |
3681 | 3589 |
3682 EXPECT_TRUE(animations->IsPotentiallyAnimatingProperty( | 3590 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty( |
3683 TargetProperty::OPACITY, ElementListType::PENDING)); | 3591 TargetProperty::OPACITY, ElementListType::PENDING)); |
3684 EXPECT_TRUE(animations->IsPotentiallyAnimatingProperty( | 3592 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(TargetProperty::OPACITY, |
3685 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3593 ElementListType::ACTIVE)); |
3686 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3594 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3687 TargetProperty::OPACITY, ElementListType::PENDING)); | 3595 ElementListType::PENDING)); |
3688 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3596 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3689 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3597 ElementListType::ACTIVE)); |
3690 EXPECT_TRUE(animations->HasActiveAnimation()); | 3598 EXPECT_TRUE(player_->HasActiveAnimation()); |
3691 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( | 3599 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( |
3692 TargetProperty::FILTER, ElementListType::PENDING)); | 3600 TargetProperty::FILTER, ElementListType::PENDING)); |
3693 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( | 3601 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( |
3694 TargetProperty::FILTER, ElementListType::ACTIVE)); | 3602 TargetProperty::FILTER, ElementListType::ACTIVE)); |
3695 | 3603 |
3696 animations->UpdateState(true, nullptr); | 3604 element_animations_->UpdateState(true, nullptr); |
3697 | 3605 |
3698 // Tick past the start delay. | 3606 // Tick past the start delay. |
3699 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 3607 element_animations_->Animate(kInitialTickTime + |
3700 animations->UpdateState(true, nullptr); | 3608 TimeDelta::FromMilliseconds(2000)); |
3701 EXPECT_TRUE(animations->IsPotentiallyAnimatingProperty( | 3609 element_animations_->UpdateState(true, nullptr); |
| 3610 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty( |
3702 TargetProperty::OPACITY, ElementListType::PENDING)); | 3611 TargetProperty::OPACITY, ElementListType::PENDING)); |
3703 EXPECT_TRUE(animations->IsPotentiallyAnimatingProperty( | 3612 EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(TargetProperty::OPACITY, |
3704 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3613 ElementListType::ACTIVE)); |
3705 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty( | 3614 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3706 TargetProperty::OPACITY, ElementListType::PENDING)); | 3615 ElementListType::PENDING)); |
3707 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty( | 3616 EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3708 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3617 ElementListType::ACTIVE)); |
3709 | 3618 |
3710 // After the animaton finishes, the elements it affects have neither a | 3619 // After the animaton finishes, the elements it affects have neither a |
3711 // potentially running transform animation nor a currently running transform | 3620 // potentially running transform animation nor a currently running transform |
3712 // animation. | 3621 // animation. |
3713 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); | 3622 element_animations_->Animate(kInitialTickTime + |
3714 animations->UpdateState(true, nullptr); | 3623 TimeDelta::FromMilliseconds(4000)); |
3715 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( | 3624 element_animations_->UpdateState(true, nullptr); |
| 3625 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( |
3716 TargetProperty::OPACITY, ElementListType::PENDING)); | 3626 TargetProperty::OPACITY, ElementListType::PENDING)); |
3717 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( | 3627 EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty( |
3718 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3628 TargetProperty::OPACITY, ElementListType::ACTIVE)); |
3719 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3629 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3720 TargetProperty::OPACITY, ElementListType::PENDING)); | 3630 ElementListType::PENDING)); |
3721 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3631 EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3722 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3632 ElementListType::ACTIVE)); |
3723 } | 3633 } |
3724 | 3634 |
3725 } // namespace | 3635 } // namespace |
3726 } // namespace cc | 3636 } // namespace cc |
OLD | NEW |