Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: Source/core/animation/LengthStyleInterpolationTest.cpp

Issue 813233002: Animation: Fix loss of type information when interpolating value of 0 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix second accumulateLength method Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) 63 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text)
64 { 64 {
65 CSSPrimitiveValue::CSSLengthTypeArray lengthTypeArray;
65 initLengthArray(lengthArray); 66 initLengthArray(lengthArray);
66 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr opertySet::create(); 67 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr opertySet::create();
67 propertySet->setProperty(CSSPropertyLeft, text); 68 propertySet->setProperty(CSSPropertyLeft, text);
68 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge t())->accumulateLengthArray(lengthArray); 69 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge t())->accumulateLengthArray(lengthArray);
69 return lengthArray; 70 return lengthArray;
70 } 71 }
71 72
72 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) 73 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b)
73 { 74 {
74 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { 75 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) {
75 if (a.at(i) != b.at(i)) 76 if (a.at(i) != b.at(i))
76 return false; 77 return false;
77 } 78 }
78 return true; 79 return true;
79 } 80 }
80 }; 81 };
81 82
82 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength) 83 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength)
83 { 84 {
84 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); 85 RefPtrWillBeRawPtr<CSSValue> value1 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX));
85 testPrimitiveValue(value, 0, CSSPrimitiveValue::CSS_PX); 86 testPrimitiveValue(value1, 0, CSSPrimitiveValue::CSS_PX);
86 87
87 value = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); 88 RefPtrWillBeRawPtr<CSSValue> value2 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PERCENTAGE));
88 testPrimitiveValue(value, 0, CSSPrimitiveValue::CSS_PX); 89 testPrimitiveValue(value2, 0, CSSPrimitiveValue::CSS_PERCENTAGE);
90
91 RefPtrWillBeRawPtr<CSSValue> value3 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS));
92 testPrimitiveValue(value3, 0, CSSPrimitiveValue::CSS_EMS);
93
89 } 94 }
90 95
91 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit) 96 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit)
92 { 97 {
93 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); 98 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX));
94 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_PX); 99 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_PX);
95 100
96 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE NTAGE)); 101 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE NTAGE));
97 testPrimitiveValue(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE); 102 testPrimitiveValue(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE);
98 103
99 value = roundTrip(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS) ); 104 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS)) ;
100 testPrimitiveValue(value, -10, CSSPrimitiveValue::CSS_EMS); 105 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_EMS);
101 } 106 }
102 107
103 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) 108 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit)
104 { 109 {
105 RefPtrWillBeRawPtr<CSSValue> value = CSSPrimitiveValue::create(-10, CSSPrimi tiveValue::CSS_EMS); 110 RefPtrWillBeRawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_PX);
106 value = interpolableValueToLength(lengthToInterpolableValue(*value).get(), V alueRangeNonNegative); 111 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1).get(), ValueRangeNonNegative);
107 testPrimitiveValue(value, 0, CSSPrimitiveValue::CSS_EMS); 112 testPrimitiveValue(value1, 0, CSSPrimitiveValue::CSS_PX);
113
114 RefPtrWillBeRawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_EMS);
115 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2).get(), ValueRangeNonNegative);
116 testPrimitiveValue(value2, 0, CSSPrimitiveValue::CSS_EMS);
108 } 117 }
109 118
110 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) 119 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits)
111 { 120 {
112 CSSLengthArray actual, expectation; 121 CSSLengthArray expectation, actual;
113 initLengthArray(expectation); 122 initLengthArray(expectation);
114 OwnPtrWillBeRawPtr<InterpolableList> list = createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10); 123 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
115 toCSSPrimitiveValue(interpolableValueToLength(list.get(), ValueRangeAll).get ())->accumulateLengthArray(expectation); 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));
126 toCSSPrimitiveValue(interpolableValueToLength(result.get(), ValueRangeAll).g et())->accumulateLengthArray(expectation);
116 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)")));
117 } 128 }
118 129
130 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithSingleValues)
131 {
132 CSSLengthArray expectation, actual;
133 initLengthArray(expectation);
134 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
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));
137 toCSSPrimitiveValue(interpolableValueToLength(result.get(), ValueRangeAll).g et())->accumulateLengthArray(expectation);
138 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)")));
139
119 } 140 }
141
142 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithMultipleValues)
143 {
144 CSSLengthArray expectation, actual;
145 initLengthArray(expectation);
146 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
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));
149 toCSSPrimitiveValue(interpolableValueToLength(result.get(), ValueRangeAll).g et())->accumulateLengthArray(expectation);
150 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(20% + 30ex + 8ch + 10vh + 7vmax)")));
151
152 }
153
154 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValue)
155 {
156 CSSLengthArray expectation, actual;
157 initLengthArray(expectation);
158 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
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));
161 toCSSPrimitiveValue(interpolableValueToLength(result.get(), ValueRangeAll).g et())->accumulateLengthArray(expectation);
162 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(0px + 10% + 10ex + 10ch + 10vh + 10vmax)")));
163 }
164
165 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues)
166 {
167 CSSLengthArray expectation, actual;
168 initLengthArray(expectation);
169 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
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));
172 toCSSPrimitiveValue(interpolableValueToLength(result.get(), ValueRangeAll).g et())->accumulateLengthArray(expectation);
173 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(0px + 10% + 0em + 10ex + 10ch + 10vh + 0vmin + 10vmax)")));
174 }
175
176 }
OLDNEW
« no previous file with comments | « Source/core/animation/LengthStyleInterpolation.cpp ('k') | Source/core/css/CSSCalculationValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698