| 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/stringprintf.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.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/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.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/public/browser/notification_service.h" |
| 29 #include "content/common/view_messages.h" | 30 #include "content/common/view_messages.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 "views/focus/focus_manager.h" | 34 #include "views/focus/focus_manager.h" |
| 34 #include "views/view.h" | 35 #include "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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 bool OnMessageReceived(const IPC::Message& message) { | 176 bool OnMessageReceived(const IPC::Message& message) { |
| 176 bool handled = true; | 177 bool handled = true; |
| 177 IPC_BEGIN_MESSAGE_MAP(TestInterstitialPage, message) | 178 IPC_BEGIN_MESSAGE_MAP(TestInterstitialPage, message) |
| 178 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged) | 179 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged) |
| 179 IPC_MESSAGE_UNHANDLED(handled = false) | 180 IPC_MESSAGE_UNHANDLED(handled = false) |
| 180 IPC_END_MESSAGE_MAP() | 181 IPC_END_MESSAGE_MAP() |
| 181 return handled; | 182 return handled; |
| 182 } | 183 } |
| 183 | 184 |
| 184 void OnFocusedNodeChanged(bool is_editable_node) { | 185 void OnFocusedNodeChanged(bool is_editable_node) { |
| 185 NotificationService::current()->Notify( | 186 content::NotificationService::current()->Notify( |
| 186 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 187 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 187 content::Source<TabContents>(tab()), | 188 content::Source<TabContents>(tab()), |
| 188 content::Details<const bool>(&is_editable_node)); | 189 content::Details<const bool>(&is_editable_node)); |
| 189 } | 190 } |
| 190 | 191 |
| 191 private: | 192 private: |
| 192 std::string html_contents_; | 193 std::string html_contents_; |
| 193 }; | 194 }; |
| 194 | 195 |
| 195 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { | 196 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 // Let's make sure the focus is on the expected element in the page. | 626 // Let's make sure the focus is on the expected element in the page. |
| 626 std::string actual; | 627 std::string actual; |
| 627 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 628 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 628 interstitial_page->render_view_host(), L"", | 629 interstitial_page->render_view_host(), L"", |
| 629 L"window.domAutomationController.send(getFocusedElement());", | 630 L"window.domAutomationController.send(getFocusedElement());", |
| 630 &actual)); | 631 &actual)); |
| 631 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); | 632 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 632 | 633 |
| 633 int notification_type; | 634 int notification_type; |
| 634 content::NotificationSource notification_source = | 635 content::NotificationSource notification_source = |
| 635 NotificationService::AllSources(); | 636 content::NotificationService::AllSources(); |
| 636 if (j < arraysize(kExpElementIDs) - 1) { | 637 if (j < arraysize(kExpElementIDs) - 1) { |
| 637 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; | 638 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; |
| 638 notification_source = content::Source<TabContents>( | 639 notification_source = content::Source<TabContents>( |
| 639 interstitial_page->tab()); | 640 interstitial_page->tab()); |
| 640 } else { | 641 } else { |
| 641 // On the last tab key press, the focus returns to the browser. | 642 // On the last tab key press, the focus returns to the browser. |
| 642 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; | 643 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; |
| 643 notification_source = content::Source<Browser>(browser()); | 644 notification_source = content::Source<Browser>(browser()); |
| 644 } | 645 } |
| 645 | 646 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 660 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 661 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
| 661 | 662 |
| 662 // Move the caret to the end, otherwise the next Tab key may not move focus. | 663 // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 663 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 664 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 664 browser(), ui::VKEY_END, false, false, false, false)); | 665 browser(), ui::VKEY_END, false, false, false, false)); |
| 665 | 666 |
| 666 // Now let's press shift-tab to move the focus in reverse. | 667 // Now let's press shift-tab to move the focus in reverse. |
| 667 for (size_t j = 0; j < 7; ++j) { | 668 for (size_t j = 0; j < 7; ++j) { |
| 668 int notification_type; | 669 int notification_type; |
| 669 content::NotificationSource notification_source = | 670 content::NotificationSource notification_source = |
| 670 NotificationService::AllSources(); | 671 content::NotificationService::AllSources(); |
| 671 if (j < arraysize(kExpElementIDs) - 1) { | 672 if (j < arraysize(kExpElementIDs) - 1) { |
| 672 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; | 673 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; |
| 673 notification_source = content::Source<TabContents>( | 674 notification_source = content::Source<TabContents>( |
| 674 interstitial_page->tab()); | 675 interstitial_page->tab()); |
| 675 } else { | 676 } else { |
| 676 // On the last tab key press, the focus returns to the browser. | 677 // On the last tab key press, the focus returns to the browser. |
| 677 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; | 678 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; |
| 678 notification_source = content::Source<Browser>(browser()); | 679 notification_source = content::Source<Browser>(browser()); |
| 679 } | 680 } |
| 680 | 681 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 | 845 |
| 845 // Tests that focus goes where expected when using reload. | 846 // Tests that focus goes where expected when using reload. |
| 846 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { | 847 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { |
| 847 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 848 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 848 ASSERT_TRUE(test_server()->Start()); | 849 ASSERT_TRUE(test_server()->Start()); |
| 849 | 850 |
| 850 // Open the new tab, reload. | 851 // Open the new tab, reload. |
| 851 { | 852 { |
| 852 ui_test_utils::WindowedNotificationObserver observer( | 853 ui_test_utils::WindowedNotificationObserver observer( |
| 853 content::NOTIFICATION_LOAD_STOP, | 854 content::NOTIFICATION_LOAD_STOP, |
| 854 NotificationService::AllSources()); | 855 content::NotificationService::AllSources()); |
| 855 browser()->NewTab(); | 856 browser()->NewTab(); |
| 856 observer.Wait(); | 857 observer.Wait(); |
| 857 } | 858 } |
| 858 ui_test_utils::RunAllPendingInMessageLoop(); | 859 ui_test_utils::RunAllPendingInMessageLoop(); |
| 859 | 860 |
| 860 { | 861 { |
| 861 ui_test_utils::WindowedNotificationObserver observer( | 862 ui_test_utils::WindowedNotificationObserver observer( |
| 862 content::NOTIFICATION_LOAD_STOP, | 863 content::NOTIFICATION_LOAD_STOP, |
| 863 content::Source<NavigationController>( | 864 content::Source<NavigationController>( |
| 864 &browser()->GetSelectedTabContentsWrapper()->controller())); | 865 &browser()->GetSelectedTabContentsWrapper()->controller())); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 browser()->Reload(CURRENT_TAB); | 903 browser()->Reload(CURRENT_TAB); |
| 903 observer.Wait(); | 904 observer.Wait(); |
| 904 } | 905 } |
| 905 | 906 |
| 906 // Focus should now be on the tab contents. | 907 // Focus should now be on the tab contents. |
| 907 browser()->ShowDownloadsTab(); | 908 browser()->ShowDownloadsTab(); |
| 908 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 909 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 909 } | 910 } |
| 910 | 911 |
| 911 } // namespace | 912 } // namespace |
| OLD | NEW |