| 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/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 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 InterpolableList* createInterpolableLength(double a, double b, double
c, double d, double e, double f, double g, double h, double i, double j) |
| 33 { | 33 { |
| 34 OwnPtrWillBeRawPtr<InterpolableList> list = InterpolableList::create(10)
; | 34 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)); |
| 40 list->set(5, InterpolableNumber::create(f)); | 40 list->set(5, InterpolableNumber::create(f)); |
| 41 list->set(6, InterpolableNumber::create(g)); | 41 list->set(6, InterpolableNumber::create(g)); |
| 42 list->set(7, InterpolableNumber::create(h)); | 42 list->set(7, InterpolableNumber::create(h)); |
| 43 list->set(8, InterpolableNumber::create(i)); | 43 list->set(8, InterpolableNumber::create(i)); |
| 44 list->set(9, InterpolableNumber::create(j)); | 44 list->set(9, InterpolableNumber::create(j)); |
| 45 | 45 |
| 46 return list.release(); | 46 return list; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void initLengthArray(CSSLengthArray& lengthArray) | 49 void initLengthArray(CSSLengthArray& lengthArray) |
| 50 { | 50 { |
| 51 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); | 51 lengthArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); |
| 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) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType:
:Percentage)); | 94 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType:
:Percentage)); |
| 95 TEST_PRIMITIVE_VALUE(value, 30, CSSPrimitiveValue::UnitType::Percentage); | 95 TEST_PRIMITIVE_VALUE(value, 30, CSSPrimitiveValue::UnitType::Percentage); |
| 96 | 96 |
| 97 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType:
:Ems)); | 97 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType:
:Ems)); |
| 98 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::UnitType::Ems); | 98 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::UnitType::Ems); |
| 99 } | 99 } |
| 100 | 100 |
| 101 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) | 101 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) |
| 102 { | 102 { |
| 103 RefPtrWillBeRawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrim
itiveValue::UnitType::Pixels); | 103 RefPtrWillBeRawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrim
itiveValue::UnitType::Pixels); |
| 104 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1).get(),
RangeNonNegative); | 104 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1), Range
NonNegative); |
| 105 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::UnitType::Pixels); | 105 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::UnitType::Pixels); |
| 106 | 106 |
| 107 RefPtrWillBeRawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrim
itiveValue::UnitType::Ems); | 107 RefPtrWillBeRawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrim
itiveValue::UnitType::Ems); |
| 108 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2).get(),
RangeNonNegative); | 108 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2), Range
NonNegative); |
| 109 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::UnitType::Ems); | 109 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::UnitType::Ems); |
| 110 } | 110 } |
| 111 | 111 |
| 112 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) | 112 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) |
| 113 { | 113 { |
| 114 CSSLengthArray expectation, actual; | 114 CSSLengthArray expectation, actual; |
| 115 initLengthArray(expectation); | 115 initLengthArray(expectation); |
| 116 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | 116 InterpolableList* result = InterpolableList::create(2); |
| 117 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); | 117 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); |
| 118 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); | 118 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); |
| 119 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())
->accumulateLengthArray(expectation); | 119 toCSSPrimitiveValue(interpolableValueToLength(result, RangeAll).get())->accu
mulateLengthArray(expectation); |
| 120 setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"); | 120 setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"); |
| 121 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); | 121 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); |
| 122 } | 122 } |
| 123 | 123 |
| 124 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithSingleValues) | 124 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithSingleValues) |
| 125 { | 125 { |
| 126 CSSLengthArray expectation, actual; | 126 CSSLengthArray expectation, actual; |
| 127 initLengthArray(expectation); | 127 initLengthArray(expectation); |
| 128 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | 128 InterpolableList* result = InterpolableList::create(2); |
| 129 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)); |
| 130 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)); |
| 131 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())
->accumulateLengthArray(expectation); | 131 toCSSPrimitiveValue(interpolableValueToLength(result, RangeAll).get())->accu
mulateLengthArray(expectation); |
| 132 setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"); | 132 setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"); |
| 133 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); | 133 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithMultipleValues) | 136 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithMultipleValues) |
| 137 { | 137 { |
| 138 CSSLengthArray expectation, actual; | 138 CSSLengthArray expectation, actual; |
| 139 initLengthArray(expectation); | 139 initLengthArray(expectation); |
| 140 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | 140 InterpolableList* result = InterpolableList::create(2); |
| 141 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)); |
| 142 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)); |
| 143 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())
->accumulateLengthArray(expectation); | 143 toCSSPrimitiveValue(interpolableValueToLength(result, RangeAll).get())->accu
mulateLengthArray(expectation); |
| 144 setLengthArray(actual, "calc(20% + 30ex + 8ch + 10vh + 7vmax)"); | 144 setLengthArray(actual, "calc(20% + 30ex + 8ch + 10vh + 7vmax)"); |
| 145 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); | 145 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); |
| 146 } | 146 } |
| 147 | 147 |
| 148 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValue) | 148 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValue) |
| 149 { | 149 { |
| 150 CSSLengthArray expectation, actual; | 150 CSSLengthArray expectation, actual; |
| 151 initLengthArray(expectation); | 151 initLengthArray(expectation); |
| 152 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | 152 InterpolableList* result = InterpolableList::create(2); |
| 153 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)); |
| 154 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)); |
| 155 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())
->accumulateLengthArray(expectation); | 155 toCSSPrimitiveValue(interpolableValueToLength(result, RangeAll).get())->accu
mulateLengthArray(expectation); |
| 156 setLengthArray(actual, "calc(0px + 10% + 10ex + 10ch + 10vh + 10vmax)"); | 156 setLengthArray(actual, "calc(0px + 10% + 10ex + 10ch + 10vh + 10vmax)"); |
| 157 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); | 157 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); |
| 158 } | 158 } |
| 159 | 159 |
| 160 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues) | 160 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues) |
| 161 { | 161 { |
| 162 CSSLengthArray expectation, actual; | 162 CSSLengthArray expectation, actual; |
| 163 initLengthArray(expectation); | 163 initLengthArray(expectation); |
| 164 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); | 164 InterpolableList* result = InterpolableList::create(2); |
| 165 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)); |
| 166 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)); |
| 167 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get())
->accumulateLengthArray(expectation); | 167 toCSSPrimitiveValue(interpolableValueToLength(result, RangeAll).get())->accu
mulateLengthArray(expectation); |
| 168 setLengthArray(actual, "calc(0px + 10% + 0em + 10ex + 10ch + 10vh + 0vmin +
10vmax)"); | 168 setLengthArray(actual, "calc(0px + 10% + 0em + 10ex + 10ch + 10vh + 0vmin +
10vmax)"); |
| 169 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); | 169 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual); |
| 170 } | 170 } |
| 171 | 171 |
| 172 } | 172 } |
| OLD | NEW |