| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sky/engine/core/animation/LengthStyleInterpolation.h" | |
| 6 | |
| 7 #include "sky/engine/core/css/CSSPrimitiveValue.h" | |
| 8 #include "sky/engine/core/css/StylePropertySet.h" | |
| 9 | |
| 10 #include <gtest/gtest.h> | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 class AnimationLengthStyleInterpolationTest : public ::testing::Test { | |
| 15 protected: | |
| 16 static PassOwnPtr<InterpolableValue> lengthToInterpolableValue(CSSValue* val
ue) | |
| 17 { | |
| 18 return LengthStyleInterpolation::lengthToInterpolableValue(value); | |
| 19 } | |
| 20 | |
| 21 static PassRefPtr<CSSValue> interpolableValueToLength(InterpolableValue* val
ue, ValueRange range) | |
| 22 { | |
| 23 return LengthStyleInterpolation::interpolableValueToLength(value, range)
; | |
| 24 } | |
| 25 | |
| 26 static PassRefPtr<CSSValue> roundTrip(PassRefPtr<CSSValue> value) | |
| 27 { | |
| 28 return interpolableValueToLength(lengthToInterpolableValue(value.get()).
get(), ValueRangeAll); | |
| 29 } | |
| 30 | |
| 31 static void testPrimitiveValue(RefPtr<CSSValue> value, double doubleValue, C
SSPrimitiveValue::UnitType unitType) | |
| 32 { | |
| 33 EXPECT_TRUE(value->isPrimitiveValue()); | |
| 34 EXPECT_EQ(doubleValue, toCSSPrimitiveValue(value.get())->getDoubleValue(
)); | |
| 35 EXPECT_EQ(unitType, toCSSPrimitiveValue(value.get())->primitiveType()); | |
| 36 } | |
| 37 | |
| 38 static PassOwnPtr<InterpolableList> createInterpolableLength(double a, doubl
e b, double c, double d, double e, double f, double g, double h, double i, doubl
e j) | |
| 39 { | |
| 40 OwnPtr<InterpolableList> list = InterpolableList::create(10); | |
| 41 list->set(0, InterpolableNumber::create(a)); | |
| 42 list->set(1, InterpolableNumber::create(b)); | |
| 43 list->set(2, InterpolableNumber::create(c)); | |
| 44 list->set(3, InterpolableNumber::create(d)); | |
| 45 list->set(4, InterpolableNumber::create(e)); | |
| 46 list->set(5, InterpolableNumber::create(f)); | |
| 47 list->set(6, InterpolableNumber::create(g)); | |
| 48 list->set(7, InterpolableNumber::create(h)); | |
| 49 list->set(8, InterpolableNumber::create(i)); | |
| 50 list->set(9, InterpolableNumber::create(j)); | |
| 51 | |
| 52 return list.release(); | |
| 53 } | |
| 54 | |
| 55 void initLengthArray(CSSLengthArray& lengthArray) | |
| 56 { | |
| 57 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); | |
| 58 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) | |
| 59 lengthArray.at(i) = 0; | |
| 60 } | |
| 61 | |
| 62 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) | |
| 63 { | |
| 64 initLengthArray(lengthArray); | |
| 65 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c
reate(); | |
| 66 propertySet->setProperty(CSSPropertyLeft, text); | |
| 67 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge
t())->accumulateLengthArray(lengthArray); | |
| 68 return lengthArray; | |
| 69 } | |
| 70 | |
| 71 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) | |
| 72 { | |
| 73 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { | |
| 74 if (a.at(i) != b.at(i)) | |
| 75 return false; | |
| 76 } | |
| 77 return true; | |
| 78 } | |
| 79 }; | |
| 80 | |
| 81 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength) | |
| 82 { | |
| 83 RefPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitive
Value::CSS_PX)); | |
| 84 testPrimitiveValue(value, 0, CSSPrimitiveValue::CSS_PX); | |
| 85 | |
| 86 value = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); | |
| 87 testPrimitiveValue(value, 0, CSSPrimitiveValue::CSS_PX); | |
| 88 } | |
| 89 | |
| 90 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit) | |
| 91 { | |
| 92 RefPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiv
eValue::CSS_PX)); | |
| 93 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_PX); | |
| 94 | |
| 95 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE
NTAGE)); | |
| 96 testPrimitiveValue(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE); | |
| 97 | |
| 98 value = roundTrip(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS)
); | |
| 99 testPrimitiveValue(value, -10, CSSPrimitiveValue::CSS_EMS); | |
| 100 } | |
| 101 | |
| 102 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) | |
| 103 { | |
| 104 RefPtr<CSSValue> value = CSSPrimitiveValue::create(-10, CSSPrimitiveValue::C
SS_EMS); | |
| 105 value = interpolableValueToLength(lengthToInterpolableValue(value.get()).get
(), ValueRangeNonNegative); | |
| 106 testPrimitiveValue(value, 0, CSSPrimitiveValue::CSS_EMS); | |
| 107 } | |
| 108 | |
| 109 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) | |
| 110 { | |
| 111 CSSLengthArray actual, expectation; | |
| 112 initLengthArray(expectation); | |
| 113 OwnPtr<InterpolableList> list = createInterpolableLength(0, 10, 0, 10, 0, 10
, 0, 10, 0, 10); | |
| 114 toCSSPrimitiveValue(interpolableValueToLength(list.get(), ValueRangeAll).get
())->accumulateLengthArray(expectation); | |
| 115 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10%%
+ 10ex + 10ch + 10vh + 10vmax)"))); | |
| 116 } | |
| 117 | |
| 118 } | |
| OLD | NEW |