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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/ui/views/menu_test_base.h" | 6 #include "chrome/browser/ui/views/menu_test_base.h" |
7 #include "chrome/test/base/interactive_test_utils.h" | 7 #include "chrome/test/base/interactive_test_utils.h" |
8 #include "ui/base/dragdrop/drag_drop_types.h" | 8 #include "ui/base/dragdrop/drag_drop_types.h" |
9 #include "ui/base/dragdrop/os_exchange_data.h" | 9 #include "ui/base/dragdrop/os_exchange_data.h" |
| 10 #include "ui/views/controls/menu/menu_controller.h" |
10 #include "ui/views/controls/menu/menu_item_view.h" | 11 #include "ui/views/controls/menu/menu_item_view.h" |
| 12 #include "ui/views/controls/menu/menu_runner.h" |
11 #include "ui/views/controls/menu/submenu_view.h" | 13 #include "ui/views/controls/menu/submenu_view.h" |
12 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 // Borrowed from chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc, | 18 // Borrowed from chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc, |
17 // since these are also disabled on Linux for drag and drop. | 19 // since these are also disabled on Linux for drag and drop. |
18 // TODO(erg): Fix DND tests on linux_aura. crbug.com/163931 | 20 // TODO(erg): Fix DND tests on linux_aura. crbug.com/163931 |
19 #if defined(OS_LINUX) && defined(USE_AURA) | 21 #if defined(OS_LINUX) && defined(USE_AURA) |
20 #define MAYBE(x) DISABLED_##x | 22 #define MAYBE(x) DISABLED_##x |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // delegate should not have been asked whether or not to close, and the menu | 338 // delegate should not have been asked whether or not to close, and the menu |
337 // should simply be closed. | 339 // should simply be closed. |
338 EXPECT_TRUE(performed_in_menu_drop()); | 340 EXPECT_TRUE(performed_in_menu_drop()); |
339 EXPECT_FALSE(target_view()->dropped()); | 341 EXPECT_FALSE(target_view()->dropped()); |
340 EXPECT_FALSE(asked_to_close()); | 342 EXPECT_FALSE(asked_to_close()); |
341 EXPECT_FALSE(menu()->GetSubmenu()->IsShowing()); | 343 EXPECT_FALSE(menu()->GetSubmenu()->IsShowing()); |
342 | 344 |
343 Done(); | 345 Done(); |
344 } | 346 } |
345 | 347 |
| 348 // Test that an in-menu (i.e., entirely implemented in the menu code) closes the |
| 349 // menu automatically once the drag is complete, and does not ask the delegate |
| 350 // to stay open. |
346 VIEW_TEST(MenuViewDragAndDropTestTestInMenuDrag, MAYBE(TestInMenuDrag)) | 351 VIEW_TEST(MenuViewDragAndDropTestTestInMenuDrag, MAYBE(TestInMenuDrag)) |
347 | 352 |
348 class MenuViewDragAndDropTestNestedDrag : public MenuViewDragAndDropTest { | 353 class MenuViewDragAndDropTestNestedDrag : public MenuViewDragAndDropTest { |
349 public: | 354 public: |
350 MenuViewDragAndDropTestNestedDrag() {} | 355 MenuViewDragAndDropTestNestedDrag() {} |
351 virtual ~MenuViewDragAndDropTestNestedDrag() {} | 356 virtual ~MenuViewDragAndDropTestNestedDrag() {} |
352 | 357 |
353 private: | 358 private: |
354 // MenuViewDragAndDropTest: | 359 // MenuViewDragAndDropTest: |
355 virtual void DoTestWithMenuOpen() OVERRIDE; | 360 virtual void DoTestWithMenuOpen() OVERRIDE; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 EXPECT_FALSE(performed_in_menu_drop()); | 436 EXPECT_FALSE(performed_in_menu_drop()); |
432 EXPECT_TRUE(asked_to_close()); | 437 EXPECT_TRUE(asked_to_close()); |
433 EXPECT_TRUE(menu()->GetSubmenu()->IsShowing()); | 438 EXPECT_TRUE(menu()->GetSubmenu()->IsShowing()); |
434 | 439 |
435 // Clean up. | 440 // Clean up. |
436 menu()->GetSubmenu()->Close(); | 441 menu()->GetSubmenu()->Close(); |
437 | 442 |
438 Done(); | 443 Done(); |
439 } | 444 } |
440 | 445 |
| 446 // Test that a nested drag (i.e. one via a child view, and not entirely |
| 447 // implemented in menu code) will consult the delegate before closing the view |
| 448 // after the drag. |
441 VIEW_TEST(MenuViewDragAndDropTestNestedDrag, | 449 VIEW_TEST(MenuViewDragAndDropTestNestedDrag, |
442 MAYBE(MenuViewDragAndDropNestedDrag)) | 450 MAYBE(MenuViewDragAndDropNestedDrag)) |
| 451 |
| 452 class MenuViewDragAndDropForDropStayOpen : public MenuViewDragAndDropTest { |
| 453 public: |
| 454 MenuViewDragAndDropForDropStayOpen() {} |
| 455 virtual ~MenuViewDragAndDropForDropStayOpen() {} |
| 456 |
| 457 private: |
| 458 // MenuViewDragAndDropTest: |
| 459 virtual int GetMenuRunnerFlags() OVERRIDE; |
| 460 virtual void DoTestWithMenuOpen() OVERRIDE; |
| 461 }; |
| 462 |
| 463 int MenuViewDragAndDropForDropStayOpen::GetMenuRunnerFlags() { |
| 464 return views::MenuRunner::HAS_MNEMONICS | |
| 465 views::MenuRunner::NESTED_DRAG | |
| 466 views::MenuRunner::FOR_DROP; |
| 467 } |
| 468 |
| 469 void MenuViewDragAndDropForDropStayOpen::DoTestWithMenuOpen() { |
| 470 views::SubmenuView* submenu = menu()->GetSubmenu(); |
| 471 ASSERT_TRUE(submenu); |
| 472 ASSERT_TRUE(submenu->IsShowing()); |
| 473 |
| 474 views::MenuController* controller = menu()->GetMenuController(); |
| 475 ASSERT_TRUE(controller); |
| 476 EXPECT_FALSE(controller->IsCancelAllTimerRunningForTest()); |
| 477 |
| 478 Done(); |
| 479 } |
| 480 |
| 481 // Test that if a menu is opened for a drop which is handled by a child view |
| 482 // that the menu does not immediately try to close. |
| 483 VIEW_TEST(MenuViewDragAndDropForDropStayOpen, MenuViewStaysOpenForNestedDrag) |
| 484 |
| 485 class MenuViewDragAndDropForDropCancel : public MenuViewDragAndDropTest { |
| 486 public: |
| 487 MenuViewDragAndDropForDropCancel() {} |
| 488 virtual ~MenuViewDragAndDropForDropCancel() {} |
| 489 |
| 490 private: |
| 491 // MenuViewDragAndDropTest: |
| 492 virtual int GetMenuRunnerFlags() OVERRIDE; |
| 493 virtual void DoTestWithMenuOpen() OVERRIDE; |
| 494 }; |
| 495 |
| 496 int MenuViewDragAndDropForDropCancel::GetMenuRunnerFlags() { |
| 497 return views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::FOR_DROP; |
| 498 } |
| 499 |
| 500 void MenuViewDragAndDropForDropCancel::DoTestWithMenuOpen() { |
| 501 views::SubmenuView* submenu = menu()->GetSubmenu(); |
| 502 ASSERT_TRUE(submenu); |
| 503 ASSERT_TRUE(submenu->IsShowing()); |
| 504 |
| 505 views::MenuController* controller = menu()->GetMenuController(); |
| 506 ASSERT_TRUE(controller); |
| 507 EXPECT_TRUE(controller->IsCancelAllTimerRunningForTest()); |
| 508 |
| 509 Done(); |
| 510 } |
| 511 |
| 512 // Test that if a menu is opened for a drop handled entirely by menu code, the |
| 513 // menu will try to close if it does not receive any drag updates. |
| 514 VIEW_TEST(MenuViewDragAndDropForDropCancel, MenuViewCancelsForOwnDrag) |
OLD | NEW |