| 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" |
| 11 #include "base/stringprintf.h" |
| 11 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 12 #include "base/string_util.h" | |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/tabs/tab_strip_model.h" | 14 #include "chrome/browser/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/view_ids.h" | 17 #include "chrome/browser/ui/view_ids.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/test/in_process_browser_test.h" | 20 #include "chrome/test/in_process_browser_test.h" |
| 21 #include "chrome/test/ui_test_utils.h" | 21 #include "chrome/test/ui_test_utils.h" |
| 22 #include "content/browser/renderer_host/render_view_host.h" | 22 #include "content/browser/renderer_host/render_view_host.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" | 38 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 #if defined(TOOLKIT_USES_GTK) | 41 #if defined(TOOLKIT_USES_GTK) |
| 42 #include "chrome/browser/ui/gtk/view_id_util.h" | 42 #include "chrome/browser/ui/gtk/view_id_util.h" |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
| 46 #include <Psapi.h> | 46 #include <Psapi.h> |
| 47 #include <windows.h> | 47 #include <windows.h> |
| 48 #include "base/string_util.h" |
| 48 #endif | 49 #endif |
| 49 | 50 |
| 50 #if defined(OS_LINUX) | 51 #if defined(OS_LINUX) |
| 51 #define MAYBE_FocusTraversal FocusTraversal | 52 #define MAYBE_FocusTraversal FocusTraversal |
| 52 #define MAYBE_FocusTraversalOnInterstitial FocusTraversalOnInterstitial | 53 #define MAYBE_FocusTraversalOnInterstitial FocusTraversalOnInterstitial |
| 53 // TODO(jcampan): http://crbug.com/23683 | 54 // TODO(jcampan): http://crbug.com/23683 |
| 54 #define MAYBE_TabsRememberFocusFindInPage FAILS_TabsRememberFocusFindInPage | 55 #define MAYBE_TabsRememberFocusFindInPage FAILS_TabsRememberFocusFindInPage |
| 55 #elif defined(OS_MACOSX) | 56 #elif defined(OS_MACOSX) |
| 56 // TODO(suzhe): http://crbug.com/60973 (following two tests) | 57 // TODO(suzhe): http://crbug.com/60973 (following two tests) |
| 57 #define MAYBE_FocusTraversal DISABLED_FocusTraversal | 58 #define MAYBE_FocusTraversal DISABLED_FocusTraversal |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 const char* kTextElementID = "textEdit"; | 459 const char* kTextElementID = "textEdit"; |
| 459 const char* kExpElementIDs[] = { | 460 const char* kExpElementIDs[] = { |
| 460 "", // Initially no element in the page should be focused | 461 "", // Initially no element in the page should be focused |
| 461 // (the location bar is focused). | 462 // (the location bar is focused). |
| 462 kTextElementID, "searchButton", "luckyButton", "googleLink", "gmailLink", | 463 kTextElementID, "searchButton", "luckyButton", "googleLink", "gmailLink", |
| 463 "gmapLink" | 464 "gmapLink" |
| 464 }; | 465 }; |
| 465 | 466 |
| 466 // Test forward focus traversal. | 467 // Test forward focus traversal. |
| 467 for (int i = 0; i < 3; ++i) { | 468 for (int i = 0; i < 3; ++i) { |
| 468 SCOPED_TRACE(StringPrintf("outer loop: %d", i)); | 469 SCOPED_TRACE(base::StringPrintf("outer loop: %d", i)); |
| 469 // Location bar should be focused. | 470 // Location bar should be focused. |
| 470 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 471 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
| 471 | 472 |
| 472 // Move the caret to the end, otherwise the next Tab key may not move focus. | 473 // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 473 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 474 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 474 browser(), ui::VKEY_END, false, false, false, false)); | 475 browser(), ui::VKEY_END, false, false, false, false)); |
| 475 | 476 |
| 476 // Now let's press tab to move the focus. | 477 // Now let's press tab to move the focus. |
| 477 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { | 478 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { |
| 478 SCOPED_TRACE(StringPrintf("inner loop %" PRIuS, j)); | 479 SCOPED_TRACE(base::StringPrintf("inner loop %" PRIuS, j)); |
| 479 // Let's make sure the focus is on the expected element in the page. | 480 // Let's make sure the focus is on the expected element in the page. |
| 480 std::string actual; | 481 std::string actual; |
| 481 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 482 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 482 browser()->GetSelectedTabContents()->render_view_host(), | 483 browser()->GetSelectedTabContents()->render_view_host(), |
| 483 L"", | 484 L"", |
| 484 L"window.domAutomationController.send(getFocusedElement());", | 485 L"window.domAutomationController.send(getFocusedElement());", |
| 485 &actual)); | 486 &actual)); |
| 486 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); | 487 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 487 | 488 |
| 488 if (j < arraysize(kExpElementIDs) - 1) { | 489 if (j < arraysize(kExpElementIDs) - 1) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 508 } | 509 } |
| 509 | 510 |
| 510 // At this point the renderer has sent us a message asking to advance the | 511 // At this point the renderer has sent us a message asking to advance the |
| 511 // focus (as the end of the focus loop was reached in the renderer). | 512 // focus (as the end of the focus loop was reached in the renderer). |
| 512 // We need to run the message loop to process it. | 513 // We need to run the message loop to process it. |
| 513 ui_test_utils::RunAllPendingInMessageLoop(); | 514 ui_test_utils::RunAllPendingInMessageLoop(); |
| 514 } | 515 } |
| 515 | 516 |
| 516 // Now let's try reverse focus traversal. | 517 // Now let's try reverse focus traversal. |
| 517 for (int i = 0; i < 3; ++i) { | 518 for (int i = 0; i < 3; ++i) { |
| 518 SCOPED_TRACE(StringPrintf("outer loop: %d", i)); | 519 SCOPED_TRACE(base::StringPrintf("outer loop: %d", i)); |
| 519 // Location bar should be focused. | 520 // Location bar should be focused. |
| 520 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 521 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
| 521 | 522 |
| 522 // Move the caret to the end, otherwise the next Tab key may not move focus. | 523 // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 523 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 524 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 524 browser(), ui::VKEY_END, false, false, false, false)); | 525 browser(), ui::VKEY_END, false, false, false, false)); |
| 525 | 526 |
| 526 // Now let's press shift-tab to move the focus in reverse. | 527 // Now let's press shift-tab to move the focus in reverse. |
| 527 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { | 528 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { |
| 528 SCOPED_TRACE(StringPrintf("inner loop: %" PRIuS, j)); | 529 SCOPED_TRACE(base::StringPrintf("inner loop: %" PRIuS, j)); |
| 529 const char* next_element = | 530 const char* next_element = |
| 530 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j]; | 531 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j]; |
| 531 | 532 |
| 532 if (j < arraysize(kExpElementIDs) - 1) { | 533 if (j < arraysize(kExpElementIDs) - 1) { |
| 533 // If the next element is the kTextElementID, we expect to be | 534 // If the next element is the kTextElementID, we expect to be |
| 534 // notified we have switched to an editable node. | 535 // notified we have switched to an editable node. |
| 535 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); | 536 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); |
| 536 Details<bool> details(&is_editable_node); | 537 Details<bool> details(&is_editable_node); |
| 537 | 538 |
| 538 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( | 539 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); | 866 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
| 866 browser()->Reload(CURRENT_TAB); | 867 browser()->Reload(CURRENT_TAB); |
| 867 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | 868 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
| 868 | 869 |
| 869 // Focus should now be on the tab contents. | 870 // Focus should now be on the tab contents. |
| 870 browser()->ShowDownloadsTab(); | 871 browser()->ShowDownloadsTab(); |
| 871 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 872 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 872 } | 873 } |
| 873 | 874 |
| 874 } // namespace | 875 } // namespace |
| OLD | NEW |