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