Index: chrome/browser/ui/browser_focus_uitest.cc |
diff --git a/chrome/browser/ui/browser_focus_uitest.cc b/chrome/browser/ui/browser_focus_uitest.cc |
index c6a81d3424c615c61a5e4deb3b95120295dcf857..d554c13916a3872210f1f40bcd7d83523c31986b 100644 |
--- a/chrome/browser/ui/browser_focus_uitest.cc |
+++ b/chrome/browser/ui/browser_focus_uitest.cc |
@@ -45,6 +45,7 @@ |
#include "content/public/browser/render_widget_host_view.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/test/browser_test_utils.h" |
+#include "content/public/test/test_navigation_observer.h" |
#include "net/test/embedded_test_server/embedded_test_server.h" |
#if defined(OS_WIN) |
@@ -738,4 +739,34 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, AboutBlankNavigationLocationTest) { |
EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
} |
+// Regression test for https://crbug.com/677716. This ensures that the omnibox |
+// does not get focused if another tab in the same window navigates to the New |
+// Tab Page, since that can scroll the origin of the selected tab out of view. |
+IN_PROC_BROWSER_TEST_F(BrowserFocusTest, NoFocusForBackgroundNTP) { |
+ // Start at the NTP and navigate to a test page. We will later go back to the |
+ // NTP, which gives the omnibox focus in some cases. |
+ chrome::NewTab(browser()); |
+ 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
|
+ ui_test_utils::NavigateToURL(browser(), url1); |
+ |
+ TabStripModel* tab_strip = browser()->tab_strip_model(); |
+ WebContents* opener_web_contents = tab_strip->GetActiveWebContents(); |
+ |
+ // Open a second tab from the test page. |
+ const GURL url2(embedded_test_server()->GetURL("/title2.html")); |
+ const std::string open_script("window.open('" + url2.spec() + "');"); |
+ content::WebContentsAddedObserver open_observer; |
+ ASSERT_TRUE(content::ExecuteScript(opener_web_contents, open_script)); |
+ WebContents* new_web_contents = open_observer.GetWebContents(); |
+ |
+ // Tell the first (non-selected) tab to go back. This should not give the |
+ // omnibox focus, since the navigation occurred in a different tab. Otherwise |
+ // the focus may scroll the origin out of view, making a spoof possible. |
+ const std::string go_back_script("window.opener.history.back();"); |
+ content::TestNavigationObserver back_observer(opener_web_contents); |
+ ASSERT_TRUE(content::ExecuteScript(new_web_contents, go_back_script)); |
+ back_observer.Wait(); |
+ EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
+} |
+ |
} // namespace |