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

Side by Side Diff: chrome/browser/browser_focus_uitest.cc

Issue 8800011: Use Textfield's view ID instead of Location bar's view id (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/browser_keyevents_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 << "Caption: " << caption.c_str(); 120 << "Caption: " << caption.c_str();
121 return chrome_window_in_foreground; 121 return chrome_window_in_foreground;
122 #else 122 #else
123 // Windows only at the moment. 123 // Windows only at the moment.
124 return true; 124 return true;
125 #endif 125 #endif
126 } 126 }
127 127
128 class BrowserFocusTest : public InProcessBrowserTest { 128 class BrowserFocusTest : public InProcessBrowserTest {
129 public: 129 public:
130 BrowserFocusTest() { 130 BrowserFocusTest() :
131 #if defined(USE_AURA)
132 location_bar_focus_view_id_(VIEW_ID_OMNIBOX)
133 #else
134 location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR)
135 #endif
136 {
131 set_show_window(true); 137 set_show_window(true);
132 EnableDOMAutomation(); 138 EnableDOMAutomation();
133 } 139 }
134 140
135 bool IsViewFocused(ViewID vid) { 141 bool IsViewFocused(ViewID vid) {
136 return ui_test_utils::IsViewFocused(browser(), vid); 142 return ui_test_utils::IsViewFocused(browser(), vid);
137 } 143 }
138 144
139 void ClickOnView(ViewID vid) { 145 void ClickOnView(ViewID vid) {
140 ui_test_utils::ClickOnView(browser(), vid); 146 ui_test_utils::ClickOnView(browser(), vid);
141 } 147 }
148
149 ViewID location_bar_focus_view_id_;
142 }; 150 };
143 151
144 class TestInterstitialPage : public InterstitialPage { 152 class TestInterstitialPage : public InterstitialPage {
145 public: 153 public:
146 TestInterstitialPage(TabContents* tab, bool new_navigation, const GURL& url) 154 TestInterstitialPage(TabContents* tab, bool new_navigation, const GURL& url)
147 : InterstitialPage(tab, new_navigation, url) { 155 : InterstitialPage(tab, new_navigation, url) {
148 FilePath file_path; 156 FilePath file_path;
149 bool r = PathService::Get(chrome::DIR_TEST_DATA, &file_path); 157 bool r = PathService::Get(chrome::DIR_TEST_DATA, &file_path);
150 EXPECT_TRUE(r); 158 EXPECT_TRUE(r);
151 file_path = file_path.AppendASCII("focus"); 159 file_path = file_path.AppendASCII("focus");
(...skipping 28 matching lines...) Expand all
180 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 188 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
181 #if defined(OS_POSIX) 189 #if defined(OS_POSIX)
182 // It seems we have to wait a little bit for the widgets to spin up before 190 // It seems we have to wait a little bit for the widgets to spin up before
183 // we can start clicking on them. 191 // we can start clicking on them.
184 MessageLoop::current()->PostDelayedTask(FROM_HERE, 192 MessageLoop::current()->PostDelayedTask(FROM_HERE,
185 new MessageLoop::QuitTask(), 193 new MessageLoop::QuitTask(),
186 kActionDelayMs); 194 kActionDelayMs);
187 ui_test_utils::RunMessageLoop(); 195 ui_test_utils::RunMessageLoop();
188 #endif // defined(OS_POSIX) 196 #endif // defined(OS_POSIX)
189 197
190 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 198 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
191 199
192 ClickOnView(VIEW_ID_TAB_CONTAINER); 200 ClickOnView(VIEW_ID_TAB_CONTAINER);
193 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 201 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
194 202
195 ClickOnView(VIEW_ID_LOCATION_BAR); 203 ClickOnView(VIEW_ID_LOCATION_BAR);
196 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 204 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
197 } 205 }
198 206
199 // Flaky, http://crbug.com/69034. 207 // Flaky, http://crbug.com/69034.
200 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_BrowsersRememberFocus) { 208 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_BrowsersRememberFocus) {
201 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 209 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
202 ASSERT_TRUE(test_server()->Start()); 210 ASSERT_TRUE(test_server()->Start());
203 211
204 // First we navigate to our test page. 212 // First we navigate to our test page.
205 GURL url = test_server()->GetURL(kSimplePage); 213 GURL url = test_server()->GetURL(kSimplePage);
206 ui_test_utils::NavigateToURL(browser(), url); 214 ui_test_utils::NavigateToURL(browser(), url);
207 215
208 gfx::NativeWindow window = browser()->window()->GetNativeHandle(); 216 gfx::NativeWindow window = browser()->window()->GetNativeHandle();
209 217
210 // The focus should be on the Tab contents. 218 // The focus should be on the Tab contents.
211 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 219 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
212 // Now hide the window, show it again, the focus should not have changed. 220 // Now hide the window, show it again, the focus should not have changed.
213 ui_test_utils::HideNativeWindow(window); 221 ui_test_utils::HideNativeWindow(window);
214 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); 222 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window));
215 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 223 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
216 224
217 browser()->FocusLocationBar(); 225 browser()->FocusLocationBar();
218 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 226 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
219 // Hide the window, show it again, the focus should not have changed. 227 // Hide the window, show it again, the focus should not have changed.
220 ui_test_utils::HideNativeWindow(window); 228 ui_test_utils::HideNativeWindow(window);
221 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); 229 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window));
222 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 230 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
223 231
224 // The rest of this test does not make sense on Linux because the behavior 232 // The rest of this test does not make sense on Linux because the behavior
225 // of Activate() is not well defined and can vary by window manager. 233 // of Activate() is not well defined and can vary by window manager.
226 #if defined(OS_WIN) 234 #if defined(OS_WIN)
227 // Open a new browser window. 235 // Open a new browser window.
228 Browser* browser2 = Browser::Create(browser()->profile()); 236 Browser* browser2 = Browser::Create(browser()->profile());
229 ASSERT_TRUE(browser2); 237 ASSERT_TRUE(browser2);
230 browser2->tabstrip_model()->delegate()->AddBlankTab(true); 238 browser2->tabstrip_model()->delegate()->AddBlankTab(true);
231 browser2->window()->Show(); 239 browser2->window()->Show();
232 ui_test_utils::NavigateToURL(browser2, url); 240 ui_test_utils::NavigateToURL(browser2, url);
233 241
234 gfx::NativeWindow window2 = browser2->window()->GetNativeHandle(); 242 gfx::NativeWindow window2 = browser2->window()->GetNativeHandle();
235 BrowserView* browser_view2 = 243 BrowserView* browser_view2 =
236 BrowserView::GetBrowserViewForBrowser(browser2); 244 BrowserView::GetBrowserViewForBrowser(browser2);
237 ASSERT_TRUE(browser_view2); 245 ASSERT_TRUE(browser_view2);
238 const views::Widget* widget2 = 246 const views::Widget* widget2 =
239 views::Widget::GetWidgetForNativeWindow(window2); 247 views::Widget::GetWidgetForNativeWindow(window2);
240 ASSERT_TRUE(widget2); 248 ASSERT_TRUE(widget2);
241 const views::FocusManager* focus_manager2 = widget2->GetFocusManager(); 249 const views::FocusManager* focus_manager2 = widget2->GetFocusManager();
242 ASSERT_TRUE(focus_manager2); 250 ASSERT_TRUE(focus_manager2);
243 EXPECT_EQ(browser_view2->GetTabContentsContainerView(), 251 EXPECT_EQ(browser_view2->GetTabContentsContainerView(),
244 focus_manager2->GetFocusedView()); 252 focus_manager2->GetFocusedView());
245 253
246 // Switch to the 1st browser window, focus should still be on the location 254 // Switch to the 1st browser window, focus should still be on the location
247 // bar and the second browser should have nothing focused. 255 // bar and the second browser should have nothing focused.
248 browser()->window()->Activate(); 256 browser()->window()->Activate();
249 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 257 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
250 EXPECT_EQ(NULL, focus_manager2->GetFocusedView()); 258 EXPECT_EQ(NULL, focus_manager2->GetFocusedView());
251 259
252 // Switch back to the second browser, focus should still be on the page. 260 // Switch back to the second browser, focus should still be on the page.
253 browser2->window()->Activate(); 261 browser2->window()->Activate();
254 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 262 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
255 ASSERT_TRUE(widget); 263 ASSERT_TRUE(widget);
256 EXPECT_EQ(NULL, widget->GetFocusManager()->GetFocusedView()); 264 EXPECT_EQ(NULL, widget->GetFocusManager()->GetFocusedView());
257 EXPECT_EQ(browser_view2->GetTabContentsContainerView(), 265 EXPECT_EQ(browser_view2->GetTabContentsContainerView(),
258 focus_manager2->GetFocusedView()); 266 focus_manager2->GetFocusedView());
259 267
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 browser()->FocusLocationBar(); 303 browser()->FocusLocationBar();
296 } 304 }
297 } 305 }
298 306
299 // Now come back to the tab and check the right view is focused. 307 // Now come back to the tab and check the right view is focused.
300 for (int j = 0; j < 5; j++) { 308 for (int j = 0; j < 5; j++) {
301 // Activate the tab. 309 // Activate the tab.
302 browser()->ActivateTabAt(j, true); 310 browser()->ActivateTabAt(j, true);
303 311
304 ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : 312 ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW :
305 VIEW_ID_LOCATION_BAR; 313 location_bar_focus_view_id_;
306 ASSERT_TRUE(IsViewFocused(vid)); 314 ASSERT_TRUE(IsViewFocused(vid));
307 } 315 }
308 316
309 browser()->ActivateTabAt(0, true); 317 browser()->ActivateTabAt(0, true);
310 // Try the above, but with ctrl+tab. Since tab normally changes focus, 318 // Try the above, but with ctrl+tab. Since tab normally changes focus,
311 // this has regressed in the past. Loop through several times to be sure. 319 // this has regressed in the past. Loop through several times to be sure.
312 for (int j = 0; j < 15; j++) { 320 for (int j = 0; j < 15; j++) {
313 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : 321 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW :
314 VIEW_ID_LOCATION_BAR; 322 location_bar_focus_view_id_;
315 ASSERT_TRUE(IsViewFocused(vid)); 323 ASSERT_TRUE(IsViewFocused(vid));
316 324
317 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 325 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
318 browser(), ui::VKEY_TAB, true, false, false, false)); 326 browser(), ui::VKEY_TAB, true, false, false, false));
319 } 327 }
320 328
321 // As above, but with ctrl+shift+tab. 329 // As above, but with ctrl+shift+tab.
322 browser()->ActivateTabAt(4, true); 330 browser()->ActivateTabAt(4, true);
323 for (int j = 14; j >= 0; --j) { 331 for (int j = 14; j >= 0; --j) {
324 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : 332 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW :
325 VIEW_ID_LOCATION_BAR; 333 location_bar_focus_view_id_;
326 ASSERT_TRUE(IsViewFocused(vid)); 334 ASSERT_TRUE(IsViewFocused(vid));
327 335
328 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 336 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
329 browser(), ui::VKEY_TAB, true, true, false, false)); 337 browser(), ui::VKEY_TAB, true, true, false, false));
330 } 338 }
331 } 339 }
332 } 340 }
333 341
334 // Tabs remember focus with find-in-page box. 342 // Tabs remember focus with find-in-page box.
335 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { 343 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) {
(...skipping 14 matching lines...) Expand all
350 358
351 // Create a 2nd tab. 359 // Create a 2nd tab.
352 browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); 360 browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED);
353 361
354 // Focus should be on the recently opened tab page. 362 // Focus should be on the recently opened tab page.
355 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 363 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
356 364
357 // Select 1st tab, focus should still be on the location-bar. 365 // Select 1st tab, focus should still be on the location-bar.
358 // (bug http://crbug.com/23296) 366 // (bug http://crbug.com/23296)
359 browser()->ActivateTabAt(0, true); 367 browser()->ActivateTabAt(0, true);
360 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 368 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
361 369
362 // Now open the find box again, switch to another tab and come back, the focus 370 // Now open the find box again, switch to another tab and come back, the focus
363 // should return to the find box. 371 // should return to the find box.
364 browser()->Find(); 372 browser()->Find();
365 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 373 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
366 browser()->ActivateTabAt(1, true); 374 browser()->ActivateTabAt(1, true);
367 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 375 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
368 browser()->ActivateTabAt(0, true); 376 browser()->ActivateTabAt(0, true);
369 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 377 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
370 } 378 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 GURL url = test_server()->GetURL(kStealFocusPage); 436 GURL url = test_server()->GetURL(kStealFocusPage);
429 ui_test_utils::NavigateToURL(browser(), url); 437 ui_test_utils::NavigateToURL(browser(), url);
430 438
431 browser()->FocusLocationBar(); 439 browser()->FocusLocationBar();
432 440
433 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 441 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
434 browser()->GetSelectedTabContents()->render_view_host(), L"", 442 browser()->GetSelectedTabContents()->render_view_host(), L"",
435 L"stealFocus();")); 443 L"stealFocus();"));
436 444
437 // Make sure the location bar is still focused. 445 // Make sure the location bar is still focused.
438 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 446 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
439 } 447 }
440 448
441 // Focus traversal on a regular page. 449 // Focus traversal on a regular page.
442 // Note that this test relies on a notification from the renderer that the 450 // Note that this test relies on a notification from the renderer that the
443 // focus has changed in the page. The notification in the renderer may change 451 // focus has changed in the page. The notification in the renderer may change
444 // at which point this test would fail (see comment in 452 // at which point this test would fail (see comment in
445 // RenderWidget::didFocus()). 453 // RenderWidget::didFocus()).
446 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) { 454 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) {
447 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 455 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
448 ASSERT_TRUE(test_server()->Start()); 456 ASSERT_TRUE(test_server()->Start());
449 457
450 // First we navigate to our test page. 458 // First we navigate to our test page.
451 GURL url = test_server()->GetURL(kTypicalPage); 459 GURL url = test_server()->GetURL(kTypicalPage);
452 ui_test_utils::NavigateToURL(browser(), url); 460 ui_test_utils::NavigateToURL(browser(), url);
453 461
454 browser()->FocusLocationBar(); 462 browser()->FocusLocationBar();
455 463
456 const char* kTextElementID = "textEdit"; 464 const char* kTextElementID = "textEdit";
457 const char* kExpElementIDs[] = { 465 const char* kExpElementIDs[] = {
458 "", // Initially no element in the page should be focused 466 "", // Initially no element in the page should be focused
459 // (the location bar is focused). 467 // (the location bar is focused).
460 kTextElementID, "searchButton", "luckyButton", "googleLink", "gmailLink", 468 kTextElementID, "searchButton", "luckyButton", "googleLink", "gmailLink",
461 "gmapLink" 469 "gmapLink"
462 }; 470 };
463 471
464 // Test forward focus traversal. 472 // Test forward focus traversal.
465 for (int i = 0; i < 3; ++i) { 473 for (int i = 0; i < 3; ++i) {
466 SCOPED_TRACE(base::StringPrintf("outer loop: %d", i)); 474 SCOPED_TRACE(base::StringPrintf("outer loop: %d", i));
467 // Location bar should be focused. 475 // Location bar should be focused.
468 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 476 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
469 477
470 // Move the caret to the end, otherwise the next Tab key may not move focus. 478 // Move the caret to the end, otherwise the next Tab key may not move focus.
471 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 479 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
472 browser(), ui::VKEY_END, false, false, false, false)); 480 browser(), ui::VKEY_END, false, false, false, false));
473 481
474 // Now let's press tab to move the focus. 482 // Now let's press tab to move the focus.
475 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { 483 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) {
476 SCOPED_TRACE(base::StringPrintf("inner loop %" PRIuS, j)); 484 SCOPED_TRACE(base::StringPrintf("inner loop %" PRIuS, j));
477 // Let's make sure the focus is on the expected element in the page. 485 // Let's make sure the focus is on the expected element in the page.
478 std::string actual; 486 std::string actual;
(...skipping 29 matching lines...) Expand all
508 // At this point the renderer has sent us a message asking to advance the 516 // At this point the renderer has sent us a message asking to advance the
509 // focus (as the end of the focus loop was reached in the renderer). 517 // focus (as the end of the focus loop was reached in the renderer).
510 // We need to run the message loop to process it. 518 // We need to run the message loop to process it.
511 ui_test_utils::RunAllPendingInMessageLoop(); 519 ui_test_utils::RunAllPendingInMessageLoop();
512 } 520 }
513 521
514 // Now let's try reverse focus traversal. 522 // Now let's try reverse focus traversal.
515 for (int i = 0; i < 3; ++i) { 523 for (int i = 0; i < 3; ++i) {
516 SCOPED_TRACE(base::StringPrintf("outer loop: %d", i)); 524 SCOPED_TRACE(base::StringPrintf("outer loop: %d", i));
517 // Location bar should be focused. 525 // Location bar should be focused.
518 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 526 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
519 527
520 // Move the caret to the end, otherwise the next Tab key may not move focus. 528 // Move the caret to the end, otherwise the next Tab key may not move focus.
521 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 529 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
522 browser(), ui::VKEY_END, false, false, false, false)); 530 browser(), ui::VKEY_END, false, false, false, false));
523 531
524 // Now let's press shift-tab to move the focus in reverse. 532 // Now let's press shift-tab to move the focus in reverse.
525 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { 533 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) {
526 SCOPED_TRACE(base::StringPrintf("inner loop: %" PRIuS, j)); 534 SCOPED_TRACE(base::StringPrintf("inner loop: %" PRIuS, j));
527 const char* next_element = 535 const char* next_element =
528 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j]; 536 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j];
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 const char* kExpElementIDs[] = { 600 const char* kExpElementIDs[] = {
593 "", // Initially no element in the page should be focused 601 "", // Initially no element in the page should be focused
594 // (the location bar is focused). 602 // (the location bar is focused).
595 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", 603 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink",
596 "gmapLink" 604 "gmapLink"
597 }; 605 };
598 606
599 // Test forward focus traversal. 607 // Test forward focus traversal.
600 for (int i = 0; i < 2; ++i) { 608 for (int i = 0; i < 2; ++i) {
601 // Location bar should be focused. 609 // Location bar should be focused.
602 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 610 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
603 611
604 // Move the caret to the end, otherwise the next Tab key may not move focus. 612 // Move the caret to the end, otherwise the next Tab key may not move focus.
605 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 613 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
606 browser(), ui::VKEY_END, false, false, false, false)); 614 browser(), ui::VKEY_END, false, false, false, false));
607 615
608 // Now let's press tab to move the focus. 616 // Now let's press tab to move the focus.
609 for (size_t j = 0; j < 7; ++j) { 617 for (size_t j = 0; j < 7; ++j) {
610 // Let's make sure the focus is on the expected element in the page. 618 // Let's make sure the focus is on the expected element in the page.
611 std::string actual; 619 std::string actual;
612 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 620 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
(...skipping 22 matching lines...) Expand all
635 643
636 // At this point the renderer has sent us a message asking to advance the 644 // At this point the renderer has sent us a message asking to advance the
637 // focus (as the end of the focus loop was reached in the renderer). 645 // focus (as the end of the focus loop was reached in the renderer).
638 // We need to run the message loop to process it. 646 // We need to run the message loop to process it.
639 ui_test_utils::RunAllPendingInMessageLoop(); 647 ui_test_utils::RunAllPendingInMessageLoop();
640 } 648 }
641 649
642 // Now let's try reverse focus traversal. 650 // Now let's try reverse focus traversal.
643 for (int i = 0; i < 2; ++i) { 651 for (int i = 0; i < 2; ++i) {
644 // Location bar should be focused. 652 // Location bar should be focused.
645 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 653 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
646 654
647 // Move the caret to the end, otherwise the next Tab key may not move focus. 655 // Move the caret to the end, otherwise the next Tab key may not move focus.
648 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 656 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
649 browser(), ui::VKEY_END, false, false, false, false)); 657 browser(), ui::VKEY_END, false, false, false, false));
650 658
651 // Now let's press shift-tab to move the focus in reverse. 659 // Now let's press shift-tab to move the focus in reverse.
652 for (size_t j = 0; j < 7; ++j) { 660 for (size_t j = 0; j < 7; ++j) {
653 int notification_type; 661 int notification_type;
654 content::NotificationSource notification_source = 662 content::NotificationSource notification_source =
655 content::NotificationService::AllSources(); 663 content::NotificationService::AllSources();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 // could create a RenderViewHostDelegate wrapper and hook-it up by either: 764 // could create a RenderViewHostDelegate wrapper and hook-it up by either:
757 // - creating a factory used to create the delegate 765 // - creating a factory used to create the delegate
758 // - making the test a private and overwriting the delegate member directly. 766 // - making the test a private and overwriting the delegate member directly.
759 MessageLoop::current()->PostDelayedTask( 767 MessageLoop::current()->PostDelayedTask(
760 FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs); 768 FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs);
761 ui_test_utils::RunMessageLoop(); 769 ui_test_utils::RunMessageLoop();
762 770
763 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 771 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
764 772
765 browser()->FocusLocationBar(); 773 browser()->FocusLocationBar();
766 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 774 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
767 775
768 // Now press Ctrl+F again and focus should move to the Find box. 776 // Now press Ctrl+F again and focus should move to the Find box.
769 #if defined(OS_MACOSX) 777 #if defined(OS_MACOSX)
770 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 778 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
771 browser(), ui::VKEY_F, false, false, false, true)); 779 browser(), ui::VKEY_F, false, false, false, true));
772 #else 780 #else
773 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 781 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
774 browser(), ui::VKEY_F, true, false, false, false)); 782 browser(), ui::VKEY_F, true, false, false, false));
775 #endif 783 #endif
776 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 784 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
(...skipping 27 matching lines...) Expand all
804 // Open the history tab, focus should be on the tab contents. 812 // Open the history tab, focus should be on the tab contents.
805 browser()->ShowHistoryTab(); 813 browser()->ShowHistoryTab();
806 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( 814 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop(
807 browser()->GetSelectedTabContents())); 815 browser()->GetSelectedTabContents()));
808 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 816 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
809 817
810 // Open the new tab, focus should be on the location bar. 818 // Open the new tab, focus should be on the location bar.
811 browser()->NewTab(); 819 browser()->NewTab();
812 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( 820 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop(
813 browser()->GetSelectedTabContents())); 821 browser()->GetSelectedTabContents()));
814 EXPECT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 822 EXPECT_TRUE(IsViewFocused(location_bar_focus_view_id_));
815 823
816 // Open the download tab, focus should be on the tab contents. 824 // Open the download tab, focus should be on the tab contents.
817 browser()->ShowDownloadsTab(); 825 browser()->ShowDownloadsTab();
818 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( 826 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop(
819 browser()->GetSelectedTabContents())); 827 browser()->GetSelectedTabContents()));
820 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 828 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
821 829
822 // Open about:blank, focus should be on the location bar. 830 // Open about:blank, focus should be on the location bar.
823 browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), 831 browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL),
824 content::PAGE_TRANSITION_LINK); 832 content::PAGE_TRANSITION_LINK);
825 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( 833 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop(
826 browser()->GetSelectedTabContents())); 834 browser()->GetSelectedTabContents()));
827 EXPECT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 835 EXPECT_TRUE(IsViewFocused(location_bar_focus_view_id_));
828 } 836 }
829 837
830 // Tests that focus goes where expected when using reload. 838 // Tests that focus goes where expected when using reload.
831 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { 839 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) {
832 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 840 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
833 ASSERT_TRUE(test_server()->Start()); 841 ASSERT_TRUE(test_server()->Start());
834 842
835 // Open the new tab, reload. 843 // Open the new tab, reload.
836 { 844 {
837 ui_test_utils::WindowedNotificationObserver observer( 845 ui_test_utils::WindowedNotificationObserver observer(
838 content::NOTIFICATION_LOAD_STOP, 846 content::NOTIFICATION_LOAD_STOP,
839 content::NotificationService::AllSources()); 847 content::NotificationService::AllSources());
840 browser()->NewTab(); 848 browser()->NewTab();
841 observer.Wait(); 849 observer.Wait();
842 } 850 }
843 ui_test_utils::RunAllPendingInMessageLoop(); 851 ui_test_utils::RunAllPendingInMessageLoop();
844 852
845 { 853 {
846 ui_test_utils::WindowedNotificationObserver observer( 854 ui_test_utils::WindowedNotificationObserver observer(
847 content::NOTIFICATION_LOAD_STOP, 855 content::NOTIFICATION_LOAD_STOP,
848 content::Source<NavigationController>( 856 content::Source<NavigationController>(
849 &browser()->GetSelectedTabContentsWrapper()->controller())); 857 &browser()->GetSelectedTabContentsWrapper()->controller()));
850 browser()->Reload(CURRENT_TAB); 858 browser()->Reload(CURRENT_TAB);
851 observer.Wait(); 859 observer.Wait();
852 } 860 }
853 // Focus should stay on the location bar. 861 // Focus should stay on the location bar.
854 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 862 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
855 863
856 // Open a regular page, focus the location bar, reload. 864 // Open a regular page, focus the location bar, reload.
857 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); 865 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage));
858 browser()->FocusLocationBar(); 866 browser()->FocusLocationBar();
859 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 867 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
860 { 868 {
861 ui_test_utils::WindowedNotificationObserver observer( 869 ui_test_utils::WindowedNotificationObserver observer(
862 content::NOTIFICATION_LOAD_STOP, 870 content::NOTIFICATION_LOAD_STOP,
863 content::Source<NavigationController>( 871 content::Source<NavigationController>(
864 &browser()->GetSelectedTabContentsWrapper()->controller())); 872 &browser()->GetSelectedTabContentsWrapper()->controller()));
865 browser()->Reload(CURRENT_TAB); 873 browser()->Reload(CURRENT_TAB);
866 observer.Wait(); 874 observer.Wait();
867 } 875 }
868 876
869 // Focus should now be on the tab contents. 877 // Focus should now be on the tab contents.
(...skipping 17 matching lines...) Expand all
887 browser()->Reload(CURRENT_TAB); 895 browser()->Reload(CURRENT_TAB);
888 observer.Wait(); 896 observer.Wait();
889 } 897 }
890 898
891 // Focus should now be on the tab contents. 899 // Focus should now be on the tab contents.
892 browser()->ShowDownloadsTab(); 900 browser()->ShowDownloadsTab();
893 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 901 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
894 } 902 }
895 903
896 } // namespace 904 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browser_keyevents_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698