summaryrefslogtreecommitdiffstats
path: root/ui/views/view_targeter_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ui/views/view_targeter_unittest.cc')
-rw-r--r--ui/views/view_targeter_unittest.cc134
1 files changed, 0 insertions, 134 deletions
diff --git a/ui/views/view_targeter_unittest.cc b/ui/views/view_targeter_unittest.cc
index e6f7eeb..5757793 100644
--- a/ui/views/view_targeter_unittest.cc
+++ b/ui/views/view_targeter_unittest.cc
@@ -208,140 +208,6 @@ TEST_F(ViewTargeterTest, ViewTargeterForScrollEvents) {
EXPECT_EQ(content, static_cast<View*>(current_target));
}
-// Tests the basic functionality of the method
-// ViewTargeter::SubtreeShouldBeExploredForEvent().
-TEST_F(ViewTargeterTest, SubtreeShouldBeExploredForEvent) {
- Widget widget;
- Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
- params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- params.bounds = gfx::Rect(0, 0, 650, 650);
- widget.Init(params);
-
- internal::RootView* root_view =
- static_cast<internal::RootView*>(widget.GetRootView());
- ViewTargeter* targeter = new ViewTargeter(root_view);
- root_view->SetEventTargeter(make_scoped_ptr(targeter));
-
- // The coordinates used for SetBounds() are in the parent coordinate space.
- View v1, v2, v3;
- v1.SetBounds(0, 0, 300, 300);
- v2.SetBounds(100, 100, 100, 100);
- v3.SetBounds(0, 0, 10, 10);
- v3.SetVisible(false);
- root_view->AddChildView(&v1);
- v1.AddChildView(&v2);
- v2.AddChildView(&v3);
-
- // Note that the coordinates used below are in |v1|'s coordinate space,
- // and that SubtreeShouldBeExploredForEvent() expects the event location
- // to be in the coordinate space of the target's parent. |v1| and
- // its parent share a common coordinate space.
-
- // Event located within |v1| only.
- gfx::Point point(10, 10);
- ui::MouseEvent event(ui::ET_MOUSE_PRESSED, point, point,
- ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
- EXPECT_TRUE(targeter->SubtreeShouldBeExploredForEvent(&v1, event));
- EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(&v2, event));
- v1.ConvertEventToTarget(&v2, &event);
- EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(&v3, event));
-
- // Event located within |v1| and |v2| only.
- event.set_location(gfx::Point(150, 150));
- EXPECT_TRUE(targeter->SubtreeShouldBeExploredForEvent(&v1, event));
- EXPECT_TRUE(targeter->SubtreeShouldBeExploredForEvent(&v2, event));
- v1.ConvertEventToTarget(&v2, &event);
- EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(&v3, event));
-
- // Event located within |v1|, |v2|, and |v3|. Note that |v3| is not
- // visible, so it cannot handle the event.
- event.set_location(gfx::Point(105, 105));
- EXPECT_TRUE(targeter->SubtreeShouldBeExploredForEvent(&v1, event));
- EXPECT_TRUE(targeter->SubtreeShouldBeExploredForEvent(&v2, event));
- v1.ConvertEventToTarget(&v2, &event);
- EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(&v3, event));
-
- // Event located outside the bounds of all views.
- event.set_location(gfx::Point(400, 400));
- EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(&v1, event));
- EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(&v2, event));
- v1.ConvertEventToTarget(&v2, &event);
- EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(&v3, event));
-}
-
-// Tests that FindTargetForEvent() returns the correct target when some
-// views in the view tree return false when CanProcessEventsWithinSubtree()
-// is called on them.
-TEST_F(ViewTargeterTest, CanProcessEventsWithinSubtree) {
- Widget widget;
- Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
- params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- params.bounds = gfx::Rect(0, 0, 650, 650);
- widget.Init(params);
-
- internal::RootView* root_view =
- static_cast<internal::RootView*>(widget.GetRootView());
- ViewTargeter* view_targeter = new ViewTargeter(root_view);
- ui::EventTargeter* targeter = view_targeter;
- root_view->SetEventTargeter(make_scoped_ptr(view_targeter));
-
- // The coordinates used for SetBounds() are in the parent coordinate space.
- TestingView v1, v2, v3;
- v1.SetBounds(0, 0, 300, 300);
- v2.SetBounds(100, 100, 100, 100);
- v3.SetBounds(0, 0, 10, 10);
- root_view->AddChildView(&v1);
- v1.AddChildView(&v2);
- v2.AddChildView(&v3);
-
- // Note that the coordinates used below are in the coordinate space of
- // the root view.
-
- // Define |scroll| to be (105, 105) (in the coordinate space of the root
- // view). This is located within all of |v1|, |v2|, and |v3|.
- gfx::Point scroll_point(105, 105);
- ui::ScrollEvent scroll(
- ui::ET_SCROLL, scroll_point, ui::EventTimeForNow(), 0, 0, 3, 0, 3, 2);
-
- // If CanProcessEventsWithinSubtree() returns true for each view,
- // |scroll| should be targeted at the deepest view in the hierarchy,
- // which is |v3|.
- ui::EventTarget* current_target =
- targeter->FindTargetForEvent(root_view, &scroll);
- EXPECT_EQ(&v3, current_target);
-
- // If CanProcessEventsWithinSubtree() returns |false| when called
- // on |v3|, then |v3| cannot be the target of |scroll| (this should
- // instead be |v2|). Note we need to reset the location of |scroll|
- // because it may have been mutated by the previous call to
- // FindTargetForEvent().
- scroll.set_location(scroll_point);
- v3.set_can_process_events_within_subtree(false);
- current_target = targeter->FindTargetForEvent(root_view, &scroll);
- EXPECT_EQ(&v2, current_target);
-
- // If CanProcessEventsWithinSubtree() returns |false| when called
- // on |v2|, then neither |v2| nor |v3| can be the target of |scroll|
- // (this should instead be |v1|).
- scroll.set_location(scroll_point);
- v3.Reset();
- v2.set_can_process_events_within_subtree(false);
- current_target = targeter->FindTargetForEvent(root_view, &scroll);
- EXPECT_EQ(&v1, current_target);
-
- // If CanProcessEventsWithinSubtree() returns |false| when called
- // on |v1|, then none of |v1|, |v2| or |v3| can be the target of |scroll|
- // (this should instead be the root view itself).
- scroll.set_location(scroll_point);
- v2.Reset();
- v1.set_can_process_events_within_subtree(false);
- current_target = targeter->FindTargetForEvent(root_view, &scroll);
- EXPECT_EQ(root_view, current_target);
-
- // TODO(tdanderson): We should also test that targeting works correctly
- // with gestures. See crbug.com/375822.
-}
-
// Tests that the functions ViewTargeterDelegate::DoesIntersectRect()
// and MaskedTargeterDelegate::DoesIntersectRect() work as intended when
// called on views which are derived from ViewTargeterDelegate.