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

Side by Side Diff: chrome/browser/browser_keyevents_browsertest.cc

Issue 5576002: Fix BrowserKeyEventsTest.ReservedAccelerators on Mac 10.6 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unittest and remove FLAKY tag. Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/nsmenuitem_additions.h » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "app/keyboard_codes.h" 7 #include "app/keyboard_codes.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccess1)); 629 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccess1));
630 #if defined(TOOLKIT_GTK) 630 #if defined(TOOLKIT_GTK)
631 // On GTK, alt-0..9 are assigned as tab selection accelerators, so they can 631 // On GTK, alt-0..9 are assigned as tab selection accelerators, so they can
632 // not be used as accesskeys. 632 // not be used as accesskeys.
633 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); 633 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
634 #else 634 #else
635 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"1")); 635 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"1"));
636 #endif 636 #endif
637 } 637 }
638 638
639 #if defined(OS_MACOSX) 639 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, ReservedAccelerators) {
640 // See http://crbug.com/50447 for details.
641 #define MAYBE_ReservedAccelerators FLAKY_ReservedAccelerators
642 #else
643 #define MAYBE_ReservedAccelerators ReservedAccelerators
644 #endif
645
646 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_ReservedAccelerators) {
647 ASSERT_TRUE(test_server()->Start()); 640 ASSERT_TRUE(test_server()->Start());
648 641
649 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 642 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
650 GURL url = test_server()->GetURL(kTestingPage); 643 GURL url = test_server()->GetURL(kTestingPage);
651 ui_test_utils::NavigateToURL(browser(), url); 644 ui_test_utils::NavigateToURL(browser(), url);
652 645
653 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); 646 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
654 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 647 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
655 648
656 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) 649 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
657 static const KeyEventTestData kTestCtrlT = { 650 static const KeyEventTestData kTestCtrlT = {
658 app::VKEY_T, true, false, false, false, 651 app::VKEY_T, true, false, false, false,
659 true, false, false, false, 1, 652 true, false, false, false, 1,
660 { "D 17 0 true false false false" } 653 { "D 17 0 true false false false" }
661 }; 654 };
662 655
663 ASSERT_EQ(1, browser()->tab_count()); 656 ASSERT_EQ(1, browser()->tab_count());
664 // Press Ctrl+T, which will open a new tab. 657 // Press Ctrl+T, which will open a new tab.
665 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlT)); 658 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlT));
666 EXPECT_EQ(2, browser()->tab_count()); 659 EXPECT_EQ(2, browser()->tab_count());
667 browser()->SelectNumberedTab(0); 660 browser()->SelectNumberedTab(0);
668 ASSERT_EQ(0, browser()->selected_index()); 661 ASSERT_EQ(0, browser()->selected_index());
669 662
670 int result_length; 663 int result_length;
671 ASSERT_NO_FATAL_FAILURE(GetResultLength(0, &result_length)); 664 ASSERT_NO_FATAL_FAILURE(GetResultLength(0, &result_length));
672 EXPECT_EQ(1, result_length); 665 EXPECT_EQ(1, result_length);
673 666
667 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
668
674 // Reserved accelerators can't be suppressed. 669 // Reserved accelerators can't be suppressed.
675 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true)); 670 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true));
676 // Press Ctrl+W, which will close the tab. 671 // Press Ctrl+W, which will close the tab.
677 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 672 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
678 browser(), app::VKEY_W, true, false, false, false)); 673 browser(), app::VKEY_W, true, false, false, false));
679 EXPECT_EQ(1, browser()->tab_count()); 674 EXPECT_EQ(1, browser()->tab_count());
680 #elif defined(OS_MACOSX) 675 #elif defined(OS_MACOSX)
681 static const KeyEventTestData kTestCmdT = { 676 static const KeyEventTestData kTestCmdT = {
682 app::VKEY_T, false, false, false, true, 677 app::VKEY_T, false, false, false, true,
683 true, false, false, false, 1, 678 true, false, false, false, 1,
684 { "D 91 0 false false false true" } 679 { "D 91 0 false false false true" }
685 }; 680 };
686 681
687 ASSERT_EQ(1, browser()->tab_count()); 682 ASSERT_EQ(1, browser()->tab_count());
688 // Press Cmd+T, which will open a new tab. 683
684 ui_test_utils::WindowedNotificationObserver wait_for_new_tab(
685 NotificationType::TAB_PARENTED,
686 NotificationService::AllSources());
687
688 // Press Cmd+T, which will open a new tab, it can not be suppressed.
Ilya Sherman 2010/12/04 02:31:00 nit: The added part would be better as ". It canno
James Su 2010/12/04 03:21:11 Done.
689 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCmdT)); 689 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCmdT));
690 EXPECT_EQ(2, browser()->tab_count()); 690
691 browser()->SelectNumberedTab(0); 691 wait_for_new_tab.WaitFor(Source<NavigationController>(
692 ASSERT_EQ(0, browser()->selected_index()); 692 &browser()->GetTabContentsAt(1)->controller()));
693 693
694 int result_length; 694 int result_length;
695 ASSERT_NO_FATAL_FAILURE(GetResultLength(0, &result_length)); 695 ASSERT_NO_FATAL_FAILURE(GetResultLength(0, &result_length));
696 EXPECT_EQ(1, result_length); 696 EXPECT_EQ(1, result_length);
697 697
698 EXPECT_EQ(2, browser()->tab_count());
699 ASSERT_EQ(1, browser()->selected_index());
700
701 // Because of issue http://crbug.com/65375, switching back to the first tab
702 // may cause the focus to be grabbed by omnibox. So instead, we load our
703 // testing page in the newly created tab and try Cmd-W here.
704 ui_test_utils::NavigateToURL(browser(), url);
705
706 // Make sure the focus is in the testing page.
707 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
708 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
709
698 // Reserved accelerators can't be suppressed. 710 // Reserved accelerators can't be suppressed.
699 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true)); 711 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(1, true));
712
700 // Press Cmd+W, which will close the tab. 713 // Press Cmd+W, which will close the tab.
701 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 714 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
702 browser(), app::VKEY_W, false, false, false, true)); 715 browser(), app::VKEY_W, false, false, false, true));
703 EXPECT_EQ(1, browser()->tab_count()); 716 EXPECT_EQ(1, browser()->tab_count());
704 #elif defined(TOOLKIT_GTK) 717 #elif defined(TOOLKIT_GTK)
705 // Ctrl-[a-z] are not treated as reserved accelerators on GTK. 718 // Ctrl-[a-z] are not treated as reserved accelerators on GTK.
706 static const KeyEventTestData kTestCtrlT = { 719 static const KeyEventTestData kTestCtrlT = {
707 app::VKEY_T, true, false, false, false, 720 app::VKEY_T, true, false, false, false,
708 false, false, false, false, 2, 721 false, false, false, false, 2,
709 { "D 17 0 true false false false", 722 { "D 17 0 true false false false",
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 757
745 // Ctrl+T should be blockable. 758 // Ctrl+T should be blockable.
746 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlTBlocked)); 759 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlTBlocked));
747 ASSERT_EQ(1, browser()->tab_count()); 760 ASSERT_EQ(1, browser()->tab_count());
748 761
749 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlT)); 762 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlT));
750 ASSERT_EQ(2, browser()->tab_count()); 763 ASSERT_EQ(2, browser()->tab_count());
751 ASSERT_EQ(1, browser()->selected_index()); 764 ASSERT_EQ(1, browser()->selected_index());
752 browser()->SelectNumberedTab(0); 765 browser()->SelectNumberedTab(0);
753 ASSERT_EQ(0, browser()->selected_index()); 766 ASSERT_EQ(0, browser()->selected_index());
767 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
754 768
755 // Ctrl+PageDown and Ctrl+Tab switches to the next tab. 769 // Ctrl+PageDown and Ctrl+Tab switches to the next tab.
756 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlPageDown)); 770 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlPageDown));
757 ASSERT_EQ(1, browser()->selected_index()); 771 ASSERT_EQ(1, browser()->selected_index());
758 772
759 browser()->SelectNumberedTab(0); 773 browser()->SelectNumberedTab(0);
760 ASSERT_EQ(0, browser()->selected_index()); 774 ASSERT_EQ(0, browser()->selected_index());
775 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
776
761 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlTab)); 777 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlTab));
762 ASSERT_EQ(1, browser()->selected_index()); 778 ASSERT_EQ(1, browser()->selected_index());
763 779
764 // Ctrl+W should be blockable. 780 // Ctrl+W should be blockable.
765 browser()->SelectNumberedTab(0); 781 browser()->SelectNumberedTab(0);
766 ASSERT_EQ(0, browser()->selected_index()); 782 ASSERT_EQ(0, browser()->selected_index());
783 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
784
767 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlWBlocked)); 785 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlWBlocked));
768 ASSERT_EQ(2, browser()->tab_count()); 786 ASSERT_EQ(2, browser()->tab_count());
769 787
770 // Ctrl+F4 to close the tab. 788 // Ctrl+F4 to close the tab.
771 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true)); 789 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true));
772 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 790 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
773 browser(), app::VKEY_F4, true, false, false, false)); 791 browser(), app::VKEY_F4, true, false, false, false));
774 ASSERT_EQ(1, browser()->tab_count()); 792 ASSERT_EQ(1, browser()->tab_count());
775 #endif 793 #endif
776 } 794 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); 921 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress));
904 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 922 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
905 923
906 // Ctrl+Alt should have no effect. 924 // Ctrl+Alt should have no effect.
907 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); 925 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey));
908 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 926 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
909 } 927 }
910 #endif 928 #endif
911 929
912 } // namespace 930 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/nsmenuitem_additions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698