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