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

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

Issue 1120003002: [Oilpan] Migrate most classes under core/animations to Oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Resize expect size of Persistent Created 5 years, 6 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 InterpolableValue* lengthToInterpolableValue(const 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 PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToLength(Interpolab leValue* value, InterpolationRange 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 PassRefPtrWillBeRawPtr<CSSValue> roundTrip(PassRefPtrWillBeRawPtr<CSS Value> value)
28 { 28 {
29 return interpolableValueToLength(lengthToInterpolableValue(*value).get() , RangeAll); 29 return interpolableValueToLength(lengthToInterpolableValue(*value), Rang eAll);
30 } 30 }
31 31
32 static void testPrimitiveValue(RefPtrWillBeRawPtr<CSSValue> value, double do ubleValue, CSSPrimitiveValue::UnitType unitType) 32 static void testPrimitiveValue(RefPtrWillBeRawPtr<CSSValue> value, double do ubleValue, CSSPrimitiveValue::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.get())->getDoubleValue( ));
36 EXPECT_EQ(unitType, toCSSPrimitiveValue(value.get())->primitiveType()); 36 EXPECT_EQ(unitType, toCSSPrimitiveValue(value.get())->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 InterpolableList* createInterpolableLength(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j)
40 { 40 {
41 OwnPtrWillBeRawPtr<InterpolableList> list = InterpolableList::create(10) ; 41 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));
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;
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 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) 63 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 RefPtrWillBeRawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_PX);
111 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1).get(), RangeNonNegative); 111 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1), Range NonNegative);
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 RefPtrWillBeRawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_EMS);
115 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2).get(), RangeNonNegative); 115 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2), Range NonNegative);
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 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, RangeAll).get())->accu mulateLengthArray(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 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, RangeAll).get())->accu mulateLengthArray(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 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, RangeAll).get())->accu mulateLengthArray(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 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, RangeAll).get())->accu mulateLengthArray(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 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, RangeAll).get())->accu mulateLengthArray(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698