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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/win/rect_util_unittest.cc
diff --git a/ui/gfx/win/rect_util_unittest.cc b/ui/gfx/win/rect_util_unittest.cc
deleted file mode 100644
index a4f17cfe7546fc8267cc99683b705c56dd643e2b..0000000000000000000000000000000000000000
--- a/ui/gfx/win/rect_util_unittest.cc
+++ /dev/null
@@ -1,380 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/gfx/win/rect_util.h"
-
-namespace gfx {
-namespace win {
-
-TEST(RectUtilTest, FindTouchingRectEdgeBottom) {
- EXPECT_EQ(RectEdge::BOTTOM,
- FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 2, 1, 1)));
-}
-
-TEST(RectUtilTest, FindTouchingRectEdgeLeft) {
- EXPECT_EQ(RectEdge::LEFT,
- FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(0, 1, 1, 1)));
-}
-
-TEST(RectUtilTest, FindTouchingRectEdgeTop) {
- EXPECT_EQ(RectEdge::TOP,
- FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 0, 1, 1)));
-}
-
-TEST(RectUtilTest, FindTouchingRectEdgeRight) {
- EXPECT_EQ(RectEdge::RIGHT,
- FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(2, 1, 1, 1)));
-}
-
-TEST(RectUtilTest, FindTouchingRectEdgeBottomRightCorner) {
- EXPECT_EQ(RectEdge::BOTTOM,
- FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(2, 2, 1, 1)));
-}
-
-TEST(RectUtilTest, FindTouchingRectEdgeBottomLeftCorner) {
- EXPECT_EQ(RectEdge::BOTTOM,
- FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(0, 2, 1, 1)));
-}
-
-TEST(RectUtilTest, FindTouchingRectEdgeUpperLeftCorner) {
- EXPECT_EQ(RectEdge::LEFT,
- FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(0, 0, 1, 1)));
-}
-
-TEST(RectUtilTest, FindTouchingRectEdgeUpperRightCorner) {
- EXPECT_EQ(RectEdge::TOP,
- FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(2, 0, 1, 1)));
-}
-
-TEST(RectUtilTest, FindTouchingRectEdgeNone) {
- EXPECT_EQ(RectEdge::NONE,
- FindTouchingRectEdge(gfx::Rect(1, 1, 1, 1), gfx::Rect(3, 1, 1, 1)));
-}
-
-TEST(RectUtilTest, ScaleAndPositionRectNoScaleRight) {
- // Top edge aligned.
- EXPECT_EQ(gfx::Rect(800, 0, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(800, 0, 1024, 768),
- 1.0f));
- // Bottom edge aligned.
- EXPECT_EQ(gfx::Rect(800, -168, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(800, -168, 1024, 768),
- 1.0f));
- // Offset to the top.
- EXPECT_EQ(gfx::Rect(800, -10, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(800, -10, 1024, 768),
- 1.0f));
- // Offset to the bottom.
- EXPECT_EQ(gfx::Rect(800, 10, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(800, 10, 1024, 768),
- 1.0f));
-
-}
-
-TEST(RectUtilTest, ScaleAndPositionRectNoScaleLeft) {
- // Top edge aligned.
- EXPECT_EQ(gfx::Rect(-1024, 0, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(-1024, 0, 1024, 768),
- 1.0f));
- // Bottom edge aligned.
- EXPECT_EQ(gfx::Rect(-1024, -168, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(-1024, -168, 1024, 768),
- 1.0f));
- // Offset to the top.
- EXPECT_EQ(gfx::Rect(-1024, -10, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(-1024, -10, 1024, 768),
- 1.0f));
- // Offset to the bottom.
- EXPECT_EQ(gfx::Rect(-1024, 10, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(-1024, 10, 1024, 768),
- 1.0f));
-}
-
-TEST(RectUtilTest, ScaleAndPositionRectNoScaleTop) {
- // Left edge aligned.
- EXPECT_EQ(gfx::Rect(0, -768, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, -768, 1024, 768),
- 1.0f));
- // Right edge aligned.
- EXPECT_EQ(gfx::Rect(-224, -768, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(-224, -768, 1024, 768),
- 1.0f));
- // Offset to the right.
- EXPECT_EQ(gfx::Rect(10, -768, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(10, -768, 1024, 768),
- 1.0f));
- // Offset to the left.
- EXPECT_EQ(gfx::Rect(-10, -768, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(-10, -768, 1024, 768),
- 1.0f));
-}
-
-TEST(RectUtilTest, ScaleAndPositionRectNoScaleBottom) {
- // Left edge aligned.
- EXPECT_EQ(gfx::Rect(0, 600, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 600, 1024, 768),
- 1.0f));
- // Right edge aligned.
- EXPECT_EQ(gfx::Rect(-224, 600, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(-224, 600, 1024, 768),
- 1.0f));
- // Offset to the right
- EXPECT_EQ(gfx::Rect(10, 600, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(10, 600, 1024, 768),
- 1.0f));
- // Offset to the left
- EXPECT_EQ(gfx::Rect(-10, 600, 1024, 768),
- ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
- gfx::Rect(0, 0, 800, 600),
- gfx::Rect(-10, 600, 1024, 768),
- 1.0f));
-}
-
-TEST(RectUtilTest, ScaleAndPositionRectNoScaleOddDimensions) {
- EXPECT_EQ(gfx::Rect(59, 77, 7, 9),
- ScaleAndPositionRect(gfx::Rect(35, 72, 24, 24),
- gfx::Rect(35, 72, 24, 24),
- gfx::Rect(59, 77, 7, 9),
- 1.0f));
- EXPECT_EQ(gfx::Rect(-701, 9, 702, 2),
- ScaleAndPositionRect(gfx::Rect(1, 7, 30, 40),
- gfx::Rect(1, 7, 30, 40),
- gfx::Rect(-701, 9, 702, 2),
- 1.0f));
-}
-
-TEST(RectUtilTest, ScaleAndPositionRect1_5xScale) {
- // Side by side to the right.
- EXPECT_EQ(gfx::Rect(900, 50, 667, 467),
- ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(900, 50, 1000, 700),
- 1.5f));
-
- // Side-by-side to the left.
- EXPECT_EQ(gfx::Rect(-567, 50, 667, 467),
- ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(-900, 50, 1000, 700),
- 1.5f));
-
- // Side-by-side to the top (note size inconsistency due to enclosing rect).
- EXPECT_EQ(gfx::Rect(67, -418, 667, 468),
- ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(50, -650, 1000, 700),
- 1.5f));
-
- // // Side-by-side on the bottom.
- EXPECT_EQ(gfx::Rect(67, 650, 667, 467),
- ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(50, 650, 1000, 700),
- 1.5f));
-
- // Side by side to the right.
- EXPECT_EQ(gfx::Rect(500, 50, 667, 467),
- ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(900, 50, 1000, 700),
- 1.5f));
-
- // Side-by-side to the left.
- EXPECT_EQ(gfx::Rect(-567, 50, 667, 467),
- ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(-900, 50, 1000, 700),
- 1.5f));
-
- // Side-by-side to the top (note size inconsistency due to enclosing rect).
- EXPECT_EQ(gfx::Rect(67, -418, 667, 468),
- ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(50, -650, 1000, 700),
- 1.5f));
-
-
- // Side-by-side to the bottom.
- EXPECT_EQ(gfx::Rect(67, 350, 667, 467),
- ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(50, 650, 1000, 700),
- 1.5f));
-}
-
-TEST(RectUtilTest, ScaleAndPositionRect2xScale) {
- // Side by side to the right.
- EXPECT_EQ(gfx::Rect(900, 50, 500, 350),
- ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(900, 50, 1000, 700),
- 2.0f));
- // Side-by-side to the left.
- EXPECT_EQ(gfx::Rect(-400, 50, 500, 350),
- ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(-900, 50, 1000, 700),
- 2.0f));
-
- // Side-by-side to the top.
- EXPECT_EQ(gfx::Rect(75, -300, 500, 350),
- ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(50, -650, 1000, 700),
- 2.0f));
-
- // Side-by-side on the bottom.
- EXPECT_EQ(gfx::Rect(75, 650, 500, 350),
- ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(50, 650, 1000, 700),
- 2.0f));
-
- // Side by side to the right.
- EXPECT_EQ(gfx::Rect(500, 50, 500, 350),
- ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(900, 50, 1000, 700),
- 2.0f));
-
- // Side-by-side to the left.
- EXPECT_EQ(gfx::Rect(-400, 50, 500, 350),
- ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(-900, 50, 1000, 700),
- 2.0f));
-
- // Side-by-side to the top.
- EXPECT_EQ(gfx::Rect(75, -300, 500, 350),
- ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(50, -650, 1000, 700),
- 2.0f));
-
-
- // Side-by-side to the bottom.
- EXPECT_EQ(gfx::Rect(75, 350, 500, 350),
- ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
- gfx::Rect(100, 50, 800, 600),
- gfx::Rect(50, 650, 1000, 700),
- 2.0f));
-}
-
-TEST(RectUtilTest, SquaredDistanceBetweenRectsFullyIntersecting) {
- gfx::Rect rect1(0, 0, 100, 100);
- gfx::Rect rect2(5, 5, 10, 10);
- EXPECT_EQ(0, SquaredDistanceBetweenRects(rect1, rect2));
- EXPECT_EQ(0, SquaredDistanceBetweenRects(rect2, rect1));
-}
-
-TEST(RectUtilTest, SquaredDistanceBetweenRectsPartiallyIntersecting) {
- gfx::Rect rect1(0, 0, 10, 10);
- gfx::Rect rect2(5, 5, 10, 10);
- EXPECT_EQ(0, SquaredDistanceBetweenRects(rect1, rect2));
- EXPECT_EQ(0, SquaredDistanceBetweenRects(rect2, rect1));
-}
-
-TEST(RectUtilTest, 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(RectUtilTest, 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(RectUtilTest, 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 win
-} // namespace gfx
« 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