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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 | 732 |
732 ASSERT_TRUE(content::ExecuteScript(web_contents, spoof)); | 733 ASSERT_TRUE(content::ExecuteScript(web_contents, spoof)); |
733 EXPECT_EQ(url1, web_contents->GetVisibleURL()); | 734 EXPECT_EQ(url1, web_contents->GetVisibleURL()); |
734 // After running the spoof code, |GetActiveWebContents| returns the new tab, | 735 // After running the spoof code, |GetActiveWebContents| returns the new tab, |
735 // not the same as |web_contents|. | 736 // not the same as |web_contents|. |
736 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( | 737 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( |
737 browser()->tab_strip_model()->GetActiveWebContents())); | 738 browser()->tab_strip_model()->GetActiveWebContents())); |
738 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 739 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
739 } | 740 } |
740 | 741 |
742 // Regression test for https://crbug.com/677716. This ensures that the omnibox | |
743 // does not get focused if another tab in the same window navigates to the New | |
744 // Tab Page, since that can scroll the origin of the selected tab out of view. | |
745 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, NoFocusForBackgroundNTP) { | |
746 // Start at the NTP and navigate to a test page. We will later go back to the | |
747 // NTP, which gives the omnibox focus in some cases. | |
748 chrome::NewTab(browser()); | |
749 const GURL url1(embedded_test_server()->GetURL("/title1.html")); | |
Peter Kasting
2017/01/12 18:24:04
Nit: Prefer = to () for initializing things like G
Charlie Reis
2017/01/12 19:26:54
Thanks, done. I updated the source of the pattern
| |
750 ui_test_utils::NavigateToURL(browser(), url1); | |
751 | |
752 TabStripModel* tab_strip = browser()->tab_strip_model(); | |
753 WebContents* opener_web_contents = tab_strip->GetActiveWebContents(); | |
754 | |
755 // Open a second tab from the test page. | |
756 const GURL url2(embedded_test_server()->GetURL("/title2.html")); | |
757 const std::string open_script("window.open('" + url2.spec() + "');"); | |
758 content::WebContentsAddedObserver open_observer; | |
759 ASSERT_TRUE(content::ExecuteScript(opener_web_contents, open_script)); | |
760 WebContents* new_web_contents = open_observer.GetWebContents(); | |
761 | |
762 // Tell the first (non-selected) tab to go back. This should not give the | |
763 // omnibox focus, since the navigation occurred in a different tab. Otherwise | |
764 // the focus may scroll the origin out of view, making a spoof possible. | |
765 const std::string go_back_script("window.opener.history.back();"); | |
766 content::TestNavigationObserver back_observer(opener_web_contents); | |
767 ASSERT_TRUE(content::ExecuteScript(new_web_contents, go_back_script)); | |
768 back_observer.Wait(); | |
769 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | |
770 } | |
771 | |
741 } // namespace | 772 } // namespace |
OLD | NEW |