| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/animation/KeyframeEffectModel.h" | 31 #include "core/animation/KeyframeEffectModel.h" |
| 32 | 32 |
| 33 #include "core/animation/LegacyStyleInterpolation.h" | 33 #include "core/animation/LegacyStyleInterpolation.h" |
| 34 #include "core/animation/animatable/AnimatableLength.h" | 34 #include "core/animation/animatable/AnimatableDouble.h" |
| 35 #include "core/animation/animatable/AnimatableUnknown.h" | 35 #include "core/animation/animatable/AnimatableUnknown.h" |
| 36 #include "core/css/CSSPrimitiveValue.h" | 36 #include "core/css/CSSPrimitiveValue.h" |
| 37 #include "core/dom/Element.h" | 37 #include "core/dom/Element.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 const double duration = 1.0; | 42 const double duration = 1.0; |
| 43 | 43 |
| 44 PassRefPtr<AnimatableValue> unknownAnimatableValue(double n) { | 44 PassRefPtr<AnimatableValue> unknownAnimatableValue(double n) { |
| 45 return AnimatableUnknown::create( | 45 return AnimatableUnknown::create( |
| 46 CSSPrimitiveValue::create(n, CSSPrimitiveValue::UnitType::Unknown)); | 46 CSSPrimitiveValue::create(n, CSSPrimitiveValue::UnitType::Unknown)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 PassRefPtr<AnimatableValue> pixelAnimatableValue(double n) { | |
| 50 return AnimatableLength::create(Length(n, Fixed), 1); | |
| 51 } | |
| 52 | |
| 53 AnimatableValueKeyframeVector keyframesAtZeroAndOne( | 49 AnimatableValueKeyframeVector keyframesAtZeroAndOne( |
| 54 PassRefPtr<AnimatableValue> zeroValue, | 50 PassRefPtr<AnimatableValue> zeroValue, |
| 55 PassRefPtr<AnimatableValue> oneValue) { | 51 PassRefPtr<AnimatableValue> oneValue) { |
| 56 AnimatableValueKeyframeVector keyframes(2); | 52 AnimatableValueKeyframeVector keyframes(2); |
| 57 keyframes[0] = AnimatableValueKeyframe::create(); | 53 keyframes[0] = AnimatableValueKeyframe::create(); |
| 58 keyframes[0]->setOffset(0.0); | 54 keyframes[0]->setOffset(0.0); |
| 59 keyframes[0]->setPropertyValue(CSSPropertyLeft, zeroValue.get()); | 55 keyframes[0]->setPropertyValue(CSSPropertyLeft, zeroValue.get()); |
| 60 keyframes[1] = AnimatableValueKeyframe::create(); | 56 keyframes[1] = AnimatableValueKeyframe::create(); |
| 61 keyframes[1]->setOffset(1.0); | 57 keyframes[1]->setOffset(1.0); |
| 62 keyframes[1]->setPropertyValue(CSSPropertyLeft, oneValue.get()); | 58 keyframes[1]->setPropertyValue(CSSPropertyLeft, oneValue.get()); |
| 63 return keyframes; | 59 return keyframes; |
| 64 } | 60 } |
| 65 | 61 |
| 66 void expectProperty(CSSPropertyID property, | 62 void expectProperty(CSSPropertyID property, |
| 67 PassRefPtr<Interpolation> interpolationValue) { | 63 PassRefPtr<Interpolation> interpolationValue) { |
| 68 LegacyStyleInterpolation* interpolation = | 64 LegacyStyleInterpolation* interpolation = |
| 69 toLegacyStyleInterpolation(interpolationValue.get()); | 65 toLegacyStyleInterpolation(interpolationValue.get()); |
| 70 ASSERT_EQ(property, interpolation->id()); | 66 ASSERT_EQ(property, interpolation->id()); |
| 71 } | 67 } |
| 72 | 68 |
| 73 void expectDoubleValue(double expectedValue, | 69 void expectDoubleValue(double expectedValue, |
| 74 PassRefPtr<Interpolation> interpolationValue) { | 70 PassRefPtr<Interpolation> interpolationValue) { |
| 75 LegacyStyleInterpolation* interpolation = | 71 LegacyStyleInterpolation* interpolation = |
| 76 toLegacyStyleInterpolation(interpolationValue.get()); | 72 toLegacyStyleInterpolation(interpolationValue.get()); |
| 77 RefPtr<AnimatableValue> value = interpolation->currentValue(); | 73 RefPtr<AnimatableValue> value = interpolation->currentValue(); |
| 78 | 74 |
| 79 ASSERT_TRUE(value->isLength() || value->isUnknown()); | 75 ASSERT_TRUE(value->isDouble() || value->isUnknown()); |
| 80 | 76 |
| 81 double actualValue; | 77 double actualValue; |
| 82 if (value->isLength()) | 78 if (value->isDouble()) |
| 83 actualValue = | 79 actualValue = toAnimatableDouble(value.get())->toDouble(); |
| 84 toAnimatableLength(value.get())->getLength(1, ValueRangeAll).value(); | |
| 85 else | 80 else |
| 86 actualValue = | 81 actualValue = |
| 87 toCSSPrimitiveValue(toAnimatableUnknown(value.get())->toCSSValue()) | 82 toCSSPrimitiveValue(toAnimatableUnknown(value.get())->toCSSValue()) |
| 88 ->getDoubleValue(); | 83 ->getDoubleValue(); |
| 89 | 84 |
| 90 EXPECT_FLOAT_EQ(static_cast<float>(expectedValue), actualValue); | 85 EXPECT_FLOAT_EQ(static_cast<float>(expectedValue), actualValue); |
| 91 } | 86 } |
| 92 | 87 |
| 93 Interpolation* findValue(Vector<RefPtr<Interpolation>>& values, | 88 Interpolation* findValue(Vector<RefPtr<Interpolation>>& values, |
| 94 CSSPropertyID id) { | 89 CSSPropertyID id) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 118 keyframes[1]->setComposite(EffectModel::CompositeReplace); | 113 keyframes[1]->setComposite(EffectModel::CompositeReplace); |
| 119 AnimatableValueKeyframeEffectModel* effect = | 114 AnimatableValueKeyframeEffectModel* effect = |
| 120 AnimatableValueKeyframeEffectModel::create(keyframes); | 115 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 121 Vector<RefPtr<Interpolation>> values; | 116 Vector<RefPtr<Interpolation>> values; |
| 122 effect->sample(0, 0.6, duration, values); | 117 effect->sample(0, 0.6, duration, values); |
| 123 expectDoubleValue(5.0, values.at(0)); | 118 expectDoubleValue(5.0, values.at(0)); |
| 124 } | 119 } |
| 125 | 120 |
| 126 TEST(AnimationKeyframeEffectModel, CompositeReplace) { | 121 TEST(AnimationKeyframeEffectModel, CompositeReplace) { |
| 127 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( | 122 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( |
| 128 pixelAnimatableValue(3.0), pixelAnimatableValue(5.0)); | 123 AnimatableDouble::create(3.0), AnimatableDouble::create(5.0)); |
| 129 keyframes[0]->setComposite(EffectModel::CompositeReplace); | 124 keyframes[0]->setComposite(EffectModel::CompositeReplace); |
| 130 keyframes[1]->setComposite(EffectModel::CompositeReplace); | 125 keyframes[1]->setComposite(EffectModel::CompositeReplace); |
| 131 AnimatableValueKeyframeEffectModel* effect = | 126 AnimatableValueKeyframeEffectModel* effect = |
| 132 AnimatableValueKeyframeEffectModel::create(keyframes); | 127 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 133 Vector<RefPtr<Interpolation>> values; | 128 Vector<RefPtr<Interpolation>> values; |
| 134 effect->sample(0, 0.6, duration, values); | 129 effect->sample(0, 0.6, duration, values); |
| 135 expectDoubleValue(3.0 * 0.4 + 5.0 * 0.6, values.at(0)); | 130 expectDoubleValue(3.0 * 0.4 + 5.0 * 0.6, values.at(0)); |
| 136 } | 131 } |
| 137 | 132 |
| 138 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. | 133 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. |
| 139 TEST(AnimationKeyframeEffectModel, DISABLED_CompositeAdd) { | 134 TEST(AnimationKeyframeEffectModel, DISABLED_CompositeAdd) { |
| 140 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( | 135 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( |
| 141 pixelAnimatableValue(3.0), pixelAnimatableValue(5.0)); | 136 AnimatableDouble::create(3.0), AnimatableDouble::create(5.0)); |
| 142 keyframes[0]->setComposite(EffectModel::CompositeAdd); | 137 keyframes[0]->setComposite(EffectModel::CompositeAdd); |
| 143 keyframes[1]->setComposite(EffectModel::CompositeAdd); | 138 keyframes[1]->setComposite(EffectModel::CompositeAdd); |
| 144 AnimatableValueKeyframeEffectModel* effect = | 139 AnimatableValueKeyframeEffectModel* effect = |
| 145 AnimatableValueKeyframeEffectModel::create(keyframes); | 140 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 146 Vector<RefPtr<Interpolation>> values; | 141 Vector<RefPtr<Interpolation>> values; |
| 147 effect->sample(0, 0.6, duration, values); | 142 effect->sample(0, 0.6, duration, values); |
| 148 expectDoubleValue((7.0 + 3.0) * 0.4 + (7.0 + 5.0) * 0.6, values.at(0)); | 143 expectDoubleValue((7.0 + 3.0) * 0.4 + (7.0 + 5.0) * 0.6, values.at(0)); |
| 149 } | 144 } |
| 150 | 145 |
| 151 TEST(AnimationKeyframeEffectModel, CompositeEaseIn) { | 146 TEST(AnimationKeyframeEffectModel, CompositeEaseIn) { |
| 152 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( | 147 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( |
| 153 pixelAnimatableValue(3.0), pixelAnimatableValue(5.0)); | 148 AnimatableDouble::create(3.0), AnimatableDouble::create(5.0)); |
| 154 keyframes[0]->setComposite(EffectModel::CompositeReplace); | 149 keyframes[0]->setComposite(EffectModel::CompositeReplace); |
| 155 keyframes[0]->setEasing(CubicBezierTimingFunction::preset( | 150 keyframes[0]->setEasing(CubicBezierTimingFunction::preset( |
| 156 CubicBezierTimingFunction::EaseType::EASE_IN)); | 151 CubicBezierTimingFunction::EaseType::EASE_IN)); |
| 157 keyframes[1]->setComposite(EffectModel::CompositeReplace); | 152 keyframes[1]->setComposite(EffectModel::CompositeReplace); |
| 158 AnimatableValueKeyframeEffectModel* effect = | 153 AnimatableValueKeyframeEffectModel* effect = |
| 159 AnimatableValueKeyframeEffectModel::create(keyframes); | 154 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 160 Vector<RefPtr<Interpolation>> values; | 155 Vector<RefPtr<Interpolation>> values; |
| 161 effect->sample(0, 0.6, duration, values); | 156 effect->sample(0, 0.6, duration, values); |
| 162 expectDoubleValue(3.8579516, values.at(0)); | 157 expectDoubleValue(3.8579516, values.at(0)); |
| 163 effect->sample(0, 0.6, duration * 100, values); | 158 effect->sample(0, 0.6, duration * 100, values); |
| 164 expectDoubleValue(3.8582394, values.at(0)); | 159 expectDoubleValue(3.8582394, values.at(0)); |
| 165 } | 160 } |
| 166 | 161 |
| 167 TEST(AnimationKeyframeEffectModel, CompositeCubicBezier) { | 162 TEST(AnimationKeyframeEffectModel, CompositeCubicBezier) { |
| 168 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( | 163 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( |
| 169 pixelAnimatableValue(3.0), pixelAnimatableValue(5.0)); | 164 AnimatableDouble::create(3.0), AnimatableDouble::create(5.0)); |
| 170 keyframes[0]->setComposite(EffectModel::CompositeReplace); | 165 keyframes[0]->setComposite(EffectModel::CompositeReplace); |
| 171 keyframes[0]->setEasing(CubicBezierTimingFunction::create(0.42, 0, 0.58, 1)); | 166 keyframes[0]->setEasing(CubicBezierTimingFunction::create(0.42, 0, 0.58, 1)); |
| 172 keyframes[1]->setComposite(EffectModel::CompositeReplace); | 167 keyframes[1]->setComposite(EffectModel::CompositeReplace); |
| 173 AnimatableValueKeyframeEffectModel* effect = | 168 AnimatableValueKeyframeEffectModel* effect = |
| 174 AnimatableValueKeyframeEffectModel::create(keyframes); | 169 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 175 Vector<RefPtr<Interpolation>> values; | 170 Vector<RefPtr<Interpolation>> values; |
| 176 effect->sample(0, 0.6, duration, values); | 171 effect->sample(0, 0.6, duration, values); |
| 177 expectDoubleValue(4.3363357, values.at(0)); | 172 expectDoubleValue(4.3363357, values.at(0)); |
| 178 effect->sample(0, 0.6, duration * 1000, values); | 173 effect->sample(0, 0.6, duration * 1000, values); |
| 179 expectDoubleValue(4.3362322, values.at(0)); | 174 expectDoubleValue(4.3362322, values.at(0)); |
| 180 } | 175 } |
| 181 | 176 |
| 182 TEST(AnimationKeyframeEffectModel, ExtrapolateReplaceNonInterpolable) { | 177 TEST(AnimationKeyframeEffectModel, ExtrapolateReplaceNonInterpolable) { |
| 183 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( | 178 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( |
| 184 unknownAnimatableValue(3.0), unknownAnimatableValue(5.0)); | 179 unknownAnimatableValue(3.0), unknownAnimatableValue(5.0)); |
| 185 keyframes[0]->setComposite(EffectModel::CompositeReplace); | 180 keyframes[0]->setComposite(EffectModel::CompositeReplace); |
| 186 keyframes[1]->setComposite(EffectModel::CompositeReplace); | 181 keyframes[1]->setComposite(EffectModel::CompositeReplace); |
| 187 AnimatableValueKeyframeEffectModel* effect = | 182 AnimatableValueKeyframeEffectModel* effect = |
| 188 AnimatableValueKeyframeEffectModel::create(keyframes); | 183 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 189 Vector<RefPtr<Interpolation>> values; | 184 Vector<RefPtr<Interpolation>> values; |
| 190 effect->sample(0, 1.6, duration, values); | 185 effect->sample(0, 1.6, duration, values); |
| 191 expectDoubleValue(5.0, values.at(0)); | 186 expectDoubleValue(5.0, values.at(0)); |
| 192 } | 187 } |
| 193 | 188 |
| 194 TEST(AnimationKeyframeEffectModel, ExtrapolateReplace) { | 189 TEST(AnimationKeyframeEffectModel, ExtrapolateReplace) { |
| 195 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( | 190 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( |
| 196 pixelAnimatableValue(3.0), pixelAnimatableValue(5.0)); | 191 AnimatableDouble::create(3.0), AnimatableDouble::create(5.0)); |
| 197 AnimatableValueKeyframeEffectModel* effect = | 192 AnimatableValueKeyframeEffectModel* effect = |
| 198 AnimatableValueKeyframeEffectModel::create(keyframes); | 193 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 199 keyframes[0]->setComposite(EffectModel::CompositeReplace); | 194 keyframes[0]->setComposite(EffectModel::CompositeReplace); |
| 200 keyframes[1]->setComposite(EffectModel::CompositeReplace); | 195 keyframes[1]->setComposite(EffectModel::CompositeReplace); |
| 201 Vector<RefPtr<Interpolation>> values; | 196 Vector<RefPtr<Interpolation>> values; |
| 202 effect->sample(0, 1.6, duration, values); | 197 effect->sample(0, 1.6, duration, values); |
| 203 expectDoubleValue(3.0 * -0.6 + 5.0 * 1.6, values.at(0)); | 198 expectDoubleValue(3.0 * -0.6 + 5.0 * 1.6, values.at(0)); |
| 204 } | 199 } |
| 205 | 200 |
| 206 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. | 201 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. |
| 207 TEST(AnimationKeyframeEffectModel, DISABLED_ExtrapolateAdd) { | 202 TEST(AnimationKeyframeEffectModel, DISABLED_ExtrapolateAdd) { |
| 208 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( | 203 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( |
| 209 pixelAnimatableValue(3.0), pixelAnimatableValue(5.0)); | 204 AnimatableDouble::create(3.0), AnimatableDouble::create(5.0)); |
| 210 keyframes[0]->setComposite(EffectModel::CompositeAdd); | 205 keyframes[0]->setComposite(EffectModel::CompositeAdd); |
| 211 keyframes[1]->setComposite(EffectModel::CompositeAdd); | 206 keyframes[1]->setComposite(EffectModel::CompositeAdd); |
| 212 AnimatableValueKeyframeEffectModel* effect = | 207 AnimatableValueKeyframeEffectModel* effect = |
| 213 AnimatableValueKeyframeEffectModel::create(keyframes); | 208 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 214 Vector<RefPtr<Interpolation>> values; | 209 Vector<RefPtr<Interpolation>> values; |
| 215 effect->sample(0, 1.6, duration, values); | 210 effect->sample(0, 1.6, duration, values); |
| 216 expectDoubleValue((7.0 + 3.0) * -0.6 + (7.0 + 5.0) * 1.6, values.at(0)); | 211 expectDoubleValue((7.0 + 3.0) * -0.6 + (7.0 + 5.0) * 1.6, values.at(0)); |
| 217 } | 212 } |
| 218 | 213 |
| 219 TEST(AnimationKeyframeEffectModel, ZeroKeyframes) { | 214 TEST(AnimationKeyframeEffectModel, ZeroKeyframes) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 239 effect->sample(0, 0.6, duration, values); | 234 effect->sample(0, 0.6, duration, values); |
| 240 expectDoubleValue(3.0, values.at(0)); | 235 expectDoubleValue(3.0, values.at(0)); |
| 241 } | 236 } |
| 242 | 237 |
| 243 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. | 238 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. |
| 244 TEST(AnimationKeyframeEffectModel, DISABLED_SingleKeyframeAtOffsetOne) { | 239 TEST(AnimationKeyframeEffectModel, DISABLED_SingleKeyframeAtOffsetOne) { |
| 245 AnimatableValueKeyframeVector keyframes(1); | 240 AnimatableValueKeyframeVector keyframes(1); |
| 246 keyframes[0] = AnimatableValueKeyframe::create(); | 241 keyframes[0] = AnimatableValueKeyframe::create(); |
| 247 keyframes[0]->setOffset(1.0); | 242 keyframes[0]->setOffset(1.0); |
| 248 keyframes[0]->setPropertyValue(CSSPropertyLeft, | 243 keyframes[0]->setPropertyValue(CSSPropertyLeft, |
| 249 pixelAnimatableValue(5.0).get()); | 244 AnimatableDouble::create(5.0).get()); |
| 250 | 245 |
| 251 AnimatableValueKeyframeEffectModel* effect = | 246 AnimatableValueKeyframeEffectModel* effect = |
| 252 AnimatableValueKeyframeEffectModel::create(keyframes); | 247 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 253 Vector<RefPtr<Interpolation>> values; | 248 Vector<RefPtr<Interpolation>> values; |
| 254 effect->sample(0, 0.6, duration, values); | 249 effect->sample(0, 0.6, duration, values); |
| 255 expectDoubleValue(7.0 * 0.4 + 5.0 * 0.6, values.at(0)); | 250 expectDoubleValue(7.0 * 0.4 + 5.0 * 0.6, values.at(0)); |
| 256 } | 251 } |
| 257 | 252 |
| 258 TEST(AnimationKeyframeEffectModel, MoreThanTwoKeyframes) { | 253 TEST(AnimationKeyframeEffectModel, MoreThanTwoKeyframes) { |
| 259 AnimatableValueKeyframeVector keyframes(3); | 254 AnimatableValueKeyframeVector keyframes(3); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 effect->sample(0, 1.0, duration, values); | 381 effect->sample(0, 1.0, duration, values); |
| 387 expectDoubleValue(7.0, values.at(0)); | 382 expectDoubleValue(7.0, values.at(0)); |
| 388 } | 383 } |
| 389 | 384 |
| 390 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. | 385 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. |
| 391 TEST(AnimationKeyframeEffectModel, DISABLED_PerKeyframeComposite) { | 386 TEST(AnimationKeyframeEffectModel, DISABLED_PerKeyframeComposite) { |
| 392 AnimatableValueKeyframeVector keyframes(2); | 387 AnimatableValueKeyframeVector keyframes(2); |
| 393 keyframes[0] = AnimatableValueKeyframe::create(); | 388 keyframes[0] = AnimatableValueKeyframe::create(); |
| 394 keyframes[0]->setOffset(0.0); | 389 keyframes[0]->setOffset(0.0); |
| 395 keyframes[0]->setPropertyValue(CSSPropertyLeft, | 390 keyframes[0]->setPropertyValue(CSSPropertyLeft, |
| 396 pixelAnimatableValue(3.0).get()); | 391 AnimatableDouble::create(3.0).get()); |
| 397 keyframes[1] = AnimatableValueKeyframe::create(); | 392 keyframes[1] = AnimatableValueKeyframe::create(); |
| 398 keyframes[1]->setOffset(1.0); | 393 keyframes[1]->setOffset(1.0); |
| 399 keyframes[1]->setPropertyValue(CSSPropertyLeft, | 394 keyframes[1]->setPropertyValue(CSSPropertyLeft, |
| 400 pixelAnimatableValue(5.0).get()); | 395 AnimatableDouble::create(5.0).get()); |
| 401 keyframes[1]->setComposite(EffectModel::CompositeAdd); | 396 keyframes[1]->setComposite(EffectModel::CompositeAdd); |
| 402 | 397 |
| 403 AnimatableValueKeyframeEffectModel* effect = | 398 AnimatableValueKeyframeEffectModel* effect = |
| 404 AnimatableValueKeyframeEffectModel::create(keyframes); | 399 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 405 Vector<RefPtr<Interpolation>> values; | 400 Vector<RefPtr<Interpolation>> values; |
| 406 effect->sample(0, 0.6, duration, values); | 401 effect->sample(0, 0.6, duration, values); |
| 407 expectDoubleValue(3.0 * 0.4 + (7.0 + 5.0) * 0.6, values.at(0)); | 402 expectDoubleValue(3.0 * 0.4 + (7.0 + 5.0) * 0.6, values.at(0)); |
| 408 } | 403 } |
| 409 | 404 |
| 410 TEST(AnimationKeyframeEffectModel, MultipleProperties) { | 405 TEST(AnimationKeyframeEffectModel, MultipleProperties) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 431 ASSERT_TRUE(leftValue); | 426 ASSERT_TRUE(leftValue); |
| 432 expectDoubleValue(5.0, leftValue); | 427 expectDoubleValue(5.0, leftValue); |
| 433 Interpolation* rightValue = findValue(values, CSSPropertyRight); | 428 Interpolation* rightValue = findValue(values, CSSPropertyRight); |
| 434 ASSERT_TRUE(rightValue); | 429 ASSERT_TRUE(rightValue); |
| 435 expectDoubleValue(6.0, rightValue); | 430 expectDoubleValue(6.0, rightValue); |
| 436 } | 431 } |
| 437 | 432 |
| 438 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. | 433 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. |
| 439 TEST(AnimationKeyframeEffectModel, DISABLED_RecompositeCompositableValue) { | 434 TEST(AnimationKeyframeEffectModel, DISABLED_RecompositeCompositableValue) { |
| 440 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( | 435 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( |
| 441 pixelAnimatableValue(3.0), pixelAnimatableValue(5.0)); | 436 AnimatableDouble::create(3.0), AnimatableDouble::create(5.0)); |
| 442 keyframes[0]->setComposite(EffectModel::CompositeAdd); | 437 keyframes[0]->setComposite(EffectModel::CompositeAdd); |
| 443 keyframes[1]->setComposite(EffectModel::CompositeAdd); | 438 keyframes[1]->setComposite(EffectModel::CompositeAdd); |
| 444 AnimatableValueKeyframeEffectModel* effect = | 439 AnimatableValueKeyframeEffectModel* effect = |
| 445 AnimatableValueKeyframeEffectModel::create(keyframes); | 440 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 446 Vector<RefPtr<Interpolation>> values; | 441 Vector<RefPtr<Interpolation>> values; |
| 447 effect->sample(0, 0.6, duration, values); | 442 effect->sample(0, 0.6, duration, values); |
| 448 expectDoubleValue((7.0 + 3.0) * 0.4 + (7.0 + 5.0) * 0.6, values.at(0)); | 443 expectDoubleValue((7.0 + 3.0) * 0.4 + (7.0 + 5.0) * 0.6, values.at(0)); |
| 449 expectDoubleValue((9.0 + 3.0) * 0.4 + (9.0 + 5.0) * 0.6, values.at(1)); | 444 expectDoubleValue((9.0 + 3.0) * 0.4 + (9.0 + 5.0) * 0.6, values.at(1)); |
| 450 } | 445 } |
| 451 | 446 |
| 452 TEST(AnimationKeyframeEffectModel, MultipleIterations) { | 447 TEST(AnimationKeyframeEffectModel, MultipleIterations) { |
| 453 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( | 448 AnimatableValueKeyframeVector keyframes = keyframesAtZeroAndOne( |
| 454 pixelAnimatableValue(1.0), pixelAnimatableValue(3.0)); | 449 AnimatableDouble::create(1.0), AnimatableDouble::create(3.0)); |
| 455 AnimatableValueKeyframeEffectModel* effect = | 450 AnimatableValueKeyframeEffectModel* effect = |
| 456 AnimatableValueKeyframeEffectModel::create(keyframes); | 451 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 457 Vector<RefPtr<Interpolation>> values; | 452 Vector<RefPtr<Interpolation>> values; |
| 458 effect->sample(0, 0.5, duration, values); | 453 effect->sample(0, 0.5, duration, values); |
| 459 expectDoubleValue(2.0, values.at(0)); | 454 expectDoubleValue(2.0, values.at(0)); |
| 460 effect->sample(1, 0.5, duration, values); | 455 effect->sample(1, 0.5, duration, values); |
| 461 expectDoubleValue(2.0, values.at(0)); | 456 expectDoubleValue(2.0, values.at(0)); |
| 462 effect->sample(2, 0.5, duration, values); | 457 effect->sample(2, 0.5, duration, values); |
| 463 expectDoubleValue(2.0, values.at(0)); | 458 expectDoubleValue(2.0, values.at(0)); |
| 464 } | 459 } |
| 465 | 460 |
| 466 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. | 461 // FIXME: Re-enable this test once compositing of CompositeAdd is supported. |
| 467 TEST(AnimationKeyframeEffectModel, DISABLED_DependsOnUnderlyingValue) { | 462 TEST(AnimationKeyframeEffectModel, DISABLED_DependsOnUnderlyingValue) { |
| 468 AnimatableValueKeyframeVector keyframes(3); | 463 AnimatableValueKeyframeVector keyframes(3); |
| 469 keyframes[0] = AnimatableValueKeyframe::create(); | 464 keyframes[0] = AnimatableValueKeyframe::create(); |
| 470 keyframes[0]->setOffset(0.0); | 465 keyframes[0]->setOffset(0.0); |
| 471 keyframes[0]->setPropertyValue(CSSPropertyLeft, | 466 keyframes[0]->setPropertyValue(CSSPropertyLeft, |
| 472 pixelAnimatableValue(1.0).get()); | 467 AnimatableDouble::create(1.0).get()); |
| 473 keyframes[0]->setComposite(EffectModel::CompositeAdd); | 468 keyframes[0]->setComposite(EffectModel::CompositeAdd); |
| 474 keyframes[1] = AnimatableValueKeyframe::create(); | 469 keyframes[1] = AnimatableValueKeyframe::create(); |
| 475 keyframes[1]->setOffset(0.5); | 470 keyframes[1]->setOffset(0.5); |
| 476 keyframes[1]->setPropertyValue(CSSPropertyLeft, | 471 keyframes[1]->setPropertyValue(CSSPropertyLeft, |
| 477 pixelAnimatableValue(1.0).get()); | 472 AnimatableDouble::create(1.0).get()); |
| 478 keyframes[2] = AnimatableValueKeyframe::create(); | 473 keyframes[2] = AnimatableValueKeyframe::create(); |
| 479 keyframes[2]->setOffset(1.0); | 474 keyframes[2]->setOffset(1.0); |
| 480 keyframes[2]->setPropertyValue(CSSPropertyLeft, | 475 keyframes[2]->setPropertyValue(CSSPropertyLeft, |
| 481 pixelAnimatableValue(1.0).get()); | 476 AnimatableDouble::create(1.0).get()); |
| 482 | 477 |
| 483 AnimatableValueKeyframeEffectModel* effect = | 478 AnimatableValueKeyframeEffectModel* effect = |
| 484 AnimatableValueKeyframeEffectModel::create(keyframes); | 479 AnimatableValueKeyframeEffectModel::create(keyframes); |
| 485 Vector<RefPtr<Interpolation>> values; | 480 Vector<RefPtr<Interpolation>> values; |
| 486 effect->sample(0, 0, duration, values); | 481 effect->sample(0, 0, duration, values); |
| 487 EXPECT_TRUE(values.at(0)); | 482 EXPECT_TRUE(values.at(0)); |
| 488 effect->sample(0, 0.1, duration, values); | 483 effect->sample(0, 0.1, duration, values); |
| 489 EXPECT_TRUE(values.at(0)); | 484 EXPECT_TRUE(values.at(0)); |
| 490 effect->sample(0, 0.25, duration, values); | 485 effect->sample(0, 0.25, duration, values); |
| 491 EXPECT_TRUE(values.at(0)); | 486 EXPECT_TRUE(values.at(0)); |
| 492 effect->sample(0, 0.4, duration, values); | 487 effect->sample(0, 0.4, duration, values); |
| 493 EXPECT_TRUE(values.at(0)); | 488 EXPECT_TRUE(values.at(0)); |
| 494 effect->sample(0, 0.5, duration, values); | 489 effect->sample(0, 0.5, duration, values); |
| 495 EXPECT_FALSE(values.at(0)); | 490 EXPECT_FALSE(values.at(0)); |
| 496 effect->sample(0, 0.6, duration, values); | 491 effect->sample(0, 0.6, duration, values); |
| 497 EXPECT_FALSE(values.at(0)); | 492 EXPECT_FALSE(values.at(0)); |
| 498 effect->sample(0, 0.75, duration, values); | 493 effect->sample(0, 0.75, duration, values); |
| 499 EXPECT_FALSE(values.at(0)); | 494 EXPECT_FALSE(values.at(0)); |
| 500 effect->sample(0, 0.8, duration, values); | 495 effect->sample(0, 0.8, duration, values); |
| 501 EXPECT_FALSE(values.at(0)); | 496 EXPECT_FALSE(values.at(0)); |
| 502 effect->sample(0, 1, duration, values); | 497 effect->sample(0, 1, duration, values); |
| 503 EXPECT_FALSE(values.at(0)); | 498 EXPECT_FALSE(values.at(0)); |
| 504 } | 499 } |
| 505 | 500 |
| 506 TEST(AnimationKeyframeEffectModel, AddSyntheticKeyframes) { | 501 TEST(AnimationKeyframeEffectModel, AddSyntheticKeyframes) { |
| 507 AnimatableValueKeyframeVector keyframes(1); | 502 StringKeyframeVector keyframes(1); |
| 508 keyframes[0] = AnimatableValueKeyframe::create(); | 503 keyframes[0] = StringKeyframe::create(); |
| 509 keyframes[0]->setOffset(0.5); | 504 keyframes[0]->setOffset(0.5); |
| 510 keyframes[0]->setPropertyValue(CSSPropertyLeft, | 505 keyframes[0]->setCSSPropertyValue(CSSPropertyLeft, "4px", nullptr); |
| 511 unknownAnimatableValue(4.0).get()); | |
| 512 | 506 |
| 513 AnimatableValueKeyframeEffectModel* effect = | 507 StringKeyframeEffectModel* effect = |
| 514 AnimatableValueKeyframeEffectModel::create(keyframes); | 508 StringKeyframeEffectModel::create(keyframes); |
| 515 const AnimatableValuePropertySpecificKeyframeVector& | 509 const StringPropertySpecificKeyframeVector& propertySpecificKeyframes = |
| 516 propertySpecificKeyframes = | 510 effect->getPropertySpecificKeyframes(PropertyHandle(CSSPropertyLeft)); |
| 517 effect->getPropertySpecificKeyframes(PropertyHandle(CSSPropertyLeft)); | |
| 518 EXPECT_EQ(3U, propertySpecificKeyframes.size()); | 511 EXPECT_EQ(3U, propertySpecificKeyframes.size()); |
| 519 EXPECT_DOUBLE_EQ(0.0, propertySpecificKeyframes[0]->offset()); | 512 EXPECT_DOUBLE_EQ(0.0, propertySpecificKeyframes[0]->offset()); |
| 520 EXPECT_DOUBLE_EQ(0.5, propertySpecificKeyframes[1]->offset()); | 513 EXPECT_DOUBLE_EQ(0.5, propertySpecificKeyframes[1]->offset()); |
| 521 EXPECT_DOUBLE_EQ(1.0, propertySpecificKeyframes[2]->offset()); | 514 EXPECT_DOUBLE_EQ(1.0, propertySpecificKeyframes[2]->offset()); |
| 522 } | 515 } |
| 523 | 516 |
| 524 TEST(AnimationKeyframeEffectModel, ToKeyframeEffectModel) { | 517 TEST(AnimationKeyframeEffectModel, ToKeyframeEffectModel) { |
| 525 AnimatableValueKeyframeVector keyframes(0); | 518 AnimatableValueKeyframeVector keyframes(0); |
| 526 AnimatableValueKeyframeEffectModel* effect = | 519 AnimatableValueKeyframeEffectModel* effect = |
| 527 AnimatableValueKeyframeEffectModel::create(keyframes); | 520 AnimatableValueKeyframeEffectModel::create(keyframes); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 EXPECT_DOUBLE_EQ(0.6, result[5]->offset()); | 601 EXPECT_DOUBLE_EQ(0.6, result[5]->offset()); |
| 609 EXPECT_DOUBLE_EQ(0.7, result[6]->offset()); | 602 EXPECT_DOUBLE_EQ(0.7, result[6]->offset()); |
| 610 EXPECT_DOUBLE_EQ(0.8, result[7]->offset()); | 603 EXPECT_DOUBLE_EQ(0.8, result[7]->offset()); |
| 611 EXPECT_DOUBLE_EQ(0.85, result[8]->offset()); | 604 EXPECT_DOUBLE_EQ(0.85, result[8]->offset()); |
| 612 EXPECT_DOUBLE_EQ(0.9, result[9]->offset()); | 605 EXPECT_DOUBLE_EQ(0.9, result[9]->offset()); |
| 613 EXPECT_DOUBLE_EQ(0.95, result[10]->offset()); | 606 EXPECT_DOUBLE_EQ(0.95, result[10]->offset()); |
| 614 EXPECT_DOUBLE_EQ(1.0, result[11]->offset()); | 607 EXPECT_DOUBLE_EQ(1.0, result[11]->offset()); |
| 615 } | 608 } |
| 616 | 609 |
| 617 } // namespace blink | 610 } // namespace blink |
| OLD | NEW |