Chromium Code Reviews| 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/layer_animation_controller.h" | 5 #include "cc/layer_animation_controller.h" |
| 6 | 6 |
| 7 #include "cc/animation.h" | 7 #include "cc/animation.h" |
| 8 #include "cc/animation_curve.h" | 8 #include "cc/animation_curve.h" |
| 9 #include "cc/keyframed_animation_curve.h" | |
| 9 #include "cc/test/animation_test_common.h" | 10 #include "cc/test/animation_test_common.h" |
| 11 #include "cc/transform_operations.h" | |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gfx/transform.h" | 14 #include "ui/gfx/transform.h" |
| 13 | 15 |
| 14 namespace cc { | 16 namespace cc { |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 void expectTranslateX(double translateX, const gfx::Transform& matrix) | 19 void expectTranslateX(double translateX, const gfx::Transform& matrix) |
| 18 { | 20 { |
| 19 EXPECT_FLOAT_EQ(translateX, matrix.matrix().getDouble(0, 3)); | 21 EXPECT_FLOAT_EQ(translateX, matrix.matrix().getDouble(0, 3)); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 151 |
| 150 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); | 152 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); |
| 151 | 153 |
| 152 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 154 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 153 | 155 |
| 154 // Even though the main thread has a 'new' animation, it should not be pushe d because the animation has already completed on the impl thread. | 156 // Even though the main thread has a 'new' animation, it should not be pushe d because the animation has already completed on the impl thread. |
| 155 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); | 157 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); |
| 156 } | 158 } |
| 157 | 159 |
| 158 // Tests that transitioning opacity from 0 to 1 works as expected. | 160 // Tests that transitioning opacity from 0 to 1 works as expected. |
| 161 | |
| 162 static const AnimationEvent* getMostRecentPropertyUpdateEvent(const AnimationEve ntsVector* events) | |
| 163 { | |
| 164 const AnimationEvent* event = 0; | |
| 165 for (size_t i = 0; i < events->size(); ++i) | |
| 166 if ((*events)[i].type == AnimationEvent::PropertyUpdate) | |
| 167 event = &(*events)[i]; | |
| 168 | |
| 169 return event; | |
| 170 } | |
| 171 | |
| 159 TEST(LayerAnimationControllerTest, TrivialTransition) | 172 TEST(LayerAnimationControllerTest, TrivialTransition) |
| 160 { | 173 { |
| 161 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 174 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); |
| 162 FakeLayerAnimationValueObserver dummy; | 175 FakeLayerAnimationValueObserver dummy; |
| 163 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 176 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); |
| 164 controller->addObserver(&dummy); | 177 controller->addObserver(&dummy); |
| 165 | 178 |
| 166 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 179 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
| 167 | 180 |
| 168 controller->addAnimation(toAdd.Pass()); | 181 controller->addAnimation(toAdd.Pass()); |
| 169 controller->animate(0); | 182 controller->animate(0); |
| 170 controller->updateState(events.get()); | 183 controller->updateState(events.get()); |
| 171 EXPECT_TRUE(controller->hasActiveAnimation()); | 184 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 172 EXPECT_EQ(0, dummy.opacity()); | 185 EXPECT_EQ(0, dummy.opacity()); |
| 173 controller->animate(1); | 186 controller->animate(1); |
| 174 controller->updateState(events.get()); | 187 controller->updateState(events.get()); |
| 175 EXPECT_EQ(1, dummy.opacity()); | 188 EXPECT_EQ(1, dummy.opacity()); |
| 176 EXPECT_FALSE(controller->hasActiveAnimation()); | 189 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 177 } | 190 } |
| 178 | 191 |
|
Ian Vollick
2013/03/06 23:29:45
I'd also like you to confirm that we don't generat
wjmaclean
2013/03/07 13:49:29
We already do that implicitly, in that the checks
| |
| 192 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) | |
| 193 { | |
| 194 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | |
| 195 FakeLayerAnimationValueObserver dummyImpl; | |
| 196 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl ler::create(0)); | |
| 197 controllerImpl->addObserver(&dummyImpl); | |
| 198 | |
| 199 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | |
| 200 toAdd->setIsImplOnly(true); | |
| 201 | |
| 202 controllerImpl->addAnimation(toAdd.Pass()); | |
| 203 controllerImpl->animate(0); | |
| 204 controllerImpl->updateState(events.get()); | |
| 205 EXPECT_TRUE(controllerImpl->hasActiveAnimation()); | |
| 206 EXPECT_EQ(0, dummyImpl.opacity()); | |
| 207 EXPECT_EQ(2, events->size()); | |
| 208 const AnimationEvent* startOpacityEvent = getMostRecentPropertyUpdateEvent(e vents.get()); | |
| 209 EXPECT_EQ(0, startOpacityEvent->value); | |
| 210 | |
| 211 controllerImpl->animate(1); | |
| 212 controllerImpl->updateState(events.get()); | |
| 213 EXPECT_EQ(1, dummyImpl.opacity()); | |
| 214 EXPECT_FALSE(controllerImpl->hasActiveAnimation()); | |
| 215 EXPECT_EQ(4, events->size()); | |
| 216 const AnimationEvent* endOpacityEvent = getMostRecentPropertyUpdateEvent(eve nts.get()); | |
| 217 EXPECT_EQ(1, endOpacityEvent->value); | |
| 218 } | |
| 219 | |
| 220 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) | |
| 221 { | |
| 222 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | |
| 223 FakeLayerAnimationValueObserver dummyImpl; | |
| 224 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl ler::create(0)); | |
| 225 controllerImpl->addObserver(&dummyImpl); | |
| 226 | |
| 227 // Choose different values for x and y to avoid coincidental values in the | |
| 228 // observed transforms. | |
| 229 const float deltaX = 3; | |
| 230 const float deltaY = 4; | |
| 231 | |
| 232 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create()); | |
| 233 | |
| 234 // Create simple Transform animation. | |
| 235 TransformOperations operations; | |
| 236 curve->addKeyframe(TransformKeyframe::create(0, operations, scoped_ptr<cc::T imingFunction>())); | |
| 237 operations.AppendTranslate(deltaX, deltaY, 0); | |
| 238 curve->addKeyframe(TransformKeyframe::create(1, operations, scoped_ptr<cc::T imingFunction>())); | |
| 239 | |
| 240 scoped_ptr<Animation> animation(Animation::create(curve.PassAs<AnimationCurv e>(), 1, 0, Animation::Transform)); | |
| 241 animation->setIsImplOnly(true); | |
| 242 controllerImpl->addAnimation(animation.Pass()); | |
| 243 | |
| 244 // Run animation. | |
| 245 controllerImpl->animate(0); | |
| 246 controllerImpl->updateState(events.get()); | |
| 247 EXPECT_TRUE(controllerImpl->hasActiveAnimation()); | |
| 248 EXPECT_EQ(gfx::Transform(), dummyImpl.transform()); | |
| 249 EXPECT_EQ(2, events->size()); | |
| 250 const AnimationEvent* startTransformEvent = getMostRecentPropertyUpdateEvent (events.get()); | |
| 251 ASSERT_TRUE(startTransformEvent); | |
| 252 EXPECT_EQ(gfx::Transform(), startTransformEvent->transform); | |
| 253 | |
| 254 gfx::Transform expectedTransform; | |
| 255 expectedTransform.Translate(deltaX, deltaY); | |
| 256 | |
| 257 controllerImpl->animate(1); | |
| 258 controllerImpl->updateState(events.get()); | |
| 259 EXPECT_EQ(expectedTransform, dummyImpl.transform()); | |
| 260 EXPECT_FALSE(controllerImpl->hasActiveAnimation()); | |
| 261 EXPECT_EQ(4, events->size()); | |
| 262 const AnimationEvent* endTransformEvent = getMostRecentPropertyUpdateEvent(e vents.get()); | |
| 263 EXPECT_EQ(expectedTransform, endTransformEvent->transform); | |
| 264 } | |
| 265 | |
| 179 // Tests animations that are waiting for a synchronized start time do not finish . | 266 // Tests animations that are waiting for a synchronized start time do not finish . |
| 180 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe yWaitLongerToStartThanTheirDuration) | 267 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe yWaitLongerToStartThanTheirDuration) |
| 181 { | 268 { |
| 182 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 269 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); |
| 183 FakeLayerAnimationValueObserver dummy; | 270 FakeLayerAnimationValueObserver dummy; |
| 184 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 271 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); |
| 185 controller->addObserver(&dummy); | 272 controller->addObserver(&dummy); |
| 186 | 273 |
| 187 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 274 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
| 188 toAdd->setNeedsSynchronizedStartTime(true); | 275 toAdd->setNeedsSynchronizedStartTime(true); |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 controller->animate(3); | 738 controller->animate(3); |
| 652 controller->updateState(events.get()); | 739 controller->updateState(events.get()); |
| 653 | 740 |
| 654 // The float tranisition should now be done. | 741 // The float tranisition should now be done. |
| 655 EXPECT_EQ(1, dummy.opacity()); | 742 EXPECT_EQ(1, dummy.opacity()); |
| 656 EXPECT_FALSE(controller->hasActiveAnimation()); | 743 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 657 } | 744 } |
| 658 | 745 |
| 659 } // namespace | 746 } // namespace |
| 660 } // namespace cc | 747 } // namespace cc |
| OLD | NEW |