File: scaling_util_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (520 lines) | stat: -rw-r--r-- 21,956 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/display/win/scaling_util.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/win/test/screen_util_win.h"
#include "ui/gfx/geometry/rect.h"

namespace display {
namespace win {
namespace test {
namespace {

const wchar_t kFakeDisplayName[] = L"Fake Display";

internal::DisplayInfo CreateDisplayInfo(int x,
                                        int y,
                                        int width,
                                        int height,
                                        float scale_factor) {
  MONITORINFOEX monitor_info = CreateMonitorInfo(gfx::Rect(x, y, width, height),
                                                 gfx::Rect(x, y, width, height),
                                                 kFakeDisplayName);
  return internal::DisplayInfo(
      monitor_info, scale_factor, 1.0f, Display::ROTATE_0, 60.0f,
      gfx::Vector2dF(), DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER, std::string());
}

::testing::AssertionResult AssertOffsetsEqual(
    const char* lhs_expr,
    const char* rhs_expr,
    const DisplayPlacement& lhs,
    const DisplayPlacement& rhs) {
  if (lhs.position == rhs.position &&
      lhs.offset == rhs.offset &&
      lhs.offset_reference == rhs.offset_reference) {
    return ::testing::AssertionSuccess();
  }

  return ::testing::AssertionFailure() <<
      "Value of: " << rhs_expr << "\n  Actual: " << rhs.ToString() <<
      "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString();
}

#define EXPECT_OFFSET_EQ(a, b) \
  EXPECT_PRED_FORMAT2(AssertOffsetsEqual, a, b);

TEST(ScalingUtilTest, DisplayInfosTouchBottom) {
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                CreateDisplayInfo(1, 2, 1, 1, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 3, 1, 1.0f),
                                CreateDisplayInfo(0, 2, 2, 1, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 3, 1, 1.0f),
                                CreateDisplayInfo(1, 2, 2, 1, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 3, 1, 1.0f),
                                CreateDisplayInfo(2, 2, 2, 1, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 3, 1, 1.0f),
                                CreateDisplayInfo(3, 2, 2, 1, 1.0f)));
}

TEST(ScalingUtilTest, DisplayInfosTouchLeft) {
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                CreateDisplayInfo(0, 1, 1, 1, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 3, 1.0f),
                                CreateDisplayInfo(0, 0, 1, 2, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 3, 1.0f),
                                CreateDisplayInfo(0, 1, 1, 2, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 3, 1.0f),
                                CreateDisplayInfo(0, 2, 1, 2, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 3, 1.0f),
                                CreateDisplayInfo(0, 3, 1, 2, 1.0f)));
}

TEST(ScalingUtilTest, DisplayInfosTouchTop) {
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                CreateDisplayInfo(1, 0, 1, 1, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 3, 1, 1.0f),
                                CreateDisplayInfo(0, 0, 2, 1, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 3, 1, 1.0f),
                                CreateDisplayInfo(1, 0, 2, 1, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 3, 1, 1.0f),
                                CreateDisplayInfo(2, 0, 2, 1, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 3, 1, 1.0f),
                                CreateDisplayInfo(3, 0, 2, 1, 1.0f)));
}

TEST(ScalingUtilTest, DisplayInfosTouchRight) {
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                CreateDisplayInfo(2, 1, 1, 1, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 3, 1.0f),
                                CreateDisplayInfo(2, 0, 1, 2, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 3, 1.0f),
                                CreateDisplayInfo(2, 1, 1, 2, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 3, 1.0f),
                                CreateDisplayInfo(2, 2, 1, 2, 1.0f)));
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 3, 1.0f),
                                CreateDisplayInfo(2, 3, 1, 2, 1.0f)));
}

TEST(ScalingUtilTest, DisplayInfosTouchBottomRightCorner) {
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                CreateDisplayInfo(2, 2, 1, 1, 1.0f)));
}

TEST(ScalingUtilTest, DisplayInfosTouchBottomLeftCorner) {
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                CreateDisplayInfo(0, 2, 1, 1, 1.0f)));
}

