| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 EXPECT_EQ(CCAnimationCurve::Float, activeAnimation->curve()->type()); | 80 EXPECT_EQ(CCAnimationCurve::Float, activeAnimation->curve()->type()); |
| 81 | 81 |
| 82 const CCFloatAnimationCurve* curve = activeAnimation->curve()->toFloatAnimat
ionCurve(); | 82 const CCFloatAnimationCurve* curve = activeAnimation->curve()->toFloatAnimat
ionCurve(); |
| 83 EXPECT_TRUE(curve); | 83 EXPECT_TRUE(curve); |
| 84 | 84 |
| 85 EXPECT_EQ(0, curve->getValue(0)); | 85 EXPECT_EQ(0, curve->getValue(0)); |
| 86 EXPECT_EQ(1, curve->getValue(duration)); | 86 EXPECT_EQ(1, curve->getValue(duration)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 TEST(CCLayerAnimationControllerTest, ignoreUnsupportedAnimationDirections) | |
| 90 { | |
| 91 FakeLayerAnimationControllerClient dummy; | |
| 92 OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::cr
eate(&dummy)); | |
| 93 const double duration = 1; | |
| 94 WebCore::KeyframeValueList values(AnimatedPropertyOpacity); | |
| 95 values.insert(new FloatAnimationValue(0, 0)); | |
| 96 values.insert(new FloatAnimationValue(duration, 1)); | |
| 97 | |
| 98 RefPtr<Animation> animation = Animation::create(); | |
| 99 animation->setDuration(duration); | |
| 100 | |
| 101 IntSize boxSize; | |
| 102 | |
| 103 animation->setDirection(Animation::AnimationDirectionAlternate); | |
| 104 EXPECT_FALSE(controller->addAnimation(values, boxSize, animation.get(), 0, 0
, 0)); | |
| 105 | |
| 106 animation->setDirection(Animation::AnimationDirectionAlternateReverse); | |
| 107 EXPECT_FALSE(controller->addAnimation(values, boxSize, animation.get(), 0, 0
, 0)); | |
| 108 | |
| 109 animation->setDirection(Animation::AnimationDirectionReverse); | |
| 110 EXPECT_FALSE(controller->addAnimation(values, boxSize, animation.get(), 0, 0
, 0)); | |
| 111 | |
| 112 animation->setDirection(Animation::AnimationDirectionNormal); | |
| 113 EXPECT_TRUE(controller->addAnimation(values, boxSize, animation.get(), 0, 0,
0)); | |
| 114 } | |
| 115 | |
| 116 TEST(CCLayerAnimationControllerTest, createTransformAnimation) | 89 TEST(CCLayerAnimationControllerTest, createTransformAnimation) |
| 117 { | 90 { |
| 118 FakeLayerAnimationControllerClient dummy; | 91 FakeLayerAnimationControllerClient dummy; |
| 119 OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::cr
eate(&dummy)); | 92 OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::cr
eate(&dummy)); |
| 93 const double duration = 1; |
| 94 WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform); |
| 95 |
| 96 TransformOperations operations1; |
| 97 operations1.operations().append(TranslateTransformOperation::create(Length(2
, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); |
| 98 values.insert(new TransformAnimationValue(0, &operations1)); |
| 99 |
| 100 TransformOperations operations2; |
| 101 operations2.operations().append(TranslateTransformOperation::create(Length(4
, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); |
| 102 values.insert(new TransformAnimationValue(duration, &operations2)); |
| 103 |
| 104 RefPtr<Animation> animation = Animation::create(); |
| 105 animation->setDuration(duration); |
| 106 |
| 107 IntSize boxSize; |
| 108 controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0); |
| 109 |
| 110 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 111 |
| 112 CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCAct
iveAnimation::Transform); |
| 113 EXPECT_TRUE(activeAnimation); |
| 114 |
| 115 EXPECT_EQ(1, activeAnimation->iterations()); |
| 116 EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty()); |
| 117 |
| 118 EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type()); |
| 119 |
| 120 const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransfo
rmAnimationCurve(); |
| 121 EXPECT_TRUE(curve); |
| 122 |
| 123 expectTranslateX(2, curve->getValue(0, boxSize)); |
| 124 expectTranslateX(4, curve->getValue(duration, boxSize)); |
| 125 } |
| 126 |
| 127 TEST(CCLayerAnimationControllerTest, createReversedAnimation) |
| 128 { |
| 129 FakeLayerAnimationControllerClient dummy; |
| 130 OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::cr
eate(&dummy)); |
| 120 const double duration = 1; | 131 const double duration = 1; |
| 121 WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform); | 132 WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform); |
| 122 | 133 |
| 123 TransformOperations operations1; | 134 TransformOperations operations1; |
| 124 operations1.operations().append(TranslateTransformOperation::create(Length(2
, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); | 135 operations1.operations().append(TranslateTransformOperation::create(Length(2
, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); |
| 125 values.insert(new TransformAnimationValue(0, &operations1)); | 136 values.insert(new TransformAnimationValue(0, &operations1)); |
| 126 | 137 |
| 127 TransformOperations operations2; | 138 TransformOperations operations2; |
| 128 operations2.operations().append(TranslateTransformOperation::create(Length(4
, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); | 139 operations2.operations().append(TranslateTransformOperation::create(Length(4
, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); |
| 129 values.insert(new TransformAnimationValue(duration, &operations2)); | 140 values.insert(new TransformAnimationValue(duration, &operations2)); |
| 130 | 141 |
| 131 RefPtr<Animation> animation = Animation::create(); | 142 RefPtr<Animation> animation = Animation::create(); |
| 132 animation->setDuration(duration); | 143 animation->setDuration(duration); |
| 144 animation->setDirection(Animation::AnimationDirectionReverse); |
| 133 | 145 |
| 134 IntSize boxSize; | 146 IntSize boxSize; |
| 135 controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0); | 147 controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0); |
| 136 | 148 |
| 137 EXPECT_TRUE(controller->hasActiveAnimation()); | 149 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 138 | 150 |
| 139 CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCAct
iveAnimation::Transform); | 151 CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCAct
iveAnimation::Transform); |
| 140 EXPECT_TRUE(activeAnimation); | 152 EXPECT_TRUE(activeAnimation); |
| 141 | 153 |
| 142 EXPECT_EQ(1, activeAnimation->iterations()); | 154 EXPECT_EQ(1, activeAnimation->iterations()); |
| 143 EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty()); | 155 EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty()); |
| 144 | 156 |
| 145 EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type()); | 157 EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type()); |
| 146 | 158 |
| 147 const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransfo
rmAnimationCurve(); | 159 const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransfo
rmAnimationCurve(); |
| 148 EXPECT_TRUE(curve); | 160 EXPECT_TRUE(curve); |
| 149 | 161 |
| 162 expectTranslateX(4, curve->getValue(0, boxSize)); |
| 163 expectTranslateX(2, curve->getValue(duration, boxSize)); |
| 164 } |
| 165 |
| 166 TEST(CCLayerAnimationControllerTest, createAlternatingAnimation) |
| 167 { |
| 168 FakeLayerAnimationControllerClient dummy; |
| 169 OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::cr
eate(&dummy)); |
| 170 const double duration = 1; |
| 171 WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform); |
| 172 |
| 173 TransformOperations operations1; |
| 174 operations1.operations().append(TranslateTransformOperation::create(Length(2
, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); |
| 175 values.insert(new TransformAnimationValue(0, &operations1)); |
| 176 |
| 177 TransformOperations operations2; |
| 178 operations2.operations().append(TranslateTransformOperation::create(Length(4
, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); |
| 179 values.insert(new TransformAnimationValue(duration, &operations2)); |
| 180 |
| 181 RefPtr<Animation> animation = Animation::create(); |
| 182 animation->setDuration(duration); |
| 183 animation->setDirection(Animation::AnimationDirectionAlternate); |
| 184 animation->setIterationCount(2); |
| 185 |
| 186 IntSize boxSize; |
| 187 controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0); |
| 188 |
| 189 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 190 |
| 191 CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCAct
iveAnimation::Transform); |
| 192 EXPECT_TRUE(activeAnimation); |
| 193 EXPECT_TRUE(activeAnimation->alternatesDirection()); |
| 194 |
| 195 EXPECT_EQ(2, activeAnimation->iterations()); |
| 196 EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty()); |
| 197 |
| 198 EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type()); |
| 199 |
| 200 const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransfo
rmAnimationCurve(); |
| 201 EXPECT_TRUE(curve); |
| 202 |
| 150 expectTranslateX(2, curve->getValue(0, boxSize)); | 203 expectTranslateX(2, curve->getValue(0, boxSize)); |
| 151 expectTranslateX(4, curve->getValue(duration, boxSize)); | 204 expectTranslateX(4, curve->getValue(duration, boxSize)); |
| 152 } | 205 } |
| 153 | 206 |
| 207 TEST(CCLayerAnimationControllerTest, createReversedAlternatingAnimation) |
| 208 { |
| 209 FakeLayerAnimationControllerClient dummy; |
| 210 OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::cr
eate(&dummy)); |
| 211 const double duration = 1; |
| 212 WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform); |
| 213 |
| 214 TransformOperations operations1; |
| 215 operations1.operations().append(TranslateTransformOperation::create(Length(2
, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); |
| 216 values.insert(new TransformAnimationValue(0, &operations1)); |
| 217 |
| 218 TransformOperations operations2; |
| 219 operations2.operations().append(TranslateTransformOperation::create(Length(4
, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X)); |
| 220 values.insert(new TransformAnimationValue(duration, &operations2)); |
| 221 |
| 222 RefPtr<Animation> animation = Animation::create(); |
| 223 animation->setDuration(duration); |
| 224 animation->setDirection(Animation::AnimationDirectionAlternateReverse); |
| 225 animation->setIterationCount(2); |
| 226 |
| 227 IntSize boxSize; |
| 228 controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0); |
| 229 |
| 230 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 231 |
| 232 CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCAct
iveAnimation::Transform); |
| 233 EXPECT_TRUE(activeAnimation); |
| 234 EXPECT_TRUE(activeAnimation->alternatesDirection()); |
| 235 |
| 236 EXPECT_EQ(2, activeAnimation->iterations()); |
| 237 EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty()); |
| 238 |
| 239 EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type()); |
| 240 |
| 241 const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransfo
rmAnimationCurve(); |
| 242 EXPECT_TRUE(curve); |
| 243 |
| 244 expectTranslateX(4, curve->getValue(0, boxSize)); |
| 245 expectTranslateX(2, curve->getValue(duration, boxSize)); |
| 246 } |
| 247 |
| 154 TEST(CCLayerAnimationControllerTest, syncNewAnimation) | 248 TEST(CCLayerAnimationControllerTest, syncNewAnimation) |
| 155 { | 249 { |
| 156 FakeLayerAnimationControllerClient dummyImpl; | 250 FakeLayerAnimationControllerClient dummyImpl; |
| 157 OwnPtr<CCLayerAnimationController> controllerImpl(CCLayerAnimationController
::create(&dummyImpl)); | 251 OwnPtr<CCLayerAnimationController> controllerImpl(CCLayerAnimationController
::create(&dummyImpl)); |
| 158 FakeLayerAnimationControllerClient dummy; | 252 FakeLayerAnimationControllerClient dummy; |
| 159 OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::cr
eate(&dummy)); | 253 OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::cr
eate(&dummy)); |
| 160 | 254 |
| 161 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacit
y)); | 255 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacit
y)); |
| 162 | 256 |
| 163 addOpacityTransitionToController(*controller, 1, 0, 1, false); | 257 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 controller->getActiveAnimation(id, CCActiveAnimation::Opacity)->setRunState(
CCActiveAnimation::Aborted, 1); | 741 controller->getActiveAnimation(id, CCActiveAnimation::Opacity)->setRunState(
CCActiveAnimation::Aborted, 1); |
| 648 controller->animate(1, events.get()); | 742 controller->animate(1, events.get()); |
| 649 EXPECT_TRUE(controller->hasActiveAnimation()); | 743 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 650 EXPECT_EQ(1, dummy.opacity()); | 744 EXPECT_EQ(1, dummy.opacity()); |
| 651 controller->animate(2, events.get()); | 745 controller->animate(2, events.get()); |
| 652 EXPECT_TRUE(!controller->hasActiveAnimation()); | 746 EXPECT_TRUE(!controller->hasActiveAnimation()); |
| 653 EXPECT_EQ(0.75, dummy.opacity()); | 747 EXPECT_EQ(0.75, dummy.opacity()); |
| 654 } | 748 } |
| 655 | 749 |
| 656 } // namespace | 750 } // namespace |
| OLD | NEW |