| 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 kTextElementID, "searchButton", "luckyButton", "googleLink", "gmailLink", | 462 kTextElementID, "searchButton", "luckyButton", "googleLink", "gmailLink", |
| 463 "gmapLink" | 463 "gmapLink" |
| 464 }; | 464 }; |
| 465 | 465 |
| 466 // Test forward focus traversal. | 466 // Test forward focus traversal. |
| 467 for (int i = 0; i < 3; ++i) { | 467 for (int i = 0; i < 3; ++i) { |
| 468 SCOPED_TRACE(StringPrintf("outer loop: %d", i)); | 468 SCOPED_TRACE(StringPrintf("outer loop: %d", i)); |
| 469 // Location bar should be focused. | 469 // Location bar should be focused. |
| 470 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 470 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
| 471 | 471 |
| 472 // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 473 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 474 browser(), ui::VKEY_END, false, false, false, false)); |
| 475 |
| 472 // Now let's press tab to move the focus. | 476 // Now let's press tab to move the focus. |
| 473 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { | 477 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { |
| 474 SCOPED_TRACE(StringPrintf("inner loop %" PRIuS, j)); | 478 SCOPED_TRACE(StringPrintf("inner loop %" PRIuS, j)); |
| 475 // Let's make sure the focus is on the expected element in the page. | 479 // Let's make sure the focus is on the expected element in the page. |
| 476 std::string actual; | 480 std::string actual; |
| 477 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 481 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 478 browser()->GetSelectedTabContents()->render_view_host(), | 482 browser()->GetSelectedTabContents()->render_view_host(), |
| 479 L"", | 483 L"", |
| 480 L"window.domAutomationController.send(getFocusedElement());", | 484 L"window.domAutomationController.send(getFocusedElement());", |
| 481 &actual)); | 485 &actual)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 508 // We need to run the message loop to process it. | 512 // We need to run the message loop to process it. |
| 509 ui_test_utils::RunAllPendingInMessageLoop(); | 513 ui_test_utils::RunAllPendingInMessageLoop(); |
| 510 } | 514 } |
| 511 | 515 |
| 512 // Now let's try reverse focus traversal. | 516 // Now let's try reverse focus traversal. |
| 513 for (int i = 0; i < 3; ++i) { | 517 for (int i = 0; i < 3; ++i) { |
| 514 SCOPED_TRACE(StringPrintf("outer loop: %d", i)); | 518 SCOPED_TRACE(StringPrintf("outer loop: %d", i)); |
| 515 // Location bar should be focused. | 519 // Location bar should be focused. |
| 516 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 520 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
| 517 | 521 |
| 522 // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 523 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 524 browser(), ui::VKEY_END, false, false, false, false)); |
| 525 |
| 518 // Now let's press shift-tab to move the focus in reverse. | 526 // Now let's press shift-tab to move the focus in reverse. |
| 519 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { | 527 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { |
| 520 SCOPED_TRACE(StringPrintf("inner loop: %" PRIuS, j)); | 528 SCOPED_TRACE(StringPrintf("inner loop: %" PRIuS, j)); |
| 521 const char* next_element = | 529 const char* next_element = |
| 522 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j]; | 530 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j]; |
| 523 | 531 |
| 524 if (j < arraysize(kExpElementIDs) - 1) { | 532 if (j < arraysize(kExpElementIDs) - 1) { |
| 525 // If the next element is the kTextElementID, we expect to be | 533 // If the next element is the kTextElementID, we expect to be |
| 526 // notified we have switched to an editable node. | 534 // notified we have switched to an editable node. |
| 527 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); | 535 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 // (the location bar is focused). | 596 // (the location bar is focused). |
| 589 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", | 597 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", |
| 590 "gmapLink" | 598 "gmapLink" |
| 591 }; | 599 }; |
| 592 | 600 |
| 593 // Test forward focus traversal. | 601 // Test forward focus traversal. |
| 594 for (int i = 0; i < 2; ++i) { | 602 for (int i = 0; i < 2; ++i) { |
| 595 // Location bar should be focused. | 603 // Location bar should be focused. |
| 596 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 604 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
| 597 | 605 |
| 606 // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 607 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 608 browser(), ui::VKEY_END, false, false, false, false)); |
| 609 |
| 598 // Now let's press tab to move the focus. | 610 // Now let's press tab to move the focus. |
| 599 for (size_t j = 0; j < 7; ++j) { | 611 for (size_t j = 0; j < 7; ++j) { |
| 600 // Let's make sure the focus is on the expected element in the page. | 612 // Let's make sure the focus is on the expected element in the page. |
| 601 std::string actual; | 613 std::string actual; |
| 602 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 614 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 603 interstitial_page->render_view_host(), L"", | 615 interstitial_page->render_view_host(), L"", |
| 604 L"window.domAutomationController.send(getFocusedElement());", | 616 L"window.domAutomationController.send(getFocusedElement());", |
| 605 &actual)); | 617 &actual)); |
| 606 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); | 618 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 607 | 619 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 627 // focus (as the end of the focus loop was reached in the renderer). | 639 // focus (as the end of the focus loop was reached in the renderer). |
| 628 // We need to run the message loop to process it. | 640 // We need to run the message loop to process it. |
| 629 ui_test_utils::RunAllPendingInMessageLoop(); | 641 ui_test_utils::RunAllPendingInMessageLoop(); |
| 630 } | 642 } |
| 631 | 643 |
| 632 // Now let's try reverse focus traversal. | 644 // Now let's try reverse focus traversal. |
| 633 for (int i = 0; i < 2; ++i) { | 645 for (int i = 0; i < 2; ++i) { |
| 634 // Location bar should be focused. | 646 // Location bar should be focused. |
| 635 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 647 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
| 636 | 648 |
| 649 // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 650 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 651 browser(), ui::VKEY_END, false, false, false, false)); |
| 652 |
| 637 // Now let's press shift-tab to move the focus in reverse. | 653 // Now let's press shift-tab to move the focus in reverse. |
| 638 for (size_t j = 0; j < 7; ++j) { | 654 for (size_t j = 0; j < 7; ++j) { |
| 639 NotificationType::Type notification_type; | 655 NotificationType::Type notification_type; |
| 640 NotificationSource notification_source = | 656 NotificationSource notification_source = |
| 641 NotificationService::AllSources(); | 657 NotificationService::AllSources(); |
| 642 if (j < arraysize(kExpElementIDs) - 1) { | 658 if (j < arraysize(kExpElementIDs) - 1) { |
| 643 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; | 659 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; |
| 644 notification_source = Source<TabContents>( | 660 notification_source = Source<TabContents>( |
| 645 interstitial_page->tab()); | 661 interstitial_page->tab()); |
| 646 } else { | 662 } else { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); | 854 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
| 839 browser()->Reload(CURRENT_TAB); | 855 browser()->Reload(CURRENT_TAB); |
| 840 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | 856 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
| 841 | 857 |
| 842 // Focus should now be on the tab contents. | 858 // Focus should now be on the tab contents. |
| 843 browser()->ShowDownloadsTab(); | 859 browser()->ShowDownloadsTab(); |
| 844 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 860 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 845 } | 861 } |
| 846 | 862 |
| 847 } // namespace | 863 } // namespace |
| OLD | NEW |