OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/view_ids.h" | 5 #include "chrome/browser/view_ids.h" |
6 #include "chrome/views/view.h" | 6 #include "chrome/views/view.h" |
7 #include "chrome/test/automation/browser_proxy.h" | 7 #include "chrome/test/automation/browser_proxy.h" |
8 #include "chrome/test/automation/window_proxy.h" | 8 #include "chrome/test/automation/window_proxy.h" |
9 #include "chrome/test/automation/tab_proxy.h" | 9 #include "chrome/test/automation/tab_proxy.h" |
10 #include "chrome/test/ui/ui_test.h" | 10 #include "chrome/test/ui/ui_test.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 // Wait a bit to let the click be processed. | 49 // Wait a bit to let the click be processed. |
50 ::Sleep(kActionDelayMs); | 50 ::Sleep(kActionDelayMs); |
51 | 51 |
52 return true; | 52 return true; |
53 } | 53 } |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 TEST_F(BrowserFocusTest, BrowsersRememberFocus) { | 57 TEST_F(BrowserFocusTest, BrowsersRememberFocus) { |
58 TestServer server(kDocRoot); | 58 scoped_refptr<HTTPTestServer> server = |
| 59 HTTPTestServer::CreateServer(kDocRoot); |
| 60 ASSERT_TRUE(NULL != server.get()); |
59 | 61 |
60 // First we navigate to our test page. | 62 // First we navigate to our test page. |
61 GURL url = server.TestServerPageW(kSimplePage); | 63 GURL url = server->TestServerPageW(kSimplePage); |
62 scoped_ptr<TabProxy> tab(GetActiveTab()); | 64 scoped_ptr<TabProxy> tab(GetActiveTab()); |
63 EXPECT_NE(AUTOMATION_MSG_NAVIGATION_ERROR, tab->NavigateToURL(url)); | 65 EXPECT_NE(AUTOMATION_MSG_NAVIGATION_ERROR, tab->NavigateToURL(url)); |
64 | 66 |
65 // The focus should be on the Tab contents. | 67 // The focus should be on the Tab contents. |
66 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); | 68 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); |
67 ASSERT_TRUE(window.get() != NULL); | 69 ASSERT_TRUE(window.get() != NULL); |
68 | 70 |
69 scoped_ptr<BrowserProxy> browser(automation()-> | 71 scoped_ptr<BrowserProxy> browser(automation()-> |
70 GetBrowserForWindow(window.get())); | 72 GetBrowserForWindow(window.get())); |
71 ASSERT_TRUE(browser.get() != NULL); | 73 ASSERT_TRUE(browser.get() != NULL); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // Switch back to the second browser, focus should still be on the page. | 125 // Switch back to the second browser, focus should still be on the page. |
124 EXPECT_TRUE(new_window->Activate()); | 126 EXPECT_TRUE(new_window->Activate()); |
125 EXPECT_TRUE(new_window->GetFocusedViewID(&focused_view_id)); | 127 EXPECT_TRUE(new_window->GetFocusedViewID(&focused_view_id)); |
126 EXPECT_EQ(VIEW_ID_TAB_CONTAINER, focused_view_id); | 128 EXPECT_EQ(VIEW_ID_TAB_CONTAINER, focused_view_id); |
127 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); | 129 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); |
128 EXPECT_EQ(-1, focused_view_id); | 130 EXPECT_EQ(-1, focused_view_id); |
129 } | 131 } |
130 | 132 |
131 // Tabs remember focus. | 133 // Tabs remember focus. |
132 TEST_F(BrowserFocusTest, TabsRememberFocus) { | 134 TEST_F(BrowserFocusTest, TabsRememberFocus) { |
133 TestServer server(kDocRoot); | 135 scoped_refptr<HTTPTestServer> server = |
| 136 HTTPTestServer::CreateServer(kDocRoot); |
| 137 ASSERT_TRUE(NULL != server.get()); |
134 | 138 |
135 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); | 139 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); |
136 ASSERT_TRUE(window.get() != NULL); | 140 ASSERT_TRUE(window.get() != NULL); |
137 scoped_ptr<BrowserProxy> browser( | 141 scoped_ptr<BrowserProxy> browser( |
138 automation()->GetBrowserForWindow(window.get())); | 142 automation()->GetBrowserForWindow(window.get())); |
139 ASSERT_TRUE(browser.get() != NULL); | 143 ASSERT_TRUE(browser.get() != NULL); |
140 | 144 |
141 // First we navigate to our test page. | 145 // First we navigate to our test page. |
142 GURL url = server.TestServerPageW(kSimplePage); | 146 GURL url = server->TestServerPageW(kSimplePage); |
143 scoped_ptr<TabProxy> tab(GetActiveTab()); | 147 scoped_ptr<TabProxy> tab(GetActiveTab()); |
144 tab->NavigateToURL(url); | 148 tab->NavigateToURL(url); |
145 | 149 |
146 // Create several tabs. | 150 // Create several tabs. |
147 EXPECT_TRUE(browser->AppendTab(url)); | 151 EXPECT_TRUE(browser->AppendTab(url)); |
148 EXPECT_TRUE(browser->AppendTab(url)); | 152 EXPECT_TRUE(browser->AppendTab(url)); |
149 EXPECT_TRUE(browser->AppendTab(url)); | 153 EXPECT_TRUE(browser->AppendTab(url)); |
150 EXPECT_TRUE(browser->AppendTab(url)); | 154 EXPECT_TRUE(browser->AppendTab(url)); |
151 | 155 |
152 int tab_count; | 156 int tab_count; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 VIEW_ID_LOCATION_BAR; | 191 VIEW_ID_LOCATION_BAR; |
188 int focused_view_id; | 192 int focused_view_id; |
189 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); | 193 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); |
190 EXPECT_EQ(exp_view_id, focused_view_id); | 194 EXPECT_EQ(exp_view_id, focused_view_id); |
191 } | 195 } |
192 } | 196 } |
193 } | 197 } |
194 | 198 |
195 // Background window does not steal focus. | 199 // Background window does not steal focus. |
196 TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { | 200 TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { |
197 TestServer server(kDocRoot); | 201 scoped_refptr<HTTPTestServer> server = |
| 202 HTTPTestServer::CreateServer(kDocRoot); |
| 203 ASSERT_TRUE(NULL != server.get()); |
198 | 204 |
199 // First we navigate to our test page. | 205 // First we navigate to our test page. |
200 GURL simple_page_url = server.TestServerPageW(kSimplePage); | 206 GURL simple_page_url = server->TestServerPageW(kSimplePage); |
201 scoped_ptr<TabProxy> tab(GetActiveTab()); | 207 scoped_ptr<TabProxy> tab(GetActiveTab()); |
202 tab->NavigateToURL(simple_page_url); | 208 tab->NavigateToURL(simple_page_url); |
203 | 209 |
204 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); | 210 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); |
205 ASSERT_TRUE(window.get() != NULL); | 211 ASSERT_TRUE(window.get() != NULL); |
206 scoped_ptr<BrowserProxy> browser( | 212 scoped_ptr<BrowserProxy> browser( |
207 automation()->GetBrowserForWindow(window.get())); | 213 automation()->GetBrowserForWindow(window.get())); |
208 ASSERT_TRUE(browser.get() != NULL); | 214 ASSERT_TRUE(browser.get() != NULL); |
209 | 215 |
210 // Open a new browser window. | 216 // Open a new browser window. |
211 EXPECT_TRUE(automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)); | 217 EXPECT_TRUE(automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)); |
212 scoped_ptr<WindowProxy> new_window(automation()->GetActiveWindow()); | 218 scoped_ptr<WindowProxy> new_window(automation()->GetActiveWindow()); |
213 ASSERT_TRUE(window.get() != NULL); | 219 ASSERT_TRUE(window.get() != NULL); |
214 scoped_ptr<BrowserProxy> new_browser( | 220 scoped_ptr<BrowserProxy> new_browser( |
215 automation()->GetBrowserForWindow(new_window.get())); | 221 automation()->GetBrowserForWindow(new_window.get())); |
216 ASSERT_TRUE(new_browser.get() != NULL); | 222 ASSERT_TRUE(new_browser.get() != NULL); |
217 | 223 |
218 GURL steal_focus_url = server.TestServerPageW(kStealFocusPage); | 224 GURL steal_focus_url = server->TestServerPageW(kStealFocusPage); |
219 new_browser->AppendTab(steal_focus_url); | 225 new_browser->AppendTab(steal_focus_url); |
220 | 226 |
221 // Make the first browser active | 227 // Make the first browser active |
222 EXPECT_TRUE(window->Activate()); | 228 EXPECT_TRUE(window->Activate()); |
223 | 229 |
224 // Wait for the focus to be stolen by the other browser. | 230 // Wait for the focus to be stolen by the other browser. |
225 ::Sleep(2000); | 231 ::Sleep(2000); |
226 | 232 |
227 // Make sure the 1st browser window is still active. | 233 // Make sure the 1st browser window is still active. |
228 bool is_active = false; | 234 bool is_active = false; |
229 EXPECT_TRUE(window->IsActive(&is_active)); | 235 EXPECT_TRUE(window->IsActive(&is_active)); |
230 EXPECT_TRUE(is_active); | 236 EXPECT_TRUE(is_active); |
231 } | 237 } |
232 | 238 |
233 // Page cannot steal focus when focus is on location bar. | 239 // Page cannot steal focus when focus is on location bar. |
234 TEST_F(BrowserFocusTest, LocationBarLockFocus) { | 240 TEST_F(BrowserFocusTest, LocationBarLockFocus) { |
235 TestServer server(kDocRoot); | 241 scoped_refptr<HTTPTestServer> server = |
| 242 HTTPTestServer::CreateServer(kDocRoot); |
| 243 ASSERT_TRUE(NULL != server.get()); |
236 | 244 |
237 // Open the page that steals focus. | 245 // Open the page that steals focus. |
238 GURL url = server.TestServerPageW(kStealFocusPage); | 246 GURL url = server->TestServerPageW(kStealFocusPage); |
239 scoped_ptr<TabProxy> tab(GetActiveTab()); | 247 scoped_ptr<TabProxy> tab(GetActiveTab()); |
240 tab->NavigateToURL(url); | 248 tab->NavigateToURL(url); |
241 | 249 |
242 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); | 250 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); |
243 ASSERT_TRUE(window.get() != NULL); | 251 ASSERT_TRUE(window.get() != NULL); |
244 scoped_ptr<BrowserProxy> browser( | 252 scoped_ptr<BrowserProxy> browser( |
245 automation()->GetBrowserForWindow(window.get())); | 253 automation()->GetBrowserForWindow(window.get())); |
246 ASSERT_TRUE(browser.get() != NULL); | 254 ASSERT_TRUE(browser.get() != NULL); |
247 | 255 |
248 // Click on the location bar. | 256 // Click on the location bar. |
249 gfx::Rect bounds; | 257 gfx::Rect bounds; |
250 EXPECT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &bounds, true)); | 258 EXPECT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &bounds, true)); |
251 POINT click(bounds.CenterPoint().ToPOINT()); | 259 POINT click(bounds.CenterPoint().ToPOINT()); |
252 EXPECT_TRUE(window->SimulateOSClick(click, | 260 EXPECT_TRUE(window->SimulateOSClick(click, |
253 views::Event::EF_LEFT_BUTTON_DOWN)); | 261 views::Event::EF_LEFT_BUTTON_DOWN)); |
254 ::Sleep(kActionDelayMs); | 262 ::Sleep(kActionDelayMs); |
255 | 263 |
256 // Wait for the page to steal focus. | 264 // Wait for the page to steal focus. |
257 ::Sleep(2000); | 265 ::Sleep(2000); |
258 | 266 |
259 // Make sure the location bar is still focused. | 267 // Make sure the location bar is still focused. |
260 int focused_view_id; | 268 int focused_view_id; |
261 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); | 269 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); |
262 EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id); | 270 EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id); |
263 } | 271 } |
264 | 272 |
265 // Focus traversal | 273 // Focus traversal |
266 TEST_F(BrowserFocusTest, FocusTraversal) { | 274 TEST_F(BrowserFocusTest, FocusTraversal) { |
267 TestServer server(kDocRoot); | 275 scoped_refptr<HTTPTestServer> server = |
| 276 HTTPTestServer::CreateServer(kDocRoot); |
| 277 ASSERT_TRUE(NULL != server.get()); |
268 | 278 |
269 // Open the page the test page. | 279 // Open the page the test page. |
270 GURL url = server.TestServerPageW(kTypicalPage); | 280 GURL url = server->TestServerPageW(kTypicalPage); |
271 scoped_ptr<TabProxy> tab(GetActiveTab()); | 281 scoped_ptr<TabProxy> tab(GetActiveTab()); |
272 tab->NavigateToURL(url); | 282 tab->NavigateToURL(url); |
273 | 283 |
274 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); | 284 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); |
275 ASSERT_TRUE(window.get() != NULL); | 285 ASSERT_TRUE(window.get() != NULL); |
276 scoped_ptr<BrowserProxy> browser( | 286 scoped_ptr<BrowserProxy> browser( |
277 automation()->GetBrowserForWindow(window.get())); | 287 automation()->GetBrowserForWindow(window.get())); |
278 ASSERT_TRUE(browser.get() != NULL); | 288 ASSERT_TRUE(browser.get() != NULL); |
279 | 289 |
280 // Click on the location bar. | 290 // Click on the location bar. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", | 340 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", |
331 L"window.domAutomationController.send(getFocusedElement());", | 341 L"window.domAutomationController.send(getFocusedElement());", |
332 &actual)); | 342 &actual)); |
333 ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); | 343 ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); |
334 } | 344 } |
335 } | 345 } |
336 } | 346 } |
337 | 347 |
338 // Make sure Find box can request focus, even when it is already open. | 348 // Make sure Find box can request focus, even when it is already open. |
339 TEST_F(BrowserFocusTest, FindFocusTest) { | 349 TEST_F(BrowserFocusTest, FindFocusTest) { |
340 TestServer server(kDocRoot); | 350 scoped_refptr<HTTPTestServer> server = |
| 351 HTTPTestServer::CreateServer(kDocRoot); |
| 352 ASSERT_TRUE(NULL != server.get()); |
341 | 353 |
342 // Open some page (any page that doesn't steal focus). | 354 // Open some page (any page that doesn't steal focus). |
343 GURL url = server.TestServerPageW(kTypicalPage); | 355 GURL url = server->TestServerPageW(kTypicalPage); |
344 scoped_ptr<TabProxy> tab(GetActiveTab()); | 356 scoped_ptr<TabProxy> tab(GetActiveTab()); |
345 tab->NavigateToURL(url); | 357 tab->NavigateToURL(url); |
346 | 358 |
347 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); | 359 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); |
348 ASSERT_TRUE(window.get() != NULL); | 360 ASSERT_TRUE(window.get() != NULL); |
349 scoped_ptr<BrowserProxy> browser( | 361 scoped_ptr<BrowserProxy> browser( |
350 automation()->GetBrowserForWindow(window.get())); | 362 automation()->GetBrowserForWindow(window.get())); |
351 ASSERT_TRUE(browser.get() != NULL); | 363 ASSERT_TRUE(browser.get() != NULL); |
352 | 364 |
353 // Press Ctrl+F, which will make the Find box open and request focus. | 365 // Press Ctrl+F, which will make the Find box open and request focus. |
(...skipping 29 matching lines...) Expand all Loading... |
383 ::Sleep(kActionDelayMs); | 395 ::Sleep(kActionDelayMs); |
384 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); | 396 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); |
385 EXPECT_EQ(VIEW_ID_TAB_CONTAINER, focused_view_id); | 397 EXPECT_EQ(VIEW_ID_TAB_CONTAINER, focused_view_id); |
386 | 398 |
387 // Now press Ctrl+F again and focus should move to the Find box. | 399 // Now press Ctrl+F again and focus should move to the Find box. |
388 EXPECT_TRUE(window->SimulateOSKeyPress(VK_F, views::Event::EF_CONTROL_DOWN)); | 400 EXPECT_TRUE(window->SimulateOSKeyPress(VK_F, views::Event::EF_CONTROL_DOWN)); |
389 ::Sleep(kActionDelayMs); | 401 ::Sleep(kActionDelayMs); |
390 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); | 402 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); |
391 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view_id); | 403 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view_id); |
392 } | 404 } |
OLD | NEW |