| Index: ui/views/view_targeter_unittest.cc
|
| diff --git a/ui/views/view_targeter_unittest.cc b/ui/views/view_targeter_unittest.cc
|
| index fa851f083023e99e2f20937c9fb3174c462b9fda..62adec8e82803d9e8cea3c72e5bd0759d3551cfd 100644
|
| --- a/ui/views/view_targeter_unittest.cc
|
| +++ b/ui/views/view_targeter_unittest.cc
|
| @@ -78,6 +78,22 @@ namespace test {
|
|
|
| typedef ViewsTestBase ViewTargeterTest;
|
|
|
| +namespace {
|
| +
|
| +gfx::Point ConvertPointToView(View* view, const gfx::Point& p) {
|
| + gfx::Point tmp(p);
|
| + View::ConvertPointToTarget(view->GetWidget()->GetRootView(), view, &tmp);
|
| + return tmp;
|
| +}
|
| +
|
| +gfx::Rect ConvertRectToView(View* view, const gfx::Rect& r) {
|
| + gfx::Rect tmp(r);
|
| + tmp.set_origin(ConvertPointToView(view, r.origin()));
|
| + return tmp;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| // Verifies that the the functions ViewTargeter::FindTargetForEvent()
|
| // and ViewTargeter::FindNextBestTarget() are implemented correctly
|
| // for key events.
|
| @@ -388,5 +404,80 @@ TEST_F(ViewTargeterTest, DoesIntersectRect) {
|
| gfx::Rect(-20, -20, 10, 10)));
|
| }
|
|
|
| +// Tests that calls made directly on the hit-testing methods in View
|
| +// (HitTestPoint(), HitTestRect(), etc.) return the correct values.
|
| +TEST_F(ViewTargeterTest, HitTestCallsOnView) {
|
| + // The coordinates in this test are in the coordinate space of the root view.
|
| + Widget* widget = new Widget;
|
| + Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
|
| + widget->Init(params);
|
| + View* root_view = widget->GetRootView();
|
| + root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500));
|
| +
|
| + // |v1| has no hit test mask. No ViewTargeter is installed on |v1|, which
|
| + // means that View::HitTestRect() will call into the targeter installed on
|
| + // the root view instead when we hit test against |v1|.
|
| + gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100);
|
| + TestingView* v1 = new TestingView();
|
| + v1->SetBoundsRect(v1_bounds);
|
| + root_view->AddChildView(v1);
|
| +
|
| + // |v2| has a triangular hit test mask. Install a ViewTargeter on |v2| which
|
| + // will be called into by View::HitTestRect().
|
| + gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100);
|
| + TestMaskedView* v2 = new TestMaskedView();
|
| + v2->SetBoundsRect(v2_bounds);
|
| + root_view->AddChildView(v2);
|
| + ViewTargeter* view_targeter = new ViewTargeter(v2);
|
| + v2->SetEventTargeter(make_scoped_ptr(view_targeter));
|
| +
|
| + gfx::Point v1_centerpoint = v1_bounds.CenterPoint();
|
| + gfx::Point v2_centerpoint = v2_bounds.CenterPoint();
|
| + gfx::Point v1_origin = v1_bounds.origin();
|
| + gfx::Point v2_origin = v2_bounds.origin();
|
| + 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 calls into View::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)));
|
| +
|
| + // Test calls into View::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 calls into View::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));
|
| +
|
| + // Test calls into View::GetTooltipHandlerForPoint().
|
| + EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_centerpoint));
|
| + EXPECT_EQ(v2, root_view->GetTooltipHandlerForPoint(v2_centerpoint));
|
| +
|
| + EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin));
|
| + EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin));
|
| +
|
| + EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin));
|
| +
|
| + widget->CloseNow();
|
| +}
|
| +
|
| } // namespace test
|
| } // namespace views
|
|
|