TEST(ScalingUtilTest, DisplayInfosTouchUpperLeftCorner) {
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                CreateDisplayInfo(0, 0, 1, 1, 1.0f)));
}

TEST(ScalingUtilTest, DisplayInfosTouchUpperRightCorner) {
  EXPECT_TRUE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                CreateDisplayInfo(2, 0, 1, 1, 1.0f)));
}

TEST(ScalingUtilTest, DisplayInfosTouchNone) {
  EXPECT_FALSE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                 CreateDisplayInfo(3, 1, 1, 1, 1.0f)));
}

TEST(ScalingUtilTest, DisplayInfosTouchNoneShareXAxis) {
  EXPECT_FALSE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                 CreateDisplayInfo(5, 2, 1, 1, 1.0f)));

  EXPECT_FALSE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                 CreateDisplayInfo(-2, 1, 1, 1, 1.0f)));
}

TEST(ScalingUtilTest, DisplayInfosTouchNoneShareYAxis) {
  EXPECT_FALSE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                 CreateDisplayInfo(2, 3, 1, 1, 1.0f)));

  EXPECT_FALSE(DisplayInfosTouch(CreateDisplayInfo(1, 1, 1, 1, 1.0f),
                                 CreateDisplayInfo(0, -1, 1, 1, 1.0f)));
}

TEST(ScalingUtilTest, CalculateDisplayPlacementNoScaleRight) {
  // Top edge aligned.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::RIGHT, 0, DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(800, 0, 1024, 768, 1.0f)));

  // Bottom edge aligned.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::RIGHT,
                       0,
                       DisplayPlacement::BOTTOM_RIGHT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(800, -168, 1024, 768, 1.0f)));

  // Offset to the top
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::RIGHT,
                       -10,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(800, -10, 1024, 768, 1.0f)));

  // Offset to the bottom.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::RIGHT,
                       10,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(800, 10, 1024, 768, 1.0f)));
}

TEST(ScalingUtilTest, CalculateDisplayPlacementNoScaleLeft) {
  // Top edge aligned.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::LEFT,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(-1024, 0, 1024, 768, 1.0f)));

  // Bottom edge aligned.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::LEFT,
                       0,
                       DisplayPlacement::BOTTOM_RIGHT),
      CalculateDisplayPlacement(
          CreateDisplayInfo(0, 0, 800, 600, 1.0f),
          CreateDisplayInfo(-1024, -168, 1024, 768, 1.0f)));

  // Offset to the top.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::LEFT,
                       -10,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(
          CreateDisplayInfo(0, 0, 800, 600, 1.0f),
          CreateDisplayInfo(-1024, -10, 1024, 768, 1.0f)));

  // Offset to the bottom.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::LEFT,
                       10,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(-1024, 10, 1024, 768, 1.0f)));
}

TEST(ScalingUtilTest, CalculateDisplayPlacementNoScaleTop) {
  // Left edge aligned.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::TOP,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(0, -768, 1024, 768, 1.0f)));

  // Right edge aligned.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::TOP,
                       0,
                       DisplayPlacement::BOTTOM_RIGHT),
      CalculateDisplayPlacement(
          CreateDisplayInfo(0, 0, 800, 600, 1.0f),
          CreateDisplayInfo(-224, -768, 1024, 768, 1.0f)));

  // Offset to the right.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::TOP,
                       10,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(10, -768, 1024, 768, 1.0f)));

  // Offset to the left.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::TOP,
                       -10,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(-10, -768, 1024, 768, 1.0f)));
}

TEST(ScalingUtilTest, CalculateDisplayPlacementNoScaleBottom) {
  // Left edge aligned.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::BOTTOM,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(0, 600, 1024, 768, 1.0f)));

  // Right edge aligned.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::BOTTOM,
                       0,
                       DisplayPlacement::BOTTOM_RIGHT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(-224, 600, 1024, 768, 1.0f)));

  // Offset to the right
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::BOTTOM,
                       10,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(10, 600, 1024, 768, 1.0f)));

  // Offset to the left
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::BOTTOM,
                       -10,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(0, 0, 800, 600, 1.0f),
                                CreateDisplayInfo(-10, 600, 1024, 768, 1.0f)));
}

