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/keyframed_animation_curve.h" | 9 #include "cc/animation/keyframed_animation_curve.h" |
10 #include "cc/animation/transform_operations.h" | 10 #include "cc/animation/transform_operations.h" |
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 EXPECT_EQ(0.f, dummy.opacity()); | 1086 EXPECT_EQ(0.f, dummy.opacity()); |
1087 | 1087 |
1088 controller->Animate(3.0); | 1088 controller->Animate(3.0); |
1089 controller->UpdateState(true, events.get()); | 1089 controller->UpdateState(true, events.get()); |
1090 | 1090 |
1091 // The float tranisition should now be done. | 1091 // The float tranisition should now be done. |
1092 EXPECT_EQ(1.f, dummy.opacity()); | 1092 EXPECT_EQ(1.f, dummy.opacity()); |
1093 EXPECT_FALSE(controller->HasActiveAnimation()); | 1093 EXPECT_FALSE(controller->HasActiveAnimation()); |
1094 } | 1094 } |
1095 | 1095 |
| 1096 // Tests that an animation controller with only an inactive observer gets ticked |
| 1097 // but doesn't progress animations past the Starting state. |
| 1098 TEST(LayerAnimationControllerTest, InactiveObserverGetsTicked) { |
| 1099 scoped_ptr<AnimationEventsVector> events( |
| 1100 make_scoped_ptr(new AnimationEventsVector)); |
| 1101 FakeLayerAnimationValueObserver dummy; |
| 1102 FakeInactiveLayerAnimationValueObserver inactive_dummy; |
| 1103 scoped_refptr<LayerAnimationController> controller( |
| 1104 LayerAnimationController::Create(0)); |
| 1105 |
| 1106 const int id = 1; |
| 1107 controller->AddAnimation(CreateAnimation(scoped_ptr<AnimationCurve>( |
| 1108 new FakeFloatTransition(1.0, 0.5f, 1.f)).Pass(), |
| 1109 id, |
| 1110 Animation::Opacity)); |
| 1111 |
| 1112 // Without an observer, the animation shouldn't progress to the Starting |
| 1113 // state. |
| 1114 controller->Animate(0.0); |
| 1115 controller->UpdateState(true, events.get()); |
| 1116 EXPECT_EQ(0u, events->size()); |
| 1117 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
| 1118 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
| 1119 |
| 1120 controller->AddValueObserver(&inactive_dummy); |
| 1121 |
| 1122 // With only an inactive observer, the animation should progress to the |
| 1123 // Starting state and get ticked at its starting point, but should not |
| 1124 // progress to Running. |
| 1125 controller->Animate(1.0); |
| 1126 controller->UpdateState(true, events.get()); |
| 1127 EXPECT_EQ(0u, events->size()); |
| 1128 EXPECT_EQ(Animation::Starting, |
| 1129 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
| 1130 EXPECT_EQ(0.5f, inactive_dummy.opacity()); |
| 1131 |
| 1132 // Even when already in the Starting state, the animation should stay |
| 1133 // there, and shouldn't be ticked past its starting point. |
| 1134 controller->Animate(2.0); |
| 1135 controller->UpdateState(true, events.get()); |
| 1136 EXPECT_EQ(0u, events->size()); |
| 1137 EXPECT_EQ(Animation::Starting, |
| 1138 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
| 1139 EXPECT_EQ(0.5f, inactive_dummy.opacity()); |
| 1140 |
| 1141 controller->AddValueObserver(&dummy); |
| 1142 |
| 1143 // Now that an active observer has been added, the animation should still |
| 1144 // initially tick at its starting point, but should now progress to Running. |
| 1145 controller->Animate(3.0); |
| 1146 controller->UpdateState(true, events.get()); |
| 1147 EXPECT_EQ(1u, events->size()); |
| 1148 EXPECT_EQ(Animation::Running, |
| 1149 controller->GetAnimation(id, Animation::Opacity)->run_state()); |
| 1150 EXPECT_EQ(0.5f, inactive_dummy.opacity()); |
| 1151 EXPECT_EQ(0.5f, dummy.opacity()); |
| 1152 |
| 1153 // The animation should now tick past its starting point. |
| 1154 controller->Animate(3.5); |
| 1155 EXPECT_NE(0.5f, inactive_dummy.opacity()); |
| 1156 EXPECT_NE(0.5f, dummy.opacity()); |
| 1157 } |
| 1158 |
1096 } // namespace | 1159 } // namespace |
1097 } // namespace cc | 1160 } // namespace cc |
OLD | NEW |