| OLD | NEW |
| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 306 |
| 307 browser()->SelectTabContentsAt(0, true); | 307 browser()->SelectTabContentsAt(0, true); |
| 308 // Try the above, but with ctrl+tab. Since tab normally changes focus, | 308 // Try the above, but with ctrl+tab. Since tab normally changes focus, |
| 309 // this has regressed in the past. Loop through several times to be sure. | 309 // this has regressed in the past. Loop through several times to be sure. |
| 310 for (int j = 0; j < 15; j++) { | 310 for (int j = 0; j < 15; j++) { |
| 311 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : | 311 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : |
| 312 VIEW_ID_LOCATION_BAR; | 312 VIEW_ID_LOCATION_BAR; |
| 313 ASSERT_TRUE(IsViewFocused(vid)); | 313 ASSERT_TRUE(IsViewFocused(vid)); |
| 314 | 314 |
| 315 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 315 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 316 browser(), app::VKEY_TAB, true, false, false, false)); | 316 browser(), ui::VKEY_TAB, true, false, false, false)); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // As above, but with ctrl+shift+tab. | 319 // As above, but with ctrl+shift+tab. |
| 320 browser()->SelectTabContentsAt(4, true); | 320 browser()->SelectTabContentsAt(4, true); |
| 321 for (int j = 14; j >= 0; --j) { | 321 for (int j = 14; j >= 0; --j) { |
| 322 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : | 322 ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : |
| 323 VIEW_ID_LOCATION_BAR; | 323 VIEW_ID_LOCATION_BAR; |
| 324 ASSERT_TRUE(IsViewFocused(vid)); | 324 ASSERT_TRUE(IsViewFocused(vid)); |
| 325 | 325 |
| 326 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 326 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 327 browser(), app::VKEY_TAB, true, true, false, false)); | 327 browser(), ui::VKEY_TAB, true, true, false, false)); |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 // Tabs remember focus with find-in-page box. | 332 // Tabs remember focus with find-in-page box. |
| 333 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { | 333 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { |
| 334 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 334 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 335 ASSERT_TRUE(test_server()->Start()); | 335 ASSERT_TRUE(test_server()->Start()); |
| 336 | 336 |
| 337 // First we navigate to our test page. | 337 // First we navigate to our test page. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); | 478 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 479 | 479 |
| 480 if (j < arraysize(kExpElementIDs) - 1) { | 480 if (j < arraysize(kExpElementIDs) - 1) { |
| 481 // If the next element is the kTextElementID, we expect to be | 481 // If the next element is the kTextElementID, we expect to be |
| 482 // notified we have switched to an editable node. | 482 // notified we have switched to an editable node. |
| 483 bool is_editable_node = | 483 bool is_editable_node = |
| 484 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); | 484 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); |
| 485 Details<bool> details(&is_editable_node); | 485 Details<bool> details(&is_editable_node); |
| 486 | 486 |
| 487 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( | 487 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
| 488 browser(), app::VKEY_TAB, false, false, false, false, | 488 browser(), ui::VKEY_TAB, false, false, false, false, |
| 489 NotificationType::FOCUS_CHANGED_IN_PAGE, | 489 NotificationType::FOCUS_CHANGED_IN_PAGE, |
| 490 NotificationSource(Source<RenderViewHost>( | 490 NotificationSource(Source<RenderViewHost>( |
| 491 browser()->GetSelectedTabContents()->render_view_host())), | 491 browser()->GetSelectedTabContents()->render_view_host())), |
| 492 details)); | 492 details)); |
| 493 } else { | 493 } else { |
| 494 // On the last tab key press, the focus returns to the browser. | 494 // On the last tab key press, the focus returns to the browser. |
| 495 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 495 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 496 browser(), app::VKEY_TAB, false, false, false, false, | 496 browser(), ui::VKEY_TAB, false, false, false, false, |
| 497 NotificationType::FOCUS_RETURNED_TO_BROWSER, | 497 NotificationType::FOCUS_RETURNED_TO_BROWSER, |
| 498 NotificationSource(Source<Browser>(browser())))); | 498 NotificationSource(Source<Browser>(browser())))); |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 | 501 |
| 502 // At this point the renderer has sent us a message asking to advance the | 502 // At this point the renderer has sent us a message asking to advance the |
| 503 // focus (as the end of the focus loop was reached in the renderer). | 503 // focus (as the end of the focus loop was reached in the renderer). |
| 504 // We need to run the message loop to process it. | 504 // We need to run the message loop to process it. |
| 505 ui_test_utils::RunAllPendingInMessageLoop(); | 505 ui_test_utils::RunAllPendingInMessageLoop(); |
| 506 } | 506 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 517 const char* next_element = | 517 const char* next_element = |
| 518 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j]; | 518 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j]; |
| 519 | 519 |
| 520 if (j < arraysize(kExpElementIDs) - 1) { | 520 if (j < arraysize(kExpElementIDs) - 1) { |
| 521 // If the next element is the kTextElementID, we expect to be | 521 // If the next element is the kTextElementID, we expect to be |
| 522 // notified we have switched to an editable node. | 522 // notified we have switched to an editable node. |
| 523 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); | 523 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); |
| 524 Details<bool> details(&is_editable_node); | 524 Details<bool> details(&is_editable_node); |
| 525 | 525 |
| 526 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( | 526 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
| 527 browser(), app::VKEY_TAB, false, true, false, false, | 527 browser(), ui::VKEY_TAB, false, true, false, false, |
| 528 NotificationType::FOCUS_CHANGED_IN_PAGE, | 528 NotificationType::FOCUS_CHANGED_IN_PAGE, |
| 529 NotificationSource(Source<RenderViewHost>( | 529 NotificationSource(Source<RenderViewHost>( |
| 530 browser()->GetSelectedTabContents()->render_view_host())), | 530 browser()->GetSelectedTabContents()->render_view_host())), |
| 531 details)); | 531 details)); |
| 532 } else { | 532 } else { |
| 533 // On the last tab key press, the focus returns to the browser. | 533 // On the last tab key press, the focus returns to the browser. |
| 534 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 534 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 535 browser(), app::VKEY_TAB, false, true, false, false, | 535 browser(), ui::VKEY_TAB, false, true, false, false, |
| 536 NotificationType::FOCUS_RETURNED_TO_BROWSER, | 536 NotificationType::FOCUS_RETURNED_TO_BROWSER, |
| 537 NotificationSource(Source<Browser>(browser())))); | 537 NotificationSource(Source<Browser>(browser())))); |
| 538 } | 538 } |
| 539 | 539 |
| 540 // Let's make sure the focus is on the expected element in the page. | 540 // Let's make sure the focus is on the expected element in the page. |
| 541 std::string actual; | 541 std::string actual; |
| 542 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 542 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 543 browser()->GetSelectedTabContents()->render_view_host(), | 543 browser()->GetSelectedTabContents()->render_view_host(), |
| 544 L"", | 544 L"", |
| 545 L"window.domAutomationController.send(getFocusedElement());", | 545 L"window.domAutomationController.send(getFocusedElement());", |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; | 608 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; |
| 609 notification_source = Source<RenderViewHost>( | 609 notification_source = Source<RenderViewHost>( |
| 610 interstitial_page->render_view_host()); | 610 interstitial_page->render_view_host()); |
| 611 } else { | 611 } else { |
| 612 // On the last tab key press, the focus returns to the browser. | 612 // On the last tab key press, the focus returns to the browser. |
| 613 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; | 613 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; |
| 614 notification_source = Source<Browser>(browser()); | 614 notification_source = Source<Browser>(browser()); |
| 615 } | 615 } |
| 616 | 616 |
| 617 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 617 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 618 browser(), app::VKEY_TAB, false, false, false, false, | 618 browser(), ui::VKEY_TAB, false, false, false, false, |
| 619 notification_type, notification_source)); | 619 notification_type, notification_source)); |
| 620 } | 620 } |
| 621 | 621 |
| 622 // At this point the renderer has sent us a message asking to advance the | 622 // At this point the renderer has sent us a message asking to advance the |
| 623 // focus (as the end of the focus loop was reached in the renderer). | 623 // focus (as the end of the focus loop was reached in the renderer). |
| 624 // We need to run the message loop to process it. | 624 // We need to run the message loop to process it. |
| 625 ui_test_utils::RunAllPendingInMessageLoop(); | 625 ui_test_utils::RunAllPendingInMessageLoop(); |
| 626 } | 626 } |
| 627 | 627 |
| 628 // Now let's try reverse focus traversal. | 628 // Now let's try reverse focus traversal. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 639 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; | 639 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; |
| 640 notification_source = Source<RenderViewHost>( | 640 notification_source = Source<RenderViewHost>( |
| 641 interstitial_page->render_view_host()); | 641 interstitial_page->render_view_host()); |
| 642 } else { | 642 } else { |
| 643 // On the last tab key press, the focus returns to the browser. | 643 // On the last tab key press, the focus returns to the browser. |
| 644 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; | 644 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; |
| 645 notification_source = Source<Browser>(browser()); | 645 notification_source = Source<Browser>(browser()); |
| 646 } | 646 } |
| 647 | 647 |
| 648 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 648 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 649 browser(), app::VKEY_TAB, false, true, false, false, | 649 browser(), ui::VKEY_TAB, false, true, false, false, |
| 650 notification_type, notification_source)); | 650 notification_type, notification_source)); |
| 651 | 651 |
| 652 // Let's make sure the focus is on the expected element in the page. | 652 // Let's make sure the focus is on the expected element in the page. |
| 653 std::string actual; | 653 std::string actual; |
| 654 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 654 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 655 interstitial_page->render_view_host(), L"", | 655 interstitial_page->render_view_host(), L"", |
| 656 L"window.domAutomationController.send(getFocusedElement());", | 656 L"window.domAutomationController.send(getFocusedElement());", |
| 657 &actual)); | 657 &actual)); |
| 658 ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); | 658 ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); |
| 659 } | 659 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 | 708 |
| 709 // Open some page (any page that doesn't steal focus). | 709 // Open some page (any page that doesn't steal focus). |
| 710 GURL url = test_server()->GetURL(kTypicalPage); | 710 GURL url = test_server()->GetURL(kTypicalPage); |
| 711 ui_test_utils::NavigateToURL(browser(), url); | 711 ui_test_utils::NavigateToURL(browser(), url); |
| 712 | 712 |
| 713 EXPECT_TRUE(ChromeInForeground()); | 713 EXPECT_TRUE(ChromeInForeground()); |
| 714 | 714 |
| 715 #if defined(OS_MACOSX) | 715 #if defined(OS_MACOSX) |
| 716 // Press Cmd+F, which will make the Find box open and request focus. | 716 // Press Cmd+F, which will make the Find box open and request focus. |
| 717 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 717 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 718 browser(), app::VKEY_F, false, false, false, true)); | 718 browser(), ui::VKEY_F, false, false, false, true)); |
| 719 #else | 719 #else |
| 720 // Press Ctrl+F, which will make the Find box open and request focus. | 720 // Press Ctrl+F, which will make the Find box open and request focus. |
| 721 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 721 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 722 browser(), app::VKEY_F, true, false, false, false)); | 722 browser(), ui::VKEY_F, true, false, false, false)); |
| 723 #endif | 723 #endif |
| 724 | 724 |
| 725 // Ideally, we wouldn't sleep here and instead would intercept the | 725 // Ideally, we wouldn't sleep here and instead would intercept the |
| 726 // RenderViewHostDelegate::HandleKeyboardEvent() callback. To do that, we | 726 // RenderViewHostDelegate::HandleKeyboardEvent() callback. To do that, we |
| 727 // could create a RenderViewHostDelegate wrapper and hook-it up by either: | 727 // could create a RenderViewHostDelegate wrapper and hook-it up by either: |
| 728 // - creating a factory used to create the delegate | 728 // - creating a factory used to create the delegate |
| 729 // - making the test a private and overwriting the delegate member directly. | 729 // - making the test a private and overwriting the delegate member directly. |
| 730 MessageLoop::current()->PostDelayedTask( | 730 MessageLoop::current()->PostDelayedTask( |
| 731 FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs); | 731 FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs); |
| 732 ui_test_utils::RunMessageLoop(); | 732 ui_test_utils::RunMessageLoop(); |
| 733 | 733 |
| 734 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 734 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 735 | 735 |
| 736 browser()->FocusLocationBar(); | 736 browser()->FocusLocationBar(); |
| 737 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 737 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
| 738 | 738 |
| 739 // Now press Ctrl+F again and focus should move to the Find box. | 739 // Now press Ctrl+F again and focus should move to the Find box. |
| 740 #if defined(OS_MACOSX) | 740 #if defined(OS_MACOSX) |
| 741 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 741 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 742 browser(), app::VKEY_F, false, false, false, true)); | 742 browser(), ui::VKEY_F, false, false, false, true)); |
| 743 #else | 743 #else |
| 744 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 744 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 745 browser(), app::VKEY_F, true, false, false, false)); | 745 browser(), ui::VKEY_F, true, false, false, false)); |
| 746 #endif | 746 #endif |
| 747 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 747 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 748 | 748 |
| 749 // Set focus to the page. | 749 // Set focus to the page. |
| 750 ClickOnView(VIEW_ID_TAB_CONTAINER); | 750 ClickOnView(VIEW_ID_TAB_CONTAINER); |
| 751 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 751 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 752 | 752 |
| 753 // Now press Ctrl+F again and focus should move to the Find box. | 753 // Now press Ctrl+F again and focus should move to the Find box. |
| 754 #if defined(OS_MACOSX) | 754 #if defined(OS_MACOSX) |
| 755 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 755 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 756 browser(), app::VKEY_F, false, false, false, true)); | 756 browser(), ui::VKEY_F, false, false, false, true)); |
| 757 #else | 757 #else |
| 758 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 758 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 759 browser(), app::VKEY_F, true, false, false, false)); | 759 browser(), ui::VKEY_F, true, false, false, false)); |
| 760 #endif | 760 #endif |
| 761 | 761 |
| 762 // See remark above on why we wait. | 762 // See remark above on why we wait. |
| 763 MessageLoop::current()->PostDelayedTask( | 763 MessageLoop::current()->PostDelayedTask( |
| 764 FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs); | 764 FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs); |
| 765 ui_test_utils::RunMessageLoop(); | 765 ui_test_utils::RunMessageLoop(); |
| 766 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 766 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 767 } | 767 } |
| 768 | 768 |
| 769 // Makes sure the focus is in the right location when opening the different | 769 // Makes sure the focus is in the right location when opening the different |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); | 834 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
| 835 browser()->Reload(CURRENT_TAB); | 835 browser()->Reload(CURRENT_TAB); |
| 836 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | 836 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
| 837 | 837 |
| 838 // Focus should now be on the tab contents. | 838 // Focus should now be on the tab contents. |
| 839 browser()->ShowDownloadsTab(); | 839 browser()->ShowDownloadsTab(); |
| 840 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 840 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 841 } | 841 } |
| 842 | 842 |
| 843 } // namespace | 843 } // namespace |
| OLD | NEW |