Chromium Code Reviews| Index: ui/views/controls/menu/menu_runner_unittest.cc |
| diff --git a/ui/views/controls/menu/menu_runner_unittest.cc b/ui/views/controls/menu/menu_runner_unittest.cc |
| index 6d76f7e92e2e718e7045cec79f8d6581bfb3712a..4056dc31a92e8c44ad1d2aa36752b45cd7a4b84a 100644 |
| --- a/ui/views/controls/menu/menu_runner_unittest.cc |
| +++ b/ui/views/controls/menu/menu_runner_unittest.cc |
| @@ -254,6 +254,63 @@ TEST_F(MenuRunnerTest, WidgetDoesntTakeCapture) { |
| widget->CloseNow(); |
| } |
| +// Tests that after showing a menu on mouse press, that the subsequent mouse |
| +// will be delivered to the correct view, and not to the one that shown the |
|
tapted
2016/10/27 23:19:24
nit: shown -> showed (or `has shown` - English gra
themblsha
2016/10/29 13:47:19
Done.
|
| +// menu. |
| +// |
| +// The original bug is reproducible only when showing the menu on mouse press, |
| +// as RootView::OnMouseReleased() doesn't have the same behavior. |
| +TEST_F(MenuRunnerTest, ClearsMouseHandlerOnRun) { |
| + Widget* widget = new Widget; |
| + Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| + widget->Init(params); |
| + widget->Show(); |
| + widget->SetSize(gfx::Size(200, 100)); |
| + |
| + // Create a view that will show a menu on press. |
| + EventCountView* event_count_view = new EventCountView(); |
| + event_count_view->SetBounds(0, 0, 100, 100); |
| + widget->GetRootView()->AddChildView(event_count_view); |
| + |
| + InitMenuRunner(MenuRunner::ASYNC); |
|
tapted
2016/10/27 23:19:24
I think this will make a MenuRunnerImpl on Mac, so
themblsha
2016/10/29 13:47:19
Yeah, it's non-Cocoa but tests a common code path
|
| + MenuRunner* runner = menu_runner(); |
| + |
| + MenuLauncherEventHandler consumer(runner, widget); |
| + event_count_view->AddPostTargetHandler(&consumer); |
|
tapted
2016/10/27 23:19:24
everything above is copy-paste from WidgetDoesntTa
themblsha
2016/10/29 13:47:19
Thanks for the name :-)
|
| + |
| + // Create a second view that's supposed to get the second mouse press. |
| + EventCountView* second_event_count_view = new EventCountView(); |
| + second_event_count_view->SetBounds(100, 0, 100, 100); |
| + widget->GetRootView()->AddChildView(second_event_count_view); |
| + |
| + // Click on the first view to show the menu. |
| + std::unique_ptr<ui::test::EventGenerator> generator( |
| + new ui::test::EventGenerator( |
| + IsMus() ? widget->GetNativeWindow() : GetContext(), |
| + widget->GetNativeWindow())); |
| + generator->MoveMouseTo(gfx::Point(50, 50)); |
| + generator->PressLeftButton(); |
| + |
| + // Pretend we dismissed the menu using normal means, as it doesn't matter. |
| + EXPECT_TRUE(runner->IsRunning()); |
| + runner->Cancel(); |
| + |
|
tapted
2016/10/27 23:19:24
EXPECT_FALSE(runner->IsRunning());
themblsha
2016/10/29 13:47:19
Done.
|
| + // EventGenerator won't allow us to re-send the left button press without |
| + // releasing it first. We can't send the release event using the same |
| + // generator as it would be handled by the RootView in the main Widget. |
| + // In actual application the RootView doesn't see the release event. |
| + generator.reset(); |
| + generator.reset(new ui::test::EventGenerator( |
| + IsMus() ? widget->GetNativeWindow() : GetContext(), |
| + widget->GetNativeWindow())); |
| + |
| + generator->MoveMouseTo(gfx::Point(150, 50)); |
| + generator->PressLeftButton(); |
| + EXPECT_EQ(1, second_event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
| + |
| + widget->CloseNow(); |
| +} |
| + |
| typedef MenuRunnerTest MenuRunnerImplTest; |
| // Tests that when nested menu runners are destroyed out of order, that |