| 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 "config.h" | 31 #include "config.h" |
| 32 #include "core/animation/KeyframeAnimationEffect.h" | 32 #include "core/animation/KeyframeAnimationEffect.h" |
| 33 | 33 |
| 34 #include "core/animation/AnimatableNumber.h" | 34 #include "core/animation/AnimatableLength.h" |
| 35 #include "core/animation/AnimatableUnknown.h" | 35 #include "core/animation/AnimatableUnknown.h" |
| 36 #include "core/css/CSSPrimitiveValue.h" | 36 #include "core/css/CSSPrimitiveValue.h" |
| 37 #include <gtest/gtest.h> | 37 #include <gtest/gtest.h> |
| 38 | 38 |
| 39 using namespace WebCore; | 39 using namespace WebCore; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 AnimatableValue* unknownAnimatableValue(double n) | 43 AnimatableValue* unknownAnimatableValue(double n) |
| 44 { | 44 { |
| 45 return AnimatableUnknown::create(CSSPrimitiveValue::create(n, CSSPrimitiveVa
lue::CSS_UNKNOWN).get()).leakRef(); | 45 return AnimatableUnknown::create(CSSPrimitiveValue::create(n, CSSPrimitiveVa
lue::CSS_UNKNOWN).get()).leakRef(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 AnimatableValue* pixelAnimatableValue(double n) | 48 AnimatableValue* pixelAnimatableValue(double n) |
| 49 { | 49 { |
| 50 return AnimatableNumber::create(CSSPrimitiveValue::create(n, CSSPrimitiveVal
ue::CSS_PX).get()).leakRef(); | 50 return AnimatableLength::create(CSSPrimitiveValue::create(n, CSSPrimitiveVal
ue::CSS_PX).get()).leakRef(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 KeyframeAnimationEffect::KeyframeVector keyframesAtZeroAndOne(AnimatableValue* z
eroValue, AnimatableValue* oneValue) | 53 KeyframeAnimationEffect::KeyframeVector keyframesAtZeroAndOne(AnimatableValue* z
eroValue, AnimatableValue* oneValue) |
| 54 { | 54 { |
| 55 KeyframeAnimationEffect::KeyframeVector keyframes(2); | 55 KeyframeAnimationEffect::KeyframeVector keyframes(2); |
| 56 keyframes[0] = Keyframe::create(); | 56 keyframes[0] = Keyframe::create(); |
| 57 keyframes[0]->setOffset(0.0); | 57 keyframes[0]->setOffset(0.0); |
| 58 keyframes[0]->setPropertyValue(CSSPropertyLeft, zeroValue); | 58 keyframes[0]->setPropertyValue(CSSPropertyLeft, zeroValue); |
| 59 keyframes[1] = Keyframe::create(); | 59 keyframes[1] = Keyframe::create(); |
| 60 keyframes[1]->setOffset(1.0); | 60 keyframes[1]->setOffset(1.0); |
| 61 keyframes[1]->setPropertyValue(CSSPropertyLeft, oneValue); | 61 keyframes[1]->setPropertyValue(CSSPropertyLeft, oneValue); |
| 62 return keyframes; | 62 return keyframes; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void expectDoubleValue(double expectedValue, PassRefPtr<AnimatableValue> value) | 65 void expectDoubleValue(double expectedValue, PassRefPtr<AnimatableValue> value) |
| 66 { | 66 { |
| 67 ASSERT_TRUE(value->isNumber() || value->isUnknown()); | 67 ASSERT_TRUE(value->isLength() || value->isUnknown()); |
| 68 | 68 |
| 69 double actualValue; | 69 double actualValue; |
| 70 if (value->isNumber()) | 70 if (value->isLength()) |
| 71 actualValue = toCSSPrimitiveValue(toAnimatableNumber(value.get())->toCSS
Value().get())->getDoubleValue(); | 71 actualValue = toCSSPrimitiveValue(toAnimatableLength(value.get())->toCSS
Value().get())->getDoubleValue(); |
| 72 else | 72 else |
| 73 actualValue = toCSSPrimitiveValue(toAnimatableUnknown(value.get())->toCS
SValue().get())->getDoubleValue(); | 73 actualValue = toCSSPrimitiveValue(toAnimatableUnknown(value.get())->toCS
SValue().get())->getDoubleValue(); |
| 74 | 74 |
| 75 EXPECT_FLOAT_EQ(static_cast<float>(expectedValue), actualValue); | 75 EXPECT_FLOAT_EQ(static_cast<float>(expectedValue), actualValue); |
| 76 } | 76 } |
| 77 | 77 |
| 78 | 78 |
| 79 TEST(KeyframeAnimationEffect, BasicOperation) | 79 TEST(KeyframeAnimationEffect, BasicOperation) |
| 80 { | 80 { |
| 81 KeyframeAnimationEffect::KeyframeVector keyframes = keyframesAtZeroAndOne(un
knownAnimatableValue(3.0), unknownAnimatableValue(5.0)); | 81 KeyframeAnimationEffect::KeyframeVector keyframes = keyframesAtZeroAndOne(un
knownAnimatableValue(3.0), unknownAnimatableValue(5.0)); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 EXPECT_TRUE(effect->sample(0, 0.25)->begin()->value->dependsOnUnderlyingValu
e()); | 361 EXPECT_TRUE(effect->sample(0, 0.25)->begin()->value->dependsOnUnderlyingValu
e()); |
| 362 EXPECT_TRUE(effect->sample(0, 0.4)->begin()->value->dependsOnUnderlyingValue
()); | 362 EXPECT_TRUE(effect->sample(0, 0.4)->begin()->value->dependsOnUnderlyingValue
()); |
| 363 EXPECT_FALSE(effect->sample(0, 0.5)->begin()->value->dependsOnUnderlyingValu
e()); | 363 EXPECT_FALSE(effect->sample(0, 0.5)->begin()->value->dependsOnUnderlyingValu
e()); |
| 364 EXPECT_FALSE(effect->sample(0, 0.6)->begin()->value->dependsOnUnderlyingValu
e()); | 364 EXPECT_FALSE(effect->sample(0, 0.6)->begin()->value->dependsOnUnderlyingValu
e()); |
| 365 EXPECT_FALSE(effect->sample(0, 0.75)->begin()->value->dependsOnUnderlyingVal
ue()); | 365 EXPECT_FALSE(effect->sample(0, 0.75)->begin()->value->dependsOnUnderlyingVal
ue()); |
| 366 EXPECT_FALSE(effect->sample(0, 0.8)->begin()->value->dependsOnUnderlyingValu
e()); | 366 EXPECT_FALSE(effect->sample(0, 0.8)->begin()->value->dependsOnUnderlyingValu
e()); |
| 367 EXPECT_FALSE(effect->sample(0, 1)->begin()->value->dependsOnUnderlyingValue(
)); | 367 EXPECT_FALSE(effect->sample(0, 1)->begin()->value->dependsOnUnderlyingValue(
)); |
| 368 } | 368 } |
| 369 | 369 |
| 370 } // namespace | 370 } // namespace |
| OLD | NEW |