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

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

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