| 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/LengthBoxStyleInterpolation.h" | 6 #include "core/animation/LengthBoxStyleInterpolation.h" |
| 7 | 7 |
| 8 #include "core/animation/LengthStyleInterpolation.h" | 8 #include "core/animation/LengthStyleInterpolation.h" |
| 9 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
| 10 #include "core/css/Rect.h" | 10 #include "core/css/Rect.h" |
| 11 #include "core/css/StylePropertySet.h" | 11 #include "core/css/StylePropertySet.h" |
| 12 | 12 |
| 13 #include <gtest/gtest.h> | 13 #include <gtest/gtest.h> |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class AnimationLengthBoxStyleInterpolationTest : public ::testing::Test { | 17 class AnimationLengthBoxStyleInterpolationTest : public ::testing::Test { |
| 18 protected: | 18 protected: |
| 19 static PassOwnPtrWillBeRawPtr<InterpolableValue> lengthBoxToInterpolableValu
e(const CSSValue& value) | 19 static PassOwnPtrWillBeRawPtr<InterpolableValue> lengthBoxToInterpolableValu
e(const CSSValue& value) |
| 20 { | 20 { |
| 21 return LengthBoxStyleInterpolation::lengthBoxtoInterpolableValue(value,
value, false); | 21 return LengthBoxStyleInterpolation::lengthBoxtoInterpolableValue(value,
value, false); |
| 22 } | 22 } |
| 23 | 23 |
| 24 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToLengthBox(Interpo
lableValue* value, const CSSValue& start, const CSSValue& end) | 24 static CSSValue interpolableValueToLengthBox(InterpolableValue* value, const
CSSValue& start, const CSSValue& end) |
| 25 { | 25 { |
| 26 return LengthBoxStyleInterpolation::interpolableValueToLengthBox(value,
start, end); | 26 return LengthBoxStyleInterpolation::interpolableValueToLengthBox(value,
start, end); |
| 27 } | 27 } |
| 28 | 28 |
| 29 static PassRefPtrWillBeRawPtr<CSSValue> roundTrip(PassRefPtrWillBeRawPtr<CSS
Value> value) | 29 static CSSValue roundTrip(CSSValue value) |
| 30 { | 30 { |
| 31 return interpolableValueToLengthBox(lengthBoxToInterpolableValue(*value)
.get(), *value, *value); | 31 return interpolableValueToLengthBox(lengthBoxToInterpolableValue(value).
get(), value, value); |
| 32 } | 32 } |
| 33 | 33 |
| 34 static void testPrimitiveValue(RefPtrWillBeRawPtr<CSSValue> value, double le
ft, double right, double top, double bottom, CSSPrimitiveValue::UnitType unitTyp
e) | 34 static void testPrimitiveValue(CSSValue value, double left, double right, do
uble top, double bottom, CSSPrimitiveValue::UnitType unitType) |
| 35 { | 35 { |
| 36 EXPECT_TRUE(value->isPrimitiveValue()); | 36 EXPECT_TRUE(value.isPrimitiveValue()); |
| 37 Rect* rect = toCSSPrimitiveValue(value.get())->getRectValue(); | 37 Rect* rect = toCSSPrimitiveValue(value).getRectValue(); |
| 38 | 38 |
| 39 EXPECT_EQ(rect->left()->getDoubleValue(), left); | 39 EXPECT_EQ(rect->left()->getDoubleValue(), left); |
| 40 EXPECT_EQ(rect->right()->getDoubleValue(), right); | 40 EXPECT_EQ(rect->right()->getDoubleValue(), right); |
| 41 EXPECT_EQ(rect->top()->getDoubleValue(), top); | 41 EXPECT_EQ(rect->top()->getDoubleValue(), top); |
| 42 EXPECT_EQ(rect->bottom()->getDoubleValue(), bottom); | 42 EXPECT_EQ(rect->bottom()->getDoubleValue(), bottom); |
| 43 | 43 |
| 44 EXPECT_EQ(unitType, rect->left()->primitiveType()); | 44 EXPECT_EQ(unitType, rect->left()->primitiveType()); |
| 45 EXPECT_EQ(unitType, rect->right()->primitiveType()); | 45 EXPECT_EQ(unitType, rect->right()->primitiveType()); |
| 46 EXPECT_EQ(unitType, rect->top()->primitiveType()); | 46 EXPECT_EQ(unitType, rect->top()->primitiveType()); |
| 47 EXPECT_EQ(unitType, rect->bottom()->primitiveType()); | 47 EXPECT_EQ(unitType, rect->bottom()->primitiveType()); |
| 48 } | 48 } |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 TEST_F(AnimationLengthBoxStyleInterpolationTest, ZeroLengthBox) | 51 TEST_F(AnimationLengthBoxStyleInterpolationTest, ZeroLengthBox) |
| 52 { | 52 { |
| 53 RefPtrWillBeRawPtr<Rect> rectPx = Rect::create(); | 53 RefPtrWillBeRawPtr<Rect> rectPx = Rect::create(); |
| 54 rectPx->setLeft(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 54 rectPx->setLeft(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 55 rectPx->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 55 rectPx->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 56 rectPx->setTop(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 56 rectPx->setTop(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 57 rectPx->setBottom(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 57 rectPx->setBottom(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 58 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(rec
tPx.release())); | 58 CSSValue value = roundTrip(CSSPrimitiveValue::create(rectPx.release())); |
| 59 testPrimitiveValue(value, 0, 0, 0, 0, CSSPrimitiveValue::CSS_PX); | 59 testPrimitiveValue(value, 0, 0, 0, 0, CSSPrimitiveValue::CSS_PX); |
| 60 | 60 |
| 61 RefPtrWillBeRawPtr<Rect> rectEms = Rect::create(); | 61 RefPtrWillBeRawPtr<Rect> rectEms = Rect::create(); |
| 62 rectEms->setLeft(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); | 62 rectEms->setLeft(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); |
| 63 rectEms->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); | 63 rectEms->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); |
| 64 rectEms->setTop(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); | 64 rectEms->setTop(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); |
| 65 rectEms->setBottom(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS))
; | 65 rectEms->setBottom(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS))
; |
| 66 | 66 |
| 67 value = roundTrip(CSSPrimitiveValue::create(rectEms.release())); | 67 value = roundTrip(CSSPrimitiveValue::create(rectEms.release())); |
| 68 testPrimitiveValue(value, 0, 0, 0, 0, CSSPrimitiveValue::CSS_EMS); | 68 testPrimitiveValue(value, 0, 0, 0, 0, CSSPrimitiveValue::CSS_EMS); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST_F(AnimationLengthBoxStyleInterpolationTest, SingleUnitBox) | 71 TEST_F(AnimationLengthBoxStyleInterpolationTest, SingleUnitBox) |
| 72 { | 72 { |
| 73 RefPtrWillBeRawPtr<Rect> rectPx = Rect::create(); | 73 RefPtrWillBeRawPtr<Rect> rectPx = Rect::create(); |
| 74 rectPx->setLeft(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); | 74 rectPx->setLeft(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); |
| 75 rectPx->setRight(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); | 75 rectPx->setRight(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); |
| 76 rectPx->setTop(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); | 76 rectPx->setTop(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); |
| 77 rectPx->setBottom(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); | 77 rectPx->setBottom(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); |
| 78 | 78 |
| 79 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(rec
tPx.release())); | 79 CSSValue value = roundTrip(CSSPrimitiveValue::create(rectPx.release())); |
| 80 testPrimitiveValue(value, 10, 10, 10, 10, CSSPrimitiveValue::CSS_PX); | 80 testPrimitiveValue(value, 10, 10, 10, 10, CSSPrimitiveValue::CSS_PX); |
| 81 | 81 |
| 82 RefPtrWillBeRawPtr<Rect> rectPer = Rect::create(); | 82 RefPtrWillBeRawPtr<Rect> rectPer = Rect::create(); |
| 83 rectPer->setLeft(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCEN
TAGE)); | 83 rectPer->setLeft(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCEN
TAGE)); |
| 84 rectPer->setRight(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE
NTAGE)); | 84 rectPer->setRight(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE
NTAGE)); |
| 85 rectPer->setTop(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCENT
AGE)); | 85 rectPer->setTop(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCENT
AGE)); |
| 86 rectPer->setBottom(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERC
ENTAGE)); | 86 rectPer->setBottom(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERC
ENTAGE)); |
| 87 | 87 |
| 88 value = roundTrip(CSSPrimitiveValue::create(rectPer.release())); | 88 value = roundTrip(CSSPrimitiveValue::create(rectPer.release())); |
| 89 testPrimitiveValue(value, 30, 30, 30, 30, CSSPrimitiveValue::CSS_PERCENTAGE)
; | 89 testPrimitiveValue(value, 30, 30, 30, 30, CSSPrimitiveValue::CSS_PERCENTAGE)
; |
| 90 | 90 |
| 91 RefPtrWillBeRawPtr<Rect> rectEms = Rect::create(); | 91 RefPtrWillBeRawPtr<Rect> rectEms = Rect::create(); |
| 92 rectEms->setLeft(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS))
; | 92 rectEms->setLeft(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS))
; |
| 93 rectEms->setRight(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS)
); | 93 rectEms->setRight(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS)
); |
| 94 rectEms->setTop(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS)); | 94 rectEms->setTop(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS)); |
| 95 rectEms->setBottom(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS
)); | 95 rectEms->setBottom(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS
)); |
| 96 | 96 |
| 97 value = roundTrip(CSSPrimitiveValue::create(rectEms.release())); | 97 value = roundTrip(CSSPrimitiveValue::create(rectEms.release())); |
| 98 testPrimitiveValue(value, -10, -10, -10, -10, CSSPrimitiveValue::CSS_EMS); | 98 testPrimitiveValue(value, -10, -10, -10, -10, CSSPrimitiveValue::CSS_EMS); |
| 99 } | 99 } |
| 100 | 100 |
| 101 TEST_F(AnimationLengthBoxStyleInterpolationTest, MultipleValues) | 101 TEST_F(AnimationLengthBoxStyleInterpolationTest, MultipleValues) |
| 102 { | 102 { |
| 103 RefPtrWillBeRawPtr<Rect> rectPx = Rect::create(); | 103 RefPtrWillBeRawPtr<Rect> rectPx = Rect::create(); |
| 104 rectPx->setLeft(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); | 104 rectPx->setLeft(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); |
| 105 rectPx->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 105 rectPx->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 106 rectPx->setTop(CSSPrimitiveValue::create(20, CSSPrimitiveValue::CSS_PX)); | 106 rectPx->setTop(CSSPrimitiveValue::create(20, CSSPrimitiveValue::CSS_PX)); |
| 107 rectPx->setBottom(CSSPrimitiveValue::create(40, CSSPrimitiveValue::CSS_PX)); | 107 rectPx->setBottom(CSSPrimitiveValue::create(40, CSSPrimitiveValue::CSS_PX)); |
| 108 | 108 |
| 109 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(rec
tPx.release())); | 109 CSSValue value = roundTrip(CSSPrimitiveValue::create(rectPx.release())); |
| 110 testPrimitiveValue(value, 10, 0, 20, 40, CSSPrimitiveValue::CSS_PX); | 110 testPrimitiveValue(value, 10, 0, 20, 40, CSSPrimitiveValue::CSS_PX); |
| 111 | 111 |
| 112 RefPtrWillBeRawPtr<Rect> rectPer = Rect::create(); | 112 RefPtrWillBeRawPtr<Rect> rectPer = Rect::create(); |
| 113 rectPer->setLeft(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCEN
TAGE)); | 113 rectPer->setLeft(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCEN
TAGE)); |
| 114 rectPer->setRight(CSSPrimitiveValue::create(-30, CSSPrimitiveValue::CSS_PERC
ENTAGE)); | 114 rectPer->setRight(CSSPrimitiveValue::create(-30, CSSPrimitiveValue::CSS_PERC
ENTAGE)); |
| 115 rectPer->setTop(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCENT
AGE)); | 115 rectPer->setTop(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCENT
AGE)); |
| 116 rectPer->setBottom(CSSPrimitiveValue::create(-30, CSSPrimitiveValue::CSS_PER
CENTAGE)); | 116 rectPer->setBottom(CSSPrimitiveValue::create(-30, CSSPrimitiveValue::CSS_PER
CENTAGE)); |
| 117 | 117 |
| 118 value = roundTrip(CSSPrimitiveValue::create(rectPer.release())); | 118 value = roundTrip(CSSPrimitiveValue::create(rectPer.release())); |
| 119 testPrimitiveValue(value, 30, -30, 30, -30, CSSPrimitiveValue::CSS_PERCENTAG
E); | 119 testPrimitiveValue(value, 30, -30, 30, -30, CSSPrimitiveValue::CSS_PERCENTAG
E); |
| 120 } | 120 } |
| 121 | 121 |
| 122 } | 122 } |
| OLD | NEW |