Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: cc/animation/animation_player_unittest.cc

Issue 947033002: CC Animations: Establish AnimationHost, AnimationTimeline and AnimationPlayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix code review issues. Rebase. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/animation/animation_player.h"
6
7 #include "base/containers/hash_tables.h"
8 #include "cc/animation/animation_delegate.h"
9 #include "cc/animation/animation_host.h"
10 #include "cc/animation/animation_id_provider.h"
11 #include "cc/animation/animation_registrar.h"
12 #include "cc/animation/animation_timeline.h"
13 #include "cc/test/animation_test_common.h"
14 #include "cc/trees/layer_tree_mutators_client.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace cc {
19 namespace {
20
21 struct TestLayer {
22 TestLayer() { ClearMutatedProperties(); }
23
24 void ClearMutatedProperties() {
25 transform_x_ = 0;
26 transform_y_ = 0;
27
28 opacity_ = 0;
29 brightness_ = 0;
30
31 for (int i = 0; i <= Animation::LAST_TARGET_PROPERTY; ++i)
32 mutated_properties_[i] = false;
33 }
34
35 int transform_x_;
36 int transform_y_;
37
38 float opacity_;
39 float brightness_;
40 gfx::ScrollOffset scroll_offset_;
41
42 bool mutated_properties_[Animation::LAST_TARGET_PROPERTY + 1];
43 };
44
45 class TestLayerTreeMutatorsClient : public LayerTreeMutatorsClient {
46 public:
47 explicit TestLayerTreeMutatorsClient(ThreadInstance thread_instance)
48 : host_(AnimationHost::Create(thread_instance)),
49 mutators_need_commit_(false) {
50 host_->SetLayerTreeMutatorsClient(this);
51 }
52
53 ~TestLayerTreeMutatorsClient() {
54 for (auto& kv : layers_in_pending_tree_)
55 delete kv.second;
56 for (auto& kv : layers_in_active_tree_)
57 delete kv.second;
58 host_->SetLayerTreeMutatorsClient(nullptr);
59 }
60
61 void ClearMutatedProperties() {
62 for (auto& kv : layers_in_pending_tree_)
63 kv.second->ClearMutatedProperties();
64 for (auto& kv : layers_in_active_tree_)
65 kv.second->ClearMutatedProperties();
66 }
67
68 bool IsLayerInTree(int layer_id, LayerTreeType tree_type) const override {
69 return tree_type == LayerTreeType::ACTIVE
70 ? layers_in_active_tree_.count(layer_id)
71 : layers_in_pending_tree_.count(layer_id);
72 }
73
74 void SetMutatorsNeedCommit() override { mutators_need_commit_ = true; }
75
76 void SetLayerFilterMutated(int layer_id,
77 LayerTreeType tree_type,
78 const FilterOperations& filters) override {
79 for (unsigned i = 0; i < filters.size(); ++i) {
80 const FilterOperation& filter = filters.at(i);
81 if (filter.type() == FilterOperation::BRIGHTNESS) {
82 TestLayer* layer = FindTestLayer(layer_id, tree_type);
83 layer->mutated_properties_[Animation::FILTER] = true;
84 layer->brightness_ = filter.amount();
85 }
86 }
87 }
88
89 void SetLayerOpacityMutated(int layer_id,
90 LayerTreeType tree_type,
91 float opacity) override {
92 TestLayer* layer = FindTestLayer(layer_id, tree_type);
93 layer->mutated_properties_[Animation::OPACITY] = true;
94 layer->opacity_ = opacity;
95 }
96
97 void SetLayerTransformMutated(int layer_id,
98 LayerTreeType tree_type,
99 const gfx::Transform& transform) override {
100 TestLayer* layer = FindTestLayer(layer_id, tree_type);
101 layer->mutated_properties_[Animation::TRANSFORM] = true;
102 gfx::Vector2dF vec = transform.To2dTranslation();
103 layer->transform_x_ = static_cast<int>(vec.x());
104 layer->transform_y_ = static_cast<int>(vec.y());
105 }
106
107 void SetLayerScrollOffsetMutated(
108 int layer_id,
109 LayerTreeType tree_type,
110 const gfx::ScrollOffset& scroll_offset) override {
111 TestLayer* layer = FindTestLayer(layer_id, tree_type);
112 layer->mutated_properties_[Animation::SCROLL_OFFSET] = true;
113 layer->scroll_offset_ = scroll_offset;
114 }
115
116 bool mutators_need_commit() const { return mutators_need_commit_; }
117 void set_mutators_need_commit(bool need) { mutators_need_commit_ = need; }
118
119 void RegisterLayer(int layer_id, LayerTreeType tree_type) {
120 LayerIdToTestLayer& layers_in_tree = tree_type == LayerTreeType::ACTIVE
121 ? layers_in_active_tree_
122 : layers_in_pending_tree_;
123 DCHECK(layers_in_tree.find(layer_id) == layers_in_tree.end());
124 layers_in_tree.insert(std::make_pair(layer_id, new TestLayer()));
125
126 DCHECK(host_);
127 host_->RegisterLayer(layer_id, tree_type);
128 }
129
130 void UnregisterLayer(int layer_id, LayerTreeType tree_type) {
131 DCHECK(host_);
132 host_->UnregisterLayer(layer_id, tree_type);
133
134 LayerIdToTestLayer& layers_in_tree = tree_type == LayerTreeType::ACTIVE
135 ? layers_in_active_tree_
136 : layers_in_pending_tree_;
137 auto kv = layers_in_tree.find(layer_id);
138 DCHECK(kv != layers_in_tree.end());
139 delete kv->second;
140 layers_in_tree.erase(kv);
141 }
142
143 AnimationHost* host() {
144 DCHECK(host_);
145 return host_.get();
146 }
147
148 bool IsPropertyMutated(int layer_id,
149 LayerTreeType tree_type,
150 Animation::TargetProperty property) const {
151 TestLayer* layer = FindTestLayer(layer_id, tree_type);
152 return layer->mutated_properties_[property];
153 }
154
155 void ExpectFilterPropertyMutated(int layer_id,
156 LayerTreeType tree_type,
157 float brightness) const {
158 TestLayer* layer = FindTestLayer(layer_id, tree_type);
159 EXPECT_TRUE(layer->mutated_properties_[Animation::OPACITY]);
160 EXPECT_EQ(brightness, layer->brightness_);
161 }
162
163 void ExpectOpacityPropertyMutated(int layer_id,
164 LayerTreeType tree_type,
165 float opacity) const {
166 TestLayer* layer = FindTestLayer(layer_id, tree_type);
167 EXPECT_TRUE(layer->mutated_properties_[Animation::OPACITY]);
168 EXPECT_EQ(opacity, layer->opacity_);
169 }
170
171 void ExpectTransformPropertyMutated(int layer_id,
172 LayerTreeType tree_type,
173 int transform_x,
174 int transform_y) const {
175 TestLayer* layer = FindTestLayer(layer_id, tree_type);
176 EXPECT_TRUE(layer->mutated_properties_[Animation::OPACITY]);
177 EXPECT_EQ(transform_x, layer->transform_x_);
178 EXPECT_EQ(transform_y, layer->transform_y_);
179 }
180
181 void ExpectScrollOffsetPropertyMutated(
182 int layer_id,
183 LayerTreeType tree_type,
184 const gfx::ScrollOffset& scroll_offset) const {
185 TestLayer* layer = FindTestLayer(layer_id, tree_type);
186 EXPECT_TRUE(layer->mutated_properties_[Animation::OPACITY]);
187 EXPECT_EQ(scroll_offset, layer->scroll_offset_);
188 }
189
190 TestLayer* FindTestLayer(int layer_id, LayerTreeType tree_type) const {
191 const LayerIdToTestLayer& layers_in_tree =
192 tree_type == LayerTreeType::ACTIVE ? layers_in_active_tree_
193 : layers_in_pending_tree_;
194 auto kv = layers_in_tree.find(layer_id);
195 DCHECK(kv != layers_in_tree.end());
196 DCHECK(kv->second);
197 return kv->second;
198 }
199
200 private:
201 scoped_ptr<AnimationHost> host_;
202
203 typedef base::hash_map<int, TestLayer*> LayerIdToTestLayer;
204 LayerIdToTestLayer layers_in_active_tree_;
205 LayerIdToTestLayer layers_in_pending_tree_;
206
207 bool mutators_need_commit_;
208 };
209
210 class TestAnimationDelegate : public AnimationDelegate {
211 public:
212 TestAnimationDelegate() : started_(false), finished_(false) {}
213
214 void NotifyAnimationStarted(base::TimeTicks monotonic_time,
215 Animation::TargetProperty target_property,
216 int group) override {
217 started_ = true;
218 }
219 void NotifyAnimationFinished(base::TimeTicks monotonic_time,
220 Animation::TargetProperty target_property,
221 int group) override {
222 finished_ = true;
223 }
224
225 bool started_;
226 bool finished_;
227 };
228
229 class AnimationPlayerTest : public testing::Test {
230 public:
231 AnimationPlayerTest()
232 : client_(ThreadInstance::MAIN),
233 client_impl_(ThreadInstance::IMPL),
234 timeline_id_(AnimationIdProvider::NextTimelineId()),
235 player_id_(AnimationIdProvider::NextPlayerId()),
236 layer_id_(1) {
237 host_ = client_.host();
238 host_impl_ = client_impl_.host();
239 }
240
241 protected:
242 void SetUp() override {
243 timeline_ = AnimationTimeline::Create(timeline_id_);
244 player_ = AnimationPlayer::Create(player_id_);
245 }
246
247 void GetImplTimelineAndPlayerByID() {
248 timeline_impl_ = host_impl_->GetTimelineById(timeline_id_);
249 EXPECT_TRUE(timeline_impl_);
250 player_impl_ = timeline_impl_->GetPlayerById(player_id_);
251 EXPECT_TRUE(player_impl_);
252 }
253
254 void ReleaseRefPtrs() {
255 player_ = nullptr;
256 timeline_ = nullptr;
257 player_impl_ = nullptr;
258 timeline_impl_ = nullptr;
259 }
260
261 void AnimateLayersTransferEvents(base::TimeTicks time,
262 unsigned expect_events) {
263 scoped_ptr<AnimationEventsVector> events =
264 host_->animation_registrar()->CreateEvents();
265
266 host_impl_->animation_registrar()->AnimateLayers(time);
267 host_impl_->animation_registrar()->UpdateAnimationState(true, events.get());
268 EXPECT_EQ(expect_events, events->size());
269
270 host_->animation_registrar()->AnimateLayers(time);
271 host_->animation_registrar()->UpdateAnimationState(true, nullptr);
272 host_->animation_registrar()->SetAnimationEvents(events.Pass());
273 }
274
275 AnimationPlayer* GetPlayerForLayerId(int layer_id) {
276 const AnimationHost::PlayersList* list =
277 host_->GetPlayersForLayerId(layer_id);
278 return list ? list->head()->value() : nullptr;
279 }
280
281 AnimationPlayer* GetImplPlayerForLayerId(int layer_id) {
282 const AnimationHost::PlayersList* list =
283 host_impl_->GetPlayersForLayerId(layer_id);
284 return list ? list->head()->value() : nullptr;
285 }
286
287 TestLayerTreeMutatorsClient client_;
288 TestLayerTreeMutatorsClient client_impl_;
289
290 AnimationHost* host_;
291 AnimationHost* host_impl_;
292
293 const int timeline_id_;
294 const int player_id_;
295 const int layer_id_;
296
297 scoped_refptr<AnimationTimeline> timeline_;
298 scoped_refptr<AnimationPlayer> player_;
299
300 scoped_refptr<AnimationTimeline> timeline_impl_;
301 scoped_refptr<AnimationPlayer> player_impl_;
302 };
303
304 TEST_F(AnimationPlayerTest, AttachDetachLayerIfTimelineAttached) {
305 host_->AddAnimationTimeline(timeline_.get());
306 timeline_->AttachPlayer(player_.get());
307 EXPECT_FALSE(player_->layer_animation_controller());
308 EXPECT_FALSE(player_->layer_id());
309
310 host_->PushPropertiesTo(host_impl_);
311
312 EXPECT_FALSE(GetImplPlayerForLayerId(layer_id_));
313
314 GetImplTimelineAndPlayerByID();
315
316 EXPECT_FALSE(player_impl_->layer_animation_controller());
317 EXPECT_FALSE(player_impl_->layer_id());
318
319 player_->AttachLayer(layer_id_);
320 EXPECT_EQ(player_, GetPlayerForLayerId(layer_id_));
321 EXPECT_TRUE(player_->layer_animation_controller());
322 EXPECT_EQ(player_->layer_id(), layer_id_);
323
324 host_->PushPropertiesTo(host_impl_);
325
326 EXPECT_EQ(player_impl_, GetImplPlayerForLayerId(layer_id_));
327 EXPECT_TRUE(player_impl_->layer_animation_controller());
328 EXPECT_EQ(player_impl_->layer_id(), layer_id_);
329
330 player_->DetachLayer();
331 EXPECT_FALSE(GetPlayerForLayerId(layer_id_));
332 EXPECT_FALSE(player_->layer_animation_controller());
333 EXPECT_FALSE(player_->layer_id());
334
335 host_->PushPropertiesTo(host_impl_);
336
337 EXPECT_FALSE(GetImplPlayerForLayerId(layer_id_));
338 EXPECT_FALSE(player_impl_->layer_animation_controller());
339 EXPECT_FALSE(player_impl_->layer_id());
340
341 timeline_->DetachPlayer(player_.get());
342 EXPECT_FALSE(player_->animation_timeline());
343 EXPECT_FALSE(player_->layer_animation_controller());
344 EXPECT_FALSE(player_->layer_id());
345 }
346
347 TEST_F(AnimationPlayerTest, AttachDetachTimelineIfLayerAttached) {
348 host_->AddAnimationTimeline(timeline_.get());
349
350 EXPECT_FALSE(player_->layer_animation_controller());
351 EXPECT_FALSE(player_->layer_id());
352
353 player_->AttachLayer(layer_id_);
354 EXPECT_FALSE(player_->animation_timeline());
355 EXPECT_FALSE(GetPlayerForLayerId(layer_id_));
356 EXPECT_FALSE(player_->layer_animation_controller());
357 EXPECT_EQ(player_->layer_id(), layer_id_);
358
359 timeline_->AttachPlayer(player_.get());
360 EXPECT_EQ(timeline_, player_->animation_timeline());
361 EXPECT_EQ(player_, GetPlayerForLayerId(layer_id_));
362 EXPECT_TRUE(player_->layer_animation_controller());
363 EXPECT_EQ(player_->layer_id(), layer_id_);
364
365 // Removing player from timeline detaches layer.
366 timeline_->DetachPlayer(player_.get());
367 EXPECT_FALSE(player_->animation_timeline());
368 EXPECT_FALSE(GetPlayerForLayerId(layer_id_));
369 EXPECT_FALSE(player_->layer_animation_controller());
370 EXPECT_FALSE(player_->layer_id());
371 }
372
373 TEST_F(AnimationPlayerTest, AttachToLayerInActiveTree) {
374 // Set up the layer which is in active tree for main thread and not
375 // yet passed onto the impl thread.
376 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
377 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING);
378
379 EXPECT_TRUE(client_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE));
380 EXPECT_FALSE(client_.IsLayerInTree(layer_id_, LayerTreeType::PENDING));
381
382 host_->AddAnimationTimeline(timeline_.get());
383
384 timeline_->AttachPlayer(player_.get());
385 player_->AttachLayer(layer_id_);
386 EXPECT_TRUE(player_->has_active_value_observer_for_testing());
387 EXPECT_FALSE(player_->has_pending_value_observer_for_testing());
388 EXPECT_TRUE(player_->layer_animation_controller());
389
390 host_->PushPropertiesTo(host_impl_);
391
392 GetImplTimelineAndPlayerByID();
393
394 EXPECT_FALSE(player_impl_->has_active_value_observer_for_testing());
395 EXPECT_TRUE(player_impl_->has_pending_value_observer_for_testing());
396
397 // Create the layer in the impl active tree.
398 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
399 EXPECT_TRUE(player_impl_->has_active_value_observer_for_testing());
400 EXPECT_TRUE(player_impl_->has_pending_value_observer_for_testing());
401
402 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE));
403 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::PENDING));
404
405 // kill layer on main thread.
406 client_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE);
407 EXPECT_FALSE(player_->has_active_value_observer_for_testing());
408 EXPECT_FALSE(player_->has_pending_value_observer_for_testing());
409 EXPECT_TRUE(player_->layer_animation_controller());
410
411 // Sync doesn't detach LayerImpl.
412 host_->PushPropertiesTo(host_impl_);
413 EXPECT_TRUE(player_impl_->has_active_value_observer_for_testing());
414 EXPECT_TRUE(player_impl_->has_pending_value_observer_for_testing());
415 EXPECT_TRUE(player_impl_->layer_animation_controller());
416
417 // Kill layer on impl thread in pending tree.
418 client_impl_.UnregisterLayer(layer_id_, LayerTreeType::PENDING);
419 EXPECT_TRUE(player_impl_->has_active_value_observer_for_testing());
420 EXPECT_FALSE(player_impl_->has_pending_value_observer_for_testing());
421 EXPECT_TRUE(player_impl_->layer_animation_controller());
422
423 // Kill layer on impl thread in active tree.
424 client_impl_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE);
425 EXPECT_FALSE(player_impl_->has_active_value_observer_for_testing());
426 EXPECT_FALSE(player_impl_->has_pending_value_observer_for_testing());
427 EXPECT_TRUE(player_impl_->layer_animation_controller());
428
429 // Sync doesn't change anything.
430 host_->PushPropertiesTo(host_impl_);
431 EXPECT_FALSE(player_impl_->has_active_value_observer_for_testing());
432 EXPECT_FALSE(player_impl_->has_pending_value_observer_for_testing());
433 EXPECT_TRUE(player_impl_->layer_animation_controller());
434
435 player_->DetachLayer();
436 EXPECT_FALSE(player_->layer_animation_controller());
437
438 // Release ptrs now to test the order of destruction.
439 ReleaseRefPtrs();
440 }
441
442 TEST_F(AnimationPlayerTest, AttachToNotYetCreatedLayer) {
443 host_->AddAnimationTimeline(timeline_.get());
444 timeline_->AttachPlayer(player_.get());
445
446 host_->PushPropertiesTo(host_impl_);
447
448 GetImplTimelineAndPlayerByID();
449
450 player_->AttachLayer(layer_id_);
451 EXPECT_FALSE(player_->has_active_value_observer_for_testing());
452 EXPECT_FALSE(player_->has_pending_value_observer_for_testing());
453 EXPECT_TRUE(player_->layer_animation_controller());
454
455 host_->PushPropertiesTo(host_impl_);
456 EXPECT_FALSE(player_impl_->has_active_value_observer_for_testing());
457 EXPECT_FALSE(player_impl_->has_pending_value_observer_for_testing());
458 EXPECT_TRUE(player_impl_->layer_animation_controller());
459
460 // Create layer.
461 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
462 EXPECT_TRUE(player_->has_active_value_observer_for_testing());
463 EXPECT_FALSE(player_->has_pending_value_observer_for_testing());
464
465 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING);
466 EXPECT_FALSE(player_impl_->has_active_value_observer_for_testing());
467 EXPECT_TRUE(player_impl_->has_pending_value_observer_for_testing());
468
469 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
470 EXPECT_TRUE(player_impl_->has_active_value_observer_for_testing());
471 EXPECT_TRUE(player_impl_->has_pending_value_observer_for_testing());
472 }
473
474 TEST_F(AnimationPlayerTest, PropertiesMutate) {
475 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
476 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING);
477 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
478
479 host_->AddAnimationTimeline(timeline_.get());
480 timeline_->AttachPlayer(player_.get());
481 player_->AttachLayer(layer_id_);
482
483 const float start_opacity = .7f;
484 const float end_opacity = .3f;
485
486 const float start_brightness = .6f;
487 const float end_brightness = .4f;
488
489 const int transform_x = 10;
490 const int transform_y = 20;
491
492 const double duration = 1.;
493
494 AddOpacityTransitionToPlayer(player_.get(), duration, start_opacity,
495 end_opacity, false);
496 AddAnimatedTransformToPlayer(player_.get(), duration, transform_x,
497 transform_y);
498 AddAnimatedFilterToPlayer(player_.get(), duration, start_brightness,
499 end_brightness);
500
501 host_->PushPropertiesTo(host_impl_);
502
503 EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
504 Animation::OPACITY));
505 EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
506 Animation::TRANSFORM));
507 EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
508 Animation::FILTER));
509
510 EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
511 Animation::OPACITY));
512 EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
513 Animation::TRANSFORM));
514 EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
515 Animation::FILTER));
516
517 host_impl_->animation_registrar()->ActivateAnimations();
518
519 base::TimeTicks time;
520 time += base::TimeDelta::FromSecondsD(0.1);
521 AnimateLayersTransferEvents(time, 3u);
522
523 time += base::TimeDelta::FromSecondsD(duration);
524 AnimateLayersTransferEvents(time, 3u);
525
526 client_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
527 end_opacity);
528 client_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
529 transform_x, transform_y);
530 client_.ExpectFilterPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
531 end_brightness);
532
533 client_impl_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
534 end_opacity);
535 client_impl_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
536 transform_x, transform_y);
537 client_impl_.ExpectFilterPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
538 end_brightness);
539
540 client_impl_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::PENDING,
541 end_opacity);
542 client_impl_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::PENDING,
543 transform_x, transform_y);
544 client_impl_.ExpectFilterPropertyMutated(layer_id_, LayerTreeType::PENDING,
545 end_brightness);
546 }
547
548 TEST_F(AnimationPlayerTest, LayerAnimationDelegate) {
549 TestAnimationDelegate delegate;
550
551 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
552 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING);
553 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
554
555 host_->AddAnimationTimeline(timeline_.get());
556 timeline_->AttachPlayer(player_.get());
557
558 // Set delegate before controller created.
559 player_->set_layer_animation_delegate(&delegate);
560 player_->AttachLayer(layer_id_);
561
562 const double duration = 1.;
563
564 AddOpacityTransitionToPlayer(player_.get(), duration, .7f, .3f, false);
565
566 host_->PushPropertiesTo(host_impl_);
567 host_impl_->animation_registrar()->ActivateAnimations();
568
569 EXPECT_FALSE(delegate.started_);
570 EXPECT_FALSE(delegate.finished_);
571
572 base::TimeTicks time;
573 time += base::TimeDelta::FromSecondsD(0.1);
574 AnimateLayersTransferEvents(time, 1u);
575
576 EXPECT_TRUE(delegate.started_);
577 EXPECT_FALSE(delegate.finished_);
578
579 time += base::TimeDelta::FromSecondsD(duration);
580 AnimateLayersTransferEvents(time, 1u);
581
582 EXPECT_TRUE(delegate.finished_);
583 }
584
585 TEST_F(AnimationPlayerTest, AddRemoveAnimationCausesSetNeedsCommit) {
586 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
587 host_->AddAnimationTimeline(timeline_.get());
588 timeline_->AttachPlayer(player_.get());
589 player_->AttachLayer(layer_id_);
590
591 EXPECT_FALSE(client_.mutators_need_commit());
592
593 const int animation_id =
594 AddOpacityTransitionToPlayer(player_.get(), 1., .7f, .3f, false);
595
596 EXPECT_TRUE(client_.mutators_need_commit());
597 client_.set_mutators_need_commit(false);
598
599 player_->PauseAnimation(animation_id, 1.);
600 EXPECT_TRUE(client_.mutators_need_commit());
601 client_.set_mutators_need_commit(false);
602
603 player_->RemoveAnimation(animation_id);
604 EXPECT_TRUE(client_.mutators_need_commit());
605 client_.set_mutators_need_commit(false);
606 }
607
608 } // namespace
609 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698