OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/animation/element_animations.h" | 5 #include "cc/animation/element_animations.h" |
6 | 6 |
7 #include "cc/animation/animation_delegate.h" | 7 #include "cc/animation/animation_delegate.h" |
8 #include "cc/animation/animation_host.h" | 8 #include "cc/animation/animation_host.h" |
9 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
10 #include "cc/animation/animation_player.h" | 10 #include "cc/animation/animation_player.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 public: | 36 public: |
37 ElementAnimationsTest() {} | 37 ElementAnimationsTest() {} |
38 ~ElementAnimationsTest() override {} | 38 ~ElementAnimationsTest() override {} |
39 }; | 39 }; |
40 | 40 |
41 // See animation_player_unittest.cc for integration with AnimationPlayer. | 41 // See animation_player_unittest.cc for integration with AnimationPlayer. |
42 | 42 |
43 TEST_F(ElementAnimationsTest, AttachToLayerInActiveTree) { | 43 TEST_F(ElementAnimationsTest, AttachToLayerInActiveTree) { |
44 // Set up the layer which is in active tree for main thread and not | 44 // Set up the layer which is in active tree for main thread and not |
45 // yet passed onto the impl thread. | 45 // yet passed onto the impl thread. |
46 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); | 46 client_.RegisterLayer(element_id_, LayerTreeType::ACTIVE); |
47 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING); | 47 client_impl_.RegisterLayer(element_id_, LayerTreeType::PENDING); |
48 | 48 |
49 EXPECT_TRUE(client_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE)); | 49 EXPECT_TRUE(client_.IsLayerInTree(element_id_, LayerTreeType::ACTIVE)); |
50 EXPECT_FALSE(client_.IsLayerInTree(layer_id_, LayerTreeType::PENDING)); | 50 EXPECT_FALSE(client_.IsLayerInTree(element_id_, LayerTreeType::PENDING)); |
51 | 51 |
52 host_->AddAnimationTimeline(timeline_); | 52 host_->AddAnimationTimeline(timeline_); |
53 | 53 |
54 timeline_->AttachPlayer(player_); | 54 timeline_->AttachPlayer(player_); |
55 player_->AttachLayer(layer_id_); | 55 player_->AttachLayer(element_id_); |
56 | 56 |
57 scoped_refptr<ElementAnimations> element_animations = | 57 scoped_refptr<ElementAnimations> element_animations = |
58 player_->element_animations(); | 58 player_->element_animations(); |
59 EXPECT_TRUE(element_animations); | 59 EXPECT_TRUE(element_animations); |
60 | 60 |
61 EXPECT_TRUE(element_animations->has_element_in_active_list()); | 61 EXPECT_TRUE(element_animations->has_element_in_active_list()); |
62 EXPECT_FALSE(element_animations->has_element_in_pending_list()); | 62 EXPECT_FALSE(element_animations->has_element_in_pending_list()); |
63 | 63 |
64 host_->PushPropertiesTo(host_impl_); | 64 host_->PushPropertiesTo(host_impl_); |
65 | 65 |
66 GetImplTimelineAndPlayerByID(); | 66 GetImplTimelineAndPlayerByID(); |
67 | 67 |
68 scoped_refptr<ElementAnimations> element_animations_impl = | 68 scoped_refptr<ElementAnimations> element_animations_impl = |
69 player_impl_->element_animations(); | 69 player_impl_->element_animations(); |
70 EXPECT_TRUE(element_animations_impl); | 70 EXPECT_TRUE(element_animations_impl); |
71 | 71 |
72 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); | 72 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); |
73 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); | 73 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); |
74 | 74 |
75 // Create the layer in the impl active tree. | 75 // Create the layer in the impl active tree. |
76 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); | 76 client_impl_.RegisterLayer(element_id_, LayerTreeType::ACTIVE); |
77 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); | 77 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); |
78 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); | 78 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); |
79 | 79 |
80 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE)); | 80 EXPECT_TRUE(client_impl_.IsLayerInTree(element_id_, LayerTreeType::ACTIVE)); |
81 EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::PENDING)); | 81 EXPECT_TRUE(client_impl_.IsLayerInTree(element_id_, LayerTreeType::PENDING)); |
82 | 82 |
83 // kill layer on main thread. | 83 // kill layer on main thread. |
84 client_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE); | 84 client_.UnregisterLayer(element_id_, LayerTreeType::ACTIVE); |
85 EXPECT_EQ(element_animations, player_->element_animations()); | 85 EXPECT_EQ(element_animations, player_->element_animations()); |
86 EXPECT_FALSE(element_animations->has_element_in_active_list()); | 86 EXPECT_FALSE(element_animations->has_element_in_active_list()); |
87 EXPECT_FALSE(element_animations->has_element_in_pending_list()); | 87 EXPECT_FALSE(element_animations->has_element_in_pending_list()); |
88 | 88 |
89 // Sync doesn't detach LayerImpl. | 89 // Sync doesn't detach LayerImpl. |
90 host_->PushPropertiesTo(host_impl_); | 90 host_->PushPropertiesTo(host_impl_); |
91 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 91 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
92 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); | 92 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); |
93 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); | 93 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); |
94 | 94 |
95 // Kill layer on impl thread in pending tree. | 95 // Kill layer on impl thread in pending tree. |
96 client_impl_.UnregisterLayer(layer_id_, LayerTreeType::PENDING); | 96 client_impl_.UnregisterLayer(element_id_, LayerTreeType::PENDING); |
97 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 97 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
98 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); | 98 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); |
99 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); | 99 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); |
100 | 100 |
101 // Kill layer on impl thread in active tree. | 101 // Kill layer on impl thread in active tree. |
102 client_impl_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE); | 102 client_impl_.UnregisterLayer(element_id_, LayerTreeType::ACTIVE); |
103 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 103 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
104 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); | 104 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); |
105 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); | 105 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); |
106 | 106 |
107 // Sync doesn't change anything. | 107 // Sync doesn't change anything. |
108 host_->PushPropertiesTo(host_impl_); | 108 host_->PushPropertiesTo(host_impl_); |
109 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); | 109 EXPECT_EQ(element_animations_impl, player_impl_->element_animations()); |
110 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); | 110 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); |
111 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); | 111 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); |
112 | 112 |
113 player_->DetachLayer(); | 113 player_->DetachLayer(); |
114 EXPECT_FALSE(player_->element_animations()); | 114 EXPECT_FALSE(player_->element_animations()); |
115 | 115 |
116 // Release ptrs now to test the order of destruction. | 116 // Release ptrs now to test the order of destruction. |
117 ReleaseRefPtrs(); | 117 ReleaseRefPtrs(); |
118 } | 118 } |
119 | 119 |
120 TEST_F(ElementAnimationsTest, AttachToNotYetCreatedLayer) { | 120 TEST_F(ElementAnimationsTest, AttachToNotYetCreatedLayer) { |
121 host_->AddAnimationTimeline(timeline_); | 121 host_->AddAnimationTimeline(timeline_); |
122 timeline_->AttachPlayer(player_); | 122 timeline_->AttachPlayer(player_); |
123 | 123 |
124 host_->PushPropertiesTo(host_impl_); | 124 host_->PushPropertiesTo(host_impl_); |
125 | 125 |
126 GetImplTimelineAndPlayerByID(); | 126 GetImplTimelineAndPlayerByID(); |
127 | 127 |
128 player_->AttachLayer(layer_id_); | 128 player_->AttachLayer(element_id_); |
129 | 129 |
130 scoped_refptr<ElementAnimations> element_animations = | 130 scoped_refptr<ElementAnimations> element_animations = |
131 player_->element_animations(); | 131 player_->element_animations(); |
132 EXPECT_TRUE(element_animations); | 132 EXPECT_TRUE(element_animations); |
133 | 133 |
134 EXPECT_FALSE(element_animations->has_element_in_active_list()); | 134 EXPECT_FALSE(element_animations->has_element_in_active_list()); |
135 EXPECT_FALSE(element_animations->has_element_in_pending_list()); | 135 EXPECT_FALSE(element_animations->has_element_in_pending_list()); |
136 | 136 |
137 host_->PushPropertiesTo(host_impl_); | 137 host_->PushPropertiesTo(host_impl_); |
138 | 138 |
139 scoped_refptr<ElementAnimations> element_animations_impl = | 139 scoped_refptr<ElementAnimations> element_animations_impl = |
140 player_impl_->element_animations(); | 140 player_impl_->element_animations(); |
141 EXPECT_TRUE(element_animations_impl); | 141 EXPECT_TRUE(element_animations_impl); |
142 | 142 |
143 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); | 143 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); |
144 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); | 144 EXPECT_FALSE(element_animations_impl->has_element_in_pending_list()); |
145 | 145 |
146 // Create layer. | 146 // Create layer. |
147 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); | 147 client_.RegisterLayer(element_id_, LayerTreeType::ACTIVE); |
148 EXPECT_TRUE(element_animations->has_element_in_active_list()); | 148 EXPECT_TRUE(element_animations->has_element_in_active_list()); |
149 EXPECT_FALSE(element_animations->has_element_in_pending_list()); | 149 EXPECT_FALSE(element_animations->has_element_in_pending_list()); |
150 | 150 |
151 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING); | 151 client_impl_.RegisterLayer(element_id_, LayerTreeType::PENDING); |
152 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); | 152 EXPECT_FALSE(element_animations_impl->has_element_in_active_list()); |
153 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); | 153 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); |
154 | 154 |
155 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); | 155 client_impl_.RegisterLayer(element_id_, LayerTreeType::ACTIVE); |
156 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); | 156 EXPECT_TRUE(element_animations_impl->has_element_in_active_list()); |
157 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); | 157 EXPECT_TRUE(element_animations_impl->has_element_in_pending_list()); |
158 } | 158 } |
159 | 159 |
160 TEST_F(ElementAnimationsTest, AddRemovePlayers) { | 160 TEST_F(ElementAnimationsTest, AddRemovePlayers) { |
161 host_->AddAnimationTimeline(timeline_); | 161 host_->AddAnimationTimeline(timeline_); |
162 timeline_->AttachPlayer(player_); | 162 timeline_->AttachPlayer(player_); |
163 player_->AttachLayer(layer_id_); | 163 player_->AttachLayer(element_id_); |
164 | 164 |
165 scoped_refptr<ElementAnimations> element_animations = | 165 scoped_refptr<ElementAnimations> element_animations = |
166 player_->element_animations(); | 166 player_->element_animations(); |
167 EXPECT_TRUE(element_animations); | 167 EXPECT_TRUE(element_animations); |
168 | 168 |
169 scoped_refptr<AnimationPlayer> player1 = | 169 scoped_refptr<AnimationPlayer> player1 = |
170 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); | 170 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
171 scoped_refptr<AnimationPlayer> player2 = | 171 scoped_refptr<AnimationPlayer> player2 = |
172 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); | 172 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
173 | 173 |
174 timeline_->AttachPlayer(player1); | 174 timeline_->AttachPlayer(player1); |
175 timeline_->AttachPlayer(player2); | 175 timeline_->AttachPlayer(player2); |
176 | 176 |
177 // Attach players to the same layer. | 177 // Attach players to the same layer. |
178 player1->AttachLayer(layer_id_); | 178 player1->AttachLayer(element_id_); |
179 player2->AttachLayer(layer_id_); | 179 player2->AttachLayer(element_id_); |
180 | 180 |
181 EXPECT_EQ(element_animations, player1->element_animations()); | 181 EXPECT_EQ(element_animations, player1->element_animations()); |
182 EXPECT_EQ(element_animations, player2->element_animations()); | 182 EXPECT_EQ(element_animations, player2->element_animations()); |
183 | 183 |
184 host_->PushPropertiesTo(host_impl_); | 184 host_->PushPropertiesTo(host_impl_); |
185 GetImplTimelineAndPlayerByID(); | 185 GetImplTimelineAndPlayerByID(); |
186 | 186 |
187 scoped_refptr<ElementAnimations> element_animations_impl = | 187 scoped_refptr<ElementAnimations> element_animations_impl = |
188 player_impl_->element_animations(); | 188 player_impl_->element_animations(); |
189 EXPECT_TRUE(element_animations_impl); | 189 EXPECT_TRUE(element_animations_impl); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 493 |
494 animations->Animate(time); | 494 animations->Animate(time); |
495 animations->UpdateState(true, nullptr); | 495 animations->UpdateState(true, nullptr); |
496 animations->NotifyAnimationStarted(events->events_[0]); | 496 animations->NotifyAnimationStarted(events->events_[0]); |
497 | 497 |
498 EXPECT_EQ(Animation::RUNNING, | 498 EXPECT_EQ(Animation::RUNNING, |
499 animations_impl->GetAnimationById(animation_id)->run_state()); | 499 animations_impl->GetAnimationById(animation_id)->run_state()); |
500 EXPECT_EQ(Animation::RUNNING, | 500 EXPECT_EQ(Animation::RUNNING, |
501 animations->GetAnimationById(animation_id)->run_state()); | 501 animations->GetAnimationById(animation_id)->run_state()); |
502 | 502 |
503 EXPECT_EQ(0.3f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 503 EXPECT_EQ(0.3f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
504 EXPECT_EQ(0.3f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 504 EXPECT_EQ(0.3f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
505 | 505 |
506 EXPECT_EQ(kInitialTickTime, | 506 EXPECT_EQ(kInitialTickTime, |
507 animations->GetAnimationById(animation_id)->start_time()); | 507 animations->GetAnimationById(animation_id)->start_time()); |
508 EXPECT_EQ(kInitialTickTime, | 508 EXPECT_EQ(kInitialTickTime, |
509 animations_impl->GetAnimationById(animation_id)->start_time()); | 509 animations_impl->GetAnimationById(animation_id)->start_time()); |
510 | 510 |
511 // Pause the animation at the middle of the second range so the offset | 511 // Pause the animation at the middle of the second range so the offset |
512 // delays animation until the middle of the third range. | 512 // delays animation until the middle of the third range. |
513 animations->PauseAnimation(animation_id, TimeDelta::FromSecondsD(1.5)); | 513 animations->PauseAnimation(animation_id, TimeDelta::FromSecondsD(1.5)); |
514 EXPECT_EQ(Animation::PAUSED, | 514 EXPECT_EQ(Animation::PAUSED, |
515 animations->GetAnimationById(animation_id)->run_state()); | 515 animations->GetAnimationById(animation_id)->run_state()); |
516 | 516 |
517 // The pause run state change should make it to the impl thread animations. | 517 // The pause run state change should make it to the impl thread animations. |
518 animations->PushPropertiesTo(animations_impl.get()); | 518 animations->PushPropertiesTo(animations_impl.get()); |
519 animations_impl->ActivateAnimations(); | 519 animations_impl->ActivateAnimations(); |
520 | 520 |
521 // Advance time so it stays within the first range. | 521 // Advance time so it stays within the first range. |
522 time += TimeDelta::FromMilliseconds(10); | 522 time += TimeDelta::FromMilliseconds(10); |
523 animations->Animate(time); | 523 animations->Animate(time); |
524 animations_impl->Animate(time); | 524 animations_impl->Animate(time); |
525 | 525 |
526 EXPECT_EQ(Animation::PAUSED, | 526 EXPECT_EQ(Animation::PAUSED, |
527 animations_impl->GetAnimationById(animation_id)->run_state()); | 527 animations_impl->GetAnimationById(animation_id)->run_state()); |
528 | 528 |
529 // Opacity value doesn't depend on time if paused at specified time offset. | 529 // Opacity value doesn't depend on time if paused at specified time offset. |
530 EXPECT_EQ(0.4f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 530 EXPECT_EQ(0.4f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
531 EXPECT_EQ(0.4f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 531 EXPECT_EQ(0.4f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
532 } | 532 } |
533 | 533 |
534 TEST_F(ElementAnimationsTest, DoNotSyncFinishedAnimation) { | 534 TEST_F(ElementAnimationsTest, DoNotSyncFinishedAnimation) { |
535 CreateTestLayer(true, false); | 535 CreateTestLayer(true, false); |
536 AttachTimelinePlayerLayer(); | 536 AttachTimelinePlayerLayer(); |
537 CreateImplTimelineAndPlayer(); | 537 CreateImplTimelineAndPlayer(); |
538 | 538 |
539 scoped_refptr<ElementAnimations> animations = element_animations(); | 539 scoped_refptr<ElementAnimations> animations = element_animations(); |
540 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 540 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
541 | 541 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 675 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
676 1, TargetProperty::OPACITY)); | 676 1, TargetProperty::OPACITY)); |
677 | 677 |
678 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); | 678 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); |
679 animations->AddAnimation(std::move(to_add)); | 679 animations->AddAnimation(std::move(to_add)); |
680 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); | 680 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); |
681 animations->Animate(kInitialTickTime); | 681 animations->Animate(kInitialTickTime); |
682 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); | 682 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); |
683 animations->UpdateState(true, events.get()); | 683 animations->UpdateState(true, events.get()); |
684 EXPECT_TRUE(animations->HasActiveAnimation()); | 684 EXPECT_TRUE(animations->HasActiveAnimation()); |
685 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 685 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
686 // A non-impl-only animation should not generate property updates. | 686 // A non-impl-only animation should not generate property updates. |
687 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 687 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
688 EXPECT_FALSE(event); | 688 EXPECT_FALSE(event); |
689 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 689 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
690 animations->UpdateState(true, events.get()); | 690 animations->UpdateState(true, events.get()); |
691 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 691 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
692 EXPECT_FALSE(animations->HasActiveAnimation()); | 692 EXPECT_FALSE(animations->HasActiveAnimation()); |
693 event = GetMostRecentPropertyUpdateEvent(events.get()); | 693 event = GetMostRecentPropertyUpdateEvent(events.get()); |
694 EXPECT_FALSE(event); | 694 EXPECT_FALSE(event); |
695 } | 695 } |
696 | 696 |
697 TEST_F(ElementAnimationsTest, TrivialTransitionOnImpl) { | 697 TEST_F(ElementAnimationsTest, TrivialTransitionOnImpl) { |
698 CreateTestLayer(true, false); | 698 CreateTestLayer(true, false); |
699 AttachTimelinePlayerLayer(); | 699 AttachTimelinePlayerLayer(); |
700 CreateImplTimelineAndPlayer(); | 700 CreateImplTimelineAndPlayer(); |
701 | 701 |
702 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 702 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
703 | 703 |
704 auto events = host_impl_->CreateEvents(); | 704 auto events = host_impl_->CreateEvents(); |
705 | 705 |
706 std::unique_ptr<Animation> to_add(CreateAnimation( | 706 std::unique_ptr<Animation> to_add(CreateAnimation( |
707 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 707 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
708 1, TargetProperty::OPACITY)); | 708 1, TargetProperty::OPACITY)); |
709 to_add->set_is_impl_only(true); | 709 to_add->set_is_impl_only(true); |
710 | 710 |
711 animations_impl->AddAnimation(std::move(to_add)); | 711 animations_impl->AddAnimation(std::move(to_add)); |
712 animations_impl->Animate(kInitialTickTime); | 712 animations_impl->Animate(kInitialTickTime); |
713 animations_impl->UpdateState(true, events.get()); | 713 animations_impl->UpdateState(true, events.get()); |
714 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | 714 EXPECT_TRUE(animations_impl->HasActiveAnimation()); |
715 EXPECT_EQ(0.f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 715 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
716 EXPECT_EQ(1u, events->events_.size()); | 716 EXPECT_EQ(1u, events->events_.size()); |
717 const AnimationEvent* start_opacity_event = | 717 const AnimationEvent* start_opacity_event = |
718 GetMostRecentPropertyUpdateEvent(events.get()); | 718 GetMostRecentPropertyUpdateEvent(events.get()); |
719 EXPECT_EQ(0.f, start_opacity_event->opacity); | 719 EXPECT_EQ(0.f, start_opacity_event->opacity); |
720 | 720 |
721 animations_impl->Animate(kInitialTickTime + | 721 animations_impl->Animate(kInitialTickTime + |
722 TimeDelta::FromMilliseconds(1000)); | 722 TimeDelta::FromMilliseconds(1000)); |
723 animations_impl->UpdateState(true, events.get()); | 723 animations_impl->UpdateState(true, events.get()); |
724 EXPECT_EQ(1.f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 724 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
725 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | 725 EXPECT_FALSE(animations_impl->HasActiveAnimation()); |
726 EXPECT_EQ(2u, events->events_.size()); | 726 EXPECT_EQ(2u, events->events_.size()); |
727 const AnimationEvent* end_opacity_event = | 727 const AnimationEvent* end_opacity_event = |
728 GetMostRecentPropertyUpdateEvent(events.get()); | 728 GetMostRecentPropertyUpdateEvent(events.get()); |
729 EXPECT_EQ(1.f, end_opacity_event->opacity); | 729 EXPECT_EQ(1.f, end_opacity_event->opacity); |
730 } | 730 } |
731 | 731 |
732 TEST_F(ElementAnimationsTest, TrivialTransformOnImpl) { | 732 TEST_F(ElementAnimationsTest, TrivialTransformOnImpl) { |
733 CreateTestLayer(true, false); | 733 CreateTestLayer(true, false); |
734 AttachTimelinePlayerLayer(); | 734 AttachTimelinePlayerLayer(); |
(...skipping 22 matching lines...) Expand all Loading... |
757 std::unique_ptr<Animation> animation( | 757 std::unique_ptr<Animation> animation( |
758 Animation::Create(std::move(curve), 1, 0, TargetProperty::TRANSFORM)); | 758 Animation::Create(std::move(curve), 1, 0, TargetProperty::TRANSFORM)); |
759 animation->set_is_impl_only(true); | 759 animation->set_is_impl_only(true); |
760 animations_impl->AddAnimation(std::move(animation)); | 760 animations_impl->AddAnimation(std::move(animation)); |
761 | 761 |
762 // Run animation. | 762 // Run animation. |
763 animations_impl->Animate(kInitialTickTime); | 763 animations_impl->Animate(kInitialTickTime); |
764 animations_impl->UpdateState(true, events.get()); | 764 animations_impl->UpdateState(true, events.get()); |
765 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | 765 EXPECT_TRUE(animations_impl->HasActiveAnimation()); |
766 EXPECT_EQ(gfx::Transform(), | 766 EXPECT_EQ(gfx::Transform(), |
767 client_impl_.GetTransform(layer_id_, LayerTreeType::ACTIVE)); | 767 client_impl_.GetTransform(element_id_, LayerTreeType::ACTIVE)); |
768 EXPECT_EQ(1u, events->events_.size()); | 768 EXPECT_EQ(1u, events->events_.size()); |
769 const AnimationEvent* start_transform_event = | 769 const AnimationEvent* start_transform_event = |
770 GetMostRecentPropertyUpdateEvent(events.get()); | 770 GetMostRecentPropertyUpdateEvent(events.get()); |
771 ASSERT_TRUE(start_transform_event); | 771 ASSERT_TRUE(start_transform_event); |
772 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); | 772 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); |
773 EXPECT_TRUE(start_transform_event->is_impl_only); | 773 EXPECT_TRUE(start_transform_event->is_impl_only); |
774 | 774 |
775 gfx::Transform expected_transform; | 775 gfx::Transform expected_transform; |
776 expected_transform.Translate(delta_x, delta_y); | 776 expected_transform.Translate(delta_x, delta_y); |
777 | 777 |
778 animations_impl->Animate(kInitialTickTime + | 778 animations_impl->Animate(kInitialTickTime + |
779 TimeDelta::FromMilliseconds(1000)); | 779 TimeDelta::FromMilliseconds(1000)); |
780 animations_impl->UpdateState(true, events.get()); | 780 animations_impl->UpdateState(true, events.get()); |
781 EXPECT_EQ(expected_transform, | 781 EXPECT_EQ(expected_transform, |
782 client_impl_.GetTransform(layer_id_, LayerTreeType::ACTIVE)); | 782 client_impl_.GetTransform(element_id_, LayerTreeType::ACTIVE)); |
783 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | 783 EXPECT_FALSE(animations_impl->HasActiveAnimation()); |
784 EXPECT_EQ(2u, events->events_.size()); | 784 EXPECT_EQ(2u, events->events_.size()); |
785 const AnimationEvent* end_transform_event = | 785 const AnimationEvent* end_transform_event = |
786 GetMostRecentPropertyUpdateEvent(events.get()); | 786 GetMostRecentPropertyUpdateEvent(events.get()); |
787 EXPECT_EQ(expected_transform, end_transform_event->transform); | 787 EXPECT_EQ(expected_transform, end_transform_event->transform); |
788 EXPECT_TRUE(end_transform_event->is_impl_only); | 788 EXPECT_TRUE(end_transform_event->is_impl_only); |
789 } | 789 } |
790 | 790 |
791 TEST_F(ElementAnimationsTest, FilterTransition) { | 791 TEST_F(ElementAnimationsTest, FilterTransition) { |
792 CreateTestLayer(true, false); | 792 CreateTestLayer(true, false); |
(...skipping 16 matching lines...) Expand all Loading... |
809 end_filters, nullptr)); | 809 end_filters, nullptr)); |
810 | 810 |
811 std::unique_ptr<Animation> animation( | 811 std::unique_ptr<Animation> animation( |
812 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); | 812 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); |
813 animations->AddAnimation(std::move(animation)); | 813 animations->AddAnimation(std::move(animation)); |
814 | 814 |
815 animations->Animate(kInitialTickTime); | 815 animations->Animate(kInitialTickTime); |
816 animations->UpdateState(true, events.get()); | 816 animations->UpdateState(true, events.get()); |
817 EXPECT_TRUE(animations->HasActiveAnimation()); | 817 EXPECT_TRUE(animations->HasActiveAnimation()); |
818 EXPECT_EQ(start_filters, | 818 EXPECT_EQ(start_filters, |
819 client_.GetFilters(layer_id_, LayerTreeType::ACTIVE)); | 819 client_.GetFilters(element_id_, LayerTreeType::ACTIVE)); |
820 // A non-impl-only animation should not generate property updates. | 820 // A non-impl-only animation should not generate property updates. |
821 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 821 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
822 EXPECT_FALSE(event); | 822 EXPECT_FALSE(event); |
823 | 823 |
824 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 824 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
825 animations->UpdateState(true, events.get()); | 825 animations->UpdateState(true, events.get()); |
826 EXPECT_EQ(1u, client_.GetFilters(layer_id_, LayerTreeType::ACTIVE).size()); | 826 EXPECT_EQ(1u, client_.GetFilters(element_id_, LayerTreeType::ACTIVE).size()); |
827 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), | 827 EXPECT_EQ(FilterOperation::CreateBrightnessFilter(1.5f), |
828 client_.GetFilters(layer_id_, LayerTreeType::ACTIVE).at(0)); | 828 client_.GetFilters(element_id_, LayerTreeType::ACTIVE).at(0)); |
829 event = GetMostRecentPropertyUpdateEvent(events.get()); | 829 event = GetMostRecentPropertyUpdateEvent(events.get()); |
830 EXPECT_FALSE(event); | 830 EXPECT_FALSE(event); |
831 | 831 |
832 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 832 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
833 animations->UpdateState(true, events.get()); | 833 animations->UpdateState(true, events.get()); |
834 EXPECT_EQ(end_filters, client_.GetFilters(layer_id_, LayerTreeType::ACTIVE)); | 834 EXPECT_EQ(end_filters, |
| 835 client_.GetFilters(element_id_, LayerTreeType::ACTIVE)); |
835 EXPECT_FALSE(animations->HasActiveAnimation()); | 836 EXPECT_FALSE(animations->HasActiveAnimation()); |
836 event = GetMostRecentPropertyUpdateEvent(events.get()); | 837 event = GetMostRecentPropertyUpdateEvent(events.get()); |
837 EXPECT_FALSE(event); | 838 EXPECT_FALSE(event); |
838 } | 839 } |
839 | 840 |
840 TEST_F(ElementAnimationsTest, FilterTransitionOnImplOnly) { | 841 TEST_F(ElementAnimationsTest, FilterTransitionOnImplOnly) { |
841 CreateTestLayer(true, false); | 842 CreateTestLayer(true, false); |
842 AttachTimelinePlayerLayer(); | 843 AttachTimelinePlayerLayer(); |
843 CreateImplTimelineAndPlayer(); | 844 CreateImplTimelineAndPlayer(); |
844 | 845 |
(...skipping 17 matching lines...) Expand all Loading... |
862 std::unique_ptr<Animation> animation( | 863 std::unique_ptr<Animation> animation( |
863 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); | 864 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); |
864 animation->set_is_impl_only(true); | 865 animation->set_is_impl_only(true); |
865 animations_impl->AddAnimation(std::move(animation)); | 866 animations_impl->AddAnimation(std::move(animation)); |
866 | 867 |
867 // Run animation. | 868 // Run animation. |
868 animations_impl->Animate(kInitialTickTime); | 869 animations_impl->Animate(kInitialTickTime); |
869 animations_impl->UpdateState(true, events.get()); | 870 animations_impl->UpdateState(true, events.get()); |
870 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | 871 EXPECT_TRUE(animations_impl->HasActiveAnimation()); |
871 EXPECT_EQ(start_filters, | 872 EXPECT_EQ(start_filters, |
872 client_impl_.GetFilters(layer_id_, LayerTreeType::ACTIVE)); | 873 client_impl_.GetFilters(element_id_, LayerTreeType::ACTIVE)); |
873 EXPECT_EQ(1u, events->events_.size()); | 874 EXPECT_EQ(1u, events->events_.size()); |
874 const AnimationEvent* start_filter_event = | 875 const AnimationEvent* start_filter_event = |
875 GetMostRecentPropertyUpdateEvent(events.get()); | 876 GetMostRecentPropertyUpdateEvent(events.get()); |
876 EXPECT_TRUE(start_filter_event); | 877 EXPECT_TRUE(start_filter_event); |
877 EXPECT_EQ(start_filters, start_filter_event->filters); | 878 EXPECT_EQ(start_filters, start_filter_event->filters); |
878 EXPECT_TRUE(start_filter_event->is_impl_only); | 879 EXPECT_TRUE(start_filter_event->is_impl_only); |
879 | 880 |
880 animations_impl->Animate(kInitialTickTime + | 881 animations_impl->Animate(kInitialTickTime + |
881 TimeDelta::FromMilliseconds(1000)); | 882 TimeDelta::FromMilliseconds(1000)); |
882 animations_impl->UpdateState(true, events.get()); | 883 animations_impl->UpdateState(true, events.get()); |
883 EXPECT_EQ(end_filters, | 884 EXPECT_EQ(end_filters, |
884 client_impl_.GetFilters(layer_id_, LayerTreeType::ACTIVE)); | 885 client_impl_.GetFilters(element_id_, LayerTreeType::ACTIVE)); |
885 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | 886 EXPECT_FALSE(animations_impl->HasActiveAnimation()); |
886 EXPECT_EQ(2u, events->events_.size()); | 887 EXPECT_EQ(2u, events->events_.size()); |
887 const AnimationEvent* end_filter_event = | 888 const AnimationEvent* end_filter_event = |
888 GetMostRecentPropertyUpdateEvent(events.get()); | 889 GetMostRecentPropertyUpdateEvent(events.get()); |
889 EXPECT_TRUE(end_filter_event); | 890 EXPECT_TRUE(end_filter_event); |
890 EXPECT_EQ(end_filters, end_filter_event->filters); | 891 EXPECT_EQ(end_filters, end_filter_event->filters); |
891 EXPECT_TRUE(end_filter_event->is_impl_only); | 892 EXPECT_TRUE(end_filter_event->is_impl_only); |
892 } | 893 } |
893 | 894 |
894 TEST_F(ElementAnimationsTest, ScrollOffsetTransition) { | 895 TEST_F(ElementAnimationsTest, ScrollOffsetTransition) { |
(...skipping 26 matching lines...) Expand all Loading... |
921 ->curve() | 922 ->curve() |
922 ->Duration(); | 923 ->Duration(); |
923 EXPECT_EQ(duration, animations->GetAnimation(TargetProperty::SCROLL_OFFSET) | 924 EXPECT_EQ(duration, animations->GetAnimation(TargetProperty::SCROLL_OFFSET) |
924 ->curve() | 925 ->curve() |
925 ->Duration()); | 926 ->Duration()); |
926 | 927 |
927 animations->Animate(kInitialTickTime); | 928 animations->Animate(kInitialTickTime); |
928 animations->UpdateState(true, nullptr); | 929 animations->UpdateState(true, nullptr); |
929 EXPECT_TRUE(animations->HasActiveAnimation()); | 930 EXPECT_TRUE(animations->HasActiveAnimation()); |
930 EXPECT_EQ(initial_value, | 931 EXPECT_EQ(initial_value, |
931 client_.GetScrollOffset(layer_id_, LayerTreeType::ACTIVE)); | 932 client_.GetScrollOffset(element_id_, LayerTreeType::ACTIVE)); |
932 | 933 |
933 animations_impl->Animate(kInitialTickTime); | 934 animations_impl->Animate(kInitialTickTime); |
934 animations_impl->UpdateState(true, events.get()); | 935 animations_impl->UpdateState(true, events.get()); |
935 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | 936 EXPECT_TRUE(animations_impl->HasActiveAnimation()); |
936 EXPECT_EQ(initial_value, | 937 EXPECT_EQ(initial_value, |
937 client_impl_.GetScrollOffset(layer_id_, LayerTreeType::ACTIVE)); | 938 client_impl_.GetScrollOffset(element_id_, LayerTreeType::ACTIVE)); |
938 // Scroll offset animations should not generate property updates. | 939 // Scroll offset animations should not generate property updates. |
939 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 940 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
940 EXPECT_FALSE(event); | 941 EXPECT_FALSE(event); |
941 | 942 |
942 animations->NotifyAnimationStarted(events->events_[0]); | 943 animations->NotifyAnimationStarted(events->events_[0]); |
943 animations->Animate(kInitialTickTime + duration / 2); | 944 animations->Animate(kInitialTickTime + duration / 2); |
944 animations->UpdateState(true, nullptr); | 945 animations->UpdateState(true, nullptr); |
945 EXPECT_TRUE(animations->HasActiveAnimation()); | 946 EXPECT_TRUE(animations->HasActiveAnimation()); |
946 EXPECT_VECTOR2DF_EQ( | 947 EXPECT_VECTOR2DF_EQ( |
947 gfx::Vector2dF(200.f, 250.f), | 948 gfx::Vector2dF(200.f, 250.f), |
948 client_.GetScrollOffset(layer_id_, LayerTreeType::ACTIVE)); | 949 client_.GetScrollOffset(element_id_, LayerTreeType::ACTIVE)); |
949 | 950 |
950 animations_impl->Animate(kInitialTickTime + duration / 2); | 951 animations_impl->Animate(kInitialTickTime + duration / 2); |
951 animations_impl->UpdateState(true, events.get()); | 952 animations_impl->UpdateState(true, events.get()); |
952 EXPECT_VECTOR2DF_EQ( | 953 EXPECT_VECTOR2DF_EQ( |
953 gfx::Vector2dF(200.f, 250.f), | 954 gfx::Vector2dF(200.f, 250.f), |
954 client_impl_.GetScrollOffset(layer_id_, LayerTreeType::ACTIVE)); | 955 client_impl_.GetScrollOffset(element_id_, LayerTreeType::ACTIVE)); |
955 event = GetMostRecentPropertyUpdateEvent(events.get()); | 956 event = GetMostRecentPropertyUpdateEvent(events.get()); |
956 EXPECT_FALSE(event); | 957 EXPECT_FALSE(event); |
957 | 958 |
958 animations_impl->Animate(kInitialTickTime + duration); | 959 animations_impl->Animate(kInitialTickTime + duration); |
959 animations_impl->UpdateState(true, events.get()); | 960 animations_impl->UpdateState(true, events.get()); |
960 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( | 961 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( |
961 layer_id_, LayerTreeType::ACTIVE)); | 962 element_id_, LayerTreeType::ACTIVE)); |
962 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | 963 EXPECT_FALSE(animations_impl->HasActiveAnimation()); |
963 event = GetMostRecentPropertyUpdateEvent(events.get()); | 964 event = GetMostRecentPropertyUpdateEvent(events.get()); |
964 EXPECT_FALSE(event); | 965 EXPECT_FALSE(event); |
965 | 966 |
966 animations->Animate(kInitialTickTime + duration); | 967 animations->Animate(kInitialTickTime + duration); |
967 animations->UpdateState(true, nullptr); | 968 animations->UpdateState(true, nullptr); |
968 EXPECT_VECTOR2DF_EQ( | 969 EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset( |
969 target_value, client_.GetScrollOffset(layer_id_, LayerTreeType::ACTIVE)); | 970 element_id_, LayerTreeType::ACTIVE)); |
970 EXPECT_FALSE(animations->HasActiveAnimation()); | 971 EXPECT_FALSE(animations->HasActiveAnimation()); |
971 } | 972 } |
972 | 973 |
973 TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) { | 974 TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) { |
974 CreateTestLayer(true, false); | 975 CreateTestLayer(true, false); |
975 AttachTimelinePlayerLayer(); | 976 AttachTimelinePlayerLayer(); |
976 CreateImplTimelineAndPlayer(); | 977 CreateImplTimelineAndPlayer(); |
977 | 978 |
978 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 979 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
979 | 980 |
980 auto events = host_impl_->CreateEvents(); | 981 auto events = host_impl_->CreateEvents(); |
981 | 982 |
982 gfx::ScrollOffset initial_value(100.f, 300.f); | 983 gfx::ScrollOffset initial_value(100.f, 300.f); |
983 gfx::ScrollOffset target_value(300.f, 200.f); | 984 gfx::ScrollOffset target_value(300.f, 200.f); |
984 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 985 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
985 ScrollOffsetAnimationCurve::Create(target_value, | 986 ScrollOffsetAnimationCurve::Create(target_value, |
986 EaseInOutTimingFunction::Create())); | 987 EaseInOutTimingFunction::Create())); |
987 curve->SetInitialValue(initial_value); | 988 curve->SetInitialValue(initial_value); |
988 double duration_in_seconds = curve->Duration().InSecondsF(); | 989 double duration_in_seconds = curve->Duration().InSecondsF(); |
989 | 990 |
990 std::unique_ptr<Animation> animation( | 991 std::unique_ptr<Animation> animation( |
991 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 992 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
992 animation->set_is_impl_only(true); | 993 animation->set_is_impl_only(true); |
993 animations_impl->AddAnimation(std::move(animation)); | 994 animations_impl->AddAnimation(std::move(animation)); |
994 | 995 |
995 animations_impl->Animate(kInitialTickTime); | 996 animations_impl->Animate(kInitialTickTime); |
996 animations_impl->UpdateState(true, events.get()); | 997 animations_impl->UpdateState(true, events.get()); |
997 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | 998 EXPECT_TRUE(animations_impl->HasActiveAnimation()); |
998 EXPECT_EQ(initial_value, | 999 EXPECT_EQ(initial_value, |
999 client_impl_.GetScrollOffset(layer_id_, LayerTreeType::ACTIVE)); | 1000 client_impl_.GetScrollOffset(element_id_, LayerTreeType::ACTIVE)); |
1000 // Scroll offset animations should not generate property updates. | 1001 // Scroll offset animations should not generate property updates. |
1001 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 1002 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
1002 EXPECT_FALSE(event); | 1003 EXPECT_FALSE(event); |
1003 | 1004 |
1004 TimeDelta duration = TimeDelta::FromMicroseconds( | 1005 TimeDelta duration = TimeDelta::FromMicroseconds( |
1005 duration_in_seconds * base::Time::kMicrosecondsPerSecond); | 1006 duration_in_seconds * base::Time::kMicrosecondsPerSecond); |
1006 | 1007 |
1007 animations_impl->Animate(kInitialTickTime + duration / 2); | 1008 animations_impl->Animate(kInitialTickTime + duration / 2); |
1008 animations_impl->UpdateState(true, events.get()); | 1009 animations_impl->UpdateState(true, events.get()); |
1009 EXPECT_VECTOR2DF_EQ( | 1010 EXPECT_VECTOR2DF_EQ( |
1010 gfx::Vector2dF(200.f, 250.f), | 1011 gfx::Vector2dF(200.f, 250.f), |
1011 client_impl_.GetScrollOffset(layer_id_, LayerTreeType::ACTIVE)); | 1012 client_impl_.GetScrollOffset(element_id_, LayerTreeType::ACTIVE)); |
1012 event = GetMostRecentPropertyUpdateEvent(events.get()); | 1013 event = GetMostRecentPropertyUpdateEvent(events.get()); |
1013 EXPECT_FALSE(event); | 1014 EXPECT_FALSE(event); |
1014 | 1015 |
1015 animations_impl->Animate(kInitialTickTime + duration); | 1016 animations_impl->Animate(kInitialTickTime + duration); |
1016 animations_impl->UpdateState(true, events.get()); | 1017 animations_impl->UpdateState(true, events.get()); |
1017 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( | 1018 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( |
1018 layer_id_, LayerTreeType::ACTIVE)); | 1019 element_id_, LayerTreeType::ACTIVE)); |
1019 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | 1020 EXPECT_FALSE(animations_impl->HasActiveAnimation()); |
1020 event = GetMostRecentPropertyUpdateEvent(events.get()); | 1021 event = GetMostRecentPropertyUpdateEvent(events.get()); |
1021 EXPECT_FALSE(event); | 1022 EXPECT_FALSE(event); |
1022 } | 1023 } |
1023 | 1024 |
1024 // Ensure that when the impl animations doesn't have a value provider, | 1025 // Ensure that when the impl animations doesn't have a value provider, |
1025 // the main-thread animations's value provider is used to obtain the intial | 1026 // the main-thread animations's value provider is used to obtain the intial |
1026 // scroll offset. | 1027 // scroll offset. |
1027 TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) { | 1028 TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) { |
1028 CreateTestLayer(false, false); | 1029 CreateTestLayer(false, false); |
(...skipping 30 matching lines...) Expand all Loading... |
1059 ->Duration(); | 1060 ->Duration(); |
1060 EXPECT_EQ(duration, animations->GetAnimation(TargetProperty::SCROLL_OFFSET) | 1061 EXPECT_EQ(duration, animations->GetAnimation(TargetProperty::SCROLL_OFFSET) |
1061 ->curve() | 1062 ->curve() |
1062 ->Duration()); | 1063 ->Duration()); |
1063 | 1064 |
1064 animations->Animate(kInitialTickTime); | 1065 animations->Animate(kInitialTickTime); |
1065 animations->UpdateState(true, nullptr); | 1066 animations->UpdateState(true, nullptr); |
1066 | 1067 |
1067 EXPECT_TRUE(animations->HasActiveAnimation()); | 1068 EXPECT_TRUE(animations->HasActiveAnimation()); |
1068 EXPECT_EQ(initial_value, | 1069 EXPECT_EQ(initial_value, |
1069 client_.GetScrollOffset(layer_id_, LayerTreeType::ACTIVE)); | 1070 client_.GetScrollOffset(element_id_, LayerTreeType::ACTIVE)); |
1070 EXPECT_EQ(gfx::ScrollOffset(), | 1071 EXPECT_EQ(gfx::ScrollOffset(), |
1071 client_impl_.GetScrollOffset(layer_id_, LayerTreeType::PENDING)); | 1072 client_impl_.GetScrollOffset(element_id_, LayerTreeType::PENDING)); |
1072 | 1073 |
1073 animations_impl->Animate(kInitialTickTime); | 1074 animations_impl->Animate(kInitialTickTime); |
1074 | 1075 |
1075 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | 1076 EXPECT_TRUE(animations_impl->HasActiveAnimation()); |
1076 EXPECT_EQ(initial_value, | 1077 EXPECT_EQ(initial_value, |
1077 client_impl_.GetScrollOffset(layer_id_, LayerTreeType::PENDING)); | 1078 client_impl_.GetScrollOffset(element_id_, LayerTreeType::PENDING)); |
1078 | 1079 |
1079 CreateTestImplLayer(LayerTreeType::ACTIVE); | 1080 CreateTestImplLayer(LayerTreeType::ACTIVE); |
1080 | 1081 |
1081 animations_impl->UpdateState(true, events.get()); | 1082 animations_impl->UpdateState(true, events.get()); |
1082 DCHECK_EQ(1UL, events->events_.size()); | 1083 DCHECK_EQ(1UL, events->events_.size()); |
1083 | 1084 |
1084 // Scroll offset animations should not generate property updates. | 1085 // Scroll offset animations should not generate property updates. |
1085 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 1086 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
1086 EXPECT_FALSE(event); | 1087 EXPECT_FALSE(event); |
1087 | 1088 |
1088 animations->NotifyAnimationStarted(events->events_[0]); | 1089 animations->NotifyAnimationStarted(events->events_[0]); |
1089 animations->Animate(kInitialTickTime + duration / 2); | 1090 animations->Animate(kInitialTickTime + duration / 2); |
1090 animations->UpdateState(true, nullptr); | 1091 animations->UpdateState(true, nullptr); |
1091 EXPECT_TRUE(animations->HasActiveAnimation()); | 1092 EXPECT_TRUE(animations->HasActiveAnimation()); |
1092 EXPECT_VECTOR2DF_EQ( | 1093 EXPECT_VECTOR2DF_EQ( |
1093 gfx::Vector2dF(400.f, 150.f), | 1094 gfx::Vector2dF(400.f, 150.f), |
1094 client_.GetScrollOffset(layer_id_, LayerTreeType::ACTIVE)); | 1095 client_.GetScrollOffset(element_id_, LayerTreeType::ACTIVE)); |
1095 | 1096 |
1096 animations_impl->Animate(kInitialTickTime + duration / 2); | 1097 animations_impl->Animate(kInitialTickTime + duration / 2); |
1097 animations_impl->UpdateState(true, events.get()); | 1098 animations_impl->UpdateState(true, events.get()); |
1098 EXPECT_VECTOR2DF_EQ( | 1099 EXPECT_VECTOR2DF_EQ( |
1099 gfx::Vector2dF(400.f, 150.f), | 1100 gfx::Vector2dF(400.f, 150.f), |
1100 client_impl_.GetScrollOffset(layer_id_, LayerTreeType::PENDING)); | 1101 client_impl_.GetScrollOffset(element_id_, LayerTreeType::PENDING)); |
1101 event = GetMostRecentPropertyUpdateEvent(events.get()); | 1102 event = GetMostRecentPropertyUpdateEvent(events.get()); |
1102 EXPECT_FALSE(event); | 1103 EXPECT_FALSE(event); |
1103 | 1104 |
1104 animations_impl->Animate(kInitialTickTime + duration); | 1105 animations_impl->Animate(kInitialTickTime + duration); |
1105 animations_impl->UpdateState(true, events.get()); | 1106 animations_impl->UpdateState(true, events.get()); |
1106 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( | 1107 EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset( |
1107 layer_id_, LayerTreeType::PENDING)); | 1108 element_id_, LayerTreeType::PENDING)); |
1108 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | 1109 EXPECT_FALSE(animations_impl->HasActiveAnimation()); |
1109 event = GetMostRecentPropertyUpdateEvent(events.get()); | 1110 event = GetMostRecentPropertyUpdateEvent(events.get()); |
1110 EXPECT_FALSE(event); | 1111 EXPECT_FALSE(event); |
1111 | 1112 |
1112 animations->Animate(kInitialTickTime + duration); | 1113 animations->Animate(kInitialTickTime + duration); |
1113 animations->UpdateState(true, nullptr); | 1114 animations->UpdateState(true, nullptr); |
1114 EXPECT_VECTOR2DF_EQ( | 1115 EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset( |
1115 target_value, client_.GetScrollOffset(layer_id_, LayerTreeType::ACTIVE)); | 1116 element_id_, LayerTreeType::ACTIVE)); |
1116 EXPECT_FALSE(animations->HasActiveAnimation()); | 1117 EXPECT_FALSE(animations->HasActiveAnimation()); |
1117 } | 1118 } |
1118 | 1119 |
1119 TEST_F(ElementAnimationsTest, ScrollOffsetRemovalClearsScrollDelta) { | 1120 TEST_F(ElementAnimationsTest, ScrollOffsetRemovalClearsScrollDelta) { |
1120 CreateTestLayer(true, false); | 1121 CreateTestLayer(true, false); |
1121 AttachTimelinePlayerLayer(); | 1122 AttachTimelinePlayerLayer(); |
1122 CreateImplTimelineAndPlayer(); | 1123 CreateImplTimelineAndPlayer(); |
1123 | 1124 |
1124 scoped_refptr<ElementAnimations> animations = element_animations(); | 1125 scoped_refptr<ElementAnimations> animations = element_animations(); |
1125 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 1126 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1304 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1304 1, TargetProperty::OPACITY)); | 1305 1, TargetProperty::OPACITY)); |
1305 to_add->set_needs_synchronized_start_time(true); | 1306 to_add->set_needs_synchronized_start_time(true); |
1306 | 1307 |
1307 // We should pause at the first keyframe indefinitely waiting for that | 1308 // We should pause at the first keyframe indefinitely waiting for that |
1308 // animation to start. | 1309 // animation to start. |
1309 animations->AddAnimation(std::move(to_add)); | 1310 animations->AddAnimation(std::move(to_add)); |
1310 animations->Animate(kInitialTickTime); | 1311 animations->Animate(kInitialTickTime); |
1311 animations->UpdateState(true, events.get()); | 1312 animations->UpdateState(true, events.get()); |
1312 EXPECT_TRUE(animations->HasActiveAnimation()); | 1313 EXPECT_TRUE(animations->HasActiveAnimation()); |
1313 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1314 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1314 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1315 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1315 animations->UpdateState(true, events.get()); | 1316 animations->UpdateState(true, events.get()); |
1316 EXPECT_TRUE(animations->HasActiveAnimation()); | 1317 EXPECT_TRUE(animations->HasActiveAnimation()); |
1317 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1318 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1318 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1319 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1319 animations->UpdateState(true, events.get()); | 1320 animations->UpdateState(true, events.get()); |
1320 EXPECT_TRUE(animations->HasActiveAnimation()); | 1321 EXPECT_TRUE(animations->HasActiveAnimation()); |
1321 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1322 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1322 | 1323 |
1323 // Send the synchronized start time. | 1324 // Send the synchronized start time. |
1324 animations->NotifyAnimationStarted( | 1325 animations->NotifyAnimationStarted( |
1325 AnimationEvent(AnimationEvent::STARTED, 0, 1, TargetProperty::OPACITY, | 1326 AnimationEvent(AnimationEvent::STARTED, 0, 1, TargetProperty::OPACITY, |
1326 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); | 1327 kInitialTickTime + TimeDelta::FromMilliseconds(2000))); |
1327 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); | 1328 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(5000)); |
1328 animations->UpdateState(true, events.get()); | 1329 animations->UpdateState(true, events.get()); |
1329 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1330 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1330 EXPECT_FALSE(animations->HasActiveAnimation()); | 1331 EXPECT_FALSE(animations->HasActiveAnimation()); |
1331 } | 1332 } |
1332 | 1333 |
1333 // Tests that two queued animations affecting the same property run in sequence. | 1334 // Tests that two queued animations affecting the same property run in sequence. |
1334 TEST_F(ElementAnimationsTest, TrivialQueuing) { | 1335 TEST_F(ElementAnimationsTest, TrivialQueuing) { |
1335 CreateTestLayer(false, false); | 1336 CreateTestLayer(false, false); |
1336 AttachTimelinePlayerLayer(); | 1337 AttachTimelinePlayerLayer(); |
1337 | 1338 |
1338 scoped_refptr<ElementAnimations> animations = element_animations(); | 1339 scoped_refptr<ElementAnimations> animations = element_animations(); |
1339 | 1340 |
(...skipping 10 matching lines...) Expand all Loading... |
1350 | 1351 |
1351 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); | 1352 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); |
1352 | 1353 |
1353 animations->Animate(kInitialTickTime); | 1354 animations->Animate(kInitialTickTime); |
1354 | 1355 |
1355 // The second animation still needs to be started. | 1356 // The second animation still needs to be started. |
1356 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); | 1357 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); |
1357 | 1358 |
1358 animations->UpdateState(true, events.get()); | 1359 animations->UpdateState(true, events.get()); |
1359 EXPECT_TRUE(animations->HasActiveAnimation()); | 1360 EXPECT_TRUE(animations->HasActiveAnimation()); |
1360 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1361 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1361 | 1362 |
1362 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1363 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1363 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); | 1364 EXPECT_TRUE(animations->needs_to_start_animations_for_testing()); |
1364 animations->UpdateState(true, events.get()); | 1365 animations->UpdateState(true, events.get()); |
1365 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); | 1366 EXPECT_FALSE(animations->needs_to_start_animations_for_testing()); |
1366 | 1367 |
1367 EXPECT_TRUE(animations->HasActiveAnimation()); | 1368 EXPECT_TRUE(animations->HasActiveAnimation()); |
1368 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1369 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1369 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1370 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1370 animations->UpdateState(true, events.get()); | 1371 animations->UpdateState(true, events.get()); |
1371 EXPECT_EQ(0.5f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1372 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1372 EXPECT_FALSE(animations->HasActiveAnimation()); | 1373 EXPECT_FALSE(animations->HasActiveAnimation()); |
1373 } | 1374 } |
1374 | 1375 |
1375 // Tests interrupting a transition with another transition. | 1376 // Tests interrupting a transition with another transition. |
1376 TEST_F(ElementAnimationsTest, Interrupt) { | 1377 TEST_F(ElementAnimationsTest, Interrupt) { |
1377 CreateTestLayer(false, false); | 1378 CreateTestLayer(false, false); |
1378 AttachTimelinePlayerLayer(); | 1379 AttachTimelinePlayerLayer(); |
1379 | 1380 |
1380 scoped_refptr<ElementAnimations> animations = element_animations(); | 1381 scoped_refptr<ElementAnimations> animations = element_animations(); |
1381 | 1382 |
1382 auto events = host_impl_->CreateEvents(); | 1383 auto events = host_impl_->CreateEvents(); |
1383 | 1384 |
1384 animations->AddAnimation(CreateAnimation( | 1385 animations->AddAnimation(CreateAnimation( |
1385 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1386 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1386 1, TargetProperty::OPACITY)); | 1387 1, TargetProperty::OPACITY)); |
1387 animations->Animate(kInitialTickTime); | 1388 animations->Animate(kInitialTickTime); |
1388 animations->UpdateState(true, events.get()); | 1389 animations->UpdateState(true, events.get()); |
1389 EXPECT_TRUE(animations->HasActiveAnimation()); | 1390 EXPECT_TRUE(animations->HasActiveAnimation()); |
1390 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1391 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1391 | 1392 |
1392 std::unique_ptr<Animation> to_add(CreateAnimation( | 1393 std::unique_ptr<Animation> to_add(CreateAnimation( |
1393 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1394 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
1394 2, TargetProperty::OPACITY)); | 1395 2, TargetProperty::OPACITY)); |
1395 animations->AbortAnimations(TargetProperty::OPACITY); | 1396 animations->AbortAnimations(TargetProperty::OPACITY); |
1396 animations->AddAnimation(std::move(to_add)); | 1397 animations->AddAnimation(std::move(to_add)); |
1397 | 1398 |
1398 // Since the previous animation was aborted, the new animation should start | 1399 // Since the previous animation was aborted, the new animation should start |
1399 // right in this call to animate. | 1400 // right in this call to animate. |
1400 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1401 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
1401 animations->UpdateState(true, events.get()); | 1402 animations->UpdateState(true, events.get()); |
1402 EXPECT_TRUE(animations->HasActiveAnimation()); | 1403 EXPECT_TRUE(animations->HasActiveAnimation()); |
1403 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1404 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1404 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | 1405 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); |
1405 animations->UpdateState(true, events.get()); | 1406 animations->UpdateState(true, events.get()); |
1406 EXPECT_EQ(0.5f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1407 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1407 EXPECT_FALSE(animations->HasActiveAnimation()); | 1408 EXPECT_FALSE(animations->HasActiveAnimation()); |
1408 } | 1409 } |
1409 | 1410 |
1410 // Tests scheduling two animations to run together when only one property is | 1411 // Tests scheduling two animations to run together when only one property is |
1411 // free. | 1412 // free. |
1412 TEST_F(ElementAnimationsTest, ScheduleTogetherWhenAPropertyIsBlocked) { | 1413 TEST_F(ElementAnimationsTest, ScheduleTogetherWhenAPropertyIsBlocked) { |
1413 CreateTestLayer(false, false); | 1414 CreateTestLayer(false, false); |
1414 AttachTimelinePlayerLayer(); | 1415 AttachTimelinePlayerLayer(); |
1415 | 1416 |
1416 scoped_refptr<ElementAnimations> animations = element_animations(); | 1417 scoped_refptr<ElementAnimations> animations = element_animations(); |
1417 | 1418 |
1418 auto events = host_impl_->CreateEvents(); | 1419 auto events = host_impl_->CreateEvents(); |
1419 | 1420 |
1420 animations->AddAnimation(CreateAnimation( | 1421 animations->AddAnimation(CreateAnimation( |
1421 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, | 1422 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, |
1422 TargetProperty::TRANSFORM)); | 1423 TargetProperty::TRANSFORM)); |
1423 animations->AddAnimation(CreateAnimation( | 1424 animations->AddAnimation(CreateAnimation( |
1424 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, | 1425 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 2, |
1425 TargetProperty::TRANSFORM)); | 1426 TargetProperty::TRANSFORM)); |
1426 animations->AddAnimation(CreateAnimation( | 1427 animations->AddAnimation(CreateAnimation( |
1427 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1428 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1428 2, TargetProperty::OPACITY)); | 1429 2, TargetProperty::OPACITY)); |
1429 | 1430 |
1430 animations->Animate(kInitialTickTime); | 1431 animations->Animate(kInitialTickTime); |
1431 animations->UpdateState(true, events.get()); | 1432 animations->UpdateState(true, events.get()); |
1432 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1433 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1433 EXPECT_TRUE(animations->HasActiveAnimation()); | 1434 EXPECT_TRUE(animations->HasActiveAnimation()); |
1434 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1435 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1435 animations->UpdateState(true, events.get()); | 1436 animations->UpdateState(true, events.get()); |
1436 // Should not have started the float transition yet. | 1437 // Should not have started the float transition yet. |
1437 EXPECT_TRUE(animations->HasActiveAnimation()); | 1438 EXPECT_TRUE(animations->HasActiveAnimation()); |
1438 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1439 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1439 // The float animation should have started at time 1 and should be done. | 1440 // The float animation should have started at time 1 and should be done. |
1440 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1441 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1441 animations->UpdateState(true, events.get()); | 1442 animations->UpdateState(true, events.get()); |
1442 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1443 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1443 EXPECT_FALSE(animations->HasActiveAnimation()); | 1444 EXPECT_FALSE(animations->HasActiveAnimation()); |
1444 } | 1445 } |
1445 | 1446 |
1446 // Tests scheduling two animations to run together with different lengths and | 1447 // Tests scheduling two animations to run together with different lengths and |
1447 // another animation queued to start when the shorter animation finishes (should | 1448 // another animation queued to start when the shorter animation finishes (should |
1448 // wait for both to finish). | 1449 // wait for both to finish). |
1449 TEST_F(ElementAnimationsTest, ScheduleTogetherWithAnAnimWaiting) { | 1450 TEST_F(ElementAnimationsTest, ScheduleTogetherWithAnAnimWaiting) { |
1450 CreateTestLayer(false, false); | 1451 CreateTestLayer(false, false); |
1451 AttachTimelinePlayerLayer(); | 1452 AttachTimelinePlayerLayer(); |
1452 | 1453 |
1453 scoped_refptr<ElementAnimations> animations = element_animations(); | 1454 scoped_refptr<ElementAnimations> animations = element_animations(); |
1454 | 1455 |
1455 auto events = host_impl_->CreateEvents(); | 1456 auto events = host_impl_->CreateEvents(); |
1456 | 1457 |
1457 animations->AddAnimation(CreateAnimation( | 1458 animations->AddAnimation(CreateAnimation( |
1458 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, | 1459 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(2)), 1, |
1459 TargetProperty::TRANSFORM)); | 1460 TargetProperty::TRANSFORM)); |
1460 animations->AddAnimation(CreateAnimation( | 1461 animations->AddAnimation(CreateAnimation( |
1461 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1462 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1462 1, TargetProperty::OPACITY)); | 1463 1, TargetProperty::OPACITY)); |
1463 animations->AddAnimation(CreateAnimation( | 1464 animations->AddAnimation(CreateAnimation( |
1464 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), | 1465 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)), |
1465 2, TargetProperty::OPACITY)); | 1466 2, TargetProperty::OPACITY)); |
1466 | 1467 |
1467 // Animations with id 1 should both start now. | 1468 // Animations with id 1 should both start now. |
1468 animations->Animate(kInitialTickTime); | 1469 animations->Animate(kInitialTickTime); |
1469 animations->UpdateState(true, events.get()); | 1470 animations->UpdateState(true, events.get()); |
1470 EXPECT_TRUE(animations->HasActiveAnimation()); | 1471 EXPECT_TRUE(animations->HasActiveAnimation()); |
1471 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1472 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1472 // The opacity animation should have finished at time 1, but the group | 1473 // The opacity animation should have finished at time 1, but the group |
1473 // of animations with id 1 don't finish until time 2 because of the length | 1474 // of animations with id 1 don't finish until time 2 because of the length |
1474 // of the transform animation. | 1475 // of the transform animation. |
1475 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1476 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1476 animations->UpdateState(true, events.get()); | 1477 animations->UpdateState(true, events.get()); |
1477 // Should not have started the float transition yet. | 1478 // Should not have started the float transition yet. |
1478 EXPECT_TRUE(animations->HasActiveAnimation()); | 1479 EXPECT_TRUE(animations->HasActiveAnimation()); |
1479 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1480 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1480 | 1481 |
1481 // The second opacity animation should start at time 2 and should be done by | 1482 // The second opacity animation should start at time 2 and should be done by |
1482 // time 3. | 1483 // time 3. |
1483 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1484 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
1484 animations->UpdateState(true, events.get()); | 1485 animations->UpdateState(true, events.get()); |
1485 EXPECT_EQ(0.5f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1486 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1486 EXPECT_FALSE(animations->HasActiveAnimation()); | 1487 EXPECT_FALSE(animations->HasActiveAnimation()); |
1487 } | 1488 } |
1488 | 1489 |
1489 // Test that a looping animation loops and for the correct number of iterations. | 1490 // Test that a looping animation loops and for the correct number of iterations. |
1490 TEST_F(ElementAnimationsTest, TrivialLooping) { | 1491 TEST_F(ElementAnimationsTest, TrivialLooping) { |
1491 CreateTestLayer(false, false); | 1492 CreateTestLayer(false, false); |
1492 AttachTimelinePlayerLayer(); | 1493 AttachTimelinePlayerLayer(); |
1493 | 1494 |
1494 scoped_refptr<ElementAnimations> animations = element_animations(); | 1495 scoped_refptr<ElementAnimations> animations = element_animations(); |
1495 | 1496 |
1496 auto events = host_impl_->CreateEvents(); | 1497 auto events = host_impl_->CreateEvents(); |
1497 | 1498 |
1498 std::unique_ptr<Animation> to_add(CreateAnimation( | 1499 std::unique_ptr<Animation> to_add(CreateAnimation( |
1499 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1500 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1500 1, TargetProperty::OPACITY)); | 1501 1, TargetProperty::OPACITY)); |
1501 to_add->set_iterations(3); | 1502 to_add->set_iterations(3); |
1502 animations->AddAnimation(std::move(to_add)); | 1503 animations->AddAnimation(std::move(to_add)); |
1503 | 1504 |
1504 animations->Animate(kInitialTickTime); | 1505 animations->Animate(kInitialTickTime); |
1505 animations->UpdateState(true, events.get()); | 1506 animations->UpdateState(true, events.get()); |
1506 EXPECT_TRUE(animations->HasActiveAnimation()); | 1507 EXPECT_TRUE(animations->HasActiveAnimation()); |
1507 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1508 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1508 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); | 1509 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); |
1509 animations->UpdateState(true, events.get()); | 1510 animations->UpdateState(true, events.get()); |
1510 EXPECT_TRUE(animations->HasActiveAnimation()); | 1511 EXPECT_TRUE(animations->HasActiveAnimation()); |
1511 EXPECT_EQ(0.25f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1512 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1512 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); | 1513 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); |
1513 animations->UpdateState(true, events.get()); | 1514 animations->UpdateState(true, events.get()); |
1514 EXPECT_TRUE(animations->HasActiveAnimation()); | 1515 EXPECT_TRUE(animations->HasActiveAnimation()); |
1515 EXPECT_EQ(0.75f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1516 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1516 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2250)); | 1517 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2250)); |
1517 animations->UpdateState(true, events.get()); | 1518 animations->UpdateState(true, events.get()); |
1518 EXPECT_TRUE(animations->HasActiveAnimation()); | 1519 EXPECT_TRUE(animations->HasActiveAnimation()); |
1519 EXPECT_EQ(0.25f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1520 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1520 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2750)); | 1521 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2750)); |
1521 animations->UpdateState(true, events.get()); | 1522 animations->UpdateState(true, events.get()); |
1522 EXPECT_TRUE(animations->HasActiveAnimation()); | 1523 EXPECT_TRUE(animations->HasActiveAnimation()); |
1523 EXPECT_EQ(0.75f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1524 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1524 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1525 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
1525 animations->UpdateState(true, events.get()); | 1526 animations->UpdateState(true, events.get()); |
1526 EXPECT_FALSE(animations->HasActiveAnimation()); | 1527 EXPECT_FALSE(animations->HasActiveAnimation()); |
1527 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1528 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1528 | 1529 |
1529 // Just be extra sure. | 1530 // Just be extra sure. |
1530 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); | 1531 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(4000)); |
1531 animations->UpdateState(true, events.get()); | 1532 animations->UpdateState(true, events.get()); |
1532 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1533 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1533 } | 1534 } |
1534 | 1535 |
1535 // Test that an infinitely looping animation does indeed go until aborted. | 1536 // Test that an infinitely looping animation does indeed go until aborted. |
1536 TEST_F(ElementAnimationsTest, InfiniteLooping) { | 1537 TEST_F(ElementAnimationsTest, InfiniteLooping) { |
1537 CreateTestLayer(false, false); | 1538 CreateTestLayer(false, false); |
1538 AttachTimelinePlayerLayer(); | 1539 AttachTimelinePlayerLayer(); |
1539 | 1540 |
1540 scoped_refptr<ElementAnimations> animations = element_animations(); | 1541 scoped_refptr<ElementAnimations> animations = element_animations(); |
1541 | 1542 |
1542 auto events = host_impl_->CreateEvents(); | 1543 auto events = host_impl_->CreateEvents(); |
1543 | 1544 |
1544 std::unique_ptr<Animation> to_add(CreateAnimation( | 1545 std::unique_ptr<Animation> to_add(CreateAnimation( |
1545 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1546 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1546 1, TargetProperty::OPACITY)); | 1547 1, TargetProperty::OPACITY)); |
1547 to_add->set_iterations(-1); | 1548 to_add->set_iterations(-1); |
1548 animations->AddAnimation(std::move(to_add)); | 1549 animations->AddAnimation(std::move(to_add)); |
1549 | 1550 |
1550 animations->Animate(kInitialTickTime); | 1551 animations->Animate(kInitialTickTime); |
1551 animations->UpdateState(true, events.get()); | 1552 animations->UpdateState(true, events.get()); |
1552 EXPECT_TRUE(animations->HasActiveAnimation()); | 1553 EXPECT_TRUE(animations->HasActiveAnimation()); |
1553 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1554 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1554 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); | 1555 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); |
1555 animations->UpdateState(true, events.get()); | 1556 animations->UpdateState(true, events.get()); |
1556 EXPECT_TRUE(animations->HasActiveAnimation()); | 1557 EXPECT_TRUE(animations->HasActiveAnimation()); |
1557 EXPECT_EQ(0.25f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1558 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1558 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); | 1559 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); |
1559 animations->UpdateState(true, events.get()); | 1560 animations->UpdateState(true, events.get()); |
1560 EXPECT_TRUE(animations->HasActiveAnimation()); | 1561 EXPECT_TRUE(animations->HasActiveAnimation()); |
1561 EXPECT_EQ(0.75f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1562 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1562 | 1563 |
1563 animations->Animate(kInitialTickTime + | 1564 animations->Animate(kInitialTickTime + |
1564 TimeDelta::FromMilliseconds(1073741824250)); | 1565 TimeDelta::FromMilliseconds(1073741824250)); |
1565 animations->UpdateState(true, events.get()); | 1566 animations->UpdateState(true, events.get()); |
1566 EXPECT_TRUE(animations->HasActiveAnimation()); | 1567 EXPECT_TRUE(animations->HasActiveAnimation()); |
1567 EXPECT_EQ(0.25f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1568 EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1568 animations->Animate(kInitialTickTime + | 1569 animations->Animate(kInitialTickTime + |
1569 TimeDelta::FromMilliseconds(1073741824750)); | 1570 TimeDelta::FromMilliseconds(1073741824750)); |
1570 animations->UpdateState(true, events.get()); | 1571 animations->UpdateState(true, events.get()); |
1571 EXPECT_TRUE(animations->HasActiveAnimation()); | 1572 EXPECT_TRUE(animations->HasActiveAnimation()); |
1572 EXPECT_EQ(0.75f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1573 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1573 | 1574 |
1574 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); | 1575 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); |
1575 animations->GetAnimation(TargetProperty::OPACITY) | 1576 animations->GetAnimation(TargetProperty::OPACITY) |
1576 ->SetRunState(Animation::ABORTED, | 1577 ->SetRunState(Animation::ABORTED, |
1577 kInitialTickTime + TimeDelta::FromMilliseconds(750)); | 1578 kInitialTickTime + TimeDelta::FromMilliseconds(750)); |
1578 EXPECT_FALSE(animations->HasActiveAnimation()); | 1579 EXPECT_FALSE(animations->HasActiveAnimation()); |
1579 EXPECT_EQ(0.75f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1580 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1580 } | 1581 } |
1581 | 1582 |
1582 // Test that pausing and resuming work as expected. | 1583 // Test that pausing and resuming work as expected. |
1583 TEST_F(ElementAnimationsTest, PauseResume) { | 1584 TEST_F(ElementAnimationsTest, PauseResume) { |
1584 CreateTestLayer(false, false); | 1585 CreateTestLayer(false, false); |
1585 AttachTimelinePlayerLayer(); | 1586 AttachTimelinePlayerLayer(); |
1586 | 1587 |
1587 scoped_refptr<ElementAnimations> animations = element_animations(); | 1588 scoped_refptr<ElementAnimations> animations = element_animations(); |
1588 | 1589 |
1589 auto events = host_impl_->CreateEvents(); | 1590 auto events = host_impl_->CreateEvents(); |
1590 | 1591 |
1591 animations->AddAnimation(CreateAnimation( | 1592 animations->AddAnimation(CreateAnimation( |
1592 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1593 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
1593 1, TargetProperty::OPACITY)); | 1594 1, TargetProperty::OPACITY)); |
1594 | 1595 |
1595 animations->Animate(kInitialTickTime); | 1596 animations->Animate(kInitialTickTime); |
1596 animations->UpdateState(true, events.get()); | 1597 animations->UpdateState(true, events.get()); |
1597 EXPECT_TRUE(animations->HasActiveAnimation()); | 1598 EXPECT_TRUE(animations->HasActiveAnimation()); |
1598 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1599 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1599 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1600 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
1600 animations->UpdateState(true, events.get()); | 1601 animations->UpdateState(true, events.get()); |
1601 EXPECT_TRUE(animations->HasActiveAnimation()); | 1602 EXPECT_TRUE(animations->HasActiveAnimation()); |
1602 EXPECT_EQ(0.5f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1603 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1603 | 1604 |
1604 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); | 1605 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); |
1605 animations->GetAnimation(TargetProperty::OPACITY) | 1606 animations->GetAnimation(TargetProperty::OPACITY) |
1606 ->SetRunState(Animation::PAUSED, | 1607 ->SetRunState(Animation::PAUSED, |
1607 kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 1608 kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
1608 | 1609 |
1609 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); | 1610 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); |
1610 animations->UpdateState(true, events.get()); | 1611 animations->UpdateState(true, events.get()); |
1611 EXPECT_TRUE(animations->HasActiveAnimation()); | 1612 EXPECT_TRUE(animations->HasActiveAnimation()); |
1612 EXPECT_EQ(0.5f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1613 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1613 | 1614 |
1614 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); | 1615 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); |
1615 animations->GetAnimation(TargetProperty::OPACITY) | 1616 animations->GetAnimation(TargetProperty::OPACITY) |
1616 ->SetRunState(Animation::RUNNING, | 1617 ->SetRunState(Animation::RUNNING, |
1617 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); | 1618 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); |
1618 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250)); | 1619 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250)); |
1619 animations->UpdateState(true, events.get()); | 1620 animations->UpdateState(true, events.get()); |
1620 EXPECT_TRUE(animations->HasActiveAnimation()); | 1621 EXPECT_TRUE(animations->HasActiveAnimation()); |
1621 EXPECT_EQ(0.75f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1622 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1622 | 1623 |
1623 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); | 1624 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); |
1624 animations->UpdateState(true, events.get()); | 1625 animations->UpdateState(true, events.get()); |
1625 EXPECT_FALSE(animations->HasActiveAnimation()); | 1626 EXPECT_FALSE(animations->HasActiveAnimation()); |
1626 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1627 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1627 } | 1628 } |
1628 | 1629 |
1629 TEST_F(ElementAnimationsTest, AbortAGroupedAnimation) { | 1630 TEST_F(ElementAnimationsTest, AbortAGroupedAnimation) { |
1630 CreateTestLayer(false, false); | 1631 CreateTestLayer(false, false); |
1631 AttachTimelinePlayerLayer(); | 1632 AttachTimelinePlayerLayer(); |
1632 | 1633 |
1633 scoped_refptr<ElementAnimations> animations = element_animations(); | 1634 scoped_refptr<ElementAnimations> animations = element_animations(); |
1634 | 1635 |
1635 auto events = host_impl_->CreateEvents(); | 1636 auto events = host_impl_->CreateEvents(); |
1636 | 1637 |
1637 const int animation_id = 2; | 1638 const int animation_id = 2; |
1638 animations->AddAnimation(Animation::Create( | 1639 animations->AddAnimation(Animation::Create( |
1639 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, | 1640 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1)), 1, 1, |
1640 TargetProperty::TRANSFORM)); | 1641 TargetProperty::TRANSFORM)); |
1641 animations->AddAnimation(Animation::Create( | 1642 animations->AddAnimation(Animation::Create( |
1642 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), | 1643 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)), |
1643 animation_id, 1, TargetProperty::OPACITY)); | 1644 animation_id, 1, TargetProperty::OPACITY)); |
1644 animations->AddAnimation(Animation::Create( | 1645 animations->AddAnimation(Animation::Create( |
1645 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), | 1646 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f)), |
1646 3, 2, TargetProperty::OPACITY)); | 1647 3, 2, TargetProperty::OPACITY)); |
1647 | 1648 |
1648 animations->Animate(kInitialTickTime); | 1649 animations->Animate(kInitialTickTime); |
1649 animations->UpdateState(true, events.get()); | 1650 animations->UpdateState(true, events.get()); |
1650 EXPECT_TRUE(animations->HasActiveAnimation()); | 1651 EXPECT_TRUE(animations->HasActiveAnimation()); |
1651 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1652 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1652 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1653 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1653 animations->UpdateState(true, events.get()); | 1654 animations->UpdateState(true, events.get()); |
1654 EXPECT_TRUE(animations->HasActiveAnimation()); | 1655 EXPECT_TRUE(animations->HasActiveAnimation()); |
1655 EXPECT_EQ(0.5f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1656 EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1656 | 1657 |
1657 EXPECT_TRUE(animations->GetAnimationById(animation_id)); | 1658 EXPECT_TRUE(animations->GetAnimationById(animation_id)); |
1658 animations->GetAnimationById(animation_id) | 1659 animations->GetAnimationById(animation_id) |
1659 ->SetRunState(Animation::ABORTED, | 1660 ->SetRunState(Animation::ABORTED, |
1660 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1661 kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1661 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1662 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1662 animations->UpdateState(true, events.get()); | 1663 animations->UpdateState(true, events.get()); |
1663 EXPECT_TRUE(animations->HasActiveAnimation()); | 1664 EXPECT_TRUE(animations->HasActiveAnimation()); |
1664 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1665 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1665 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1666 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1666 animations->UpdateState(true, events.get()); | 1667 animations->UpdateState(true, events.get()); |
1667 EXPECT_TRUE(!animations->HasActiveAnimation()); | 1668 EXPECT_TRUE(!animations->HasActiveAnimation()); |
1668 EXPECT_EQ(0.75f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1669 EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1669 } | 1670 } |
1670 | 1671 |
1671 TEST_F(ElementAnimationsTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { | 1672 TEST_F(ElementAnimationsTest, PushUpdatesWhenSynchronizedStartTimeNeeded) { |
1672 CreateTestLayer(true, false); | 1673 CreateTestLayer(true, false); |
1673 AttachTimelinePlayerLayer(); | 1674 AttachTimelinePlayerLayer(); |
1674 CreateImplTimelineAndPlayer(); | 1675 CreateImplTimelineAndPlayer(); |
1675 | 1676 |
1676 scoped_refptr<ElementAnimations> animations = element_animations(); | 1677 scoped_refptr<ElementAnimations> animations = element_animations(); |
1677 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 1678 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
1678 | 1679 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1732 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1732 events = host_impl_->CreateEvents(); | 1733 events = host_impl_->CreateEvents(); |
1733 animations->UpdateState(true, events.get()); | 1734 animations->UpdateState(true, events.get()); |
1734 | 1735 |
1735 // Should have one STARTED event and one FINISHED event. | 1736 // Should have one STARTED event and one FINISHED event. |
1736 EXPECT_EQ(2u, events->events_.size()); | 1737 EXPECT_EQ(2u, events->events_.size()); |
1737 EXPECT_NE(events->events_[0].type, events->events_[1].type); | 1738 EXPECT_NE(events->events_[0].type, events->events_[1].type); |
1738 | 1739 |
1739 // The float transition should still be at its starting point. | 1740 // The float transition should still be at its starting point. |
1740 EXPECT_TRUE(animations->HasActiveAnimation()); | 1741 EXPECT_TRUE(animations->HasActiveAnimation()); |
1741 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1742 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1742 | 1743 |
1743 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1744 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
1744 animations->UpdateState(true, events.get()); | 1745 animations->UpdateState(true, events.get()); |
1745 | 1746 |
1746 // The float tranisition should now be done. | 1747 // The float tranisition should now be done. |
1747 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1748 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1748 EXPECT_FALSE(animations->HasActiveAnimation()); | 1749 EXPECT_FALSE(animations->HasActiveAnimation()); |
1749 } | 1750 } |
1750 | 1751 |
1751 // Tests that an animation animations with only a pending observer gets ticked | 1752 // Tests that an animation animations with only a pending observer gets ticked |
1752 // but doesn't progress animations past the STARTING state. | 1753 // but doesn't progress animations past the STARTING state. |
1753 TEST_F(ElementAnimationsTest, InactiveObserverGetsTicked) { | 1754 TEST_F(ElementAnimationsTest, InactiveObserverGetsTicked) { |
1754 AttachTimelinePlayerLayer(); | 1755 AttachTimelinePlayerLayer(); |
1755 CreateImplTimelineAndPlayer(); | 1756 CreateImplTimelineAndPlayer(); |
1756 | 1757 |
1757 scoped_refptr<ElementAnimations> animations = element_animations_impl(); | 1758 scoped_refptr<ElementAnimations> animations = element_animations_impl(); |
(...skipping 16 matching lines...) Expand all Loading... |
1774 CreateTestImplLayer(LayerTreeType::PENDING); | 1775 CreateTestImplLayer(LayerTreeType::PENDING); |
1775 | 1776 |
1776 // With only a pending observer, the animation should progress to the | 1777 // With only a pending observer, the animation should progress to the |
1777 // STARTING state and get ticked at its starting point, but should not | 1778 // STARTING state and get ticked at its starting point, but should not |
1778 // progress to RUNNING. | 1779 // progress to RUNNING. |
1779 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 1780 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
1780 animations->UpdateState(true, events.get()); | 1781 animations->UpdateState(true, events.get()); |
1781 EXPECT_EQ(0u, events->events_.size()); | 1782 EXPECT_EQ(0u, events->events_.size()); |
1782 EXPECT_EQ(Animation::STARTING, | 1783 EXPECT_EQ(Animation::STARTING, |
1783 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1784 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); |
1784 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 1785 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
1785 | 1786 |
1786 // Even when already in the STARTING state, the animation should stay | 1787 // Even when already in the STARTING state, the animation should stay |
1787 // there, and shouldn't be ticked past its starting point. | 1788 // there, and shouldn't be ticked past its starting point. |
1788 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 1789 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
1789 animations->UpdateState(true, events.get()); | 1790 animations->UpdateState(true, events.get()); |
1790 EXPECT_EQ(0u, events->events_.size()); | 1791 EXPECT_EQ(0u, events->events_.size()); |
1791 EXPECT_EQ(Animation::STARTING, | 1792 EXPECT_EQ(Animation::STARTING, |
1792 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1793 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); |
1793 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 1794 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
1794 | 1795 |
1795 CreateTestImplLayer(LayerTreeType::ACTIVE); | 1796 CreateTestImplLayer(LayerTreeType::ACTIVE); |
1796 | 1797 |
1797 // Now that an active observer has been added, the animation should still | 1798 // Now that an active observer has been added, the animation should still |
1798 // initially tick at its starting point, but should now progress to RUNNING. | 1799 // initially tick at its starting point, but should now progress to RUNNING. |
1799 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); | 1800 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); |
1800 animations->UpdateState(true, events.get()); | 1801 animations->UpdateState(true, events.get()); |
1801 EXPECT_EQ(1u, events->events_.size()); | 1802 EXPECT_EQ(1u, events->events_.size()); |
1802 EXPECT_EQ(Animation::RUNNING, | 1803 EXPECT_EQ(Animation::RUNNING, |
1803 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1804 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); |
1804 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 1805 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
1805 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1806 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1806 | 1807 |
1807 // The animation should now tick past its starting point. | 1808 // The animation should now tick past its starting point. |
1808 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); | 1809 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); |
1809 EXPECT_NE(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 1810 EXPECT_NE(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
1810 EXPECT_NE(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 1811 EXPECT_NE(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
1811 } | 1812 } |
1812 | 1813 |
1813 TEST_F(ElementAnimationsTest, TransformAnimationBounds) { | 1814 TEST_F(ElementAnimationsTest, TransformAnimationBounds) { |
1814 AttachTimelinePlayerLayer(); | 1815 AttachTimelinePlayerLayer(); |
1815 CreateImplTimelineAndPlayer(); | 1816 CreateImplTimelineAndPlayer(); |
1816 | 1817 |
1817 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 1818 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
1818 | 1819 |
1819 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( | 1820 std::unique_ptr<KeyframedTransformAnimationCurve> curve1( |
1820 KeyframedTransformAnimationCurve::Create()); | 1821 KeyframedTransformAnimationCurve::Create()); |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2682 EXPECT_FALSE(animations_impl->needs_to_start_animations_for_testing()); | 2683 EXPECT_FALSE(animations_impl->needs_to_start_animations_for_testing()); |
2683 animations_impl->UpdateState(true, events.get()); | 2684 animations_impl->UpdateState(true, events.get()); |
2684 | 2685 |
2685 // Since the animation hasn't been activated, it should still be STARTING | 2686 // Since the animation hasn't been activated, it should still be STARTING |
2686 // rather than RUNNING. | 2687 // rather than RUNNING. |
2687 EXPECT_EQ(Animation::STARTING, | 2688 EXPECT_EQ(Animation::STARTING, |
2688 animations_impl->GetAnimationById(animation_id)->run_state()); | 2689 animations_impl->GetAnimationById(animation_id)->run_state()); |
2689 | 2690 |
2690 // Since the animation hasn't been activated, only the pending observer | 2691 // Since the animation hasn't been activated, only the pending observer |
2691 // should have been ticked. | 2692 // should have been ticked. |
2692 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 2693 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
2693 EXPECT_EQ(0.f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 2694 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
2694 | 2695 |
2695 animations_impl->ActivateAnimations(); | 2696 animations_impl->ActivateAnimations(); |
2696 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2697 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) |
2697 ->affects_pending_elements()); | 2698 ->affects_pending_elements()); |
2698 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2699 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) |
2699 ->affects_active_elements()); | 2700 ->affects_active_elements()); |
2700 | 2701 |
2701 animations_impl->Animate(kInitialTickTime + | 2702 animations_impl->Animate(kInitialTickTime + |
2702 TimeDelta::FromMilliseconds(1000)); | 2703 TimeDelta::FromMilliseconds(1000)); |
2703 animations_impl->UpdateState(true, events.get()); | 2704 animations_impl->UpdateState(true, events.get()); |
2704 | 2705 |
2705 // Since the animation has been activated, it should have reached the | 2706 // Since the animation has been activated, it should have reached the |
2706 // RUNNING state and the active observer should start to get ticked. | 2707 // RUNNING state and the active observer should start to get ticked. |
2707 EXPECT_EQ(Animation::RUNNING, | 2708 EXPECT_EQ(Animation::RUNNING, |
2708 animations_impl->GetAnimationById(animation_id)->run_state()); | 2709 animations_impl->GetAnimationById(animation_id)->run_state()); |
2709 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 2710 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
2710 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 2711 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
2711 } | 2712 } |
2712 | 2713 |
2713 TEST_F(ElementAnimationsTest, ActivationBetweenAnimateAndUpdateState) { | 2714 TEST_F(ElementAnimationsTest, ActivationBetweenAnimateAndUpdateState) { |
2714 CreateTestLayer(true, true); | 2715 CreateTestLayer(true, true); |
2715 AttachTimelinePlayerLayer(); | 2716 AttachTimelinePlayerLayer(); |
2716 CreateImplTimelineAndPlayer(); | 2717 CreateImplTimelineAndPlayer(); |
2717 | 2718 |
2718 scoped_refptr<ElementAnimations> animations = element_animations(); | 2719 scoped_refptr<ElementAnimations> animations = element_animations(); |
2719 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 2720 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
2720 | 2721 |
2721 auto events = host_impl_->CreateEvents(); | 2722 auto events = host_impl_->CreateEvents(); |
2722 | 2723 |
2723 const int animation_id = AddOpacityTransitionToElementAnimations( | 2724 const int animation_id = AddOpacityTransitionToElementAnimations( |
2724 animations.get(), 1, 0.5f, 1.f, true); | 2725 animations.get(), 1, 0.5f, 1.f, true); |
2725 | 2726 |
2726 animations->PushPropertiesTo(animations_impl.get()); | 2727 animations->PushPropertiesTo(animations_impl.get()); |
2727 | 2728 |
2728 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); | 2729 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); |
2729 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 2730 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
2730 animations_impl->GetAnimationById(animation_id)->run_state()); | 2731 animations_impl->GetAnimationById(animation_id)->run_state()); |
2731 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2732 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) |
2732 ->affects_pending_elements()); | 2733 ->affects_pending_elements()); |
2733 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id) | 2734 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id) |
2734 ->affects_active_elements()); | 2735 ->affects_active_elements()); |
2735 | 2736 |
2736 animations_impl->Animate(kInitialTickTime); | 2737 animations_impl->Animate(kInitialTickTime); |
2737 | 2738 |
2738 // Since the animation hasn't been activated, only the pending observer | 2739 // Since the animation hasn't been activated, only the pending observer |
2739 // should have been ticked. | 2740 // should have been ticked. |
2740 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 2741 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
2741 EXPECT_EQ(0.f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 2742 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
2742 | 2743 |
2743 animations_impl->ActivateAnimations(); | 2744 animations_impl->ActivateAnimations(); |
2744 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2745 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) |
2745 ->affects_pending_elements()); | 2746 ->affects_pending_elements()); |
2746 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2747 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) |
2747 ->affects_active_elements()); | 2748 ->affects_active_elements()); |
2748 | 2749 |
2749 animations_impl->UpdateState(true, events.get()); | 2750 animations_impl->UpdateState(true, events.get()); |
2750 | 2751 |
2751 // Since the animation has been activated, it should have reached the | 2752 // Since the animation has been activated, it should have reached the |
2752 // RUNNING state. | 2753 // RUNNING state. |
2753 EXPECT_EQ(Animation::RUNNING, | 2754 EXPECT_EQ(Animation::RUNNING, |
2754 animations_impl->GetAnimationById(animation_id)->run_state()); | 2755 animations_impl->GetAnimationById(animation_id)->run_state()); |
2755 | 2756 |
2756 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2757 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
2757 | 2758 |
2758 // Both elements should have been ticked. | 2759 // Both elements should have been ticked. |
2759 EXPECT_EQ(0.75f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 2760 EXPECT_EQ(0.75f, |
2760 EXPECT_EQ(0.75f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 2761 client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
| 2762 EXPECT_EQ(0.75f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
2761 } | 2763 } |
2762 | 2764 |
2763 TEST_F(ElementAnimationsTest, | 2765 TEST_F(ElementAnimationsTest, |
2764 ObserverNotifiedWhenTransformIsPotentiallyAnimatingChanges) { | 2766 ObserverNotifiedWhenTransformIsPotentiallyAnimatingChanges) { |
2765 CreateTestLayer(true, true); | 2767 CreateTestLayer(true, true); |
2766 AttachTimelinePlayerLayer(); | 2768 AttachTimelinePlayerLayer(); |
2767 CreateImplTimelineAndPlayer(); | 2769 CreateImplTimelineAndPlayer(); |
2768 | 2770 |
2769 scoped_refptr<ElementAnimations> animations = element_animations(); | 2771 scoped_refptr<ElementAnimations> animations = element_animations(); |
2770 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 2772 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
2771 | 2773 |
2772 auto events = host_impl_->CreateEvents(); | 2774 auto events = host_impl_->CreateEvents(); |
2773 | 2775 |
2774 EXPECT_FALSE( | 2776 EXPECT_FALSE( |
2775 client_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2777 client_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
| 2778 EXPECT_FALSE(client_impl_.GetTransformIsAnimating(element_id_, |
| 2779 LayerTreeType::PENDING)); |
2776 EXPECT_FALSE( | 2780 EXPECT_FALSE( |
2777 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2781 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2778 EXPECT_FALSE( | |
2779 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | |
2780 | 2782 |
2781 // Case 1: An animation that's allowed to run until its finish point. | 2783 // Case 1: An animation that's allowed to run until its finish point. |
2782 AddAnimatedTransformToElementAnimations(animations.get(), 1.0, 1, 1); | 2784 AddAnimatedTransformToElementAnimations(animations.get(), 1.0, 1, 1); |
2783 EXPECT_TRUE( | 2785 EXPECT_TRUE( |
2784 client_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2786 client_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2785 | 2787 |
2786 animations->PushPropertiesTo(animations_impl.get()); | 2788 animations->PushPropertiesTo(animations_impl.get()); |
2787 EXPECT_TRUE( | 2789 EXPECT_TRUE(client_impl_.GetTransformIsAnimating(element_id_, |
2788 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2790 LayerTreeType::PENDING)); |
2789 EXPECT_FALSE( | 2791 EXPECT_FALSE( |
2790 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2792 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2791 | 2793 |
2792 animations_impl->ActivateAnimations(); | 2794 animations_impl->ActivateAnimations(); |
| 2795 EXPECT_TRUE(client_impl_.GetTransformIsAnimating(element_id_, |
| 2796 LayerTreeType::PENDING)); |
2793 EXPECT_TRUE( | 2797 EXPECT_TRUE( |
2794 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2798 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2795 EXPECT_TRUE( | |
2796 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | |
2797 | 2799 |
2798 animations_impl->Animate(kInitialTickTime); | 2800 animations_impl->Animate(kInitialTickTime); |
2799 animations_impl->UpdateState(true, events.get()); | 2801 animations_impl->UpdateState(true, events.get()); |
2800 | 2802 |
2801 animations->NotifyAnimationStarted(events->events_[0]); | 2803 animations->NotifyAnimationStarted(events->events_[0]); |
2802 events->events_.clear(); | 2804 events->events_.clear(); |
2803 | 2805 |
2804 // Finish the animation. | 2806 // Finish the animation. |
2805 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2807 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
2806 animations->UpdateState(true, nullptr); | 2808 animations->UpdateState(true, nullptr); |
2807 EXPECT_FALSE( | 2809 EXPECT_FALSE( |
2808 client_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2810 client_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2809 | 2811 |
2810 animations->PushPropertiesTo(animations_impl.get()); | 2812 animations->PushPropertiesTo(animations_impl.get()); |
2811 | 2813 |
2812 // animations_impl hasn't yet ticked at/past the end of the animation. | 2814 // animations_impl hasn't yet ticked at/past the end of the animation. |
| 2815 EXPECT_TRUE(client_impl_.GetTransformIsAnimating(element_id_, |
| 2816 LayerTreeType::PENDING)); |
2813 EXPECT_TRUE( | 2817 EXPECT_TRUE( |
2814 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2818 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2815 EXPECT_TRUE( | |
2816 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | |
2817 | 2819 |
2818 animations_impl->Animate(kInitialTickTime + | 2820 animations_impl->Animate(kInitialTickTime + |
2819 TimeDelta::FromMilliseconds(1000)); | 2821 TimeDelta::FromMilliseconds(1000)); |
2820 animations_impl->UpdateState(true, events.get()); | 2822 animations_impl->UpdateState(true, events.get()); |
| 2823 EXPECT_FALSE(client_impl_.GetTransformIsAnimating(element_id_, |
| 2824 LayerTreeType::PENDING)); |
2821 EXPECT_FALSE( | 2825 EXPECT_FALSE( |
2822 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2826 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2823 EXPECT_FALSE( | |
2824 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | |
2825 | 2827 |
2826 animations->NotifyAnimationFinished(events->events_[0]); | 2828 animations->NotifyAnimationFinished(events->events_[0]); |
2827 events->events_.clear(); | 2829 events->events_.clear(); |
2828 | 2830 |
2829 // Case 2: An animation that's removed before it finishes. | 2831 // Case 2: An animation that's removed before it finishes. |
2830 int animation_id = | 2832 int animation_id = |
2831 AddAnimatedTransformToElementAnimations(animations.get(), 10.0, 2, 2); | 2833 AddAnimatedTransformToElementAnimations(animations.get(), 10.0, 2, 2); |
2832 EXPECT_TRUE( | 2834 EXPECT_TRUE( |
2833 client_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2835 client_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2834 | 2836 |
2835 animations->PushPropertiesTo(animations_impl.get()); | 2837 animations->PushPropertiesTo(animations_impl.get()); |
2836 EXPECT_TRUE( | 2838 EXPECT_TRUE(client_impl_.GetTransformIsAnimating(element_id_, |
2837 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2839 LayerTreeType::PENDING)); |
2838 EXPECT_FALSE( | 2840 EXPECT_FALSE( |
2839 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2841 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2840 | 2842 |
2841 animations_impl->ActivateAnimations(); | 2843 animations_impl->ActivateAnimations(); |
| 2844 EXPECT_TRUE(client_impl_.GetTransformIsAnimating(element_id_, |
| 2845 LayerTreeType::PENDING)); |
2842 EXPECT_TRUE( | 2846 EXPECT_TRUE( |
2843 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2847 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2844 EXPECT_TRUE( | |
2845 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | |
2846 | 2848 |
2847 animations_impl->Animate(kInitialTickTime + | 2849 animations_impl->Animate(kInitialTickTime + |
2848 TimeDelta::FromMilliseconds(2000)); | 2850 TimeDelta::FromMilliseconds(2000)); |
2849 animations_impl->UpdateState(true, events.get()); | 2851 animations_impl->UpdateState(true, events.get()); |
2850 | 2852 |
2851 animations->NotifyAnimationStarted(events->events_[0]); | 2853 animations->NotifyAnimationStarted(events->events_[0]); |
2852 events->events_.clear(); | 2854 events->events_.clear(); |
2853 | 2855 |
2854 animations->RemoveAnimation(animation_id); | 2856 animations->RemoveAnimation(animation_id); |
2855 EXPECT_FALSE( | 2857 EXPECT_FALSE( |
2856 client_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2858 client_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2857 | 2859 |
2858 animations->PushPropertiesTo(animations_impl.get()); | 2860 animations->PushPropertiesTo(animations_impl.get()); |
2859 EXPECT_FALSE( | 2861 EXPECT_FALSE(client_impl_.GetTransformIsAnimating(element_id_, |
2860 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2862 LayerTreeType::PENDING)); |
2861 EXPECT_TRUE( | 2863 EXPECT_TRUE( |
2862 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2864 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2863 | 2865 |
2864 animations_impl->ActivateAnimations(); | 2866 animations_impl->ActivateAnimations(); |
| 2867 EXPECT_FALSE(client_impl_.GetTransformIsAnimating(element_id_, |
| 2868 LayerTreeType::PENDING)); |
2865 EXPECT_FALSE( | 2869 EXPECT_FALSE( |
2866 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2870 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2867 EXPECT_FALSE( | |
2868 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | |
2869 | 2871 |
2870 // Case 3: An animation that's aborted before it finishes. | 2872 // Case 3: An animation that's aborted before it finishes. |
2871 animation_id = | 2873 animation_id = |
2872 AddAnimatedTransformToElementAnimations(animations.get(), 10.0, 3, 3); | 2874 AddAnimatedTransformToElementAnimations(animations.get(), 10.0, 3, 3); |
2873 EXPECT_TRUE( | 2875 EXPECT_TRUE( |
2874 client_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2876 client_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2875 | 2877 |
2876 animations->PushPropertiesTo(animations_impl.get()); | 2878 animations->PushPropertiesTo(animations_impl.get()); |
2877 EXPECT_TRUE( | 2879 EXPECT_TRUE(client_impl_.GetTransformIsAnimating(element_id_, |
2878 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2880 LayerTreeType::PENDING)); |
2879 EXPECT_FALSE( | 2881 EXPECT_FALSE( |
2880 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2882 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2881 | 2883 |
2882 animations_impl->ActivateAnimations(); | 2884 animations_impl->ActivateAnimations(); |
| 2885 EXPECT_TRUE(client_impl_.GetTransformIsAnimating(element_id_, |
| 2886 LayerTreeType::PENDING)); |
2883 EXPECT_TRUE( | 2887 EXPECT_TRUE( |
2884 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2888 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2885 EXPECT_TRUE( | |
2886 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | |
2887 | 2889 |
2888 animations_impl->Animate(kInitialTickTime + | 2890 animations_impl->Animate(kInitialTickTime + |
2889 TimeDelta::FromMilliseconds(3000)); | 2891 TimeDelta::FromMilliseconds(3000)); |
2890 animations_impl->UpdateState(true, events.get()); | 2892 animations_impl->UpdateState(true, events.get()); |
2891 | 2893 |
2892 animations->NotifyAnimationStarted(events->events_[0]); | 2894 animations->NotifyAnimationStarted(events->events_[0]); |
2893 events->events_.clear(); | 2895 events->events_.clear(); |
2894 | 2896 |
2895 animations_impl->AbortAnimations(TargetProperty::TRANSFORM); | 2897 animations_impl->AbortAnimations(TargetProperty::TRANSFORM); |
| 2898 EXPECT_FALSE(client_impl_.GetTransformIsAnimating(element_id_, |
| 2899 LayerTreeType::PENDING)); |
2896 EXPECT_FALSE( | 2900 EXPECT_FALSE( |
2897 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::PENDING)); | 2901 client_impl_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2898 EXPECT_FALSE( | |
2899 client_impl_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | |
2900 | 2902 |
2901 animations_impl->Animate(kInitialTickTime + | 2903 animations_impl->Animate(kInitialTickTime + |
2902 TimeDelta::FromMilliseconds(4000)); | 2904 TimeDelta::FromMilliseconds(4000)); |
2903 animations_impl->UpdateState(true, events.get()); | 2905 animations_impl->UpdateState(true, events.get()); |
2904 | 2906 |
2905 animations->NotifyAnimationAborted(events->events_[0]); | 2907 animations->NotifyAnimationAborted(events->events_[0]); |
2906 EXPECT_FALSE( | 2908 EXPECT_FALSE( |
2907 client_.GetTransformIsAnimating(layer_id_, LayerTreeType::ACTIVE)); | 2909 client_.GetTransformIsAnimating(element_id_, LayerTreeType::ACTIVE)); |
2908 } | 2910 } |
2909 | 2911 |
2910 TEST_F(ElementAnimationsTest, ClippedOpacityValues) { | 2912 TEST_F(ElementAnimationsTest, ClippedOpacityValues) { |
2911 CreateTestLayer(false, false); | 2913 CreateTestLayer(false, false); |
2912 AttachTimelinePlayerLayer(); | 2914 AttachTimelinePlayerLayer(); |
2913 | 2915 |
2914 scoped_refptr<ElementAnimations> animations = element_animations(); | 2916 scoped_refptr<ElementAnimations> animations = element_animations(); |
2915 | 2917 |
2916 AddOpacityTransitionToElementAnimations(animations.get(), 1, 1.f, 2.f, true); | 2918 AddOpacityTransitionToElementAnimations(animations.get(), 1, 1.f, 2.f, true); |
2917 | 2919 |
2918 animations->Animate(kInitialTickTime); | 2920 animations->Animate(kInitialTickTime); |
2919 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 2921 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
2920 | 2922 |
2921 // Opacity values are clipped [0,1] | 2923 // Opacity values are clipped [0,1] |
2922 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2924 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
2923 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 2925 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
2924 } | 2926 } |
2925 | 2927 |
2926 TEST_F(ElementAnimationsTest, ClippedNegativeOpacityValues) { | 2928 TEST_F(ElementAnimationsTest, ClippedNegativeOpacityValues) { |
2927 CreateTestLayer(false, false); | 2929 CreateTestLayer(false, false); |
2928 AttachTimelinePlayerLayer(); | 2930 AttachTimelinePlayerLayer(); |
2929 | 2931 |
2930 scoped_refptr<ElementAnimations> animations = element_animations(); | 2932 scoped_refptr<ElementAnimations> animations = element_animations(); |
2931 | 2933 |
2932 AddOpacityTransitionToElementAnimations(animations.get(), 1, 0.f, -2.f, true); | 2934 AddOpacityTransitionToElementAnimations(animations.get(), 1, 0.f, -2.f, true); |
2933 | 2935 |
2934 animations->Animate(kInitialTickTime); | 2936 animations->Animate(kInitialTickTime); |
2935 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 2937 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
2936 | 2938 |
2937 // Opacity values are clipped [0,1] | 2939 // Opacity values are clipped [0,1] |
2938 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 2940 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
2939 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 2941 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
2940 } | 2942 } |
2941 | 2943 |
2942 TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) { | 2944 TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) { |
2943 CreateTestLayer(true, true); | 2945 CreateTestLayer(true, true); |
2944 AttachTimelinePlayerLayer(); | 2946 AttachTimelinePlayerLayer(); |
2945 CreateImplTimelineAndPlayer(); | 2947 CreateImplTimelineAndPlayer(); |
2946 | 2948 |
2947 scoped_refptr<ElementAnimations> animations = element_animations(); | 2949 scoped_refptr<ElementAnimations> animations = element_animations(); |
2948 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 2950 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
2949 | 2951 |
2950 auto events = host_impl_->CreateEvents(); | 2952 auto events = host_impl_->CreateEvents(); |
2951 | 2953 |
2952 const int animation_id = AddOpacityTransitionToElementAnimations( | 2954 const int animation_id = AddOpacityTransitionToElementAnimations( |
2953 animations.get(), 1, 0.5f, 1.f, true); | 2955 animations.get(), 1, 0.5f, 1.f, true); |
2954 | 2956 |
2955 animations->PushPropertiesTo(animations_impl.get()); | 2957 animations->PushPropertiesTo(animations_impl.get()); |
2956 animations_impl->ActivateAnimations(); | 2958 animations_impl->ActivateAnimations(); |
2957 animations_impl->Animate(kInitialTickTime); | 2959 animations_impl->Animate(kInitialTickTime); |
2958 animations_impl->UpdateState(true, events.get()); | 2960 animations_impl->UpdateState(true, events.get()); |
2959 EXPECT_EQ(Animation::RUNNING, | 2961 EXPECT_EQ(Animation::RUNNING, |
2960 animations_impl->GetAnimationById(animation_id)->run_state()); | 2962 animations_impl->GetAnimationById(animation_id)->run_state()); |
2961 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 2963 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
2962 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 2964 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
2963 | 2965 |
2964 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2966 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) |
2965 ->affects_pending_elements()); | 2967 ->affects_pending_elements()); |
2966 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2968 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) |
2967 ->affects_active_elements()); | 2969 ->affects_active_elements()); |
2968 | 2970 |
2969 // Delete the animation on the main-thread animations. | 2971 // Delete the animation on the main-thread animations. |
2970 animations->RemoveAnimation( | 2972 animations->RemoveAnimation( |
2971 animations->GetAnimation(TargetProperty::OPACITY)->id()); | 2973 animations->GetAnimation(TargetProperty::OPACITY)->id()); |
2972 animations->PushPropertiesTo(animations_impl.get()); | 2974 animations->PushPropertiesTo(animations_impl.get()); |
2973 | 2975 |
2974 // The animation should no longer affect pending elements. | 2976 // The animation should no longer affect pending elements. |
2975 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id) | 2977 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id) |
2976 ->affects_pending_elements()); | 2978 ->affects_pending_elements()); |
2977 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) | 2979 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id) |
2978 ->affects_active_elements()); | 2980 ->affects_active_elements()); |
2979 | 2981 |
2980 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 2982 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
2981 animations_impl->UpdateState(true, events.get()); | 2983 animations_impl->UpdateState(true, events.get()); |
2982 | 2984 |
2983 // Only the active observer should have been ticked. | 2985 // Only the active observer should have been ticked. |
2984 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 2986 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
2985 EXPECT_EQ(0.75f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 2987 EXPECT_EQ(0.75f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
2986 | 2988 |
2987 animations_impl->ActivateAnimations(); | 2989 animations_impl->ActivateAnimations(); |
2988 | 2990 |
2989 // Activation should cause the animation to be deleted. | 2991 // Activation should cause the animation to be deleted. |
2990 EXPECT_FALSE(animations_impl->has_any_animation()); | 2992 EXPECT_FALSE(animations_impl->has_any_animation()); |
2991 } | 2993 } |
2992 | 2994 |
2993 // Tests that an animation that affects only active elements won't block | 2995 // Tests that an animation that affects only active elements won't block |
2994 // an animation that affects only pending elements from starting. | 2996 // an animation that affects only pending elements from starting. |
2995 TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) { | 2997 TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3035 // The original animation should still be running, and the new animation | 3037 // The original animation should still be running, and the new animation |
3036 // should be starting. | 3038 // should be starting. |
3037 EXPECT_EQ(Animation::RUNNING, | 3039 EXPECT_EQ(Animation::RUNNING, |
3038 animations_impl->GetAnimationById(first_animation_id)->run_state()); | 3040 animations_impl->GetAnimationById(first_animation_id)->run_state()); |
3039 EXPECT_EQ( | 3041 EXPECT_EQ( |
3040 Animation::STARTING, | 3042 Animation::STARTING, |
3041 animations_impl->GetAnimationById(second_animation_id)->run_state()); | 3043 animations_impl->GetAnimationById(second_animation_id)->run_state()); |
3042 | 3044 |
3043 // The active observer should have been ticked by the original animation, | 3045 // The active observer should have been ticked by the original animation, |
3044 // and the pending observer should have been ticked by the new animation. | 3046 // and the pending observer should have been ticked by the new animation. |
3045 EXPECT_EQ(1.f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 3047 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
3046 EXPECT_EQ(0.5f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 3048 EXPECT_EQ(0.5f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
3047 | 3049 |
3048 animations_impl->ActivateAnimations(); | 3050 animations_impl->ActivateAnimations(); |
3049 | 3051 |
3050 // The original animation should have been deleted, and the new animation | 3052 // The original animation should have been deleted, and the new animation |
3051 // should now affect both elements. | 3053 // should now affect both elements. |
3052 EXPECT_FALSE(animations_impl->GetAnimationById(first_animation_id)); | 3054 EXPECT_FALSE(animations_impl->GetAnimationById(first_animation_id)); |
3053 EXPECT_TRUE(animations_impl->GetAnimationById(second_animation_id) | 3055 EXPECT_TRUE(animations_impl->GetAnimationById(second_animation_id) |
3054 ->affects_pending_elements()); | 3056 ->affects_pending_elements()); |
3055 EXPECT_TRUE(animations_impl->GetAnimationById(second_animation_id) | 3057 EXPECT_TRUE(animations_impl->GetAnimationById(second_animation_id) |
3056 ->affects_active_elements()); | 3058 ->affects_active_elements()); |
3057 | 3059 |
3058 animations_impl->Animate(kInitialTickTime + | 3060 animations_impl->Animate(kInitialTickTime + |
3059 TimeDelta::FromMilliseconds(1000)); | 3061 TimeDelta::FromMilliseconds(1000)); |
3060 animations_impl->UpdateState(true, events.get()); | 3062 animations_impl->UpdateState(true, events.get()); |
3061 | 3063 |
3062 // The new animation should be running, and the active observer should have | 3064 // The new animation should be running, and the active observer should have |
3063 // been ticked at the new animation's starting point. | 3065 // been ticked at the new animation's starting point. |
3064 EXPECT_EQ( | 3066 EXPECT_EQ( |
3065 Animation::RUNNING, | 3067 Animation::RUNNING, |
3066 animations_impl->GetAnimationById(second_animation_id)->run_state()); | 3068 animations_impl->GetAnimationById(second_animation_id)->run_state()); |
3067 EXPECT_EQ(1.f, client_impl_.GetOpacity(layer_id_, LayerTreeType::PENDING)); | 3069 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, LayerTreeType::PENDING)); |
3068 EXPECT_EQ(1.f, client_impl_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 3070 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
3069 } | 3071 } |
3070 | 3072 |
3071 TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) { | 3073 TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) { |
3072 CreateTestLayer(false, false); | 3074 CreateTestLayer(false, false); |
3073 AttachTimelinePlayerLayer(); | 3075 AttachTimelinePlayerLayer(); |
3074 | 3076 |
3075 scoped_refptr<ElementAnimations> animations = element_animations(); | 3077 scoped_refptr<ElementAnimations> animations = element_animations(); |
3076 | 3078 |
3077 // Create an animation that initially affects only pending elements. | 3079 // Create an animation that initially affects only pending elements. |
3078 std::unique_ptr<Animation> animation(CreateAnimation( | 3080 std::unique_ptr<Animation> animation(CreateAnimation( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3114 | 3116 |
3115 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, | 3117 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3116 LayerTreeType::PENDING)); | 3118 LayerTreeType::PENDING)); |
3117 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, | 3119 EXPECT_TRUE(animations->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3118 LayerTreeType::ACTIVE)); | 3120 LayerTreeType::ACTIVE)); |
3119 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3121 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( |
3120 TargetProperty::FILTER, LayerTreeType::PENDING)); | 3122 TargetProperty::FILTER, LayerTreeType::PENDING)); |
3121 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, | 3123 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, |
3122 LayerTreeType::ACTIVE)); | 3124 LayerTreeType::ACTIVE)); |
3123 | 3125 |
3124 EXPECT_EQ(0.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 3126 EXPECT_EQ(0.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
3125 | 3127 |
3126 // Tick past the end of the animation. | 3128 // Tick past the end of the animation. |
3127 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1100)); | 3129 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1100)); |
3128 animations->UpdateState(true, nullptr); | 3130 animations->UpdateState(true, nullptr); |
3129 | 3131 |
3130 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3132 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( |
3131 TargetProperty::OPACITY, LayerTreeType::PENDING)); | 3133 TargetProperty::OPACITY, LayerTreeType::PENDING)); |
3132 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, | 3134 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3133 LayerTreeType::ACTIVE)); | 3135 LayerTreeType::ACTIVE)); |
3134 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3136 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( |
3135 TargetProperty::FILTER, LayerTreeType::PENDING)); | 3137 TargetProperty::FILTER, LayerTreeType::PENDING)); |
3136 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, | 3138 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(TargetProperty::FILTER, |
3137 LayerTreeType::ACTIVE)); | 3139 LayerTreeType::ACTIVE)); |
3138 | 3140 |
3139 EXPECT_EQ(1.f, client_.GetOpacity(layer_id_, LayerTreeType::ACTIVE)); | 3141 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, LayerTreeType::ACTIVE)); |
3140 } | 3142 } |
3141 | 3143 |
3142 TEST_F(ElementAnimationsTest, TestIsAnimatingPropertyTimeOffsetFillMode) { | 3144 TEST_F(ElementAnimationsTest, TestIsAnimatingPropertyTimeOffsetFillMode) { |
3143 CreateTestLayer(false, false); | 3145 CreateTestLayer(false, false); |
3144 AttachTimelinePlayerLayer(); | 3146 AttachTimelinePlayerLayer(); |
3145 | 3147 |
3146 scoped_refptr<ElementAnimations> animations = element_animations(); | 3148 scoped_refptr<ElementAnimations> animations = element_animations(); |
3147 | 3149 |
3148 // Create an animation that initially affects only pending elements, and has | 3150 // Create an animation that initially affects only pending elements, and has |
3149 // a start delay of 2 seconds. | 3151 // a start delay of 2 seconds. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3215 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( | 3217 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( |
3216 TargetProperty::OPACITY, LayerTreeType::ACTIVE)); | 3218 TargetProperty::OPACITY, LayerTreeType::ACTIVE)); |
3217 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3219 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( |
3218 TargetProperty::OPACITY, LayerTreeType::PENDING)); | 3220 TargetProperty::OPACITY, LayerTreeType::PENDING)); |
3219 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, | 3221 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY, |
3220 LayerTreeType::ACTIVE)); | 3222 LayerTreeType::ACTIVE)); |
3221 } | 3223 } |
3222 | 3224 |
3223 } // namespace | 3225 } // namespace |
3224 } // namespace cc | 3226 } // namespace cc |
OLD | NEW |