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

Side by Side Diff: chrome/browser/views/bookmark_bar_view_test.cc

Issue 1612005: Revert "BookmarkBarView tests fixes" (Closed)
Patch Set: Created 10 years, 8 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 | « no previous file | chrome/browser/views/bookmark_context_menu.cc » ('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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/keyboard_codes.h" 5 #include "base/keyboard_codes.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "chrome/browser/automation/ui_controls.h" 7 #include "chrome/browser/automation/ui_controls.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/bookmarks/bookmark_utils.h" 9 #include "chrome/browser/bookmarks/bookmark_utils.h"
10 #include "chrome/browser/pref_service.h" 10 #include "chrome/browser/pref_service.h"
11 #include "chrome/browser/profile.h" 11 #include "chrome/browser/profile.h"
12 #include "chrome/browser/tab_contents/page_navigator.h" 12 #include "chrome/browser/tab_contents/page_navigator.h"
13 #include "chrome/browser/views/bookmark_bar_view.h" 13 #include "chrome/browser/views/bookmark_bar_view.h"
14 #include "chrome/common/notification_service.h"
15 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
16 #include "chrome/test/testing_profile.h" 15 #include "chrome/test/testing_profile.h"
17 #include "chrome/test/interactive_ui/view_event_test_base.h" 16 #include "chrome/test/interactive_ui/view_event_test_base.h"
18 #include "chrome/test/ui_test_utils.h"
19 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
20 #include "views/controls/button/menu_button.h" 18 #include "views/controls/button/menu_button.h"
21 #include "views/controls/button/text_button.h" 19 #include "views/controls/button/text_button.h"
22 #include "views/controls/menu/menu_controller.h" 20 #include "views/controls/menu/menu_controller.h"
23 #include "views/controls/menu/menu_item_view.h" 21 #include "views/controls/menu/menu_item_view.h"
24 #include "views/controls/menu/submenu_view.h" 22 #include "views/controls/menu/submenu_view.h"
25 #include "views/window/window.h" 23 #include "views/window/window.h"
26 24
27 #if defined(OS_LINUX)
28 // See http://crbug.com/40040 for details.
29 #define MAYBE_DND DISABLED_DND
30 #define MAYBE_DNDToDifferentMenu DISABLED_DNDToDifferentMenu
31 #define MAYBE_DNDBackToOriginatingMenu DISABLED_DNDBackToOriginatingMenu
32
33 // See http://crbug.com/40039 for details.
34 #define MAYBE_KeyEvents DISABLED_KeyEvents
35
36 #else
37
38 #define MAYBE_DND DND
39 #define MAYBE_DNDToDifferentMenu DNDToDifferentMenu
40 #define MAYBE_DNDBackToOriginatingMenu DNDBackToOriginatingMenu
41 #define MAYBE_DNDBackToOriginatingMenu DNDBackToOriginatingMenu
42 #define MAYBE_KeyEvents KeyEvents
43
44 #endif
45
46 namespace { 25 namespace {
47 26
48 // PageNavigator implementation that records the URL. 27 // PageNavigator implementation that records the URL.
49 class TestingPageNavigator : public PageNavigator { 28 class TestingPageNavigator : public PageNavigator {
50 public: 29 public:
51 virtual void OpenURL(const GURL& url, const GURL& referrer, 30 virtual void OpenURL(const GURL& url, const GURL& referrer,
52 WindowOpenDisposition disposition, 31 WindowOpenDisposition disposition,
53 PageTransition::Type transition) { 32 PageTransition::Type transition) {
54 url_ = url; 33 url_ = url;
55 } 34 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 menu->GetSubmenu()->GetMenuItemAt(1); 338 menu->GetSubmenu()->GetMenuItemAt(1);
360 ASSERT_TRUE(child_menu->GetSubmenu() != NULL); 339 ASSERT_TRUE(child_menu->GetSubmenu() != NULL);
361 ASSERT_FALSE(child_menu->GetSubmenu()->IsShowing()); 340 ASSERT_FALSE(child_menu->GetSubmenu()->IsShowing());
362 341
363 // And submenu we last clicked is showing. 342 // And submenu we last clicked is showing.
364 child_menu = menu->GetSubmenu()->GetMenuItemAt(2); 343 child_menu = menu->GetSubmenu()->GetMenuItemAt(2);
365 ASSERT_TRUE(child_menu != NULL); 344 ASSERT_TRUE(child_menu != NULL);
366 ASSERT_TRUE(child_menu->GetSubmenu()->IsShowing()); 345 ASSERT_TRUE(child_menu->GetSubmenu()->IsShowing());
367 346
368 // Nothing should have been selected. 347 // Nothing should have been selected.
369 EXPECT_EQ(GURL(), navigator_.url_); 348 ASSERT_TRUE(navigator_.url_ == GURL());
370 349
371 // Hide menu. 350 // Hide menu.
372 menu->GetMenuController()->Cancel(true); 351 menu->GetMenuController()->Cancel(true);
373 352
374 Done(); 353 Done();
375 } 354 }
376 }; 355 };
377 356
378 VIEW_TEST(BookmarkBarViewTest3, Submenus) 357 VIEW_TEST(BookmarkBarViewTest3, Submenus)
379 358
380 // Observer that posts task upon the context menu creation.
381 // This is necessary for Linux as the context menu has to check
382 // the clipboard, which invokes the event loop.
383 class ContextMenuNotificationObserver : public NotificationObserver {
384 public:
385 explicit ContextMenuNotificationObserver(Task* task) : task_(task) {
386 registrar_.Add(this,
387 NotificationType::BOOKMARK_CONTEXT_MENU_SHOWN,
388 NotificationService::AllSources());
389 }
390
391 virtual void Observe(NotificationType type,
392 const NotificationSource& source,
393 const NotificationDetails& details) {
394 MessageLoop::current()->PostTask(FROM_HERE, task_);
395 }
396
397 private:
398 NotificationRegistrar registrar_;
399 Task* task_;
400
401 DISALLOW_COPY_AND_ASSIGN(ContextMenuNotificationObserver);
402 };
403
404 // Tests context menus by way of opening a context menu for a bookmark, 359 // Tests context menus by way of opening a context menu for a bookmark,
405 // then right clicking to get context menu and selecting the first menu item 360 // then right clicking to get context menu and selecting the first menu item
406 // (open). 361 // (open).
407 class BookmarkBarViewTest4 : public BookmarkBarViewEventTestBase { 362 class BookmarkBarViewTest4 : public BookmarkBarViewEventTestBase {
408 public:
409 BookmarkBarViewTest4()
410 : ALLOW_THIS_IN_INITIALIZER_LIST(
411 observer_(CreateEventTask(this, &BookmarkBarViewTest4::Step3))) {
412 }
413
414 protected: 363 protected:
415 virtual void DoTestOnMessageLoop() { 364 virtual void DoTestOnMessageLoop() {
416 // Move the mouse to the first folder on the bookmark bar and press the 365 // Move the mouse to the first folder on the bookmark bar and press the
417 // mouse. 366 // mouse.
418 views::TextButton* button = bb_view_->other_bookmarked_button(); 367 views::TextButton* button = bb_view_->other_bookmarked_button();
419 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT, 368 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
420 ui_controls::DOWN | ui_controls::UP, 369 ui_controls::DOWN | ui_controls::UP,
421 CreateEventTask(this, &BookmarkBarViewTest4::Step2)); 370 CreateEventTask(this, &BookmarkBarViewTest4::Step2));
422 } 371 }
423 372
424 private: 373 private:
425 void Step2() { 374 void Step2() {
426 // Menu should be showing. 375 // Menu should be showing.
427 views::MenuItemView* menu = bb_view_->GetMenu(); 376 views::MenuItemView* menu = bb_view_->GetMenu();
428 ASSERT_TRUE(menu != NULL); 377 ASSERT_TRUE(menu != NULL);
429 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 378 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
430 379
431 views::MenuItemView* child_menu = 380 views::MenuItemView* child_menu =
432 menu->GetSubmenu()->GetMenuItemAt(0); 381 menu->GetSubmenu()->GetMenuItemAt(0);
433 ASSERT_TRUE(child_menu != NULL); 382 ASSERT_TRUE(child_menu != NULL);
434 383
435 // Right click on the first child to get its context menu. 384 // Right click on the first child to get its context menu.
436 ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, 385 ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
437 ui_controls::DOWN | ui_controls::UP, NULL); 386 ui_controls::DOWN | ui_controls::UP,
438 // Step3 will be invoked by ContextMenuNotificationObserver. 387 CreateEventTask(this, &BookmarkBarViewTest4::Step3));
439 } 388 }
440 389
441 void Step3() { 390 void Step3() {
442 // Make sure the context menu is showing. 391 // Make sure the context menu is showing.
443 views::MenuItemView* menu = bb_view_->GetContextMenu(); 392 views::MenuItemView* menu = bb_view_->GetContextMenu();
444 ASSERT_TRUE(menu != NULL); 393 ASSERT_TRUE(menu != NULL);
445 ASSERT_TRUE(menu->GetSubmenu()); 394 ASSERT_TRUE(menu->GetSubmenu());
446 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 395 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
447 396
448 // Select the first menu item (open). 397 // Select the first menu item (open).
449 ui_controls::MoveMouseToCenterAndPress(menu->GetSubmenu()->GetMenuItemAt(0), 398 ui_controls::MoveMouseToCenterAndPress(menu->GetSubmenu()->GetMenuItemAt(0),
450 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, 399 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
451 CreateEventTask(this, &BookmarkBarViewTest4::Step4)); 400 CreateEventTask(this, &BookmarkBarViewTest4::Step4));
452 } 401 }
453 402
454 void Step4() { 403 void Step4() {
455 EXPECT_EQ(navigator_.url_, 404 ASSERT_TRUE(navigator_.url_ ==
456 model_->other_node()->GetChild(0)->GetURL()); 405 model_->other_node()->GetChild(0)->GetURL());
457 406
458 Done(); 407 Done();
459 } 408 }
460
461 ContextMenuNotificationObserver observer_;
462 }; 409 };
463 410
464 VIEW_TEST(BookmarkBarViewTest4, ContextMenus) 411 VIEW_TEST(BookmarkBarViewTest4, ContextMenus)
465 412
466 // Tests drag and drop within the same menu. 413 // Tests drag and drop within the same menu.
467 class BookmarkBarViewTest5 : public BookmarkBarViewEventTestBase { 414 class BookmarkBarViewTest5 : public BookmarkBarViewEventTestBase {
468 protected: 415 protected:
469 virtual void DoTestOnMessageLoop() { 416 virtual void DoTestOnMessageLoop() {
470 url_dragging_ = 417 url_dragging_ =
471 model_->GetBookmarkBarNode()->GetChild(0)->GetChild(0)->GetURL(); 418 model_->GetBookmarkBarNode()->GetChild(0)->GetChild(0)->GetURL();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 // Start a drag. 451 // Start a drag.
505 ui_controls::SendMouseMoveNotifyWhenDone(loc.x() + 10, loc.y(), 452 ui_controls::SendMouseMoveNotifyWhenDone(loc.x() + 10, loc.y(),
506 CreateEventTask(this, &BookmarkBarViewTest5::Step4)); 453 CreateEventTask(this, &BookmarkBarViewTest5::Step4));
507 454
508 // See comment above this method as to why we do this. 455 // See comment above this method as to why we do this.
509 ScheduleMouseMoveInBackground(loc.x(), loc.y()); 456 ScheduleMouseMoveInBackground(loc.x(), loc.y());
510 } 457 }
511 458
512 void Step4() { 459 void Step4() {
513 // Drop the item so that it's now the second item. 460 // Drop the item so that it's now the second item.
514 views::MenuItemView* target_menu = 461 views::MenuItemView* target_menu =
515 bb_view_->GetMenu()->GetSubmenu()->GetMenuItemAt(1); 462 bb_view_->GetMenu()->GetSubmenu()->GetMenuItemAt(1);
516 gfx::Point loc(1, target_menu->height() - 1); 463 gfx::Point loc(1, target_menu->height() - 1);
517 views::View::ConvertPointToScreen(target_menu, &loc); 464 views::View::ConvertPointToScreen(target_menu, &loc);
518 ui_controls::SendMouseMove(loc.x(), loc.y()); 465 ui_controls::SendMouseMove(loc.x(), loc.y());
519 466
520 ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT, 467 ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT,
521 ui_controls::UP, 468 ui_controls::UP,
522 CreateEventTask(this, &BookmarkBarViewTest5::Step5)); 469 CreateEventTask(this, &BookmarkBarViewTest5::Step5));
523 } 470 }
524 471
525 void Step5() { 472 void Step5() {
526 GURL url = model_->GetBookmarkBarNode()->GetChild(0)->GetChild(1)->GetURL(); 473 GURL url = model_->GetBookmarkBarNode()->GetChild(0)->GetChild(1)->GetURL();
527 EXPECT_EQ(url_dragging_, url); 474 ASSERT_TRUE(url == url_dragging_);
528 Done(); 475 Done();
529 } 476 }
530 477
531 GURL url_dragging_; 478 GURL url_dragging_;
532 }; 479 };
533 480
534 VIEW_TEST(BookmarkBarViewTest5, MAYBE_DND) 481 VIEW_TEST(BookmarkBarViewTest5, DND)
535 482
536 // Tests holding mouse down on overflow button, dragging such that menu pops up 483 // Tests holding mouse down on overflow button, dragging such that menu pops up
537 // then selecting an item. 484 // then selecting an item.
538 class BookmarkBarViewTest6 : public BookmarkBarViewEventTestBase { 485 class BookmarkBarViewTest6 : public BookmarkBarViewEventTestBase {
539 protected: 486 protected:
540 virtual void DoTestOnMessageLoop() { 487 virtual void DoTestOnMessageLoop() {
541 // Press the mouse button on the overflow button. Don't release it though. 488 // Press the mouse button on the overflow button. Don't release it though.
542 views::TextButton* button = bb_view_->overflow_button(); 489 views::TextButton* button = bb_view_->overflow_button();
543 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT, 490 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
544 ui_controls::DOWN, CreateEventTask(this, &BookmarkBarViewTest6::Step2)); 491 ui_controls::DOWN, CreateEventTask(this, &BookmarkBarViewTest6::Step2));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 } 581 }
635 582
636 void Step5() { 583 void Step5() {
637 ASSERT_TRUE(model_->other_node()->GetChild(0)->GetURL() == url_dragging_); 584 ASSERT_TRUE(model_->other_node()->GetChild(0)->GetURL() == url_dragging_);
638 Done(); 585 Done();
639 } 586 }
640 587
641 GURL url_dragging_; 588 GURL url_dragging_;
642 }; 589 };
643 590
644 VIEW_TEST(BookmarkBarViewTest7, MAYBE_DNDToDifferentMenu) 591 VIEW_TEST(BookmarkBarViewTest7, DNDToDifferentMenu)
645 592
646 // Drags from one menu to next so that original menu closes, then back to 593 // Drags from one menu to next so that original menu closes, then back to
647 // original menu. 594 // original menu.
648 class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase { 595 class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase {
649 protected: 596 protected:
650 virtual void DoTestOnMessageLoop() { 597 virtual void DoTestOnMessageLoop() {
651 url_dragging_ = 598 url_dragging_ =
652 model_->GetBookmarkBarNode()->GetChild(0)->GetChild(0)->GetURL(); 599 model_->GetBookmarkBarNode()->GetChild(0)->GetChild(0)->GetURL();
653 600
654 // Move the mouse to the first folder on the bookmark bar and press the 601 // Move the mouse to the first folder on the bookmark bar and press the
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 // Make sure drop was processed. 668 // Make sure drop was processed.
722 GURL final_url = model_->GetBookmarkBarNode()->GetChild(0)->GetChild(0)-> 669 GURL final_url = model_->GetBookmarkBarNode()->GetChild(0)->GetChild(0)->
723 GetChild(1)->GetURL(); 670 GetChild(1)->GetURL();
724 ASSERT_TRUE(final_url == url_dragging_); 671 ASSERT_TRUE(final_url == url_dragging_);
725 Done(); 672 Done();
726 } 673 }
727 674
728 GURL url_dragging_; 675 GURL url_dragging_;
729 }; 676 };
730 677
731 VIEW_TEST(BookmarkBarViewTest8, MAYBE_DNDBackToOriginatingMenu) 678 VIEW_TEST(BookmarkBarViewTest8, DNDBackToOriginatingMenu)
732 679
733 // Moves the mouse over the scroll button and makes sure we get scrolling. 680 // Moves the mouse over the scroll button and makes sure we get scrolling.
734 class BookmarkBarViewTest9 : public BookmarkBarViewEventTestBase { 681 class BookmarkBarViewTest9 : public BookmarkBarViewEventTestBase {
735 protected: 682 protected:
736 virtual bool CreateBigMenu() { return true; } 683 virtual bool CreateBigMenu() { return true; }
737 684
738 virtual void DoTestOnMessageLoop() { 685 virtual void DoTestOnMessageLoop() {
739 // Move the mouse to the first folder on the bookmark bar and press the 686 // Move the mouse to the first folder on the bookmark bar and press the
740 // mouse. 687 // mouse.
741 views::TextButton* button = bb_view_->GetBookmarkButton(0); 688 views::TextButton* button = bb_view_->GetBookmarkButton(0);
(...skipping 17 matching lines...) Expand all
759 // Move the mouse over the scroll button. 706 // Move the mouse over the scroll button.
760 views::View* scroll_container = menu->GetSubmenu()->GetParent(); 707 views::View* scroll_container = menu->GetSubmenu()->GetParent();
761 ASSERT_TRUE(scroll_container != NULL); 708 ASSERT_TRUE(scroll_container != NULL);
762 scroll_container = scroll_container->GetParent(); 709 scroll_container = scroll_container->GetParent();
763 ASSERT_TRUE(scroll_container != NULL); 710 ASSERT_TRUE(scroll_container != NULL);
764 views::View* scroll_down_button = scroll_container->GetChildViewAt(1); 711 views::View* scroll_down_button = scroll_container->GetChildViewAt(1);
765 ASSERT_TRUE(scroll_down_button); 712 ASSERT_TRUE(scroll_down_button);
766 gfx::Point loc(scroll_down_button->width() / 2, 713 gfx::Point loc(scroll_down_button->width() / 2,
767 scroll_down_button->height() / 2); 714 scroll_down_button->height() / 2);
768 views::View::ConvertPointToScreen(scroll_down_button, &loc); 715 views::View::ConvertPointToScreen(scroll_down_button, &loc);
769
770 // On linux, the sending one location isn't enough.
771 ui_controls::SendMouseMove(loc.x() - 1 , loc.y() - 1);
772 ui_controls::SendMouseMoveNotifyWhenDone( 716 ui_controls::SendMouseMoveNotifyWhenDone(
773 loc.x(), loc.y(), CreateEventTask(this, &BookmarkBarViewTest9::Step3)); 717 loc.x(), loc.y(), CreateEventTask(this, &BookmarkBarViewTest9::Step3));
774 } 718 }
775 719
776 void Step3() { 720 void Step3() {
777 MessageLoop::current()->PostDelayedTask(FROM_HERE, 721 MessageLoop::current()->PostDelayedTask(FROM_HERE,
778 NewRunnableMethod(this, &BookmarkBarViewTest9::Step4), 200); 722 NewRunnableMethod(this, &BookmarkBarViewTest9::Step4), 200);
779 } 723 }
780 724
781 void Step4() { 725 void Step4() {
782 gfx::Point menu_loc; 726 gfx::Point menu_loc;
783 views::View::ConvertPointToScreen(first_menu_, &menu_loc); 727 views::View::ConvertPointToScreen(first_menu_, &menu_loc);
784 ASSERT_NE(start_y_, menu_loc.y()); 728 ASSERT_NE(start_y_, menu_loc.y());
785 729
786 // Hide menu. 730 // Hide menu.
787 bb_view_->GetMenu()->GetMenuController()->Cancel(true); 731 bb_view_->GetMenu()->GetMenuController()->Cancel(true);
788 732
789 // On linux, Cancelling menu will call Quit on the message loop, 733 Done();
790 // which can interfere with Done. We need to run Done in the
791 // next execution loop.
792 MessageLoop::current()->PostTask(
793 FROM_HERE,
794 NewRunnableMethod(this, &ViewEventTestBase::Done));
795 } 734 }
796 735
797 int start_y_; 736 int start_y_;
798 views::MenuItemView* first_menu_; 737 views::MenuItemView* first_menu_;
799 }; 738 };
800 739
801 VIEW_TEST(BookmarkBarViewTest9, ScrollButtonScrolls) 740 VIEW_TEST(BookmarkBarViewTest9, ScrollButtonScrolls)
802 741
803 // Tests up/down/left/enter key messages. 742 // Tests up/down/left/enter key messages.
804 class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase { 743 class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase {
805 protected: 744 protected:
806 virtual void DoTestOnMessageLoop() { 745 virtual void DoTestOnMessageLoop() {
807 // Move the mouse to the first folder on the bookmark bar and press the 746 // Move the mouse to the first folder on the bookmark bar and press the
808 // mouse. 747 // mouse.
809 views::TextButton* button = bb_view_->GetBookmarkButton(0); 748 views::TextButton* button = bb_view_->GetBookmarkButton(0);
810 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT, 749 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
811 ui_controls::DOWN | ui_controls::UP, 750 ui_controls::DOWN | ui_controls::UP,
812 CreateEventTask(this, &BookmarkBarViewTest10::Step2)); 751 CreateEventTask(this, &BookmarkBarViewTest10::Step2));
813 MessageLoop::current()->RunAllPending();
814 } 752 }
815 753
816 private: 754 private:
817 void Step2() { 755 void Step2() {
818 // Menu should be showing. 756 // Menu should be showing.
819 views::MenuItemView* menu = bb_view_->GetMenu(); 757 views::MenuItemView* menu = bb_view_->GetMenu();
820 ASSERT_TRUE(menu != NULL); 758 ASSERT_TRUE(menu != NULL);
821 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 759 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
822 760
823 // Send a down event, which should select the first item. 761 // Send a down event, which should select the first item.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 797 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
860 views::MenuItemView* submenu = menu->GetSubmenu()->GetMenuItemAt(1); 798 views::MenuItemView* submenu = menu->GetSubmenu()->GetMenuItemAt(1);
861 ASSERT_TRUE(submenu->IsSelected()); 799 ASSERT_TRUE(submenu->IsSelected());
862 ASSERT_TRUE(submenu->GetSubmenu()); 800 ASSERT_TRUE(submenu->GetSubmenu());
863 ASSERT_TRUE(submenu->GetSubmenu()->IsShowing()); 801 ASSERT_TRUE(submenu->GetSubmenu()->IsShowing());
864 802
865 // Send a left arrow to close the submenu. 803 // Send a left arrow to close the submenu.
866 ui_controls::SendKeyPressNotifyWhenDone( 804 ui_controls::SendKeyPressNotifyWhenDone(
867 NULL, base::VKEY_LEFT, false, false, false, 805 NULL, base::VKEY_LEFT, false, false, false,
868 CreateEventTask(this, &BookmarkBarViewTest10::Step6)); 806 CreateEventTask(this, &BookmarkBarViewTest10::Step6));
869 MessageLoop::current()->RunAllPending();
870 } 807 }
871 808
872 void Step6() { 809 void Step6() {
873 // Make sure the submenu is showing. 810 // Make sure the submenu is showing.
874 views::MenuItemView* menu = bb_view_->GetMenu(); 811 views::MenuItemView* menu = bb_view_->GetMenu();
875 ASSERT_TRUE(menu != NULL); 812 ASSERT_TRUE(menu != NULL);
876 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 813 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
877 views::MenuItemView* submenu = menu->GetSubmenu()->GetMenuItemAt(1); 814 views::MenuItemView* submenu = menu->GetSubmenu()->GetMenuItemAt(1);
878 ASSERT_TRUE(submenu->IsSelected()); 815 ASSERT_TRUE(submenu->IsSelected());
879 ASSERT_TRUE(!submenu->GetSubmenu() || !submenu->GetSubmenu()->IsShowing()); 816 ASSERT_TRUE(!submenu->GetSubmenu() || !submenu->GetSubmenu()->IsShowing());
(...skipping 18 matching lines...) Expand all
898 } 835 }
899 836
900 void Step8() { 837 void Step8() {
901 ASSERT_TRUE( 838 ASSERT_TRUE(
902 model_->GetBookmarkBarNode()->GetChild(0)->GetChild(0)->GetURL() == 839 model_->GetBookmarkBarNode()->GetChild(0)->GetChild(0)->GetURL() ==
903 navigator_.url_); 840 navigator_.url_);
904 Done(); 841 Done();
905 } 842 }
906 }; 843 };
907 844
908 VIEW_TEST(BookmarkBarViewTest10, MAYBE_KeyEvents) 845 VIEW_TEST(BookmarkBarViewTest10, KeyEvents)
909 846
910 // Make sure the menu closes with the following sequence: show menu, show 847 // Make sure the menu closes with the following sequence: show menu, show
911 // context menu, close context menu (via escape), then click else where. This 848 // context menu, close context menu (via escape), then click else where. This
912 // effectively verifies we maintain mouse capture after the context menu is 849 // effectively verifies we maintain mouse capture after the context menu is
913 // hidden. 850 // hidden.
914 class BookmarkBarViewTest11 : public BookmarkBarViewEventTestBase { 851 class BookmarkBarViewTest11 : public BookmarkBarViewEventTestBase {
915 protected: 852 protected:
916 virtual void DoTestOnMessageLoop() { 853 virtual void DoTestOnMessageLoop() {
917 // Move the mouse to the first folder on the bookmark bar and press the 854 // Move the mouse to the first folder on the bookmark bar and press the
918 // mouse. 855 // mouse.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 void Step7() { 989 void Step7() {
1053 Done(); 990 Done();
1054 } 991 }
1055 }; 992 };
1056 993
1057 VIEW_TEST(BookmarkBarViewTest12, CloseWithModalDialog) 994 VIEW_TEST(BookmarkBarViewTest12, CloseWithModalDialog)
1058 995
1059 // Tests clicking on the separator of a context menu (this is for coverage of 996 // Tests clicking on the separator of a context menu (this is for coverage of
1060 // bug 17862). 997 // bug 17862).
1061 class BookmarkBarViewTest13 : public BookmarkBarViewEventTestBase { 998 class BookmarkBarViewTest13 : public BookmarkBarViewEventTestBase {
1062 public:
1063 BookmarkBarViewTest13()
1064 : ALLOW_THIS_IN_INITIALIZER_LIST(
1065 observer_(CreateEventTask(this, &BookmarkBarViewTest13::Step3))) {
1066 }
1067
1068 protected: 999 protected:
1069 virtual void DoTestOnMessageLoop() { 1000 virtual void DoTestOnMessageLoop() {
1070 // Move the mouse to the first folder on the bookmark bar and press the 1001 // Move the mouse to the first folder on the bookmark bar and press the
1071 // mouse. 1002 // mouse.
1072 views::TextButton* button = bb_view_->other_bookmarked_button(); 1003 views::TextButton* button = bb_view_->other_bookmarked_button();
1073 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT, 1004 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
1074 ui_controls::DOWN | ui_controls::UP, 1005 ui_controls::DOWN | ui_controls::UP,
1075 CreateEventTask(this, &BookmarkBarViewTest13::Step2)); 1006 CreateEventTask(this, &BookmarkBarViewTest13::Step2));
1076 } 1007 }
1077 1008
1078 private: 1009 private:
1079 void Step2() { 1010 void Step2() {
1080 // Menu should be showing. 1011 // Menu should be showing.
1081 views::MenuItemView* menu = bb_view_->GetMenu(); 1012 views::MenuItemView* menu = bb_view_->GetMenu();
1082 ASSERT_TRUE(menu != NULL); 1013 ASSERT_TRUE(menu != NULL);
1083 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 1014 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
1084 1015
1085 views::MenuItemView* child_menu = 1016 views::MenuItemView* child_menu =
1086 menu->GetSubmenu()->GetMenuItemAt(0); 1017 menu->GetSubmenu()->GetMenuItemAt(0);
1087 ASSERT_TRUE(child_menu != NULL); 1018 ASSERT_TRUE(child_menu != NULL);
1088 1019
1089 // Right click on the first child to get its context menu. 1020 // Right click on the first child to get its context menu.
1090 ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, 1021 ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
1091 ui_controls::DOWN | ui_controls::UP, NULL); 1022 ui_controls::DOWN | ui_controls::UP,
1092 // Step3 will be invoked by ContextMenuNotificationObserver. 1023 CreateEventTask(this, &BookmarkBarViewTest13::Step3));
1093 } 1024 }
1094 1025
1095 void Step3() { 1026 void Step3() {
1096 // Make sure the context menu is showing. 1027 // Make sure the context menu is showing.
1097 views::MenuItemView* menu = bb_view_->GetContextMenu(); 1028 views::MenuItemView* menu = bb_view_->GetContextMenu();
1098 ASSERT_TRUE(menu != NULL); 1029 ASSERT_TRUE(menu != NULL);
1099 ASSERT_TRUE(menu->GetSubmenu()); 1030 ASSERT_TRUE(menu->GetSubmenu());
1100 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 1031 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
1101 1032
1102 // Find the first separator. 1033 // Find the first separator.
(...skipping 22 matching lines...) Expand all
1125 ASSERT_TRUE(menu->GetSubmenu()); 1056 ASSERT_TRUE(menu->GetSubmenu());
1126 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 1057 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
1127 1058
1128 // Select the first context menu item. 1059 // Select the first context menu item.
1129 ui_controls::MoveMouseToCenterAndPress(menu->GetSubmenu()->GetMenuItemAt(0), 1060 ui_controls::MoveMouseToCenterAndPress(menu->GetSubmenu()->GetMenuItemAt(0),
1130 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, 1061 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
1131 CreateEventTask(this, &BookmarkBarViewTest13::Step5)); 1062 CreateEventTask(this, &BookmarkBarViewTest13::Step5));
1132 } 1063 }
1133 1064
1134 void Step5() { 1065 void Step5() {
1066 DLOG(WARNING) << " DONE";
1135 Done(); 1067 Done();
1136 } 1068 }
1137
1138 ContextMenuNotificationObserver observer_;
1139 }; 1069 };
1140 1070
1141 VIEW_TEST(BookmarkBarViewTest13, ClickOnContextMenuSeparator) 1071 VIEW_TEST(BookmarkBarViewTest13, ClickOnContextMenuSeparator)
1142 1072
1143 // Makes sure right cliking on a folder on the bookmark bar doesn't result in 1073 // Makes sure right cliking on a folder on the bookmark bar doesn't result in
1144 // both a context menu and showing the menu. 1074 // both a context menu and showing the menu.
1145 class BookmarkBarViewTest14 : public BookmarkBarViewEventTestBase { 1075 class BookmarkBarViewTest14 : public BookmarkBarViewEventTestBase {
1146 public:
1147 BookmarkBarViewTest14()
1148 : ALLOW_THIS_IN_INITIALIZER_LIST(
1149 observer_(CreateEventTask(this, &BookmarkBarViewTest14::Step2))) {
1150 }
1151
1152 protected: 1076 protected:
1153 virtual void DoTestOnMessageLoop() { 1077 virtual void DoTestOnMessageLoop() {
1154 // Move the mouse to the first folder on the bookmark bar and press the 1078 // Move the mouse to the first folder on the bookmark bar and press the
1155 // right mouse button. 1079 // right mouse button.
1156 views::TextButton* button = bb_view_->GetBookmarkButton(0); 1080 views::TextButton* button = bb_view_->GetBookmarkButton(0);
1157 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::RIGHT, 1081 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::RIGHT,
1158 ui_controls::DOWN | ui_controls::UP, NULL); 1082 ui_controls::DOWN | ui_controls::UP,
1159 // Step2 will be invoked by ContextMenuNotificationObserver. 1083 CreateEventTask(this, &BookmarkBarViewTest14::Step2));
1160 } 1084 }
1161 1085
1162 private: 1086 private:
1163
1164 void Step2() { 1087 void Step2() {
1165 // Menu should NOT be showing. 1088 // Menu should NOT be showing.
1166 views::MenuItemView* menu = bb_view_->GetMenu(); 1089 views::MenuItemView* menu = bb_view_->GetMenu();
1167 ASSERT_TRUE(menu == NULL); 1090 ASSERT_TRUE(menu == NULL);
1168 1091
1169 // Send escape so that the context menu hides. 1092 // Send escape so that the context menu hides.
1170 ui_controls::SendKeyPressNotifyWhenDone( 1093 ui_controls::SendKeyPressNotifyWhenDone(
1171 NULL, base::VKEY_ESCAPE, false, false, false, 1094 NULL, base::VKEY_ESCAPE, false, false, false,
1172 CreateEventTask(this, &BookmarkBarViewTest14::Step3)); 1095 CreateEventTask(this, &BookmarkBarViewTest14::Step3));
1173 } 1096 }
1174 1097
1175 void Step3() { 1098 void Step3() {
1176 Done(); 1099 Done();
1177 } 1100 }
1178
1179 ContextMenuNotificationObserver observer_;
1180 }; 1101 };
1181 1102
1182 VIEW_TEST(BookmarkBarViewTest14, ContextMenus2) 1103 VIEW_TEST(BookmarkBarViewTest14, ContextMenus2)
1183 1104
1184 // Makes sure deleting from the context menu keeps the bookmark menu showing. 1105 // Makes sure deleting from the context menu keeps the bookmark menu showing.
1185 class BookmarkBarViewTest15 : public BookmarkBarViewEventTestBase { 1106 class BookmarkBarViewTest15 : public BookmarkBarViewEventTestBase {
1186 public: 1107 public:
1187 BookmarkBarViewTest15() 1108 BookmarkBarViewTest15() : deleted_menu_id_(0) {}
1188 : deleted_menu_id_(0),
1189 ALLOW_THIS_IN_INITIALIZER_LIST(
1190 observer_(CreateEventTask(this, &BookmarkBarViewTest15::Step3))) {
1191 }
1192 1109
1193 protected: 1110 protected:
1194 virtual void DoTestOnMessageLoop() { 1111 virtual void DoTestOnMessageLoop() {
1195 // Show the other bookmarks. 1112 // Show the other bookmarks.
1196 views::TextButton* button = bb_view_->other_bookmarked_button(); 1113 views::TextButton* button = bb_view_->other_bookmarked_button();
1197 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT, 1114 ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
1198 ui_controls::DOWN | ui_controls::UP, 1115 ui_controls::DOWN | ui_controls::UP,
1199 CreateEventTask(this, &BookmarkBarViewTest15::Step2)); 1116 CreateEventTask(this, &BookmarkBarViewTest15::Step2));
1200 } 1117 }
1201 1118
1202 private: 1119 private:
1203 void Step2() { 1120 void Step2() {
1204 // Menu should be showing. 1121 // Menu should be showing.
1205 views::MenuItemView* menu = bb_view_->GetMenu(); 1122 views::MenuItemView* menu = bb_view_->GetMenu();
1206 ASSERT_TRUE(menu != NULL); 1123 ASSERT_TRUE(menu != NULL);
1207 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 1124 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
1208 1125
1209 views::MenuItemView* child_menu = 1126 views::MenuItemView* child_menu =
1210 menu->GetSubmenu()->GetMenuItemAt(1); 1127 menu->GetSubmenu()->GetMenuItemAt(1);
1211 ASSERT_TRUE(child_menu != NULL); 1128 ASSERT_TRUE(child_menu != NULL);
1212 1129
1213 deleted_menu_id_ = child_menu->GetCommand(); 1130 deleted_menu_id_ = child_menu->GetCommand();
1214 1131
1215 // Right click on the second child to get its context menu. 1132 // Right click on the second child to get its context menu.
1216 ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, 1133 ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
1217 ui_controls::DOWN | ui_controls::UP, NULL); 1134 ui_controls::DOWN | ui_controls::UP,
1218 // Step3 will be invoked by ContextMenuNotificationObserver. 1135 CreateEventTask(this, &BookmarkBarViewTest15::Step3));
1219 } 1136 }
1220 1137
1221 void Step3() { 1138 void Step3() {
1222 // Make sure the context menu is showing. 1139 // Make sure the context menu is showing.
1223 views::MenuItemView* menu = bb_view_->GetContextMenu(); 1140 views::MenuItemView* menu = bb_view_->GetContextMenu();
1224 ASSERT_TRUE(menu != NULL); 1141 ASSERT_TRUE(menu != NULL);
1225 ASSERT_TRUE(menu->GetSubmenu()); 1142 ASSERT_TRUE(menu->GetSubmenu());
1226 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 1143 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
1227 1144
1228 views::MenuItemView* delete_menu = 1145 views::MenuItemView* delete_menu =
(...skipping 18 matching lines...) Expand all
1247 1164
1248 // And the deleted_menu_id_ should have been removed. 1165 // And the deleted_menu_id_ should have been removed.
1249 ASSERT_TRUE(menu->GetMenuItemByID(deleted_menu_id_) == NULL); 1166 ASSERT_TRUE(menu->GetMenuItemByID(deleted_menu_id_) == NULL);
1250 1167
1251 bb_view_->GetMenu()->GetMenuController()->Cancel(true); 1168 bb_view_->GetMenu()->GetMenuController()->Cancel(true);
1252 1169
1253 Done(); 1170 Done();
1254 } 1171 }
1255 1172
1256 int deleted_menu_id_; 1173 int deleted_menu_id_;
1257 ContextMenuNotificationObserver observer_;
1258 }; 1174 };
1259 1175
1260 VIEW_TEST(BookmarkBarViewTest15, MenuStaysVisibleAfterDelete) 1176 VIEW_TEST(BookmarkBarViewTest15, MenuStaysVisibleAfterDelete)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/views/bookmark_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698