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

Side by Side Diff: ui/gfx/win/scaling_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/scaling_util.cc ('k') | ui/gfx/win/screen_win_display.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 "base/memory/scoped_ptr.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/geometry/rect.h"
8 #include "ui/gfx/test/screen_util_win.h"
9 #include "ui/gfx/win/scaling_util.h"
10
11 namespace gfx {
12 namespace win {
13
14 namespace {
15
16 const wchar_t kFakeDisplayName[] = L"Fake Display";
17
18 gfx::win::DisplayInfo CreateDisplayInfo(int x, int y, int width, int height,
19 float scale_factor) {
20 MONITORINFOEX monitor_info = gfx::test::CreateMonitorInfo(
21 gfx::Rect(x, y, width, height),
22 gfx::Rect(x, y, width, height),
23 kFakeDisplayName);
24 return gfx::win::DisplayInfo(monitor_info, scale_factor);
25 }
26
27 ::testing::AssertionResult AssertOffsetsEqual(
28 const char* lhs_expr,
29 const char* rhs_expr,
30 const gfx::DisplayPlacement& lhs,
31 const gfx::DisplayPlacement& rhs) {
32 if (lhs.position == rhs.position &&
33 lhs.offset == rhs.offset &&
34 lhs.offset_reference == rhs.offset_reference) {
35 return ::testing::AssertionSuccess();
36 }
37
38 return ::testing::AssertionFailure() <<
39 "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString() <<
40 "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString();
41 }
42
43 #define EXPECT_OFFSET_EQ(a, b) \
44 EXPECT_PRED_FORMAT2(AssertOffsetsEqual, a, b);
45
46 } // namespace
47
48 TEST(ScalingUtilTest, DisplayInfosTouchBottom) {
49 EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
50 CreateDisplayInfo(1, 2, 1, 1, 1.0f)));
51 }
52
53 TEST(ScalingUtilTest, DisplayInfosTouchLeft) {
54 EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
55 CreateDisplayInfo(0, 1, 1, 1, 1.0f)));
56 }
57
58 TEST(ScalingUtilTest, DisplayInfosTouchTop) {
59 EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
60 CreateDisplayInfo(1, 0, 1, 1, 1.0f)));
61 }
62
63 TEST(ScalingUtilTest, DisplayInfosTouchRight) {
64 EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
65 CreateDisplayInfo(2, 1, 1, 1, 1.0f)));
66 }
67
68 TEST(ScalingUtilTest, DisplayInfosTouchBottomRightCorner) {
69 EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
70 CreateDisplayInfo(2, 2, 1, 1, 1.0f)));
71 }
72
73 TEST(ScalingUtilTest, DisplayInfosTouchBottomLeftCorner) {
74 EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
75 CreateDisplayInfo(0, 2, 1, 1, 1.0f)));
76 }
77
78 TEST(ScalingUtilTest, DisplayInfosTouchUpperLeftCorner) {
79 EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
80 CreateDisplayInfo(0, 0, 1, 1, 1.0f)));
81 }
82
83 TEST(ScalingUtilTest, DisplayInfosTouchUpperRightCorner) {
84 EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
85 CreateDisplayInfo(2, 0, 1, 1, 1.0f)));
86 }
87
88 TEST(ScalingUtilTest, DisplayInfosTouchNone) {
89 EXPECT_FALSE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
90 CreateDisplayInfo(3, 1, 1, 1, 1.0f)));
91 }
92
93 TEST(ScalingUtilTest, CalculateDisplayPlacementNoScaleRight) {
94 // Top edge aligned.
95 EXPECT_OFFSET_EQ(
96 gfx::DisplayPlacement(gfx::DisplayPlacement::RIGHT,
97 0,
98 gfx::DisplayPlacement::TOP_LEFT),
99 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
100 CreateDisplayInfo(800, 0, 1024, 768, 1.0f)));
101
102 // Bottom edge aligned.
103 EXPECT_OFFSET_EQ(
104 gfx::DisplayPlacement(gfx::DisplayPlacement::RIGHT,
105 0,
106 gfx::DisplayPlacement::BOTTOM_RIGHT),
107 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
108 CreateDisplayInfo(800, -168, 1024, 768, 1.0f)));
109
110 // Offset to the top
111 EXPECT_OFFSET_EQ(
112 gfx::DisplayPlacement(gfx::DisplayPlacement::RIGHT,
113 -10,
114 gfx::DisplayPlacement::TOP_LEFT),
115 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
116 CreateDisplayInfo(800, -10, 1024, 768, 1.0f)));
117
118 // Offset to the bottom.
119 EXPECT_OFFSET_EQ(
120 gfx::DisplayPlacement(gfx::DisplayPlacement::RIGHT,
121 10,
122 gfx::DisplayPlacement::TOP_LEFT),
123 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
124 CreateDisplayInfo(800, 10, 1024, 768, 1.0f)));
125 }
126
127 TEST(ScalingUtilTest, CalculateDisplayPlacementNoScaleLeft) {
128 // Top edge aligned.
129 EXPECT_OFFSET_EQ(
130 gfx::DisplayPlacement(gfx::DisplayPlacement::LEFT,
131 0,
132 gfx::DisplayPlacement::TOP_LEFT),
133 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
134 CreateDisplayInfo(-1024, 0, 1024, 768, 1.0f)));
135
136 // Bottom edge aligned.
137 EXPECT_OFFSET_EQ(
138 gfx::DisplayPlacement(gfx::DisplayPlacement::LEFT,
139 0,
140 gfx::DisplayPlacement::BOTTOM_RIGHT),
141 CalculateDisplayPlacement(
142 CreateDisplayInfo(0, 0, 800, 600, 1.0f),
143 CreateDisplayInfo(-1024, -168, 1024, 768, 1.0f)));
144
145 // Offset to the top.
146 EXPECT_OFFSET_EQ(
147 gfx::DisplayPlacement(gfx::DisplayPlacement::LEFT,
148 -10,
149 gfx::DisplayPlacement::TOP_LEFT),
150 CalculateDisplayPlacement(
151 CreateDisplayInfo(0, 0, 800, 600, 1.0f),
152 CreateDisplayInfo(-1024, -10, 1024, 768, 1.0f)));
153
154 // Offset to the bottom.
155 EXPECT_OFFSET_EQ(
156 gfx::DisplayPlacement(gfx::DisplayPlacement::LEFT,
157 10,
158 gfx::DisplayPlacement::TOP_LEFT),
159 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
160 CreateDisplayInfo(-1024, 10, 1024, 768, 1.0f)));
161 }
162
163 TEST(ScalingUtilTest, CalculateDisplayPlacementNoScaleTop) {
164 // Left edge aligned.
165 EXPECT_OFFSET_EQ(
166 gfx::DisplayPlacement(gfx::DisplayPlacement::TOP,
167 0,
168 gfx::DisplayPlacement::TOP_LEFT),
169 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
170 CreateDisplayInfo(0, -768, 1024, 768, 1.0f)));
171
172 // Right edge aligned.
173 EXPECT_OFFSET_EQ(
174 gfx::DisplayPlacement(gfx::DisplayPlacement::TOP,
175 0,
176 gfx::DisplayPlacement::BOTTOM_RIGHT),
177 CalculateDisplayPlacement(
178 CreateDisplayInfo(0, 0, 800, 600, 1.0f),
179 CreateDisplayInfo(-224, -768, 1024, 768, 1.0f)));
180
181 // Offset to the right.
182 EXPECT_OFFSET_EQ(
183 gfx::DisplayPlacement(gfx::DisplayPlacement::TOP,
184 10,
185 gfx::DisplayPlacement::TOP_LEFT),
186 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
187 CreateDisplayInfo(10, -768, 1024, 768, 1.0f)));
188
189 // Offset to the left.
190 EXPECT_OFFSET_EQ(
191 gfx::DisplayPlacement(gfx::DisplayPlacement::TOP,
192 -10,
193 gfx::DisplayPlacement::TOP_LEFT),
194 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
195 CreateDisplayInfo(-10, -768, 1024, 768, 1.0f)));
196 }
197
198 TEST(ScalingUtilTest, CalculateDisplayPlacementNoScaleBottom) {
199 // Left edge aligned.
200 EXPECT_OFFSET_EQ(
201 gfx::DisplayPlacement(gfx::DisplayPlacement::BOTTOM,
202 0,
203 gfx::DisplayPlacement::TOP_LEFT),
204 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
205 CreateDisplayInfo(0, 600, 1024, 768, 1.0f)));
206
207 // Right edge aligned.
208 EXPECT_OFFSET_EQ(
209 gfx::DisplayPlacement(gfx::DisplayPlacement::BOTTOM,
210 0,
211 gfx::DisplayPlacement::BOTTOM_RIGHT),
212 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
213 CreateDisplayInfo(-224, 600, 1024, 768, 1.0f)));
214
215 // Offset to the right
216 EXPECT_OFFSET_EQ(
217 gfx::DisplayPlacement(gfx::DisplayPlacement::BOTTOM,
218 10,
219 gfx::DisplayPlacement::TOP_LEFT),
220 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
221 CreateDisplayInfo(10, 600, 1024, 768, 1.0f)));
222
223 // Offset to the left
224 EXPECT_OFFSET_EQ(
225 gfx::DisplayPlacement(gfx::DisplayPlacement::BOTTOM,
226 -10,
227 gfx::DisplayPlacement::TOP_LEFT),
228 CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
229 CreateDisplayInfo(-10, 600, 1024, 768, 1.0f)));
230 }
231
232 TEST(ScalingUtilTest, CalculateDisplayPlacementNoScaleOddDimensions) {
233 EXPECT_OFFSET_EQ(
234 gfx::DisplayPlacement(gfx::DisplayPlacement::RIGHT,
235 5,
236 gfx::DisplayPlacement::TOP_LEFT),
237 CalculateDisplayPlacement(CreateDisplayInfo(35, 72, 24, 24, 1.0f),
238 CreateDisplayInfo(59, 77, 7, 9, 1.0f)));
239
240 EXPECT_OFFSET_EQ(
241 gfx::DisplayPlacement(gfx::DisplayPlacement::LEFT,
242 2,
243 gfx::DisplayPlacement::TOP_LEFT),
244 CalculateDisplayPlacement(CreateDisplayInfo(1, 7, 30, 40, 1.0f),
245 CreateDisplayInfo(-701, 9, 702, 2, 1.0f)));
246 }
247
248 TEST(ScalingUtilTest, CalculateDisplayPlacement1_5xScale) {
249 // Side by side to the right.
250 EXPECT_OFFSET_EQ(
251 gfx::DisplayPlacement(gfx::DisplayPlacement::RIGHT,
252 0,
253 gfx::DisplayPlacement::TOP_LEFT),
254 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
255 CreateDisplayInfo(900, 50, 1000, 700, 1.5f)));
256
257 // Side-by-side to the left.
258 EXPECT_OFFSET_EQ(
259 gfx::DisplayPlacement(gfx::DisplayPlacement::LEFT,
260 0,
261 gfx::DisplayPlacement::TOP_LEFT),
262 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
263 CreateDisplayInfo(-900, 50, 1000, 700, 1.5f)));
264
265 // Side-by-side to the top.
266 // Note that -33 would be the normal enclosing rect offset.
267 EXPECT_OFFSET_EQ(
268 gfx::DisplayPlacement(gfx::DisplayPlacement::TOP,
269 -34,
270 gfx::DisplayPlacement::TOP_LEFT),
271 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
272 CreateDisplayInfo(50, -650, 1000, 700, 1.5f)));
273
274 // Side-by-side on the bottom.
275 // Note that -33 would be the normal enclosing rect offset.
276 EXPECT_OFFSET_EQ(
277 gfx::DisplayPlacement(gfx::DisplayPlacement::BOTTOM,
278 -34,
279 gfx::DisplayPlacement::TOP_LEFT),
280 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
281 CreateDisplayInfo(50, 650, 1000, 700, 1.5f)));
282
283 // Side by side to the right.
284 EXPECT_OFFSET_EQ(
285 gfx::DisplayPlacement(gfx::DisplayPlacement::RIGHT,
286 0,
287 gfx::DisplayPlacement::TOP_LEFT),
288 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
289 CreateDisplayInfo(900, 50, 1000, 700, 1.5f)));
290
291 // Side-by-side to the left.
292 EXPECT_OFFSET_EQ(
293 gfx::DisplayPlacement(gfx::DisplayPlacement::LEFT,
294 0,
295 gfx::DisplayPlacement::TOP_LEFT),
296 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
297 CreateDisplayInfo(-900, 50, 1000, 700, 1.5f)));
298
299 // Side-by-side to the top.
300 // Note that -33 would be the normal enclosing rect offset.
301 EXPECT_OFFSET_EQ(
302 gfx::DisplayPlacement(gfx::DisplayPlacement::TOP,
303 -34,
304 gfx::DisplayPlacement::TOP_LEFT),
305 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
306 CreateDisplayInfo(50, -650, 1000, 700, 1.5f)));
307
308
309 // Side-by-side to the bottom.
310 // Note that -33 would be the normal enclosing rect offset.
311 EXPECT_OFFSET_EQ(
312 gfx::DisplayPlacement(gfx::DisplayPlacement::BOTTOM,
313 -34,
314 gfx::DisplayPlacement::TOP_LEFT),
315 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
316 CreateDisplayInfo(50, 650, 1000, 700, 1.5f)));
317 }
318
319 TEST(ScalingUtilTest, CalculateDisplayPlacement2xScale) {
320 // Side by side to the right.
321 EXPECT_OFFSET_EQ(
322 gfx::DisplayPlacement(gfx::DisplayPlacement::RIGHT,
323 0,
324 gfx::DisplayPlacement::TOP_LEFT),
325 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
326 CreateDisplayInfo(900, 50, 1000, 700, 2.0f)));
327
328 // Side-by-side to the left.
329 EXPECT_OFFSET_EQ(
330 gfx::DisplayPlacement(gfx::DisplayPlacement::LEFT,
331 0,
332 gfx::DisplayPlacement::TOP_LEFT),
333 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
334 CreateDisplayInfo(-900, 50, 1000, 700, 2.0f)));
335
336 // Side-by-side to the top.
337 EXPECT_OFFSET_EQ(
338 gfx::DisplayPlacement(gfx::DisplayPlacement::TOP,
339 -25,
340 gfx::DisplayPlacement::TOP_LEFT),
341 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
342 CreateDisplayInfo(50, -650, 1000, 700, 2.0f)));
343
344 // Side-by-side on the bottom.
345 EXPECT_OFFSET_EQ(
346 gfx::DisplayPlacement(gfx::DisplayPlacement::BOTTOM,
347 -25,
348 gfx::DisplayPlacement::TOP_LEFT),
349 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
350 CreateDisplayInfo(50, 650, 1000, 700, 2.0f)));
351
352 // Side by side to the right.
353 EXPECT_OFFSET_EQ(
354 gfx::DisplayPlacement(gfx::DisplayPlacement::RIGHT,
355 0,
356 gfx::DisplayPlacement::TOP_LEFT),
357 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
358 CreateDisplayInfo(900, 50, 1000, 700, 2.0f)));
359
360 // Side-by-side to the left.
361 EXPECT_OFFSET_EQ(
362 gfx::DisplayPlacement(gfx::DisplayPlacement::LEFT,
363 0,
364 gfx::DisplayPlacement::TOP_LEFT),
365 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
366 CreateDisplayInfo(-900, 50, 1000, 700, 2.0f)));
367
368 // Side-by-side to the top.
369 EXPECT_OFFSET_EQ(
370 gfx::DisplayPlacement(gfx::DisplayPlacement::TOP,
371 -25,
372 gfx::DisplayPlacement::TOP_LEFT),
373 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
374 CreateDisplayInfo(50, -650, 1000, 700, 2.0f)));
375
376
377 // Side-by-side to the bottom.
378 EXPECT_OFFSET_EQ(
379 gfx::DisplayPlacement(gfx::DisplayPlacement::BOTTOM,
380 -25,
381 gfx::DisplayPlacement::TOP_LEFT),
382 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
383 CreateDisplayInfo(50, 650, 1000, 700, 2.0f)));
384 }
385
386 TEST(ScalingUtilTest, SquaredDistanceBetweenRectsFullyIntersecting) {
387 gfx::Rect rect1(0, 0, 100, 100);
388 gfx::Rect rect2(5, 5, 10, 10);
389 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect1, rect2));
390 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect2, rect1));
391 }
392
393 TEST(ScalingUtilTest, SquaredDistanceBetweenRectsPartiallyIntersecting) {
394 gfx::Rect rect1(0, 0, 10, 10);
395 gfx::Rect rect2(5, 5, 10, 10);
396 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect1, rect2));
397 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect2, rect1));
398 }
399
400 TEST(ScalingUtilTest, SquaredDistanceBetweenRectsTouching) {
401 gfx::Rect ref(2, 2, 2, 2);
402
403 gfx::Rect top_left(0, 0, 2, 2);
404 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left));
405 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left, ref));
406 gfx::Rect top_left_partial_top(1, 0, 2, 2);
407 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left_partial_top));
408 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left_partial_top, ref));
409 gfx::Rect top(2, 0, 2, 2);
410 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top));
411 EXPECT_EQ(0, SquaredDistanceBetweenRects(top, ref));
412 gfx::Rect top_right_partial_top(3, 0, 2, 2);
413 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_right_partial_top));
414 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_right_partial_top, ref));
415 gfx::Rect top_right(4, 0, 2, 2);
416 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_right));
417 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_right, ref));
418
419 gfx::Rect top_left_partial_left(0, 1, 2, 2);
420 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left_partial_left));
421 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left_partial_left, ref));
422 gfx::Rect left(0, 2, 2, 2);
423 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, left));
424 EXPECT_EQ(0, SquaredDistanceBetweenRects(left, ref));
425 gfx::Rect bottom_left_partial(0, 3, 2, 2);
426 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, bottom_left_partial));
427 EXPECT_EQ(0, SquaredDistanceBetweenRects(bottom_left_partial, ref));
428 gfx::Rect bottom_left(0, 4, 2, 2);
429 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, bottom_left));
430 EXPECT_EQ(0, SquaredDistanceBetweenRects(bottom_left, ref));
431 }
432
433 TEST(ScalingUtilTest, SquaredDistanceBetweenRectsOverlapping) {
434 gfx::Rect ref(5, 5, 2, 2);
435
436 gfx::Rect top_left_partial_top(4, 0, 2, 2);
437 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_left_partial_top));
438 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_left_partial_top, ref));
439 gfx::Rect top(5, 0, 2, 2);
440 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top));
441 EXPECT_EQ(9, SquaredDistanceBetweenRects(top, ref));
442 gfx::Rect top_right_partial(6, 0, 2, 2);
443 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_right_partial));
444 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_right_partial, ref));
445
446 gfx::Rect top_left_partial_left(0, 4, 2, 2);
447 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_left_partial_left));
448 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_left_partial_left, ref));
449 gfx::Rect left(0, 5, 2, 2);
450 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, left));
451 EXPECT_EQ(9, SquaredDistanceBetweenRects(left, ref));
452 gfx::Rect bottom_left_partial(0, 6, 2, 2);
453 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, bottom_left_partial));
454 EXPECT_EQ(9, SquaredDistanceBetweenRects(bottom_left_partial, ref));
455 }
456
457 TEST(ScalingUtilTest, SquaredDistanceBetweenRectsDiagonals) {
458 gfx::Rect ref(5, 5, 2, 2);
459
460 gfx::Rect top_left(0, 0, 2, 2);
461 EXPECT_EQ(18, SquaredDistanceBetweenRects(ref, top_left));
462 EXPECT_EQ(18, SquaredDistanceBetweenRects(top_left, ref));
463
464 gfx::Rect top_right(10, 0, 2, 2);
465 EXPECT_EQ(18, SquaredDistanceBetweenRects(ref, top_right));
466 EXPECT_EQ(18, SquaredDistanceBetweenRects(top_right, ref));
467 }
468
469 } // namespace win
470 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/win/scaling_util.cc ('k') | ui/gfx/win/screen_win_display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698