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

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

Issue 2659903002: Change MenuControllerDelegate to provide WeakPtr (Closed)
Patch Set: Created 3 years, 11 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_runner_impl.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_runner_unittest.cc
diff --git a/ui/views/controls/menu/menu_runner_unittest.cc b/ui/views/controls/menu/menu_runner_unittest.cc
index 7b0503f5cc53e613750b7d534fd96327bf92f32c..b9d8d0815404384089f0032a2de1acdde5e2e41d 100644
--- a/ui/views/controls/menu/menu_runner_unittest.cc
+++ b/ui/views/controls/menu/menu_runner_unittest.cc
@@ -420,5 +420,40 @@ TEST_F(MenuRunnerImplTest, MenuRunnerDestroyedWithNoActiveController) {
EXPECT_EQ(nullptr, menu_controller.controller());
}
+// Tests that if a delegate is destroyed, while a menu is still running, that
+// subsequent shutdown of the menu does not attempt to notify it. This should
+// not crash on ASAN bots.
+TEST_F(MenuRunnerImplTest, NestedDelegateDestroyedWhileMenuRunning) {
+ internal::MenuRunnerImpl* menu_runner =
+ new internal::MenuRunnerImpl(menu_item_view());
+ EXPECT_EQ(MenuRunner::NORMAL_EXIT,
+ menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(),
+ MENU_ANCHOR_TOPLEFT, MenuRunner::ASYNC));
+
+ std::unique_ptr<TestMenuDelegate> menu_delegate2(new TestMenuDelegate);
+ MenuItemView* menu_item_view2 = new MenuItemView(menu_delegate2.get());
+ menu_item_view2->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One"));
+
+ internal::MenuRunnerImpl* menu_runner2 =
+ new internal::MenuRunnerImpl(menu_item_view2);
+ EXPECT_EQ(MenuRunner::NORMAL_EXIT,
+ menu_runner2->RunMenuAt(owner(), nullptr, gfx::Rect(),
+ MENU_ANCHOR_TOPLEFT,
+ MenuRunner::ASYNC | MenuRunner::IS_NESTED));
+
+ // Nested delegate closed while the MenuController is still showing
+ menu_runner2->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE,
+ nullptr, 0);
+
+ // Nested delegate is deleted while not running/
+ menu_runner2->Release();
+
+ // Closing the full menu stack should not attempt to tell a delegate which
+ // has been otherwise destroyed.
+ MenuControllerTestApi menu_controller;
+ menu_controller.ClearState();
+ menu_controller.controller()->CancelAll();
+}
+
} // namespace test
} // namespace views
« no previous file with comments | « ui/views/controls/menu/menu_runner_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698