[email protected] | 265ccd9 | 2010-04-29 17:57:17 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | d9fde8d | 2009-10-08 19:59:30 | [diff] [blame] | 5 | #include "build/build_config.h" |
| 6 | |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 7 | #include "base/format_macros.h" |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 8 | #include "base/message_loop.h" |
[email protected] | ece3c8b | 2009-03-27 16:55:39 | [diff] [blame] | 9 | #include "base/ref_counted.h" |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 10 | #include "chrome/browser/automation/ui_controls.h" |
| 11 | #include "chrome/browser/browser.h" |
[email protected] | 134c47b9 | 2009-08-19 03:33:44 | [diff] [blame] | 12 | #include "chrome/browser/browser_window.h" |
| 13 | #include "chrome/browser/renderer_host/render_view_host.h" |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 14 | #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 15 | #include "chrome/browser/tab_contents/interstitial_page.h" |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 16 | #include "chrome/browser/tab_contents/tab_contents.h" |
| 17 | #include "chrome/browser/tab_contents/tab_contents_view.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | #include "chrome/browser/view_ids.h" |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 19 | #include "chrome/common/chrome_paths.h" |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 20 | #include "chrome/test/in_process_browser_test.h" |
| 21 | #include "chrome/test/ui_test_utils.h" |
[email protected] | 2362e4f | 2009-05-08 00:34:05 | [diff] [blame] | 22 | #include "views/focus/focus_manager.h" |
| 23 | #include "views/view.h" |
| 24 | #include "views/window/window.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | |
[email protected] | 134c47b9 | 2009-08-19 03:33:44 | [diff] [blame] | 26 | #if defined(TOOLKIT_VIEWS) |
| 27 | #include "chrome/browser/views/frame/browser_view.h" |
[email protected] | 265ccd9 | 2010-04-29 17:57:17 | [diff] [blame] | 28 | #include "chrome/browser/views/location_bar/location_bar_view.h" |
[email protected] | 134c47b9 | 2009-08-19 03:33:44 | [diff] [blame] | 29 | #include "chrome/browser/views/tab_contents/tab_contents_container.h" |
| 30 | #endif |
| 31 | |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 32 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | b982188 | 2009-08-17 22:25:17 | [diff] [blame] | 33 | #include "chrome/browser/gtk/view_id_util.h" |
| 34 | #endif |
| 35 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 36 | #if defined(OS_LINUX) |
| 37 | // For some reason we hit an external DNS lookup in this test in Linux but not |
| 38 | // on Windows. TODO(estade): investigate. |
| 39 | #define MAYBE_FocusTraversalOnInterstitial DISABLED_FocusTraversalOnInterstitial |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 40 | // TODO(jcampan): http://crbug.com/23683 |
[email protected] | bbe383d | 2010-07-13 21:49:59 | [diff] [blame^] | 41 | #define MAYBE_TabsRememberFocusFindInPage FAILS_TabsRememberFocusFindInPage |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 42 | #else |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 43 | #define MAYBE_FocusTraversalOnInterstitial FocusTraversalOnInterstitial |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 44 | #define MAYBE_TabsRememberFocusFindInPage TabsRememberFocusFindInPage |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 45 | #endif |
| 46 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 47 | namespace { |
| 48 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 49 | // The delay waited in some cases where we don't have a notifications for an |
| 50 | // action we take. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 51 | const int kActionDelayMs = 500; |
| 52 | |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 53 | const char kSimplePage[] = "files/focus/page_with_focus.html"; |
| 54 | const char kStealFocusPage[] = "files/focus/page_steals_focus.html"; |
| 55 | const char kTypicalPage[] = "files/focus/typical_page.html"; |
[email protected] | b65de8b9 | 2009-09-14 19:36:31 | [diff] [blame] | 56 | const char kTypicalPageName[] = "typical_page.html"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 57 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 58 | class BrowserFocusTest : public InProcessBrowserTest { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 59 | public: |
| 60 | BrowserFocusTest() { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 61 | set_show_window(true); |
| 62 | EnableDOMAutomation(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | } |
[email protected] | b982188 | 2009-08-17 22:25:17 | [diff] [blame] | 64 | |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 65 | bool IsViewFocused(ViewID vid) { |
| 66 | return ui_test_utils::IsViewFocused(browser(), vid); |
[email protected] | b982188 | 2009-08-17 22:25:17 | [diff] [blame] | 67 | } |
| 68 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 69 | void ClickOnView(ViewID vid) { |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 70 | ui_test_utils::ClickOnView(browser(), vid); |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 71 | } |
| 72 | |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 73 | static void HideNativeWindow(gfx::NativeWindow window) { |
| 74 | #if defined(OS_WIN) |
| 75 | // TODO(jcampan): retrieve the WidgetWin and show/hide on it instead of |
| 76 | // using Windows API. |
| 77 | ::ShowWindow(window, SW_HIDE); |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 78 | #elif defined(TOOLKIT_USES_GTK) |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 79 | gtk_widget_hide(GTK_WIDGET(window)); |
| 80 | #else |
| 81 | NOTIMPLEMENTED(); |
| 82 | #endif |
| 83 | } |
| 84 | |
| 85 | static void ShowNativeWindow(gfx::NativeWindow window) { |
| 86 | #if defined(OS_WIN) |
| 87 | // TODO(jcampan): retrieve the WidgetWin and show/hide on it instead of |
| 88 | // using Windows API. |
| 89 | ::ShowWindow(window, SW_SHOW); |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 90 | #elif defined(TOOLKIT_USES_GTK) |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 91 | gtk_widget_hide(GTK_WIDGET(window)); |
| 92 | #else |
| 93 | NOTIMPLEMENTED(); |
| 94 | #endif |
| 95 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | }; |
| 97 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 98 | class TestInterstitialPage : public InterstitialPage { |
| 99 | public: |
| 100 | TestInterstitialPage(TabContents* tab, bool new_navigation, const GURL& url) |
| 101 | : InterstitialPage(tab, new_navigation, url), |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 102 | waiting_for_dom_response_(false), |
| 103 | waiting_for_focus_change_(false) { |
[email protected] | b65de8b9 | 2009-09-14 19:36:31 | [diff] [blame] | 104 | FilePath file_path; |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 105 | bool r = PathService::Get(chrome::DIR_TEST_DATA, &file_path); |
| 106 | EXPECT_TRUE(r); |
[email protected] | b65de8b9 | 2009-09-14 19:36:31 | [diff] [blame] | 107 | file_path = file_path.AppendASCII("focus"); |
| 108 | file_path = file_path.AppendASCII(kTypicalPageName); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 109 | r = file_util::ReadFileToString(file_path, &html_contents_); |
| 110 | EXPECT_TRUE(r); |
| 111 | } |
| 112 | |
| 113 | virtual std::string GetHTMLContents() { |
| 114 | return html_contents_; |
| 115 | } |
| 116 | |
| 117 | virtual void DomOperationResponse(const std::string& json_string, |
| 118 | int automation_id) { |
| 119 | if (waiting_for_dom_response_) { |
| 120 | dom_response_ = json_string; |
| 121 | waiting_for_dom_response_ = false; |
| 122 | MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 123 | return; |
| 124 | } |
| 125 | InterstitialPage::DomOperationResponse(json_string, automation_id); |
| 126 | } |
| 127 | |
| 128 | std::string GetFocusedElement() { |
| 129 | std::wstring script = L"window.domAutomationController.setAutomationId(0);" |
| 130 | L"window.domAutomationController.send(getFocusedElement());"; |
| 131 | |
| 132 | render_view_host()->ExecuteJavascriptInWebFrame(L"", script); |
| 133 | DCHECK(!waiting_for_dom_response_); |
| 134 | waiting_for_dom_response_ = true; |
| 135 | ui_test_utils::RunMessageLoop(); |
| 136 | // Remove the JSON extra quotes. |
| 137 | if (dom_response_.size() >= 2 && dom_response_[0] == '"' && |
| 138 | dom_response_[dom_response_.size() - 1] == '"') { |
| 139 | dom_response_ = dom_response_.substr(1, dom_response_.size() - 2); |
| 140 | } |
| 141 | return dom_response_; |
| 142 | } |
| 143 | |
| 144 | bool HasFocus() { |
| 145 | return render_view_host()->view()->HasFocus(); |
| 146 | } |
| 147 | |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 148 | void WaitForFocusChange() { |
| 149 | waiting_for_focus_change_ = true; |
| 150 | ui_test_utils::RunMessageLoop(); |
| 151 | } |
| 152 | |
| 153 | protected: |
| 154 | virtual void FocusedNodeChanged() { |
| 155 | if (!waiting_for_focus_change_) |
| 156 | return; |
| 157 | |
| 158 | waiting_for_focus_change_= false; |
| 159 | MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 160 | } |
| 161 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 162 | private: |
| 163 | std::string html_contents_; |
| 164 | |
| 165 | bool waiting_for_dom_response_; |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 166 | bool waiting_for_focus_change_; |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 167 | std::string dom_response_; |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 168 | }; |
[email protected] | b982188 | 2009-08-17 22:25:17 | [diff] [blame] | 169 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 170 | } // namespace |
| 171 | |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 172 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 173 | #if defined(USE_X11) |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 174 | // It seems we have to wait a little bit for the widgets to spin up before |
| 175 | // we can start clicking on them. |
| 176 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 177 | new MessageLoop::QuitTask(), |
| 178 | kActionDelayMs); |
| 179 | ui_test_utils::RunMessageLoop(); |
| 180 | #endif |
| 181 | |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 182 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 183 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 184 | ClickOnView(VIEW_ID_TAB_CONTAINER); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 185 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 186 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 187 | ClickOnView(VIEW_ID_LOCATION_BAR); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 188 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 189 | } |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 190 | |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 191 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BrowsersRememberFocus) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 192 | HTTPTestServer* server = StartHTTPServer(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 193 | |
| 194 | // First we navigate to our test page. |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 195 | GURL url = server->TestServerPage(kSimplePage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 196 | ui_test_utils::NavigateToURL(browser(), url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 197 | |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 198 | gfx::NativeWindow window = browser()->window()->GetNativeHandle(); |
| 199 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 200 | // The focus should be on the Tab contents. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 201 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 202 | // Now hide the window, show it again, the focus should not have changed. |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 203 | HideNativeWindow(window); |
| 204 | ShowNativeWindow(window); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 205 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 206 | |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 207 | browser()->FocusLocationBar(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 208 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 209 | // Hide the window, show it again, the focus should not have changed. |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 210 | HideNativeWindow(window); |
| 211 | ShowNativeWindow(window); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 212 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 213 | |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 214 | // The rest of this test does not make sense on Linux because the behavior |
| 215 | // of Activate() is not well defined and can vary by window manager. |
| 216 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 217 | // Open a new browser window. |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 218 | Browser* browser2 = Browser::Create(browser()->profile()); |
| 219 | ASSERT_TRUE(browser2); |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 220 | browser2->tabstrip_model()->delegate()->AddBlankTab(true); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 221 | browser2->window()->Show(); |
| 222 | ui_test_utils::NavigateToURL(browser2, url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 223 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 224 | HWND hwnd2 = reinterpret_cast<HWND>(browser2->window()->GetNativeHandle()); |
[email protected] | 4a507a6 | 2009-05-28 00:10:00 | [diff] [blame] | 225 | BrowserView* browser_view2 = |
| 226 | BrowserView::GetBrowserViewForNativeWindow(hwnd2); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 227 | ASSERT_TRUE(browser_view2); |
| 228 | views::FocusManager* focus_manager2 = |
[email protected] | 82166b6 | 2009-06-30 18:48:00 | [diff] [blame] | 229 | views::FocusManager::GetFocusManagerForNativeView(hwnd2); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 230 | ASSERT_TRUE(focus_manager2); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 231 | EXPECT_EQ(browser_view2->GetTabContentsContainerView(), |
[email protected] | 610d36a | 2009-05-22 23:00:38 | [diff] [blame] | 232 | focus_manager2->GetFocusedView()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 233 | |
| 234 | // Switch to the 1st browser window, focus should still be on the location |
| 235 | // bar and the second browser should have nothing focused. |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 236 | browser()->window()->Activate(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 237 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 238 | EXPECT_EQ(NULL, focus_manager2->GetFocusedView()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 239 | |
| 240 | // Switch back to the second browser, focus should still be on the page. |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 241 | browser2->window()->Activate(); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 242 | EXPECT_EQ(NULL, |
| 243 | views::FocusManager::GetFocusManagerForNativeView( |
| 244 | browser()->window()->GetNativeHandle())->GetFocusedView()); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 245 | EXPECT_EQ(browser_view2->GetTabContentsContainerView(), |
[email protected] | 610d36a | 2009-05-22 23:00:38 | [diff] [blame] | 246 | focus_manager2->GetFocusedView()); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 247 | |
| 248 | // Close the 2nd browser to avoid a DCHECK(). |
| 249 | browser_view2->Close(); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 250 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | // Tabs remember focus. |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 254 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 255 | HTTPTestServer* server = StartHTTPServer(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 256 | |
| 257 | // First we navigate to our test page. |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 258 | GURL url = server->TestServerPage(kSimplePage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 259 | ui_test_utils::NavigateToURL(browser(), url); |
| 260 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 261 | // Create several tabs. |
[email protected] | 22735af6 | 2009-04-07 21:09:58 | [diff] [blame] | 262 | for (int i = 0; i < 4; ++i) { |
[email protected] | 715af7e | 2010-04-29 01:55:38 | [diff] [blame] | 263 | browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, |
[email protected] | 4a166544 | 2010-06-28 16:09:39 | [diff] [blame] | 264 | TabStripModel::ADD_SELECTED, NULL, std::string()); |
[email protected] | 22735af6 | 2009-04-07 21:09:58 | [diff] [blame] | 265 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 266 | |
| 267 | // Alternate focus for the tab. |
| 268 | const bool kFocusPage[3][5] = { |
| 269 | { true, true, true, true, false }, |
| 270 | { false, false, false, false, false }, |
| 271 | { false, true, false, true, false } |
| 272 | }; |
| 273 | |
| 274 | for (int i = 1; i < 3; i++) { |
| 275 | for (int j = 0; j < 5; j++) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 276 | // Activate the tab. |
| 277 | browser()->SelectTabContentsAt(j, true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 278 | |
| 279 | // Activate the location bar or the page. |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 280 | if (kFocusPage[i][j]) { |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 281 | browser()->GetTabContentsAt(j)->view()->Focus(); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 282 | } else { |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 283 | browser()->FocusLocationBar(); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 284 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | // Now come back to the tab and check the right view is focused. |
| 288 | for (int j = 0; j < 5; j++) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 289 | // Activate the tab. |
| 290 | browser()->SelectTabContentsAt(j, true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 291 | |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 292 | ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : |
| 293 | VIEW_ID_LOCATION_BAR; |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 294 | ASSERT_TRUE(IsViewFocused(vid)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 295 | } |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 296 | |
| 297 | gfx::NativeWindow window = browser()->window()->GetNativeHandle(); |
| 298 | browser()->SelectTabContentsAt(0, true); |
| 299 | // Try the above, but with ctrl+tab. Since tab normally changes focus, |
| 300 | // this has regressed in the past. Loop through several times to be sure. |
| 301 | for (int j = 0; j < 15; j++) { |
| 302 | ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : |
| 303 | VIEW_ID_LOCATION_BAR; |
| 304 | ASSERT_TRUE(IsViewFocused(vid)); |
| 305 | |
| 306 | ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_TAB, true, |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 307 | false, false, false, |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 308 | new MessageLoop::QuitTask()); |
| 309 | ui_test_utils::RunMessageLoop(); |
| 310 | } |
| 311 | |
| 312 | // As above, but with ctrl+shift+tab. |
| 313 | browser()->SelectTabContentsAt(4, true); |
| 314 | for (int j = 14; j >= 0; --j) { |
| 315 | ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : |
| 316 | VIEW_ID_LOCATION_BAR; |
| 317 | ASSERT_TRUE(IsViewFocused(vid)); |
| 318 | |
| 319 | ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_TAB, true, |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 320 | true, false, false, |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 321 | new MessageLoop::QuitTask()); |
| 322 | ui_test_utils::RunMessageLoop(); |
| 323 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 327 | // Tabs remember focus with find-in-page box. |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 328 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 329 | HTTPTestServer* server = StartHTTPServer(); |
| 330 | |
| 331 | // First we navigate to our test page. |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 332 | GURL url = server->TestServerPage(kSimplePage); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 333 | ui_test_utils::NavigateToURL(browser(), url); |
| 334 | |
| 335 | browser()->Find(); |
| 336 | ui_test_utils::FindInPage(browser()->GetSelectedTabContents(), |
| 337 | ASCIIToUTF16("a"), true, false, NULL); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 338 | ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 339 | |
| 340 | // Focus the location bar. |
| 341 | browser()->FocusLocationBar(); |
| 342 | |
| 343 | // Create a 2nd tab. |
[email protected] | 4a166544 | 2010-06-28 16:09:39 | [diff] [blame] | 344 | browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, |
| 345 | TabStripModel::ADD_SELECTED, NULL, std::string()); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 346 | |
| 347 | // Focus should be on the recently opened tab page. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 348 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 349 | |
| 350 | // Select 1st tab, focus should still be on the location-bar. |
| 351 | // (bug http://crbug.com/23296) |
| 352 | browser()->SelectTabContentsAt(0, true); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 353 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 354 | |
| 355 | // Now open the find box again, switch to another tab and come back, the focus |
| 356 | // should return to the find box. |
| 357 | browser()->Find(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 358 | ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 359 | browser()->SelectTabContentsAt(1, true); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 360 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 361 | browser()->SelectTabContentsAt(0, true); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 362 | ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 363 | } |
| 364 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 365 | // Background window does not steal focus. |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 366 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 367 | HTTPTestServer* server = StartHTTPServer(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 368 | |
| 369 | // First we navigate to our test page. |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 370 | GURL url = server->TestServerPage(kSimplePage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 371 | ui_test_utils::NavigateToURL(browser(), url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 372 | |
| 373 | // Open a new browser window. |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 374 | Browser* browser2 = Browser::Create(browser()->profile()); |
| 375 | ASSERT_TRUE(browser2); |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 376 | browser2->tabstrip_model()->delegate()->AddBlankTab(true); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 377 | browser2->window()->Show(); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 378 | |
[email protected] | ed179ee | 2009-10-03 21:02:51 | [diff] [blame] | 379 | Browser* focused_browser = NULL; |
| 380 | Browser* unfocused_browser = NULL; |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 381 | #if defined(USE_X11) |
| 382 | // On X11, calling Activate() is not guaranteed to move focus, so we have |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 383 | // to figure out which browser does have focus. |
| 384 | if (browser2->window()->IsActive()) { |
| 385 | focused_browser = browser2; |
| 386 | unfocused_browser = browser(); |
| 387 | } else if (browser()->window()->IsActive()) { |
| 388 | focused_browser = browser(); |
| 389 | unfocused_browser = browser2; |
| 390 | } else { |
| 391 | ASSERT_TRUE(false); |
| 392 | } |
| 393 | #elif defined(OS_WIN) |
| 394 | focused_browser = browser(); |
| 395 | unfocused_browser = browser2; |
| 396 | #endif |
| 397 | |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 398 | GURL steal_focus_url = server->TestServerPage(kStealFocusPage); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 399 | ui_test_utils::NavigateToURL(unfocused_browser, steal_focus_url); |
[email protected] | 1e187af | 2009-02-25 02:02:46 | [diff] [blame] | 400 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 401 | // Activate the first browser. |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 402 | focused_browser->window()->Activate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 403 | |
| 404 | // Wait for the focus to be stolen by the other browser. |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 405 | MessageLoop::current()->PostDelayedTask( |
| 406 | FROM_HERE, new MessageLoop::QuitTask(), 2000); |
| 407 | ui_test_utils::RunMessageLoop(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 408 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 409 | // Make sure the first browser is still active. |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 410 | EXPECT_TRUE(focused_browser->window()->IsActive()); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 411 | |
| 412 | // Close the 2nd browser to avoid a DCHECK(). |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 413 | browser2->window()->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | // Page cannot steal focus when focus is on location bar. |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 417 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 418 | HTTPTestServer* server = StartHTTPServer(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 419 | |
| 420 | // Open the page that steals focus. |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 421 | GURL url = server->TestServerPage(kStealFocusPage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 422 | ui_test_utils::NavigateToURL(browser(), url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 423 | |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 424 | browser()->FocusLocationBar(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 425 | |
| 426 | // Wait for the page to steal focus. |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 427 | PlatformThread::Sleep(2000); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 428 | |
| 429 | // Make sure the location bar is still focused. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 430 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 431 | } |
| 432 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 433 | // Focus traversal on a regular page. |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 434 | // Note that this test relies on a notification from the renderer that the |
| 435 | // focus has changed in the page. The notification in the renderer may change |
| 436 | // at which point this test would fail (see comment in |
| 437 | // RenderWidget::didFocus()). |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 438 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversal) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 439 | HTTPTestServer* server = StartHTTPServer(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 440 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 441 | // First we navigate to our test page. |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 442 | GURL url = server->TestServerPage(kTypicalPage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 443 | ui_test_utils::NavigateToURL(browser(), url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 444 | |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 445 | browser()->FocusLocationBar(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 446 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 447 | const char* kExpElementIDs[] = { |
| 448 | "", // Initially no element in the page should be focused |
| 449 | // (the location bar is focused). |
| 450 | "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", |
| 451 | "gmapLink" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 452 | }; |
| 453 | |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 454 | gfx::NativeWindow window = browser()->window()->GetNativeHandle(); |
| 455 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 456 | // Test forward focus traversal. |
| 457 | for (int i = 0; i < 3; ++i) { |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 458 | SCOPED_TRACE(StringPrintf("outer loop: %d", i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 459 | // Location bar should be focused. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 460 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 461 | |
| 462 | // Now let's press tab to move the focus. |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 463 | for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 464 | SCOPED_TRACE(StringPrintf("inner loop %" PRIuS, j)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 465 | // Let's make sure the focus is on the expected element in the page. |
[email protected] | 4567161 | 2009-04-29 22:24:01 | [diff] [blame] | 466 | std::string actual; |
| 467 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
[email protected] | 17c4f3c | 2009-07-04 16:36:25 | [diff] [blame] | 468 | browser()->GetSelectedTabContents()->render_view_host(), |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 469 | L"", |
[email protected] | 4567161 | 2009-04-29 22:24:01 | [diff] [blame] | 470 | L"window.domAutomationController.send(getFocusedElement());", |
| 471 | &actual)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 472 | ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 473 | |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 474 | ASSERT_TRUE(ui_controls::SendKeyPress(window, base::VKEY_TAB, |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 475 | false, false, false, false)); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 476 | |
| 477 | if (j < arraysize(kExpElementIDs) - 1) { |
| 478 | ui_test_utils::WaitForFocusChange(browser()->GetSelectedTabContents()-> |
| 479 | render_view_host()); |
| 480 | } else { |
| 481 | // On the last tab key press, the focus returns to the browser. |
| 482 | ui_test_utils::WaitForFocusInBrowser(browser()); |
| 483 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 484 | } |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 485 | |
| 486 | // At this point the renderer has sent us a message asking to advance the |
| 487 | // focus (as the end of the focus loop was reached in the renderer). |
| 488 | // We need to run the message loop to process it. |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 489 | ui_test_utils::RunAllPendingInMessageLoop(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | // Now let's try reverse focus traversal. |
| 493 | for (int i = 0; i < 3; ++i) { |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 494 | SCOPED_TRACE(StringPrintf("outer loop: %d", i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 495 | // Location bar should be focused. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 496 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 497 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 498 | // Now let's press shift-tab to move the focus in reverse. |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 499 | for (size_t j = 0; j < 7; ++j) { |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 500 | SCOPED_TRACE(StringPrintf("inner loop: %" PRIuS, j)); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 501 | ASSERT_TRUE(ui_controls::SendKeyPress(window, base::VKEY_TAB, |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 502 | false, true, false, false)); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 503 | |
| 504 | if (j < arraysize(kExpElementIDs) - 1) { |
| 505 | ui_test_utils::WaitForFocusChange(browser()->GetSelectedTabContents()-> |
| 506 | render_view_host()); |
| 507 | } else { |
| 508 | // On the last tab key press, the focus returns to the browser. |
| 509 | ui_test_utils::WaitForFocusInBrowser(browser()); |
| 510 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 511 | |
| 512 | // Let's make sure the focus is on the expected element in the page. |
[email protected] | 4567161 | 2009-04-29 22:24:01 | [diff] [blame] | 513 | std::string actual; |
| 514 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
[email protected] | 17c4f3c | 2009-07-04 16:36:25 | [diff] [blame] | 515 | browser()->GetSelectedTabContents()->render_view_host(), |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 516 | L"", |
[email protected] | 4567161 | 2009-04-29 22:24:01 | [diff] [blame] | 517 | L"window.domAutomationController.send(getFocusedElement());", |
| 518 | &actual)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 519 | ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); |
| 520 | } |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 521 | |
| 522 | // At this point the renderer has sent us a message asking to advance the |
| 523 | // focus (as the end of the focus loop was reached in the renderer). |
| 524 | // We need to run the message loop to process it. |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 525 | ui_test_utils::RunAllPendingInMessageLoop(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 529 | // Focus traversal while an interstitial is showing. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 530 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 531 | HTTPTestServer* server = StartHTTPServer(); |
| 532 | |
| 533 | // First we navigate to our test page. |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 534 | GURL url = server->TestServerPage(kSimplePage); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 535 | ui_test_utils::NavigateToURL(browser(), url); |
| 536 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 537 | // Focus should be on the page. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 538 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 539 | |
| 540 | // Let's show an interstitial. |
| 541 | TestInterstitialPage* interstitial_page = |
| 542 | new TestInterstitialPage(browser()->GetSelectedTabContents(), |
| 543 | true, GURL("http://interstitial.com")); |
| 544 | interstitial_page->Show(); |
| 545 | // Give some time for the interstitial to show. |
| 546 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 547 | new MessageLoop::QuitTask(), |
| 548 | 1000); |
| 549 | ui_test_utils::RunMessageLoop(); |
| 550 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 551 | browser()->FocusLocationBar(); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 552 | |
| 553 | const char* kExpElementIDs[] = { |
| 554 | "", // Initially no element in the page should be focused |
| 555 | // (the location bar is focused). |
| 556 | "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", |
| 557 | "gmapLink" |
| 558 | }; |
| 559 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 560 | gfx::NativeWindow window = browser()->window()->GetNativeHandle(); |
| 561 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 562 | // Test forward focus traversal. |
| 563 | for (int i = 0; i < 2; ++i) { |
| 564 | // Location bar should be focused. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 565 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 566 | |
| 567 | // Now let's press tab to move the focus. |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 568 | for (size_t j = 0; j < 7; ++j) { |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 569 | // Let's make sure the focus is on the expected element in the page. |
| 570 | std::string actual = interstitial_page->GetFocusedElement(); |
| 571 | ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 572 | |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 573 | ASSERT_TRUE(ui_controls::SendKeyPress(window, base::VKEY_TAB, |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 574 | false, false, false, false)); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 575 | |
| 576 | if (j < arraysize(kExpElementIDs) - 1) { |
| 577 | interstitial_page->WaitForFocusChange(); |
| 578 | } else { |
| 579 | // On the last tab key press, the focus returns to the browser. |
| 580 | ui_test_utils::WaitForFocusInBrowser(browser()); |
| 581 | } |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | // At this point the renderer has sent us a message asking to advance the |
| 585 | // focus (as the end of the focus loop was reached in the renderer). |
| 586 | // We need to run the message loop to process it. |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 587 | ui_test_utils::RunAllPendingInMessageLoop(); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | // Now let's try reverse focus traversal. |
| 591 | for (int i = 0; i < 2; ++i) { |
| 592 | // Location bar should be focused. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 593 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 594 | |
| 595 | // Now let's press shift-tab to move the focus in reverse. |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 596 | for (size_t j = 0; j < 7; ++j) { |
| 597 | ASSERT_TRUE(ui_controls::SendKeyPress(window, base::VKEY_TAB, |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 598 | false, true, false, false)); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 599 | |
| 600 | if (j < arraysize(kExpElementIDs) - 1) { |
| 601 | interstitial_page->WaitForFocusChange(); |
| 602 | } else { |
| 603 | // On the last tab key press, the focus returns to the browser. |
| 604 | ui_test_utils::WaitForFocusInBrowser(browser()); |
| 605 | } |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 606 | |
| 607 | // Let's make sure the focus is on the expected element in the page. |
| 608 | std::string actual = interstitial_page->GetFocusedElement(); |
| 609 | ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); |
| 610 | } |
| 611 | |
| 612 | // At this point the renderer has sent us a message asking to advance the |
| 613 | // focus (as the end of the focus loop was reached in the renderer). |
| 614 | // We need to run the message loop to process it. |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 615 | ui_test_utils::RunAllPendingInMessageLoop(); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
| 619 | // Focus stays on page with interstitials. |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 620 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 621 | HTTPTestServer* server = StartHTTPServer(); |
| 622 | |
| 623 | // First we navigate to our test page. |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 624 | GURL url = server->TestServerPage(kSimplePage); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 625 | ui_test_utils::NavigateToURL(browser(), url); |
| 626 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 627 | // Page should have focus. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 628 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 629 | EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()-> |
| 630 | HasFocus()); |
| 631 | |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 632 | // Let's show an interstitial. |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 633 | TestInterstitialPage* interstitial_page = |
| 634 | new TestInterstitialPage(browser()->GetSelectedTabContents(), |
| 635 | true, GURL("http://interstitial.com")); |
| 636 | interstitial_page->Show(); |
| 637 | // Give some time for the interstitial to show. |
| 638 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 639 | new MessageLoop::QuitTask(), |
| 640 | 1000); |
| 641 | ui_test_utils::RunMessageLoop(); |
| 642 | |
| 643 | // The interstitial should have focus now. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 644 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 645 | EXPECT_TRUE(interstitial_page->HasFocus()); |
| 646 | |
| 647 | // Hide the interstitial. |
| 648 | interstitial_page->DontProceed(); |
| 649 | |
| 650 | // Focus should be back on the original page. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 651 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 652 | } |
| 653 | |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 654 | // Make sure Find box can request focus, even when it is already open. |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 655 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 656 | HTTPTestServer* server = StartHTTPServer(); |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 657 | |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 658 | // Open some page (any page that doesn't steal focus). |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 659 | GURL url = server->TestServerPage(kTypicalPage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 660 | ui_test_utils::NavigateToURL(browser(), url); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 661 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 662 | gfx::NativeWindow window = browser()->window()->GetNativeHandle(); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 663 | |
| 664 | // Press Ctrl+F, which will make the Find box open and request focus. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 665 | ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, true, |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 666 | false, false, false, |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 667 | new MessageLoop::QuitTask()); |
| 668 | ui_test_utils::RunMessageLoop(); |
| 669 | |
| 670 | // Ideally, we wouldn't sleep here and instead would intercept the |
| 671 | // RenderViewHostDelegate::HandleKeyboardEvent() callback. To do that, we |
| 672 | // could create a RenderViewHostDelegate wrapper and hook-it up by either: |
| 673 | // - creating a factory used to create the delegate |
| 674 | // - making the test a private and overwriting the delegate member directly. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 675 | MessageLoop::current()->PostDelayedTask( |
| 676 | FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 677 | ui_test_utils::RunMessageLoop(); |
| 678 | |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 679 | ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 680 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 681 | browser()->FocusLocationBar(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 682 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 683 | |
| 684 | // Now press Ctrl+F again and focus should move to the Find box. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 685 | ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, true, |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 686 | false, false, false, |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 687 | new MessageLoop::QuitTask()); |
| 688 | ui_test_utils::RunMessageLoop(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 689 | ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 690 | |
| 691 | // Set focus to the page. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 692 | ClickOnView(VIEW_ID_TAB_CONTAINER); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 693 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 694 | |
| 695 | // Now press Ctrl+F again and focus should move to the Find box. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 696 | ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, true, false, |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 697 | false, false, |
| 698 | new MessageLoop::QuitTask()); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 699 | ui_test_utils::RunMessageLoop(); |
| 700 | |
| 701 | // See remark above on why we wait. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 702 | MessageLoop::current()->PostDelayedTask( |
| 703 | FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 704 | ui_test_utils::RunMessageLoop(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 705 | ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 706 | } |
[email protected] | 401513c | 2009-03-12 00:21:28 | [diff] [blame] | 707 | |
| 708 | // Makes sure the focus is in the right location when opening the different |
| 709 | // types of tabs. |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 710 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) { |
[email protected] | 401513c | 2009-03-12 00:21:28 | [diff] [blame] | 711 | // Open the history tab, focus should be on the tab contents. |
| 712 | browser()->ShowHistoryTab(); |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 713 | |
| 714 | ui_test_utils::RunAllPendingInMessageLoop(); |
| 715 | |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 716 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | 401513c | 2009-03-12 00:21:28 | [diff] [blame] | 717 | |
| 718 | // Open the new tab, focus should be on the location bar. |
| 719 | browser()->NewTab(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 720 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | 401513c | 2009-03-12 00:21:28 | [diff] [blame] | 721 | |
| 722 | // Open the download tab, focus should be on the tab contents. |
| 723 | browser()->ShowDownloadsTab(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 724 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | 3e3f0eb | 2009-06-22 18:33:43 | [diff] [blame] | 725 | |
| 726 | // Open about:blank, focus should be on the location bar. |
| 727 | browser()->AddTabWithURL(GURL("about:blank"), GURL(), PageTransition::LINK, |
[email protected] | 4a166544 | 2010-06-28 16:09:39 | [diff] [blame] | 728 | -1, TabStripModel::ADD_SELECTED, NULL, |
| 729 | std::string()); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 730 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | 401513c | 2009-03-12 00:21:28 | [diff] [blame] | 731 | } |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 732 | |
| 733 | // Tests that focus goes where expected when using reload. |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 734 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 735 | HTTPTestServer* server = StartHTTPServer(); |
| 736 | |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 737 | // Open the new tab, reload. |
| 738 | browser()->NewTab(); |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 739 | |
| 740 | ui_test_utils::RunAllPendingInMessageLoop(); |
| 741 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 742 | browser()->Reload(CURRENT_TAB); |
[email protected] | b7a20d3 | 2009-08-15 00:02:40 | [diff] [blame] | 743 | ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 744 | // Focus should stay on the location bar. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 745 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 746 | |
| 747 | // Open a regular page, focus the location bar, reload. |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 748 | ui_test_utils::NavigateToURL(browser(), server->TestServerPage(kSimplePage)); |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 749 | browser()->FocusLocationBar(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 750 | ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 751 | browser()->Reload(CURRENT_TAB); |
[email protected] | b7a20d3 | 2009-08-15 00:02:40 | [diff] [blame] | 752 | ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 753 | // Focus should now be on the tab contents. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 754 | browser()->ShowDownloadsTab(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 755 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | // Tests that focus goes where expected when using reload on a crashed tab. |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 759 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReloadCrashedTab) { |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 760 | HTTPTestServer* server = StartHTTPServer(); |
| 761 | |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 762 | // Open a regular page, crash, reload. |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 763 | ui_test_utils::NavigateToURL(browser(), server->TestServerPage(kSimplePage)); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 764 | ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 765 | browser()->Reload(CURRENT_TAB); |
[email protected] | b7a20d3 | 2009-08-15 00:02:40 | [diff] [blame] | 766 | ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 767 | // Focus should now be on the tab contents. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 768 | browser()->ShowDownloadsTab(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 769 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 770 | } |