OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 private: | 183 private: |
184 std::string html_contents_; | 184 std::string html_contents_; |
185 }; | 185 }; |
186 | 186 |
187 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { | 187 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { |
188 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 188 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
189 #if defined(OS_POSIX) | 189 #if defined(OS_POSIX) |
190 // It seems we have to wait a little bit for the widgets to spin up before | 190 // It seems we have to wait a little bit for the widgets to spin up before |
191 // we can start clicking on them. | 191 // we can start clicking on them. |
192 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 192 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
193 new MessageLoop::QuitTask(), | 193 MessageLoop::QuitClosure(), |
194 kActionDelayMs); | 194 kActionDelayMs); |
195 ui_test_utils::RunMessageLoop(); | 195 ui_test_utils::RunMessageLoop(); |
196 #endif // defined(OS_POSIX) | 196 #endif // defined(OS_POSIX) |
197 | 197 |
198 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); | 198 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
199 | 199 |
200 ClickOnView(VIEW_ID_TAB_CONTAINER); | 200 ClickOnView(VIEW_ID_TAB_CONTAINER); |
201 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 201 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
202 | 202 |
203 ClickOnView(VIEW_ID_LOCATION_BAR); | 203 ClickOnView(VIEW_ID_LOCATION_BAR); |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 // Focus should be on the page. | 584 // Focus should be on the page. |
585 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 585 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
586 | 586 |
587 // Let's show an interstitial. | 587 // Let's show an interstitial. |
588 TestInterstitialPage* interstitial_page = | 588 TestInterstitialPage* interstitial_page = |
589 new TestInterstitialPage(browser()->GetSelectedTabContents(), | 589 new TestInterstitialPage(browser()->GetSelectedTabContents(), |
590 true, GURL("http://interstitial.com")); | 590 true, GURL("http://interstitial.com")); |
591 interstitial_page->Show(); | 591 interstitial_page->Show(); |
592 // Give some time for the interstitial to show. | 592 // Give some time for the interstitial to show. |
593 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 593 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
594 new MessageLoop::QuitTask(), | 594 MessageLoop::QuitClosure(), |
595 1000); | 595 1000); |
596 ui_test_utils::RunMessageLoop(); | 596 ui_test_utils::RunMessageLoop(); |
597 | 597 |
598 browser()->FocusLocationBar(); | 598 browser()->FocusLocationBar(); |
599 | 599 |
600 const char* kExpElementIDs[] = { | 600 const char* kExpElementIDs[] = { |
601 "", // Initially no element in the page should be focused | 601 "", // Initially no element in the page should be focused |
602 // (the location bar is focused). | 602 // (the location bar is focused). |
603 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", | 603 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", |
604 "gmapLink" | 604 "gmapLink" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()-> | 710 EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()-> |
711 HasFocus()); | 711 HasFocus()); |
712 | 712 |
713 // Let's show an interstitial. | 713 // Let's show an interstitial. |
714 TestInterstitialPage* interstitial_page = | 714 TestInterstitialPage* interstitial_page = |
715 new TestInterstitialPage(browser()->GetSelectedTabContents(), | 715 new TestInterstitialPage(browser()->GetSelectedTabContents(), |
716 true, GURL("http://interstitial.com")); | 716 true, GURL("http://interstitial.com")); |
717 interstitial_page->Show(); | 717 interstitial_page->Show(); |
718 // Give some time for the interstitial to show. | 718 // Give some time for the interstitial to show. |
719 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 719 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
720 new MessageLoop::QuitTask(), | 720 MessageLoop::QuitClosure(), |
721 1000); | 721 1000); |
722 ui_test_utils::RunMessageLoop(); | 722 ui_test_utils::RunMessageLoop(); |
723 | 723 |
724 // The interstitial should have focus now. | 724 // The interstitial should have focus now. |
725 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 725 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
726 EXPECT_TRUE(interstitial_page->HasFocus()); | 726 EXPECT_TRUE(interstitial_page->HasFocus()); |
727 | 727 |
728 // Hide the interstitial. | 728 // Hide the interstitial. |
729 interstitial_page->DontProceed(); | 729 interstitial_page->DontProceed(); |
730 | 730 |
(...skipping 27 matching lines...) Expand all Loading... |
758 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 758 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
759 browser(), ui::VKEY_F, true, false, false, false)); | 759 browser(), ui::VKEY_F, true, false, false, false)); |
760 #endif | 760 #endif |
761 | 761 |
762 // Ideally, we wouldn't sleep here and instead would intercept the | 762 // Ideally, we wouldn't sleep here and instead would intercept the |
763 // RenderViewHostDelegate::HandleKeyboardEvent() callback. To do that, we | 763 // RenderViewHostDelegate::HandleKeyboardEvent() callback. To do that, we |
764 // could create a RenderViewHostDelegate wrapper and hook-it up by either: | 764 // could create a RenderViewHostDelegate wrapper and hook-it up by either: |
765 // - creating a factory used to create the delegate | 765 // - creating a factory used to create the delegate |
766 // - making the test a private and overwriting the delegate member directly. | 766 // - making the test a private and overwriting the delegate member directly. |
767 MessageLoop::current()->PostDelayedTask( | 767 MessageLoop::current()->PostDelayedTask( |
768 FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs); | 768 FROM_HERE, MessageLoop::QuitClosure(), kActionDelayMs); |
769 ui_test_utils::RunMessageLoop(); | 769 ui_test_utils::RunMessageLoop(); |
770 | 770 |
771 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 771 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
772 | 772 |
773 browser()->FocusLocationBar(); | 773 browser()->FocusLocationBar(); |
774 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); | 774 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
775 | 775 |
776 // Now press Ctrl+F again and focus should move to the Find box. | 776 // Now press Ctrl+F again and focus should move to the Find box. |
777 #if defined(OS_MACOSX) | 777 #if defined(OS_MACOSX) |
778 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 778 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
(...skipping 12 matching lines...) Expand all Loading... |
791 #if defined(OS_MACOSX) | 791 #if defined(OS_MACOSX) |
792 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 792 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
793 browser(), ui::VKEY_F, false, false, false, true)); | 793 browser(), ui::VKEY_F, false, false, false, true)); |
794 #else | 794 #else |
795 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 795 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
796 browser(), ui::VKEY_F, true, false, false, false)); | 796 browser(), ui::VKEY_F, true, false, false, false)); |
797 #endif | 797 #endif |
798 | 798 |
799 // See remark above on why we wait. | 799 // See remark above on why we wait. |
800 MessageLoop::current()->PostDelayedTask( | 800 MessageLoop::current()->PostDelayedTask( |
801 FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs); | 801 FROM_HERE, MessageLoop::QuitClosure(), kActionDelayMs); |
802 ui_test_utils::RunMessageLoop(); | 802 ui_test_utils::RunMessageLoop(); |
803 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 803 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
804 } | 804 } |
805 | 805 |
806 // Makes sure the focus is in the right location when opening the different | 806 // Makes sure the focus is in the right location when opening the different |
807 // types of tabs. | 807 // types of tabs. |
808 // Flaky, http://crbug.com/62539. | 808 // Flaky, http://crbug.com/62539. |
809 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_TabInitialFocus) { | 809 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_TabInitialFocus) { |
810 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 810 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
811 | 811 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 browser()->Reload(CURRENT_TAB); | 895 browser()->Reload(CURRENT_TAB); |
896 observer.Wait(); | 896 observer.Wait(); |
897 } | 897 } |
898 | 898 |
899 // Focus should now be on the tab contents. | 899 // Focus should now be on the tab contents. |
900 browser()->ShowDownloadsTab(); | 900 browser()->ShowDownloadsTab(); |
901 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 901 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
902 } | 902 } |
903 | 903 |
904 } // namespace | 904 } // namespace |
OLD | NEW |