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