Index: ui/views/widget/widget_unittest.cc |
diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc |
index e006e068aae4f74568a33c440149b9647211d1df..60607acb8819348e7e93a33994a9474134ac6780 100644 |
--- a/ui/views/widget/widget_unittest.cc |
+++ b/ui/views/widget/widget_unittest.cc |
@@ -3193,6 +3193,84 @@ TEST_F(WidgetTest, MouseEventTypesViaGenerator) { |
widget->CloseNow(); |
} |
+// Tests that a view does not receive entered, dragged, or moved events if |
+// a mouse cursor is moved into it while the left mouse button is pressed. |
+TEST_F(WidgetTest, DragIntoView) { |
+ EventCountView* container = new EventCountView; |
+ container->SetBounds(0, 0, 100, 80); |
+ |
+ EventCountView* consume_view = new EventCountView; |
+ consume_view->set_handle_mode(EventCountView::CONSUME_EVENTS); |
+ consume_view->SetBounds(10, 10, 50, 40); |
+ |
+ Widget* widget = CreateTopLevelFramelessPlatformWidget(); |
+ widget->SetBounds(gfx::Rect(0, 0, 100, 80)); |
+ widget->SetContentsView(container); |
+ container->AddChildView(consume_view); |
+ |
+ widget->Show(); |
+ |
+ ui::test::EventGenerator generator(GetContext(), widget->GetNativeWindow()); |
+ generator.set_current_location(gfx::Point(75, 15)); |
+ |
+ generator.PressLeftButton(); |
+ generator.MoveMouseTo(gfx::Point(20, 20)); |
+ EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_ENTERED)); |
+ EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_DRAGGED)); |
+ EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_MOVED)); |
+ |
+ widget->CloseNow(); |
+} |
+ |
+// Tests that a view receives the correct mouse events if a mouse cursor |
+// is moved out of its bounds while the left mouse button is pressed. |
+TEST_F(WidgetTest, DragOutOfView) { |
+ EventCountView* container = new EventCountView; |
+ container->SetBounds(0, 0, 100, 80); |
+ |
+ EventCountView* consume_view = new EventCountView; |
+ consume_view->set_handle_mode(EventCountView::CONSUME_EVENTS); |
+ consume_view->SetBounds(10, 10, 50, 40); |
+ |
+ Widget* widget = CreateTopLevelFramelessPlatformWidget(); |
+ widget->SetBounds(gfx::Rect(0, 0, 100, 80)); |
+ widget->SetContentsView(container); |
+ container->AddChildView(consume_view); |
+ |
+ widget->Show(); |
+ |
+ ui::test::EventGenerator generator(GetContext(), widget->GetNativeWindow()); |
+ generator.set_current_location(gfx::Point(20, 20)); |
+ |
+ generator.PressLeftButton(); |
+ EXPECT_EQ(1, consume_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
+ EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_PRESSED)); |
+ consume_view->ResetCounts(); |
+ |
+ generator.MoveMouseTo(gfx::Point(70, 70)); |
+ EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_EXITED)); |
+ EXPECT_EQ(1, consume_view->GetEventCount(ui::ET_MOUSE_DRAGGED)); |
+ EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_MOVED)); |
+ EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_ENTERED)); |
+ EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_DRAGGED)); |
+ EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_MOVED)); |
+ consume_view->ResetCounts(); |
+ |
+ generator.MoveMouseTo(gfx::Point(71, 71)); |
+ EXPECT_EQ(1, consume_view->GetEventCount(ui::ET_MOUSE_DRAGGED)); |
+ EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_MOVED)); |
+ EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_DRAGGED)); |
+ EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_MOVED)); |
+ consume_view->ResetCounts(); |
+ |
+ generator.ReleaseLeftButton(); |
+ EXPECT_EQ(1, consume_view->GetEventCount(ui::ET_MOUSE_RELEASED)); |
+ EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_RELEASED)); |
sadrul
2014/09/26 20:59:13
Should we be sending an EXIT event here?
tdanderson
2014/09/29 18:38:13
From what I can see, we don't send an EXIT on ToT
|
+ consume_view->ResetCounts(); |
+ |
+ widget->CloseNow(); |
+} |
+ |
// Tests that the root view is correctly set up for Widget types that do not |
// require a non-client view, before any other views are added to the widget. |
// That is, before Widget::ReorderNativeViews() is called which, if called with |