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