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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 "core/animation/LengthStyleInterpolation.h" 5 #include "core/animation/LengthStyleInterpolation.h"
6 6
7 #include "core/css/CSSPrimitiveValue.h" 7 #include "core/css/CSSPrimitiveValue.h"
8 #include "core/css/StylePropertySet.h" 8 #include "core/css/StylePropertySet.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 class AnimationLengthStyleInterpolationTest : public ::testing::Test { 13 class AnimationLengthStyleInterpolationTest : public ::testing::Test {
14 protected: 14 protected:
15 static PassOwnPtr<InterpolableValue> lengthToInterpolableValue(const CSSValu e& value) 15 static PassOwnPtr<InterpolableValue> lengthToInterpolableValue(const CSSValu e& value)
16 { 16 {
17 return LengthStyleInterpolation::toInterpolableValue(value); 17 return LengthStyleInterpolation::toInterpolableValue(value);
18 } 18 }
19 19
20 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToLength(Interpolab leValue* value, InterpolationRange range) 20 static RawPtr<CSSValue> interpolableValueToLength(InterpolableValue* value, InterpolationRange range)
21 { 21 {
22 return LengthStyleInterpolation::fromInterpolableValue(*value, range); 22 return LengthStyleInterpolation::fromInterpolableValue(*value, range);
23 } 23 }
24 24
25 static PassRefPtrWillBeRawPtr<CSSValue> roundTrip(PassRefPtrWillBeRawPtr<CSS Value> value) 25 static RawPtr<CSSValue> roundTrip(RawPtr<CSSValue> value)
26 { 26 {
27 return interpolableValueToLength(lengthToInterpolableValue(*value).get() , RangeAll); 27 return interpolableValueToLength(lengthToInterpolableValue(*value).get() , RangeAll);
28 } 28 }
29 29
30 static PassOwnPtr<InterpolableList> createInterpolableLength(double a, doubl e b, double c, double d, double e, double f, double g, double h, double i, doubl e j) 30 static PassOwnPtr<InterpolableList> createInterpolableLength(double a, doubl e b, double c, double d, double e, double f, double g, double h, double i, doubl e j)
31 { 31 {
32 OwnPtr<InterpolableList> list = InterpolableList::create(10); 32 OwnPtr<InterpolableList> list = InterpolableList::create(10);
33 list->set(0, InterpolableNumber::create(a)); 33 list->set(0, InterpolableNumber::create(a));
34 list->set(1, InterpolableNumber::create(b)); 34 list->set(1, InterpolableNumber::create(b));
35 list->set(2, InterpolableNumber::create(c)); 35 list->set(2, InterpolableNumber::create(c));
(...skipping 12 matching lines...) Expand all
48 { 48 {
49 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); 49 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount);
50 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) 50 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i)
51 lengthArray.at(i) = 0; 51 lengthArray.at(i) = 0;
52 } 52 }
53 53
54 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) 54 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text)
55 { 55 {
56 CSSPrimitiveValue::CSSLengthTypeArray lengthTypeArray; 56 CSSPrimitiveValue::CSSLengthTypeArray lengthTypeArray;
57 initLengthArray(lengthArray); 57 initLengthArray(lengthArray);
58 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr opertySet::create(HTMLQuirksMode); 58 RawPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c reate(HTMLQuirksMode);
59 propertySet->setProperty(CSSPropertyLeft, text); 59 propertySet->setProperty(CSSPropertyLeft, text);
60 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge t())->accumulateLengthArray(lengthArray); 60 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge t())->accumulateLengthArray(lengthArray);
61 return lengthArray; 61 return lengthArray;
62 } 62 }
63 }; 63 };
64 64
65 #define TEST_PRIMITIVE_VALUE(ACTUAL_VALUE, EXPECTED_DOUBLE_VALUE, EXPECTED_UNIT_ TYPE) \ 65 #define TEST_PRIMITIVE_VALUE(ACTUAL_VALUE, EXPECTED_DOUBLE_VALUE, EXPECTED_UNIT_ TYPE) \
66 EXPECT_TRUE((ACTUAL_VALUE)->isPrimitiveValue()); \ 66 EXPECT_TRUE((ACTUAL_VALUE)->isPrimitiveValue()); \
67 EXPECT_EQ((EXPECTED_DOUBLE_VALUE), toCSSPrimitiveValue((ACTUAL_VALUE).get()) ->getDoubleValue()); \ 67 EXPECT_EQ((EXPECTED_DOUBLE_VALUE), toCSSPrimitiveValue((ACTUAL_VALUE).get()) ->getDoubleValue()); \
68 EXPECT_EQ((EXPECTED_UNIT_TYPE), toCSSPrimitiveValue((ACTUAL_VALUE).get())->t ypeWithCalcResolved()); 68 EXPECT_EQ((EXPECTED_UNIT_TYPE), toCSSPrimitiveValue((ACTUAL_VALUE).get())->t ypeWithCalcResolved());
69 69
70 #define EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(EXPECTED, ACTUAL) \ 70 #define EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(EXPECTED, ACTUAL) \
71 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { \ 71 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { \
72 EXPECT_EQ((EXPECTED).at(i), (ACTUAL).at(i)); \ 72 EXPECT_EQ((EXPECTED).at(i), (ACTUAL).at(i)); \
73 } 73 }
74 74
75 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength) 75 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength)
76 { 76 {
77 RefPtrWillBeRawPtr<CSSValue> value1 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Pixels)); 77 RawPtr<CSSValue> value1 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiv eValue::UnitType::Pixels));
78 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::UnitType::Pixels); 78 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::UnitType::Pixels);
79 79
80 RefPtrWillBeRawPtr<CSSValue> value2 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Percentage)); 80 RawPtr<CSSValue> value2 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiv eValue::UnitType::Percentage));
81 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::UnitType::Percentage); 81 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::UnitType::Percentage);
82 82
83 RefPtrWillBeRawPtr<CSSValue> value3 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Ems)); 83 RawPtr<CSSValue> value3 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiv eValue::UnitType::Ems));
84 TEST_PRIMITIVE_VALUE(value3, 0, CSSPrimitiveValue::UnitType::Ems); 84 TEST_PRIMITIVE_VALUE(value3, 0, CSSPrimitiveValue::UnitType::Ems);
85 } 85 }
86 86
87 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit) 87 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit)
88 { 88 {
89 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType::Pixels)); 89 RawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiv eValue::UnitType::Pixels));
90 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::UnitType::Pixels); 90 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::UnitType::Pixels);
91 91
92 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType: :Percentage)); 92 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType: :Percentage));
93 TEST_PRIMITIVE_VALUE(value, 30, CSSPrimitiveValue::UnitType::Percentage); 93 TEST_PRIMITIVE_VALUE(value, 30, CSSPrimitiveValue::UnitType::Percentage);
94 94
95 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType: :Ems)); 95 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType: :Ems));
96 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::UnitType::Ems); 96 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::UnitType::Ems);
97 } 97 }
98 98
99 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) 99 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit)
100 { 100 {
101 RefPtrWillBeRawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::UnitType::Pixels); 101 RawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrimitiveValue:: UnitType::Pixels);
102 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1).get(), RangeNonNegative); 102 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1).get(), RangeNonNegative);
103 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::UnitType::Pixels); 103 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::UnitType::Pixels);
104 104
105 RefPtrWillBeRawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::UnitType::Ems); 105 RawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrimitiveValue:: UnitType::Ems);
106 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2).get(), RangeNonNegative); 106 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2).get(), RangeNonNegative);
107 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::UnitType::Ems); 107 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::UnitType::Ems);
108 } 108 }
109 109
110 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) 110 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits)
111 { 111 {
112 CSSLengthArray expectation, actual; 112 CSSLengthArray expectation, actual;
113 initLengthArray(expectation); 113 initLengthArray(expectation);
114 OwnPtr<InterpolableList> result = InterpolableList::create(2); 114 OwnPtr<InterpolableList> result = InterpolableList::create(2);
115 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); 115 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 initLengthArray(expectation); 161 initLengthArray(expectation);
162 OwnPtr<InterpolableList> result = InterpolableList::create(2); 162 OwnPtr<InterpolableList> result = InterpolableList::create(2);
163 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); 163 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10));
164 result->set(1, createInterpolableLength(1, 1, 1, 1, 0, 1, 0, 1, 1, 1)); 164 result->set(1, createInterpolableLength(1, 1, 1, 1, 0, 1, 0, 1, 1, 1));
165 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 165 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation);
166 setLengthArray(actual, "calc(0px + 10% + 0em + 10ex + 10ch + 10vh + 0vmin + 10vmax)"); 166 setLengthArray(actual, "calc(0px + 10% + 0em + 10ex + 10ch + 10vh + 0vmin + 10vmax)");
167 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); 167 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
168 } 168 }
169 169
170 } // namespace blink 170 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698