| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base/touch/selection_bound.h" | 5 #include "ui/base/touch/selection_bound.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/gfx/geometry/rect.h" | 8 #include "ui/gfx/geometry/rect.h" |
| 9 | 9 |
| 10 namespace ui { | 10 namespace ui { |
| 11 | 11 |
| 12 TEST(SelectionBoundTest, RectBetweenSelectionBounds) { | 12 TEST(SelectionBoundTest, RectBetweenSelectionBounds) { |
| 13 SelectionBound b1, b2; | 13 SelectionBound b1, b2; |
| 14 // Simple case of aligned vertical bounds of equal height | 14 // Simple case of aligned vertical bounds of equal height |
| 15 b1.SetEdge(gfx::Point(0, 20), gfx::Point(0, 25)); | 15 b1.SetEdge(gfx::PointF(0.f, 20.f), gfx::PointF(0.f, 25.f)); |
| 16 b2.SetEdge(gfx::Point(110, 20), gfx::Point(110, 25)); | 16 b2.SetEdge(gfx::PointF(110.f, 20.f), gfx::PointF(110.f, 25.f)); |
| 17 gfx::Rect expected_rect( | 17 gfx::Rect expected_rect( |
| 18 b1.edge_top_rounded().x(), | 18 b1.edge_top_rounded().x(), |
| 19 b1.edge_top_rounded().y(), | 19 b1.edge_top_rounded().y(), |
| 20 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | 20 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), |
| 21 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); | 21 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); |
| 22 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | 22 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); |
| 23 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | 23 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); |
| 24 | 24 |
| 25 // Parallel vertical bounds of different heights | 25 // Parallel vertical bounds of different heights |
| 26 b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 25)); | 26 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 25.f)); |
| 27 b2.SetEdge(gfx::Point(110, 0), gfx::Point(110, 35)); | 27 b2.SetEdge(gfx::PointF(110.f, 0.f), gfx::PointF(110.f, 35.f)); |
| 28 expected_rect = gfx::Rect( | 28 expected_rect = gfx::Rect( |
| 29 b1.edge_top_rounded().x(), | 29 b1.edge_top_rounded().x(), |
| 30 b2.edge_top_rounded().y(), | 30 b2.edge_top_rounded().y(), |
| 31 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | 31 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), |
| 32 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); | 32 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); |
| 33 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | 33 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); |
| 34 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | 34 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); |
| 35 | 35 |
| 36 b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30)); | 36 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); |
| 37 b2.SetEdge(gfx::Point(110, 25), gfx::Point(110, 45)); | 37 b2.SetEdge(gfx::PointF(110.f, 25.f), gfx::PointF(110.f, 45.f)); |
| 38 expected_rect = gfx::Rect( | 38 expected_rect = gfx::Rect( |
| 39 b1.edge_top_rounded().x(), | 39 b1.edge_top_rounded().x(), |
| 40 b1.edge_top_rounded().y(), | 40 b1.edge_top_rounded().y(), |
| 41 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | 41 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), |
| 42 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | 42 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); |
| 43 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | 43 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); |
| 44 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | 44 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); |
| 45 | 45 |
| 46 b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30)); | 46 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); |
| 47 b2.SetEdge(gfx::Point(110, 40), gfx::Point(110, 60)); | 47 b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(110.f, 60.f)); |
| 48 expected_rect = gfx::Rect( | 48 expected_rect = gfx::Rect( |
| 49 b1.edge_top_rounded().x(), | 49 b1.edge_top_rounded().x(), |
| 50 b1.edge_top_rounded().y(), | 50 b1.edge_top_rounded().y(), |
| 51 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | 51 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), |
| 52 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | 52 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); |
| 53 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | 53 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); |
| 54 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | 54 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); |
| 55 | 55 |
| 56 // Overlapping vertical bounds | 56 // Overlapping vertical bounds |
| 57 b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30)); | 57 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); |
| 58 b2.SetEdge(gfx::Point(10, 25), gfx::Point(10, 40)); | 58 b2.SetEdge(gfx::PointF(10.f, 25.f), gfx::PointF(10.f, 40.f)); |
| 59 expected_rect = gfx::Rect( | 59 expected_rect = gfx::Rect( |
| 60 b1.edge_top_rounded().x(), | 60 b1.edge_top_rounded().x(), |
| 61 b1.edge_top_rounded().y(), | 61 b1.edge_top_rounded().y(), |
| 62 0, | 62 0, |
| 63 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | 63 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); |
| 64 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | 64 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); |
| 65 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | 65 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); |
| 66 | 66 |
| 67 // Non-vertical bounds: "\ \" | 67 // Non-vertical bounds: "\ \" |
| 68 b1.SetEdge(gfx::Point(10, 20), gfx::Point(20, 30)); | 68 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(20.f, 30.f)); |
| 69 b2.SetEdge(gfx::Point(110, 40), gfx::Point(120, 60)); | 69 b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(120.f, 60.f)); |
| 70 expected_rect = gfx::Rect( | 70 expected_rect = gfx::Rect( |
| 71 b1.edge_top_rounded().x(), | 71 b1.edge_top_rounded().x(), |
| 72 b1.edge_top_rounded().y(), | 72 b1.edge_top_rounded().y(), |
| 73 b2.edge_bottom_rounded().x() - b1.edge_top_rounded().x(), | 73 b2.edge_bottom_rounded().x() - b1.edge_top_rounded().x(), |
| 74 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | 74 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); |
| 75 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | 75 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); |
| 76 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | 76 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); |
| 77 | 77 |
| 78 // Non-vertical bounds: "/ \" | 78 // Non-vertical bounds: "/ \" |
| 79 b1.SetEdge(gfx::Point(20, 30), gfx::Point(0, 40)); | 79 b1.SetEdge(gfx::PointF(20.f, 30.f), gfx::PointF(0.f, 40.f)); |
| 80 b2.SetEdge(gfx::Point(110, 30), gfx::Point(120, 40)); | 80 b2.SetEdge(gfx::PointF(110.f, 30.f), gfx::PointF(120.f, 40.f)); |
| 81 expected_rect = gfx::Rect( | 81 expected_rect = gfx::Rect( |
| 82 b1.edge_bottom_rounded().x(), | 82 b1.edge_bottom_rounded().x(), |
| 83 b1.edge_top_rounded().y(), | 83 b1.edge_top_rounded().y(), |
| 84 b2.edge_bottom_rounded().x() - b1.edge_bottom_rounded().x(), | 84 b2.edge_bottom_rounded().x() - b1.edge_bottom_rounded().x(), |
| 85 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); | 85 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); |
| 86 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | 86 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); |
| 87 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | 87 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace ui | 90 } // namespace ui |
| OLD | NEW |