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

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

Issue 1164573002: CSSValue Immediates: Change CSSValue to an object instead of a pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 5 years, 4 months 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
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 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) 32 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)
33 { 33 {
34 OwnPtrWillBeRawPtr<InterpolableList> list = InterpolableList::create(10) ; 34 OwnPtrWillBeRawPtr<InterpolableList> list = InterpolableList::create(10) ;
35 list->set(0, InterpolableNumber::create(a)); 35 list->set(0, InterpolableNumber::create(a));
36 list->set(1, InterpolableNumber::create(b)); 36 list->set(1, InterpolableNumber::create(b));
37 list->set(2, InterpolableNumber::create(c)); 37 list->set(2, InterpolableNumber::create(c));
38 list->set(3, InterpolableNumber::create(d)); 38 list->set(3, InterpolableNumber::create(d));
39 list->set(4, InterpolableNumber::create(e)); 39 list->set(4, InterpolableNumber::create(e));
(...skipping 12 matching lines...) Expand all
52 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) 52 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i)
53 lengthArray.at(i) = 0; 53 lengthArray.at(i) = 0;
54 } 54 }
55 55
56 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) 56 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text)
57 { 57 {
58 CSSPrimitiveValue::CSSLengthTypeArray lengthTypeArray; 58 CSSPrimitiveValue::CSSLengthTypeArray lengthTypeArray;
59 initLengthArray(lengthArray); 59 initLengthArray(lengthArray);
60 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr opertySet::create(); 60 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr opertySet::create();
61 propertySet->setProperty(CSSPropertyLeft, text); 61 propertySet->setProperty(CSSPropertyLeft, text);
62 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge t())->accumulateLengthArray(lengthArray); 62 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft))-> accumulateLengthArray(lengthArray);
63 return lengthArray; 63 return lengthArray;
64 } 64 }
65 }; 65 };
66 66
67 #define TEST_PRIMITIVE_VALUE(ACTUAL_VALUE, EXPECTED_DOUBLE_VALUE, EXPECTED_UNIT_ TYPE) \ 67 #define TEST_PRIMITIVE_VALUE(ACTUAL_VALUE, EXPECTED_DOUBLE_VALUE, EXPECTED_UNIT_ TYPE) \
68 EXPECT_TRUE((ACTUAL_VALUE)->isPrimitiveValue()); \ 68 EXPECT_TRUE((ACTUAL_VALUE).isPrimitiveValue()); \
69 EXPECT_EQ((EXPECTED_DOUBLE_VALUE), toCSSPrimitiveValue((ACTUAL_VALUE).get()) ->getDoubleValue()); \ 69 EXPECT_EQ((EXPECTED_DOUBLE_VALUE), toCSSPrimitiveValue((ACTUAL_VALUE)).getDouble Value()); \
70 EXPECT_EQ((EXPECTED_UNIT_TYPE), toCSSPrimitiveValue((ACTUAL_VALUE).get())->p rimitiveType()); 70 EXPECT_EQ((EXPECTED_UNIT_TYPE), toCSSPrimitiveValue((ACTUAL_VALUE)).primitiveTyp e());
71 71
72 #define EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(EXPECTED, ACTUAL) \ 72 #define EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(EXPECTED, ACTUAL) \
73 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) \ 73 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) \
74 EXPECT_EQ((EXPECTED).at(i), (ACTUAL).at(i)) 74 EXPECT_EQ((EXPECTED).at(i), (ACTUAL).at(i));
75 75
76 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength) 76 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength)
77 { 77 {
78 RefPtrWillBeRawPtr<CSSValue> value1 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); 78 CSSValue value1 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue:: CSS_PX));
79 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::CSS_PX); 79 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::CSS_PX);
80 80
81 RefPtrWillBeRawPtr<CSSValue> value2 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PERCENTAGE)); 81 CSSValue value2 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue:: CSS_PERCENTAGE));
82 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::CSS_PERCENTAGE); 82 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::CSS_PERCENTAGE);
83 83
84 RefPtrWillBeRawPtr<CSSValue> value3 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); 84 CSSValue value3 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue:: CSS_EMS));
85 TEST_PRIMITIVE_VALUE(value3, 0, CSSPrimitiveValue::CSS_EMS); 85 TEST_PRIMITIVE_VALUE(value3, 0, CSSPrimitiveValue::CSS_EMS);
86 } 86 }
87 87
88 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit) 88 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit)
89 { 89 {
90 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); 90 CSSValue value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue:: CSS_PX));
91 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::CSS_PX); 91 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::CSS_PX);
92 92
93 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE NTAGE)); 93 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE NTAGE));
94 TEST_PRIMITIVE_VALUE(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE); 94 TEST_PRIMITIVE_VALUE(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE);
95 95
96 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS)) ; 96 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS)) ;
97 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::CSS_EMS); 97 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::CSS_EMS);
98 } 98 }
99 99
100 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) 100 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit)
101 { 101 {
102 RefPtrWillBeRawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_PX); 102 CSSValue value1 = CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_PX);
103 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1).get(), RangeNonNegative); 103 value1 = interpolableValueToLength(lengthToInterpolableValue(value1).get(), RangeNonNegative);
104 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::CSS_PX); 104 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::CSS_PX);
105 105
106 RefPtrWillBeRawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_EMS); 106 CSSValue value2 = CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS) ;
107 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2).get(), RangeNonNegative); 107 value2 = interpolableValueToLength(lengthToInterpolableValue(value2).get(), RangeNonNegative);
108 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::CSS_EMS); 108 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::CSS_EMS);
109 } 109 }
110 110
111 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) 111 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits)
112 { 112 {
113 CSSLengthArray expectation, actual; 113 CSSLengthArray expectation, actual;
114 initLengthArray(expectation); 114 initLengthArray(expectation);
115 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); 115 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
116 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); 116 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10));
117 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); 117 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1));
118 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 118 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll)).accum ulateLengthArray(expectation);
119 setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"); 119 setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)");
120
120 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); 121 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
121 } 122 }
122 123
123 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithSingleValues) 124 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithSingleValues)
124 { 125 {
125 CSSLengthArray expectation, actual; 126 CSSLengthArray expectation, actual;
126 initLengthArray(expectation); 127 initLengthArray(expectation);
127 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); 128 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
128 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); 129 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10));
129 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); 130 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1));
130 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 131 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll)).accum ulateLengthArray(expectation);
131 setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"); 132 setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)");
132 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); 133 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
133 } 134 }
134 135
135 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithMultipleValues) 136 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithMultipleValues)
136 { 137 {
137 CSSLengthArray expectation, actual; 138 CSSLengthArray expectation, actual;
138 initLengthArray(expectation); 139 initLengthArray(expectation);
139 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); 140 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
140 result->set(0, createInterpolableLength(0, 20, 0, 30, 0, 8, 0, 10, 0, 7)); 141 result->set(0, createInterpolableLength(0, 20, 0, 30, 0, 8, 0, 10, 0, 7));
141 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); 142 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1));
142 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 143 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll)).accum ulateLengthArray(expectation);
143 setLengthArray(actual, "calc(20% + 30ex + 8ch + 10vh + 7vmax)"); 144 setLengthArray(actual, "calc(20% + 30ex + 8ch + 10vh + 7vmax)");
144 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); 145 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
145 } 146 }
146 147
147 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValue) 148 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValue)
148 { 149 {
149 CSSLengthArray expectation, actual; 150 CSSLengthArray expectation, actual;
150 initLengthArray(expectation); 151 initLengthArray(expectation);
151 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); 152 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
152 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); 153 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10));
153 result->set(1, createInterpolableLength(1, 1, 0, 1, 0, 1, 0, 1, 0, 1)); 154 result->set(1, createInterpolableLength(1, 1, 0, 1, 0, 1, 0, 1, 0, 1));
154 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 155 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll)).accum ulateLengthArray(expectation);
155 setLengthArray(actual, "calc(0px + 10% + 10ex + 10ch + 10vh + 10vmax)"); 156 setLengthArray(actual, "calc(0px + 10% + 10ex + 10ch + 10vh + 10vmax)");
156 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); 157 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
157 } 158 }
158 159
159 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues) 160 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues)
160 { 161 {
161 CSSLengthArray expectation, actual; 162 CSSLengthArray expectation, actual;
162 initLengthArray(expectation); 163 initLengthArray(expectation);
163 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); 164 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
164 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); 165 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10));
165 result->set(1, createInterpolableLength(1, 1, 1, 1, 0, 1, 0, 1, 1, 1)); 166 result->set(1, createInterpolableLength(1, 1, 1, 1, 0, 1, 0, 1, 1, 1));
166 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 167 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll)).accum ulateLengthArray(expectation);
167 setLengthArray(actual, "calc(0px + 10% + 0em + 10ex + 10ch + 10vh + 0vmin + 10vmax)"); 168 setLengthArray(actual, "calc(0px + 10% + 0em + 10ex + 10ch + 10vh + 0vmin + 10vmax)");
168 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); 169 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
169 } 170 }
170 171
171 } 172 }
OLDNEW
« no previous file with comments | « Source/core/animation/LengthStyleInterpolation.cpp ('k') | Source/core/animation/ListStyleInterpolation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698