blob: 8feebc4d73def12aea465b2c615eb69da56da2e1 [file] [log] [blame]
mohsenf837da7c2014-12-09 19:01:341// 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
fsamuel181cbc02016-06-03 02:31:145#include "ui/gfx/selection_bound.h"
mohsenf837da7c2014-12-09 19:01:346
7#include "testing/gtest/include/gtest/gtest.h"
tfarina3b0452d2014-12-31 15:20:098#include "ui/gfx/geometry/rect.h"
mohsenf837da7c2014-12-09 19:01:349
fsamuel181cbc02016-06-03 02:31:1410namespace gfx {
mohsenf837da7c2014-12-09 19:01:3411
12TEST(SelectionBoundTest, RectBetweenSelectionBounds) {
13 SelectionBound b1, b2;
14 // Simple case of aligned vertical bounds of equal height
danakj089746f2015-11-02 22:52:3315 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));
mohsenf837da7c2014-12-09 19:01:3417 gfx::Rect expected_rect(
fsamuel181cbc02016-06-03 02:31:1418 b1.edge_top_rounded().x(), b1.edge_top_rounded().y(),
mohsenf837da7c2014-12-09 19:01:3419 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
20 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y());
21 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
22 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
23
24 // Parallel vertical bounds of different heights
danakj089746f2015-11-02 22:52:3325 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 25.f));
26 b2.SetEdge(gfx::PointF(110.f, 0.f), gfx::PointF(110.f, 35.f));
fsamuel181cbc02016-06-03 02:31:1427 expected_rect =
28 gfx::Rect(b1.edge_top_rounded().x(), b2.edge_top_rounded().y(),
29 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
30 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y());
mohsenf837da7c2014-12-09 19:01:3431 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
32 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
33
danakj089746f2015-11-02 22:52:3334 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f));
35 b2.SetEdge(gfx::PointF(110.f, 25.f), gfx::PointF(110.f, 45.f));
fsamuel181cbc02016-06-03 02:31:1436 expected_rect =
37 gfx::Rect(b1.edge_top_rounded().x(), b1.edge_top_rounded().y(),
38 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
39 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
mohsenf837da7c2014-12-09 19:01:3440 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
41 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
42
danakj089746f2015-11-02 22:52:3343 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f));
44 b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(110.f, 60.f));
fsamuel181cbc02016-06-03 02:31:1445 expected_rect =
46 gfx::Rect(b1.edge_top_rounded().x(), b1.edge_top_rounded().y(),
47 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
48 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
mohsenf837da7c2014-12-09 19:01:3449 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
50 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
51
52 // Overlapping vertical bounds
danakj089746f2015-11-02 22:52:3353 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f));
54 b2.SetEdge(gfx::PointF(10.f, 25.f), gfx::PointF(10.f, 40.f));
fsamuel181cbc02016-06-03 02:31:1455 expected_rect =
56 gfx::Rect(b1.edge_top_rounded().x(), b1.edge_top_rounded().y(), 0,
57 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
mohsenf837da7c2014-12-09 19:01:3458 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
59 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
60
61 // Non-vertical bounds: "\ \"
danakj089746f2015-11-02 22:52:3362 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(20.f, 30.f));
63 b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(120.f, 60.f));
fsamuel181cbc02016-06-03 02:31:1464 expected_rect =
65 gfx::Rect(b1.edge_top_rounded().x(), b1.edge_top_rounded().y(),
66 b2.edge_bottom_rounded().x() - b1.edge_top_rounded().x(),
67 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
mohsenf837da7c2014-12-09 19:01:3468 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
69 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
70
71 // Non-vertical bounds: "/ \"
danakj089746f2015-11-02 22:52:3372 b1.SetEdge(gfx::PointF(20.f, 30.f), gfx::PointF(0.f, 40.f));
73 b2.SetEdge(gfx::PointF(110.f, 30.f), gfx::PointF(120.f, 40.f));
fsamuel181cbc02016-06-03 02:31:1474 expected_rect =
75 gfx::Rect(b1.edge_bottom_rounded().x(), b1.edge_top_rounded().y(),
76 b2.edge_bottom_rounded().x() - b1.edge_bottom_rounded().x(),
77 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y());
mohsenf837da7c2014-12-09 19:01:3478 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
79 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
80}
81
fsamuel181cbc02016-06-03 02:31:1482} // namespace gfx