TEST(ScalingUtilTest, CalculateDisplayPlacementNoScaleOddDimensions) {
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::RIGHT,
                       5,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(35, 72, 24, 24, 1.0f),
                                CreateDisplayInfo(59, 77, 7, 9, 1.0f)));

  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::LEFT,
                       2,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(1, 7, 30, 40, 1.0f),
                                CreateDisplayInfo(-701, 9, 702, 2, 1.0f)));
}

TEST(ScalingUtilTest, CalculateDisplayPlacement1_5xScale) {
  // Side by side to the right.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::RIGHT,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
                                CreateDisplayInfo(900, 50, 1000, 700, 1.5f)));

  // Side-by-side to the left.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::LEFT,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
                                CreateDisplayInfo(-900, 50, 1000, 700, 1.5f)));

  // Side-by-side to the top.
  // Note that -33 would be the normal enclosing rect offset.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::TOP,
                       -34,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
                                CreateDisplayInfo(50, -650, 1000, 700, 1.5f)));

  // Side-by-side on the bottom.
  // Note that -33 would be the normal enclosing rect offset.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::BOTTOM,
                       -34,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
                                CreateDisplayInfo(50, 650, 1000, 700, 1.5f)));

  // Side by side to the right.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::RIGHT,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
                                CreateDisplayInfo(900, 50, 1000, 700, 1.5f)));

  // Side-by-side to the left.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::LEFT,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
                                CreateDisplayInfo(-900, 50, 1000, 700, 1.5f)));

  // Side-by-side to the top.
  // Note that -33 would be the normal enclosing rect offset.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::TOP,
                       -34,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
                                CreateDisplayInfo(50, -650, 1000, 700, 1.5f)));


  // Side-by-side to the bottom.
  // Note that -33 would be the normal enclosing rect offset.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::BOTTOM,
                       -34,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
                                CreateDisplayInfo(50, 650, 1000, 700, 1.5f)));
}

TEST(ScalingUtilTest, CalculateDisplayPlacement2xScale) {
  // Side by side to the right.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::RIGHT,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
                                CreateDisplayInfo(900, 50, 1000, 700, 2.0f)));

  // Side-by-side to the left.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::LEFT,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
                                CreateDisplayInfo(-900, 50, 1000, 700, 2.0f)));

  // Side-by-side to the top.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::TOP,
                       -25,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
                                CreateDisplayInfo(50, -650, 1000, 700, 2.0f)));

  // Side-by-side on the bottom.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::BOTTOM,
                       -25,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 1.0f),
                                CreateDisplayInfo(50, 650, 1000, 700, 2.0f)));

  // Side by side to the right.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::RIGHT,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
                                CreateDisplayInfo(900, 50, 1000, 700, 2.0f)));

  // Side-by-side to the left.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::LEFT,
                       0,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
                                CreateDisplayInfo(-900, 50, 1000, 700, 2.0f)));

  // Side-by-side to the top.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::TOP,
                       -25,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
                                CreateDisplayInfo(50, -650, 1000, 700, 2.0f)));


  // Side-by-side to the bottom.
  EXPECT_OFFSET_EQ(
      DisplayPlacement(DisplayPlacement::BOTTOM,
                       -25,
                       DisplayPlacement::TOP_LEFT),
      CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f),
                                CreateDisplayInfo(50, 650, 1000, 700, 2.0f)));
}

TEST(ScalingUtilTest, SquaredDistanceBetweenRectsFullyIntersecting) {
  gfx::Rect rect1(0, 0, 100, 100);
  gfx::Rect rect2(5, 5, 10, 10);
  EXPECT_EQ(-100, SquaredDistanceBetweenRects(rect1, rect2));
  EXPECT_EQ(-100, SquaredDistanceBetweenRects(rect2, rect1));
}

