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

Side by Side Diff: cc/keyframed_animation_curve_unittest.cc

Issue 11644004: Only create instances of WebTransformOperations using cc::TransformOperations::Create (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase, and fix WebTransformAnimationCurveImpl Created 8 years 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "cc/keyframed_animation_curve.h" 5 #include "cc/keyframed_animation_curve.h"
6 6
7 #include "cc/transform_operations.h"
7 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformOperati ons.h" 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformOperati ons.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa trix.h" 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa trix.h"
11 12
12 using WebKit::WebTransformationMatrix; 13 using WebKit::WebTransformationMatrix;
13 14
14 namespace cc { 15 namespace cc {
15 namespace { 16 namespace {
16 17
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 EXPECT_FLOAT_EQ(6, curve->getValue(1.5)); 81 EXPECT_FLOAT_EQ(6, curve->getValue(1.5));
81 EXPECT_FLOAT_EQ(6, curve->getValue(2)); 82 EXPECT_FLOAT_EQ(6, curve->getValue(2));
82 EXPECT_FLOAT_EQ(6, curve->getValue(3)); 83 EXPECT_FLOAT_EQ(6, curve->getValue(3));
83 } 84 }
84 85
85 86
86 // Tests that a transform animation with one keyframe works as expected. 87 // Tests that a transform animation with one keyframe works as expected.
87 TEST(KeyframedAnimationCurveTest, OneTransformKeyframe) 88 TEST(KeyframedAnimationCurveTest, OneTransformKeyframe)
88 { 89 {
89 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create()); 90 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create());
90 WebKit::WebTransformOperations operations; 91 scoped_ptr<WebKit::WebTransformOperations> operations(
91 operations.appendTranslate(2, 0, 0); 92 TransformOperations::Create());
92 curve->addKeyframe(TransformKeyframe::create(0, operations, scoped_ptr<Timin gFunction>())); 93 operations->appendTranslate(2, 0, 0);
94 curve->addKeyframe(TransformKeyframe::create(0, *operations, scoped_ptr<Timi ngFunction>()));
93 95
94 expectTranslateX(2, curve->getValue(-1)); 96 expectTranslateX(2, curve->getValue(-1));
95 expectTranslateX(2, curve->getValue(0)); 97 expectTranslateX(2, curve->getValue(0));
96 expectTranslateX(2, curve->getValue(0.5)); 98 expectTranslateX(2, curve->getValue(0.5));
97 expectTranslateX(2, curve->getValue(1)); 99 expectTranslateX(2, curve->getValue(1));
98 expectTranslateX(2, curve->getValue(2)); 100 expectTranslateX(2, curve->getValue(2));
99 } 101 }
100 102
101 // Tests that a transform animation with two keyframes works as expected. 103 // Tests that a transform animation with two keyframes works as expected.
102 TEST(KeyframedAnimationCurveTest, TwoTransformKeyframe) 104 TEST(KeyframedAnimationCurveTest, TwoTransformKeyframe)
103 { 105 {
104 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create()); 106 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create());
105 WebKit::WebTransformOperations operations1; 107 scoped_ptr<WebKit::WebTransformOperations> operations1(
106 operations1.appendTranslate(2, 0, 0); 108 TransformOperations::Create());
107 WebKit::WebTransformOperations operations2; 109 operations1->appendTranslate(2, 0, 0);
108 operations2.appendTranslate(4, 0, 0); 110 scoped_ptr<WebKit::WebTransformOperations> operations2(
111 TransformOperations::Create());
112 operations2->appendTranslate(4, 0, 0);
109 113
110 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi ngFunction>())); 114 curve->addKeyframe(TransformKeyframe::create(0, *operations1, scoped_ptr<Tim ingFunction>()));
111 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi ngFunction>())); 115 curve->addKeyframe(TransformKeyframe::create(1, *operations2, scoped_ptr<Tim ingFunction>()));
112 expectTranslateX(2, curve->getValue(-1)); 116 expectTranslateX(2, curve->getValue(-1));
113 expectTranslateX(2, curve->getValue(0)); 117 expectTranslateX(2, curve->getValue(0));
114 expectTranslateX(3, curve->getValue(0.5)); 118 expectTranslateX(3, curve->getValue(0.5));
115 expectTranslateX(4, curve->getValue(1)); 119 expectTranslateX(4, curve->getValue(1));
116 expectTranslateX(4, curve->getValue(2)); 120 expectTranslateX(4, curve->getValue(2));
117 } 121 }
118 122
119 // Tests that a transform animation with three keyframes works as expected. 123 // Tests that a transform animation with three keyframes works as expected.
120 TEST(KeyframedAnimationCurveTest, ThreeTransformKeyframe) 124 TEST(KeyframedAnimationCurveTest, ThreeTransformKeyframe)
121 { 125 {
122 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create()); 126 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create());
123 WebKit::WebTransformOperations operations1; 127 scoped_ptr<WebKit::WebTransformOperations> operations1(
124 operations1.appendTranslate(2, 0, 0); 128 TransformOperations::Create());
125 WebKit::WebTransformOperations operations2; 129 operations1->appendTranslate(2, 0, 0);
126 operations2.appendTranslate(4, 0, 0); 130 scoped_ptr<WebKit::WebTransformOperations> operations2(
127 WebKit::WebTransformOperations operations3; 131 TransformOperations::Create());
128 operations3.appendTranslate(8, 0, 0); 132 operations2->appendTranslate(4, 0, 0);
129 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi ngFunction>())); 133 scoped_ptr<WebKit::WebTransformOperations> operations3(
130 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi ngFunction>())); 134 TransformOperations::Create());
131 curve->addKeyframe(TransformKeyframe::create(2, operations3, scoped_ptr<Timi ngFunction>())); 135 operations3->appendTranslate(8, 0, 0);
136 curve->addKeyframe(TransformKeyframe::create(0, *operations1, scoped_ptr<Tim ingFunction>()));
137 curve->addKeyframe(TransformKeyframe::create(1, *operations2, scoped_ptr<Tim ingFunction>()));
138 curve->addKeyframe(TransformKeyframe::create(2, *operations3, scoped_ptr<Tim ingFunction>()));
132 expectTranslateX(2, curve->getValue(-1)); 139 expectTranslateX(2, curve->getValue(-1));
133 expectTranslateX(2, curve->getValue(0)); 140 expectTranslateX(2, curve->getValue(0));
134 expectTranslateX(3, curve->getValue(0.5)); 141 expectTranslateX(3, curve->getValue(0.5));
135 expectTranslateX(4, curve->getValue(1)); 142 expectTranslateX(4, curve->getValue(1));
136 expectTranslateX(6, curve->getValue(1.5)); 143 expectTranslateX(6, curve->getValue(1.5));
137 expectTranslateX(8, curve->getValue(2)); 144 expectTranslateX(8, curve->getValue(2));
138 expectTranslateX(8, curve->getValue(3)); 145 expectTranslateX(8, curve->getValue(3));
139 } 146 }
140 147
141 // Tests that a transform animation with multiple keys at a given time works san ely. 148 // Tests that a transform animation with multiple keys at a given time works san ely.
142 TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes) 149 TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes)
143 { 150 {
144 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create()); 151 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create());
145 // A step function. 152 // A step function.
146 WebKit::WebTransformOperations operations1; 153 scoped_ptr<WebKit::WebTransformOperations> operations1(
147 operations1.appendTranslate(4, 0, 0); 154 TransformOperations::Create());
148 WebKit::WebTransformOperations operations2; 155 operations1->appendTranslate(4, 0, 0);
149 operations2.appendTranslate(4, 0, 0); 156 scoped_ptr<WebKit::WebTransformOperations> operations2(
150 WebKit::WebTransformOperations operations3; 157 TransformOperations::Create());
151 operations3.appendTranslate(6, 0, 0); 158 operations2->appendTranslate(4, 0, 0);
152 WebKit::WebTransformOperations operations4; 159 scoped_ptr<WebKit::WebTransformOperations> operations3(
153 operations4.appendTranslate(6, 0, 0); 160 TransformOperations::Create());
154 curve->addKeyframe(TransformKeyframe::create(0, operations1, scoped_ptr<Timi ngFunction>())); 161 operations3->appendTranslate(6, 0, 0);
155 curve->addKeyframe(TransformKeyframe::create(1, operations2, scoped_ptr<Timi ngFunction>())); 162 scoped_ptr<WebKit::WebTransformOperations> operations4(
156 curve->addKeyframe(TransformKeyframe::create(1, operations3, scoped_ptr<Timi ngFunction>())); 163 TransformOperations::Create());
157 curve->addKeyframe(TransformKeyframe::create(2, operations4, scoped_ptr<Timi ngFunction>())); 164 operations4->appendTranslate(6, 0, 0);
165 curve->addKeyframe(TransformKeyframe::create(0, *operations1, scoped_ptr<Tim ingFunction>()));
166 curve->addKeyframe(TransformKeyframe::create(1, *operations2, scoped_ptr<Tim ingFunction>()));
167 curve->addKeyframe(TransformKeyframe::create(1, *operations3, scoped_ptr<Tim ingFunction>()));
168 curve->addKeyframe(TransformKeyframe::create(2, *operations4, scoped_ptr<Tim ingFunction>()));
158 169
159 expectTranslateX(4, curve->getValue(-1)); 170 expectTranslateX(4, curve->getValue(-1));
160 expectTranslateX(4, curve->getValue(0)); 171 expectTranslateX(4, curve->getValue(0));
161 expectTranslateX(4, curve->getValue(0.5)); 172 expectTranslateX(4, curve->getValue(0.5));
162 173
163 // There is a discontinuity at 1. Any value between 4 and 6 is valid. 174 // There is a discontinuity at 1. Any value between 4 and 6 is valid.
164 WebTransformationMatrix value = curve->getValue(1); 175 WebTransformationMatrix value = curve->getValue(1);
165 EXPECT_TRUE(value.m41() >= 4 && value.m41() <= 6); 176 EXPECT_TRUE(value.m41() >= 4 && value.m41() <= 6);
166 177
167 expectTranslateX(6, curve->getValue(1.5)); 178 expectTranslateX(6, curve->getValue(1.5));
(...skipping 28 matching lines...) Expand all
196 EXPECT_LT(0, curve->getValue(0.25)); 207 EXPECT_LT(0, curve->getValue(0.25));
197 EXPECT_GT(0.25, curve->getValue(0.25)); 208 EXPECT_GT(0.25, curve->getValue(0.25));
198 EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015); 209 EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015);
199 EXPECT_LT(0.75, curve->getValue(0.75)); 210 EXPECT_LT(0.75, curve->getValue(0.75));
200 EXPECT_GT(1, curve->getValue(0.75)); 211 EXPECT_GT(1, curve->getValue(0.75));
201 EXPECT_FLOAT_EQ(1, curve->getValue(1)); 212 EXPECT_FLOAT_EQ(1, curve->getValue(1));
202 } 213 }
203 214
204 } // namespace 215 } // namespace
205 } // namespace cc 216 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698