blob: 869f43d047f072213f23b9753afb5369278761b6 [file] [log] [blame]
[email protected]a9c060ca2012-01-05 20:43:411// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]a9c060ca2012-01-05 20:43:415#include "base/bind.h"
[email protected]3985ba82010-07-29 21:44:126#include "base/file_util.h"
[email protected]f07d7bf2010-04-06 08:02:427#include "base/format_macros.h"
[email protected]3cc55ad2013-07-17 22:17:418#include "base/message_loop/message_loop.h"
[email protected]3985ba82010-07-29 21:44:129#include "base/path_service.h"
[email protected]3ea1b182013-02-08 22:38:4110#include "base/strings/string_number_conversions.h"
[email protected]11521182013-06-11 04:06:3611#include "base/strings/stringprintf.h"
[email protected]5846d582013-06-08 16:02:1212#include "base/strings/utf_string_conversions.h"
[email protected]dcc8fbc2013-07-12 00:54:0913#include "chrome/browser/chrome_notification_types.h"
[email protected]7b5dc002010-11-16 23:08:1014#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1015#include "chrome/browser/ui/browser_commands.h"
[email protected]52877dbc62012-06-29 22:22:0316#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]00070c732011-04-09 15:31:3317#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:1218#include "chrome/browser/ui/chrome_pages.h"
[email protected]895a84722012-11-29 18:45:4419#include "chrome/browser/ui/omnibox/location_bar.h"
20#include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
21#include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
22#include "chrome/browser/ui/omnibox/omnibox_view.h"
[email protected]b56e2e32012-05-11 21:18:0423#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]6a3ec2312010-12-02 19:30:1924#include "chrome/browser/ui/view_ids.h"
[email protected]9e0c83a2009-05-06 19:44:3725#include "chrome/common/chrome_paths.h"
[email protected]cecc93a2010-10-05 15:58:5526#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3227#include "chrome/test/base/in_process_browser_test.h"
[email protected]3ea1b182013-02-08 22:38:4128#include "chrome/test/base/interactive_test_utils.h"
[email protected]477ae052011-11-18 23:53:5729#include "chrome/test/base/ui_test_utils.h"
[email protected]cadaec52012-02-08 21:53:1330#include "content/public/browser/interstitial_page.h"
[email protected]85f0a572012-02-07 22:20:1331#include "content/public/browser/interstitial_page_delegate.h"
[email protected]477ae052011-11-18 23:53:5732#include "content/public/browser/notification_service.h"
[email protected]9c1662b2012-03-06 15:44:3333#include "content/public/browser/render_view_host.h"
[email protected]5626b0892012-02-20 14:46:5834#include "content/public/browser/render_widget_host_view.h"
[email protected]6acde6352012-01-04 16:52:2035#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1036#include "content/public/browser/web_contents_view.h"
[email protected]7d478cb2012-07-24 17:19:4237#include "content/public/test/browser_test_utils.h"
[email protected]c1dffe82013-06-26 20:59:0538#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]853300a82010-07-27 21:17:5739
[email protected]a711df102010-12-14 09:47:0340#if defined(OS_WIN)
[email protected]93270d002011-01-19 22:32:5941#include <windows.h>
[email protected]3ea1b182013-02-08 22:38:4142#include <Psapi.h>
[email protected]11521182013-06-11 04:06:3643#include "base/strings/string_util.h"
[email protected]a711df102010-12-14 09:47:0344#endif
45
[email protected]cadaec52012-02-08 21:53:1346using content::InterstitialPage;
[email protected]c5eed492012-01-04 17:07:5047using content::NavigationController;
[email protected]eaabba22012-03-07 15:02:1148using content::RenderViewHost;
[email protected]4b19ea52012-01-02 20:15:2549using content::WebContents;
50
[email protected]3a3cf4d2011-12-09 00:39:3551#if defined(OS_MACOSX)
52// TODO(suzhe): http://crbug.com/60973
[email protected]a5eb2d672010-10-22 07:24:4853#define MAYBE_FocusTraversal DISABLED_FocusTraversal
54#define MAYBE_FocusTraversalOnInterstitial DISABLED_FocusTraversalOnInterstitial
[email protected]5b6d0432013-01-24 20:30:1655#elif defined(OS_WIN) || defined(OS_CHROMEOS)
56// http://crbug.com/109770 and http://crbug.com/62544
[email protected]2f2bf1172012-01-10 22:17:1857#define MAYBE_FocusTraversal FocusTraversal
[email protected]871153922012-01-10 20:13:4858#define MAYBE_FocusTraversalOnInterstitial DISABLED_FocusTraversalOnInterstitial
[email protected]3a3cf4d2011-12-09 00:39:3559#else
60#define MAYBE_FocusTraversal FocusTraversal
61#define MAYBE_FocusTraversalOnInterstitial FocusTraversalOnInterstitial
62#endif
63
64#if defined(OS_LINUX) || defined(OS_MACOSX)
65// TODO(jcampan): http://crbug.com/23683 for linux.
66// TODO(suzhe): http://crbug.com/49737 for mac.
[email protected]e00ccc92012-11-01 17:32:3067#define MAYBE_TabsRememberFocusFindInPage DISABLED_TabsRememberFocusFindInPage
[email protected]853300a82010-07-27 21:17:5768#elif defined(OS_WIN)
[email protected]c92928672010-11-09 18:31:0769// Flaky, http://crbug.com/62537.
[email protected]4d2451652012-02-14 23:54:2670#define MAYBE_TabsRememberFocusFindInPage DISABLED_TabsRememberFocusFindInPage
[email protected]fc2e0872009-08-21 22:14:4171#endif
72
initial.commit09911bf2008-07-26 23:55:2973namespace {
74
[email protected]8bcdec92009-02-25 16:15:1875// The delay waited in some cases where we don't have a notifications for an
76// action we take.
initial.commit09911bf2008-07-26 23:55:2977const int kActionDelayMs = 500;
78
[email protected]a9c060ca2012-01-05 20:43:4179// Maxiumum time to wait until the focus is moved to expected view.
80const int kFocusChangeTimeoutMs = 500;
81
[email protected]c1dffe82013-06-26 20:59:0582const char kSimplePage[] = "/focus/page_with_focus.html";
83const char kStealFocusPage[] = "/focus/page_steals_focus.html";
84const char kTypicalPage[] = "/focus/typical_page.html";
[email protected]b65de8b92009-09-14 19:36:3185const char kTypicalPageName[] = "typical_page.html";
initial.commit09911bf2008-07-26 23:55:2986
[email protected]a711df102010-12-14 09:47:0387// Test to make sure Chrome is in the foreground as we start testing. This is
88// required for tests that synthesize input to the Chrome window.
89bool ChromeInForeground() {
90#if defined(OS_WIN)
91 HWND window = ::GetForegroundWindow();
92 std::wstring caption;
93 std::wstring filename;
94 int len = ::GetWindowTextLength(window) + 1;
[email protected]fdce4782011-11-29 20:06:1895 if (len > 1)
96 ::GetWindowText(window, WriteInto(&caption, len), len);
[email protected]a711df102010-12-14 09:47:0397 bool chrome_window_in_foreground =
98 EndsWith(caption, L" - Google Chrome", true) ||
99 EndsWith(caption, L" - Chromium", true);
100 if (!chrome_window_in_foreground) {
101 DWORD process_id;
102 int thread_id = ::GetWindowThreadProcessId(window, &process_id);
103
104 base::ProcessHandle process;
105 if (base::OpenProcessHandleWithAccess(process_id,
106 PROCESS_QUERY_LIMITED_INFORMATION,
107 &process)) {
[email protected]fdce4782011-11-29 20:06:18108 if (!GetProcessImageFileName(process, WriteInto(&filename, MAX_PATH),
109 MAX_PATH)) {
[email protected]a711df102010-12-14 09:47:03110 int error = GetLastError();
111 filename = std::wstring(L"Unable to read filename for process id '" +
112 base::IntToString16(process_id) +
113 L"' (error ") +
114 base::IntToString16(error) + L")";
115 }
116 base::CloseProcessHandle(process);
117 }
118 }
119 EXPECT_TRUE(chrome_window_in_foreground)
120 << "Chrome must be in the foreground when running interactive tests\n"
121 << "Process in foreground: " << filename.c_str() << "\n"
122 << "Window: " << window << "\n"
123 << "Caption: " << caption.c_str();
124 return chrome_window_in_foreground;
125#else
126 // Windows only at the moment.
127 return true;
128#endif
129}
130
[email protected]a9c060ca2012-01-05 20:43:41131// Wait the focus change in message loop.
132void CheckFocus(Browser* browser, ViewID id, const base::Time& timeout) {
133 if (ui_test_utils::IsViewFocused(browser, id) ||
134 base::Time::Now() > timeout) {
[email protected]3264d162013-05-08 22:02:11135 base::MessageLoop::current()->PostTask(FROM_HERE,
136 base::MessageLoop::QuitClosure());
[email protected]a9c060ca2012-01-05 20:43:41137 } else {
[email protected]3264d162013-05-08 22:02:11138 base::MessageLoop::current()->PostDelayedTask(
[email protected]a9c060ca2012-01-05 20:43:41139 FROM_HERE,
140 base::Bind(&CheckFocus, browser, id, timeout),
[email protected]7e560102012-03-08 20:58:42141 base::TimeDelta::FromMilliseconds(10));
[email protected]a9c060ca2012-01-05 20:43:41142 }
143};
144
[email protected]8bcdec92009-02-25 16:15:18145class BrowserFocusTest : public InProcessBrowserTest {
initial.commit09911bf2008-07-26 23:55:29146 public:
[email protected]21abcc742009-10-23 02:52:06147 bool IsViewFocused(ViewID vid) {
148 return ui_test_utils::IsViewFocused(browser(), vid);
[email protected]b9821882009-08-17 22:25:17149 }
150
[email protected]fc2e0872009-08-21 22:14:41151 void ClickOnView(ViewID vid) {
[email protected]21abcc742009-10-23 02:52:06152 ui_test_utils::ClickOnView(browser(), vid);
[email protected]fc2e0872009-08-21 22:14:41153 }
[email protected]0b8fa8b2011-12-07 00:54:52154
[email protected]a9c060ca2012-01-05 20:43:41155 bool WaitForFocusChange(ViewID vid) {
156 const base::Time timeout = base::Time::Now() +
157 base::TimeDelta::FromMilliseconds(kFocusChangeTimeoutMs);
[email protected]3264d162013-05-08 22:02:11158 base::MessageLoop::current()->PostDelayedTask(
[email protected]a9c060ca2012-01-05 20:43:41159 FROM_HERE,
160 base::Bind(&CheckFocus, browser(), vid, timeout),
[email protected]7e560102012-03-08 20:58:42161 base::TimeDelta::FromMilliseconds(100));
[email protected]729eb632012-07-26 04:45:26162 content::RunMessageLoop();
[email protected]a9c060ca2012-01-05 20:43:41163 return IsViewFocused(vid);
164 }
initial.commit09911bf2008-07-26 23:55:29165};
166
[email protected]85f0a572012-02-07 22:20:13167class TestInterstitialPage : public content::InterstitialPageDelegate {
[email protected]9e0c83a2009-05-06 19:44:37168 public:
[email protected]85f0a572012-02-07 22:20:13169 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) {
[email protected]650b2d52013-02-10 03:41:45170 base::FilePath file_path;
[email protected]9e0c83a2009-05-06 19:44:37171 bool r = PathService::Get(chrome::DIR_TEST_DATA, &file_path);
172 EXPECT_TRUE(r);
[email protected]b65de8b92009-09-14 19:36:31173 file_path = file_path.AppendASCII("focus");
174 file_path = file_path.AppendASCII(kTypicalPageName);
[email protected]82f84b92013-08-30 18:23:50175 r = base::ReadFileToString(file_path, &html_contents_);
[email protected]9e0c83a2009-05-06 19:44:37176 EXPECT_TRUE(r);
[email protected]85f0a572012-02-07 22:20:13177 interstitial_page_ = InterstitialPage::Create(
178 tab, new_navigation, url , this);
179 interstitial_page_->Show();
[email protected]9e0c83a2009-05-06 19:44:37180 }
181
[email protected]626cc902013-02-06 18:30:53182 virtual std::string GetHTMLContents() OVERRIDE {
[email protected]9e0c83a2009-05-06 19:44:37183 return html_contents_;
184 }
185
[email protected]85f0a572012-02-07 22:20:13186 RenderViewHost* render_view_host() {
[email protected]cadaec52012-02-08 21:53:13187 return interstitial_page_->GetRenderViewHostForTesting();
[email protected]9e0c83a2009-05-06 19:44:37188 }
189
[email protected]85f0a572012-02-07 22:20:13190 void DontProceed() {
191 interstitial_page_->DontProceed();
[email protected]4e85c112011-01-26 22:27:21192 }
193
[email protected]9e0c83a2009-05-06 19:44:37194 bool HasFocus() {
[email protected]9f76c1e2012-03-05 15:15:58195 return render_view_host()->GetView()->HasFocus();
[email protected]9e0c83a2009-05-06 19:44:37196 }
197
198 private:
199 std::string html_contents_;
[email protected]85f0a572012-02-07 22:20:13200 InterstitialPage* interstitial_page_; // Owns us.
[email protected]9e0c83a2009-05-06 19:44:37201};
[email protected]b9821882009-08-17 22:25:17202
[email protected]c39e233d2012-05-18 13:24:12203// Flaky on mac. http://crbug.com/67301.
204#if defined(OS_MACOSX)
[email protected]839e0802012-05-18 14:45:23205#define MAYBE_ClickingMovesFocus DISABLED_ClickingMovesFocus
[email protected]c39e233d2012-05-18 13:24:12206#else
[email protected]839e0802012-05-18 14:45:23207#define MAYBE_ClickingMovesFocus ClickingMovesFocus
[email protected]c39e233d2012-05-18 13:24:12208#endif
209IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_ClickingMovesFocus) {
[email protected]a6e602f2010-09-28 22:28:30210 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]0ff0ff32010-12-21 19:34:42211#if defined(OS_POSIX)
[email protected]fc2e0872009-08-21 22:14:41212 // It seems we have to wait a little bit for the widgets to spin up before
213 // we can start clicking on them.
[email protected]3264d162013-05-08 22:02:11214 base::MessageLoop::current()->PostDelayedTask(
[email protected]7e560102012-03-08 20:58:42215 FROM_HERE,
[email protected]3264d162013-05-08 22:02:11216 base::MessageLoop::QuitClosure(),
[email protected]7e560102012-03-08 20:58:42217 base::TimeDelta::FromMilliseconds(kActionDelayMs));
[email protected]729eb632012-07-26 04:45:26218 content::RunMessageLoop();
[email protected]0ff0ff32010-12-21 19:34:42219#endif // defined(OS_POSIX)
[email protected]fc2e0872009-08-21 22:14:41220
[email protected]5c4e4482013-03-03 00:09:18221 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
[email protected]186f13f2009-08-19 20:34:00222
[email protected]fc2e0872009-08-21 22:14:41223 ClickOnView(VIEW_ID_TAB_CONTAINER);
[email protected]f2159ba2012-04-17 19:13:21224 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]186f13f2009-08-19 20:34:00225
[email protected]5c4e4482013-03-03 00:09:18226 ClickOnView(VIEW_ID_OMNIBOX);
227 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
[email protected]186f13f2009-08-19 20:34:00228}
[email protected]186f13f2009-08-19 20:34:00229
[email protected]320948e02011-01-10 08:21:12230// Flaky, http://crbug.com/69034.
[email protected]4d2451652012-02-14 23:54:26231IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) {
[email protected]a6e602f2010-09-28 22:28:30232 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05233 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
initial.commit09911bf2008-07-26 23:55:29234
235 // First we navigate to our test page.
[email protected]c1dffe82013-06-26 20:59:05236 GURL url = embedded_test_server()->GetURL(kSimplePage);
[email protected]8bcdec92009-02-25 16:15:18237 ui_test_utils::NavigateToURL(browser(), url);
initial.commit09911bf2008-07-26 23:55:29238
[email protected]90556dd2012-06-07 20:26:18239 gfx::NativeWindow window = browser()->window()->GetNativeWindow();
[email protected]186f13f2009-08-19 20:34:00240
initial.commit09911bf2008-07-26 23:55:29241 // The focus should be on the Tab contents.
[email protected]f2159ba2012-04-17 19:13:21242 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
initial.commit09911bf2008-07-26 23:55:29243 // Now hide the window, show it again, the focus should not have changed.
[email protected]853300a82010-07-27 21:17:57244 ui_test_utils::HideNativeWindow(window);
[email protected]7807088c2011-11-09 15:16:29245 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window));
[email protected]f2159ba2012-04-17 19:13:21246 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
initial.commit09911bf2008-07-26 23:55:29247
[email protected]a37d4b02012-06-25 21:56:10248 chrome::FocusLocationBar(browser());
[email protected]5c4e4482013-03-03 00:09:18249 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
initial.commit09911bf2008-07-26 23:55:29250 // Hide the window, show it again, the focus should not have changed.
[email protected]853300a82010-07-27 21:17:57251 ui_test_utils::HideNativeWindow(window);
[email protected]7807088c2011-11-09 15:16:29252 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window));
[email protected]5c4e4482013-03-03 00:09:18253 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
initial.commit09911bf2008-07-26 23:55:29254}
255
256// Tabs remember focus.
[email protected]26153732010-11-09 18:47:39257// Disabled, http://crbug.com/62542.
258IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) {
[email protected]a6e602f2010-09-28 22:28:30259 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05260 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
initial.commit09911bf2008-07-26 23:55:29261
262 // First we navigate to our test page.
[email protected]c1dffe82013-06-26 20:59:05263 GURL url = embedded_test_server()->GetURL(kSimplePage);
[email protected]8bcdec92009-02-25 16:15:18264 ui_test_utils::NavigateToURL(browser(), url);
265
initial.commit09911bf2008-07-26 23:55:29266 // Create several tabs.
[email protected]52877dbc62012-06-29 22:22:03267 for (int i = 0; i < 4; ++i) {
268 chrome::AddSelectedTabWithURL(browser(), url,
269 content::PAGE_TRANSITION_TYPED);
270 }
initial.commit09911bf2008-07-26 23:55:29271
272 // Alternate focus for the tab.
273 const bool kFocusPage[3][5] = {
274 { true, true, true, true, false },
275 { false, false, false, false, false },
276 { false, true, false, true, false }
277 };
278
279 for (int i = 1; i < 3; i++) {
280 for (int j = 0; j < 5; j++) {
[email protected]8bcdec92009-02-25 16:15:18281 // Activate the tab.
[email protected]57892182012-12-03 19:15:39282 browser()->tab_strip_model()->ActivateTabAt(j, true);
initial.commit09911bf2008-07-26 23:55:29283
284 // Activate the location bar or the page.
[email protected]7e383692009-06-12 19:14:54285 if (kFocusPage[i][j]) {
[email protected]57892182012-12-03 19:15:39286 browser()->tab_strip_model()->GetWebContentsAt(j)->GetView()->Focus();
[email protected]7e383692009-06-12 19:14:54287 } else {
[email protected]a37d4b02012-06-25 21:56:10288 chrome::FocusLocationBar(browser());
[email protected]7e383692009-06-12 19:14:54289 }
initial.commit09911bf2008-07-26 23:55:29290 }
291
292 // Now come back to the tab and check the right view is focused.
293 for (int j = 0; j < 5; j++) {
[email protected]8bcdec92009-02-25 16:15:18294 // Activate the tab.
[email protected]57892182012-12-03 19:15:39295 browser()->tab_strip_model()->ActivateTabAt(j, true);
initial.commit09911bf2008-07-26 23:55:29296
[email protected]5c4e4482013-03-03 00:09:18297 ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER : VIEW_ID_OMNIBOX;
[email protected]21abcc742009-10-23 02:52:06298 ASSERT_TRUE(IsViewFocused(vid));
initial.commit09911bf2008-07-26 23:55:29299 }
[email protected]cb7e2542009-12-14 22:02:35300
[email protected]57892182012-12-03 19:15:39301 browser()->tab_strip_model()->ActivateTabAt(0, true);
[email protected]cb7e2542009-12-14 22:02:35302 // Try the above, but with ctrl+tab. Since tab normally changes focus,
303 // this has regressed in the past. Loop through several times to be sure.
304 for (int j = 0; j < 15; j++) {
[email protected]f2159ba2012-04-17 19:13:21305 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER :
[email protected]5c4e4482013-03-03 00:09:18306 VIEW_ID_OMNIBOX;
[email protected]cb7e2542009-12-14 22:02:35307 ASSERT_TRUE(IsViewFocused(vid));
308
[email protected]1d000682010-08-23 16:21:28309 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
[email protected]b6d81262011-01-13 17:36:09310 browser(), ui::VKEY_TAB, true, false, false, false));
[email protected]cb7e2542009-12-14 22:02:35311 }
312
313 // As above, but with ctrl+shift+tab.
[email protected]57892182012-12-03 19:15:39314 browser()->tab_strip_model()->ActivateTabAt(4, true);
[email protected]cb7e2542009-12-14 22:02:35315 for (int j = 14; j >= 0; --j) {
[email protected]f2159ba2012-04-17 19:13:21316 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER :
[email protected]5c4e4482013-03-03 00:09:18317 VIEW_ID_OMNIBOX;
[email protected]cb7e2542009-12-14 22:02:35318 ASSERT_TRUE(IsViewFocused(vid));
319
[email protected]1d000682010-08-23 16:21:28320 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
[email protected]b6d81262011-01-13 17:36:09321 browser(), ui::VKEY_TAB, true, true, false, false));
[email protected]cb7e2542009-12-14 22:02:35322 }
initial.commit09911bf2008-07-26 23:55:29323 }
324}
325
[email protected]ae40b572009-10-02 21:17:45326// Tabs remember focus with find-in-page box.
[email protected]cb7e2542009-12-14 22:02:35327IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) {
[email protected]a6e602f2010-09-28 22:28:30328 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05329 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]ae40b572009-10-02 21:17:45330
331 // First we navigate to our test page.
[email protected]c1dffe82013-06-26 20:59:05332 GURL url = embedded_test_server()->GetURL(kSimplePage);
[email protected]ae40b572009-10-02 21:17:45333 ui_test_utils::NavigateToURL(browser(), url);
334
[email protected]a37d4b02012-06-25 21:56:10335 chrome::Find(browser());
[email protected]cc872372013-01-28 21:57:07336 ui_test_utils::FindInPage(
337 browser()->tab_strip_model()->GetActiveWebContents(),
338 ASCIIToUTF16("a"), true, false, NULL, NULL);
[email protected]21abcc742009-10-23 02:52:06339 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
[email protected]ae40b572009-10-02 21:17:45340
341 // Focus the location bar.
[email protected]a37d4b02012-06-25 21:56:10342 chrome::FocusLocationBar(browser());
[email protected]ae40b572009-10-02 21:17:45343
344 // Create a 2nd tab.
[email protected]52877dbc62012-06-29 22:22:03345 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
[email protected]ae40b572009-10-02 21:17:45346
347 // Focus should be on the recently opened tab page.
[email protected]f2159ba2012-04-17 19:13:21348 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]ae40b572009-10-02 21:17:45349
350 // Select 1st tab, focus should still be on the location-bar.
351 // (bug http://crbug.com/23296)
[email protected]57892182012-12-03 19:15:39352 browser()->tab_strip_model()->ActivateTabAt(0, true);
[email protected]5c4e4482013-03-03 00:09:18353 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
[email protected]ae40b572009-10-02 21:17:45354
355 // Now open the find box again, switch to another tab and come back, the focus
356 // should return to the find box.
[email protected]a37d4b02012-06-25 21:56:10357 chrome::Find(browser());
[email protected]21abcc742009-10-23 02:52:06358 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
[email protected]57892182012-12-03 19:15:39359 browser()->tab_strip_model()->ActivateTabAt(1, true);
[email protected]f2159ba2012-04-17 19:13:21360 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]57892182012-12-03 19:15:39361 browser()->tab_strip_model()->ActivateTabAt(0, true);
[email protected]21abcc742009-10-23 02:52:06362 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
[email protected]ae40b572009-10-02 21:17:45363}
364
initial.commit09911bf2008-07-26 23:55:29365// Background window does not steal focus.
[email protected]c92928672010-11-09 18:31:07366// Flaky, http://crbug.com/62538.
367IN_PROC_BROWSER_TEST_F(BrowserFocusTest,
[email protected]4d2451652012-02-14 23:54:26368 DISABLED_BackgroundBrowserDontStealFocus) {
[email protected]a6e602f2010-09-28 22:28:30369 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05370 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
initial.commit09911bf2008-07-26 23:55:29371
initial.commit09911bf2008-07-26 23:55:29372 // Open a new browser window.
[email protected]c125cdc2013-02-25 19:10:21373 Browser* browser2 =
374 new Browser(Browser::CreateParams(browser()->profile(),
375 browser()->host_desktop_type()));
[email protected]8bcdec92009-02-25 16:15:18376 ASSERT_TRUE(browser2);
[email protected]686221c2012-11-08 07:30:10377 chrome::AddBlankTabAt(browser2, -1, true);
[email protected]8bcdec92009-02-25 16:15:18378 browser2->window()->Show();
[email protected]186f13f2009-08-19 20:34:00379
[email protected]ed179ee2009-10-03 21:02:51380 Browser* focused_browser = NULL;
381 Browser* unfocused_browser = NULL;
[email protected]753efc42010-03-09 19:52:16382#if defined(USE_X11)
383 // On X11, calling Activate() is not guaranteed to move focus, so we have
[email protected]186f13f2009-08-19 20:34:00384 // to figure out which browser does have focus.
385 if (browser2->window()->IsActive()) {
386 focused_browser = browser2;
387 unfocused_browser = browser();
388 } else if (browser()->window()->IsActive()) {
389 focused_browser = browser();
390 unfocused_browser = browser2;
391 } else {
[email protected]579c3d82010-10-06 03:53:51392 FAIL() << "Could not determine which browser has focus";
[email protected]186f13f2009-08-19 20:34:00393 }
394#elif defined(OS_WIN)
395 focused_browser = browser();
396 unfocused_browser = browser2;
[email protected]853300a82010-07-27 21:17:57397#elif defined(OS_MACOSX)
398 // On Mac, the newly created window always gets the focus.
399 focused_browser = browser2;
400 unfocused_browser = browser();
[email protected]186f13f2009-08-19 20:34:00401#endif
402
[email protected]c1dffe82013-06-26 20:59:05403 GURL steal_focus_url = embedded_test_server()->GetURL(kStealFocusPage);
[email protected]186f13f2009-08-19 20:34:00404 ui_test_utils::NavigateToURL(unfocused_browser, steal_focus_url);
[email protected]1e187af2009-02-25 02:02:46405
[email protected]8bcdec92009-02-25 16:15:18406 // Activate the first browser.
[email protected]186f13f2009-08-19 20:34:00407 focused_browser->window()->Activate();
initial.commit09911bf2008-07-26 23:55:29408
[email protected]b6987e02013-01-04 18:30:43409 ASSERT_TRUE(content::ExecuteScript(
[email protected]da2bfa42013-01-29 23:47:05410 unfocused_browser->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13411 "stealFocus();"));
initial.commit09911bf2008-07-26 23:55:29412
[email protected]8bcdec92009-02-25 16:15:18413 // Make sure the first browser is still active.
[email protected]186f13f2009-08-19 20:34:00414 EXPECT_TRUE(focused_browser->window()->IsActive());
initial.commit09911bf2008-07-26 23:55:29415}
416
417// Page cannot steal focus when focus is on location bar.
[email protected]7ef7c6e2012-10-30 12:32:44418IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) {
[email protected]a6e602f2010-09-28 22:28:30419 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05420 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
initial.commit09911bf2008-07-26 23:55:29421
422 // Open the page that steals focus.
[email protected]c1dffe82013-06-26 20:59:05423 GURL url = embedded_test_server()->GetURL(kStealFocusPage);
[email protected]8bcdec92009-02-25 16:15:18424 ui_test_utils::NavigateToURL(browser(), url);
initial.commit09911bf2008-07-26 23:55:29425
[email protected]a37d4b02012-06-25 21:56:10426 chrome::FocusLocationBar(browser());
initial.commit09911bf2008-07-26 23:55:29427
[email protected]b6987e02013-01-04 18:30:43428 ASSERT_TRUE(content::ExecuteScript(
[email protected]cc872372013-01-28 21:57:07429 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13430 "stealFocus();"));
initial.commit09911bf2008-07-26 23:55:29431
432 // Make sure the location bar is still focused.
[email protected]5c4e4482013-03-03 00:09:18433 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
initial.commit09911bf2008-07-26 23:55:29434}
435
[email protected]9e0c83a2009-05-06 19:44:37436// Focus traversal on a regular page.
[email protected]130efb02009-09-18 18:54:35437// Note that this test relies on a notification from the renderer that the
438// focus has changed in the page. The notification in the renderer may change
439// at which point this test would fail (see comment in
440// RenderWidget::didFocus()).
[email protected]853300a82010-07-27 21:17:57441IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) {
[email protected]a6e602f2010-09-28 22:28:30442 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05443 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
initial.commit09911bf2008-07-26 23:55:29444
[email protected]8bcdec92009-02-25 16:15:18445 // First we navigate to our test page.
[email protected]c1dffe82013-06-26 20:59:05446 GURL url = embedded_test_server()->GetURL(kTypicalPage);
[email protected]8bcdec92009-02-25 16:15:18447 ui_test_utils::NavigateToURL(browser(), url);
initial.commit09911bf2008-07-26 23:55:29448
[email protected]a37d4b02012-06-25 21:56:10449 chrome::FocusLocationBar(browser());
initial.commit09911bf2008-07-26 23:55:29450
[email protected]546ae4e02010-12-08 14:57:19451 const char* kTextElementID = "textEdit";
[email protected]8bcdec92009-02-25 16:15:18452 const char* kExpElementIDs[] = {
453 "", // Initially no element in the page should be focused
454 // (the location bar is focused).
[email protected]546ae4e02010-12-08 14:57:19455 kTextElementID, "searchButton", "luckyButton", "googleLink", "gmailLink",
[email protected]8bcdec92009-02-25 16:15:18456 "gmapLink"
initial.commit09911bf2008-07-26 23:55:29457 };
458
459 // Test forward focus traversal.
460 for (int i = 0; i < 3; ++i) {
[email protected]1870d5cf2011-05-12 01:55:40461 SCOPED_TRACE(base::StringPrintf("outer loop: %d", i));
initial.commit09911bf2008-07-26 23:55:29462 // Location bar should be focused.
[email protected]5c4e4482013-03-03 00:09:18463 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
initial.commit09911bf2008-07-26 23:55:29464
[email protected]911696b2011-01-28 02:36:49465 // Move the caret to the end, otherwise the next Tab key may not move focus.
466 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
467 browser(), ui::VKEY_END, false, false, false, false));
468
initial.commit09911bf2008-07-26 23:55:29469 // Now let's press tab to move the focus.
[email protected]130efb02009-09-18 18:54:35470 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) {
[email protected]1870d5cf2011-05-12 01:55:40471 SCOPED_TRACE(base::StringPrintf("inner loop %" PRIuS, j));
initial.commit09911bf2008-07-26 23:55:29472 // Let's make sure the focus is on the expected element in the page.
[email protected]45671612009-04-29 22:24:01473 std::string actual;
[email protected]b6987e02013-01-04 18:30:43474 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]cc872372013-01-28 21:57:07475 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13476 "window.domAutomationController.send(getFocusedElement());",
[email protected]45671612009-04-29 22:24:01477 &actual));
initial.commit09911bf2008-07-26 23:55:29478 ASSERT_STREQ(kExpElementIDs[j], actual.c_str());
479
[email protected]130efb02009-09-18 18:54:35480 if (j < arraysize(kExpElementIDs) - 1) {
[email protected]546ae4e02010-12-08 14:57:19481 // If the next element is the kTextElementID, we expect to be
482 // notified we have switched to an editable node.
483 bool is_editable_node =
484 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0);
[email protected]6c2381d2011-10-19 02:52:53485 content::Details<bool> details(&is_editable_node);
[email protected]546ae4e02010-12-08 14:57:19486
487 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails(
[email protected]b6d81262011-01-13 17:36:09488 browser(), ui::VKEY_TAB, false, false, false, false,
[email protected]432115822011-07-10 15:52:27489 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
[email protected]d53092652011-12-06 06:12:56490 content::NotificationSource(content::Source<RenderViewHost>(
[email protected]cc872372013-01-28 21:57:07491 browser()->tab_strip_model()->GetActiveWebContents()->
492 GetRenderViewHost())),
[email protected]546ae4e02010-12-08 14:57:19493 details));
[email protected]130efb02009-09-18 18:54:35494 } else {
495 // On the last tab key press, the focus returns to the browser.
[email protected]546ae4e02010-12-08 14:57:19496 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
[email protected]b6d81262011-01-13 17:36:09497 browser(), ui::VKEY_TAB, false, false, false, false,
[email protected]432115822011-07-10 15:52:27498 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
[email protected]6c2381d2011-10-19 02:52:53499 content::NotificationSource(content::Source<Browser>(browser()))));
[email protected]130efb02009-09-18 18:54:35500 }
initial.commit09911bf2008-07-26 23:55:29501 }
[email protected]8bcdec92009-02-25 16:15:18502
503 // At this point the renderer has sent us a message asking to advance the
504 // focus (as the end of the focus loop was reached in the renderer).
505 // We need to run the message loop to process it.
[email protected]b8deecd2012-07-30 21:09:44506 content::RunAllPendingInMessageLoop();
initial.commit09911bf2008-07-26 23:55:29507 }
508
509 // Now let's try reverse focus traversal.
510 for (int i = 0; i < 3; ++i) {
[email protected]1870d5cf2011-05-12 01:55:40511 SCOPED_TRACE(base::StringPrintf("outer loop: %d", i));
initial.commit09911bf2008-07-26 23:55:29512 // Location bar should be focused.
[email protected]5c4e4482013-03-03 00:09:18513 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
initial.commit09911bf2008-07-26 23:55:29514
[email protected]911696b2011-01-28 02:36:49515 // Move the caret to the end, otherwise the next Tab key may not move focus.
516 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
517 browser(), ui::VKEY_END, false, false, false, false));
518
[email protected]8bcdec92009-02-25 16:15:18519 // Now let's press shift-tab to move the focus in reverse.
[email protected]a6e602f2010-09-28 22:28:30520 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) {
[email protected]1870d5cf2011-05-12 01:55:40521 SCOPED_TRACE(base::StringPrintf("inner loop: %" PRIuS, j));
[email protected]546ae4e02010-12-08 14:57:19522 const char* next_element =
523 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j];
[email protected]130efb02009-09-18 18:54:35524
525 if (j < arraysize(kExpElementIDs) - 1) {
[email protected]546ae4e02010-12-08 14:57:19526 // If the next element is the kTextElementID, we expect to be
527 // notified we have switched to an editable node.
528 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0);
[email protected]6c2381d2011-10-19 02:52:53529 content::Details<bool> details(&is_editable_node);
[email protected]546ae4e02010-12-08 14:57:19530
531 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails(
[email protected]b6d81262011-01-13 17:36:09532 browser(), ui::VKEY_TAB, false, true, false, false,
[email protected]432115822011-07-10 15:52:27533 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
[email protected]d53092652011-12-06 06:12:56534 content::NotificationSource(content::Source<RenderViewHost>(
[email protected]cc872372013-01-28 21:57:07535 browser()->tab_strip_model()->GetActiveWebContents()->
536 GetRenderViewHost())),
[email protected]546ae4e02010-12-08 14:57:19537 details));
[email protected]130efb02009-09-18 18:54:35538 } else {
539 // On the last tab key press, the focus returns to the browser.
[email protected]546ae4e02010-12-08 14:57:19540 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
[email protected]b6d81262011-01-13 17:36:09541 browser(), ui::VKEY_TAB, false, true, false, false,
[email protected]432115822011-07-10 15:52:27542 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
[email protected]6c2381d2011-10-19 02:52:53543 content::NotificationSource(content::Source<Browser>(browser()))));
[email protected]130efb02009-09-18 18:54:35544 }
initial.commit09911bf2008-07-26 23:55:29545
546 // Let's make sure the focus is on the expected element in the page.
[email protected]45671612009-04-29 22:24:01547 std::string actual;
[email protected]b6987e02013-01-04 18:30:43548 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]cc872372013-01-28 21:57:07549 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13550 "window.domAutomationController.send(getFocusedElement());",
[email protected]45671612009-04-29 22:24:01551 &actual));
[email protected]546ae4e02010-12-08 14:57:19552 ASSERT_STREQ(next_element, actual.c_str());
initial.commit09911bf2008-07-26 23:55:29553 }
[email protected]8bcdec92009-02-25 16:15:18554
555 // At this point the renderer has sent us a message asking to advance the
556 // focus (as the end of the focus loop was reached in the renderer).
557 // We need to run the message loop to process it.
[email protected]b8deecd2012-07-30 21:09:44558 content::RunAllPendingInMessageLoop();
initial.commit09911bf2008-07-26 23:55:29559 }
560}
561
[email protected]9e0c83a2009-05-06 19:44:37562// Focus traversal while an interstitial is showing.
[email protected]fc2e0872009-08-21 22:14:41563IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) {
[email protected]a6e602f2010-09-28 22:28:30564 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05565 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]9e0c83a2009-05-06 19:44:37566
567 // First we navigate to our test page.
[email protected]c1dffe82013-06-26 20:59:05568 GURL url = embedded_test_server()->GetURL(kSimplePage);
[email protected]9e0c83a2009-05-06 19:44:37569 ui_test_utils::NavigateToURL(browser(), url);
570
[email protected]9e0c83a2009-05-06 19:44:37571 // Focus should be on the page.
[email protected]f2159ba2012-04-17 19:13:21572 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]9e0c83a2009-05-06 19:44:37573
574 // Let's show an interstitial.
[email protected]cc872372013-01-28 21:57:07575 TestInterstitialPage* interstitial_page = new TestInterstitialPage(
576 browser()->tab_strip_model()->GetActiveWebContents(),
577 true, GURL("http://interstitial.com"));
[email protected]9e0c83a2009-05-06 19:44:37578 // Give some time for the interstitial to show.
[email protected]3264d162013-05-08 22:02:11579 base::MessageLoop::current()->PostDelayedTask(
580 FROM_HERE,
581 base::MessageLoop::QuitClosure(),
582 base::TimeDelta::FromSeconds(1));
[email protected]729eb632012-07-26 04:45:26583 content::RunMessageLoop();
[email protected]9e0c83a2009-05-06 19:44:37584
[email protected]a37d4b02012-06-25 21:56:10585 chrome::FocusLocationBar(browser());
[email protected]9e0c83a2009-05-06 19:44:37586
587 const char* kExpElementIDs[] = {
588 "", // Initially no element in the page should be focused
589 // (the location bar is focused).
590 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink",
591 "gmapLink"
592 };
593
594 // Test forward focus traversal.
595 for (int i = 0; i < 2; ++i) {
596 // Location bar should be focused.
[email protected]5c4e4482013-03-03 00:09:18597 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
[email protected]9e0c83a2009-05-06 19:44:37598
[email protected]911696b2011-01-28 02:36:49599 // Move the caret to the end, otherwise the next Tab key may not move focus.
600 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
601 browser(), ui::VKEY_END, false, false, false, false));
602
[email protected]9e0c83a2009-05-06 19:44:37603 // Now let's press tab to move the focus.
[email protected]130efb02009-09-18 18:54:35604 for (size_t j = 0; j < 7; ++j) {
[email protected]9e0c83a2009-05-06 19:44:37605 // Let's make sure the focus is on the expected element in the page.
[email protected]a6e602f2010-09-28 22:28:30606 std::string actual;
[email protected]b6987e02013-01-04 18:30:43607 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]06bc5d92013-01-02 22:44:13608 interstitial_page->render_view_host(),
[email protected]06bc5d92013-01-02 22:44:13609 "window.domAutomationController.send(getFocusedElement());",
[email protected]a6e602f2010-09-28 22:28:30610 &actual));
[email protected]9e0c83a2009-05-06 19:44:37611 ASSERT_STREQ(kExpElementIDs[j], actual.c_str());
612
[email protected]432115822011-07-10 15:52:27613 int notification_type;
[email protected]6c2381d2011-10-19 02:52:53614 content::NotificationSource notification_source =
[email protected]ad50def52011-10-19 23:17:07615 content::NotificationService::AllSources();
[email protected]130efb02009-09-18 18:54:35616 if (j < arraysize(kExpElementIDs) - 1) {
[email protected]432115822011-07-10 15:52:27617 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE;
[email protected]d53092652011-12-06 06:12:56618 notification_source = content::Source<RenderViewHost>(
619 interstitial_page->render_view_host());
[email protected]130efb02009-09-18 18:54:35620 } else {
621 // On the last tab key press, the focus returns to the browser.
[email protected]432115822011-07-10 15:52:27622 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER;
[email protected]6c2381d2011-10-19 02:52:53623 notification_source = content::Source<Browser>(browser());
[email protected]130efb02009-09-18 18:54:35624 }
[email protected]a6e602f2010-09-28 22:28:30625
626 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
[email protected]b6d81262011-01-13 17:36:09627 browser(), ui::VKEY_TAB, false, false, false, false,
[email protected]a6e602f2010-09-28 22:28:30628 notification_type, notification_source));
[email protected]9e0c83a2009-05-06 19:44:37629 }
630
631 // At this point the renderer has sent us a message asking to advance the
632 // focus (as the end of the focus loop was reached in the renderer).
633 // We need to run the message loop to process it.
[email protected]b8deecd2012-07-30 21:09:44634 content::RunAllPendingInMessageLoop();
[email protected]9e0c83a2009-05-06 19:44:37635 }
636
637 // Now let's try reverse focus traversal.
638 for (int i = 0; i < 2; ++i) {
639 // Location bar should be focused.
[email protected]5c4e4482013-03-03 00:09:18640 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
[email protected]9e0c83a2009-05-06 19:44:37641
[email protected]911696b2011-01-28 02:36:49642 // Move the caret to the end, otherwise the next Tab key may not move focus.
643 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
644 browser(), ui::VKEY_END, false, false, false, false));
645
[email protected]9e0c83a2009-05-06 19:44:37646 // Now let's press shift-tab to move the focus in reverse.
[email protected]130efb02009-09-18 18:54:35647 for (size_t j = 0; j < 7; ++j) {
[email protected]432115822011-07-10 15:52:27648 int notification_type;
[email protected]6c2381d2011-10-19 02:52:53649 content::NotificationSource notification_source =
[email protected]ad50def52011-10-19 23:17:07650 content::NotificationService::AllSources();
[email protected]130efb02009-09-18 18:54:35651 if (j < arraysize(kExpElementIDs) - 1) {
[email protected]432115822011-07-10 15:52:27652 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE;
[email protected]d53092652011-12-06 06:12:56653 notification_source = content::Source<RenderViewHost>(
654 interstitial_page->render_view_host());
[email protected]130efb02009-09-18 18:54:35655 } else {
656 // On the last tab key press, the focus returns to the browser.
[email protected]432115822011-07-10 15:52:27657 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER;
[email protected]6c2381d2011-10-19 02:52:53658 notification_source = content::Source<Browser>(browser());
[email protected]130efb02009-09-18 18:54:35659 }
[email protected]9e0c83a2009-05-06 19:44:37660
[email protected]a6e602f2010-09-28 22:28:30661 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
[email protected]b6d81262011-01-13 17:36:09662 browser(), ui::VKEY_TAB, false, true, false, false,
[email protected]a6e602f2010-09-28 22:28:30663 notification_type, notification_source));
664
[email protected]9e0c83a2009-05-06 19:44:37665 // Let's make sure the focus is on the expected element in the page.
[email protected]a6e602f2010-09-28 22:28:30666 std::string actual;
[email protected]b6987e02013-01-04 18:30:43667 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]06bc5d92013-01-02 22:44:13668 interstitial_page->render_view_host(),
[email protected]06bc5d92013-01-02 22:44:13669 "window.domAutomationController.send(getFocusedElement());",
[email protected]a6e602f2010-09-28 22:28:30670 &actual));
[email protected]9e0c83a2009-05-06 19:44:37671 ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str());
672 }
673
674 // At this point the renderer has sent us a message asking to advance the
675 // focus (as the end of the focus loop was reached in the renderer).
676 // We need to run the message loop to process it.
[email protected]b8deecd2012-07-30 21:09:44677 content::RunAllPendingInMessageLoop();
[email protected]9e0c83a2009-05-06 19:44:37678 }
679}
680
681// Focus stays on page with interstitials.
[email protected]cb931932011-05-03 19:57:33682// http://crbug.com/81451
[email protected]4d2451652012-02-14 23:54:26683IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_InterstitialFocus) {
[email protected]a6e602f2010-09-28 22:28:30684 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05685 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]9e0c83a2009-05-06 19:44:37686
687 // First we navigate to our test page.
[email protected]c1dffe82013-06-26 20:59:05688 GURL url = embedded_test_server()->GetURL(kSimplePage);
[email protected]9e0c83a2009-05-06 19:44:37689 ui_test_utils::NavigateToURL(browser(), url);
690
[email protected]9e0c83a2009-05-06 19:44:37691 // Page should have focus.
[email protected]f2159ba2012-04-17 19:13:21692 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]cc872372013-01-28 21:57:07693 EXPECT_TRUE(browser()->tab_strip_model()->GetActiveWebContents()->
694 GetRenderViewHost()->GetView()->HasFocus());
[email protected]9e0c83a2009-05-06 19:44:37695
[email protected]9d8a4642009-07-29 17:25:30696 // Let's show an interstitial.
[email protected]cc872372013-01-28 21:57:07697 TestInterstitialPage* interstitial_page = new TestInterstitialPage(
698 browser()->tab_strip_model()->GetActiveWebContents(),
699 true, GURL("http://interstitial.com"));
[email protected]9e0c83a2009-05-06 19:44:37700 // Give some time for the interstitial to show.
[email protected]3264d162013-05-08 22:02:11701 base::MessageLoop::current()->PostDelayedTask(
702 FROM_HERE,
703 base::MessageLoop::QuitClosure(),
704 base::TimeDelta::FromSeconds(1));
[email protected]729eb632012-07-26 04:45:26705 content::RunMessageLoop();
[email protected]9e0c83a2009-05-06 19:44:37706
707 // The interstitial should have focus now.
[email protected]f2159ba2012-04-17 19:13:21708 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]9e0c83a2009-05-06 19:44:37709 EXPECT_TRUE(interstitial_page->HasFocus());
710
711 // Hide the interstitial.
712 interstitial_page->DontProceed();
713
714 // Focus should be back on the original page.
[email protected]f2159ba2012-04-17 19:13:21715 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]9e0c83a2009-05-06 19:44:37716}
717
[email protected]9bd491ee2008-12-10 22:31:07718// Make sure Find box can request focus, even when it is already open.
[email protected]06e85dfd2012-10-31 01:32:35719// Disabled due to flakiness. http://crbug.com/67301.
720IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FindFocusTest) {
[email protected]a6e602f2010-09-28 22:28:30721 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05722 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
license.botbf09a502008-08-24 00:55:55723
[email protected]9bd491ee2008-12-10 22:31:07724 // Open some page (any page that doesn't steal focus).
[email protected]c1dffe82013-06-26 20:59:05725 GURL url = embedded_test_server()->GetURL(kTypicalPage);
[email protected]8bcdec92009-02-25 16:15:18726 ui_test_utils::NavigateToURL(browser(), url);
[email protected]9bd491ee2008-12-10 22:31:07727
[email protected]a711df102010-12-14 09:47:03728 EXPECT_TRUE(ChromeInForeground());
729
[email protected]853300a82010-07-27 21:17:57730#if defined(OS_MACOSX)
731 // Press Cmd+F, which will make the Find box open and request focus.
[email protected]1d000682010-08-23 16:21:28732 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
[email protected]b6d81262011-01-13 17:36:09733 browser(), ui::VKEY_F, false, false, false, true));
[email protected]853300a82010-07-27 21:17:57734#else
[email protected]9bd491ee2008-12-10 22:31:07735 // Press Ctrl+F, which will make the Find box open and request focus.
[email protected]1d000682010-08-23 16:21:28736 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
[email protected]b6d81262011-01-13 17:36:09737 browser(), ui::VKEY_F, true, false, false, false));
[email protected]853300a82010-07-27 21:17:57738#endif
[email protected]8bcdec92009-02-25 16:15:18739
[email protected]a9c060ca2012-01-05 20:43:41740 ASSERT_TRUE(WaitForFocusChange(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
[email protected]9bd491ee2008-12-10 22:31:07741
[email protected]a37d4b02012-06-25 21:56:10742 chrome::FocusLocationBar(browser());
[email protected]5c4e4482013-03-03 00:09:18743 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
[email protected]9bd491ee2008-12-10 22:31:07744
745 // Now press Ctrl+F again and focus should move to the Find box.
[email protected]853300a82010-07-27 21:17:57746#if defined(OS_MACOSX)
[email protected]1d000682010-08-23 16:21:28747 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
[email protected]b6d81262011-01-13 17:36:09748 browser(), ui::VKEY_F, false, false, false, true));
[email protected]853300a82010-07-27 21:17:57749#else
[email protected]1d000682010-08-23 16:21:28750 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
[email protected]b6d81262011-01-13 17:36:09751 browser(), ui::VKEY_F, true, false, false, false));
[email protected]853300a82010-07-27 21:17:57752#endif
[email protected]21abcc742009-10-23 02:52:06753 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
[email protected]9bd491ee2008-12-10 22:31:07754
755 // Set focus to the page.
[email protected]fc2e0872009-08-21 22:14:41756 ClickOnView(VIEW_ID_TAB_CONTAINER);
[email protected]f2159ba2012-04-17 19:13:21757 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]9bd491ee2008-12-10 22:31:07758
759 // Now press Ctrl+F again and focus should move to the Find box.
[email protected]853300a82010-07-27 21:17:57760#if defined(OS_MACOSX)
[email protected]1d000682010-08-23 16:21:28761 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
[email protected]b6d81262011-01-13 17:36:09762 browser(), ui::VKEY_F, false, false, false, true));
[email protected]853300a82010-07-27 21:17:57763#else
[email protected]1d000682010-08-23 16:21:28764 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
[email protected]b6d81262011-01-13 17:36:09765 browser(), ui::VKEY_F, true, false, false, false));
[email protected]853300a82010-07-27 21:17:57766#endif
[email protected]8bcdec92009-02-25 16:15:18767
[email protected]a9c060ca2012-01-05 20:43:41768 ASSERT_TRUE(WaitForFocusChange(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
[email protected]9bd491ee2008-12-10 22:31:07769}
[email protected]401513c2009-03-12 00:21:28770
771// Makes sure the focus is in the right location when opening the different
772// types of tabs.
[email protected]c92928672010-11-09 18:31:07773// Flaky, http://crbug.com/62539.
[email protected]4d2451652012-02-14 23:54:26774IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabInitialFocus) {
[email protected]a6e602f2010-09-28 22:28:30775 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]9ba21ede2010-07-30 01:11:07776
[email protected]401513c2009-03-12 00:21:28777 // Open the history tab, focus should be on the tab contents.
[email protected]5d9cace72012-06-21 16:07:12778 chrome::ShowHistory(browser());
[email protected]6ddc6e3f22012-07-26 01:15:35779 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop(
[email protected]cc872372013-01-28 21:57:07780 browser()->tab_strip_model()->GetActiveWebContents()));
[email protected]f2159ba2012-04-17 19:13:21781 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]401513c2009-03-12 00:21:28782
783 // Open the new tab, focus should be on the location bar.
[email protected]a37d4b02012-06-25 21:56:10784 chrome::NewTab(browser());
[email protected]6ddc6e3f22012-07-26 01:15:35785 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop(
[email protected]cc872372013-01-28 21:57:07786 browser()->tab_strip_model()->GetActiveWebContents()));
[email protected]5c4e4482013-03-03 00:09:18787 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
[email protected]401513c2009-03-12 00:21:28788
789 // Open the download tab, focus should be on the tab contents.
[email protected]5d9cace72012-06-21 16:07:12790 chrome::ShowDownloads(browser());
[email protected]6ddc6e3f22012-07-26 01:15:35791 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop(
[email protected]cc872372013-01-28 21:57:07792 browser()->tab_strip_model()->GetActiveWebContents()));
[email protected]f2159ba2012-04-17 19:13:21793 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]3e3f0eb2009-06-22 18:33:43794
795 // Open about:blank, focus should be on the location bar.
[email protected]081dc522013-05-15 04:59:20796 chrome::AddSelectedTabWithURL(browser(), GURL(content::kAboutBlankURL),
[email protected]52877dbc62012-06-29 22:22:03797 content::PAGE_TRANSITION_LINK);
[email protected]6ddc6e3f22012-07-26 01:15:35798 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop(
[email protected]cc872372013-01-28 21:57:07799 browser()->tab_strip_model()->GetActiveWebContents()));
[email protected]5c4e4482013-03-03 00:09:18800 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
[email protected]401513c2009-03-12 00:21:28801}
[email protected]9d8a4642009-07-29 17:25:30802
803// Tests that focus goes where expected when using reload.
[email protected]e4f4e0b2009-10-13 19:58:21804IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) {
[email protected]a6e602f2010-09-28 22:28:30805 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05806 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]9d8a4642009-07-29 17:25:30807
[email protected]9d8a4642009-07-29 17:25:30808 // Open the new tab, reload.
[email protected]6b4e8e42011-08-17 19:36:06809 {
[email protected]a7fe9112012-07-20 02:34:45810 content::WindowedNotificationObserver observer(
[email protected]6b4e8e42011-08-17 19:36:06811 content::NOTIFICATION_LOAD_STOP,
[email protected]ad50def52011-10-19 23:17:07812 content::NotificationService::AllSources());
[email protected]a37d4b02012-06-25 21:56:10813 chrome::NewTab(browser());
[email protected]6b4e8e42011-08-17 19:36:06814 observer.Wait();
815 }
[email protected]b8deecd2012-07-30 21:09:44816 content::RunAllPendingInMessageLoop();
[email protected]f07d7bf2010-04-06 08:02:42817
[email protected]6b4e8e42011-08-17 19:36:06818 {
[email protected]a7fe9112012-07-20 02:34:45819 content::WindowedNotificationObserver observer(
[email protected]6b4e8e42011-08-17 19:36:06820 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50821 content::Source<NavigationController>(
[email protected]cc872372013-01-28 21:57:07822 &browser()->tab_strip_model()->GetActiveWebContents()->
823 GetController()));
[email protected]a37d4b02012-06-25 21:56:10824 chrome::Reload(browser(), CURRENT_TAB);
[email protected]6b4e8e42011-08-17 19:36:06825 observer.Wait();
826 }
[email protected]9d8a4642009-07-29 17:25:30827 // Focus should stay on the location bar.
[email protected]5c4e4482013-03-03 00:09:18828 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
[email protected]9d8a4642009-07-29 17:25:30829
830 // Open a regular page, focus the location bar, reload.
[email protected]c1dffe82013-06-26 20:59:05831 ui_test_utils::NavigateToURL(browser(),
832 embedded_test_server()->GetURL(kSimplePage));
[email protected]a37d4b02012-06-25 21:56:10833 chrome::FocusLocationBar(browser());
[email protected]5c4e4482013-03-03 00:09:18834 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
[email protected]6b4e8e42011-08-17 19:36:06835 {
[email protected]a7fe9112012-07-20 02:34:45836 content::WindowedNotificationObserver observer(
[email protected]6b4e8e42011-08-17 19:36:06837 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50838 content::Source<NavigationController>(
[email protected]cc872372013-01-28 21:57:07839 &browser()->tab_strip_model()->GetActiveWebContents()->
840 GetController()));
[email protected]a37d4b02012-06-25 21:56:10841 chrome::Reload(browser(), CURRENT_TAB);
[email protected]6b4e8e42011-08-17 19:36:06842 observer.Wait();
843 }
[email protected]9ba21ede2010-07-30 01:11:07844
[email protected]9d8a4642009-07-29 17:25:30845 // Focus should now be on the tab contents.
[email protected]5d9cace72012-06-21 16:07:12846 chrome::ShowDownloads(browser());
[email protected]f2159ba2012-04-17 19:13:21847 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]9d8a4642009-07-29 17:25:30848}
849
850// Tests that focus goes where expected when using reload on a crashed tab.
[email protected]160f29ad2010-10-28 15:43:27851IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) {
[email protected]a6e602f2010-09-28 22:28:30852 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
[email protected]c1dffe82013-06-26 20:59:05853 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]9d8a4642009-07-29 17:25:30854
[email protected]9d8a4642009-07-29 17:25:30855 // Open a regular page, crash, reload.
[email protected]c1dffe82013-06-26 20:59:05856 ui_test_utils::NavigateToURL(browser(),
857 embedded_test_server()->GetURL(kSimplePage));
[email protected]cc872372013-01-28 21:57:07858 content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents());
[email protected]6b4e8e42011-08-17 19:36:06859 {
[email protected]a7fe9112012-07-20 02:34:45860 content::WindowedNotificationObserver observer(
[email protected]6b4e8e42011-08-17 19:36:06861 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50862 content::Source<NavigationController>(
[email protected]cc872372013-01-28 21:57:07863 &browser()->tab_strip_model()->GetActiveWebContents()->
864 GetController()));
[email protected]a37d4b02012-06-25 21:56:10865 chrome::Reload(browser(), CURRENT_TAB);
[email protected]6b4e8e42011-08-17 19:36:06866 observer.Wait();
867 }
[email protected]9ba21ede2010-07-30 01:11:07868
[email protected]9d8a4642009-07-29 17:25:30869 // Focus should now be on the tab contents.
[email protected]5d9cace72012-06-21 16:07:12870 chrome::ShowDownloads(browser());
[email protected]f2159ba2012-04-17 19:13:21871 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
[email protected]9d8a4642009-07-29 17:25:30872}
[email protected]629e0342010-07-27 23:30:13873
[email protected]895a84722012-11-29 18:45:44874// Tests that when a new tab is opened from the omnibox, the focus is moved from
875// the omnibox for the current tab.
876IN_PROC_BROWSER_TEST_F(BrowserFocusTest,
877 NavigateFromOmniboxIntoNewTab) {
878 GURL url("http://www.google.com/");
879 GURL url2("http://maps.google.com/");
880
881 // Navigate to url.
882 chrome::NavigateParams p(browser(), url, content::PAGE_TRANSITION_LINK);
883 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
884 p.disposition = CURRENT_TAB;
885 chrome::Navigate(&p);
886
887 // Focus the omnibox.
888 chrome::FocusLocationBar(browser());
889
890 OmniboxEditController* controller =
891 browser()->window()->GetLocationBar()->GetLocationEntry()->model()->
892 controller();
893
894 // Simulate an alt-enter.
895 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB,
[email protected]04ef14d2013-10-04 01:01:49896 content::PAGE_TRANSITION_TYPED);
[email protected]895a84722012-11-29 18:45:44897
898 // Make sure the second tab is selected.
[email protected]04e3ead52013-01-14 01:09:20899 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]895a84722012-11-29 18:45:44900
901 // The tab contents should have the focus in the second tab.
902 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
903
904 // Go back to the first tab. The focus should not be in the omnibox.
905 chrome::SelectPreviousTab(browser());
[email protected]04e3ead52013-01-14 01:09:20906 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]5c4e4482013-03-03 00:09:18907 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
[email protected]895a84722012-11-29 18:45:44908}
909
[email protected]19506d542013-10-15 23:11:06910IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnNavigate) {
[email protected]c744f7d22013-04-12 20:29:04911 // Needed on Mac.
912 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
913 // Load the NTP.
[email protected]19506d542013-10-15 23:11:06914 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
[email protected]c744f7d22013-04-12 20:29:04915 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
916
917 // Navigate to another page.
918 const base::FilePath::CharType* kEmptyFile = FILE_PATH_LITERAL("empty.html");
919 GURL file_url(ui_test_utils::GetTestUrl(base::FilePath(
920 base::FilePath::kCurrentDirectory), base::FilePath(kEmptyFile)));
921 ui_test_utils::NavigateToURL(browser(), file_url);
922
923 ClickOnView(VIEW_ID_TAB_CONTAINER);
924
925 // Navigate back. Should focus the location bar.
926 {
927 content::WindowedNotificationObserver back_nav_observer(
928 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
929 content::NotificationService::AllSources());
930 chrome::GoBack(browser(), CURRENT_TAB);
931 back_nav_observer.Wait();
932 }
933
934 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
935
936 // Navigate forward. Shouldn't focus the location bar.
937 ClickOnView(VIEW_ID_TAB_CONTAINER);
938 {
939 content::WindowedNotificationObserver forward_nav_observer(
940 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
941 content::NotificationService::AllSources());
942 chrome::GoForward(browser(), CURRENT_TAB);
943 forward_nav_observer.Wait();
944 }
945
946 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX));
947}
948
[email protected]629e0342010-07-27 23:30:13949} // namespace