TEST(ScalingUtilTest, SquaredDistanceBetweenRectsPartiallyIntersecting) {
  gfx::Rect rect1(0, 0, 10, 10);
  gfx::Rect rect2(5, 5, 20, 20);
  EXPECT_EQ(-25, SquaredDistanceBetweenRects(rect1, rect2));
  EXPECT_EQ(-25, SquaredDistanceBetweenRects(rect2, rect1));
}

TEST(ScalingUtilTest, SquaredDistanceBetweenRectsTouching) {
  gfx::Rect ref(2, 2, 2, 2);

  gfx::Rect top_left(0, 0, 2, 2);
  EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left));
  EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left, ref));
  gfx::Rect top_left_partial_top(1, 0, 2, 2);
  EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left_partial_top));
  EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left_partial_top, ref));
  gfx::Rect top(2, 0, 2, 2);
  EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top));
  EXPECT_EQ(0, SquaredDistanceBetweenRects(top, ref));
  gfx::Rect top_right_partial_top(3, 0, 2, 2);
  EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_right_partial_top));
  EXPECT_EQ(0, SquaredDistanceBetweenRects(top_right_partial_top, ref));
  gfx::Rect top_right(4, 0, 2, 2);
  EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_right));
  EXPECT_EQ(0, SquaredDistanceBetweenRects(top_right, ref));

  gfx::Rect top_left_partial_left(0, 1, 2, 2);
  EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left_partial_left));
  EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left_partial_left, ref));
  gfx::Rect left(0, 2, 2, 2);
  EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, left));
  EXPECT_EQ(0, SquaredDistanceBetweenRects(left, ref));
  gfx::Rect bottom_left_partial(0, 3, 2, 2);
  EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, bottom_left_partial));
  EXPECT_EQ(0, SquaredDistanceBetweenRects(bottom_left_partial, ref));
  gfx::Rect bottom_left(0, 4, 2, 2);
  EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, bottom_left));
  EXPECT_EQ(0, SquaredDistanceBetweenRects(bottom_left, ref));
}

TEST(ScalingUtilTest, SquaredDistanceBetweenRectsOverlapping) {
  gfx::Rect ref(5, 5, 2, 2);

  gfx::Rect top_left_partial_top(4, 0, 2, 2);
  EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_left_partial_top));
  EXPECT_EQ(9, SquaredDistanceBetweenRects(top_left_partial_top, ref));
  gfx::Rect top(5, 0, 2, 2);
  EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top));
  EXPECT_EQ(9, SquaredDistanceBetweenRects(top, ref));
  gfx::Rect top_right_partial(6, 0, 2, 2);
  EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_right_partial));
  EXPECT_EQ(9, SquaredDistanceBetweenRects(top_right_partial, ref));

  gfx::Rect top_left_partial_left(0, 4, 2, 2);
  EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_left_partial_left));
  EXPECT_EQ(9, SquaredDistanceBetweenRects(top_left_partial_left, ref));
  gfx::Rect left(0, 5, 2, 2);
  EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, left));
  EXPECT_EQ(9, SquaredDistanceBetweenRects(left, ref));
  gfx::Rect bottom_left_partial(0, 6, 2, 2);
  EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, bottom_left_partial));
  EXPECT_EQ(9, SquaredDistanceBetweenRects(bottom_left_partial, ref));
}

TEST(ScalingUtilTest, SquaredDistanceBetweenRectsDiagonals) {
  gfx::Rect ref(5, 5, 2, 2);

  gfx::Rect top_left(0, 0, 2, 2);
  EXPECT_EQ(18, SquaredDistanceBetweenRects(ref, top_left));
  EXPECT_EQ(18, SquaredDistanceBetweenRects(top_left, ref));

  gfx::Rect top_right(10, 0, 2, 2);
  EXPECT_EQ(18, SquaredDistanceBetweenRects(ref, top_right));
  EXPECT_EQ(18, SquaredDistanceBetweenRects(top_right, ref));
}

}  // namespace
}  // namespace test
}  // namespace win
}  // namespace display