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

Side by Side Diff: ui/views/animation/square_ink_drop_animation_unittest.cc

Issue 1937103003: Rename of InkDropAnimation classes to InkDropRipple. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed test_ink_drop_animation_observer.h from views.gyp and doc update. Created 4 years, 7 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_UNITTEST_H_
6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_UNITTEST_H_
7
8 #include "ui/views/animation/square_ink_drop_animation.h"
9
10 #include <memory>
11
12 #include "base/macros.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/gfx/geometry/point.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/geometry/size_f.h"
17 #include "ui/views/animation/ink_drop_animation_observer.h"
18 #include "ui/views/animation/ink_drop_state.h"
19 #include "ui/views/animation/test/square_ink_drop_animation_test_api.h"
20 #include "ui/views/animation/test/test_ink_drop_animation_observer.h"
21
22 namespace views {
23 namespace test {
24
25 namespace {
26
27 using PaintedShape = views::test::SquareInkDropAnimationTestApi::PaintedShape;
28
29 // Transforms a copy of |point| with |transform| and returns it.
30 gfx::Point TransformPoint(const gfx::Transform& transform,
31 const gfx::Point& point) {
32 gfx::Point transformed_point = point;
33 transform.TransformPoint(&transformed_point);
34 return transformed_point;
35 }
36
37 class SquareInkDropAnimationCalculateTransformsTest : public testing::Test {
38 public:
39 SquareInkDropAnimationCalculateTransformsTest();
40 ~SquareInkDropAnimationCalculateTransformsTest() override;
41
42 protected:
43 // Half the width/height of the drawn ink drop.
44 static const int kHalfDrawnSize;
45
46 // The full width/height of the drawn ink drop.
47 static const int kDrawnSize;
48
49 // The radius of the rounded rectangle corners.
50 static const int kTransformedRadius;
51
52 // Half the width/height of the transformed ink drop.
53 static const int kHalfTransformedSize;
54
55 // The full width/height of the transformed ink drop.
56 static const int kTransformedSize;
57
58 // Constant points in the drawn space that will be transformed.
59 static const gfx::Point kDrawnCenterPoint;
60 static const gfx::Point kDrawnMidLeftPoint;
61 static const gfx::Point kDrawnMidRightPoint;
62 static const gfx::Point kDrawnTopMidPoint;
63 static const gfx::Point kDrawnBottomMidPoint;
64
65 // The test target.
66 SquareInkDropAnimation ink_drop_animation_;
67
68 // Provides internal access to the test target.
69 SquareInkDropAnimationTestApi test_api_;
70
71 // The gfx::Transforms collection that is populated via the
72 // Calculate*Transforms() calls.
73 SquareInkDropAnimationTestApi::InkDropTransforms transforms_;
74
75 private:
76 DISALLOW_COPY_AND_ASSIGN(SquareInkDropAnimationCalculateTransformsTest);
77 };
78
79 const int SquareInkDropAnimationCalculateTransformsTest::kHalfDrawnSize = 5;
80 const int SquareInkDropAnimationCalculateTransformsTest::kDrawnSize =
81 2 * kHalfDrawnSize;
82
83 const int SquareInkDropAnimationCalculateTransformsTest::kTransformedRadius =
84 10;
85 const int SquareInkDropAnimationCalculateTransformsTest::kHalfTransformedSize =
86 100;
87 const int SquareInkDropAnimationCalculateTransformsTest::kTransformedSize =
88 2 * kHalfTransformedSize;
89
90 const gfx::Point
91 SquareInkDropAnimationCalculateTransformsTest::kDrawnCenterPoint =
92 gfx::Point(kHalfDrawnSize, kHalfDrawnSize);
93
94 const gfx::Point
95 SquareInkDropAnimationCalculateTransformsTest::kDrawnMidLeftPoint =
96 gfx::Point(0, kHalfDrawnSize);
97
98 const gfx::Point
99 SquareInkDropAnimationCalculateTransformsTest::kDrawnMidRightPoint =
100 gfx::Point(kDrawnSize, kHalfDrawnSize);
101
102 const gfx::Point
103 SquareInkDropAnimationCalculateTransformsTest::kDrawnTopMidPoint =
104 gfx::Point(kHalfDrawnSize, 0);
105
106 const gfx::Point
107 SquareInkDropAnimationCalculateTransformsTest::kDrawnBottomMidPoint =
108 gfx::Point(kHalfDrawnSize, kDrawnSize);
109
110 SquareInkDropAnimationCalculateTransformsTest::
111 SquareInkDropAnimationCalculateTransformsTest()
112 : ink_drop_animation_(gfx::Size(kDrawnSize, kDrawnSize),
113 2,
114 gfx::Size(kHalfDrawnSize, kHalfDrawnSize),
115 1,
116 gfx::Point(),
117 SK_ColorBLACK),
118 test_api_(&ink_drop_animation_) {}
119
120 SquareInkDropAnimationCalculateTransformsTest::
121 ~SquareInkDropAnimationCalculateTransformsTest() {}
122
123 } // namespace
124
125 TEST_F(SquareInkDropAnimationCalculateTransformsTest,
126 TransformedPointsUsingTransformsFromCalculateCircleTransforms) {
127 test_api_.CalculateCircleTransforms(
128 gfx::Size(kTransformedSize, kTransformedSize), &transforms_);
129
130 struct {
131 PaintedShape shape;
132 gfx::Point center_point;
133 gfx::Point mid_left_point;
134 gfx::Point mid_right_point;
135 gfx::Point top_mid_point;
136 gfx::Point bottom_mid_point;
137 } test_cases[] = {
138 {PaintedShape::TOP_LEFT_CIRCLE, gfx::Point(0, 0),
139 gfx::Point(-kHalfTransformedSize, 0),
140 gfx::Point(kHalfTransformedSize, 0),
141 gfx::Point(0, -kHalfTransformedSize),
142 gfx::Point(0, kHalfTransformedSize)},
143 {PaintedShape::TOP_RIGHT_CIRCLE, gfx::Point(0, 0),
144 gfx::Point(-kHalfTransformedSize, 0),
145 gfx::Point(kHalfTransformedSize, 0),
146 gfx::Point(0, -kHalfTransformedSize),
147 gfx::Point(0, kHalfTransformedSize)},
148 {PaintedShape::BOTTOM_RIGHT_CIRCLE, gfx::Point(0, 0),
149 gfx::Point(-kHalfTransformedSize, 0),
150 gfx::Point(kHalfTransformedSize, 0),
151 gfx::Point(0, -kHalfTransformedSize),
152 gfx::Point(0, kHalfTransformedSize)},
153 {PaintedShape::BOTTOM_LEFT_CIRCLE, gfx::Point(0, 0),
154 gfx::Point(-kHalfTransformedSize, 0),
155 gfx::Point(kHalfTransformedSize, 0),
156 gfx::Point(0, -kHalfTransformedSize),
157 gfx::Point(0, kHalfTransformedSize)},
158 {PaintedShape::HORIZONTAL_RECT, gfx::Point(0, 0),
159 gfx::Point(-kHalfTransformedSize, 0),
160 gfx::Point(kHalfTransformedSize, 0), gfx::Point(0, 0), gfx::Point(0, 0)},
161 {PaintedShape::VERTICAL_RECT, gfx::Point(0, 0), gfx::Point(0, 0),
162 gfx::Point(0, 0), gfx::Point(0, -kHalfTransformedSize),
163 gfx::Point(0, kHalfTransformedSize)}};
164
165 for (size_t i = 0; i < arraysize(test_cases); ++i) {
166 PaintedShape shape = test_cases[i].shape;
167 SCOPED_TRACE(testing::Message() << "i=" << i << " shape=" << shape);
168 gfx::Transform transform = transforms_[shape];
169
170 EXPECT_EQ(test_cases[i].center_point,
171 TransformPoint(transform, kDrawnCenterPoint));
172 EXPECT_EQ(test_cases[i].mid_left_point,
173 TransformPoint(transform, kDrawnMidLeftPoint));
174 EXPECT_EQ(test_cases[i].mid_right_point,
175 TransformPoint(transform, kDrawnMidRightPoint));
176 EXPECT_EQ(test_cases[i].top_mid_point,
177 TransformPoint(transform, kDrawnTopMidPoint));
178 EXPECT_EQ(test_cases[i].bottom_mid_point,
179 TransformPoint(transform, kDrawnBottomMidPoint));
180 }
181 }
182
183 TEST_F(SquareInkDropAnimationCalculateTransformsTest,
184 TransformedPointsUsingTransformsFromCalculateRectTransforms) {
185 test_api_.CalculateRectTransforms(
186 gfx::Size(kTransformedSize, kTransformedSize), kTransformedRadius,
187 &transforms_);
188
189 const int x_offset = kHalfTransformedSize - kTransformedRadius;
190 const int y_offset = kHalfTransformedSize - kTransformedRadius;
191
192 struct {
193 PaintedShape shape;
194 gfx::Point center_point;
195 gfx::Point mid_left_point;
196 gfx::Point mid_right_point;
197 gfx::Point top_mid_point;
198 gfx::Point bottom_mid_point;
199 } test_cases[] = {
200 {PaintedShape::TOP_LEFT_CIRCLE, gfx::Point(-x_offset, -y_offset),
201 gfx::Point(-kHalfTransformedSize, -y_offset),
202 gfx::Point(-x_offset + kTransformedRadius, -y_offset),
203 gfx::Point(-x_offset, -kHalfTransformedSize),
204 gfx::Point(-x_offset, -y_offset + kTransformedRadius)},
205 {PaintedShape::TOP_RIGHT_CIRCLE, gfx::Point(x_offset, -y_offset),
206 gfx::Point(x_offset - kTransformedRadius, -y_offset),
207 gfx::Point(kHalfTransformedSize, -y_offset),
208 gfx::Point(x_offset, -kHalfTransformedSize),
209 gfx::Point(x_offset, -y_offset + kTransformedRadius)},
210 {PaintedShape::BOTTOM_RIGHT_CIRCLE, gfx::Point(x_offset, y_offset),
211 gfx::Point(x_offset - kTransformedRadius, y_offset),
212 gfx::Point(kHalfTransformedSize, y_offset),
213 gfx::Point(x_offset, y_offset - kTransformedRadius),
214 gfx::Point(x_offset, kHalfTransformedSize)},
215 {PaintedShape::BOTTOM_LEFT_CIRCLE, gfx::Point(-x_offset, y_offset),
216 gfx::Point(-kHalfTransformedSize, y_offset),
217 gfx::Point(-x_offset + kTransformedRadius, y_offset),
218 gfx::Point(-x_offset, y_offset - kTransformedRadius),
219 gfx::Point(-x_offset, kHalfTransformedSize)},
220 {PaintedShape::HORIZONTAL_RECT, gfx::Point(0, 0),
221 gfx::Point(-kHalfTransformedSize, 0),
222 gfx::Point(kHalfTransformedSize, 0), gfx::Point(0, -y_offset),
223 gfx::Point(0, y_offset)},
224 {PaintedShape::VERTICAL_RECT, gfx::Point(0, 0), gfx::Point(-x_offset, 0),
225 gfx::Point(x_offset, 0), gfx::Point(0, -kHalfTransformedSize),
226 gfx::Point(0, kHalfTransformedSize)}};
227
228 for (size_t i = 0; i < arraysize(test_cases); ++i) {
229 PaintedShape shape = test_cases[i].shape;
230 SCOPED_TRACE(testing::Message() << "i=" << i << " shape=" << shape);
231 gfx::Transform transform = transforms_[shape];
232
233 EXPECT_EQ(test_cases[i].center_point,
234 TransformPoint(transform, kDrawnCenterPoint));
235 EXPECT_EQ(test_cases[i].mid_left_point,
236 TransformPoint(transform, kDrawnMidLeftPoint));
237 EXPECT_EQ(test_cases[i].mid_right_point,
238 TransformPoint(transform, kDrawnMidRightPoint));
239 EXPECT_EQ(test_cases[i].top_mid_point,
240 TransformPoint(transform, kDrawnTopMidPoint));
241 EXPECT_EQ(test_cases[i].bottom_mid_point,
242 TransformPoint(transform, kDrawnBottomMidPoint));
243 }
244 }
245
246 } // namespace test
247 } // namespace views
248
249 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_UNITTEST_H_
OLDNEW
« no previous file with comments | « ui/views/animation/square_ink_drop_animation.cc ('k') | ui/views/animation/square_ink_drop_ripple.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698