| OLD | NEW |
| 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // active instance. | 382 // active instance. |
| 383 void TestMenuControllerReplacementDuringDrag() { | 383 void TestMenuControllerReplacementDuringDrag() { |
| 384 DestroyMenuController(); | 384 DestroyMenuController(); |
| 385 menu_item()->GetSubmenu()->Close(); | 385 menu_item()->GetSubmenu()->Close(); |
| 386 menu_controller_ = | 386 menu_controller_ = |
| 387 new MenuController(true, menu_controller_delegate_.get()); | 387 new MenuController(true, menu_controller_delegate_.get()); |
| 388 menu_controller_->owner_ = owner_.get(); | 388 menu_controller_->owner_ = owner_.get(); |
| 389 menu_controller_->showing_ = true; | 389 menu_controller_->showing_ = true; |
| 390 } | 390 } |
| 391 | 391 |
| 392 // Tests that the menu does not destroy itself when canceled during a drag. |
| 393 void TestCancelAllDuringDrag() { |
| 394 menu_controller_->CancelAll(); |
| 395 EXPECT_EQ(0, menu_controller_delegate_->on_menu_closed_called()); |
| 396 } |
| 397 |
| 392 protected: | 398 protected: |
| 393 void SetPendingStateItem(MenuItemView* item) { | 399 void SetPendingStateItem(MenuItemView* item) { |
| 394 menu_controller_->pending_state_.item = item; | 400 menu_controller_->pending_state_.item = item; |
| 395 menu_controller_->pending_state_.submenu_open = true; | 401 menu_controller_->pending_state_.submenu_open = true; |
| 396 } | 402 } |
| 397 | 403 |
| 398 void ResetSelection() { | 404 void ResetSelection() { |
| 399 menu_controller_->SetSelection( | 405 menu_controller_->SetSelection( |
| 400 nullptr, | 406 nullptr, |
| 401 MenuController::SELECTION_EXIT | | 407 MenuController::SELECTION_EXIT | |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 | 1410 |
| 1405 TestDragDropClient drag_drop_client( | 1411 TestDragDropClient drag_drop_client( |
| 1406 base::Bind(&MenuControllerTest::TestMenuControllerReplacementDuringDrag, | 1412 base::Bind(&MenuControllerTest::TestMenuControllerReplacementDuringDrag, |
| 1407 base::Unretained(this))); | 1413 base::Unretained(this))); |
| 1408 aura::client::SetDragDropClient(owner()->GetNativeWindow()->GetRootWindow(), | 1414 aura::client::SetDragDropClient(owner()->GetNativeWindow()->GetRootWindow(), |
| 1409 &drag_drop_client); | 1415 &drag_drop_client); |
| 1410 AddButtonMenuItems(); | 1416 AddButtonMenuItems(); |
| 1411 StartDrag(); | 1417 StartDrag(); |
| 1412 } | 1418 } |
| 1413 | 1419 |
| 1420 // Tests that if a CancelAll is called during drag-and-drop that it does not |
| 1421 // destroy the MenuController. On Windows and Linux this destruction also |
| 1422 // destroys the Widget used for drag-and-drop, thereby ending the drag. |
| 1423 TEST_F(MenuControllerTest, CancelAllDuringDrag) { |
| 1424 // This test creates two native widgets, but expects the child native widget |
| 1425 // to be able to reach up and use the parent native widget's aura |
| 1426 // objects. https://crbug.com/614037 |
| 1427 if (IsMus()) |
| 1428 return; |
| 1429 |
| 1430 MenuController* controller = menu_controller(); |
| 1431 controller->SetAsyncRun(true); |
| 1432 |
| 1433 TestDragDropClient drag_drop_client(base::Bind( |
| 1434 &MenuControllerTest::TestCancelAllDuringDrag, base::Unretained(this))); |
| 1435 aura::client::SetDragDropClient(owner()->GetNativeWindow()->GetRootWindow(), |
| 1436 &drag_drop_client); |
| 1437 AddButtonMenuItems(); |
| 1438 StartDrag(); |
| 1439 } |
| 1440 |
| 1414 #endif // defined(USE_AURA) | 1441 #endif // defined(USE_AURA) |
| 1415 | 1442 |
| 1416 } // namespace test | 1443 } // namespace test |
| 1417 } // namespace views | 1444 } // namespace views |
| OLD | NEW |