| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/animation/LengthStyleInterpolation.h" | 6 #include "core/animation/LengthStyleInterpolation.h" |
| 7 | 7 |
| 8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 #include "core/css/StylePropertySet.h" | 9 #include "core/css/StylePropertySet.h" |
| 10 | 10 |
| 11 #include <gtest/gtest.h> | 11 #include <gtest/gtest.h> |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 class AnimationLengthStyleInterpolationTest : public ::testing::Test { | 15 class AnimationLengthStyleInterpolationTest : public ::testing::Test { |
| 16 protected: | 16 protected: |
| 17 static PassOwnPtrWillBeRawPtr<InterpolableValue> lengthToInterpolableValue(c
onst CSSValue& value) | 17 static PassOwnPtrWillBeRawPtr<InterpolableValue> lengthToInterpolableValue(c
onst CSSValue& value) |
| 18 { | 18 { |
| 19 return LengthStyleInterpolation::toInterpolableValue(value); | 19 return LengthStyleInterpolation::toInterpolableValue(value); |
| 20 } | 20 } |
| 21 | 21 |
| 22 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToLength(Interpolab
leValue* value, InterpolationRange range) | 22 static CSSValue interpolableValueToLength(InterpolableValue* value, Interpol
ationRange range) |
| 23 { | 23 { |
| 24 return LengthStyleInterpolation::fromInterpolableValue(*value, range); | 24 return LengthStyleInterpolation::fromInterpolableValue(*value, range); |
| 25 } | 25 } |
| 26 | 26 |
| 27 static PassRefPtrWillBeRawPtr<CSSValue> roundTrip(PassRefPtrWillBeRawPtr<CSS
Value> value) | 27 static CSSValue roundTrip(CSSValue value) |
| 28 { | 28 { |
| 29 return interpolableValueToLength(lengthToInterpolableValue(*value).get()
, RangeAll); | 29 return interpolableValueToLength(lengthToInterpolableValue(value).get(),
RangeAll); |
| 30 } | 30 } |
| 31 | 31 |
| 32 static void testPrimitiveValue(RefPtrWillBeRawPtr<CSSValue> value, double do
ubleValue, CSSPrimitiveValue::UnitType unitType) | 32 static void testPrimitiveValue(CSSValue value, double doubleValue, CSSPrimit
iveValue::UnitType unitType) |
| 33 { | 33 { |
| 34 EXPECT_TRUE(value->isPrimitiveValue()); | 34 EXPECT_TRUE(value.isPrimitiveValue()); |
| 35 EXPECT_EQ(doubleValue, toCSSPrimitiveValue(value.get())->getDoubleValue(
)); | 35 EXPECT_EQ(doubleValue, toCSSPrimitiveValue(value).getDoubleValue()); |
| 36 EXPECT_EQ(unitType, toCSSPrimitiveValue(value.get())->primitiveType()); | 36 EXPECT_EQ(unitType, toCSSPrimitiveValue(value).primitiveType()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 static PassOwnPtrWillBeRawPtr<InterpolableList> createInterpolableLength(dou
ble a, double b, double c, double d, double e, double f, double g, double h, dou
ble i, double j) | 39 static PassOwnPtrWillBeRawPtr<InterpolableList> createInterpolableLength(dou
ble a, double b, double c, double d, double e, double f, double g, double h, dou
ble i, double j) |
| 40 { | 40 { |
| 41 OwnPtrWillBeRawPtr<InterpolableList> list = InterpolableList::create(10)
; | 41 OwnPtrWillBeRawPtr<InterpolableList> list = InterpolableList::create(10)
; |
| 42 list->set(0, InterpolableNumber::create(a)); | 42 list->set(0, InterpolableNumber::create(a)); |
| 43 list->set(1, InterpolableNumber::create(b)); | 43 list->set(1, InterpolableNumber::create(b)); |
| 44 list->set(2, InterpolableNumber::create(c)); | 44 list->set(2, InterpolableNumber::create(c)); |
| 45 list->set(3, InterpolableNumber::create(d)); | 45 list->set(3, InterpolableNumber::create(d)); |
| 46 list->set(4, InterpolableNumber::create(e)); | 46 list->set(4, InterpolableNumber::create(e)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 59 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) | 59 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) |
| 60 lengthArray.at(i) = 0; | 60 lengthArray.at(i) = 0; |
| 61 } | 61 } |
| 62 | 62 |
| 63 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) | 63 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) |
| 64 { | 64 { |
| 65 CSSPrimitiveValue::CSSLengthTypeArray lengthTypeArray; | 65 CSSPrimitiveValue::CSSLengthTypeArray lengthTypeArray; |
| 66 initLengthArray(lengthArray); | 66 initLengthArray(lengthArray); |
| 67 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr
opertySet::create(); | 67 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr
opertySet::create(); |
| 68 propertySet->setProperty(CSSPropertyLeft, text); | 68 propertySet->setProperty(CSSPropertyLeft, text); |
| 69 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge
t())->accumulateLengthArray(lengthArray); | 69 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft))->
accumulateLengthArray(lengthArray); |
| 70 return lengthArray; | 70 return lengthArray; |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) | 73 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) |
| 74 { | 74 { |
| 75 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { | 75 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { |
| 76 if (a.at(i) != b.at(i)) | 76 if (a.at(i) != b.at(i)) |
| 77 return false; | 77 return false; |
| 78 } | 78 } |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength) | 83 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength) |
| 84 { | 84 { |
| 85 RefPtrWillBeRawPtr<CSSValue> value1 = roundTrip(CSSPrimitiveValue::create(0,
CSSPrimitiveValue::CSS_PX)); | 85 CSSValue value1 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::
CSS_PX)); |
| 86 testPrimitiveValue(value1, 0, CSSPrimitiveValue::CSS_PX); | 86 testPrimitiveValue(value1, 0, CSSPrimitiveValue::CSS_PX); |
| 87 | 87 |
| 88 RefPtrWillBeRawPtr<CSSValue> value2 = roundTrip(CSSPrimitiveValue::create(0,
CSSPrimitiveValue::CSS_PERCENTAGE)); | 88 CSSValue value2 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::
CSS_PERCENTAGE)); |
| 89 testPrimitiveValue(value2, 0, CSSPrimitiveValue::CSS_PERCENTAGE); | 89 testPrimitiveValue(value2, 0, CSSPrimitiveValue::CSS_PERCENTAGE); |
| 90 | 90 |
| 91 RefPtrWillBeRawPtr<CSSValue> value3 = roundTrip(CSSPrimitiveValue::create(0,
CSSPrimitiveValue::CSS_EMS)); | 91 CSSValue value3 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::
CSS_EMS)); |
| 92 testPrimitiveValue(value3, 0, CSSPrimitiveValue::CSS_EMS); | 92 testPrimitiveValue(value3, 0, CSSPrimitiveValue::CSS_EMS); |
| 93 | 93 |
| 94 } | 94 } |
| 95 | 95 |
| 96 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit) | 96 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit) |
| 97 { | 97 { |
| 98 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10,
CSSPrimitiveValue::CSS_PX)); | 98 CSSValue value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::
CSS_PX)); |
| 99 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_PX); | 99 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_PX); |
| 100 | 100 |
| 101 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE
NTAGE)); | 101 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE
NTAGE)); |
| 102 testPrimitiveValue(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE); | 102 testPrimitiveValue(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE); |
| 103 | 103 |
| 104 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS))
; | 104 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS))
; |
| 105 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_EMS); | 105 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_EMS); |
| 106 } | 106 } |
| 107 | 107 |
| 108 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) | 108 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) |
| 109 { | 109 { |
| 110 RefPtrWillBeRawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrim
itiveValue::CSS_PX); | 110 CSSValue value1 = CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_PX); |
| 111 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1).get(),
RangeNonNegative); | 111 value1 = interpolableValueToLength(lengthToInterpolableValue(value1).get(),
RangeNonNegative); |
| 112 testPrimitiveValue(value1, 0, CSSPrimitiveValue::CSS_PX); | 112 testPrimitiveValue(value1, 0, CSSPrimitiveValue::CSS_PX); |
| 113 | 113 |
| 114 RefPtrWillBeRawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrim
itiveValue::CSS_EMS); | 114 CSSValue value2 = CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS)
; |
| 115 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2).get(),
RangeNonNegative); | 115 value2 = interpolableValueToLength(lengthToInterpolableValue(value2).get(),
RangeNonNegative); |
| 116 testPrimitiveValue(value2, 0, CSSPrimitiveValue::CSS_EMS); | 116 testPrimitiveValue(value2, 0, CSSPrimitiveValue::CSS_EMS); |
| 117 } | 117 } |
| 118 | 118 |
| 119 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) | 119 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) |
| 120 { | 120 { |
| 121 CSSLengthArray expectation, actual; | 121 CSSLengthArray expectation, actual; |
| 122 initLengthArray(expectation); | 122 initLengthArray(expectation); |
| 123 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | 123 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); |
| 124 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); | 124 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); |
| 125 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); | 125 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); |
| 126 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())
->accumulateLengthArray(expectation); | 126 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll)).accum
ulateLengthArray(expectation); |
| 127 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10%
+ 10ex + 10ch + 10vh + 10vmax)"))); | 127 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10%
+ 10ex + 10ch + 10vh + 10vmax)"))); |
| 128 } | 128 } |
| 129 | 129 |
| 130 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithSingleValues) | 130 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithSingleValues) |
| 131 { | 131 { |
| 132 CSSLengthArray expectation, actual; | 132 CSSLengthArray expectation, actual; |
| 133 initLengthArray(expectation); | 133 initLengthArray(expectation); |
| 134 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | 134 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); |
| 135 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); | 135 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); |
| 136 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); | 136 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); |
| 137 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())
->accumulateLengthArray(expectation); | 137 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll)).accum
ulateLengthArray(expectation); |
| 138 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10%
+ 10ex + 10ch + 10vh + 10vmax)"))); | 138 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10%
+ 10ex + 10ch + 10vh + 10vmax)"))); |
| 139 | 139 |
| 140 } | 140 } |
| 141 | 141 |
| 142 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithMultipleValues) | 142 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithMultipleValues) |
| 143 { | 143 { |
| 144 CSSLengthArray expectation, actual; | 144 CSSLengthArray expectation, actual; |
| 145 initLengthArray(expectation); | 145 initLengthArray(expectation); |
| 146 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | 146 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); |
| 147 result->set(0, createInterpolableLength(0, 20, 0, 30, 0, 8, 0, 10, 0, 7)); | 147 result->set(0, createInterpolableLength(0, 20, 0, 30, 0, 8, 0, 10, 0, 7)); |
| 148 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); | 148 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); |
| 149 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())
->accumulateLengthArray(expectation); | 149 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll)).accum
ulateLengthArray(expectation); |
| 150 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(20%
+ 30ex + 8ch + 10vh + 7vmax)"))); | 150 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(20%
+ 30ex + 8ch + 10vh + 7vmax)"))); |
| 151 | 151 |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValue) | 154 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValue) |
| 155 { | 155 { |
| 156 CSSLengthArray expectation, actual; | 156 CSSLengthArray expectation, actual; |
| 157 initLengthArray(expectation); | 157 initLengthArray(expectation); |
| 158 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | 158 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); |
| 159 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); | 159 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); |
| 160 result->set(1, createInterpolableLength(1, 1, 0, 1, 0, 1, 0, 1, 0, 1)); | 160 result->set(1, createInterpolableLength(1, 1, 0, 1, 0, 1, 0, 1, 0, 1)); |
| 161 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())
->accumulateLengthArray(expectation); | 161 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll)).accum
ulateLengthArray(expectation); |
| 162 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(0px
+ 10% + 10ex + 10ch + 10vh + 10vmax)"))); | 162 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(0px
+ 10% + 10ex + 10ch + 10vh + 10vmax)"))); |
| 163 } | 163 } |
| 164 | 164 |
| 165 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues) | 165 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues) |
| 166 { | 166 { |
| 167 CSSLengthArray expectation, actual; | 167 CSSLengthArray expectation, actual; |
| 168 initLengthArray(expectation); | 168 initLengthArray(expectation); |
| 169 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | 169 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); |
| 170 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); | 170 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); |
| 171 result->set(1, createInterpolableLength(1, 1, 1, 1, 0, 1, 0, 1, 1, 1)); | 171 result->set(1, createInterpolableLength(1, 1, 1, 1, 0, 1, 0, 1, 1, 1)); |
| 172 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())
->accumulateLengthArray(expectation); | 172 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll)).accum
ulateLengthArray(expectation); |
| 173 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(0px
+ 10% + 0em + 10ex + 10ch + 10vh + 0vmin + 10vmax)"))); | 173 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(0px
+ 10% + 0em + 10ex + 10ch + 10vh + 0vmin + 10vmax)"))); |
| 174 } | 174 } |
| 175 | 175 |
| 176 } | 176 } |
| OLD | NEW |