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