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/Interpolation.h" | 6 #include "core/animation/Interpolation.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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 list->set(4, InterpolableNumber::create(e)); | 46 list->set(4, InterpolableNumber::create(e)); |
47 list->set(5, InterpolableNumber::create(f)); | 47 list->set(5, InterpolableNumber::create(f)); |
48 list->set(6, InterpolableNumber::create(g)); | 48 list->set(6, InterpolableNumber::create(g)); |
49 list->set(7, InterpolableNumber::create(h)); | 49 list->set(7, InterpolableNumber::create(h)); |
50 list->set(8, InterpolableNumber::create(i)); | 50 list->set(8, InterpolableNumber::create(i)); |
51 list->set(9, InterpolableNumber::create(j)); | 51 list->set(9, InterpolableNumber::create(j)); |
52 | 52 |
53 return list.release(); | 53 return list.release(); |
54 } | 54 } |
55 | 55 |
56 void initLengthArray(CSSLengthArray& lengthArray) | |
57 { | |
58 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); | |
59 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) | |
60 lengthArray.at(i) = 0; | |
61 } | |
62 | |
63 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) | 56 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) |
64 { | 57 { |
65 initLengthArray(lengthArray); | 58 CSSPrimitiveValue::zeroLengthArray(lengthArray); |
66 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c
reate(); | 59 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c
reate(); |
67 propertySet->setProperty(CSSPropertyLeft, text); | 60 propertySet->setProperty(CSSPropertyLeft, text); |
68 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge
t())->accumulateLengthArray(lengthArray); | 61 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge
t())->accumulateLengthArray(lengthArray); |
69 return lengthArray; | 62 return lengthArray; |
70 } | 63 } |
71 | 64 |
72 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) | 65 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) |
73 { | 66 { |
74 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { | 67 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { |
75 if (a.at(i) != b.at(i)) | 68 if (a.at(i) != b.at(i)) |
(...skipping 17 matching lines...) Expand all Loading... |
93 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10,
CSSPrimitiveValue::CSS_PX)); | 86 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10,
CSSPrimitiveValue::CSS_PX)); |
94 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_PX); | 87 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_PX); |
95 | 88 |
96 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE
NTAGE)); | 89 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE
NTAGE)); |
97 testPrimitiveValue(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE); | 90 testPrimitiveValue(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE); |
98 } | 91 } |
99 | 92 |
100 TEST_F(AnimationInterpolationTest, MultipleUnits) | 93 TEST_F(AnimationInterpolationTest, MultipleUnits) |
101 { | 94 { |
102 CSSLengthArray actual, expectation; | 95 CSSLengthArray actual, expectation; |
103 initLengthArray(expectation); | 96 CSSPrimitiveValue::zeroLengthArray(expectation); |
104 OwnPtrWillBeRawPtr<InterpolableList> list = createInterpolableLength(0, 10,
0, 10, 0, 10, 0, 10, 0, 10); | 97 OwnPtrWillBeRawPtr<InterpolableList> list = createInterpolableLength(0, 10,
0, 10, 0, 10, 0, 10, 0, 10); |
105 toCSSPrimitiveValue(interpolableValueToLength(list.get()).get())->accumulate
LengthArray(expectation); | 98 toCSSPrimitiveValue(interpolableValueToLength(list.get()).get())->accumulate
LengthArray(expectation); |
106 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10%%
+ 10ex + 10ch + 10vh + 10vmax)"))); | 99 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10%%
+ 10ex + 10ch + 10vh + 10vmax)"))); |
107 } | 100 } |
108 | 101 |
109 } | 102 } |
OLD | NEW |