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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/menu/menu_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/menu/menu_controller.h" 5 #include "ui/views/controls/menu/menu_controller.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 DestroyMenuControllerOnMenuClosed(nested_delegate.get()); 1120 DestroyMenuControllerOnMenuClosed(nested_delegate.get());
1121 // When attempting to select outside of all menus this should lead to a 1121 // When attempting to select outside of all menus this should lead to a
1122 // shutdown. This should not crash while attempting to repost the event. 1122 // shutdown. This should not crash while attempting to repost the event.
1123 SetSelectionOnPointerDown(sub_menu, &event); 1123 SetSelectionOnPointerDown(sub_menu, &event);
1124 1124
1125 // Close to remove observers before test TearDown 1125 // Close to remove observers before test TearDown
1126 sub_menu->Close(); 1126 sub_menu->Close();
1127 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); 1127 EXPECT_EQ(1, nested_delegate->on_menu_closed_called());
1128 } 1128 }
1129 1129
1130 // Tests that having the MenuController deleted during OnGestureEvent does not
1131 // cause a crash. ASAN bots should not detect use-after-free in MenuController.
1132 TEST_F(MenuControllerTest, AsynchronousGestureDeletesController) {
1133 MenuController* controller = menu_controller();
1134 scoped_ptr<TestMenuControllerDelegate> nested_delegate(
1135 new TestMenuControllerDelegate());
1136 ASSERT_FALSE(IsAsyncRun());
1137
1138 controller->AddNestedDelegate(nested_delegate.get());
1139 controller->SetAsyncRun(true);
1140
1141 EXPECT_TRUE(IsAsyncRun());
1142 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate());
1143
1144 MenuItemView* item = menu_item();
1145 int mouse_event_flags = 0;
1146 MenuItemView* run_result =
1147 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT,
1148 false, false, &mouse_event_flags);
1149 EXPECT_EQ(run_result, nullptr);
1150
1151 // Show a sub menu to target with a tap event.
1152 SubmenuView* sub_menu = item->GetSubmenu();
1153 sub_menu->ShowAt(owner(), gfx::Rect(0, 0, 100, 100), true);
1154
1155 gfx::Point location(sub_menu->bounds().CenterPoint());
1156 ui::GestureEvent event(location.x(), location.y(), 0, ui::EventTimeForNow(),
1157 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
1158
1159 // This will lead to MenuController being deleted during the processing of the
1160 // gesture event. The remainder of this test, and TearDown should not crash.
1161 DestroyMenuControllerOnMenuClosed(nested_delegate.get());
1162 controller->OnGestureEvent(sub_menu, &event);
1163
1164 // Close to remove observers before test TearDown
1165 sub_menu->Close();
1166 EXPECT_EQ(1, nested_delegate->on_menu_closed_called());
1167 }
1168
1130 } // namespace test 1169 } // namespace test
1131 } // namespace views 1170 } // namespace views
OLDNEW
« 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