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..bd3d0ea318e08c70cf22f82066ee8653b747c88f 100644 |
--- a/ui/views/widget/widget_unittest.cc |
+++ b/ui/views/widget/widget_unittest.cc |
@@ -2103,6 +2103,115 @@ TEST_F(WidgetTest, GestureBeginAndEndEvents) { |
widget->Close(); |
} |
+// Tests that gesture events which should not be processed (because |
+// RootView::OnEventProcessingStarted() has returned false) 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 processed. |
+ 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_FALSE(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 processed. |
+ 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_FALSE(end_second_touch_point.handled()); |
+ v1->ResetCounts(); |
+ v2->ResetCounts(); |
+ v3->ResetCounts(); |
+ v4->ResetCounts(); |
+ |
+ // ui::ET_GESTURE_SCROLL_UPDATE events should never be processed when there |
+ // is no default gesture handler set. |
+ 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_FALSE(scroll_update.handled()); |
+ v1->ResetCounts(); |
+ v2->ResetCounts(); |
+ v3->ResetCounts(); |
+ v4->ResetCounts(); |
+ |
+ // ui::ET_GESTURE_SCROLL_END events should never be processed when there |
+ // is no default gesture handler set. |
+ 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_FALSE(scroll_end.handled()); |
+ v1->ResetCounts(); |
+ v2->ResetCounts(); |
+ v3->ResetCounts(); |
+ v4->ResetCounts(); |
+ |
+ // ui::ET_SCROLL_FLING_START events should never be processed when there |
+ // is no default gesture handler set. |
+ 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_FALSE(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. |