| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "core/animation/AnimatableLength.h" | 33 #include "core/animation/AnimatableLength.h" |
| 34 | 34 |
| 35 #include "core/animation/AnimatableValueTestHelper.h" | 35 #include "core/animation/AnimatableValueTestHelper.h" |
| 36 #include "core/css/CSSCalculationValue.h" | 36 #include "core/css/CSSCalculationValue.h" |
| 37 #include "core/css/CSSPrimitiveValue.h" | 37 #include "core/css/CSSPrimitiveValue.h" |
| 38 #include "core/css/CSSToLengthConversionData.h" |
| 38 #include "core/rendering/style/RenderStyle.h" | 39 #include "core/rendering/style/RenderStyle.h" |
| 39 #include "core/rendering/style/StyleInheritedData.h" | 40 #include "core/rendering/style/StyleInheritedData.h" |
| 40 #include "platform/CalculationValue.h" | 41 #include "platform/CalculationValue.h" |
| 41 #include "wtf/MathExtras.h" | 42 #include "wtf/MathExtras.h" |
| 42 | 43 |
| 43 #include <gtest/gtest.h> | 44 #include <gtest/gtest.h> |
| 44 | 45 |
| 45 #define EXPECT_ROUNDTRIP(a, f) EXPECT_REFV_EQ(a, f(a.get())) | 46 #define EXPECT_ROUNDTRIP(a, f) EXPECT_REFV_EQ(a, f(a.get())) |
| 46 | 47 |
| 47 namespace WebCore { | 48 namespace WebCore { |
| 48 | 49 |
| 49 class AnimationAnimatableLengthTest : public ::testing::Test { | 50 class AnimationAnimatableLengthTest : public ::testing::Test { |
| 50 protected: | 51 protected: |
| 51 virtual void SetUp() | 52 AnimationAnimatableLengthTest() |
| 53 : style(RenderStyle::createDefaultStyle()) |
| 54 , conversionDataZoom1(style.get(), style.get(), 1.0f) |
| 55 , conversionDataZoom3(style.get(), style.get(), 3.0f) |
| 52 { | 56 { |
| 53 style = RenderStyle::createDefaultStyle(); | |
| 54 } | 57 } |
| 55 | 58 |
| 56 PassRefPtr<AnimatableLength> create(double value, CSSPrimitiveValue::UnitTyp
es type) | 59 PassRefPtr<AnimatableLength> create(double value, CSSPrimitiveValue::UnitTyp
es type) |
| 57 { | 60 { |
| 58 return AnimatableLength::create(CSSPrimitiveValue::create(value, type).g
et()); | 61 return AnimatableLength::create(CSSPrimitiveValue::create(value, type).g
et()); |
| 59 } | 62 } |
| 60 | 63 |
| 61 PassRefPtr<AnimatableLength> create(double valueLeft, CSSPrimitiveValue::Uni
tTypes typeLeft, double valueRight, CSSPrimitiveValue::UnitTypes typeRight) | 64 PassRefPtr<AnimatableLength> create(double valueLeft, CSSPrimitiveValue::Uni
tTypes typeLeft, double valueRight, CSSPrimitiveValue::UnitTypes typeRight) |
| 62 { | 65 { |
| 63 return AnimatableLength::create(createCalc(valueLeft, typeLeft, valueRig
ht, typeRight).get()); | 66 return AnimatableLength::create(createCalc(valueLeft, typeLeft, valueRig
ht, typeRight).get()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 81 { | 84 { |
| 82 return a->commonUnitType(b.get()); | 85 return a->commonUnitType(b.get()); |
| 83 } | 86 } |
| 84 | 87 |
| 85 bool isUnitlessZero(PassRefPtr<AnimatableLength> a) | 88 bool isUnitlessZero(PassRefPtr<AnimatableLength> a) |
| 86 { | 89 { |
| 87 return a->isUnitlessZero(); | 90 return a->isUnitlessZero(); |
| 88 } | 91 } |
| 89 | 92 |
| 90 RefPtr<RenderStyle> style; | 93 RefPtr<RenderStyle> style; |
| 94 CSSToLengthConversionData conversionDataZoom1; |
| 95 CSSToLengthConversionData conversionDataZoom3; |
| 91 }; | 96 }; |
| 92 | 97 |
| 93 TEST_F(AnimationAnimatableLengthTest, CanCreateFrom) | 98 TEST_F(AnimationAnimatableLengthTest, CanCreateFrom) |
| 94 { | 99 { |
| 95 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_PX).get())); | 100 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_PX).get())); |
| 96 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_CM).get())); | 101 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_CM).get())); |
| 97 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_MM).get())); | 102 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_MM).get())); |
| 98 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_IN).get())); | 103 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_IN).get())); |
| 99 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_PT).get())); | 104 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_PT).get())); |
| 100 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_PC).get())); | 105 EXPECT_TRUE(AnimatableLength::canCreateFrom(CSSPrimitiveValue::create(5, CSS
PrimitiveValue::CSS_PC).get())); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 EXPECT_ROUNDTRIP(CSSPrimitiveValue::create(-5, CSSPrimitiveValue::CSS_VMIN),
toCSSValue); | 162 EXPECT_ROUNDTRIP(CSSPrimitiveValue::create(-5, CSSPrimitiveValue::CSS_VMIN),
toCSSValue); |
| 158 EXPECT_ROUNDTRIP(CSSPrimitiveValue::create(-5, CSSPrimitiveValue::CSS_VMAX),
toCSSValue); | 163 EXPECT_ROUNDTRIP(CSSPrimitiveValue::create(-5, CSSPrimitiveValue::CSS_VMAX),
toCSSValue); |
| 159 | 164 |
| 160 EXPECT_ROUNDTRIP(CSSPrimitiveValue::create(createCalc(3, CSSPrimitiveValue::
CSS_PX, 5, CSSPrimitiveValue::CSS_IN)), toCSSValue); | 165 EXPECT_ROUNDTRIP(CSSPrimitiveValue::create(createCalc(3, CSSPrimitiveValue::
CSS_PX, 5, CSSPrimitiveValue::CSS_IN)), toCSSValue); |
| 161 EXPECT_ROUNDTRIP(CSSPrimitiveValue::create(createCalc(3, CSSPrimitiveValue::
CSS_PX, 5, CSSPrimitiveValue::CSS_IN)), toCSSValue); | 166 EXPECT_ROUNDTRIP(CSSPrimitiveValue::create(createCalc(3, CSSPrimitiveValue::
CSS_PX, 5, CSSPrimitiveValue::CSS_IN)), toCSSValue); |
| 162 } | 167 } |
| 163 | 168 |
| 164 | 169 |
| 165 TEST_F(AnimationAnimatableLengthTest, ToLength) | 170 TEST_F(AnimationAnimatableLengthTest, ToLength) |
| 166 { | 171 { |
| 167 EXPECT_EQ(Length(-5, WebCore::Fixed), create(-5, CSSPrimitiveValue::CSS_PX)-
>toLength(style.get(), style.get(), 1)); | 172 EXPECT_EQ(Length(-5, WebCore::Fixed), create(-5, CSSPrimitiveValue::CSS_PX)-
>toLength(conversionDataZoom1)); |
| 168 EXPECT_EQ(Length(-15, WebCore::Fixed), create(-5, CSSPrimitiveValue::CSS_PX)
->toLength(style.get(), style.get(), 3)); | 173 EXPECT_EQ(Length(-15, WebCore::Fixed), create(-5, CSSPrimitiveValue::CSS_PX)
->toLength(conversionDataZoom3)); |
| 169 EXPECT_EQ(Length(0, WebCore::Fixed), create(-5, CSSPrimitiveValue::CSS_PX)->
toLength(style.get(), style.get(), 1, NonNegativeValues)); | 174 EXPECT_EQ(Length(0, WebCore::Fixed), create(-5, CSSPrimitiveValue::CSS_PX)->
toLength(conversionDataZoom1, NonNegativeValues)); |
| 170 EXPECT_EQ(Length(0, WebCore::Fixed), create(-5, CSSPrimitiveValue::CSS_PX)->
toLength(style.get(), style.get(), 3, NonNegativeValues)); | 175 EXPECT_EQ(Length(0, WebCore::Fixed), create(-5, CSSPrimitiveValue::CSS_PX)->
toLength(conversionDataZoom3, NonNegativeValues)); |
| 171 | 176 |
| 172 EXPECT_EQ(Length(-5, Percent), create(-5, CSSPrimitiveValue::CSS_PERCENTAGE)
->toLength(style.get(), style.get(), 1)); | 177 EXPECT_EQ(Length(-5, Percent), create(-5, CSSPrimitiveValue::CSS_PERCENTAGE)
->toLength(conversionDataZoom1)); |
| 173 EXPECT_EQ(Length(-5, Percent), create(-5, CSSPrimitiveValue::CSS_PERCENTAGE)
->toLength(style.get(), style.get(), 3)); | 178 EXPECT_EQ(Length(-5, Percent), create(-5, CSSPrimitiveValue::CSS_PERCENTAGE)
->toLength(conversionDataZoom3)); |
| 174 EXPECT_EQ(Length(0, Percent), create(-5, CSSPrimitiveValue::CSS_PERCENTAGE)-
>toLength(style.get(), style.get(), 1, NonNegativeValues)); | 179 EXPECT_EQ(Length(0, Percent), create(-5, CSSPrimitiveValue::CSS_PERCENTAGE)-
>toLength(conversionDataZoom1, NonNegativeValues)); |
| 175 EXPECT_EQ(Length(0, Percent), create(-5, CSSPrimitiveValue::CSS_PERCENTAGE)-
>toLength(style.get(), style.get(), 3, NonNegativeValues)); | 180 EXPECT_EQ(Length(0, Percent), create(-5, CSSPrimitiveValue::CSS_PERCENTAGE)-
>toLength(conversionDataZoom3, NonNegativeValues)); |
| 176 | 181 |
| 177 EXPECT_EQ( | 182 EXPECT_EQ( |
| 178 Length(CalculationValue::create( | 183 Length(CalculationValue::create( |
| 179 adoptPtr(new CalcExpressionBinaryOperation( | 184 adoptPtr(new CalcExpressionBinaryOperation( |
| 180 adoptPtr(new CalcExpressionLength(Length(-5, WebCore::Fixed))), | 185 adoptPtr(new CalcExpressionLength(Length(-5, WebCore::Fixed))), |
| 181 adoptPtr(new CalcExpressionLength(Length(-5, Percent))), | 186 adoptPtr(new CalcExpressionLength(Length(-5, Percent))), |
| 182 CalcAdd)), | 187 CalcAdd)), |
| 183 ValueRangeAll)), | 188 ValueRangeAll)), |
| 184 create(-5, CSSPrimitiveValue::CSS_PX, -5, CSSPrimitiveValue::CSS_PERCENT
AGE)->toLength(style.get(), style.get(), 1)); | 189 create(-5, CSSPrimitiveValue::CSS_PX, -5, CSSPrimitiveValue::CSS_PERCENT
AGE)->toLength(conversionDataZoom1)); |
| 185 EXPECT_EQ( | 190 EXPECT_EQ( |
| 186 Length(CalculationValue::create( | 191 Length(CalculationValue::create( |
| 187 adoptPtr(new CalcExpressionBinaryOperation( | 192 adoptPtr(new CalcExpressionBinaryOperation( |
| 188 adoptPtr(new CalcExpressionLength(Length(-15, WebCore::Fixed))), | 193 adoptPtr(new CalcExpressionLength(Length(-15, WebCore::Fixed))), |
| 189 adoptPtr(new CalcExpressionLength(Length(-5, Percent))), | 194 adoptPtr(new CalcExpressionLength(Length(-5, Percent))), |
| 190 CalcAdd)), | 195 CalcAdd)), |
| 191 ValueRangeAll)), | 196 ValueRangeAll)), |
| 192 create(-5, CSSPrimitiveValue::CSS_PX, -5, CSSPrimitiveValue::CSS_PERCENT
AGE)->toLength(style.get(), style.get(), 3)); | 197 create(-5, CSSPrimitiveValue::CSS_PX, -5, CSSPrimitiveValue::CSS_PERCENT
AGE)->toLength(conversionDataZoom3)); |
| 193 EXPECT_EQ( | 198 EXPECT_EQ( |
| 194 Length(CalculationValue::create( | 199 Length(CalculationValue::create( |
| 195 adoptPtr(new CalcExpressionBinaryOperation( | 200 adoptPtr(new CalcExpressionBinaryOperation( |
| 196 adoptPtr(new CalcExpressionLength(Length(-5, WebCore::Fixed))), | 201 adoptPtr(new CalcExpressionLength(Length(-5, WebCore::Fixed))), |
| 197 adoptPtr(new CalcExpressionLength(Length(-5, Percent))), | 202 adoptPtr(new CalcExpressionLength(Length(-5, Percent))), |
| 198 CalcAdd)), | 203 CalcAdd)), |
| 199 ValueRangeNonNegative)), | 204 ValueRangeNonNegative)), |
| 200 create(-5, CSSPrimitiveValue::CSS_PX, -5, CSSPrimitiveValue::CSS_PERCENT
AGE)->toLength(style.get(), style.get(), 1, NonNegativeValues)); | 205 create(-5, CSSPrimitiveValue::CSS_PX, -5, CSSPrimitiveValue::CSS_PERCENT
AGE)->toLength(conversionDataZoom1, NonNegativeValues)); |
| 201 EXPECT_EQ( | 206 EXPECT_EQ( |
| 202 Length(CalculationValue::create( | 207 Length(CalculationValue::create( |
| 203 adoptPtr(new CalcExpressionBinaryOperation( | 208 adoptPtr(new CalcExpressionBinaryOperation( |
| 204 adoptPtr(new CalcExpressionLength(Length(-15, WebCore::Fixed))), | 209 adoptPtr(new CalcExpressionLength(Length(-15, WebCore::Fixed))), |
| 205 adoptPtr(new CalcExpressionLength(Length(-5, Percent))), | 210 adoptPtr(new CalcExpressionLength(Length(-5, Percent))), |
| 206 CalcAdd)), | 211 CalcAdd)), |
| 207 ValueRangeNonNegative)), | 212 ValueRangeNonNegative)), |
| 208 create(-5, CSSPrimitiveValue::CSS_PX, -5, CSSPrimitiveValue::CSS_PERCENT
AGE)->toLength(style.get(), style.get(), 3, NonNegativeValues)); | 213 create(-5, CSSPrimitiveValue::CSS_PX, -5, CSSPrimitiveValue::CSS_PERCENT
AGE)->toLength(conversionDataZoom3, NonNegativeValues)); |
| 209 } | 214 } |
| 210 | 215 |
| 211 TEST_F(AnimationAnimatableLengthTest, Interpolate) | 216 TEST_F(AnimationAnimatableLengthTest, Interpolate) |
| 212 { | 217 { |
| 213 RefPtr<AnimatableLength> from10px = create(10, CSSPrimitiveValue::CSS_PX); | 218 RefPtr<AnimatableLength> from10px = create(10, CSSPrimitiveValue::CSS_PX); |
| 214 RefPtr<AnimatableLength> to20pxAsInches = create(20.0 / 96, CSSPrimitiveValu
e::CSS_IN); | 219 RefPtr<AnimatableLength> to20pxAsInches = create(20.0 / 96, CSSPrimitiveValu
e::CSS_IN); |
| 215 | 220 |
| 216 EXPECT_REFV_EQ(create(5, CSSPrimitiveValue::CSS_PX), | 221 EXPECT_REFV_EQ(create(5, CSSPrimitiveValue::CSS_PX), |
| 217 AnimatableValue::interpolate(from10px.get(), to20pxAsInches.get(), -0.5)
); | 222 AnimatableValue::interpolate(from10px.get(), to20pxAsInches.get(), -0.5)
); |
| 218 | 223 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 358 |
| 354 RefPtr<AnimatableLength> lengthCalc = create(3, CSSPrimitiveValue::CSS_PX, 5
, CSSPrimitiveValue::CSS_CM); | 359 RefPtr<AnimatableLength> lengthCalc = create(3, CSSPrimitiveValue::CSS_PX, 5
, CSSPrimitiveValue::CSS_CM); |
| 355 EXPECT_EQ(AnimatableLength::UnitTypeCalc, commonUnitType(lengthCalc, create(
1, CSSPrimitiveValue::CSS_PX).get())); | 360 EXPECT_EQ(AnimatableLength::UnitTypeCalc, commonUnitType(lengthCalc, create(
1, CSSPrimitiveValue::CSS_PX).get())); |
| 356 EXPECT_EQ(AnimatableLength::UnitTypeCalc, commonUnitType(lengthCalc, create(
2, CSSPrimitiveValue::CSS_PERCENTAGE).get())); | 361 EXPECT_EQ(AnimatableLength::UnitTypeCalc, commonUnitType(lengthCalc, create(
2, CSSPrimitiveValue::CSS_PERCENTAGE).get())); |
| 357 EXPECT_EQ(AnimatableLength::UnitTypeCalc, commonUnitType(lengthCalc, create(
3, CSSPrimitiveValue::CSS_EMS).get())); | 362 EXPECT_EQ(AnimatableLength::UnitTypeCalc, commonUnitType(lengthCalc, create(
3, CSSPrimitiveValue::CSS_EMS).get())); |
| 358 EXPECT_EQ(AnimatableLength::UnitTypeCalc, commonUnitType(lengthCalc, create(
4, CSSPrimitiveValue::CSS_PX, 5, CSSPrimitiveValue::CSS_CM).get())); | 363 EXPECT_EQ(AnimatableLength::UnitTypeCalc, commonUnitType(lengthCalc, create(
4, CSSPrimitiveValue::CSS_PX, 5, CSSPrimitiveValue::CSS_CM).get())); |
| 359 EXPECT_EQ(AnimatableLength::UnitTypeCalc, commonUnitType(lengthCalc, create(
0, CSSPrimitiveValue::CSS_PERCENTAGE).get())); | 364 EXPECT_EQ(AnimatableLength::UnitTypeCalc, commonUnitType(lengthCalc, create(
0, CSSPrimitiveValue::CSS_PERCENTAGE).get())); |
| 360 } | 365 } |
| 361 | 366 |
| 362 } // namespace WebCore | 367 } // namespace WebCore |
| OLD | NEW |