Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2559)

Unified Diff: chrome/browser/ui/browser_focus_uitest.cc

Issue 2624373002: Don't focus the location bar for NTP navigations in non-selected tabs. (Closed)
Patch Set: Initial patch Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« chrome/browser/ui/browser.cc ('K') | « chrome/browser/ui/browser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« chrome/browser/ui/browser.cc ('K') | « chrome/browser/ui/browser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698