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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "components/omnibox/browser/omnibox_view.h" | 38 #include "components/omnibox/browser/omnibox_view.h" |
39 #include "content/public/browser/interstitial_page.h" | 39 #include "content/public/browser/interstitial_page.h" |
40 #include "content/public/browser/interstitial_page_delegate.h" | 40 #include "content/public/browser/interstitial_page_delegate.h" |
41 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
42 #include "content/public/browser/render_frame_host.h" | 42 #include "content/public/browser/render_frame_host.h" |
43 #include "content/public/browser/render_view_host.h" | 43 #include "content/public/browser/render_view_host.h" |
44 #include "content/public/browser/render_widget_host.h" | 44 #include "content/public/browser/render_widget_host.h" |
45 #include "content/public/browser/render_widget_host_view.h" | 45 #include "content/public/browser/render_widget_host_view.h" |
46 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
47 #include "content/public/test/browser_test_utils.h" | 47 #include "content/public/test/browser_test_utils.h" |
| 48 #include "content/public/test/test_navigation_observer.h" |
48 #include "net/test/embedded_test_server/embedded_test_server.h" | 49 #include "net/test/embedded_test_server/embedded_test_server.h" |
49 | 50 |
50 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
51 #include "base/win/windows_version.h" | 52 #include "base/win/windows_version.h" |
52 #endif | 53 #endif |
53 | 54 |
54 using content::RenderViewHost; | 55 using content::RenderViewHost; |
55 using content::WebContents; | 56 using content::WebContents; |
56 | 57 |
57 namespace { | 58 namespace { |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 713 |
713 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 714 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
714 } | 715 } |
715 | 716 |
716 // Ensure that crbug.com/567445 does not regress. This test checks that the | 717 // Ensure that crbug.com/567445 does not regress. This test checks that the |
717 // Omnibox does not get focused when loading about:blank in a case where it's | 718 // Omnibox does not get focused when loading about:blank in a case where it's |
718 // not the startup URL, e.g. when a page opens a popup to about:blank, with a | 719 // not the startup URL, e.g. when a page opens a popup to about:blank, with a |
719 // null opener, and then navigates it. This is a potential security issue; see | 720 // null opener, and then navigates it. This is a potential security issue; see |
720 // comments in |WebContentsImpl::FocusLocationBarByDefault|. | 721 // comments in |WebContentsImpl::FocusLocationBarByDefault|. |
721 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, AboutBlankNavigationLocationTest) { | 722 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, AboutBlankNavigationLocationTest) { |
722 const GURL url1(embedded_test_server()->GetURL("/title1.html")); | 723 const GURL url1 = embedded_test_server()->GetURL("/title1.html"); |
723 ui_test_utils::NavigateToURL(browser(), url1); | 724 ui_test_utils::NavigateToURL(browser(), url1); |
724 | 725 |
725 TabStripModel* tab_strip = browser()->tab_strip_model(); | 726 TabStripModel* tab_strip = browser()->tab_strip_model(); |
726 WebContents* web_contents = tab_strip->GetActiveWebContents(); | 727 WebContents* web_contents = tab_strip->GetActiveWebContents(); |
727 | 728 |
728 const GURL url2(embedded_test_server()->GetURL("/title2.html")); | 729 const GURL url2 = embedded_test_server()->GetURL("/title2.html"); |
729 const std::string spoof("var w = window.open('about:blank'); w.opener = null;" | 730 const std::string spoof = |
730 "w.document.location = '" + url2.spec() + "';"); | 731 "var w = window.open('about:blank'); w.opener = null;" |
| 732 "w.document.location = '" + url2.spec() + "';"; |
731 | 733 |
732 ASSERT_TRUE(content::ExecuteScript(web_contents, spoof)); | 734 ASSERT_TRUE(content::ExecuteScript(web_contents, spoof)); |
733 EXPECT_EQ(url1, web_contents->GetVisibleURL()); | 735 EXPECT_EQ(url1, web_contents->GetVisibleURL()); |
734 // After running the spoof code, |GetActiveWebContents| returns the new tab, | 736 // After running the spoof code, |GetActiveWebContents| returns the new tab, |
735 // not the same as |web_contents|. | 737 // not the same as |web_contents|. |
736 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( | 738 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( |
737 browser()->tab_strip_model()->GetActiveWebContents())); | 739 browser()->tab_strip_model()->GetActiveWebContents())); |
738 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 740 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
739 } | 741 } |
740 | 742 |
| 743 // Regression test for https://crbug.com/677716. This ensures that the omnibox |
| 744 // does not get focused if another tab in the same window navigates to the New |
| 745 // Tab Page, since that can scroll the origin of the selected tab out of view. |
| 746 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, NoFocusForBackgroundNTP) { |
| 747 // Start at the NTP and navigate to a test page. We will later go back to the |
| 748 // NTP, which gives the omnibox focus in some cases. |
| 749 chrome::NewTab(browser()); |
| 750 ui_test_utils::NavigateToURL(browser(), |
| 751 embedded_test_server()->GetURL("/title1.html")); |
| 752 |
| 753 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 754 WebContents* opener_web_contents = tab_strip->GetActiveWebContents(); |
| 755 |
| 756 // Open a second tab from the test page. |
| 757 const GURL new_url = embedded_test_server()->GetURL("/title2.html"); |
| 758 const std::string open_script = "window.open('" + new_url.spec() + "');"; |
| 759 content::WebContentsAddedObserver open_observer; |
| 760 ASSERT_TRUE(content::ExecuteScript(opener_web_contents, open_script)); |
| 761 WebContents* new_web_contents = open_observer.GetWebContents(); |
| 762 |
| 763 // Tell the first (non-selected) tab to go back. This should not give the |
| 764 // omnibox focus, since the navigation occurred in a different tab. Otherwise |
| 765 // the focus may scroll the origin out of view, making a spoof possible. |
| 766 const std::string go_back_script = "window.opener.history.back();"; |
| 767 content::TestNavigationObserver back_observer(opener_web_contents); |
| 768 ASSERT_TRUE(content::ExecuteScript(new_web_contents, go_back_script)); |
| 769 back_observer.Wait(); |
| 770 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 771 } |
| 772 |
741 } // namespace | 773 } // namespace |
OLD | NEW |