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

Unified Diff: ui/views/view_unittest.cc

Issue 10827198: Change View::HitTest to View::HitTestRect (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Revised patch with tests added Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 876a7712f90a7bc96f1ad4178902229af2dc3b36..5e75e2aa02bc769ba42d5c4d4293b6e4df1eb624 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -944,6 +944,12 @@ gfx::Point ConvertPointToView(View* view, const gfx::Point& p) {
return tmp;
}
+gfx::Rect ConvertRectToView(View* view, const gfx::Rect& r) {
+ gfx::Rect tmp(r);
+ tmp.set_origin(ConvertPointToView(view, r.origin()));
+ return tmp;
+}
+
void RotateCounterclockwise(ui::Transform* transform) {
transform->matrix().set3x3(0, -1, 0,
1, 0, 0,
@@ -979,16 +985,35 @@ TEST_F(ViewTest, HitTestMasks) {
gfx::Point v1_origin = v1_bounds.origin();
gfx::Point v2_origin = v2_bounds.origin();
- // Test HitTest
- EXPECT_TRUE(v1->HitTest(ConvertPointToView(v1, v1_centerpoint)));
- EXPECT_TRUE(v2->HitTest(ConvertPointToView(v2, v2_centerpoint)));
+ gfx::Rect r1(10, 10, 110, 15);
+ gfx::Rect r2(106, 1, 98, 98);
+ gfx::Rect r3(0, 0, 300, 300);
+ gfx::Rect r4(115, 342, 200, 10);
+
+ // Test HitTestPoint
+ EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_centerpoint)));
+ EXPECT_TRUE(v2->HitTestPoint(ConvertPointToView(v2, v2_centerpoint)));
+
+ EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_origin)));
+ EXPECT_FALSE(v2->HitTestPoint(ConvertPointToView(v2, v2_origin)));
- EXPECT_TRUE(v1->HitTest(ConvertPointToView(v1, v1_origin)));
- EXPECT_FALSE(v2->HitTest(ConvertPointToView(v2, v2_origin)));
+ // Test HitTestRect
+ EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r1)));
+ EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r1)));
+
+ EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r2)));
+ EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r2)));
+
+ EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r3)));
+ EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r3)));
+
+ EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r4)));
+ EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r4)));
// Test GetEventHandlerForPoint
EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_centerpoint));
EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint));
+
EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin));
EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin));
« ui/views/view.h ('K') | « ui/views/view.cc ('k') | ui/views/window/non_client_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698