diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-29 17:25:30 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-29 17:25:30 +0000 |
commit | 9d8a4642dad84e5bc0ca124ed5201a051045a547 (patch) | |
tree | 9aac7c292fe34386f4e4720c2066d336bd002429 | |
parent | 72f5652440c39aae6086a824b2505d23c71b731f (diff) | |
download | chromium_src-9d8a4642dad84e5bc0ca124ed5201a051045a547.zip chromium_src-9d8a4642dad84e5bc0ca124ed5201a051045a547.tar.gz chromium_src-9d8a4642dad84e5bc0ca124ed5201a051045a547.tar.bz2 |
The focus would be messed-up when reloading a crashed tab, also causing accelerators to be broken.
This CL also makes sure to keep the focus on the location bar when reloading the NTP.
BUG=http://crbug.com/14954
TEST=See bug.
Review URL: http://codereview.chromium.org/160206
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21961 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser.cc | 3 | ||||
-rw-r--r-- | chrome/browser/browser_focus_uitest.cc | 51 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/tab_contents/tab_contents_view_win.cc | 2 | ||||
-rw-r--r-- | chrome/test/ui_test_utils.cc | 31 | ||||
-rw-r--r-- | chrome/test/ui_test_utils.h | 3 |
6 files changed, 93 insertions, 3 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 3f54397..ab11f37 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -736,7 +736,8 @@ void Browser::Reload() { } // As this is caused by a user action, give the focus to the page. - current_tab->Focus(); + if (!current_tab->FocusLocationBarByDefault()) + current_tab->Focus(); current_tab->controller().Reload(true); } } diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc index 1133152..33f0bfc 100644 --- a/chrome/browser/browser_focus_uitest.cc +++ b/chrome/browser/browser_focus_uitest.cc @@ -504,7 +504,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()-> HasFocus()); - // Let's show an interstitial.erstitial + // Let's show an interstitial. TestInterstitialPage* interstitial_page = new TestInterstitialPage(browser()->GetSelectedTabContents(), true, GURL("http://interstitial.com")); @@ -637,3 +637,52 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) { EXPECT_EQ(browser_view->GetLocationBarView(), focus_manager->GetFocusedView()); } + +// Tests that focus goes where expected when using reload. +IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { + HTTPTestServer* server = StartHTTPServer(); + + HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); + BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); + ASSERT_TRUE(browser_view); + views::FocusManager* focus_manager = + views::FocusManager::GetFocusManagerForNativeView(hwnd); + ASSERT_TRUE(focus_manager); + + // Open the new tab, reload. + browser()->NewTab(); + ui_test_utils::ReloadCurrentTab(browser()); + // Focus should stay on the location bar. + EXPECT_EQ(browser_view->GetLocationBarView(), + focus_manager->GetFocusedView()); + + // Open a regular page, focus the location bar, reload. + ui_test_utils::NavigateToURL(browser(), server->TestServerPageW(kSimplePage)); + browser_view->GetLocationBarView()->FocusLocation(); + EXPECT_EQ(browser_view->GetLocationBarView(), + focus_manager->GetFocusedView()); + ui_test_utils::ReloadCurrentTab(browser()); + // Focus should now be on the tab contents. + EXPECT_EQ(browser_view->GetTabContentsContainerView(), + focus_manager->GetFocusedView()); +} + +// Tests that focus goes where expected when using reload on a crashed tab. +IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReloadCrashedTab) { + HTTPTestServer* server = StartHTTPServer(); + + HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); + BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); + ASSERT_TRUE(browser_view); + views::FocusManager* focus_manager = + views::FocusManager::GetFocusManagerForNativeView(hwnd); + ASSERT_TRUE(focus_manager); + + // Open a regular page, crash, reload. + ui_test_utils::NavigateToURL(browser(), server->TestServerPageW(kSimplePage)); + ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); + ui_test_utils::ReloadCurrentTab(browser()); + // Focus should now be on the tab contents. + EXPECT_EQ(browser_view->GetTabContentsContainerView(), + focus_manager->GetFocusedView()); +} diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 4546161..7fcbe0a 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -1779,7 +1779,13 @@ void TabContents::RenderViewReady(RenderViewHost* rvh) { } NotifyConnected(); + bool was_crashed = is_crashed(); SetIsCrashed(false); + + // Restore the focus to the tab (otherwise the focus will be on the top + // window). + if (was_crashed && !FocusLocationBarByDefault()) + Focus(); } void TabContents::RenderViewGone(RenderViewHost* rvh) { diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc index cd785d6..6febbdd 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc @@ -262,7 +262,7 @@ void TabContentsViewWin::Focus() { return; } - if (sad_tab_.get()) { + if (tab_contents()->is_crashed() && sad_tab_.get()) { sad_tab_->RequestFocus(); return; } diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc index 8167968..ee9b7d4 100644 --- a/chrome/test/ui_test_utils.cc +++ b/chrome/test/ui_test_utils.cc @@ -7,6 +7,7 @@ #include "base/json_reader.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/process_util.h" #include "base/values.h" #include "chrome/browser/browser.h" #include "chrome/browser/dom_operation_notification_details.h" @@ -229,6 +230,30 @@ class AppModalDialogObserver : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver); }; +class CrashedRenderProcessObserver : public NotificationObserver { + public: + explicit CrashedRenderProcessObserver(RenderProcessHost* rph) { + registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, + Source<RenderProcessHost>(rph)); + ui_test_utils::RunMessageLoop(); + } + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type == NotificationType::RENDERER_PROCESS_CLOSED) { + MessageLoopForUI::current()->Quit(); + } else { + NOTREACHED(); + } + } + + private: + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(CrashedRenderProcessObserver); +}; + } // namespace void RunMessageLoop() { @@ -370,4 +395,10 @@ AppModalDialog* WaitForAppModalDialog() { return observer.WaitForAppModalDialog(); } +void CrashTab(TabContents* tab) { + RenderProcessHost* rph = tab->render_view_host()->process(); + base::KillProcess(rph->process().handle(), 0, false); + CrashedRenderProcessObserver crash_observer(rph); +} + } // namespace ui_test_utils diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h index 3b2aef9..952cf5f 100644 --- a/chrome/test/ui_test_utils.h +++ b/chrome/test/ui_test_utils.h @@ -17,6 +17,7 @@ class DownloadManager; class GURL; class NavigationController; class RenderViewHost; +class TabContents; class Value; // A collections of functions designed for use with InProcessBrowserTest. @@ -90,6 +91,8 @@ void WaitForDownloadCount(DownloadManager* download_manager, size_t count); // Blocks until an application modal dialog is showns and returns it. AppModalDialog* WaitForAppModalDialog(); +// Causes the specified tab to crash. Blocks until it is crashed. +void CrashTab(TabContents* tab); } #endif // CHROME_TEST_UI_TEST_UTILS_H_ |