[email protected] | a9c060ca | 2012-01-05 20:43:41 | [diff] [blame] | 1 | // Copyright (c) 2012 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] | a9c060ca | 2012-01-05 20:43:41 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 3985ba8 | 2010-07-29 21:44:12 | [diff] [blame] | 8 | #include "base/file_util.h" |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 9 | #include "base/format_macros.h" |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 10 | #include "base/message_loop.h" |
[email protected] | 3985ba8 | 2010-07-29 21:44:12 | [diff] [blame] | 11 | #include "base/path_service.h" |
[email protected] | a711df10 | 2010-12-14 09:47:03 | [diff] [blame] | 12 | #include "base/string_number_conversions.h" |
[email protected] | 477ae05 | 2011-11-18 23:53:57 | [diff] [blame] | 13 | #include "base/stringprintf.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 14 | #include "base/utf_string_conversions.h" |
[email protected] | 7b5dc00 | 2010-11-16 23:08:10 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 16 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 17 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 18 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 19 | #include "chrome/browser/ui/chrome_pages.h" |
[email protected] | 871dc68 | 2012-06-11 19:35:33 | [diff] [blame] | 20 | #include "chrome/browser/ui/tab_contents/tab_contents.h" |
[email protected] | b56e2e3 | 2012-05-11 21:18:04 | [diff] [blame] | 21 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 22 | #include "chrome/browser/ui/view_ids.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 23 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 24 | #include "chrome/common/chrome_paths.h" |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 25 | #include "chrome/common/url_constants.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 26 | #include "chrome/test/base/in_process_browser_test.h" |
[email protected] | 477ae05 | 2011-11-18 23:53:57 | [diff] [blame] | 27 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 28 | #include "content/public/browser/interstitial_page.h" |
[email protected] | 85f0a57 | 2012-02-07 22:20:13 | [diff] [blame] | 29 | #include "content/public/browser/interstitial_page_delegate.h" |
[email protected] | 477ae05 | 2011-11-18 23:53:57 | [diff] [blame] | 30 | #include "content/public/browser/notification_service.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 31 | #include "content/public/browser/render_view_host.h" |
[email protected] | 5626b089 | 2012-02-20 14:46:58 | [diff] [blame] | 32 | #include "content/public/browser/render_widget_host_view.h" |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 33 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 34 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 3985ba8 | 2010-07-29 21:44:12 | [diff] [blame] | 35 | #include "net/test/test_server.h" |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 36 | |
| 37 | #if defined(TOOLKIT_VIEWS) || defined(OS_WIN) |
[email protected] | 477ae05 | 2011-11-18 23:53:57 | [diff] [blame] | 38 | #include "ui/views/focus/focus_manager.h" |
[email protected] | 5025f86 | 2011-11-30 23:35:20 | [diff] [blame] | 39 | #include "ui/views/view.h" |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 40 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | |
[email protected] | 134c47b9 | 2009-08-19 03:33:44 | [diff] [blame] | 42 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 9e790bd | 2011-01-10 23:48:54 | [diff] [blame] | 43 | #include "chrome/browser/ui/views/frame/browser_view.h" |
[email protected] | 134c47b9 | 2009-08-19 03:33:44 | [diff] [blame] | 44 | #endif |
| 45 | |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 46 | #if defined(TOOLKIT_GTK) |
[email protected] | 93270d00 | 2011-01-19 22:32:59 | [diff] [blame] | 47 | #include "chrome/browser/ui/gtk/view_id_util.h" |
[email protected] | b982188 | 2009-08-17 22:25:17 | [diff] [blame] | 48 | #endif |
| 49 | |
[email protected] | a711df10 | 2010-12-14 09:47:03 | [diff] [blame] | 50 | #if defined(OS_WIN) |
[email protected] | a711df10 | 2010-12-14 09:47:03 | [diff] [blame] | 51 | #include <Psapi.h> |
[email protected] | 93270d00 | 2011-01-19 22:32:59 | [diff] [blame] | 52 | #include <windows.h> |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 53 | #include "base/string_util.h" |
[email protected] | a711df10 | 2010-12-14 09:47:03 | [diff] [blame] | 54 | #endif |
| 55 | |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 56 | using content::InterstitialPage; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 57 | using content::NavigationController; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 58 | using content::RenderViewHost; |
[email protected] | 4b19ea5 | 2012-01-02 20:15:25 | [diff] [blame] | 59 | using content::WebContents; |
| 60 | |
[email protected] | 3a3cf4d | 2011-12-09 00:39:35 | [diff] [blame] | 61 | #if defined(OS_MACOSX) |
| 62 | // TODO(suzhe): http://crbug.com/60973 |
[email protected] | a5eb2d67 | 2010-10-22 07:24:48 | [diff] [blame] | 63 | #define MAYBE_FocusTraversal DISABLED_FocusTraversal |
| 64 | #define MAYBE_FocusTraversalOnInterstitial DISABLED_FocusTraversalOnInterstitial |
[email protected] | 87115392 | 2012-01-10 20:13:48 | [diff] [blame] | 65 | #elif defined(OS_WIN) |
| 66 | // http://crbug.com/109770 |
[email protected] | 2f2bf117 | 2012-01-10 22:17:18 | [diff] [blame] | 67 | #define MAYBE_FocusTraversal FocusTraversal |
[email protected] | 87115392 | 2012-01-10 20:13:48 | [diff] [blame] | 68 | #define MAYBE_FocusTraversalOnInterstitial DISABLED_FocusTraversalOnInterstitial |
[email protected] | 3a3cf4d | 2011-12-09 00:39:35 | [diff] [blame] | 69 | #else |
| 70 | #define MAYBE_FocusTraversal FocusTraversal |
| 71 | #define MAYBE_FocusTraversalOnInterstitial FocusTraversalOnInterstitial |
| 72 | #endif |
| 73 | |
| 74 | #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 75 | // TODO(jcampan): http://crbug.com/23683 for linux. |
| 76 | // TODO(suzhe): http://crbug.com/49737 for mac. |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 77 | #define MAYBE_TabsRememberFocusFindInPage FAILS_TabsRememberFocusFindInPage |
| 78 | #elif defined(OS_WIN) |
[email protected] | c9292867 | 2010-11-09 18:31:07 | [diff] [blame] | 79 | // Flaky, http://crbug.com/62537. |
[email protected] | 4d245165 | 2012-02-14 23:54:26 | [diff] [blame] | 80 | #define MAYBE_TabsRememberFocusFindInPage DISABLED_TabsRememberFocusFindInPage |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 81 | #endif |
| 82 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 83 | namespace { |
| 84 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 85 | // The delay waited in some cases where we don't have a notifications for an |
| 86 | // action we take. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 87 | const int kActionDelayMs = 500; |
| 88 | |
[email protected] | a9c060ca | 2012-01-05 20:43:41 | [diff] [blame] | 89 | // Maxiumum time to wait until the focus is moved to expected view. |
| 90 | const int kFocusChangeTimeoutMs = 500; |
| 91 | |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 92 | const char kSimplePage[] = "files/focus/page_with_focus.html"; |
| 93 | const char kStealFocusPage[] = "files/focus/page_steals_focus.html"; |
| 94 | const char kTypicalPage[] = "files/focus/typical_page.html"; |
[email protected] | b65de8b9 | 2009-09-14 19:36:31 | [diff] [blame] | 95 | const char kTypicalPageName[] = "typical_page.html"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | |
[email protected] | a711df10 | 2010-12-14 09:47:03 | [diff] [blame] | 97 | // Test to make sure Chrome is in the foreground as we start testing. This is |
| 98 | // required for tests that synthesize input to the Chrome window. |
| 99 | bool ChromeInForeground() { |
| 100 | #if defined(OS_WIN) |
| 101 | HWND window = ::GetForegroundWindow(); |
| 102 | std::wstring caption; |
| 103 | std::wstring filename; |
| 104 | int len = ::GetWindowTextLength(window) + 1; |
[email protected] | fdce478 | 2011-11-29 20:06:18 | [diff] [blame] | 105 | if (len > 1) |
| 106 | ::GetWindowText(window, WriteInto(&caption, len), len); |
[email protected] | a711df10 | 2010-12-14 09:47:03 | [diff] [blame] | 107 | bool chrome_window_in_foreground = |
| 108 | EndsWith(caption, L" - Google Chrome", true) || |
| 109 | EndsWith(caption, L" - Chromium", true); |
| 110 | if (!chrome_window_in_foreground) { |
| 111 | DWORD process_id; |
| 112 | int thread_id = ::GetWindowThreadProcessId(window, &process_id); |
| 113 | |
| 114 | base::ProcessHandle process; |
| 115 | if (base::OpenProcessHandleWithAccess(process_id, |
| 116 | PROCESS_QUERY_LIMITED_INFORMATION, |
| 117 | &process)) { |
[email protected] | fdce478 | 2011-11-29 20:06:18 | [diff] [blame] | 118 | if (!GetProcessImageFileName(process, WriteInto(&filename, MAX_PATH), |
| 119 | MAX_PATH)) { |
[email protected] | a711df10 | 2010-12-14 09:47:03 | [diff] [blame] | 120 | int error = GetLastError(); |
| 121 | filename = std::wstring(L"Unable to read filename for process id '" + |
| 122 | base::IntToString16(process_id) + |
| 123 | L"' (error ") + |
| 124 | base::IntToString16(error) + L")"; |
| 125 | } |
| 126 | base::CloseProcessHandle(process); |
| 127 | } |
| 128 | } |
| 129 | EXPECT_TRUE(chrome_window_in_foreground) |
| 130 | << "Chrome must be in the foreground when running interactive tests\n" |
| 131 | << "Process in foreground: " << filename.c_str() << "\n" |
| 132 | << "Window: " << window << "\n" |
| 133 | << "Caption: " << caption.c_str(); |
| 134 | return chrome_window_in_foreground; |
| 135 | #else |
| 136 | // Windows only at the moment. |
| 137 | return true; |
| 138 | #endif |
| 139 | } |
| 140 | |
[email protected] | a9c060ca | 2012-01-05 20:43:41 | [diff] [blame] | 141 | // Wait the focus change in message loop. |
| 142 | void CheckFocus(Browser* browser, ViewID id, const base::Time& timeout) { |
| 143 | if (ui_test_utils::IsViewFocused(browser, id) || |
| 144 | base::Time::Now() > timeout) { |
| 145 | MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 146 | } else { |
| 147 | MessageLoop::current()->PostDelayedTask( |
| 148 | FROM_HERE, |
| 149 | base::Bind(&CheckFocus, browser, id, timeout), |
[email protected] | 7e56010 | 2012-03-08 20:58:42 | [diff] [blame] | 150 | base::TimeDelta::FromMilliseconds(10)); |
[email protected] | a9c060ca | 2012-01-05 20:43:41 | [diff] [blame] | 151 | } |
| 152 | }; |
| 153 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 154 | class BrowserFocusTest : public InProcessBrowserTest { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 155 | public: |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 156 | BrowserFocusTest() : |
| 157 | #if defined(USE_AURA) |
| 158 | location_bar_focus_view_id_(VIEW_ID_OMNIBOX) |
| 159 | #else |
| 160 | location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR) |
| 161 | #endif |
[email protected] | 90ca4427 | 2012-07-18 18:15:48 | [diff] [blame] | 162 | {} |
[email protected] | b982188 | 2009-08-17 22:25:17 | [diff] [blame] | 163 | |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 164 | bool IsViewFocused(ViewID vid) { |
| 165 | return ui_test_utils::IsViewFocused(browser(), vid); |
[email protected] | b982188 | 2009-08-17 22:25:17 | [diff] [blame] | 166 | } |
| 167 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 168 | void ClickOnView(ViewID vid) { |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 169 | ui_test_utils::ClickOnView(browser(), vid); |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 170 | } |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 171 | |
[email protected] | a9c060ca | 2012-01-05 20:43:41 | [diff] [blame] | 172 | bool WaitForFocusChange(ViewID vid) { |
| 173 | const base::Time timeout = base::Time::Now() + |
| 174 | base::TimeDelta::FromMilliseconds(kFocusChangeTimeoutMs); |
| 175 | MessageLoop::current()->PostDelayedTask( |
| 176 | FROM_HERE, |
| 177 | base::Bind(&CheckFocus, browser(), vid, timeout), |
[email protected] | 7e56010 | 2012-03-08 20:58:42 | [diff] [blame] | 178 | base::TimeDelta::FromMilliseconds(100)); |
[email protected] | a9c060ca | 2012-01-05 20:43:41 | [diff] [blame] | 179 | ui_test_utils::RunMessageLoop(); |
| 180 | return IsViewFocused(vid); |
| 181 | } |
| 182 | |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 183 | ViewID location_bar_focus_view_id_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 184 | }; |
| 185 | |
[email protected] | 85f0a57 | 2012-02-07 22:20:13 | [diff] [blame] | 186 | class TestInterstitialPage : public content::InterstitialPageDelegate { |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 187 | public: |
[email protected] | 85f0a57 | 2012-02-07 22:20:13 | [diff] [blame] | 188 | TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { |
[email protected] | b65de8b9 | 2009-09-14 19:36:31 | [diff] [blame] | 189 | FilePath file_path; |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 190 | bool r = PathService::Get(chrome::DIR_TEST_DATA, &file_path); |
| 191 | EXPECT_TRUE(r); |
[email protected] | b65de8b9 | 2009-09-14 19:36:31 | [diff] [blame] | 192 | file_path = file_path.AppendASCII("focus"); |
| 193 | file_path = file_path.AppendASCII(kTypicalPageName); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 194 | r = file_util::ReadFileToString(file_path, &html_contents_); |
| 195 | EXPECT_TRUE(r); |
[email protected] | 85f0a57 | 2012-02-07 22:20:13 | [diff] [blame] | 196 | interstitial_page_ = InterstitialPage::Create( |
| 197 | tab, new_navigation, url , this); |
| 198 | interstitial_page_->Show(); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | virtual std::string GetHTMLContents() { |
| 202 | return html_contents_; |
| 203 | } |
| 204 | |
[email protected] | 85f0a57 | 2012-02-07 22:20:13 | [diff] [blame] | 205 | RenderViewHost* render_view_host() { |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 206 | return interstitial_page_->GetRenderViewHostForTesting(); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 207 | } |
| 208 | |
[email protected] | 85f0a57 | 2012-02-07 22:20:13 | [diff] [blame] | 209 | void DontProceed() { |
| 210 | interstitial_page_->DontProceed(); |
[email protected] | 4e85c11 | 2011-01-26 22:27:21 | [diff] [blame] | 211 | } |
| 212 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 213 | bool HasFocus() { |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 214 | return render_view_host()->GetView()->HasFocus(); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | private: |
| 218 | std::string html_contents_; |
[email protected] | 85f0a57 | 2012-02-07 22:20:13 | [diff] [blame] | 219 | InterstitialPage* interstitial_page_; // Owns us. |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 220 | }; |
[email protected] | b982188 | 2009-08-17 22:25:17 | [diff] [blame] | 221 | |
[email protected] | c39e233d | 2012-05-18 13:24:12 | [diff] [blame] | 222 | // Flaky on mac. http://crbug.com/67301. |
| 223 | #if defined(OS_MACOSX) |
[email protected] | 839e080 | 2012-05-18 14:45:23 | [diff] [blame] | 224 | #define MAYBE_ClickingMovesFocus DISABLED_ClickingMovesFocus |
[email protected] | c39e233d | 2012-05-18 13:24:12 | [diff] [blame] | 225 | #else |
[email protected] | 839e080 | 2012-05-18 14:45:23 | [diff] [blame] | 226 | #define MAYBE_ClickingMovesFocus ClickingMovesFocus |
[email protected] | c39e233d | 2012-05-18 13:24:12 | [diff] [blame] | 227 | #endif |
| 228 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_ClickingMovesFocus) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 229 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 0ff0ff3 | 2010-12-21 19:34:42 | [diff] [blame] | 230 | #if defined(OS_POSIX) |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 231 | // It seems we have to wait a little bit for the widgets to spin up before |
| 232 | // we can start clicking on them. |
[email protected] | 7e56010 | 2012-03-08 20:58:42 | [diff] [blame] | 233 | MessageLoop::current()->PostDelayedTask( |
| 234 | FROM_HERE, |
| 235 | MessageLoop::QuitClosure(), |
| 236 | base::TimeDelta::FromMilliseconds(kActionDelayMs)); |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 237 | ui_test_utils::RunMessageLoop(); |
[email protected] | 0ff0ff3 | 2010-12-21 19:34:42 | [diff] [blame] | 238 | #endif // defined(OS_POSIX) |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 239 | |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 240 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 241 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 242 | ClickOnView(VIEW_ID_TAB_CONTAINER); |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 243 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 244 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 245 | ClickOnView(VIEW_ID_LOCATION_BAR); |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 246 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 247 | } |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 248 | |
[email protected] | 320948e0 | 2011-01-10 08:21:12 | [diff] [blame] | 249 | // Flaky, http://crbug.com/69034. |
[email protected] | 4d245165 | 2012-02-14 23:54:26 | [diff] [blame] | 250 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 251 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 252 | ASSERT_TRUE(test_server()->Start()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 253 | |
| 254 | // First we navigate to our test page. |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 255 | GURL url = test_server()->GetURL(kSimplePage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 256 | ui_test_utils::NavigateToURL(browser(), url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 257 | |
[email protected] | 90556dd | 2012-06-07 20:26:18 | [diff] [blame] | 258 | gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 259 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 260 | // The focus should be on the Tab contents. |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 261 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 262 | // Now hide the window, show it again, the focus should not have changed. |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 263 | ui_test_utils::HideNativeWindow(window); |
[email protected] | 7807088c | 2011-11-09 15:16:29 | [diff] [blame] | 264 | ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 265 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 266 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 267 | chrome::FocusLocationBar(browser()); |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 268 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 269 | // Hide the window, show it again, the focus should not have changed. |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 270 | ui_test_utils::HideNativeWindow(window); |
[email protected] | 7807088c | 2011-11-09 15:16:29 | [diff] [blame] | 271 | ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 272 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 273 | |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 274 | // The rest of this test does not make sense on Linux because the behavior |
| 275 | // of Activate() is not well defined and can vary by window manager. |
| 276 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 277 | // Open a new browser window. |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 278 | Browser* browser2 = Browser::Create(browser()->profile()); |
| 279 | ASSERT_TRUE(browser2); |
[email protected] | 85537005 | 2012-07-10 19:30:32 | [diff] [blame] | 280 | chrome::AddBlankTab(browser2, true); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 281 | browser2->window()->Show(); |
| 282 | ui_test_utils::NavigateToURL(browser2, url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 283 | |
[email protected] | 90556dd | 2012-06-07 20:26:18 | [diff] [blame] | 284 | gfx::NativeWindow window2 = browser2->window()->GetNativeWindow(); |
[email protected] | 4a507a6 | 2009-05-28 00:10:00 | [diff] [blame] | 285 | BrowserView* browser_view2 = |
[email protected] | 075b204c | 2011-09-30 19:02:16 | [diff] [blame] | 286 | BrowserView::GetBrowserViewForBrowser(browser2); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 287 | ASSERT_TRUE(browser_view2); |
[email protected] | 0aaa528 | 2011-10-26 18:54:50 | [diff] [blame] | 288 | const views::Widget* widget2 = |
| 289 | views::Widget::GetWidgetForNativeWindow(window2); |
[email protected] | 0c96668 | 2011-08-02 18:22:10 | [diff] [blame] | 290 | ASSERT_TRUE(widget2); |
[email protected] | 0aaa528 | 2011-10-26 18:54:50 | [diff] [blame] | 291 | const views::FocusManager* focus_manager2 = widget2->GetFocusManager(); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 292 | ASSERT_TRUE(focus_manager2); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 293 | EXPECT_EQ(browser_view2->GetTabContentsContainerView(), |
[email protected] | 610d36a | 2009-05-22 23:00:38 | [diff] [blame] | 294 | focus_manager2->GetFocusedView()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 295 | |
| 296 | // Switch to the 1st browser window, focus should still be on the location |
| 297 | // bar and the second browser should have nothing focused. |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 298 | browser()->window()->Activate(); |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 299 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 300 | EXPECT_EQ(NULL, focus_manager2->GetFocusedView()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 301 | |
| 302 | // Switch back to the second browser, focus should still be on the page. |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 303 | browser2->window()->Activate(); |
[email protected] | 0c96668 | 2011-08-02 18:22:10 | [diff] [blame] | 304 | views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 305 | ASSERT_TRUE(widget); |
| 306 | EXPECT_EQ(NULL, widget->GetFocusManager()->GetFocusedView()); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 307 | EXPECT_EQ(browser_view2->GetTabContentsContainerView(), |
[email protected] | 610d36a | 2009-05-22 23:00:38 | [diff] [blame] | 308 | focus_manager2->GetFocusedView()); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 309 | |
| 310 | // Close the 2nd browser to avoid a DCHECK(). |
| 311 | browser_view2->Close(); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 312 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | // Tabs remember focus. |
[email protected] | 2615373 | 2010-11-09 18:47:39 | [diff] [blame] | 316 | // Disabled, http://crbug.com/62542. |
| 317 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 318 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 319 | ASSERT_TRUE(test_server()->Start()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 320 | |
| 321 | // First we navigate to our test page. |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 322 | GURL url = test_server()->GetURL(kSimplePage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 323 | ui_test_utils::NavigateToURL(browser(), url); |
| 324 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 325 | // Create several tabs. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 326 | for (int i = 0; i < 4; ++i) { |
| 327 | chrome::AddSelectedTabWithURL(browser(), url, |
| 328 | content::PAGE_TRANSITION_TYPED); |
| 329 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 330 | |
| 331 | // Alternate focus for the tab. |
| 332 | const bool kFocusPage[3][5] = { |
| 333 | { true, true, true, true, false }, |
| 334 | { false, false, false, false, false }, |
| 335 | { false, true, false, true, false } |
| 336 | }; |
| 337 | |
| 338 | for (int i = 1; i < 3; i++) { |
| 339 | for (int j = 0; j < 5; j++) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 340 | // Activate the tab. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 341 | chrome::ActivateTabAt(browser(), j, true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 342 | |
| 343 | // Activate the location bar or the page. |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 344 | if (kFocusPage[i][j]) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 345 | chrome::GetWebContentsAt(browser(), j)->GetView()->Focus(); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 346 | } else { |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 347 | chrome::FocusLocationBar(browser()); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 348 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | // Now come back to the tab and check the right view is focused. |
| 352 | for (int j = 0; j < 5; j++) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 353 | // Activate the tab. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 354 | chrome::ActivateTabAt(browser(), j, true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 355 | |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 356 | ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER : |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 357 | location_bar_focus_view_id_; |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 358 | ASSERT_TRUE(IsViewFocused(vid)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 359 | } |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 360 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 361 | chrome::ActivateTabAt(browser(), 0, true); |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 362 | // Try the above, but with ctrl+tab. Since tab normally changes focus, |
| 363 | // this has regressed in the past. Loop through several times to be sure. |
| 364 | for (int j = 0; j < 15; j++) { |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 365 | ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER : |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 366 | location_bar_focus_view_id_; |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 367 | ASSERT_TRUE(IsViewFocused(vid)); |
| 368 | |
[email protected] | 1d00068 | 2010-08-23 16:21:28 | [diff] [blame] | 369 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 370 | browser(), ui::VKEY_TAB, true, false, false, false)); |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | // As above, but with ctrl+shift+tab. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 374 | chrome::ActivateTabAt(browser(), 4, true); |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 375 | for (int j = 14; j >= 0; --j) { |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 376 | ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER : |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 377 | location_bar_focus_view_id_; |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 378 | ASSERT_TRUE(IsViewFocused(vid)); |
| 379 | |
[email protected] | 1d00068 | 2010-08-23 16:21:28 | [diff] [blame] | 380 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 381 | browser(), ui::VKEY_TAB, true, true, false, false)); |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 382 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 386 | // Tabs remember focus with find-in-page box. |
[email protected] | cb7e254 | 2009-12-14 22:02:35 | [diff] [blame] | 387 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 388 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 389 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 390 | |
| 391 | // First we navigate to our test page. |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 392 | GURL url = test_server()->GetURL(kSimplePage); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 393 | ui_test_utils::NavigateToURL(browser(), url); |
| 394 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 395 | chrome::Find(browser()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 396 | ui_test_utils::FindInPage(chrome::GetActiveTabContents(browser()), |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 397 | ASCIIToUTF16("a"), true, false, NULL); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 398 | ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 399 | |
| 400 | // Focus the location bar. |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 401 | chrome::FocusLocationBar(browser()); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 402 | |
| 403 | // Create a 2nd tab. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 404 | chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 405 | |
| 406 | // Focus should be on the recently opened tab page. |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 407 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 408 | |
| 409 | // Select 1st tab, focus should still be on the location-bar. |
| 410 | // (bug http://crbug.com/23296) |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 411 | chrome::ActivateTabAt(browser(), 0, true); |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 412 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 413 | |
| 414 | // Now open the find box again, switch to another tab and come back, the focus |
| 415 | // should return to the find box. |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 416 | chrome::Find(browser()); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 417 | ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 418 | chrome::ActivateTabAt(browser(), 1, true); |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 419 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 420 | chrome::ActivateTabAt(browser(), 0, true); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 421 | ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | ae40b57 | 2009-10-02 21:17:45 | [diff] [blame] | 422 | } |
| 423 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 424 | // Background window does not steal focus. |
[email protected] | c9292867 | 2010-11-09 18:31:07 | [diff] [blame] | 425 | // Flaky, http://crbug.com/62538. |
| 426 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, |
[email protected] | 4d245165 | 2012-02-14 23:54:26 | [diff] [blame] | 427 | DISABLED_BackgroundBrowserDontStealFocus) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 428 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 429 | ASSERT_TRUE(test_server()->Start()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 430 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 431 | // Open a new browser window. |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 432 | Browser* browser2 = Browser::Create(browser()->profile()); |
| 433 | ASSERT_TRUE(browser2); |
[email protected] | 85537005 | 2012-07-10 19:30:32 | [diff] [blame] | 434 | chrome::AddBlankTab(browser2, true); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 435 | browser2->window()->Show(); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 436 | |
[email protected] | ed179ee | 2009-10-03 21:02:51 | [diff] [blame] | 437 | Browser* focused_browser = NULL; |
| 438 | Browser* unfocused_browser = NULL; |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 439 | #if defined(USE_X11) |
| 440 | // On X11, calling Activate() is not guaranteed to move focus, so we have |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 441 | // to figure out which browser does have focus. |
| 442 | if (browser2->window()->IsActive()) { |
| 443 | focused_browser = browser2; |
| 444 | unfocused_browser = browser(); |
| 445 | } else if (browser()->window()->IsActive()) { |
| 446 | focused_browser = browser(); |
| 447 | unfocused_browser = browser2; |
| 448 | } else { |
[email protected] | 579c3d8 | 2010-10-06 03:53:51 | [diff] [blame] | 449 | FAIL() << "Could not determine which browser has focus"; |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 450 | } |
| 451 | #elif defined(OS_WIN) |
| 452 | focused_browser = browser(); |
| 453 | unfocused_browser = browser2; |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 454 | #elif defined(OS_MACOSX) |
| 455 | // On Mac, the newly created window always gets the focus. |
| 456 | focused_browser = browser2; |
| 457 | unfocused_browser = browser(); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 458 | #endif |
| 459 | |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 460 | GURL steal_focus_url = test_server()->GetURL(kStealFocusPage); |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 461 | ui_test_utils::NavigateToURL(unfocused_browser, steal_focus_url); |
[email protected] | 1e187af | 2009-02-25 02:02:46 | [diff] [blame] | 462 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 463 | // Activate the first browser. |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 464 | focused_browser->window()->Activate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 465 | |
[email protected] | 579c3d8 | 2010-10-06 03:53:51 | [diff] [blame] | 466 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 467 | chrome::GetActiveWebContents(unfocused_browser)->GetRenderViewHost(), L"", |
[email protected] | 579c3d8 | 2010-10-06 03:53:51 | [diff] [blame] | 468 | L"stealFocus();")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 469 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 470 | // Make sure the first browser is still active. |
[email protected] | 186f13f | 2009-08-19 20:34:00 | [diff] [blame] | 471 | EXPECT_TRUE(focused_browser->window()->IsActive()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | // Page cannot steal focus when focus is on location bar. |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 475 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 476 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 477 | ASSERT_TRUE(test_server()->Start()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 478 | |
| 479 | // Open the page that steals focus. |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 480 | GURL url = test_server()->GetURL(kStealFocusPage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 481 | ui_test_utils::NavigateToURL(browser(), url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 482 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 483 | chrome::FocusLocationBar(browser()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 484 | |
[email protected] | 579c3d8 | 2010-10-06 03:53:51 | [diff] [blame] | 485 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 486 | chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
[email protected] | 579c3d8 | 2010-10-06 03:53:51 | [diff] [blame] | 487 | L"stealFocus();")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 488 | |
| 489 | // Make sure the location bar is still focused. |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 490 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 491 | } |
| 492 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 493 | // Focus traversal on a regular page. |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 494 | // Note that this test relies on a notification from the renderer that the |
| 495 | // focus has changed in the page. The notification in the renderer may change |
| 496 | // at which point this test would fail (see comment in |
| 497 | // RenderWidget::didFocus()). |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 498 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 499 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 500 | ASSERT_TRUE(test_server()->Start()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 501 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 502 | // First we navigate to our test page. |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 503 | GURL url = test_server()->GetURL(kTypicalPage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 504 | ui_test_utils::NavigateToURL(browser(), url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 505 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 506 | chrome::FocusLocationBar(browser()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 507 | |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 508 | const char* kTextElementID = "textEdit"; |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 509 | const char* kExpElementIDs[] = { |
| 510 | "", // Initially no element in the page should be focused |
| 511 | // (the location bar is focused). |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 512 | kTextElementID, "searchButton", "luckyButton", "googleLink", "gmailLink", |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 513 | "gmapLink" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 514 | }; |
| 515 | |
| 516 | // Test forward focus traversal. |
| 517 | for (int i = 0; i < 3; ++i) { |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 518 | SCOPED_TRACE(base::StringPrintf("outer loop: %d", i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 519 | // Location bar should be focused. |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 520 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 521 | |
[email protected] | 911696b | 2011-01-28 02:36:49 | [diff] [blame] | 522 | // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 523 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 524 | browser(), ui::VKEY_END, false, false, false, false)); |
| 525 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 526 | // Now let's press tab to move the focus. |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 527 | for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 528 | SCOPED_TRACE(base::StringPrintf("inner loop %" PRIuS, j)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 529 | // 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] | 530 | std::string actual; |
| 531 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 532 | chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 533 | L"", |
[email protected] | 4567161 | 2009-04-29 22:24:01 | [diff] [blame] | 534 | L"window.domAutomationController.send(getFocusedElement());", |
| 535 | &actual)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 536 | ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 537 | |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 538 | if (j < arraysize(kExpElementIDs) - 1) { |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 539 | // If the next element is the kTextElementID, we expect to be |
| 540 | // notified we have switched to an editable node. |
| 541 | bool is_editable_node = |
| 542 | (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 543 | content::Details<bool> details(&is_editable_node); |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 544 | |
| 545 | ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 546 | browser(), ui::VKEY_TAB, false, false, false, false, |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 547 | content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
[email protected] | d5309265 | 2011-12-06 06:12:56 | [diff] [blame] | 548 | content::NotificationSource(content::Source<RenderViewHost>( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 549 | chrome::GetActiveWebContents(browser())->GetRenderViewHost())), |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 550 | details)); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 551 | } else { |
| 552 | // On the last tab key press, the focus returns to the browser. |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 553 | ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 554 | browser(), ui::VKEY_TAB, false, false, false, false, |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 555 | chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 556 | content::NotificationSource(content::Source<Browser>(browser())))); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 557 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 558 | } |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 559 | |
| 560 | // At this point the renderer has sent us a message asking to advance the |
| 561 | // focus (as the end of the focus loop was reached in the renderer). |
| 562 | // We need to run the message loop to process it. |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 563 | ui_test_utils::RunAllPendingInMessageLoop(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | // Now let's try reverse focus traversal. |
| 567 | for (int i = 0; i < 3; ++i) { |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 568 | SCOPED_TRACE(base::StringPrintf("outer loop: %d", i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 569 | // Location bar should be focused. |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 570 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 571 | |
[email protected] | 911696b | 2011-01-28 02:36:49 | [diff] [blame] | 572 | // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 573 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 574 | browser(), ui::VKEY_END, false, false, false, false)); |
| 575 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 576 | // Now let's press shift-tab to move the focus in reverse. |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 577 | for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 578 | SCOPED_TRACE(base::StringPrintf("inner loop: %" PRIuS, j)); |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 579 | const char* next_element = |
| 580 | kExpElementIDs[arraysize(kExpElementIDs) - 1 - j]; |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 581 | |
| 582 | if (j < arraysize(kExpElementIDs) - 1) { |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 583 | // If the next element is the kTextElementID, we expect to be |
| 584 | // notified we have switched to an editable node. |
| 585 | bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 586 | content::Details<bool> details(&is_editable_node); |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 587 | |
| 588 | ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 589 | browser(), ui::VKEY_TAB, false, true, false, false, |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 590 | content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
[email protected] | d5309265 | 2011-12-06 06:12:56 | [diff] [blame] | 591 | content::NotificationSource(content::Source<RenderViewHost>( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 592 | chrome::GetActiveWebContents(browser())->GetRenderViewHost())), |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 593 | details)); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 594 | } else { |
| 595 | // On the last tab key press, the focus returns to the browser. |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 596 | ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 597 | browser(), ui::VKEY_TAB, false, true, false, false, |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 598 | chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 599 | content::NotificationSource(content::Source<Browser>(browser())))); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 600 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 601 | |
| 602 | // 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] | 603 | std::string actual; |
| 604 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 605 | chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 606 | L"", |
[email protected] | 4567161 | 2009-04-29 22:24:01 | [diff] [blame] | 607 | L"window.domAutomationController.send(getFocusedElement());", |
| 608 | &actual)); |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 609 | ASSERT_STREQ(next_element, actual.c_str()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 610 | } |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 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(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 619 | // Focus traversal while an interstitial is showing. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 620 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 621 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 622 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 623 | |
| 624 | // First we navigate to our test page. |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 625 | GURL url = test_server()->GetURL(kSimplePage); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 626 | ui_test_utils::NavigateToURL(browser(), url); |
| 627 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 628 | // Focus should be on the page. |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 629 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 630 | |
| 631 | // Let's show an interstitial. |
| 632 | TestInterstitialPage* interstitial_page = |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 633 | new TestInterstitialPage(chrome::GetActiveWebContents(browser()), |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 634 | true, GURL("http://interstitial.com")); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 635 | // Give some time for the interstitial to show. |
| 636 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
[email protected] | a778709f | 2011-12-10 00:28:17 | [diff] [blame] | 637 | MessageLoop::QuitClosure(), |
[email protected] | 7e56010 | 2012-03-08 20:58:42 | [diff] [blame] | 638 | base::TimeDelta::FromSeconds(1)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 639 | ui_test_utils::RunMessageLoop(); |
| 640 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 641 | chrome::FocusLocationBar(browser()); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 642 | |
| 643 | const char* kExpElementIDs[] = { |
| 644 | "", // Initially no element in the page should be focused |
| 645 | // (the location bar is focused). |
| 646 | "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", |
| 647 | "gmapLink" |
| 648 | }; |
| 649 | |
| 650 | // Test forward focus traversal. |
| 651 | for (int i = 0; i < 2; ++i) { |
| 652 | // Location bar should be focused. |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 653 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 654 | |
[email protected] | 911696b | 2011-01-28 02:36:49 | [diff] [blame] | 655 | // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 656 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 657 | browser(), ui::VKEY_END, false, false, false, false)); |
| 658 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 659 | // Now let's press tab to move the focus. |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 660 | for (size_t j = 0; j < 7; ++j) { |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 661 | // Let's make sure the focus is on the expected element in the page. |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 662 | std::string actual; |
| 663 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 664 | interstitial_page->render_view_host(), L"", |
| 665 | L"window.domAutomationController.send(getFocusedElement());", |
| 666 | &actual)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 667 | ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 668 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 669 | int notification_type; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 670 | content::NotificationSource notification_source = |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 671 | content::NotificationService::AllSources(); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 672 | if (j < arraysize(kExpElementIDs) - 1) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 673 | notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; |
[email protected] | d5309265 | 2011-12-06 06:12:56 | [diff] [blame] | 674 | notification_source = content::Source<RenderViewHost>( |
| 675 | interstitial_page->render_view_host()); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 676 | } else { |
| 677 | // On the last tab key press, the focus returns to the browser. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 678 | notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 679 | notification_source = content::Source<Browser>(browser()); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 680 | } |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 681 | |
| 682 | ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 683 | browser(), ui::VKEY_TAB, false, false, false, false, |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 684 | notification_type, notification_source)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | // At this point the renderer has sent us a message asking to advance the |
| 688 | // focus (as the end of the focus loop was reached in the renderer). |
| 689 | // We need to run the message loop to process it. |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 690 | ui_test_utils::RunAllPendingInMessageLoop(); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | // Now let's try reverse focus traversal. |
| 694 | for (int i = 0; i < 2; ++i) { |
| 695 | // Location bar should be focused. |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 696 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 697 | |
[email protected] | 911696b | 2011-01-28 02:36:49 | [diff] [blame] | 698 | // Move the caret to the end, otherwise the next Tab key may not move focus. |
| 699 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 700 | browser(), ui::VKEY_END, false, false, false, false)); |
| 701 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 702 | // Now let's press shift-tab to move the focus in reverse. |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 703 | for (size_t j = 0; j < 7; ++j) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 704 | int notification_type; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 705 | content::NotificationSource notification_source = |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 706 | content::NotificationService::AllSources(); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 707 | if (j < arraysize(kExpElementIDs) - 1) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 708 | notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; |
[email protected] | d5309265 | 2011-12-06 06:12:56 | [diff] [blame] | 709 | notification_source = content::Source<RenderViewHost>( |
| 710 | interstitial_page->render_view_host()); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 711 | } else { |
| 712 | // On the last tab key press, the focus returns to the browser. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 713 | notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 714 | notification_source = content::Source<Browser>(browser()); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 715 | } |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 716 | |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 717 | ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 718 | browser(), ui::VKEY_TAB, false, true, false, false, |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 719 | notification_type, notification_source)); |
| 720 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 721 | // Let's make sure the focus is on the expected element in the page. |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 722 | std::string actual; |
| 723 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 724 | interstitial_page->render_view_host(), L"", |
| 725 | L"window.domAutomationController.send(getFocusedElement());", |
| 726 | &actual)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 727 | ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); |
| 728 | } |
| 729 | |
| 730 | // At this point the renderer has sent us a message asking to advance the |
| 731 | // focus (as the end of the focus loop was reached in the renderer). |
| 732 | // We need to run the message loop to process it. |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 733 | ui_test_utils::RunAllPendingInMessageLoop(); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | |
| 737 | // Focus stays on page with interstitials. |
[email protected] | cb93193 | 2011-05-03 19:57:33 | [diff] [blame] | 738 | // http://crbug.com/81451 |
[email protected] | fd5a53e | 2011-09-15 14:09:05 | [diff] [blame] | 739 | #if defined(OS_MACOSX) || defined(OS_WIN) |
[email protected] | 4d245165 | 2012-02-14 23:54:26 | [diff] [blame] | 740 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_InterstitialFocus) { |
[email protected] | cb93193 | 2011-05-03 19:57:33 | [diff] [blame] | 741 | #else |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 742 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { |
[email protected] | cb93193 | 2011-05-03 19:57:33 | [diff] [blame] | 743 | #endif |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 744 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 745 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 746 | |
| 747 | // First we navigate to our test page. |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 748 | GURL url = test_server()->GetURL(kSimplePage); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 749 | ui_test_utils::NavigateToURL(browser(), url); |
| 750 | |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 751 | // Page should have focus. |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 752 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 753 | EXPECT_TRUE(chrome::GetActiveWebContents(browser())->GetRenderViewHost()-> |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 754 | GetView()->HasFocus()); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 755 | |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 756 | // Let's show an interstitial. |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 757 | TestInterstitialPage* interstitial_page = |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 758 | new TestInterstitialPage(chrome::GetActiveWebContents(browser()), |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 759 | true, GURL("http://interstitial.com")); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 760 | // Give some time for the interstitial to show. |
| 761 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
[email protected] | a778709f | 2011-12-10 00:28:17 | [diff] [blame] | 762 | MessageLoop::QuitClosure(), |
[email protected] | 7e56010 | 2012-03-08 20:58:42 | [diff] [blame] | 763 | base::TimeDelta::FromSeconds(1)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 764 | ui_test_utils::RunMessageLoop(); |
| 765 | |
| 766 | // The interstitial should have focus now. |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 767 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 768 | EXPECT_TRUE(interstitial_page->HasFocus()); |
| 769 | |
| 770 | // Hide the interstitial. |
| 771 | interstitial_page->DontProceed(); |
| 772 | |
| 773 | // Focus should be back on the original page. |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 774 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 9e0c83a | 2009-05-06 19:44:37 | [diff] [blame] | 775 | } |
| 776 | |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 777 | // Make sure Find box can request focus, even when it is already open. |
[email protected] | 2004b76 | 2011-05-05 22:43:20 | [diff] [blame] | 778 | // Flaky on mac and valgrind. http://crbug.com/67301. |
| 779 | #if defined(OS_MACOSX) |
[email protected] | 4d245165 | 2012-02-14 23:54:26 | [diff] [blame] | 780 | #define MAYBE_FindFocusTest DISABLED_FindFocusTest |
[email protected] | 2004b76 | 2011-05-05 22:43:20 | [diff] [blame] | 781 | #else |
| 782 | #define MAYBE_FindFocusTest FindFocusTest |
| 783 | #endif |
[email protected] | c39e233d | 2012-05-18 13:24:12 | [diff] [blame] | 784 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FindFocusTest) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 785 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 786 | ASSERT_TRUE(test_server()->Start()); |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 787 | |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 788 | // Open some page (any page that doesn't steal focus). |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 789 | GURL url = test_server()->GetURL(kTypicalPage); |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 790 | ui_test_utils::NavigateToURL(browser(), url); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 791 | |
[email protected] | a711df10 | 2010-12-14 09:47:03 | [diff] [blame] | 792 | EXPECT_TRUE(ChromeInForeground()); |
| 793 | |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 794 | #if defined(OS_MACOSX) |
| 795 | // Press Cmd+F, which will make the Find box open and request focus. |
[email protected] | 1d00068 | 2010-08-23 16:21:28 | [diff] [blame] | 796 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 797 | browser(), ui::VKEY_F, false, false, false, true)); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 798 | #else |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 799 | // Press Ctrl+F, which will make the Find box open and request focus. |
[email protected] | 1d00068 | 2010-08-23 16:21:28 | [diff] [blame] | 800 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 801 | browser(), ui::VKEY_F, true, false, false, false)); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 802 | #endif |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 803 | |
[email protected] | a9c060ca | 2012-01-05 20:43:41 | [diff] [blame] | 804 | ASSERT_TRUE(WaitForFocusChange(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 805 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 806 | chrome::FocusLocationBar(browser()); |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 807 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 808 | |
| 809 | // Now press Ctrl+F again and focus should move to the Find box. |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 810 | #if defined(OS_MACOSX) |
[email protected] | 1d00068 | 2010-08-23 16:21:28 | [diff] [blame] | 811 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 812 | browser(), ui::VKEY_F, false, false, false, true)); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 813 | #else |
[email protected] | 1d00068 | 2010-08-23 16:21:28 | [diff] [blame] | 814 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 815 | browser(), ui::VKEY_F, true, false, false, false)); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 816 | #endif |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 817 | ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 818 | |
| 819 | // Set focus to the page. |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 820 | ClickOnView(VIEW_ID_TAB_CONTAINER); |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 821 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 822 | |
| 823 | // Now press Ctrl+F again and focus should move to the Find box. |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 824 | #if defined(OS_MACOSX) |
[email protected] | 1d00068 | 2010-08-23 16:21:28 | [diff] [blame] | 825 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 826 | browser(), ui::VKEY_F, false, false, false, true)); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 827 | #else |
[email protected] | 1d00068 | 2010-08-23 16:21:28 | [diff] [blame] | 828 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 829 | browser(), ui::VKEY_F, true, false, false, false)); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 830 | #endif |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 831 | |
[email protected] | a9c060ca | 2012-01-05 20:43:41 | [diff] [blame] | 832 | ASSERT_TRUE(WaitForFocusChange(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
[email protected] | 9bd491ee | 2008-12-10 22:31:07 | [diff] [blame] | 833 | } |
[email protected] | 401513c | 2009-03-12 00:21:28 | [diff] [blame] | 834 | |
| 835 | // Makes sure the focus is in the right location when opening the different |
| 836 | // types of tabs. |
[email protected] | c9292867 | 2010-11-09 18:31:07 | [diff] [blame] | 837 | // Flaky, http://crbug.com/62539. |
[email protected] | 4d245165 | 2012-02-14 23:54:26 | [diff] [blame] | 838 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabInitialFocus) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 839 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 9ba21ede | 2010-07-30 01:11:07 | [diff] [blame] | 840 | |
[email protected] | 401513c | 2009-03-12 00:21:28 | [diff] [blame] | 841 | // Open the history tab, focus should be on the tab contents. |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 842 | chrome::ShowHistory(browser()); |
[email protected] | a3f343f | 2010-10-06 23:39:42 | [diff] [blame] | 843 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 844 | chrome::GetActiveWebContents(browser()))); |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 845 | EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 401513c | 2009-03-12 00:21:28 | [diff] [blame] | 846 | |
| 847 | // Open the new tab, focus should be on the location bar. |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 848 | chrome::NewTab(browser()); |
[email protected] | a3f343f | 2010-10-06 23:39:42 | [diff] [blame] | 849 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 850 | chrome::GetActiveWebContents(browser()))); |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 851 | EXPECT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | 401513c | 2009-03-12 00:21:28 | [diff] [blame] | 852 | |
| 853 | // Open the download tab, focus should be on the tab contents. |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 854 | chrome::ShowDownloads(browser()); |
[email protected] | a3f343f | 2010-10-06 23:39:42 | [diff] [blame] | 855 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 856 | chrome::GetActiveWebContents(browser()))); |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 857 | EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 3e3f0eb | 2009-06-22 18:33:43 | [diff] [blame] | 858 | |
| 859 | // Open about:blank, focus should be on the location bar. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 860 | chrome::AddSelectedTabWithURL(browser(), GURL(chrome::kAboutBlankURL), |
| 861 | content::PAGE_TRANSITION_LINK); |
[email protected] | a3f343f | 2010-10-06 23:39:42 | [diff] [blame] | 862 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 863 | chrome::GetActiveWebContents(browser()))); |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 864 | EXPECT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | 401513c | 2009-03-12 00:21:28 | [diff] [blame] | 865 | } |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 866 | |
| 867 | // Tests that focus goes where expected when using reload. |
[email protected] | e4f4e0b | 2009-10-13 19:58:21 | [diff] [blame] | 868 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 869 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 870 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 871 | |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 872 | // Open the new tab, reload. |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 873 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame^] | 874 | content::WindowedNotificationObserver observer( |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 875 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 876 | content::NotificationService::AllSources()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 877 | chrome::NewTab(browser()); |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 878 | observer.Wait(); |
| 879 | } |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 880 | ui_test_utils::RunAllPendingInMessageLoop(); |
| 881 | |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 882 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame^] | 883 | content::WindowedNotificationObserver observer( |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 884 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 885 | content::Source<NavigationController>( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 886 | &chrome::GetActiveWebContents(browser())->GetController())); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 887 | chrome::Reload(browser(), CURRENT_TAB); |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 888 | observer.Wait(); |
| 889 | } |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 890 | // Focus should stay on the location bar. |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 891 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 892 | |
| 893 | // Open a regular page, focus the location bar, reload. |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 894 | ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 895 | chrome::FocusLocationBar(browser()); |
[email protected] | 0b8fa8b | 2011-12-07 00:54:52 | [diff] [blame] | 896 | ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 897 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame^] | 898 | content::WindowedNotificationObserver observer( |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 899 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 900 | content::Source<NavigationController>( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 901 | &chrome::GetActiveWebContents(browser())->GetController())); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 902 | chrome::Reload(browser(), CURRENT_TAB); |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 903 | observer.Wait(); |
| 904 | } |
[email protected] | 9ba21ede | 2010-07-30 01:11:07 | [diff] [blame] | 905 | |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 906 | // Focus should now be on the tab contents. |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 907 | chrome::ShowDownloads(browser()); |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 908 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | // Tests that focus goes where expected when using reload on a crashed tab. |
[email protected] | 160f29ad | 2010-10-28 15:43:27 | [diff] [blame] | 912 | IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) { |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 913 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 914 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 915 | |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 916 | // Open a regular page, crash, reload. |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 917 | ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 918 | ui_test_utils::CrashTab(chrome::GetActiveWebContents(browser())); |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 919 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame^] | 920 | content::WindowedNotificationObserver observer( |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 921 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 922 | content::Source<NavigationController>( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 923 | &chrome::GetActiveWebContents(browser())->GetController())); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 924 | chrome::Reload(browser(), CURRENT_TAB); |
[email protected] | 6b4e8e4 | 2011-08-17 19:36:06 | [diff] [blame] | 925 | observer.Wait(); |
| 926 | } |
[email protected] | 9ba21ede | 2010-07-30 01:11:07 | [diff] [blame] | 927 | |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 928 | // Focus should now be on the tab contents. |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 929 | chrome::ShowDownloads(browser()); |
[email protected] | f2159ba | 2012-04-17 19:13:21 | [diff] [blame] | 930 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 931 | } |
[email protected] | 629e034 | 2010-07-27 23:30:13 | [diff] [blame] | 932 | |
| 933 | } // namespace |