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

Unified Diff: ui/views/controls/menu/menu_controller_unittest.cc

Issue 1824993003: Fix MenuController Gesture Crash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/controls/menu/menu_controller.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/menu/menu_controller_unittest.cc
diff --git a/ui/views/controls/menu/menu_controller_unittest.cc b/ui/views/controls/menu/menu_controller_unittest.cc
index 90d58d986c2d2025824265d54f9679d009b7f40f..aa26ba97a7f202e84caab2cc8427ddd8310c719d 100644
--- a/ui/views/controls/menu/menu_controller_unittest.cc
+++ b/ui/views/controls/menu/menu_controller_unittest.cc
@@ -1127,5 +1127,44 @@ TEST_F(MenuControllerTest, AsynchronousRepostEventDeletesController) {
EXPECT_EQ(1, nested_delegate->on_menu_closed_called());
}
+// Tests that having the MenuController deleted during OnGestureEvent does not
+// cause a crash. ASAN bots should not detect use-after-free in MenuController.
+TEST_F(MenuControllerTest, AsynchronousGestureDeletesController) {
+ MenuController* controller = menu_controller();
+ scoped_ptr<TestMenuControllerDelegate> nested_delegate(
+ new TestMenuControllerDelegate());
+ ASSERT_FALSE(IsAsyncRun());
+
+ controller->AddNestedDelegate(nested_delegate.get());
+ controller->SetAsyncRun(true);
+
+ EXPECT_TRUE(IsAsyncRun());
+ EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate());
+
+ MenuItemView* item = menu_item();
+ int mouse_event_flags = 0;
+ MenuItemView* run_result =
+ controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT,
+ false, false, &mouse_event_flags);
+ EXPECT_EQ(run_result, nullptr);
+
+ // Show a sub menu to target with a tap event.
+ SubmenuView* sub_menu = item->GetSubmenu();
+ sub_menu->ShowAt(owner(), gfx::Rect(0, 0, 100, 100), true);
+
+ gfx::Point location(sub_menu->bounds().CenterPoint());
+ ui::GestureEvent event(location.x(), location.y(), 0, ui::EventTimeForNow(),
+ ui::GestureEventDetails(ui::ET_GESTURE_TAP));
+
+ // This will lead to MenuController being deleted during the processing of the
+ // gesture event. The remainder of this test, and TearDown should not crash.
+ DestroyMenuControllerOnMenuClosed(nested_delegate.get());
+ controller->OnGestureEvent(sub_menu, &event);
+
+ // Close to remove observers before test TearDown
+ sub_menu->Close();
+ EXPECT_EQ(1, nested_delegate->on_menu_closed_called());
+}
+
} // namespace test
} // namespace views
« no previous file with comments | « ui/views/controls/menu/menu_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698