OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/base/touch/selection_bound.h" | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
mfomitchev
2014/12/01 21:36:24
Adjust --similarity so that it detects that this i
mohsen
2014/12/02 05:17:02
Done.
| |
8 | |
9 namespace ui { | |
10 | |
11 TEST(SelectionBoundTest, RectBetweenSelectionBounds) { | |
12 SelectionBound b1, b2; | |
13 // Simple case of aligned vertical bounds of equal height | |
14 b1.SetEdgeTop(gfx::Point(0, 20)); | |
15 b1.SetEdgeBottom(gfx::Point(0, 25)); | |
16 b2.SetEdgeTop(gfx::Point(110, 20)); | |
17 b2.SetEdgeBottom(gfx::Point(110, 25)); | |
18 gfx::Rect expected_rect( | |
19 b1.edge_top_rounded().x(), | |
20 b1.edge_top_rounded().y(), | |
21 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | |
22 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); | |
23 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
24 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
25 | |
26 // Parallel vertical bounds of different heights | |
27 b1.SetEdgeTop(gfx::Point(10, 20)); | |
28 b1.SetEdgeBottom(gfx::Point(10, 25)); | |
29 b2.SetEdgeTop(gfx::Point(110, 0)); | |
30 b2.SetEdgeBottom(gfx::Point(110, 35)); | |
31 expected_rect = gfx::Rect( | |
32 b1.edge_top_rounded().x(), | |
33 b2.edge_top_rounded().y(), | |
34 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | |
35 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); | |
36 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
37 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
38 | |
39 b1.SetEdgeTop(gfx::Point(10, 20)); | |
40 b1.SetEdgeBottom(gfx::Point(10, 30)); | |
41 b2.SetEdgeTop(gfx::Point(110, 25)); | |
42 b2.SetEdgeBottom(gfx::Point(110, 45)); | |
43 expected_rect = gfx::Rect( | |
44 b1.edge_top_rounded().x(), | |
45 b1.edge_top_rounded().y(), | |
46 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | |
47 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | |
48 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
49 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
50 | |
51 b1.SetEdgeTop(gfx::Point(10, 20)); | |
52 b1.SetEdgeBottom(gfx::Point(10, 30)); | |
53 b2.SetEdgeTop(gfx::Point(110, 40)); | |
54 b2.SetEdgeBottom(gfx::Point(110, 60)); | |
55 expected_rect = gfx::Rect( | |
56 b1.edge_top_rounded().x(), | |
57 b1.edge_top_rounded().y(), | |
58 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | |
59 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | |
60 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
61 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
62 | |
63 // Overlapping vertical bounds | |
64 b1.SetEdgeTop(gfx::Point(10, 20)); | |
65 b1.SetEdgeBottom(gfx::Point(10, 30)); | |
66 b2.SetEdgeTop(gfx::Point(10, 25)); | |
67 b2.SetEdgeBottom(gfx::Point(10, 40)); | |
68 expected_rect = gfx::Rect( | |
69 b1.edge_top_rounded().x(), | |
70 b1.edge_top_rounded().y(), | |
71 0, | |
72 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | |
73 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
74 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
75 | |
76 // Non-vertical bounds: "\ \" | |
77 b1.SetEdgeTop(gfx::Point(10, 20)); | |
78 b1.SetEdgeBottom(gfx::Point(20, 30)); | |
79 b2.SetEdgeTop(gfx::Point(110, 40)); | |
80 b2.SetEdgeBottom(gfx::Point(120, 60)); | |
81 expected_rect = gfx::Rect( | |
82 b1.edge_top_rounded().x(), | |
83 b1.edge_top_rounded().y(), | |
84 b2.edge_bottom_rounded().x() - b1.edge_top_rounded().x(), | |
85 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | |
86 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
87 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
88 | |
89 // Non-vertical bounds: "/ \" | |
90 b1.SetEdgeTop(gfx::Point(20, 30)); | |
91 b1.SetEdgeBottom(gfx::Point(0, 40)); | |
92 b2.SetEdgeTop(gfx::Point(110, 30)); | |
93 b2.SetEdgeBottom(gfx::Point(120, 40)); | |
94 expected_rect = gfx::Rect( | |
95 b1.edge_bottom_rounded().x(), | |
96 b1.edge_top_rounded().y(), | |
97 b2.edge_bottom_rounded().x() - b1.edge_bottom_rounded().x(), | |
98 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); | |
99 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
100 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
101 } | |
102 | |
103 } // namespace ui | |
OLD | NEW |