Enable right clicking on the applist doodle web contents and log the data.
[chromium-blink-merge.git] / ui / base / touch / selection_bound_unittest.cc
blob7a8e65160c180add3d2cae790e2b1d0af85adfae
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.
5 #include "ui/base/touch/selection_bound.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/geometry/rect.h"
10 namespace ui {
12 TEST(SelectionBoundTest, RectBetweenSelectionBounds) {
13 SelectionBound b1, b2;
14 // Simple case of aligned vertical bounds of equal height
15 b1.SetEdge(gfx::Point(0, 20), gfx::Point(0, 25));
16 b2.SetEdge(gfx::Point(110, 20), gfx::Point(110, 25));
17 gfx::Rect expected_rect(
18 b1.edge_top_rounded().x(),
19 b1.edge_top_rounded().y(),
20 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
21 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y());
22 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
23 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
25 // Parallel vertical bounds of different heights
26 b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 25));
27 b2.SetEdge(gfx::Point(110, 0), gfx::Point(110, 35));
28 expected_rect = gfx::Rect(
29 b1.edge_top_rounded().x(),
30 b2.edge_top_rounded().y(),
31 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
32 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y());
33 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
34 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
36 b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30));
37 b2.SetEdge(gfx::Point(110, 25), gfx::Point(110, 45));
38 expected_rect = gfx::Rect(
39 b1.edge_top_rounded().x(),
40 b1.edge_top_rounded().y(),
41 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
42 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
43 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
44 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
46 b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30));
47 b2.SetEdge(gfx::Point(110, 40), gfx::Point(110, 60));
48 expected_rect = gfx::Rect(
49 b1.edge_top_rounded().x(),
50 b1.edge_top_rounded().y(),
51 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
52 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
53 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
54 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
56 // Overlapping vertical bounds
57 b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30));
58 b2.SetEdge(gfx::Point(10, 25), gfx::Point(10, 40));
59 expected_rect = gfx::Rect(
60 b1.edge_top_rounded().x(),
61 b1.edge_top_rounded().y(),
63 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
64 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
65 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
67 // Non-vertical bounds: "\ \"
68 b1.SetEdge(gfx::Point(10, 20), gfx::Point(20, 30));
69 b2.SetEdge(gfx::Point(110, 40), gfx::Point(120, 60));
70 expected_rect = gfx::Rect(
71 b1.edge_top_rounded().x(),
72 b1.edge_top_rounded().y(),
73 b2.edge_bottom_rounded().x() - b1.edge_top_rounded().x(),
74 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
75 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
76 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
78 // Non-vertical bounds: "/ \"
79 b1.SetEdge(gfx::Point(20, 30), gfx::Point(0, 40));
80 b2.SetEdge(gfx::Point(110, 30), gfx::Point(120, 40));
81 expected_rect = gfx::Rect(
82 b1.edge_bottom_rounded().x(),
83 b1.edge_top_rounded().y(),
84 b2.edge_bottom_rounded().x() - b1.edge_bottom_rounded().x(),
85 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y());
86 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
87 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
90 } // namespace ui