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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 #else | 133 #else |
134 // Windows only at the moment. | 134 // Windows only at the moment. |
135 return true; | 135 return true; |
136 #endif | 136 #endif |
137 } | 137 } |
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 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 144 base::MessageLoop::QuitClosure()); |
144 } else { | 145 } else { |
145 MessageLoop::current()->PostDelayedTask( | 146 base::MessageLoop::current()->PostDelayedTask( |
146 FROM_HERE, | 147 FROM_HERE, |
147 base::Bind(&CheckFocus, browser, id, timeout), | 148 base::Bind(&CheckFocus, browser, id, timeout), |
148 base::TimeDelta::FromMilliseconds(10)); | 149 base::TimeDelta::FromMilliseconds(10)); |
149 } | 150 } |
150 }; | 151 }; |
151 | 152 |
152 class BrowserFocusTest : public InProcessBrowserTest { | 153 class BrowserFocusTest : public InProcessBrowserTest { |
153 public: | 154 public: |
154 bool IsViewFocused(ViewID vid) { | 155 bool IsViewFocused(ViewID vid) { |
155 return ui_test_utils::IsViewFocused(browser(), vid); | 156 return ui_test_utils::IsViewFocused(browser(), vid); |
156 } | 157 } |
157 | 158 |
158 void ClickOnView(ViewID vid) { | 159 void ClickOnView(ViewID vid) { |
159 ui_test_utils::ClickOnView(browser(), vid); | 160 ui_test_utils::ClickOnView(browser(), vid); |
160 } | 161 } |
161 | 162 |
162 bool WaitForFocusChange(ViewID vid) { | 163 bool WaitForFocusChange(ViewID vid) { |
163 const base::Time timeout = base::Time::Now() + | 164 const base::Time timeout = base::Time::Now() + |
164 base::TimeDelta::FromMilliseconds(kFocusChangeTimeoutMs); | 165 base::TimeDelta::FromMilliseconds(kFocusChangeTimeoutMs); |
165 MessageLoop::current()->PostDelayedTask( | 166 base::MessageLoop::current()->PostDelayedTask( |
166 FROM_HERE, | 167 FROM_HERE, |
167 base::Bind(&CheckFocus, browser(), vid, timeout), | 168 base::Bind(&CheckFocus, browser(), vid, timeout), |
168 base::TimeDelta::FromMilliseconds(100)); | 169 base::TimeDelta::FromMilliseconds(100)); |
169 content::RunMessageLoop(); | 170 content::RunMessageLoop(); |
170 return IsViewFocused(vid); | 171 return IsViewFocused(vid); |
171 } | 172 } |
172 }; | 173 }; |
173 | 174 |
174 class TestInterstitialPage : public content::InterstitialPageDelegate { | 175 class TestInterstitialPage : public content::InterstitialPageDelegate { |
175 public: | 176 public: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 #if defined(OS_MACOSX) | 212 #if defined(OS_MACOSX) |
212 #define MAYBE_ClickingMovesFocus DISABLED_ClickingMovesFocus | 213 #define MAYBE_ClickingMovesFocus DISABLED_ClickingMovesFocus |
213 #else | 214 #else |
214 #define MAYBE_ClickingMovesFocus ClickingMovesFocus | 215 #define MAYBE_ClickingMovesFocus ClickingMovesFocus |
215 #endif | 216 #endif |
216 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_ClickingMovesFocus) { | 217 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_ClickingMovesFocus) { |
217 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 218 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
218 #if defined(OS_POSIX) | 219 #if defined(OS_POSIX) |
219 // It seems we have to wait a little bit for the widgets to spin up before | 220 // It seems we have to wait a little bit for the widgets to spin up before |
220 // we can start clicking on them. | 221 // we can start clicking on them. |
221 MessageLoop::current()->PostDelayedTask( | 222 base::MessageLoop::current()->PostDelayedTask( |
222 FROM_HERE, | 223 FROM_HERE, |
223 MessageLoop::QuitClosure(), | 224 base::MessageLoop::QuitClosure(), |
224 base::TimeDelta::FromMilliseconds(kActionDelayMs)); | 225 base::TimeDelta::FromMilliseconds(kActionDelayMs)); |
225 content::RunMessageLoop(); | 226 content::RunMessageLoop(); |
226 #endif // defined(OS_POSIX) | 227 #endif // defined(OS_POSIX) |
227 | 228 |
228 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 229 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
229 | 230 |
230 ClickOnView(VIEW_ID_TAB_CONTAINER); | 231 ClickOnView(VIEW_ID_TAB_CONTAINER); |
231 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 232 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
232 | 233 |
233 ClickOnView(VIEW_ID_OMNIBOX); | 234 ClickOnView(VIEW_ID_OMNIBOX); |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 ui_test_utils::NavigateToURL(browser(), url); | 619 ui_test_utils::NavigateToURL(browser(), url); |
619 | 620 |
620 // Focus should be on the page. | 621 // Focus should be on the page. |
621 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 622 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
622 | 623 |
623 // Let's show an interstitial. | 624 // Let's show an interstitial. |
624 TestInterstitialPage* interstitial_page = new TestInterstitialPage( | 625 TestInterstitialPage* interstitial_page = new TestInterstitialPage( |
625 browser()->tab_strip_model()->GetActiveWebContents(), | 626 browser()->tab_strip_model()->GetActiveWebContents(), |
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 base::MessageLoop::current()->PostDelayedTask( |
629 MessageLoop::QuitClosure(), | 630 FROM_HERE, |
630 base::TimeDelta::FromSeconds(1)); | 631 base::MessageLoop::QuitClosure(), |
| 632 base::TimeDelta::FromSeconds(1)); |
631 content::RunMessageLoop(); | 633 content::RunMessageLoop(); |
632 | 634 |
633 chrome::FocusLocationBar(browser()); | 635 chrome::FocusLocationBar(browser()); |
634 | 636 |
635 const char* kExpElementIDs[] = { | 637 const char* kExpElementIDs[] = { |
636 "", // Initially no element in the page should be focused | 638 "", // Initially no element in the page should be focused |
637 // (the location bar is focused). | 639 // (the location bar is focused). |
638 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", | 640 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", |
639 "gmapLink" | 641 "gmapLink" |
640 }; | 642 }; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 // Page should have focus. | 741 // Page should have focus. |
740 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 742 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
741 EXPECT_TRUE(browser()->tab_strip_model()->GetActiveWebContents()-> | 743 EXPECT_TRUE(browser()->tab_strip_model()->GetActiveWebContents()-> |
742 GetRenderViewHost()->GetView()->HasFocus()); | 744 GetRenderViewHost()->GetView()->HasFocus()); |
743 | 745 |
744 // Let's show an interstitial. | 746 // Let's show an interstitial. |
745 TestInterstitialPage* interstitial_page = new TestInterstitialPage( | 747 TestInterstitialPage* interstitial_page = new TestInterstitialPage( |
746 browser()->tab_strip_model()->GetActiveWebContents(), | 748 browser()->tab_strip_model()->GetActiveWebContents(), |
747 true, GURL("http://interstitial.com")); | 749 true, GURL("http://interstitial.com")); |
748 // Give some time for the interstitial to show. | 750 // Give some time for the interstitial to show. |
749 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 751 base::MessageLoop::current()->PostDelayedTask( |
750 MessageLoop::QuitClosure(), | 752 FROM_HERE, |
751 base::TimeDelta::FromSeconds(1)); | 753 base::MessageLoop::QuitClosure(), |
| 754 base::TimeDelta::FromSeconds(1)); |
752 content::RunMessageLoop(); | 755 content::RunMessageLoop(); |
753 | 756 |
754 // The interstitial should have focus now. | 757 // The interstitial should have focus now. |
755 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 758 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
756 EXPECT_TRUE(interstitial_page->HasFocus()); | 759 EXPECT_TRUE(interstitial_page->HasFocus()); |
757 | 760 |
758 // Hide the interstitial. | 761 // Hide the interstitial. |
759 interstitial_page->DontProceed(); | 762 interstitial_page->DontProceed(); |
760 | 763 |
761 // Focus should be back on the original page. | 764 // Focus should be back on the original page. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 988 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
986 content::NotificationService::AllSources()); | 989 content::NotificationService::AllSources()); |
987 chrome::GoForward(browser(), CURRENT_TAB); | 990 chrome::GoForward(browser(), CURRENT_TAB); |
988 forward_nav_observer.Wait(); | 991 forward_nav_observer.Wait(); |
989 } | 992 } |
990 | 993 |
991 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 994 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
992 } | 995 } |
993 | 996 |
994 } // namespace | 997 } // namespace |
OLD | NEW |