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" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/tabs/tab_strip_model.h" | 15 #include "chrome/browser/tabs/tab_strip_model.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
19 #include "chrome/browser/ui/view_ids.h" | 19 #include "chrome/browser/ui/view_ids.h" |
20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
23 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
24 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
25 #include "content/browser/renderer_host/render_view_host.h" | 25 #include "content/browser/renderer_host/render_view_host.h" |
26 #include "content/browser/renderer_host/render_widget_host_view.h" | 26 #include "content/browser/renderer_host/render_widget_host_view.h" |
27 #include "content/browser/tab_contents/interstitial_page.h" | 27 #include "content/browser/tab_contents/interstitial_page.h" |
| 28 #include "content/public/browser/interstitial_page_delegate.h" |
28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
30 #include "content/public/browser/web_contents_view.h" | 31 #include "content/public/browser/web_contents_view.h" |
31 #include "net/test/test_server.h" | 32 #include "net/test/test_server.h" |
32 | 33 |
33 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN) | 34 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN) |
34 #include "ui/views/focus/focus_manager.h" | 35 #include "ui/views/focus/focus_manager.h" |
35 #include "ui/views/view.h" | 36 #include "ui/views/view.h" |
36 #endif | 37 #endif |
37 | 38 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 FROM_HERE, | 176 FROM_HERE, |
176 base::Bind(&CheckFocus, browser(), vid, timeout), | 177 base::Bind(&CheckFocus, browser(), vid, timeout), |
177 100); | 178 100); |
178 ui_test_utils::RunMessageLoop(); | 179 ui_test_utils::RunMessageLoop(); |
179 return IsViewFocused(vid); | 180 return IsViewFocused(vid); |
180 } | 181 } |
181 | 182 |
182 ViewID location_bar_focus_view_id_; | 183 ViewID location_bar_focus_view_id_; |
183 }; | 184 }; |
184 | 185 |
185 class TestInterstitialPage : public InterstitialPage { | 186 class TestInterstitialPage : public content::InterstitialPageDelegate { |
186 public: | 187 public: |
187 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) | 188 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { |
188 : InterstitialPage(tab, new_navigation, url) { | |
189 FilePath file_path; | 189 FilePath file_path; |
190 bool r = PathService::Get(chrome::DIR_TEST_DATA, &file_path); | 190 bool r = PathService::Get(chrome::DIR_TEST_DATA, &file_path); |
191 EXPECT_TRUE(r); | 191 EXPECT_TRUE(r); |
192 file_path = file_path.AppendASCII("focus"); | 192 file_path = file_path.AppendASCII("focus"); |
193 file_path = file_path.AppendASCII(kTypicalPageName); | 193 file_path = file_path.AppendASCII(kTypicalPageName); |
194 r = file_util::ReadFileToString(file_path, &html_contents_); | 194 r = file_util::ReadFileToString(file_path, &html_contents_); |
195 EXPECT_TRUE(r); | 195 EXPECT_TRUE(r); |
| 196 interstitial_page_ = InterstitialPage::Create( |
| 197 tab, new_navigation, url , this); |
| 198 interstitial_page_->Show(); |
196 } | 199 } |
197 | 200 |
198 virtual std::string GetHTMLContents() { | 201 virtual std::string GetHTMLContents() { |
199 return html_contents_; | 202 return html_contents_; |
200 } | 203 } |
201 | 204 |
202 // Exposing render_view_host() and tab() to be public; they are declared as | 205 RenderViewHost* render_view_host() { |
203 // protected in the superclass. | 206 return interstitial_page_->render_view_host(); |
204 virtual RenderViewHost* render_view_host() { | |
205 return InterstitialPage::render_view_host(); | |
206 } | 207 } |
207 | 208 |
208 virtual WebContents* tab() { | 209 void DontProceed() { |
209 return InterstitialPage::tab(); | 210 interstitial_page_->DontProceed(); |
210 } | 211 } |
211 | 212 |
212 bool HasFocus() { | 213 bool HasFocus() { |
213 return render_view_host()->view()->HasFocus(); | 214 return render_view_host()->view()->HasFocus(); |
214 } | 215 } |
215 | 216 |
216 private: | 217 private: |
217 std::string html_contents_; | 218 std::string html_contents_; |
| 219 InterstitialPage* interstitial_page_; // Owns us. |
218 }; | 220 }; |
219 | 221 |
220 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { | 222 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { |
221 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 223 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
222 #if defined(OS_POSIX) | 224 #if defined(OS_POSIX) |
223 // It seems we have to wait a little bit for the widgets to spin up before | 225 // It seems we have to wait a little bit for the widgets to spin up before |
224 // we can start clicking on them. | 226 // we can start clicking on them. |
225 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 227 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
226 MessageLoop::QuitClosure(), | 228 MessageLoop::QuitClosure(), |
227 kActionDelayMs); | 229 kActionDelayMs); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 GURL url = test_server()->GetURL(kSimplePage); | 616 GURL url = test_server()->GetURL(kSimplePage); |
615 ui_test_utils::NavigateToURL(browser(), url); | 617 ui_test_utils::NavigateToURL(browser(), url); |
616 | 618 |
617 // Focus should be on the page. | 619 // Focus should be on the page. |
618 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 620 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
619 | 621 |
620 // Let's show an interstitial. | 622 // Let's show an interstitial. |
621 TestInterstitialPage* interstitial_page = | 623 TestInterstitialPage* interstitial_page = |
622 new TestInterstitialPage(browser()->GetSelectedWebContents(), | 624 new TestInterstitialPage(browser()->GetSelectedWebContents(), |
623 true, GURL("http://interstitial.com")); | 625 true, GURL("http://interstitial.com")); |
624 interstitial_page->Show(); | |
625 // Give some time for the interstitial to show. | 626 // Give some time for the interstitial to show. |
626 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 627 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
627 MessageLoop::QuitClosure(), | 628 MessageLoop::QuitClosure(), |
628 1000); | 629 1000); |
629 ui_test_utils::RunMessageLoop(); | 630 ui_test_utils::RunMessageLoop(); |
630 | 631 |
631 browser()->FocusLocationBar(); | 632 browser()->FocusLocationBar(); |
632 | 633 |
633 const char* kExpElementIDs[] = { | 634 const char* kExpElementIDs[] = { |
634 "", // Initially no element in the page should be focused | 635 "", // Initially no element in the page should be focused |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 | 741 |
741 // Page should have focus. | 742 // Page should have focus. |
742 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 743 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
743 EXPECT_TRUE(browser()->GetSelectedWebContents()->GetRenderViewHost()->view()-> | 744 EXPECT_TRUE(browser()->GetSelectedWebContents()->GetRenderViewHost()->view()-> |
744 HasFocus()); | 745 HasFocus()); |
745 | 746 |
746 // Let's show an interstitial. | 747 // Let's show an interstitial. |
747 TestInterstitialPage* interstitial_page = | 748 TestInterstitialPage* interstitial_page = |
748 new TestInterstitialPage(browser()->GetSelectedWebContents(), | 749 new TestInterstitialPage(browser()->GetSelectedWebContents(), |
749 true, GURL("http://interstitial.com")); | 750 true, GURL("http://interstitial.com")); |
750 interstitial_page->Show(); | |
751 // Give some time for the interstitial to show. | 751 // Give some time for the interstitial to show. |
752 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 752 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
753 MessageLoop::QuitClosure(), | 753 MessageLoop::QuitClosure(), |
754 1000); | 754 1000); |
755 ui_test_utils::RunMessageLoop(); | 755 ui_test_utils::RunMessageLoop(); |
756 | 756 |
757 // The interstitial should have focus now. | 757 // The interstitial should have focus now. |
758 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 758 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
759 EXPECT_TRUE(interstitial_page->HasFocus()); | 759 EXPECT_TRUE(interstitial_page->HasFocus()); |
760 | 760 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 browser()->Reload(CURRENT_TAB); | 918 browser()->Reload(CURRENT_TAB); |
919 observer.Wait(); | 919 observer.Wait(); |
920 } | 920 } |
921 | 921 |
922 // Focus should now be on the tab contents. | 922 // Focus should now be on the tab contents. |
923 browser()->ShowDownloadsTab(); | 923 browser()->ShowDownloadsTab(); |
924 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 924 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
925 } | 925 } |
926 | 926 |
927 } // namespace | 927 } // namespace |
OLD | NEW |