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

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

Issue 2659903002: Change MenuControllerDelegate to provide WeakPtr (Closed)
Patch Set: 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') | 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 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
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // controller that it created. 413 // controller that it created.
414 menu_runner->Release(); 414 menu_runner->Release();
415 415
416 // This is not expected to run, however this is from the origin ASAN stack 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. 417 // traces. So regressions will be caught with the same stack trace.
418 if (menu_controller.controller()) 418 if (menu_controller.controller())
419 menu_controller.controller()->CancelAll(); 419 menu_controller.controller()->CancelAll();
420 EXPECT_EQ(nullptr, menu_controller.controller()); 420 EXPECT_EQ(nullptr, menu_controller.controller());
421 } 421 }
422 422
423 // Tests that if a delegate is destroyed, while a menu is still running, that
424 // subsequent shutdown of the menu does not attempt to notify it. This should
425 // not crash on ASAN bots.
426 TEST_F(MenuRunnerImplTest, NestedDelegateDestroyedWhileMenuRunning) {
427 internal::MenuRunnerImpl* menu_runner =
428 new internal::MenuRunnerImpl(menu_item_view());
429 EXPECT_EQ(MenuRunner::NORMAL_EXIT,
430 menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(),
431 MENU_ANCHOR_TOPLEFT, MenuRunner::ASYNC));
432
433 std::unique_ptr<TestMenuDelegate> menu_delegate2(new TestMenuDelegate);
434 MenuItemView* menu_item_view2 = new MenuItemView(menu_delegate2.get());
435 menu_item_view2->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One"));
436
437 internal::MenuRunnerImpl* menu_runner2 =
438 new internal::MenuRunnerImpl(menu_item_view2);
439 EXPECT_EQ(MenuRunner::NORMAL_EXIT,
440 menu_runner2->RunMenuAt(owner(), nullptr, gfx::Rect(),
441 MENU_ANCHOR_TOPLEFT,
442 MenuRunner::ASYNC | MenuRunner::IS_NESTED));
443
444 // Nested delegate closed while the MenuController is still showing
445 menu_runner2->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE,
446 nullptr, 0);
447
448 // Nested delegate is deleted while not running/
449 menu_runner2->Release();
450
451 // Closing the full menu stack should not attempt to tell a delegate which
452 // has been otherwise destroyed.
453 MenuControllerTestApi menu_controller;
454 menu_controller.ClearState();
455 menu_controller.controller()->CancelAll();
456 }
457
423 } // namespace test 458 } // namespace test
424 } // namespace views 459 } // namespace views
OLDNEW
« 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