| 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/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.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/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 18 #include "chrome/browser/ui/view_ids.h" | 18 #include "chrome/browser/ui/view_ids.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
| 25 #include "content/browser/renderer_host/render_widget_host_view.h" | 25 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 26 #include "content/browser/tab_contents/interstitial_page.h" | 26 #include "content/browser/tab_contents/interstitial_page.h" |
| 27 #include "content/browser/tab_contents/tab_contents.h" | 27 #include "content/browser/tab_contents/tab_contents.h" |
| 28 #include "content/browser/tab_contents/tab_contents_view.h" | 28 #include "content/browser/tab_contents/tab_contents_view.h" |
| 29 #include "content/common/view_messages.h" |
| 29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 30 #include "net/test/test_server.h" | 31 #include "net/test/test_server.h" |
| 31 | 32 |
| 32 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN) | 33 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN) |
| 33 #include "ui/views/focus/focus_manager.h" | 34 #include "ui/views/focus/focus_manager.h" |
| 34 #include "ui/views/view.h" | 35 #include "ui/views/view.h" |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 #if defined(TOOLKIT_VIEWS) | 38 #if defined(TOOLKIT_VIEWS) |
| 38 #include "chrome/browser/ui/views/frame/browser_view.h" | 39 #include "chrome/browser/ui/views/frame/browser_view.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 56 // TODO(jcampan): http://crbug.com/23683 | 57 // TODO(jcampan): http://crbug.com/23683 |
| 57 #define MAYBE_TabsRememberFocusFindInPage FAILS_TabsRememberFocusFindInPage | 58 #define MAYBE_TabsRememberFocusFindInPage FAILS_TabsRememberFocusFindInPage |
| 58 #elif defined(OS_MACOSX) | 59 #elif defined(OS_MACOSX) |
| 59 // TODO(suzhe): http://crbug.com/60973 (following two tests) | 60 // TODO(suzhe): http://crbug.com/60973 (following two tests) |
| 60 #define MAYBE_FocusTraversal DISABLED_FocusTraversal | 61 #define MAYBE_FocusTraversal DISABLED_FocusTraversal |
| 61 #define MAYBE_FocusTraversalOnInterstitial DISABLED_FocusTraversalOnInterstitial | 62 #define MAYBE_FocusTraversalOnInterstitial DISABLED_FocusTraversalOnInterstitial |
| 62 // TODO(suzhe): http://crbug.com/49737 | 63 // TODO(suzhe): http://crbug.com/49737 |
| 63 #define MAYBE_TabsRememberFocusFindInPage FAILS_TabsRememberFocusFindInPage | 64 #define MAYBE_TabsRememberFocusFindInPage FAILS_TabsRememberFocusFindInPage |
| 64 #elif defined(OS_WIN) | 65 #elif defined(OS_WIN) |
| 65 // Disabled, http://crbug.com/62543. | 66 // Disabled, http://crbug.com/62543. |
| 66 #define MAYBE_FocusTraversal FocusTraversal | 67 #define MAYBE_FocusTraversal DISABLED_FocusTraversal |
| 67 // Disabled, http://crbug.com/62544. | 68 // Disabled, http://crbug.com/62544. |
| 68 #define MAYBE_FocusTraversalOnInterstitial FocusTraversalOnInterstitial | 69 #define MAYBE_FocusTraversalOnInterstitial DISABLED_FocusTraversalOnInterstitial |
| 69 // Flaky, http://crbug.com/62537. | 70 // Flaky, http://crbug.com/62537. |
| 70 #define MAYBE_TabsRememberFocusFindInPage FLAKY_TabsRememberFocusFindInPage | 71 #define MAYBE_TabsRememberFocusFindInPage FLAKY_TabsRememberFocusFindInPage |
| 71 #endif | 72 #endif |
| 72 | 73 |
| 73 namespace { | 74 namespace { |
| 74 | 75 |
| 75 // The delay waited in some cases where we don't have a notifications for an | 76 // The delay waited in some cases where we don't have a notifications for an |
| 76 // action we take. | 77 // action we take. |
| 77 const int kActionDelayMs = 500; | 78 const int kActionDelayMs = 500; |
| 78 | 79 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 166 } |
| 166 | 167 |
| 167 virtual TabContents* tab() { | 168 virtual TabContents* tab() { |
| 168 return InterstitialPage::tab(); | 169 return InterstitialPage::tab(); |
| 169 } | 170 } |
| 170 | 171 |
| 171 bool HasFocus() { | 172 bool HasFocus() { |
| 172 return render_view_host()->view()->HasFocus(); | 173 return render_view_host()->view()->HasFocus(); |
| 173 } | 174 } |
| 174 | 175 |
| 176 protected: |
| 177 bool OnMessageReceived(const IPC::Message& message) { |
| 178 bool handled = true; |
| 179 IPC_BEGIN_MESSAGE_MAP(TestInterstitialPage, message) |
| 180 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged) |
| 181 IPC_MESSAGE_UNHANDLED(handled = false) |
| 182 IPC_END_MESSAGE_MAP() |
| 183 return handled; |
| 184 } |
| 185 |
| 186 void OnFocusedNodeChanged(bool is_editable_node) { |
| 187 content::NotificationService::current()->Notify( |
| 188 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 189 content::Source<TabContents>(tab()), |
| 190 content::Details<const bool>(&is_editable_node)); |
| 191 } |
| 192 |
| 175 private: | 193 private: |
| 176 std::string html_contents_; | 194 std::string html_contents_; |
| 177 }; | 195 }; |
| 178 | 196 |
| 179 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { | 197 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { |
| 180 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 198 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 181 #if defined(OS_POSIX) | 199 #if defined(OS_POSIX) |
| 182 // It seems we have to wait a little bit for the widgets to spin up before | 200 // It seems we have to wait a little bit for the widgets to spin up before |
| 183 // we can start clicking on them. | 201 // we can start clicking on them. |
| 184 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 202 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 if (j < arraysize(kExpElementIDs) - 1) { | 504 if (j < arraysize(kExpElementIDs) - 1) { |
| 487 // If the next element is the kTextElementID, we expect to be | 505 // If the next element is the kTextElementID, we expect to be |
| 488 // notified we have switched to an editable node. | 506 // notified we have switched to an editable node. |
| 489 bool is_editable_node = | 507 bool is_editable_node = |
| 490 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); | 508 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); |
| 491 content::Details<bool> details(&is_editable_node); | 509 content::Details<bool> details(&is_editable_node); |
| 492 | 510 |
| 493 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( | 511 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
| 494 browser(), ui::VKEY_TAB, false, false, false, false, | 512 browser(), ui::VKEY_TAB, false, false, false, false, |
| 495 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 513 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 496 content::NotificationSource(content::Source<RenderViewHost>( | 514 content::NotificationSource(content::Source<TabContents>( |
| 497 browser()->GetSelectedTabContents()->render_view_host())), | 515 browser()->GetSelectedTabContents())), |
| 498 details)); | 516 details)); |
| 499 } else { | 517 } else { |
| 500 // On the last tab key press, the focus returns to the browser. | 518 // On the last tab key press, the focus returns to the browser. |
| 501 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 519 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 502 browser(), ui::VKEY_TAB, false, false, false, false, | 520 browser(), ui::VKEY_TAB, false, false, false, false, |
| 503 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, | 521 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
| 504 content::NotificationSource(content::Source<Browser>(browser())))); | 522 content::NotificationSource(content::Source<Browser>(browser())))); |
| 505 } | 523 } |
| 506 } | 524 } |
| 507 | 525 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 529 | 547 |
| 530 if (j < arraysize(kExpElementIDs) - 1) { | 548 if (j < arraysize(kExpElementIDs) - 1) { |
| 531 // If the next element is the kTextElementID, we expect to be | 549 // If the next element is the kTextElementID, we expect to be |
| 532 // notified we have switched to an editable node. | 550 // notified we have switched to an editable node. |
| 533 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); | 551 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); |
| 534 content::Details<bool> details(&is_editable_node); | 552 content::Details<bool> details(&is_editable_node); |
| 535 | 553 |
| 536 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( | 554 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
| 537 browser(), ui::VKEY_TAB, false, true, false, false, | 555 browser(), ui::VKEY_TAB, false, true, false, false, |
| 538 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 556 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 539 content::NotificationSource(content::Source<RenderViewHost>( | 557 content::NotificationSource(content::Source<TabContents>( |
| 540 browser()->GetSelectedTabContents()->render_view_host())), | 558 browser()->GetSelectedTabContents())), |
| 541 details)); | 559 details)); |
| 542 } else { | 560 } else { |
| 543 // On the last tab key press, the focus returns to the browser. | 561 // On the last tab key press, the focus returns to the browser. |
| 544 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 562 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 545 browser(), ui::VKEY_TAB, false, true, false, false, | 563 browser(), ui::VKEY_TAB, false, true, false, false, |
| 546 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, | 564 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
| 547 content::NotificationSource(content::Source<Browser>(browser())))); | 565 content::NotificationSource(content::Source<Browser>(browser())))); |
| 548 } | 566 } |
| 549 | 567 |
| 550 // Let's make sure the focus is on the expected element in the page. | 568 // Let's make sure the focus is on the expected element in the page. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 interstitial_page->render_view_host(), L"", | 631 interstitial_page->render_view_host(), L"", |
| 614 L"window.domAutomationController.send(getFocusedElement());", | 632 L"window.domAutomationController.send(getFocusedElement());", |
| 615 &actual)); | 633 &actual)); |
| 616 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); | 634 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 617 | 635 |
| 618 int notification_type; | 636 int notification_type; |
| 619 content::NotificationSource notification_source = | 637 content::NotificationSource notification_source = |
| 620 content::NotificationService::AllSources(); | 638 content::NotificationService::AllSources(); |
| 621 if (j < arraysize(kExpElementIDs) - 1) { | 639 if (j < arraysize(kExpElementIDs) - 1) { |
| 622 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; | 640 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; |
| 623 notification_source = content::Source<RenderViewHost>( | 641 notification_source = content::Source<TabContents>( |
| 624 interstitial_page->render_view_host()); | 642 interstitial_page->tab()); |
| 625 } else { | 643 } else { |
| 626 // On the last tab key press, the focus returns to the browser. | 644 // On the last tab key press, the focus returns to the browser. |
| 627 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; | 645 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; |
| 628 notification_source = content::Source<Browser>(browser()); | 646 notification_source = content::Source<Browser>(browser()); |
| 629 } | 647 } |
| 630 | 648 |
| 631 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 649 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 632 browser(), ui::VKEY_TAB, false, false, false, false, | 650 browser(), ui::VKEY_TAB, false, false, false, false, |
| 633 notification_type, notification_source)); | 651 notification_type, notification_source)); |
| 634 } | 652 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 648 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 666 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 649 browser(), ui::VKEY_END, false, false, false, false)); | 667 browser(), ui::VKEY_END, false, false, false, false)); |
| 650 | 668 |
| 651 // Now let's press shift-tab to move the focus in reverse. | 669 // Now let's press shift-tab to move the focus in reverse. |
| 652 for (size_t j = 0; j < 7; ++j) { | 670 for (size_t j = 0; j < 7; ++j) { |
| 653 int notification_type; | 671 int notification_type; |
| 654 content::NotificationSource notification_source = | 672 content::NotificationSource notification_source = |
| 655 content::NotificationService::AllSources(); | 673 content::NotificationService::AllSources(); |
| 656 if (j < arraysize(kExpElementIDs) - 1) { | 674 if (j < arraysize(kExpElementIDs) - 1) { |
| 657 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; | 675 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; |
| 658 notification_source = content::Source<RenderViewHost>( | 676 notification_source = content::Source<TabContents>( |
| 659 interstitial_page->render_view_host()); | 677 interstitial_page->tab()); |
| 660 } else { | 678 } else { |
| 661 // On the last tab key press, the focus returns to the browser. | 679 // On the last tab key press, the focus returns to the browser. |
| 662 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; | 680 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; |
| 663 notification_source = content::Source<Browser>(browser()); | 681 notification_source = content::Source<Browser>(browser()); |
| 664 } | 682 } |
| 665 | 683 |
| 666 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 684 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 667 browser(), ui::VKEY_TAB, false, true, false, false, | 685 browser(), ui::VKEY_TAB, false, true, false, false, |
| 668 notification_type, notification_source)); | 686 notification_type, notification_source)); |
| 669 | 687 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 browser()->Reload(CURRENT_TAB); | 905 browser()->Reload(CURRENT_TAB); |
| 888 observer.Wait(); | 906 observer.Wait(); |
| 889 } | 907 } |
| 890 | 908 |
| 891 // Focus should now be on the tab contents. | 909 // Focus should now be on the tab contents. |
| 892 browser()->ShowDownloadsTab(); | 910 browser()->ShowDownloadsTab(); |
| 893 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 911 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 894 } | 912 } |
| 895 | 913 |
| 896 } // namespace | 914 } // namespace |
| OLD | NEW |