OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 17 #include "chrome/browser/ui/browser_tabstrip.h" |
17 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
18 #include "chrome/browser/ui/chrome_pages.h" | 19 #include "chrome/browser/ui/chrome_pages.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/browser/ui/view_ids.h" | 22 #include "chrome/browser/ui/view_ids.h" |
22 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
25 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
26 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // Disabled, http://crbug.com/62542. | 319 // Disabled, http://crbug.com/62542. |
319 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { | 320 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { |
320 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 321 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
321 ASSERT_TRUE(test_server()->Start()); | 322 ASSERT_TRUE(test_server()->Start()); |
322 | 323 |
323 // First we navigate to our test page. | 324 // First we navigate to our test page. |
324 GURL url = test_server()->GetURL(kSimplePage); | 325 GURL url = test_server()->GetURL(kSimplePage); |
325 ui_test_utils::NavigateToURL(browser(), url); | 326 ui_test_utils::NavigateToURL(browser(), url); |
326 | 327 |
327 // Create several tabs. | 328 // Create several tabs. |
328 for (int i = 0; i < 4; ++i) | 329 for (int i = 0; i < 4; ++i) { |
329 browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); | 330 chrome::AddSelectedTabWithURL(browser(), url, |
| 331 content::PAGE_TRANSITION_TYPED); |
| 332 } |
330 | 333 |
331 // Alternate focus for the tab. | 334 // Alternate focus for the tab. |
332 const bool kFocusPage[3][5] = { | 335 const bool kFocusPage[3][5] = { |
333 { true, true, true, true, false }, | 336 { true, true, true, true, false }, |
334 { false, false, false, false, false }, | 337 { false, false, false, false, false }, |
335 { false, true, false, true, false } | 338 { false, true, false, true, false } |
336 }; | 339 }; |
337 | 340 |
338 for (int i = 1; i < 3; i++) { | 341 for (int i = 1; i < 3; i++) { |
339 for (int j = 0; j < 5; j++) { | 342 for (int j = 0; j < 5; j++) { |
340 // Activate the tab. | 343 // Activate the tab. |
341 browser()->ActivateTabAt(j, true); | 344 chrome::ActivateTabAt(browser(), j, true); |
342 | 345 |
343 // Activate the location bar or the page. | 346 // Activate the location bar or the page. |
344 if (kFocusPage[i][j]) { | 347 if (kFocusPage[i][j]) { |
345 browser()->GetWebContentsAt(j)->GetView()->Focus(); | 348 chrome::GetWebContentsAt(browser(), j)->GetView()->Focus(); |
346 } else { | 349 } else { |
347 chrome::FocusLocationBar(browser()); | 350 chrome::FocusLocationBar(browser()); |
348 } | 351 } |
349 } | 352 } |
350 | 353 |
351 // Now come back to the tab and check the right view is focused. | 354 // Now come back to the tab and check the right view is focused. |
352 for (int j = 0; j < 5; j++) { | 355 for (int j = 0; j < 5; j++) { |
353 // Activate the tab. | 356 // Activate the tab. |
354 browser()->ActivateTabAt(j, true); | 357 chrome::ActivateTabAt(browser(), j, true); |
355 | 358 |
356 ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER : | 359 ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER : |
357 location_bar_focus_view_id_; | 360 location_bar_focus_view_id_; |
358 ASSERT_TRUE(IsViewFocused(vid)); | 361 ASSERT_TRUE(IsViewFocused(vid)); |
359 } | 362 } |
360 | 363 |
361 browser()->ActivateTabAt(0, true); | 364 chrome::ActivateTabAt(browser(), 0, true); |
362 // Try the above, but with ctrl+tab. Since tab normally changes focus, | 365 // Try the above, but with ctrl+tab. Since tab normally changes focus, |
363 // this has regressed in the past. Loop through several times to be sure. | 366 // this has regressed in the past. Loop through several times to be sure. |
364 for (int j = 0; j < 15; j++) { | 367 for (int j = 0; j < 15; j++) { |
365 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER : | 368 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER : |
366 location_bar_focus_view_id_; | 369 location_bar_focus_view_id_; |
367 ASSERT_TRUE(IsViewFocused(vid)); | 370 ASSERT_TRUE(IsViewFocused(vid)); |
368 | 371 |
369 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 372 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
370 browser(), ui::VKEY_TAB, true, false, false, false)); | 373 browser(), ui::VKEY_TAB, true, false, false, false)); |
371 } | 374 } |
372 | 375 |
373 // As above, but with ctrl+shift+tab. | 376 // As above, but with ctrl+shift+tab. |
374 browser()->ActivateTabAt(4, true); | 377 chrome::ActivateTabAt(browser(), 4, true); |
375 for (int j = 14; j >= 0; --j) { | 378 for (int j = 14; j >= 0; --j) { |
376 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER : | 379 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER : |
377 location_bar_focus_view_id_; | 380 location_bar_focus_view_id_; |
378 ASSERT_TRUE(IsViewFocused(vid)); | 381 ASSERT_TRUE(IsViewFocused(vid)); |
379 | 382 |
380 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 383 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
381 browser(), ui::VKEY_TAB, true, true, false, false)); | 384 browser(), ui::VKEY_TAB, true, true, false, false)); |
382 } | 385 } |
383 } | 386 } |
384 } | 387 } |
385 | 388 |
386 // Tabs remember focus with find-in-page box. | 389 // Tabs remember focus with find-in-page box. |
387 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { | 390 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { |
388 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 391 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
389 ASSERT_TRUE(test_server()->Start()); | 392 ASSERT_TRUE(test_server()->Start()); |
390 | 393 |
391 // First we navigate to our test page. | 394 // First we navigate to our test page. |
392 GURL url = test_server()->GetURL(kSimplePage); | 395 GURL url = test_server()->GetURL(kSimplePage); |
393 ui_test_utils::NavigateToURL(browser(), url); | 396 ui_test_utils::NavigateToURL(browser(), url); |
394 | 397 |
395 chrome::Find(browser()); | 398 chrome::Find(browser()); |
396 ui_test_utils::FindInPage(browser()->GetActiveTabContents(), | 399 ui_test_utils::FindInPage(chrome::GetActiveTabContents(browser()), |
397 ASCIIToUTF16("a"), true, false, NULL); | 400 ASCIIToUTF16("a"), true, false, NULL); |
398 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 401 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
399 | 402 |
400 // Focus the location bar. | 403 // Focus the location bar. |
401 chrome::FocusLocationBar(browser()); | 404 chrome::FocusLocationBar(browser()); |
402 | 405 |
403 // Create a 2nd tab. | 406 // Create a 2nd tab. |
404 browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); | 407 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED); |
405 | 408 |
406 // Focus should be on the recently opened tab page. | 409 // Focus should be on the recently opened tab page. |
407 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 410 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
408 | 411 |
409 // Select 1st tab, focus should still be on the location-bar. | 412 // Select 1st tab, focus should still be on the location-bar. |
410 // (bug http://crbug.com/23296) | 413 // (bug http://crbug.com/23296) |
411 browser()->ActivateTabAt(0, true); | 414 chrome::ActivateTabAt(browser(), 0, true); |
412 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); | 415 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
413 | 416 |
414 // Now open the find box again, switch to another tab and come back, the focus | 417 // Now open the find box again, switch to another tab and come back, the focus |
415 // should return to the find box. | 418 // should return to the find box. |
416 chrome::Find(browser()); | 419 chrome::Find(browser()); |
417 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 420 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
418 browser()->ActivateTabAt(1, true); | 421 chrome::ActivateTabAt(browser(), 1, true); |
419 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 422 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
420 browser()->ActivateTabAt(0, true); | 423 chrome::ActivateTabAt(browser(), 0, true); |
421 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 424 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
422 } | 425 } |
423 | 426 |
424 // Background window does not steal focus. | 427 // Background window does not steal focus. |
425 // Flaky, http://crbug.com/62538. | 428 // Flaky, http://crbug.com/62538. |
426 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, | 429 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, |
427 DISABLED_BackgroundBrowserDontStealFocus) { | 430 DISABLED_BackgroundBrowserDontStealFocus) { |
428 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 431 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
429 ASSERT_TRUE(test_server()->Start()); | 432 ASSERT_TRUE(test_server()->Start()); |
430 | 433 |
(...skipping 26 matching lines...) Expand all Loading... |
457 unfocused_browser = browser(); | 460 unfocused_browser = browser(); |
458 #endif | 461 #endif |
459 | 462 |
460 GURL steal_focus_url = test_server()->GetURL(kStealFocusPage); | 463 GURL steal_focus_url = test_server()->GetURL(kStealFocusPage); |
461 ui_test_utils::NavigateToURL(unfocused_browser, steal_focus_url); | 464 ui_test_utils::NavigateToURL(unfocused_browser, steal_focus_url); |
462 | 465 |
463 // Activate the first browser. | 466 // Activate the first browser. |
464 focused_browser->window()->Activate(); | 467 focused_browser->window()->Activate(); |
465 | 468 |
466 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 469 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
467 unfocused_browser->GetActiveWebContents()->GetRenderViewHost(), L"", | 470 chrome::GetActiveWebContents(unfocused_browser)->GetRenderViewHost(), L"", |
468 L"stealFocus();")); | 471 L"stealFocus();")); |
469 | 472 |
470 // Make sure the first browser is still active. | 473 // Make sure the first browser is still active. |
471 EXPECT_TRUE(focused_browser->window()->IsActive()); | 474 EXPECT_TRUE(focused_browser->window()->IsActive()); |
472 } | 475 } |
473 | 476 |
474 // Page cannot steal focus when focus is on location bar. | 477 // Page cannot steal focus when focus is on location bar. |
475 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { | 478 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { |
476 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 479 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
477 ASSERT_TRUE(test_server()->Start()); | 480 ASSERT_TRUE(test_server()->Start()); |
478 | 481 |
479 // Open the page that steals focus. | 482 // Open the page that steals focus. |
480 GURL url = test_server()->GetURL(kStealFocusPage); | 483 GURL url = test_server()->GetURL(kStealFocusPage); |
481 ui_test_utils::NavigateToURL(browser(), url); | 484 ui_test_utils::NavigateToURL(browser(), url); |
482 | 485 |
483 chrome::FocusLocationBar(browser()); | 486 chrome::FocusLocationBar(browser()); |
484 | 487 |
485 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 488 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
486 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", | 489 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
487 L"stealFocus();")); | 490 L"stealFocus();")); |
488 | 491 |
489 // Make sure the location bar is still focused. | 492 // Make sure the location bar is still focused. |
490 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); | 493 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
491 } | 494 } |
492 | 495 |
493 // Focus traversal on a regular page. | 496 // Focus traversal on a regular page. |
494 // Note that this test relies on a notification from the renderer that the | 497 // Note that this test relies on a notification from the renderer that the |
495 // focus has changed in the page. The notification in the renderer may change | 498 // focus has changed in the page. The notification in the renderer may change |
496 // at which point this test would fail (see comment in | 499 // at which point this test would fail (see comment in |
(...skipping 25 matching lines...) Expand all Loading... |
522 // Move the caret to the end, otherwise the next Tab key may not move focus. | 525 // Move the caret to the end, otherwise the next Tab key may not move focus. |
523 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 526 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
524 browser(), ui::VKEY_END, false, false, false, false)); | 527 browser(), ui::VKEY_END, false, false, false, false)); |
525 | 528 |
526 // Now let's press tab to move the focus. | 529 // Now let's press tab to move the focus. |
527 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { | 530 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { |
528 SCOPED_TRACE(base::StringPrintf("inner loop %" PRIuS, j)); | 531 SCOPED_TRACE(base::StringPrintf("inner loop %" PRIuS, j)); |
529 // Let's make sure the focus is on the expected element in the page. | 532 // Let's make sure the focus is on the expected element in the page. |
530 std::string actual; | 533 std::string actual; |
531 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 534 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
532 browser()->GetActiveWebContents()->GetRenderViewHost(), | 535 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
533 L"", | 536 L"", |
534 L"window.domAutomationController.send(getFocusedElement());", | 537 L"window.domAutomationController.send(getFocusedElement());", |
535 &actual)); | 538 &actual)); |
536 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); | 539 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
537 | 540 |
538 if (j < arraysize(kExpElementIDs) - 1) { | 541 if (j < arraysize(kExpElementIDs) - 1) { |
539 // If the next element is the kTextElementID, we expect to be | 542 // If the next element is the kTextElementID, we expect to be |
540 // notified we have switched to an editable node. | 543 // notified we have switched to an editable node. |
541 bool is_editable_node = | 544 bool is_editable_node = |
542 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); | 545 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); |
543 content::Details<bool> details(&is_editable_node); | 546 content::Details<bool> details(&is_editable_node); |
544 | 547 |
545 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( | 548 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
546 browser(), ui::VKEY_TAB, false, false, false, false, | 549 browser(), ui::VKEY_TAB, false, false, false, false, |
547 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 550 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
548 content::NotificationSource(content::Source<RenderViewHost>( | 551 content::NotificationSource(content::Source<RenderViewHost>( |
549 browser()->GetActiveWebContents()->GetRenderViewHost())), | 552 chrome::GetActiveWebContents(browser())->GetRenderViewHost())), |
550 details)); | 553 details)); |
551 } else { | 554 } else { |
552 // On the last tab key press, the focus returns to the browser. | 555 // On the last tab key press, the focus returns to the browser. |
553 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 556 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
554 browser(), ui::VKEY_TAB, false, false, false, false, | 557 browser(), ui::VKEY_TAB, false, false, false, false, |
555 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, | 558 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
556 content::NotificationSource(content::Source<Browser>(browser())))); | 559 content::NotificationSource(content::Source<Browser>(browser())))); |
557 } | 560 } |
558 } | 561 } |
559 | 562 |
(...skipping 22 matching lines...) Expand all Loading... |
582 if (j < arraysize(kExpElementIDs) - 1) { | 585 if (j < arraysize(kExpElementIDs) - 1) { |
583 // If the next element is the kTextElementID, we expect to be | 586 // If the next element is the kTextElementID, we expect to be |
584 // notified we have switched to an editable node. | 587 // notified we have switched to an editable node. |
585 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); | 588 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); |
586 content::Details<bool> details(&is_editable_node); | 589 content::Details<bool> details(&is_editable_node); |
587 | 590 |
588 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( | 591 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
589 browser(), ui::VKEY_TAB, false, true, false, false, | 592 browser(), ui::VKEY_TAB, false, true, false, false, |
590 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 593 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
591 content::NotificationSource(content::Source<RenderViewHost>( | 594 content::NotificationSource(content::Source<RenderViewHost>( |
592 browser()->GetActiveWebContents()->GetRenderViewHost())), | 595 chrome::GetActiveWebContents(browser())->GetRenderViewHost())), |
593 details)); | 596 details)); |
594 } else { | 597 } else { |
595 // On the last tab key press, the focus returns to the browser. | 598 // On the last tab key press, the focus returns to the browser. |
596 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 599 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
597 browser(), ui::VKEY_TAB, false, true, false, false, | 600 browser(), ui::VKEY_TAB, false, true, false, false, |
598 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, | 601 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
599 content::NotificationSource(content::Source<Browser>(browser())))); | 602 content::NotificationSource(content::Source<Browser>(browser())))); |
600 } | 603 } |
601 | 604 |
602 // Let's make sure the focus is on the expected element in the page. | 605 // Let's make sure the focus is on the expected element in the page. |
603 std::string actual; | 606 std::string actual; |
604 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 607 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
605 browser()->GetActiveWebContents()->GetRenderViewHost(), | 608 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
606 L"", | 609 L"", |
607 L"window.domAutomationController.send(getFocusedElement());", | 610 L"window.domAutomationController.send(getFocusedElement());", |
608 &actual)); | 611 &actual)); |
609 ASSERT_STREQ(next_element, actual.c_str()); | 612 ASSERT_STREQ(next_element, actual.c_str()); |
610 } | 613 } |
611 | 614 |
612 // At this point the renderer has sent us a message asking to advance the | 615 // At this point the renderer has sent us a message asking to advance the |
613 // focus (as the end of the focus loop was reached in the renderer). | 616 // focus (as the end of the focus loop was reached in the renderer). |
614 // We need to run the message loop to process it. | 617 // We need to run the message loop to process it. |
615 ui_test_utils::RunAllPendingInMessageLoop(); | 618 ui_test_utils::RunAllPendingInMessageLoop(); |
616 } | 619 } |
617 } | 620 } |
618 | 621 |
619 // Focus traversal while an interstitial is showing. | 622 // Focus traversal while an interstitial is showing. |
620 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { | 623 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { |
621 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 624 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
622 ASSERT_TRUE(test_server()->Start()); | 625 ASSERT_TRUE(test_server()->Start()); |
623 | 626 |
624 // First we navigate to our test page. | 627 // First we navigate to our test page. |
625 GURL url = test_server()->GetURL(kSimplePage); | 628 GURL url = test_server()->GetURL(kSimplePage); |
626 ui_test_utils::NavigateToURL(browser(), url); | 629 ui_test_utils::NavigateToURL(browser(), url); |
627 | 630 |
628 // Focus should be on the page. | 631 // Focus should be on the page. |
629 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 632 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
630 | 633 |
631 // Let's show an interstitial. | 634 // Let's show an interstitial. |
632 TestInterstitialPage* interstitial_page = | 635 TestInterstitialPage* interstitial_page = |
633 new TestInterstitialPage(browser()->GetActiveWebContents(), | 636 new TestInterstitialPage(chrome::GetActiveWebContents(browser()), |
634 true, GURL("http://interstitial.com")); | 637 true, GURL("http://interstitial.com")); |
635 // Give some time for the interstitial to show. | 638 // Give some time for the interstitial to show. |
636 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 639 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
637 MessageLoop::QuitClosure(), | 640 MessageLoop::QuitClosure(), |
638 base::TimeDelta::FromSeconds(1)); | 641 base::TimeDelta::FromSeconds(1)); |
639 ui_test_utils::RunMessageLoop(); | 642 ui_test_utils::RunMessageLoop(); |
640 | 643 |
641 chrome::FocusLocationBar(browser()); | 644 chrome::FocusLocationBar(browser()); |
642 | 645 |
643 const char* kExpElementIDs[] = { | 646 const char* kExpElementIDs[] = { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 #endif | 746 #endif |
744 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 747 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
745 ASSERT_TRUE(test_server()->Start()); | 748 ASSERT_TRUE(test_server()->Start()); |
746 | 749 |
747 // First we navigate to our test page. | 750 // First we navigate to our test page. |
748 GURL url = test_server()->GetURL(kSimplePage); | 751 GURL url = test_server()->GetURL(kSimplePage); |
749 ui_test_utils::NavigateToURL(browser(), url); | 752 ui_test_utils::NavigateToURL(browser(), url); |
750 | 753 |
751 // Page should have focus. | 754 // Page should have focus. |
752 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 755 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
753 EXPECT_TRUE(browser()->GetActiveWebContents()->GetRenderViewHost()-> | 756 EXPECT_TRUE(chrome::GetActiveWebContents(browser())->GetRenderViewHost()-> |
754 GetView()->HasFocus()); | 757 GetView()->HasFocus()); |
755 | 758 |
756 // Let's show an interstitial. | 759 // Let's show an interstitial. |
757 TestInterstitialPage* interstitial_page = | 760 TestInterstitialPage* interstitial_page = |
758 new TestInterstitialPage(browser()->GetActiveWebContents(), | 761 new TestInterstitialPage(chrome::GetActiveWebContents(browser()), |
759 true, GURL("http://interstitial.com")); | 762 true, GURL("http://interstitial.com")); |
760 // Give some time for the interstitial to show. | 763 // Give some time for the interstitial to show. |
761 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 764 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
762 MessageLoop::QuitClosure(), | 765 MessageLoop::QuitClosure(), |
763 base::TimeDelta::FromSeconds(1)); | 766 base::TimeDelta::FromSeconds(1)); |
764 ui_test_utils::RunMessageLoop(); | 767 ui_test_utils::RunMessageLoop(); |
765 | 768 |
766 // The interstitial should have focus now. | 769 // The interstitial should have focus now. |
767 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 770 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
768 EXPECT_TRUE(interstitial_page->HasFocus()); | 771 EXPECT_TRUE(interstitial_page->HasFocus()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 | 837 |
835 // Makes sure the focus is in the right location when opening the different | 838 // Makes sure the focus is in the right location when opening the different |
836 // types of tabs. | 839 // types of tabs. |
837 // Flaky, http://crbug.com/62539. | 840 // Flaky, http://crbug.com/62539. |
838 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabInitialFocus) { | 841 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabInitialFocus) { |
839 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 842 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
840 | 843 |
841 // Open the history tab, focus should be on the tab contents. | 844 // Open the history tab, focus should be on the tab contents. |
842 chrome::ShowHistory(browser()); | 845 chrome::ShowHistory(browser()); |
843 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( | 846 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( |
844 browser()->GetActiveWebContents())); | 847 chrome::GetActiveWebContents(browser()))); |
845 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 848 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
846 | 849 |
847 // Open the new tab, focus should be on the location bar. | 850 // Open the new tab, focus should be on the location bar. |
848 chrome::NewTab(browser()); | 851 chrome::NewTab(browser()); |
849 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( | 852 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( |
850 browser()->GetActiveWebContents())); | 853 chrome::GetActiveWebContents(browser()))); |
851 EXPECT_TRUE(IsViewFocused(location_bar_focus_view_id_)); | 854 EXPECT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
852 | 855 |
853 // Open the download tab, focus should be on the tab contents. | 856 // Open the download tab, focus should be on the tab contents. |
854 chrome::ShowDownloads(browser()); | 857 chrome::ShowDownloads(browser()); |
855 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( | 858 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( |
856 browser()->GetActiveWebContents())); | 859 chrome::GetActiveWebContents(browser()))); |
857 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 860 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
858 | 861 |
859 // Open about:blank, focus should be on the location bar. | 862 // Open about:blank, focus should be on the location bar. |
860 browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), | 863 chrome::AddSelectedTabWithURL(browser(), GURL(chrome::kAboutBlankURL), |
861 content::PAGE_TRANSITION_LINK); | 864 content::PAGE_TRANSITION_LINK); |
862 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( | 865 ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( |
863 browser()->GetActiveWebContents())); | 866 chrome::GetActiveWebContents(browser()))); |
864 EXPECT_TRUE(IsViewFocused(location_bar_focus_view_id_)); | 867 EXPECT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
865 } | 868 } |
866 | 869 |
867 // Tests that focus goes where expected when using reload. | 870 // Tests that focus goes where expected when using reload. |
868 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { | 871 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { |
869 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 872 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
870 ASSERT_TRUE(test_server()->Start()); | 873 ASSERT_TRUE(test_server()->Start()); |
871 | 874 |
872 // Open the new tab, reload. | 875 // Open the new tab, reload. |
873 { | 876 { |
874 ui_test_utils::WindowedNotificationObserver observer( | 877 ui_test_utils::WindowedNotificationObserver observer( |
875 content::NOTIFICATION_LOAD_STOP, | 878 content::NOTIFICATION_LOAD_STOP, |
876 content::NotificationService::AllSources()); | 879 content::NotificationService::AllSources()); |
877 chrome::NewTab(browser()); | 880 chrome::NewTab(browser()); |
878 observer.Wait(); | 881 observer.Wait(); |
879 } | 882 } |
880 ui_test_utils::RunAllPendingInMessageLoop(); | 883 ui_test_utils::RunAllPendingInMessageLoop(); |
881 | 884 |
882 { | 885 { |
883 ui_test_utils::WindowedNotificationObserver observer( | 886 ui_test_utils::WindowedNotificationObserver observer( |
884 content::NOTIFICATION_LOAD_STOP, | 887 content::NOTIFICATION_LOAD_STOP, |
885 content::Source<NavigationController>( | 888 content::Source<NavigationController>( |
886 &browser()->GetActiveWebContents()->GetController())); | 889 &chrome::GetActiveWebContents(browser())->GetController())); |
887 chrome::Reload(browser(), CURRENT_TAB); | 890 chrome::Reload(browser(), CURRENT_TAB); |
888 observer.Wait(); | 891 observer.Wait(); |
889 } | 892 } |
890 // Focus should stay on the location bar. | 893 // Focus should stay on the location bar. |
891 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); | 894 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
892 | 895 |
893 // Open a regular page, focus the location bar, reload. | 896 // Open a regular page, focus the location bar, reload. |
894 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); | 897 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); |
895 chrome::FocusLocationBar(browser()); | 898 chrome::FocusLocationBar(browser()); |
896 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); | 899 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
897 { | 900 { |
898 ui_test_utils::WindowedNotificationObserver observer( | 901 ui_test_utils::WindowedNotificationObserver observer( |
899 content::NOTIFICATION_LOAD_STOP, | 902 content::NOTIFICATION_LOAD_STOP, |
900 content::Source<NavigationController>( | 903 content::Source<NavigationController>( |
901 &browser()->GetActiveWebContents()->GetController())); | 904 &chrome::GetActiveWebContents(browser())->GetController())); |
902 chrome::Reload(browser(), CURRENT_TAB); | 905 chrome::Reload(browser(), CURRENT_TAB); |
903 observer.Wait(); | 906 observer.Wait(); |
904 } | 907 } |
905 | 908 |
906 // Focus should now be on the tab contents. | 909 // Focus should now be on the tab contents. |
907 chrome::ShowDownloads(browser()); | 910 chrome::ShowDownloads(browser()); |
908 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 911 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
909 } | 912 } |
910 | 913 |
911 // Tests that focus goes where expected when using reload on a crashed tab. | 914 // Tests that focus goes where expected when using reload on a crashed tab. |
912 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) { | 915 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) { |
913 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 916 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
914 ASSERT_TRUE(test_server()->Start()); | 917 ASSERT_TRUE(test_server()->Start()); |
915 | 918 |
916 // Open a regular page, crash, reload. | 919 // Open a regular page, crash, reload. |
917 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); | 920 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); |
918 ui_test_utils::CrashTab(browser()->GetActiveWebContents()); | 921 ui_test_utils::CrashTab(chrome::GetActiveWebContents(browser())); |
919 { | 922 { |
920 ui_test_utils::WindowedNotificationObserver observer( | 923 ui_test_utils::WindowedNotificationObserver observer( |
921 content::NOTIFICATION_LOAD_STOP, | 924 content::NOTIFICATION_LOAD_STOP, |
922 content::Source<NavigationController>( | 925 content::Source<NavigationController>( |
923 &browser()->GetActiveWebContents()->GetController())); | 926 &chrome::GetActiveWebContents(browser())->GetController())); |
924 chrome::Reload(browser(), CURRENT_TAB); | 927 chrome::Reload(browser(), CURRENT_TAB); |
925 observer.Wait(); | 928 observer.Wait(); |
926 } | 929 } |
927 | 930 |
928 // Focus should now be on the tab contents. | 931 // Focus should now be on the tab contents. |
929 chrome::ShowDownloads(browser()); | 932 chrome::ShowDownloads(browser()); |
930 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 933 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
931 } | 934 } |
932 | 935 |
933 } // namespace | 936 } // namespace |
OLD | NEW |