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

Unified Diff: ui/base/touch/selection_bound_unittest.cc

Issue 759433002: Reland: Move TouchSelectionController from content to ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for ios build and some typos Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: ui/base/touch/selection_bound_unittest.cc
diff --git a/ui/base/touch/selection_bound_unittest.cc b/ui/base/touch/selection_bound_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e3bd997c508f39343f1cc70f5a251314b6a46350
--- /dev/null
+++ b/ui/base/touch/selection_bound_unittest.cc
@@ -0,0 +1,103 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/touch/selection_bound.h"
+
+#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.
+
+namespace ui {
+
+TEST(SelectionBoundTest, RectBetweenSelectionBounds) {
+ SelectionBound b1, b2;
+ // Simple case of aligned vertical bounds of equal height
+ b1.SetEdgeTop(gfx::Point(0, 20));
+ b1.SetEdgeBottom(gfx::Point(0, 25));
+ b2.SetEdgeTop(gfx::Point(110, 20));
+ b2.SetEdgeBottom(gfx::Point(110, 25));
+ gfx::Rect expected_rect(
+ b1.edge_top_rounded().x(),
+ b1.edge_top_rounded().y(),
+ b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
+ b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y());
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
+
+ // Parallel vertical bounds of different heights
+ b1.SetEdgeTop(gfx::Point(10, 20));
+ b1.SetEdgeBottom(gfx::Point(10, 25));
+ b2.SetEdgeTop(gfx::Point(110, 0));
+ b2.SetEdgeBottom(gfx::Point(110, 35));
+ expected_rect = gfx::Rect(
+ b1.edge_top_rounded().x(),
+ b2.edge_top_rounded().y(),
+ b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
+ b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y());
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
+
+ b1.SetEdgeTop(gfx::Point(10, 20));
+ b1.SetEdgeBottom(gfx::Point(10, 30));
+ b2.SetEdgeTop(gfx::Point(110, 25));
+ b2.SetEdgeBottom(gfx::Point(110, 45));
+ expected_rect = gfx::Rect(
+ b1.edge_top_rounded().x(),
+ b1.edge_top_rounded().y(),
+ b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
+ b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
+
+ b1.SetEdgeTop(gfx::Point(10, 20));
+ b1.SetEdgeBottom(gfx::Point(10, 30));
+ b2.SetEdgeTop(gfx::Point(110, 40));
+ b2.SetEdgeBottom(gfx::Point(110, 60));
+ expected_rect = gfx::Rect(
+ b1.edge_top_rounded().x(),
+ b1.edge_top_rounded().y(),
+ b2.edge_top_rounded().x() - b1.edge_top_rounded().x(),
+ b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
+
+ // Overlapping vertical bounds
+ b1.SetEdgeTop(gfx::Point(10, 20));
+ b1.SetEdgeBottom(gfx::Point(10, 30));
+ b2.SetEdgeTop(gfx::Point(10, 25));
+ b2.SetEdgeBottom(gfx::Point(10, 40));
+ expected_rect = gfx::Rect(
+ b1.edge_top_rounded().x(),
+ b1.edge_top_rounded().y(),
+ 0,
+ b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
+
+ // Non-vertical bounds: "\ \"
+ b1.SetEdgeTop(gfx::Point(10, 20));
+ b1.SetEdgeBottom(gfx::Point(20, 30));
+ b2.SetEdgeTop(gfx::Point(110, 40));
+ b2.SetEdgeBottom(gfx::Point(120, 60));
+ expected_rect = gfx::Rect(
+ b1.edge_top_rounded().x(),
+ b1.edge_top_rounded().y(),
+ b2.edge_bottom_rounded().x() - b1.edge_top_rounded().x(),
+ b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y());
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
+
+ // Non-vertical bounds: "/ \"
+ b1.SetEdgeTop(gfx::Point(20, 30));
+ b1.SetEdgeBottom(gfx::Point(0, 40));
+ b2.SetEdgeTop(gfx::Point(110, 30));
+ b2.SetEdgeBottom(gfx::Point(120, 40));
+ expected_rect = gfx::Rect(
+ b1.edge_bottom_rounded().x(),
+ b1.edge_top_rounded().y(),
+ b2.edge_bottom_rounded().x() - b1.edge_bottom_rounded().x(),
+ b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y());
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2));
+ EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1));
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698