Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: ui/views/widget/widget_unittest.cc

Issue 1297373004: Don't synthesize mousemove events if the mouse cursor is not on the widget (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Query the mouse location instead of caching Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/widget_unittest.cc
diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc
index 08e15d5a724a563d6c8958fe083175a05c8e4dee..b6a18a94f675921c4f4f6c2607aa01ddf69fdb27 100644
--- a/ui/views/widget/widget_unittest.cc
+++ b/ui/views/widget/widget_unittest.cc
@@ -1697,28 +1697,44 @@ TEST_F(WidgetTest, EventHandlersOnRootView) {
TEST_F(WidgetTest, SynthesizeMouseMoveEvent) {
Widget* widget = CreateTopLevelNativeWidget();
View* root_view = widget->GetRootView();
+ root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500));
EventCountView* v1 = new EventCountView();
- v1->SetBounds(0, 0, 10, 10);
+ v1->SetBounds(5, 5, 10, 10);
root_view->AddChildView(v1);
EventCountView* v2 = new EventCountView();
- v2->SetBounds(0, 10, 10, 10);
+ v2->SetBounds(5, 15, 10, 10);
root_view->AddChildView(v2);
+ widget->Show();
+
+ // SynthesizeMouseMoveEvent does nothing until the mouse is entered.
+ widget->SynthesizeMouseMoveEvent();
+ EXPECT_EQ(0, v1->GetEventCount(ui::ET_MOUSE_MOVED));
+ EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED));
+
gfx::Point cursor_location(5, 5);
+ View::ConvertPointToScreen(widget->GetRootView(), &cursor_location);
ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location,
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
- widget->OnMouseEvent(&move);
+ ui::EventDispatchDetails details =
+ WidgetTest::GetEventProcessor(widget)->OnEventFromSource(&move);
+ EXPECT_FALSE(details.dispatcher_destroyed);
+
+ EXPECT_EQ(1, v1->GetEventCount(ui::ET_MOUSE_MOVED));
+ EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED));
- EXPECT_EQ(1, v1->GetEventCount(ui::ET_MOUSE_ENTERED));
- EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_ENTERED));
+ // SynthesizeMouseMoveEvent dispatches an mousemove event.
+ widget->SynthesizeMouseMoveEvent();
+ EXPECT_EQ(2, v1->GetEventCount(ui::ET_MOUSE_MOVED));
delete v1;
- v2->SetBounds(0, 0, 10, 10);
- EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_ENTERED));
+ EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED));
+ v2->SetBounds(5, 5, 10, 10);
+ EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED));
widget->SynthesizeMouseMoveEvent();
- EXPECT_EQ(1, v2->GetEventCount(ui::ET_MOUSE_ENTERED));
+ EXPECT_EQ(1, v2->GetEventCount(ui::ET_MOUSE_MOVED));
widget->CloseNow();
}
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698