Chromium Code Reviews| 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 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 return list.release(); | 53 return list.release(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void initLengthArray(CSSLengthArray& lengthArray) | 56 void initLengthArray(CSSLengthArray& lengthArray) |
| 57 { | 57 { |
| 58 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); | 58 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); |
| 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 void initLengthTypeArray(CSSLengthTypeArray& lengthTypeArray) | |
| 64 { | |
| 65 lengthTypeArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); | |
| 66 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) | |
| 67 lengthTypeArray.clear(i); | |
| 68 } | |
| 69 | |
|
samli
2014/12/22 03:38:04
Don't need these anymore!
evemj (not active)
2014/12/22 06:09:05
Done.
| |
| 63 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) | 70 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) |
| 64 { | 71 { |
| 72 CSSLengthTypeArray lengthTypeArray; | |
| 65 initLengthArray(lengthArray); | 73 initLengthArray(lengthArray); |
| 74 initLengthTypeArray(lengthTypeArray); | |
| 66 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr opertySet::create(); | 75 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr opertySet::create(); |
| 67 propertySet->setProperty(CSSPropertyLeft, text); | 76 propertySet->setProperty(CSSPropertyLeft, text); |
| 68 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge t())->accumulateLengthArray(lengthArray); | 77 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge t())->accumulateLengthArray(lengthArray, lengthTypeArray); |
| 69 return lengthArray; | 78 return lengthArray; |
| 70 } | 79 } |
| 71 | 80 |
| 72 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) | 81 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) |
| 73 { | 82 { |
| 74 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { | 83 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { |
| 75 if (a.at(i) != b.at(i)) | 84 if (a.at(i) != b.at(i)) |
| 76 return false; | 85 return false; |
| 77 } | 86 } |
| 78 return true; | 87 return true; |
| 79 } | 88 } |
| 80 }; | 89 }; |
| 81 | 90 |
| 82 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength) | 91 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength) |
| 83 { | 92 { |
| 84 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 93 RefPtrWillBeRawPtr<CSSValue> value1 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 85 testPrimitiveValue(value, 0, CSSPrimitiveValue::CSS_PX); | 94 testPrimitiveValue(value1, 0, CSSPrimitiveValue::CSS_PX); |
| 86 | 95 |
| 87 value = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); | 96 RefPtrWillBeRawPtr<CSSValue> value2 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PERCENTAGE)); |
| 88 testPrimitiveValue(value, 0, CSSPrimitiveValue::CSS_PX); | 97 testPrimitiveValue(value2, 0, CSSPrimitiveValue::CSS_PERCENTAGE); |
| 98 | |
| 99 RefPtrWillBeRawPtr<CSSValue> value3 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); | |
| 100 testPrimitiveValue(value3, 0, CSSPrimitiveValue::CSS_EMS); | |
| 101 | |
| 89 } | 102 } |
| 90 | 103 |
| 91 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit) | 104 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit) |
| 92 { | 105 { |
| 93 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); | 106 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); |
| 94 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_PX); | 107 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_PX); |
| 95 | 108 |
| 96 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE NTAGE)); | 109 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE NTAGE)); |
| 97 testPrimitiveValue(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE); | 110 testPrimitiveValue(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE); |
| 98 | 111 |
| 99 value = roundTrip(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS) ); | 112 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS)) ; |
| 100 testPrimitiveValue(value, -10, CSSPrimitiveValue::CSS_EMS); | 113 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_EMS); |
| 101 } | 114 } |
| 102 | 115 |
| 103 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) | 116 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) |
| 104 { | 117 { |
| 105 RefPtrWillBeRawPtr<CSSValue> value = CSSPrimitiveValue::create(-10, CSSPrimi tiveValue::CSS_EMS); | 118 RefPtrWillBeRawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_PX); |
| 106 value = interpolableValueToLength(lengthToInterpolableValue(*value).get(), V alueRangeNonNegative); | 119 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1).get(), ValueRangeNonNegative); |
| 107 testPrimitiveValue(value, 0, CSSPrimitiveValue::CSS_EMS); | 120 testPrimitiveValue(value1, 0, CSSPrimitiveValue::CSS_PX); |
| 121 | |
| 122 RefPtrWillBeRawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_EMS); | |
| 123 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2).get(), ValueRangeNonNegative); | |
| 124 testPrimitiveValue(value2, 0, CSSPrimitiveValue::CSS_EMS); | |
| 108 } | 125 } |
| 109 | 126 |
| 110 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) | 127 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) |
| 111 { | 128 { |
| 112 CSSLengthArray actual, expectation; | 129 CSSLengthArray expectation, actual; |
| 130 CSSLengthTypeArray expectedType, actualType; | |
| 113 initLengthArray(expectation); | 131 initLengthArray(expectation); |
| 114 OwnPtrWillBeRawPtr<InterpolableList> list = createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10); | 132 initLengthTypeArray(expectedType); |
| 115 toCSSPrimitiveValue(interpolableValueToLength(list.get(), ValueRangeAll).get ())->accumulateLengthArray(expectation); | 133 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); |
| 134 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); | |
| 135 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); | |
| 136 toCSSPrimitiveValue(interpolableValueToLength(result.get(), ValueRangeAll).g et())->accumulateLengthArray(expectation, expectedType); | |
| 116 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"))); | 137 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"))); |
| 117 } | 138 } |
| 118 | 139 |
| 140 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithSingleValues) | |
| 141 { | |
| 142 CSSLengthArray expectation, actual; | |
| 143 CSSLengthTypeArray expectedType, actualType; | |
| 144 initLengthArray(expectation); | |
| 145 initLengthTypeArray(expectedType); | |
| 146 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | |
| 147 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); | |
| 148 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); | |
| 149 toCSSPrimitiveValue(interpolableValueToLength(result.get(), ValueRangeAll).g et())->accumulateLengthArray(expectation, expectedType); | |
| 150 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"))); | |
| 151 | |
| 119 } | 152 } |
| 153 | |
| 154 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithMultipleValues) | |
| 155 { | |
| 156 CSSLengthArray expectation, actual; | |
| 157 CSSLengthTypeArray expectedType, actualType; | |
| 158 initLengthArray(expectation); | |
| 159 initLengthTypeArray(expectedType); | |
| 160 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | |
| 161 result->set(0, createInterpolableLength(0, 20, 0, 30, 0, 8, 0, 10, 0, 7)); | |
| 162 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); | |
| 163 toCSSPrimitiveValue(interpolableValueToLength(result.get(), ValueRangeAll).g et())->accumulateLengthArray(expectation, expectedType); | |
| 164 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(20% + 30ex + 8ch + 10vh + 7vmax)"))); | |
| 165 | |
| 166 } | |
| 167 | |
| 168 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues) | |
|
samli
2014/12/22 03:38:04
Only has one zero value. Add an extra test with mu
| |
| 169 { | |
| 170 CSSLengthArray expectation, actual; | |
| 171 CSSLengthTypeArray expectedType, actualType; | |
|
samli
2014/12/22 03:38:04
This isn't needed
evemj (not active)
2014/12/22 06:09:05
Done.
| |
| 172 initLengthArray(expectation); | |
| 173 initLengthTypeArray(expectedType); | |
| 174 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | |
| 175 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); | |
| 176 result->set(1, createInterpolableLength(1, 1, 0, 1, 0, 1, 0, 1, 0, 1)); | |
| 177 toCSSPrimitiveValue(interpolableValueToLength(result.get(), ValueRangeAll).g et())->accumulateLengthArray(expectation, expectedType); | |
| 178 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(0px + 10% + 10ex + 10ch + 10vh + 10vmax)"))); | |
| 179 } | |
| 180 | |
| 181 } | |
| OLD | NEW |