OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "ui/display/win/scaling_util.h" | 5 #include "ui/display/win/scaling_util.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/display/win/test/screen_util_win.h" | 8 #include "ui/display/win/test/screen_util_win.h" |
9 #include "ui/gfx/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
10 | 10 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 419 |
420 // Side-by-side to the bottom. | 420 // Side-by-side to the bottom. |
421 EXPECT_OFFSET_EQ( | 421 EXPECT_OFFSET_EQ( |
422 DisplayPlacement(DisplayPlacement::BOTTOM, | 422 DisplayPlacement(DisplayPlacement::BOTTOM, |
423 -25, | 423 -25, |
424 DisplayPlacement::TOP_LEFT), | 424 DisplayPlacement::TOP_LEFT), |
425 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f), | 425 CalculateDisplayPlacement(CreateDisplayInfo(100, 50, 800, 600, 2.0f), |
426 CreateDisplayInfo(50, 650, 1000, 700, 2.0f))); | 426 CreateDisplayInfo(50, 650, 1000, 700, 2.0f))); |
427 } | 427 } |
428 | 428 |
| 429 TEST(ScalingUtilTest, SquaredDistanceBetweenRectsFullyIntersecting) { |
| 430 gfx::Rect rect1(0, 0, 100, 100); |
| 431 gfx::Rect rect2(5, 5, 10, 10); |
| 432 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect1, rect2)); |
| 433 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect2, rect1)); |
| 434 } |
| 435 |
| 436 TEST(ScalingUtilTest, SquaredDistanceBetweenRectsPartiallyIntersecting) { |
| 437 gfx::Rect rect1(0, 0, 10, 10); |
| 438 gfx::Rect rect2(5, 5, 10, 10); |
| 439 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect1, rect2)); |
| 440 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect2, rect1)); |
| 441 } |
| 442 |
| 443 TEST(ScalingUtilTest, SquaredDistanceBetweenRectsTouching) { |
| 444 gfx::Rect ref(2, 2, 2, 2); |
| 445 |
| 446 gfx::Rect top_left(0, 0, 2, 2); |
| 447 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left)); |
| 448 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left, ref)); |
| 449 gfx::Rect top_left_partial_top(1, 0, 2, 2); |
| 450 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left_partial_top)); |
| 451 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left_partial_top, ref)); |
| 452 gfx::Rect top(2, 0, 2, 2); |
| 453 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top)); |
| 454 EXPECT_EQ(0, SquaredDistanceBetweenRects(top, ref)); |
| 455 gfx::Rect top_right_partial_top(3, 0, 2, 2); |
| 456 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_right_partial_top)); |
| 457 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_right_partial_top, ref)); |
| 458 gfx::Rect top_right(4, 0, 2, 2); |
| 459 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_right)); |
| 460 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_right, ref)); |
| 461 |
| 462 gfx::Rect top_left_partial_left(0, 1, 2, 2); |
| 463 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left_partial_left)); |
| 464 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left_partial_left, ref)); |
| 465 gfx::Rect left(0, 2, 2, 2); |
| 466 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, left)); |
| 467 EXPECT_EQ(0, SquaredDistanceBetweenRects(left, ref)); |
| 468 gfx::Rect bottom_left_partial(0, 3, 2, 2); |
| 469 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, bottom_left_partial)); |
| 470 EXPECT_EQ(0, SquaredDistanceBetweenRects(bottom_left_partial, ref)); |
| 471 gfx::Rect bottom_left(0, 4, 2, 2); |
| 472 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, bottom_left)); |
| 473 EXPECT_EQ(0, SquaredDistanceBetweenRects(bottom_left, ref)); |
| 474 } |
| 475 |
| 476 TEST(ScalingUtilTest, SquaredDistanceBetweenRectsOverlapping) { |
| 477 gfx::Rect ref(5, 5, 2, 2); |
| 478 |
| 479 gfx::Rect top_left_partial_top(4, 0, 2, 2); |
| 480 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_left_partial_top)); |
| 481 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_left_partial_top, ref)); |
| 482 gfx::Rect top(5, 0, 2, 2); |
| 483 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top)); |
| 484 EXPECT_EQ(9, SquaredDistanceBetweenRects(top, ref)); |
| 485 gfx::Rect top_right_partial(6, 0, 2, 2); |
| 486 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_right_partial)); |
| 487 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_right_partial, ref)); |
| 488 |
| 489 gfx::Rect top_left_partial_left(0, 4, 2, 2); |
| 490 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_left_partial_left)); |
| 491 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_left_partial_left, ref)); |
| 492 gfx::Rect left(0, 5, 2, 2); |
| 493 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, left)); |
| 494 EXPECT_EQ(9, SquaredDistanceBetweenRects(left, ref)); |
| 495 gfx::Rect bottom_left_partial(0, 6, 2, 2); |
| 496 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, bottom_left_partial)); |
| 497 EXPECT_EQ(9, SquaredDistanceBetweenRects(bottom_left_partial, ref)); |
| 498 } |
| 499 |
| 500 TEST(ScalingUtilTest, SquaredDistanceBetweenRectsDiagonals) { |
| 501 gfx::Rect ref(5, 5, 2, 2); |
| 502 |
| 503 gfx::Rect top_left(0, 0, 2, 2); |
| 504 EXPECT_EQ(18, SquaredDistanceBetweenRects(ref, top_left)); |
| 505 EXPECT_EQ(18, SquaredDistanceBetweenRects(top_left, ref)); |
| 506 |
| 507 gfx::Rect top_right(10, 0, 2, 2); |
| 508 EXPECT_EQ(18, SquaredDistanceBetweenRects(ref, top_right)); |
| 509 EXPECT_EQ(18, SquaredDistanceBetweenRects(top_right, ref)); |
| 510 } |
| 511 |
429 } // namespace | 512 } // namespace |
430 } // namespace test | 513 } // namespace test |
431 } // namespace win | 514 } // namespace win |
432 } // namespace display | 515 } // namespace display |
OLD | NEW |