| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/layer_animation_controller.h" | 5 #include "cc/animation/layer_animation_controller.h" |
| 6 | 6 |
| 7 #include "cc/animation/animation.h" | 7 #include "cc/animation/animation.h" |
| 8 #include "cc/animation/animation_curve.h" | 8 #include "cc/animation/animation_curve.h" |
| 9 #include "cc/animation/animation_delegate.h" | 9 #include "cc/animation/animation_delegate.h" |
| 10 #include "cc/animation/animation_registrar.h" |
| 10 #include "cc/animation/keyframed_animation_curve.h" | 11 #include "cc/animation/keyframed_animation_curve.h" |
| 11 #include "cc/animation/transform_operations.h" | 12 #include "cc/animation/transform_operations.h" |
| 12 #include "cc/test/animation_test_common.h" | 13 #include "cc/test/animation_test_common.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/gfx/box_f.h" | 16 #include "ui/gfx/box_f.h" |
| 16 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
| 17 | 18 |
| 18 namespace cc { | 19 namespace cc { |
| 19 namespace { | 20 namespace { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 86 |
| 86 // Start the animation on the main thread. Should not affect the start time. | 87 // Start the animation on the main thread. Should not affect the start time. |
| 87 controller->Animate(1.5); | 88 controller->Animate(1.5); |
| 88 controller->UpdateState(true, NULL); | 89 controller->UpdateState(true, NULL); |
| 89 EXPECT_EQ(controller->GetAnimation(group_id, | 90 EXPECT_EQ(controller->GetAnimation(group_id, |
| 90 Animation::Opacity)->start_time(), | 91 Animation::Opacity)->start_time(), |
| 91 controller_impl->GetAnimation(group_id, | 92 controller_impl->GetAnimation(group_id, |
| 92 Animation::Opacity)->start_time()); | 93 Animation::Opacity)->start_time()); |
| 93 } | 94 } |
| 94 | 95 |
| 96 // Tests that controllers activate and deactivate as expected. |
| 97 TEST(LayerAnimationControllerTest, Activation) { |
| 98 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); |
| 99 scoped_ptr<AnimationRegistrar> registrar_impl = AnimationRegistrar::Create(); |
| 100 |
| 101 FakeLayerAnimationValueObserver dummy_impl; |
| 102 scoped_refptr<LayerAnimationController> controller_impl( |
| 103 LayerAnimationController::Create(0)); |
| 104 controller_impl->AddValueObserver(&dummy_impl); |
| 105 FakeLayerAnimationValueObserver dummy; |
| 106 scoped_refptr<LayerAnimationController> controller( |
| 107 LayerAnimationController::Create(0)); |
| 108 controller->AddValueObserver(&dummy); |
| 109 scoped_ptr<AnimationEventsVector> events( |
| 110 make_scoped_ptr(new AnimationEventsVector)); |
| 111 |
| 112 controller->SetAnimationRegistrar(registrar.get()); |
| 113 controller_impl->SetAnimationRegistrar(registrar_impl.get()); |
| 114 EXPECT_EQ(1u, registrar->all_animation_controllers().size()); |
| 115 EXPECT_EQ(1u, registrar_impl->all_animation_controllers().size()); |
| 116 |
| 117 // Initially, both controllers should be inactive. |
| 118 EXPECT_EQ(0u, registrar->active_animation_controllers().size()); |
| 119 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size()); |
| 120 |
| 121 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 122 // The main thread controller should now be active. |
| 123 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
| 124 |
| 125 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 126 // Both controllers should now be active. |
| 127 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
| 128 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); |
| 129 |
| 130 controller_impl->Animate(1.0); |
| 131 controller_impl->UpdateState(true, events.get()); |
| 132 EXPECT_EQ(1u, events->size()); |
| 133 controller->NotifyAnimationStarted((*events)[0], 0.0); |
| 134 |
| 135 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
| 136 EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size()); |
| 137 |
| 138 controller->Animate(1.5); |
| 139 controller->UpdateState(true, NULL); |
| 140 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
| 141 |
| 142 controller->Animate(2.0); |
| 143 controller->UpdateState(true, NULL); |
| 144 EXPECT_EQ(Animation::Finished, |
| 145 controller->GetAnimation(Animation::Opacity)->run_state()); |
| 146 EXPECT_EQ(1u, registrar->active_animation_controllers().size()); |
| 147 |
| 148 events.reset(new AnimationEventsVector); |
| 149 controller_impl->Animate(2.5); |
| 150 controller_impl->UpdateState(true, events.get()); |
| 151 |
| 152 EXPECT_EQ(Animation::WaitingForDeletion, |
| 153 controller_impl->GetAnimation(Animation::Opacity)->run_state()); |
| 154 // The impl thread controller should have de-activated. |
| 155 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size()); |
| 156 |
| 157 EXPECT_EQ(1u, events->size()); |
| 158 controller->NotifyAnimationFinished((*events)[0], 0.0); |
| 159 controller->Animate(2.5); |
| 160 controller->UpdateState(true, NULL); |
| 161 |
| 162 EXPECT_EQ(Animation::WaitingForDeletion, |
| 163 controller->GetAnimation(Animation::Opacity)->run_state()); |
| 164 // The main thread controller should have de-activated. |
| 165 EXPECT_EQ(0u, registrar->active_animation_controllers().size()); |
| 166 |
| 167 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 168 EXPECT_FALSE(controller->has_any_animation()); |
| 169 EXPECT_FALSE(controller_impl->has_any_animation()); |
| 170 EXPECT_EQ(0u, registrar->active_animation_controllers().size()); |
| 171 EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size()); |
| 172 |
| 173 controller->SetAnimationRegistrar(NULL); |
| 174 controller_impl->SetAnimationRegistrar(NULL); |
| 175 } |
| 176 |
| 95 TEST(LayerAnimationControllerTest, SyncPause) { | 177 TEST(LayerAnimationControllerTest, SyncPause) { |
| 96 FakeLayerAnimationValueObserver dummy_impl; | 178 FakeLayerAnimationValueObserver dummy_impl; |
| 97 scoped_refptr<LayerAnimationController> controller_impl( | 179 scoped_refptr<LayerAnimationController> controller_impl( |
| 98 LayerAnimationController::Create(0)); | 180 LayerAnimationController::Create(0)); |
| 99 controller_impl->AddValueObserver(&dummy_impl); | 181 controller_impl->AddValueObserver(&dummy_impl); |
| 100 FakeLayerAnimationValueObserver dummy; | 182 FakeLayerAnimationValueObserver dummy; |
| 101 scoped_refptr<LayerAnimationController> controller( | 183 scoped_refptr<LayerAnimationController> controller( |
| 102 LayerAnimationController::Create(0)); | 184 LayerAnimationController::Create(0)); |
| 103 controller->AddValueObserver(&dummy); | 185 controller->AddValueObserver(&dummy); |
| 104 | 186 |
| (...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 curve3->AddKeyframe(TransformKeyframe::Create( | 1350 curve3->AddKeyframe(TransformKeyframe::Create( |
| 1269 1.0, operations3, scoped_ptr<TimingFunction>())); | 1351 1.0, operations3, scoped_ptr<TimingFunction>())); |
| 1270 animation = Animation::Create( | 1352 animation = Animation::Create( |
| 1271 curve3.PassAs<AnimationCurve>(), 3, 3, Animation::Transform); | 1353 curve3.PassAs<AnimationCurve>(), 3, 3, Animation::Transform); |
| 1272 controller_impl->AddAnimation(animation.Pass()); | 1354 controller_impl->AddAnimation(animation.Pass()); |
| 1273 EXPECT_FALSE(controller_impl->AnimatedBoundsForBox(box, &bounds)); | 1355 EXPECT_FALSE(controller_impl->AnimatedBoundsForBox(box, &bounds)); |
| 1274 } | 1356 } |
| 1275 | 1357 |
| 1276 } // namespace | 1358 } // namespace |
| 1277 } // namespace cc | 1359 } // namespace cc |
| OLD | NEW |