| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 138 |
| 139 // Wait the focus change in message loop. | 139 // Wait the focus change in message loop. |
| 140 void CheckFocus(Browser* browser, ViewID id, const base::Time& timeout) { | 140 void CheckFocus(Browser* browser, ViewID id, const base::Time& timeout) { |
| 141 if (ui_test_utils::IsViewFocused(browser, id) || | 141 if (ui_test_utils::IsViewFocused(browser, id) || |
| 142 base::Time::Now() > timeout) { | 142 base::Time::Now() > timeout) { |
| 143 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 143 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 144 } else { | 144 } else { |
| 145 MessageLoop::current()->PostDelayedTask( | 145 MessageLoop::current()->PostDelayedTask( |
| 146 FROM_HERE, | 146 FROM_HERE, |
| 147 base::Bind(&CheckFocus, browser, id, timeout), | 147 base::Bind(&CheckFocus, browser, id, timeout), |
| 148 10); | 148 base::TimeDelta::FromMilliseconds(10)); |
| 149 } | 149 } |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 class BrowserFocusTest : public InProcessBrowserTest { | 152 class BrowserFocusTest : public InProcessBrowserTest { |
| 153 public: | 153 public: |
| 154 BrowserFocusTest() : | 154 BrowserFocusTest() : |
| 155 #if defined(USE_AURA) | 155 #if defined(USE_AURA) |
| 156 location_bar_focus_view_id_(VIEW_ID_OMNIBOX) | 156 location_bar_focus_view_id_(VIEW_ID_OMNIBOX) |
| 157 #else | 157 #else |
| 158 location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR) | 158 location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 169 void ClickOnView(ViewID vid) { | 169 void ClickOnView(ViewID vid) { |
| 170 ui_test_utils::ClickOnView(browser(), vid); | 170 ui_test_utils::ClickOnView(browser(), vid); |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool WaitForFocusChange(ViewID vid) { | 173 bool WaitForFocusChange(ViewID vid) { |
| 174 const base::Time timeout = base::Time::Now() + | 174 const base::Time timeout = base::Time::Now() + |
| 175 base::TimeDelta::FromMilliseconds(kFocusChangeTimeoutMs); | 175 base::TimeDelta::FromMilliseconds(kFocusChangeTimeoutMs); |
| 176 MessageLoop::current()->PostDelayedTask( | 176 MessageLoop::current()->PostDelayedTask( |
| 177 FROM_HERE, | 177 FROM_HERE, |
| 178 base::Bind(&CheckFocus, browser(), vid, timeout), | 178 base::Bind(&CheckFocus, browser(), vid, timeout), |
| 179 100); | 179 base::TimeDelta::FromMilliseconds(100)); |
| 180 ui_test_utils::RunMessageLoop(); | 180 ui_test_utils::RunMessageLoop(); |
| 181 return IsViewFocused(vid); | 181 return IsViewFocused(vid); |
| 182 } | 182 } |
| 183 | 183 |
| 184 ViewID location_bar_focus_view_id_; | 184 ViewID location_bar_focus_view_id_; |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 class TestInterstitialPage : public content::InterstitialPageDelegate { | 187 class TestInterstitialPage : public content::InterstitialPageDelegate { |
| 188 public: | 188 public: |
| 189 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { | 189 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 218 private: | 218 private: |
| 219 std::string html_contents_; | 219 std::string html_contents_; |
| 220 InterstitialPage* interstitial_page_; // Owns us. | 220 InterstitialPage* interstitial_page_; // Owns us. |
| 221 }; | 221 }; |
| 222 | 222 |
| 223 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { | 223 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { |
| 224 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 224 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 225 #if defined(OS_POSIX) | 225 #if defined(OS_POSIX) |
| 226 // It seems we have to wait a little bit for the widgets to spin up before | 226 // It seems we have to wait a little bit for the widgets to spin up before |
| 227 // we can start clicking on them. | 227 // we can start clicking on them. |
| 228 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 228 MessageLoop::current()->PostDelayedTask( |
| 229 MessageLoop::QuitClosure(), | 229 FROM_HERE, |
| 230 kActionDelayMs); | 230 MessageLoop::QuitClosure(), |
| 231 base::TimeDelta::FromMilliseconds(kActionDelayMs)); |
| 231 ui_test_utils::RunMessageLoop(); | 232 ui_test_utils::RunMessageLoop(); |
| 232 #endif // defined(OS_POSIX) | 233 #endif // defined(OS_POSIX) |
| 233 | 234 |
| 234 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); | 235 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
| 235 | 236 |
| 236 ClickOnView(VIEW_ID_TAB_CONTAINER); | 237 ClickOnView(VIEW_ID_TAB_CONTAINER); |
| 237 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 238 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 238 | 239 |
| 239 ClickOnView(VIEW_ID_LOCATION_BAR); | 240 ClickOnView(VIEW_ID_LOCATION_BAR); |
| 240 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); | 241 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 // Focus should be on the page. | 621 // Focus should be on the page. |
| 621 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 622 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 622 | 623 |
| 623 // Let's show an interstitial. | 624 // Let's show an interstitial. |
| 624 TestInterstitialPage* interstitial_page = | 625 TestInterstitialPage* interstitial_page = |
| 625 new TestInterstitialPage(browser()->GetSelectedWebContents(), | 626 new TestInterstitialPage(browser()->GetSelectedWebContents(), |
| 626 true, GURL("http://interstitial.com")); | 627 true, GURL("http://interstitial.com")); |
| 627 // Give some time for the interstitial to show. | 628 // Give some time for the interstitial to show. |
| 628 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 629 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 629 MessageLoop::QuitClosure(), | 630 MessageLoop::QuitClosure(), |
| 630 1000); | 631 base::TimeDelta::FromSeconds(1)); |
| 631 ui_test_utils::RunMessageLoop(); | 632 ui_test_utils::RunMessageLoop(); |
| 632 | 633 |
| 633 browser()->FocusLocationBar(); | 634 browser()->FocusLocationBar(); |
| 634 | 635 |
| 635 const char* kExpElementIDs[] = { | 636 const char* kExpElementIDs[] = { |
| 636 "", // Initially no element in the page should be focused | 637 "", // Initially no element in the page should be focused |
| 637 // (the location bar is focused). | 638 // (the location bar is focused). |
| 638 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", | 639 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", |
| 639 "gmapLink" | 640 "gmapLink" |
| 640 }; | 641 }; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 EXPECT_TRUE(browser()->GetSelectedWebContents()->GetRenderViewHost()->view()-> | 746 EXPECT_TRUE(browser()->GetSelectedWebContents()->GetRenderViewHost()->view()-> |
| 746 HasFocus()); | 747 HasFocus()); |
| 747 | 748 |
| 748 // Let's show an interstitial. | 749 // Let's show an interstitial. |
| 749 TestInterstitialPage* interstitial_page = | 750 TestInterstitialPage* interstitial_page = |
| 750 new TestInterstitialPage(browser()->GetSelectedWebContents(), | 751 new TestInterstitialPage(browser()->GetSelectedWebContents(), |
| 751 true, GURL("http://interstitial.com")); | 752 true, GURL("http://interstitial.com")); |
| 752 // Give some time for the interstitial to show. | 753 // Give some time for the interstitial to show. |
| 753 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 754 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 754 MessageLoop::QuitClosure(), | 755 MessageLoop::QuitClosure(), |
| 755 1000); | 756 base::TimeDelta::FromSeconds(1)); |
| 756 ui_test_utils::RunMessageLoop(); | 757 ui_test_utils::RunMessageLoop(); |
| 757 | 758 |
| 758 // The interstitial should have focus now. | 759 // The interstitial should have focus now. |
| 759 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 760 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 760 EXPECT_TRUE(interstitial_page->HasFocus()); | 761 EXPECT_TRUE(interstitial_page->HasFocus()); |
| 761 | 762 |
| 762 // Hide the interstitial. | 763 // Hide the interstitial. |
| 763 interstitial_page->DontProceed(); | 764 interstitial_page->DontProceed(); |
| 764 | 765 |
| 765 // Focus should be back on the original page. | 766 // Focus should be back on the original page. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 browser()->Reload(CURRENT_TAB); | 920 browser()->Reload(CURRENT_TAB); |
| 920 observer.Wait(); | 921 observer.Wait(); |
| 921 } | 922 } |
| 922 | 923 |
| 923 // Focus should now be on the tab contents. | 924 // Focus should now be on the tab contents. |
| 924 browser()->ShowDownloadsTab(); | 925 browser()->ShowDownloadsTab(); |
| 925 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 926 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 926 } | 927 } |
| 927 | 928 |
| 928 } // namespace | 929 } // namespace |
| OLD | NEW |