Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: ui/gfx/selection_bound_unittest.cc

Issue 2034863002: Move SelectionBound from ui/base/touch to ui/gfx to be used by cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated views_unittests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/selection_bound.cc ('k') | ui/touch_selection/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gfx/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 gfx {
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::PointF(0.f, 20.f), gfx::PointF(0.f, 25.f)); 15 b1.SetEdge(gfx::PointF(0.f, 20.f), gfx::PointF(0.f, 25.f));
16 b2.SetEdge(gfx::PointF(110.f, 20.f), gfx::PointF(110.f, 25.f)); 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(), b1.edge_top_rounded().y(),
19 b1.edge_top_rounded().y(),
20 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), 19 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
21 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); 20 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y());
22 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); 21 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
23 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); 22 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
24 23
25 // Parallel vertical bounds of different heights 24 // Parallel vertical bounds of different heights
26 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 25.f)); 25 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 25.f));
27 b2.SetEdge(gfx::PointF(110.f, 0.f), gfx::PointF(110.f, 35.f)); 26 b2.SetEdge(gfx::PointF(110.f, 0.f), gfx::PointF(110.f, 35.f));
28 expected_rect = gfx::Rect( 27 expected_rect =
29 b1.edge_top_rounded().x(), 28 gfx::Rect(b1.edge_top_rounded().x(), b2.edge_top_rounded().y(),
30 b2.edge_top_rounded().y(), 29 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
31 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), 30 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)); 31 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
34 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); 32 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
35 33
36 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); 34 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f));
37 b2.SetEdge(gfx::PointF(110.f, 25.f), gfx::PointF(110.f, 45.f)); 35 b2.SetEdge(gfx::PointF(110.f, 25.f), gfx::PointF(110.f, 45.f));
38 expected_rect = gfx::Rect( 36 expected_rect =
39 b1.edge_top_rounded().x(), 37 gfx::Rect(b1.edge_top_rounded().x(), b1.edge_top_rounded().y(),
40 b1.edge_top_rounded().y(), 38 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
41 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), 39 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)); 40 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
44 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); 41 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
45 42
46 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); 43 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f));
47 b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(110.f, 60.f)); 44 b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(110.f, 60.f));
48 expected_rect = gfx::Rect( 45 expected_rect =
49 b1.edge_top_rounded().x(), 46 gfx::Rect(b1.edge_top_rounded().x(), b1.edge_top_rounded().y(),
50 b1.edge_top_rounded().y(), 47 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
51 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), 48 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)); 49 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
54 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); 50 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
55 51
56 // Overlapping vertical bounds 52 // Overlapping vertical bounds
57 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); 53 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f));
58 b2.SetEdge(gfx::PointF(10.f, 25.f), gfx::PointF(10.f, 40.f)); 54 b2.SetEdge(gfx::PointF(10.f, 25.f), gfx::PointF(10.f, 40.f));
59 expected_rect = gfx::Rect( 55 expected_rect =
60 b1.edge_top_rounded().x(), 56 gfx::Rect(b1.edge_top_rounded().x(), b1.edge_top_rounded().y(), 0,
61 b1.edge_top_rounded().y(), 57 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
62 0,
63 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
64 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); 58 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
65 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); 59 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
66 60
67 // Non-vertical bounds: "\ \" 61 // Non-vertical bounds: "\ \"
68 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(20.f, 30.f)); 62 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(20.f, 30.f));
69 b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(120.f, 60.f)); 63 b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(120.f, 60.f));
70 expected_rect = gfx::Rect( 64 expected_rect =
71 b1.edge_top_rounded().x(), 65 gfx::Rect(b1.edge_top_rounded().x(), b1.edge_top_rounded().y(),
72 b1.edge_top_rounded().y(), 66 b2.edge_bottom_rounded().x() - b1.edge_top_rounded().x(),
73 b2.edge_bottom_rounded().x() - b1.edge_top_rounded().x(), 67 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)); 68 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
76 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); 69 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
77 70
78 // Non-vertical bounds: "/ \" 71 // Non-vertical bounds: "/ \"
79 b1.SetEdge(gfx::PointF(20.f, 30.f), gfx::PointF(0.f, 40.f)); 72 b1.SetEdge(gfx::PointF(20.f, 30.f), gfx::PointF(0.f, 40.f));
80 b2.SetEdge(gfx::PointF(110.f, 30.f), gfx::PointF(120.f, 40.f)); 73 b2.SetEdge(gfx::PointF(110.f, 30.f), gfx::PointF(120.f, 40.f));
81 expected_rect = gfx::Rect( 74 expected_rect =
82 b1.edge_bottom_rounded().x(), 75 gfx::Rect(b1.edge_bottom_rounded().x(), b1.edge_top_rounded().y(),
83 b1.edge_top_rounded().y(), 76 b2.edge_bottom_rounded().x() - b1.edge_bottom_rounded().x(),
84 b2.edge_bottom_rounded().x() - b1.edge_bottom_rounded().x(), 77 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)); 78 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
87 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); 79 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
88 } 80 }
89 81
90 } // namespace ui 82 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/selection_bound.cc ('k') | ui/touch_selection/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698