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

Side by Side Diff: ui/gfx/win/rect_util_unittest.cc

Issue 1813493002: COMPLETED PREVIEW Migrate to Display Placement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gfxmove
Patch Set: Created 4 years, 9 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
« no previous file with comments | « ui/gfx/win/rect_util.cc ('k') | ui/gfx/win/scaling_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/gfx/geometry/rect.h"
7 #include "ui/gfx/win/rect_util.h"
8
9 namespace gfx {
10 namespace win {
11
12 TEST(RectUtilTest, FindTouchingRectEdgeBottom) {
13 EXPECT_EQ(RectEdge::BOTTOM,
14 FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 2, 1, 1)));
15 }
16
17 TEST(RectUtilTest, FindTouchingRectEdgeLeft) {
18 EXPECT_EQ(RectEdge::LEFT,
19 FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(0, 1, 1, 1)));
20 }
21
22 TEST(RectUtilTest, FindTouchingRectEdgeTop) {
23 EXPECT_EQ(RectEdge::TOP,
24 FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 0, 1, 1)));
25 }
26
27 TEST(RectUtilTest, FindTouchingRectEdgeRight) {
28 EXPECT_EQ(RectEdge::RIGHT,
29 FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(2, 1, 1, 1)));
30 }
31
32 TEST(RectUtilTest, FindTouchingRectEdgeBottomRightCorner) {
33 EXPECT_EQ(RectEdge::BOTTOM,
34 FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(2, 2, 1, 1)));
35 }
36
37 TEST(RectUtilTest, FindTouchingRectEdgeBottomLeftCorner) {
38 EXPECT_EQ(RectEdge::BOTTOM,
39 FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(0, 2, 1, 1)));
40 }
41
42 TEST(RectUtilTest, FindTouchingRectEdgeUpperLeftCorner) {
43 EXPECT_EQ(RectEdge::LEFT,
44 FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(0, 0, 1, 1)));
45 }
46
47 TEST(RectUtilTest, FindTouchingRectEdgeUpperRightCorner) {
48 EXPECT_EQ(RectEdge::TOP,
49 FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(2, 0, 1, 1)));
50 }
51
52 TEST(RectUtilTest, FindTouchingRectEdgeNone) {
53 EXPECT_EQ(RectEdge::NONE,
54 FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(3, 1, 1, 1)));
55 }
56
57 TEST(RectUtilTest, ScaleAndPositionRectNoScaleRight) {
58 // Top edge aligned.
59 EXPECT_EQ(gfx::Rect(800, 0, 1024, 768),
60 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
61 gfx::Rect(0, 0, 800, 600),
62 gfx::Rect(800, 0, 1024, 768),
63 1.0f));
64 // Bottom edge aligned.
65 EXPECT_EQ(gfx::Rect(800, -168, 1024, 768),
66 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
67 gfx::Rect(0, 0, 800, 600),
68 gfx::Rect(800, -168, 1024, 768),
69 1.0f));
70 // Offset to the top.
71 EXPECT_EQ(gfx::Rect(800, -10, 1024, 768),
72 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
73 gfx::Rect(0, 0, 800, 600),
74 gfx::Rect(800, -10, 1024, 768),
75 1.0f));
76 // Offset to the bottom.
77 EXPECT_EQ(gfx::Rect(800, 10, 1024, 768),
78 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
79 gfx::Rect(0, 0, 800, 600),
80 gfx::Rect(800, 10, 1024, 768),
81 1.0f));
82
83 }
84
85 TEST(RectUtilTest, ScaleAndPositionRectNoScaleLeft) {
86 // Top edge aligned.
87 EXPECT_EQ(gfx::Rect(-1024, 0, 1024, 768),
88 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
89 gfx::Rect(0, 0, 800, 600),
90 gfx::Rect(-1024, 0, 1024, 768),
91 1.0f));
92 // Bottom edge aligned.
93 EXPECT_EQ(gfx::Rect(-1024, -168, 1024, 768),
94 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
95 gfx::Rect(0, 0, 800, 600),
96 gfx::Rect(-1024, -168, 1024, 768),
97 1.0f));
98 // Offset to the top.
99 EXPECT_EQ(gfx::Rect(-1024, -10, 1024, 768),
100 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
101 gfx::Rect(0, 0, 800, 600),
102 gfx::Rect(-1024, -10, 1024, 768),
103 1.0f));
104 // Offset to the bottom.
105 EXPECT_EQ(gfx::Rect(-1024, 10, 1024, 768),
106 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
107 gfx::Rect(0, 0, 800, 600),
108 gfx::Rect(-1024, 10, 1024, 768),
109 1.0f));
110 }
111
112 TEST(RectUtilTest, ScaleAndPositionRectNoScaleTop) {
113 // Left edge aligned.
114 EXPECT_EQ(gfx::Rect(0, -768, 1024, 768),
115 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
116 gfx::Rect(0, 0, 800, 600),
117 gfx::Rect(0, -768, 1024, 768),
118 1.0f));
119 // Right edge aligned.
120 EXPECT_EQ(gfx::Rect(-224, -768, 1024, 768),
121 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
122 gfx::Rect(0, 0, 800, 600),
123 gfx::Rect(-224, -768, 1024, 768),
124 1.0f));
125 // Offset to the right.
126 EXPECT_EQ(gfx::Rect(10, -768, 1024, 768),
127 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
128 gfx::Rect(0, 0, 800, 600),
129 gfx::Rect(10, -768, 1024, 768),
130 1.0f));
131 // Offset to the left.
132 EXPECT_EQ(gfx::Rect(-10, -768, 1024, 768),
133 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
134 gfx::Rect(0, 0, 800, 600),
135 gfx::Rect(-10, -768, 1024, 768),
136 1.0f));
137 }
138
139 TEST(RectUtilTest, ScaleAndPositionRectNoScaleBottom) {
140 // Left edge aligned.
141 EXPECT_EQ(gfx::Rect(0, 600, 1024, 768),
142 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
143 gfx::Rect(0, 0, 800, 600),
144 gfx::Rect(0, 600, 1024, 768),
145 1.0f));
146 // Right edge aligned.
147 EXPECT_EQ(gfx::Rect(-224, 600, 1024, 768),
148 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
149 gfx::Rect(0, 0, 800, 600),
150 gfx::Rect(-224, 600, 1024, 768),
151 1.0f));
152 // Offset to the right
153 EXPECT_EQ(gfx::Rect(10, 600, 1024, 768),
154 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
155 gfx::Rect(0, 0, 800, 600),
156 gfx::Rect(10, 600, 1024, 768),
157 1.0f));
158 // Offset to the left
159 EXPECT_EQ(gfx::Rect(-10, 600, 1024, 768),
160 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
161 gfx::Rect(0, 0, 800, 600),
162 gfx::Rect(-10, 600, 1024, 768),
163 1.0f));
164 }
165
166 TEST(RectUtilTest, ScaleAndPositionRectNoScaleOddDimensions) {
167 EXPECT_EQ(gfx::Rect(59, 77, 7, 9),
168 ScaleAndPositionRect(gfx::Rect(35, 72, 24, 24),
169 gfx::Rect(35, 72, 24, 24),
170 gfx::Rect(59, 77, 7, 9),
171 1.0f));
172 EXPECT_EQ(gfx::Rect(-701, 9, 702, 2),
173 ScaleAndPositionRect(gfx::Rect(1, 7, 30, 40),
174 gfx::Rect(1, 7, 30, 40),
175 gfx::Rect(-701, 9, 702, 2),
176 1.0f));
177 }
178
179 TEST(RectUtilTest, ScaleAndPositionRect1_5xScale) {
180 // Side by side to the right.
181 EXPECT_EQ(gfx::Rect(900, 50, 667, 467),
182 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
183 gfx::Rect(100, 50, 800, 600),
184 gfx::Rect(900, 50, 1000, 700),
185 1.5f));
186
187 // Side-by-side to the left.
188 EXPECT_EQ(gfx::Rect(-567, 50, 667, 467),
189 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
190 gfx::Rect(100, 50, 800, 600),
191 gfx::Rect(-900, 50, 1000, 700),
192 1.5f));
193
194 // Side-by-side to the top (note size inconsistency due to enclosing rect).
195 EXPECT_EQ(gfx::Rect(67, -418, 667, 468),
196 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
197 gfx::Rect(100, 50, 800, 600),
198 gfx::Rect(50, -650, 1000, 700),
199 1.5f));
200
201 // // Side-by-side on the bottom.
202 EXPECT_EQ(gfx::Rect(67, 650, 667, 467),
203 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
204 gfx::Rect(100, 50, 800, 600),
205 gfx::Rect(50, 650, 1000, 700),
206 1.5f));
207
208 // Side by side to the right.
209 EXPECT_EQ(gfx::Rect(500, 50, 667, 467),
210 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
211 gfx::Rect(100, 50, 800, 600),
212 gfx::Rect(900, 50, 1000, 700),
213 1.5f));
214
215 // Side-by-side to the left.
216 EXPECT_EQ(gfx::Rect(-567, 50, 667, 467),
217 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
218 gfx::Rect(100, 50, 800, 600),
219 gfx::Rect(-900, 50, 1000, 700),
220 1.5f));
221
222 // Side-by-side to the top (note size inconsistency due to enclosing rect).
223 EXPECT_EQ(gfx::Rect(67, -418, 667, 468),
224 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
225 gfx::Rect(100, 50, 800, 600),
226 gfx::Rect(50, -650, 1000, 700),
227 1.5f));
228
229
230 // Side-by-side to the bottom.
231 EXPECT_EQ(gfx::Rect(67, 350, 667, 467),
232 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
233 gfx::Rect(100, 50, 800, 600),
234 gfx::Rect(50, 650, 1000, 700),
235 1.5f));
236 }
237
238 TEST(RectUtilTest, ScaleAndPositionRect2xScale) {
239 // Side by side to the right.
240 EXPECT_EQ(gfx::Rect(900, 50, 500, 350),
241 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
242 gfx::Rect(100, 50, 800, 600),
243 gfx::Rect(900, 50, 1000, 700),
244 2.0f));
245 // Side-by-side to the left.
246 EXPECT_EQ(gfx::Rect(-400, 50, 500, 350),
247 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
248 gfx::Rect(100, 50, 800, 600),
249 gfx::Rect(-900, 50, 1000, 700),
250 2.0f));
251
252 // Side-by-side to the top.
253 EXPECT_EQ(gfx::Rect(75, -300, 500, 350),
254 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
255 gfx::Rect(100, 50, 800, 600),
256 gfx::Rect(50, -650, 1000, 700),
257 2.0f));
258
259 // Side-by-side on the bottom.
260 EXPECT_EQ(gfx::Rect(75, 650, 500, 350),
261 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
262 gfx::Rect(100, 50, 800, 600),
263 gfx::Rect(50, 650, 1000, 700),
264 2.0f));
265
266 // Side by side to the right.
267 EXPECT_EQ(gfx::Rect(500, 50, 500, 350),
268 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
269 gfx::Rect(100, 50, 800, 600),
270 gfx::Rect(900, 50, 1000, 700),
271 2.0f));
272
273 // Side-by-side to the left.
274 EXPECT_EQ(gfx::Rect(-400, 50, 500, 350),
275 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
276 gfx::Rect(100, 50, 800, 600),
277 gfx::Rect(-900, 50, 1000, 700),
278 2.0f));
279
280 // Side-by-side to the top.
281 EXPECT_EQ(gfx::Rect(75, -300, 500, 350),
282 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
283 gfx::Rect(100, 50, 800, 600),
284 gfx::Rect(50, -650, 1000, 700),
285 2.0f));
286
287
288 // Side-by-side to the bottom.
289 EXPECT_EQ(gfx::Rect(75, 350, 500, 350),
290 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
291 gfx::Rect(100, 50, 800, 600),
292 gfx::Rect(50, 650, 1000, 700),
293 2.0f));
294 }
295
296 TEST(RectUtilTest, SquaredDistanceBetweenRectsFullyIntersecting) {
297 gfx::Rect rect1(0, 0, 100, 100);
298 gfx::Rect rect2(5, 5, 10, 10);
299 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect1, rect2));
300 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect2, rect1));
301 }
302
303 TEST(RectUtilTest, SquaredDistanceBetweenRectsPartiallyIntersecting) {
304 gfx::Rect rect1(0, 0, 10, 10);
305 gfx::Rect rect2(5, 5, 10, 10);
306 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect1, rect2));
307 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect2, rect1));
308 }
309
310 TEST(RectUtilTest, SquaredDistanceBetweenRectsTouching) {
311 gfx::Rect ref(2, 2, 2, 2);
312
313 gfx::Rect top_left(0, 0, 2, 2);
314 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left));
315 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left, ref));
316 gfx::Rect top_left_partial_top(1, 0, 2, 2);
317 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left_partial_top));
318 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left_partial_top, ref));
319 gfx::Rect top(2, 0, 2, 2);
320 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top));
321 EXPECT_EQ(0, SquaredDistanceBetweenRects(top, ref));
322 gfx::Rect top_right_partial_top(3, 0, 2, 2);
323 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_right_partial_top));
324 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_right_partial_top, ref));
325 gfx::Rect top_right(4, 0, 2, 2);
326 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_right));
327 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_right, ref));
328
329 gfx::Rect top_left_partial_left(0, 1, 2, 2);
330 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left_partial_left));
331 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left_partial_left, ref));
332 gfx::Rect left(0, 2, 2, 2);
333 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, left));
334 EXPECT_EQ(0, SquaredDistanceBetweenRects(left, ref));
335 gfx::Rect bottom_left_partial(0, 3, 2, 2);
336 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, bottom_left_partial));
337 EXPECT_EQ(0, SquaredDistanceBetweenRects(bottom_left_partial, ref));
338 gfx::Rect bottom_left(0, 4, 2, 2);
339 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, bottom_left));
340 EXPECT_EQ(0, SquaredDistanceBetweenRects(bottom_left, ref));
341 }
342
343 TEST(RectUtilTest, SquaredDistanceBetweenRectsOverlapping) {
344 gfx::Rect ref(5, 5, 2, 2);
345
346 gfx::Rect top_left_partial_top(4, 0, 2, 2);
347 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_left_partial_top));
348 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_left_partial_top, ref));
349 gfx::Rect top(5, 0, 2, 2);
350 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top));
351 EXPECT_EQ(9, SquaredDistanceBetweenRects(top, ref));
352 gfx::Rect top_right_partial(6, 0, 2, 2);
353 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_right_partial));
354 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_right_partial, ref));
355
356 gfx::Rect top_left_partial_left(0, 4, 2, 2);
357 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_left_partial_left));
358 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_left_partial_left, ref));
359 gfx::Rect left(0, 5, 2, 2);
360 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, left));
361 EXPECT_EQ(9, SquaredDistanceBetweenRects(left, ref));
362 gfx::Rect bottom_left_partial(0, 6, 2, 2);
363 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, bottom_left_partial));
364 EXPECT_EQ(9, SquaredDistanceBetweenRects(bottom_left_partial, ref));
365 }
366
367 TEST(RectUtilTest, SquaredDistanceBetweenRectsDiagonals) {
368 gfx::Rect ref(5, 5, 2, 2);
369
370 gfx::Rect top_left(0, 0, 2, 2);
371 EXPECT_EQ(18, SquaredDistanceBetweenRects(ref, top_left));
372 EXPECT_EQ(18, SquaredDistanceBetweenRects(top_left, ref));
373
374 gfx::Rect top_right(10, 0, 2, 2);
375 EXPECT_EQ(18, SquaredDistanceBetweenRects(ref, top_right));
376 EXPECT_EQ(18, SquaredDistanceBetweenRects(top_right, ref));
377 }
378
379 } // namespace win
380 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/win/rect_util.cc ('k') | ui/gfx/win/scaling_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698