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

Side by Side Diff: ui/views/controls/menu/menu_runner_unittest.cc

Issue 2654093005: Fix MenuRunner Releasing (Closed)
Patch Set: Clarification and renaming Created 3 years, 10 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_runner_impl.cc ('k') | ui/views/test/menu_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_runner.h" 5 #include "ui/views/controls/menu/menu_runner.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "ui/base/ui_base_types.h" 14 #include "ui/base/ui_base_types.h"
15 #include "ui/events/test/event_generator.h" 15 #include "ui/events/test/event_generator.h"
16 #include "ui/views/controls/menu/menu_controller.h"
16 #include "ui/views/controls/menu/menu_delegate.h" 17 #include "ui/views/controls/menu/menu_delegate.h"
17 #include "ui/views/controls/menu/menu_item_view.h" 18 #include "ui/views/controls/menu/menu_item_view.h"
18 #include "ui/views/controls/menu/menu_runner_impl.h" 19 #include "ui/views/controls/menu/menu_runner_impl.h"
19 #include "ui/views/controls/menu/menu_types.h" 20 #include "ui/views/controls/menu/menu_types.h"
20 #include "ui/views/controls/menu/submenu_view.h" 21 #include "ui/views/controls/menu/submenu_view.h"
21 #include "ui/views/test/menu_test_utils.h" 22 #include "ui/views/test/menu_test_utils.h"
22 #include "ui/views/test/test_views.h" 23 #include "ui/views/test/test_views.h"
23 #include "ui/views/test/views_test_base.h" 24 #include "ui/views/test/views_test_base.h"
24 #include "ui/views/widget/native_widget_private.h" 25 #include "ui/views/widget/native_widget_private.h"
25 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 359
359 internal::MenuRunnerImpl* menu_runner2 = 360 internal::MenuRunnerImpl* menu_runner2 =
360 new internal::MenuRunnerImpl(menu_item_view2); 361 new internal::MenuRunnerImpl(menu_item_view2);
361 EXPECT_EQ(MenuRunner::NORMAL_EXIT, 362 EXPECT_EQ(MenuRunner::NORMAL_EXIT,
362 menu_runner2->RunMenuAt(owner(), nullptr, gfx::Rect(), 363 menu_runner2->RunMenuAt(owner(), nullptr, gfx::Rect(),
363 MENU_ANCHOR_TOPLEFT, 364 MENU_ANCHOR_TOPLEFT,
364 MenuRunner::ASYNC | MenuRunner::IS_NESTED)); 365 MenuRunner::ASYNC | MenuRunner::IS_NESTED));
365 366
366 // Hide the controller so we can test out of order destruction. 367 // Hide the controller so we can test out of order destruction.
367 MenuControllerTestApi menu_controller; 368 MenuControllerTestApi menu_controller;
368 menu_controller.Hide(); 369 menu_controller.SetShowing(false);
369 370
370 // This destroyed MenuController 371 // This destroyed MenuController
371 menu_runner->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE, 372 menu_runner->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE,
372 nullptr, 0); 373 nullptr, 0);
373 374
374 // This should not access the destroyed MenuController 375 // This should not access the destroyed MenuController
375 menu_runner2->Release(); 376 menu_runner2->Release();
376 menu_runner->Release(); 377 menu_runner->Release();
377 } 378 }
378 379
380 // Tests that when there are two separate MenuControllers, and the active one is
381 // deleted first, that shutting down the MenuRunner of the original
382 // MenuController properly closes its controller. This should not crash on ASAN
383 // bots.
384 TEST_F(MenuRunnerImplTest, MenuRunnerDestroyedWithNoActiveController) {
385 internal::MenuRunnerImpl* menu_runner =
386 new internal::MenuRunnerImpl(menu_item_view());
387 EXPECT_EQ(MenuRunner::NORMAL_EXIT,
388 menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(),
389 MENU_ANCHOR_TOPLEFT, MenuRunner::ASYNC));
390
391 // Hide the menu, and clear its item selection state.
392 MenuControllerTestApi menu_controller;
393 menu_controller.SetShowing(false);
394 menu_controller.ClearState();
395
396 std::unique_ptr<TestMenuDelegate> menu_delegate2(new TestMenuDelegate);
397 MenuItemView* menu_item_view2 = new MenuItemView(menu_delegate2.get());
398 menu_item_view2->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One"));
399
400 internal::MenuRunnerImpl* menu_runner2 =
401 new internal::MenuRunnerImpl(menu_item_view2);
402 EXPECT_EQ(MenuRunner::NORMAL_EXIT,
403 menu_runner2->RunMenuAt(owner(), nullptr, gfx::Rect(),
404 MENU_ANCHOR_TOPLEFT,
405 MenuRunner::ASYNC | MenuRunner::FOR_DROP));
406
407 EXPECT_NE(menu_controller.controller(), MenuController::GetActiveInstance());
408 menu_controller.SetShowing(true);
409
410 // Close the runner with the active menu first.
411 menu_runner2->Release();
412 // Even though there is no active menu, this should still cleanup the
413 // controller that it created.
414 menu_runner->Release();
415
416 // This is not expected to run, however this is from the origin ASAN stack
417 // traces. So regressions will be caught with the same stack trace.
418 if (menu_controller.controller())
419 menu_controller.controller()->CancelAll();
420 EXPECT_EQ(nullptr, menu_controller.controller());
421 }
422
379 } // namespace test 423 } // namespace test
380 } // namespace views 424 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_runner_impl.cc ('k') | ui/views/test/menu_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698