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

Side by Side Diff: Source/core/animation/LengthBoxStyleInterpolationTest.cpp

Issue 1304993002: Change Rect and Quad to be CSSValues (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@split_counter_out_attempt_3
Patch Set: Created 5 years, 4 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 "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/CSSQuadValue.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 PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToLengthBox(Interpo lableValue* 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 PassRefPtrWillBeRawPtr<CSSValue> roundTrip(PassRefPtrWillBeRawPtr<CSS Value> 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 testQuadValue(RefPtrWillBeRawPtr<CSSValue> value, double left, d ouble right, double top, double bottom, CSSPrimitiveValue::UnitType unitType)
35 { 35 {
36 EXPECT_TRUE(value->isPrimitiveValue()); 36 EXPECT_TRUE(value->isQuadValue());
37 Rect* rect = toCSSPrimitiveValue(value.get())->getRectValue(); 37 RefPtrWillBeRawPtr<CSSQuadValue> rect = toCSSQuadValue(value.get());
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()->typeWithCalcResolved()); 44 EXPECT_EQ(unitType, rect->left()->typeWithCalcResolved());
45 EXPECT_EQ(unitType, rect->right()->typeWithCalcResolved()); 45 EXPECT_EQ(unitType, rect->right()->typeWithCalcResolved());
46 EXPECT_EQ(unitType, rect->top()->typeWithCalcResolved()); 46 EXPECT_EQ(unitType, rect->top()->typeWithCalcResolved());
47 EXPECT_EQ(unitType, rect->bottom()->typeWithCalcResolved()); 47 EXPECT_EQ(unitType, rect->bottom()->typeWithCalcResolved());
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<CSSPrimitiveValue> left = CSSPrimitiveValue::create(0, CS SPrimitiveValue::UnitType::Pixels);
54 rectPx->setLeft(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Pi xels)); 54 RefPtrWillBeRawPtr<CSSPrimitiveValue> right = CSSPrimitiveValue::create(0, C SSPrimitiveValue::UnitType::Pixels);
55 rectPx->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::P ixels)); 55 RefPtrWillBeRawPtr<CSSPrimitiveValue> top = CSSPrimitiveValue::create(0, CSS PrimitiveValue::UnitType::Pixels);
56 rectPx->setTop(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Pix els)); 56 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottom = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Pixels);
57 rectPx->setBottom(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType:: Pixels)); 57 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSQuadValue::createRect(top, right, bottom, left));
58 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(rec tPx.release())); 58 testQuadValue(value, 0, 0, 0, 0, CSSPrimitiveValue::UnitType::Pixels);
59 testPrimitiveValue(value, 0, 0, 0, 0, CSSPrimitiveValue::UnitType::Pixels);
60 59
61 RefPtrWillBeRawPtr<Rect> rectEms = Rect::create(); 60 RefPtrWillBeRawPtr<CSSPrimitiveValue> leftEms = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Ems);
62 rectEms->setLeft(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::E ms)); 61 RefPtrWillBeRawPtr<CSSPrimitiveValue> rightEms = CSSPrimitiveValue::create(0 , CSSPrimitiveValue::UnitType::Ems);
63 rectEms->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType:: Ems)); 62 RefPtrWillBeRawPtr<CSSPrimitiveValue> topEms = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Ems);
64 rectEms->setTop(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Em s)); 63 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottomEms = CSSPrimitiveValue::create( 0, CSSPrimitiveValue::UnitType::Ems);
65 rectEms->setBottom(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType: :Ems));
66 64
67 value = roundTrip(CSSPrimitiveValue::create(rectEms.release())); 65 value = roundTrip(CSSQuadValue::createRect(topEms, rightEms, bottomEms, left Ems));
68 testPrimitiveValue(value, 0, 0, 0, 0, CSSPrimitiveValue::UnitType::Ems); 66 testQuadValue(value, 0, 0, 0, 0, CSSPrimitiveValue::UnitType::Ems);
69 } 67 }
70 68
71 TEST_F(AnimationLengthBoxStyleInterpolationTest, SingleUnitBox) 69 TEST_F(AnimationLengthBoxStyleInterpolationTest, SingleUnitBox)
72 { 70 {
73 RefPtrWillBeRawPtr<Rect> rectPx = Rect::create(); 71 RefPtrWillBeRawPtr<CSSPrimitiveValue> leftPx = CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType::Pixels);
74 rectPx->setLeft(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType::P ixels)); 72 RefPtrWillBeRawPtr<CSSPrimitiveValue> rightPx = CSSPrimitiveValue::create(10 , CSSPrimitiveValue::UnitType::Pixels);
75 rectPx->setRight(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType:: Pixels)); 73 RefPtrWillBeRawPtr<CSSPrimitiveValue> topPx = CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType::Pixels);
76 rectPx->setTop(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType::Pi xels)); 74 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottomPx = CSSPrimitiveValue::create(1 0, CSSPrimitiveValue::UnitType::Pixels);
77 rectPx->setBottom(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType: :Pixels));
78 75
79 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(rec tPx.release())); 76 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSQuadValue::createRect(topP x, rightPx, bottomPx, leftPx));
80 testPrimitiveValue(value, 10, 10, 10, 10, CSSPrimitiveValue::UnitType::Pixel s); 77 testQuadValue(value, 10, 10, 10, 10, CSSPrimitiveValue::UnitType::Pixels);
81 78
82 RefPtrWillBeRawPtr<Rect> rectPer = Rect::create(); 79 RefPtrWillBeRawPtr<CSSPrimitiveValue> leftPer = CSSPrimitiveValue::create(30 , CSSPrimitiveValue::UnitType::Percentage);
83 rectPer->setLeft(CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType:: Percentage)); 80 RefPtrWillBeRawPtr<CSSPrimitiveValue> rightPer = CSSPrimitiveValue::create(3 0, CSSPrimitiveValue::UnitType::Percentage);
84 rectPer->setRight(CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType: :Percentage)); 81 RefPtrWillBeRawPtr<CSSPrimitiveValue> topPer = CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType::Percentage);
85 rectPer->setTop(CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType::P ercentage)); 82 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottomPer = CSSPrimitiveValue::create( 30, CSSPrimitiveValue::UnitType::Percentage);
86 rectPer->setBottom(CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType ::Percentage));
87 83
88 value = roundTrip(CSSPrimitiveValue::create(rectPer.release())); 84 value = roundTrip(CSSQuadValue::createRect(topPer, rightPer, bottomPer, left Per));
89 testPrimitiveValue(value, 30, 30, 30, 30, CSSPrimitiveValue::UnitType::Perce ntage); 85 testQuadValue(value, 30, 30, 30, 30, CSSPrimitiveValue::UnitType::Percentage );
90 86
91 RefPtrWillBeRawPtr<Rect> rectEms = Rect::create(); 87 RefPtrWillBeRawPtr<CSSPrimitiveValue> leftEms = CSSPrimitiveValue::create(-1 0, CSSPrimitiveValue::UnitType::Ems);
92 rectEms->setLeft(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::UnitType: :Ems)); 88 RefPtrWillBeRawPtr<CSSPrimitiveValue> rightEms = CSSPrimitiveValue::create(- 10, CSSPrimitiveValue::UnitType::Ems);
93 rectEms->setRight(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::UnitType ::Ems)); 89 RefPtrWillBeRawPtr<CSSPrimitiveValue> topEms = CSSPrimitiveValue::create(-10 , CSSPrimitiveValue::UnitType::Ems);
94 rectEms->setTop(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::UnitType:: Ems)); 90 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottomEms = CSSPrimitiveValue::create( -10, CSSPrimitiveValue::UnitType::Ems);
95 rectEms->setBottom(CSSPrimitiveValue::create(-10, CSSPrimitiveValue::UnitTyp e::Ems));
96 91
97 value = roundTrip(CSSPrimitiveValue::create(rectEms.release())); 92 value = roundTrip(CSSQuadValue::createRect(topEms, rightEms, bottomEms, left Ems));
98 testPrimitiveValue(value, -10, -10, -10, -10, CSSPrimitiveValue::UnitType::E ms); 93 testQuadValue(value, -10, -10, -10, -10, CSSPrimitiveValue::UnitType::Ems);
99 } 94 }
100 95
101 TEST_F(AnimationLengthBoxStyleInterpolationTest, MultipleValues) 96 TEST_F(AnimationLengthBoxStyleInterpolationTest, MultipleValues)
102 { 97 {
103 RefPtrWillBeRawPtr<Rect> rectPx = Rect::create(); 98 RefPtrWillBeRawPtr<CSSPrimitiveValue> leftPx = CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType::Pixels);
104 rectPx->setLeft(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType::P ixels)); 99 RefPtrWillBeRawPtr<CSSPrimitiveValue> rightPx = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Pixels);
105 rectPx->setRight(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::P ixels)); 100 RefPtrWillBeRawPtr<CSSPrimitiveValue> topPx = CSSPrimitiveValue::create(20, CSSPrimitiveValue::UnitType::Pixels);
106 rectPx->setTop(CSSPrimitiveValue::create(20, CSSPrimitiveValue::UnitType::Pi xels)); 101 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottomPx = CSSPrimitiveValue::create(4 0, CSSPrimitiveValue::UnitType::Pixels);
107 rectPx->setBottom(CSSPrimitiveValue::create(40, CSSPrimitiveValue::UnitType: :Pixels));
108 102
109 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(rec tPx.release())); 103 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSQuadValue::createRect(topP x, rightPx, bottomPx, leftPx));
110 testPrimitiveValue(value, 10, 0, 20, 40, CSSPrimitiveValue::UnitType::Pixels ); 104 testQuadValue(value, 10, 0, 20, 40, CSSPrimitiveValue::UnitType::Pixels);
111 105
112 RefPtrWillBeRawPtr<Rect> rectPer = Rect::create(); 106 RefPtrWillBeRawPtr<CSSPrimitiveValue> leftPer = CSSPrimitiveValue::create(30 , CSSPrimitiveValue::UnitType::Percentage);
113 rectPer->setLeft(CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType:: Percentage)); 107 RefPtrWillBeRawPtr<CSSPrimitiveValue> rightPer = CSSPrimitiveValue::create(- 30, CSSPrimitiveValue::UnitType::Percentage);
114 rectPer->setRight(CSSPrimitiveValue::create(-30, CSSPrimitiveValue::UnitType ::Percentage)); 108 RefPtrWillBeRawPtr<CSSPrimitiveValue> topPer = CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType::Percentage);
115 rectPer->setTop(CSSPrimitiveValue::create(30, CSSPrimitiveValue::UnitType::P ercentage)); 109 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottomPer = CSSPrimitiveValue::create( -30, CSSPrimitiveValue::UnitType::Percentage);
116 rectPer->setBottom(CSSPrimitiveValue::create(-30, CSSPrimitiveValue::UnitTyp e::Percentage));
117 110
118 value = roundTrip(CSSPrimitiveValue::create(rectPer.release())); 111 value = roundTrip(CSSQuadValue::createRect(topPer, rightPer, bottomPer, left Per));
119 testPrimitiveValue(value, 30, -30, 30, -30, CSSPrimitiveValue::UnitType::Per centage); 112 testQuadValue(value, 30, -30, 30, -30, CSSPrimitiveValue::UnitType::Percenta ge);
120 } 113 }
121 114
122 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698