| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 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 | |
| 50 static PassOwnPtrWillBeRawPtr<InterpolableValue> borderImageSliceToInterpola
bleValue(CSSValue& value) | |
| 51 { | |
| 52 return LengthBoxStyleInterpolation::borderImageSlicetoInterpolableValue(
value); | |
| 53 } | |
| 54 | |
| 55 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToBorderImageSlice(
InterpolableValue* value, bool fill) | |
| 56 { | |
| 57 return LengthBoxStyleInterpolation::interpolableValueToBorderImageSlice(
value, fill); | |
| 58 } | |
| 59 | |
| 60 static PassRefPtrWillBeRawPtr<CSSValue> roundTripBorderImageSlice(PassRefPtr
WillBeRawPtr<CSSValue> value) | |
| 61 { | |
| 62 return interpolableValueToBorderImageSlice(borderImageSliceToInterpolabl
eValue(*value).get(), toCSSBorderImageSliceValue(*value).m_fill); | |
| 63 } | |
| 64 | |
| 65 static void testPrimitiveValueBorderImageSlice(RefPtrWillBeRawPtr<CSSValue>
value, double left, double right, double top, double bottom, bool fill, | |
| 66 CSSPrimitiveValue::UnitType unitTypeLeft, CSSPrimitiveValue::UnitType un
itTypeRight, CSSPrimitiveValue::UnitType unitTypeTop, CSSPrimitiveValue::UnitTyp
e unitTypeBottom) | |
| 67 { | |
| 68 EXPECT_TRUE(value->isBorderImageSliceValue()); | |
| 69 Quad* quad = toCSSBorderImageSliceValue(value.get())->slices(); | |
| 70 | |
| 71 EXPECT_EQ(quad->left()->getDoubleValue(), left); | |
| 72 EXPECT_EQ(quad->right()->getDoubleValue(), right); | |
| 73 EXPECT_EQ(quad->top()->getDoubleValue(), top); | |
| 74 EXPECT_EQ(quad->bottom()->getDoubleValue(), bottom); | |
| 75 | |
| 76 EXPECT_EQ(unitTypeLeft, quad->left()->primitiveType()); | |
| 77 EXPECT_EQ(unitTypeRight, quad->right()->primitiveType()); | |
| 78 EXPECT_EQ(unitTypeTop, quad->top()->primitiveType()); | |
| 79 EXPECT_EQ(unitTypeBottom, quad->bottom()->primitiveType()); | |
| 80 EXPECT_EQ(fill, toCSSBorderImageSliceValue(value.get())->m_fill); | |
| 81 } | |
| 82 }; | 49 }; |
| 83 | 50 |
| 84 TEST_F(AnimationLengthBoxStyleInterpolationTest, ZeroLengthBox) | 51 TEST_F(AnimationLengthBoxStyleInterpolationTest, ZeroLengthBox) |
| 85 { | 52 { |
| 86 RefPtrWillBeRawPtr<Rect> rectPx = Rect::create(); | 53 RefPtrWillBeRawPtr<Rect> rectPx = Rect::create(); |
| 87 rectPx->setLeft(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 54 rectPx->setLeft(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 88 rectPx->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 55 rectPx->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 89 rectPx->setTop(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 56 rectPx->setTop(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 90 rectPx->setBottom(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 57 rectPx->setBottom(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 91 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(rec
tPx.release())); | 58 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(rec
tPx.release())); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 RefPtrWillBeRawPtr<Rect> rectPer = Rect::create(); | 112 RefPtrWillBeRawPtr<Rect> rectPer = Rect::create(); |
| 146 rectPer->setLeft(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCEN
TAGE)); | 113 rectPer->setLeft(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCEN
TAGE)); |
| 147 rectPer->setRight(CSSPrimitiveValue::create(-30, CSSPrimitiveValue::CSS_PERC
ENTAGE)); | 114 rectPer->setRight(CSSPrimitiveValue::create(-30, CSSPrimitiveValue::CSS_PERC
ENTAGE)); |
| 148 rectPer->setTop(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCENT
AGE)); | 115 rectPer->setTop(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCENT
AGE)); |
| 149 rectPer->setBottom(CSSPrimitiveValue::create(-30, CSSPrimitiveValue::CSS_PER
CENTAGE)); | 116 rectPer->setBottom(CSSPrimitiveValue::create(-30, CSSPrimitiveValue::CSS_PER
CENTAGE)); |
| 150 | 117 |
| 151 value = roundTrip(CSSPrimitiveValue::create(rectPer.release())); | 118 value = roundTrip(CSSPrimitiveValue::create(rectPer.release())); |
| 152 testPrimitiveValue(value, 30, -30, 30, -30, CSSPrimitiveValue::CSS_PERCENTAG
E); | 119 testPrimitiveValue(value, 30, -30, 30, -30, CSSPrimitiveValue::CSS_PERCENTAG
E); |
| 153 } | 120 } |
| 154 | 121 |
| 155 TEST_F(AnimationLengthBoxStyleInterpolationTest, ZeroBorderImageSlice) | |
| 156 { | |
| 157 RefPtrWillBeRawPtr<Quad> quad0 = Quad::create(); | |
| 158 quad0->setLeft(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); | |
| 159 quad0->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | |
| 160 quad0->setTop(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); | |
| 161 quad0->setBottom(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | |
| 162 RefPtrWillBeRawPtr<CSSValue> value0 = roundTripBorderImageSlice(CSSBorderIma
geSliceValue::create(CSSPrimitiveValue::create(quad0.release()), 0)); | |
| 163 testPrimitiveValueBorderImageSlice(value0, 0, 0, 0, 0, 0, CSSPrimitiveValue:
:CSS_EMS, CSSPrimitiveValue::CSS_PX, CSSPrimitiveValue::CSS_EMS, CSSPrimitiveVal
ue::CSS_PX); | |
| 164 | |
| 165 RefPtrWillBeRawPtr<Quad> quad1 = Quad::create(); | |
| 166 quad1->setLeft(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PERCENTAG
E)); | |
| 167 quad1->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | |
| 168 quad1->setTop(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); | |
| 169 quad1->setBottom(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | |
| 170 RefPtrWillBeRawPtr<CSSValue> value1 = roundTripBorderImageSlice(CSSBorderIma
geSliceValue::create(CSSPrimitiveValue::create(quad1.release()), 1)); | |
| 171 testPrimitiveValueBorderImageSlice(value1, 0, 0, 0, 0, 1, CSSPrimitiveValue:
:CSS_PERCENTAGE, CSSPrimitiveValue::CSS_PX, CSSPrimitiveValue::CSS_EMS, CSSPrimi
tiveValue::CSS_PX); | |
| 172 } | 122 } |
| 173 | |
| 174 TEST_F(AnimationLengthBoxStyleInterpolationTest, SingleUnitBoxAndBool) | |
| 175 { | |
| 176 RefPtrWillBeRawPtr<Quad> quad0 = Quad::create(); | |
| 177 quad0->setLeft(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS)); | |
| 178 quad0->setRight(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); | |
| 179 quad0->setTop(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS)); | |
| 180 quad0->setBottom(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PERCEN
TAGE)); | |
| 181 RefPtrWillBeRawPtr<CSSValue> value0 = roundTripBorderImageSlice(CSSBorderIma
geSliceValue::create(CSSPrimitiveValue::create(quad0.release()), 0)); | |
| 182 testPrimitiveValueBorderImageSlice(value0, 10, 10, 10, 10, 0, CSSPrimitiveVa
lue::CSS_EMS, CSSPrimitiveValue::CSS_PX, CSSPrimitiveValue::CSS_EMS, CSSPrimitiv
eValue::CSS_PERCENTAGE); | |
| 183 | |
| 184 RefPtrWillBeRawPtr<Quad> quad1 = Quad::create(); | |
| 185 quad1->setLeft(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_PERCENT
AGE)); | |
| 186 quad1->setRight(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_PX)); | |
| 187 quad1->setTop(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS)); | |
| 188 quad1->setBottom(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_PX)); | |
| 189 RefPtrWillBeRawPtr<CSSValue> value1 = roundTripBorderImageSlice(CSSBorderIma
geSliceValue::create(CSSPrimitiveValue::create(quad1.release()), 1)); | |
| 190 testPrimitiveValueBorderImageSlice(value1, 0, 0, 0, 0, 1, CSSPrimitiveValue:
:CSS_PERCENTAGE, CSSPrimitiveValue::CSS_PX, CSSPrimitiveValue::CSS_EMS, CSSPrimi
tiveValue::CSS_PX); | |
| 191 } | |
| 192 | |
| 193 TEST_F(AnimationLengthBoxStyleInterpolationTest, MultipleValuesBoxAndBool) | |
| 194 { | |
| 195 RefPtrWillBeRawPtr<Quad> quad0 = Quad::create(); | |
| 196 quad0->setLeft(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS)); | |
| 197 quad0->setRight(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PX)); | |
| 198 quad0->setTop(CSSPrimitiveValue::create(20, CSSPrimitiveValue::CSS_EMS)); | |
| 199 quad0->setBottom(CSSPrimitiveValue::create(40, CSSPrimitiveValue::CSS_PERCEN
TAGE)); | |
| 200 RefPtrWillBeRawPtr<CSSValue> value0 = roundTripBorderImageSlice(CSSBorderIma
geSliceValue::create(CSSPrimitiveValue::create(quad0.release()), 0)); | |
| 201 testPrimitiveValueBorderImageSlice(value0, 10, 30, 20, 40, 0, CSSPrimitiveVa
lue::CSS_EMS, CSSPrimitiveValue::CSS_PX, CSSPrimitiveValue::CSS_EMS, CSSPrimitiv
eValue::CSS_PERCENTAGE); | |
| 202 | |
| 203 RefPtrWillBeRawPtr<Quad> quad1 = Quad::create(); | |
| 204 quad1->setLeft(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_PERCENT
AGE)); | |
| 205 quad1->setRight(CSSPrimitiveValue::create(20, CSSPrimitiveValue::CSS_PX)); | |
| 206 quad1->setTop(CSSPrimitiveValue::create(50, CSSPrimitiveValue::CSS_EMS)); | |
| 207 quad1->setBottom(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_PX)); | |
| 208 RefPtrWillBeRawPtr<CSSValue> value1 = roundTripBorderImageSlice(CSSBorderIma
geSliceValue::create(CSSPrimitiveValue::create(quad1.release()), 1)); | |
| 209 testPrimitiveValueBorderImageSlice(value1, 0, 20, 50, 0, 1, CSSPrimitiveValu
e::CSS_PERCENTAGE, CSSPrimitiveValue::CSS_PX, CSSPrimitiveValue::CSS_EMS, CSSPri
mitiveValue::CSS_PX); | |
| 210 } | |
| 211 | |
| 212 } | |
| OLD | NEW |