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

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

Issue 2433933007: Fix opening App Menu after Bookmarks Drag (Closed)
Patch Set: Fix additional drag shutdown orders Created 4 years, 2 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/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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 #if defined(USE_AURA) 311 #if defined(USE_AURA)
312 // Verifies that an open menu receives a cancel event, and closes. 312 // Verifies that an open menu receives a cancel event, and closes.
313 void TestCancelEvent() { 313 void TestCancelEvent() {
314 EXPECT_EQ(MenuController::EXIT_NONE, menu_controller_->exit_type()); 314 EXPECT_EQ(MenuController::EXIT_NONE, menu_controller_->exit_type());
315 ui::CancelModeEvent cancel_event; 315 ui::CancelModeEvent cancel_event;
316 event_generator_->Dispatch(&cancel_event); 316 event_generator_->Dispatch(&cancel_event);
317 EXPECT_EQ(MenuController::EXIT_ALL, menu_controller_->exit_type()); 317 EXPECT_EQ(MenuController::EXIT_ALL, menu_controller_->exit_type());
318 } 318 }
319 #endif // defined(USE_AURA) 319 #endif // defined(USE_AURA)
320 320
321 // Verifies the state of the |menu_controller_| before destroying it.
322 void VerifyDragCompleteThenDestroy() {
323 EXPECT_FALSE(menu_controller()->drag_in_progress());
324 EXPECT_EQ(MenuController::EXIT_ALL, menu_controller()->exit_type());
325 DestroyMenuController();
326 }
327
328 // Setups |menu_controller_delegate_| to be destroyed when OnMenuClosed is
329 // called.
330 void TestDragCompleteThenDestroyOnMenuClosed() {
331 menu_controller_delegate_->set_on_menu_closed_callback(
332 base::Bind(&MenuControllerTest::VerifyDragCompleteThenDestroy,
333 base::Unretained(this)));
334 }
335
321 void TestAsynchronousNestedExitAll() { 336 void TestAsynchronousNestedExitAll() {
322 ASSERT_TRUE(test_message_loop_->is_running()); 337 ASSERT_TRUE(test_message_loop_->is_running());
323 338
324 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( 339 std::unique_ptr<TestMenuControllerDelegate> nested_delegate(
325 new TestMenuControllerDelegate()); 340 new TestMenuControllerDelegate());
326 341
327 menu_controller()->AddNestedDelegate(nested_delegate.get()); 342 menu_controller()->AddNestedDelegate(nested_delegate.get());
328 menu_controller()->SetAsyncRun(true); 343 menu_controller()->SetAsyncRun(true);
329 344
330 int mouse_event_flags = 0; 345 int mouse_event_flags = 0;
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 EXPECT_TRUE(menu_delegate->on_perform_drop_called()); 1104 EXPECT_TRUE(menu_delegate->on_perform_drop_called());
1090 EXPECT_FALSE(IsShowing()); 1105 EXPECT_FALSE(IsShowing());
1091 EXPECT_EQ(0, controller_delegate->on_menu_closed_called()); 1106 EXPECT_EQ(0, controller_delegate->on_menu_closed_called());
1092 } 1107 }
1093 1108
1094 // Tests that dragging within an asynchronous menu notifies the 1109 // Tests that dragging within an asynchronous menu notifies the
1095 // MenuControllerDelegate for shutdown. 1110 // MenuControllerDelegate for shutdown.
1096 TEST_F(MenuControllerTest, AsynchronousDragComplete) { 1111 TEST_F(MenuControllerTest, AsynchronousDragComplete) {
1097 MenuController* controller = menu_controller(); 1112 MenuController* controller = menu_controller();
1098 controller->SetAsyncRun(true); 1113 controller->SetAsyncRun(true);
1114 TestDragCompleteThenDestroyOnMenuClosed();
1099 1115
1100 controller->OnDragWillStart(); 1116 controller->OnDragWillStart();
1101 controller->OnDragComplete(true); 1117 controller->OnDragComplete(true);
1102 1118
1103 EXPECT_FALSE(controller->drag_in_progress());
1104 TestMenuControllerDelegate* controller_delegate = menu_controller_delegate(); 1119 TestMenuControllerDelegate* controller_delegate = menu_controller_delegate();
1105 EXPECT_EQ(1, controller_delegate->on_menu_closed_called()); 1120 EXPECT_EQ(1, controller_delegate->on_menu_closed_called());
1106 EXPECT_EQ(nullptr, controller_delegate->on_menu_closed_menu()); 1121 EXPECT_EQ(nullptr, controller_delegate->on_menu_closed_menu());
1107 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE, 1122 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE,
1108 controller_delegate->on_menu_closed_notify_type()); 1123 controller_delegate->on_menu_closed_notify_type());
1109 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type()); 1124 }
1125
1126 // Tests that if Cancel is called during a drag, that OnMenuClosed is still
1127 // notified when the drag completes.
1128 TEST_F(MenuControllerTest, AsynchronousCancelDuringDrag) {
1129 MenuController* controller = menu_controller();
1130 controller->SetAsyncRun(true);
1131 TestDragCompleteThenDestroyOnMenuClosed();
1132
1133 controller->OnDragWillStart();
1134 controller->CancelAll();
1135 controller->OnDragComplete(true);
1136
1137 TestMenuControllerDelegate* controller_delegate = menu_controller_delegate();
1138 EXPECT_EQ(1, controller_delegate->on_menu_closed_called());
1139 EXPECT_EQ(nullptr, controller_delegate->on_menu_closed_menu());
1140 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE,
1141 controller_delegate->on_menu_closed_notify_type());
1110 } 1142 }
1111 1143
1112 // Tests that if a menu is destroyed while drag operations are occuring, that 1144 // Tests that if a menu is destroyed while drag operations are occuring, that
1113 // the MenuHost does not crash as the drag completes. 1145 // the MenuHost does not crash as the drag completes.
1114 TEST_F(MenuControllerTest, AsynchronousDragHostDeleted) { 1146 TEST_F(MenuControllerTest, AsynchronousDragHostDeleted) {
1115 MenuController* controller = menu_controller(); 1147 MenuController* controller = menu_controller();
1116 controller->SetAsyncRun(true); 1148 controller->SetAsyncRun(true);
1117 1149
1118 SubmenuView* submenu = menu_item()->GetSubmenu(); 1150 SubmenuView* submenu = menu_item()->GetSubmenu();
1119 submenu->ShowAt(owner(), menu_item()->bounds(), false); 1151 submenu->ShowAt(owner(), menu_item()->bounds(), false);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 aura::client::SetDragDropClient(owner()->GetNativeWindow()->GetRootWindow(), 1467 aura::client::SetDragDropClient(owner()->GetNativeWindow()->GetRootWindow(),
1436 &drag_drop_client); 1468 &drag_drop_client);
1437 AddButtonMenuItems(); 1469 AddButtonMenuItems();
1438 StartDrag(); 1470 StartDrag();
1439 } 1471 }
1440 1472
1441 #endif // defined(USE_AURA) 1473 #endif // defined(USE_AURA)
1442 1474
1443 } // namespace test 1475 } // namespace test
1444 } // namespace views 1476 } // 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