| Index: ui/views/widget/widget_unittest.cc
|
| diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc
|
| index 2dc6b24905329aa0161b25e356c131d4fd09103f..7eda1022b7b67d1e6a3a273221f63c792554e6c1 100644
|
| --- a/ui/views/widget/widget_unittest.cc
|
| +++ b/ui/views/widget/widget_unittest.cc
|
| @@ -2103,6 +2103,120 @@ TEST_F(WidgetTest, GestureBeginAndEndEvents) {
|
| widget->Close();
|
| }
|
|
|
| +// Tests that gesture events which should not be processed (because
|
| +// RootView::OnEventProcessingStarted() has marked them as handled) are not
|
| +// dispatched to any views.
|
| +TEST_F(WidgetTest, GestureEventNotProcessed) {
|
| + Widget* widget = CreateTopLevelNativeWidget();
|
| + widget->SetBounds(gfx::Rect(0, 0, 300, 300));
|
| +
|
| + // Define a hierarchy of four views (coordinates are in
|
| + // their parent coordinate space).
|
| + // v1 (0, 0, 300, 300)
|
| + // v2 (0, 0, 100, 100)
|
| + // v3 (0, 0, 50, 50)
|
| + // v4(0, 0, 10, 10)
|
| + EventCountView* v1 = new EventCountView();
|
| + v1->SetBounds(0, 0, 300, 300);
|
| + EventCountView* v2 = new EventCountView();
|
| + v2->SetBounds(0, 0, 100, 100);
|
| + EventCountView* v3 = new EventCountView();
|
| + v3->SetBounds(0, 0, 50, 50);
|
| + EventCountView* v4 = new EventCountView();
|
| + v4->SetBounds(0, 0, 10, 10);
|
| + internal::RootView* root_view =
|
| + static_cast<internal::RootView*>(widget->GetRootView());
|
| + root_view->AddChildView(v1);
|
| + v1->AddChildView(v2);
|
| + v2->AddChildView(v3);
|
| + v3->AddChildView(v4);
|
| +
|
| + widget->Show();
|
| +
|
| + // ui::ET_GESTURE_BEGIN events should never be seen by any view, but
|
| + // they should be marked as handled by OnEventProcessingStarted().
|
| + GestureEventForTest begin(ui::ET_GESTURE_BEGIN, 5, 5);
|
| + widget->OnGestureEvent(&begin);
|
| + EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_BEGIN));
|
| + EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_BEGIN));
|
| + EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_BEGIN));
|
| + EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_BEGIN));
|
| + EXPECT_EQ(NULL, GetGestureHandler(root_view));
|
| + EXPECT_TRUE(begin.handled());
|
| + v1->ResetCounts();
|
| + v2->ResetCounts();
|
| + v3->ResetCounts();
|
| + v4->ResetCounts();
|
| +
|
| + // ui::ET_GESTURE_END events not corresponding to the release of the
|
| + // final touch point should never be seen by any view, but they should
|
| + // be marked as handled by OnEventProcessingStarted().
|
| + ui::GestureEventDetails details(ui::ET_GESTURE_END, 5, 5);
|
| + details.set_touch_points(2);
|
| + GestureEventForTest end_second_touch_point(details, 5, 5);
|
| + widget->OnGestureEvent(&end_second_touch_point);
|
| + EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END));
|
| + EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END));
|
| + EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END));
|
| + EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END));
|
| + EXPECT_EQ(NULL, GetGestureHandler(root_view));
|
| + EXPECT_TRUE(end_second_touch_point.handled());
|
| + v1->ResetCounts();
|
| + v2->ResetCounts();
|
| + v3->ResetCounts();
|
| + v4->ResetCounts();
|
| +
|
| + // ui::ET_GESTURE_SCROLL_UPDATE events should never be seen by any view when
|
| + // there is no default gesture handler set, but they should be marked as
|
| + // handled by OnEventProcessingStarted().
|
| + GestureEventForTest scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, 5, 5);
|
| + widget->OnGestureEvent(&scroll_update);
|
| + EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
|
| + EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
|
| + EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
|
| + EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
|
| + EXPECT_EQ(NULL, GetGestureHandler(root_view));
|
| + EXPECT_TRUE(scroll_update.handled());
|
| + v1->ResetCounts();
|
| + v2->ResetCounts();
|
| + v3->ResetCounts();
|
| + v4->ResetCounts();
|
| +
|
| + // ui::ET_GESTURE_SCROLL_END events should never be seen by any view when
|
| + // there is no default gesture handler set, but they should be marked as
|
| + // handled by OnEventProcessingStarted().
|
| + GestureEventForTest scroll_end(ui::ET_GESTURE_SCROLL_END, 5, 5);
|
| + widget->OnGestureEvent(&scroll_end);
|
| + EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_SCROLL_END));
|
| + EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_SCROLL_END));
|
| + EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_SCROLL_END));
|
| + EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_SCROLL_END));
|
| + EXPECT_EQ(NULL, GetGestureHandler(root_view));
|
| + EXPECT_TRUE(scroll_end.handled());
|
| + v1->ResetCounts();
|
| + v2->ResetCounts();
|
| + v3->ResetCounts();
|
| + v4->ResetCounts();
|
| +
|
| + // ui::ET_SCROLL_FLING_START events should never be seen by any view when
|
| + // there is no default gesture handler set, but they should be marked as
|
| + // handled by OnEventProcessingStarted().
|
| + GestureEventForTest scroll_fling_start(ui::ET_SCROLL_FLING_START, 5, 5);
|
| + widget->OnGestureEvent(&scroll_fling_start);
|
| + EXPECT_EQ(0, v1->GetEventCount(ui::ET_SCROLL_FLING_START));
|
| + EXPECT_EQ(0, v2->GetEventCount(ui::ET_SCROLL_FLING_START));
|
| + EXPECT_EQ(0, v3->GetEventCount(ui::ET_SCROLL_FLING_START));
|
| + EXPECT_EQ(0, v4->GetEventCount(ui::ET_SCROLL_FLING_START));
|
| + EXPECT_EQ(NULL, GetGestureHandler(root_view));
|
| + EXPECT_TRUE(scroll_fling_start.handled());
|
| + v1->ResetCounts();
|
| + v2->ResetCounts();
|
| + v3->ResetCounts();
|
| + v4->ResetCounts();
|
| +
|
| + widget->Close();
|
| +}
|
| +
|
| // Tests that a (non-scroll) gesture event is dispatched to the correct views
|
| // in a view hierarchy and that the default gesture handler in RootView is set
|
| // correctly.
|
|
|