Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Side by Side Diff: chrome/browser/browser_focus_uitest.cc

Issue 115830: Turn BrowserView::GetBrowserViewForNativeView() into GetBrowserViewForNativeW... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/ref_counted.h" 6 #include "base/ref_counted.h"
7 #include "chrome/browser/automation/ui_controls.h" 7 #include "chrome/browser/automation/ui_controls.h"
8 #include "chrome/browser/browser.h" 8 #include "chrome/browser/browser.h"
9 #include "chrome/browser/renderer_host/render_widget_host_view.h" 9 #include "chrome/browser/renderer_host/render_widget_host_view.h"
10 #include "chrome/browser/tab_contents/interstitial_page.h" 10 #include "chrome/browser/tab_contents/interstitial_page.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) { 99 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) {
100 HTTPTestServer* server = StartHTTPServer(); 100 HTTPTestServer* server = StartHTTPServer();
101 101
102 // First we navigate to our test page. 102 // First we navigate to our test page.
103 GURL url = server->TestServerPageW(kSimplePage); 103 GURL url = server->TestServerPageW(kSimplePage);
104 ui_test_utils::NavigateToURL(browser(), url); 104 ui_test_utils::NavigateToURL(browser(), url);
105 105
106 // The focus should be on the Tab contents. 106 // The focus should be on the Tab contents.
107 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 107 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
108 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeView(hwnd); 108 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
109 ASSERT_TRUE(browser_view); 109 ASSERT_TRUE(browser_view);
110 views::FocusManager* focus_manager = 110 views::FocusManager* focus_manager =
111 views::FocusManager::GetFocusManager(hwnd); 111 views::FocusManager::GetFocusManager(hwnd);
112 ASSERT_TRUE(focus_manager); 112 ASSERT_TRUE(focus_manager);
113 113
114 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 114 EXPECT_EQ(browser_view->contents_container()->GetFocusView(),
115 focus_manager->GetFocusedView()); 115 focus_manager->GetFocusedView());
116 116
117 // Now hide the window, show it again, the focus should not have changed. 117 // Now hide the window, show it again, the focus should not have changed.
118 // TODO(jcampan): retrieve the WidgetWin and show/hide on it instead of 118 // TODO(jcampan): retrieve the WidgetWin and show/hide on it instead of
(...skipping 19 matching lines...) Expand all
138 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); 138 EXPECT_EQ(location_bar, focus_manager->GetFocusedView());
139 139
140 // Open a new browser window. 140 // Open a new browser window.
141 Browser* browser2 = Browser::Create(browser()->profile()); 141 Browser* browser2 = Browser::Create(browser()->profile());
142 ASSERT_TRUE(browser2); 142 ASSERT_TRUE(browser2);
143 browser2->tabstrip_model()->delegate()->AddBlankTab(true); 143 browser2->tabstrip_model()->delegate()->AddBlankTab(true);
144 browser2->window()->Show(); 144 browser2->window()->Show();
145 ui_test_utils::NavigateToURL(browser2, url); 145 ui_test_utils::NavigateToURL(browser2, url);
146 146
147 HWND hwnd2 = reinterpret_cast<HWND>(browser2->window()->GetNativeHandle()); 147 HWND hwnd2 = reinterpret_cast<HWND>(browser2->window()->GetNativeHandle());
148 BrowserView* browser_view2 = BrowserView::GetBrowserViewForNativeView(hwnd2); 148 BrowserView* browser_view2 =
149 BrowserView::GetBrowserViewForNativeWindow(hwnd2);
149 ASSERT_TRUE(browser_view2); 150 ASSERT_TRUE(browser_view2);
150 views::FocusManager* focus_manager2 = 151 views::FocusManager* focus_manager2 =
151 views::FocusManager::GetFocusManager(hwnd2); 152 views::FocusManager::GetFocusManager(hwnd2);
152 ASSERT_TRUE(focus_manager2); 153 ASSERT_TRUE(focus_manager2);
153 EXPECT_EQ(browser_view2->contents_container()->GetFocusView(), 154 EXPECT_EQ(browser_view2->contents_container()->GetFocusView(),
154 focus_manager2->GetFocusedView()); 155 focus_manager2->GetFocusedView());
155 156
156 // Switch to the 1st browser window, focus should still be on the location 157 // Switch to the 1st browser window, focus should still be on the location
157 // bar and the second browser should have nothing focused. 158 // bar and the second browser should have nothing focused.
158 browser()->window()->Activate(); 159 browser()->window()->Activate();
(...skipping 12 matching lines...) Expand all
171 172
172 // Tabs remember focus. 173 // Tabs remember focus.
173 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) { 174 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) {
174 HTTPTestServer* server = StartHTTPServer(); 175 HTTPTestServer* server = StartHTTPServer();
175 176
176 // First we navigate to our test page. 177 // First we navigate to our test page.
177 GURL url = server->TestServerPageW(kSimplePage); 178 GURL url = server->TestServerPageW(kSimplePage);
178 ui_test_utils::NavigateToURL(browser(), url); 179 ui_test_utils::NavigateToURL(browser(), url);
179 180
180 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 181 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
181 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeView(hwnd); 182 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
182 ASSERT_TRUE(browser_view); 183 ASSERT_TRUE(browser_view);
183 184
184 views::FocusManager* focus_manager = 185 views::FocusManager* focus_manager =
185 views::FocusManager::GetFocusManager(hwnd); 186 views::FocusManager::GetFocusManager(hwnd);
186 ASSERT_TRUE(focus_manager); 187 ASSERT_TRUE(focus_manager);
187 188
188 // Create several tabs. 189 // Create several tabs.
189 for (int i = 0; i < 4; ++i) { 190 for (int i = 0; i < 4; ++i) {
190 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1, false , 191 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1, false ,
191 NULL); 192 NULL);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 ui_test_utils::NavigateToURL(browser2, steal_focus_url); 248 ui_test_utils::NavigateToURL(browser2, steal_focus_url);
248 249
249 // Activate the first browser. 250 // Activate the first browser.
250 browser()->window()->Activate(); 251 browser()->window()->Activate();
251 252
252 // Wait for the focus to be stolen by the other browser. 253 // Wait for the focus to be stolen by the other browser.
253 ::Sleep(2000); 254 ::Sleep(2000);
254 255
255 // Make sure the first browser is still active. 256 // Make sure the first browser is still active.
256 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 257 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
257 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeView(hwnd); 258 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
258 ASSERT_TRUE(browser_view); 259 ASSERT_TRUE(browser_view);
259 EXPECT_TRUE(browser_view->frame()->GetWindow()->IsActive()); 260 EXPECT_TRUE(browser_view->frame()->GetWindow()->IsActive());
260 261
261 // Close the 2nd browser to avoid a DCHECK(). 262 // Close the 2nd browser to avoid a DCHECK().
262 HWND hwnd2 = reinterpret_cast<HWND>(browser2->window()->GetNativeHandle()); 263 HWND hwnd2 = reinterpret_cast<HWND>(browser2->window()->GetNativeHandle());
263 BrowserView* browser_view2 = BrowserView::GetBrowserViewForNativeView(hwnd2); 264 BrowserView* browser_view2 =
265 BrowserView::GetBrowserViewForNativeWindow(hwnd2);
264 browser_view2->Close(); 266 browser_view2->Close();
265 } 267 }
266 268
267 // Page cannot steal focus when focus is on location bar. 269 // Page cannot steal focus when focus is on location bar.
268 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { 270 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) {
269 HTTPTestServer* server = StartHTTPServer(); 271 HTTPTestServer* server = StartHTTPServer();
270 272
271 // Open the page that steals focus. 273 // Open the page that steals focus.
272 GURL url = server->TestServerPageW(kStealFocusPage); 274 GURL url = server->TestServerPageW(kStealFocusPage);
273 ui_test_utils::NavigateToURL(browser(), url); 275 ui_test_utils::NavigateToURL(browser(), url);
274 276
275 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 277 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
276 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeView(hwnd); 278 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
277 views::FocusManager* focus_manager = 279 views::FocusManager* focus_manager =
278 views::FocusManager::GetFocusManager(hwnd); 280 views::FocusManager::GetFocusManager(hwnd);
279 281
280 // Click on the location bar. 282 // Click on the location bar.
281 LocationBarView* location_bar = browser_view->GetLocationBarView(); 283 LocationBarView* location_bar = browser_view->GetLocationBarView();
282 ui_controls::MoveMouseToCenterAndPress(location_bar, 284 ui_controls::MoveMouseToCenterAndPress(location_bar,
283 ui_controls::LEFT, 285 ui_controls::LEFT,
284 ui_controls::DOWN | ui_controls::UP, 286 ui_controls::DOWN | ui_controls::UP,
285 new MessageLoop::QuitTask()); 287 new MessageLoop::QuitTask());
286 ui_test_utils::RunMessageLoop(); 288 ui_test_utils::RunMessageLoop();
287 289
288 // Wait for the page to steal focus. 290 // Wait for the page to steal focus.
289 ::Sleep(2000); 291 ::Sleep(2000);
290 292
291 // Make sure the location bar is still focused. 293 // Make sure the location bar is still focused.
292 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); 294 EXPECT_EQ(location_bar, focus_manager->GetFocusedView());
293 } 295 }
294 296
295 // Focus traversal on a regular page. 297 // Focus traversal on a regular page.
296 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversal) { 298 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversal) {
297 HTTPTestServer* server = StartHTTPServer(); 299 HTTPTestServer* server = StartHTTPServer();
298 300
299 // First we navigate to our test page. 301 // First we navigate to our test page.
300 GURL url = server->TestServerPageW(kTypicalPage); 302 GURL url = server->TestServerPageW(kTypicalPage);
301 ui_test_utils::NavigateToURL(browser(), url); 303 ui_test_utils::NavigateToURL(browser(), url);
302 304
303 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 305 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
304 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeView(hwnd); 306 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
305 views::FocusManager* focus_manager = 307 views::FocusManager* focus_manager =
306 views::FocusManager::GetFocusManager(hwnd); 308 views::FocusManager::GetFocusManager(hwnd);
307 309
308 // Click on the location bar. 310 // Click on the location bar.
309 LocationBarView* location_bar = browser_view->GetLocationBarView(); 311 LocationBarView* location_bar = browser_view->GetLocationBarView();
310 ui_controls::MoveMouseToCenterAndPress(location_bar, 312 ui_controls::MoveMouseToCenterAndPress(location_bar,
311 ui_controls::LEFT, 313 ui_controls::LEFT,
312 ui_controls::DOWN | ui_controls::UP, 314 ui_controls::DOWN | ui_controls::UP,
313 new MessageLoop::QuitTask()); 315 new MessageLoop::QuitTask());
314 ui_test_utils::RunMessageLoop(); 316 ui_test_utils::RunMessageLoop();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 386
385 // Focus traversal while an interstitial is showing. 387 // Focus traversal while an interstitial is showing.
386 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversalOnInterstitial) { 388 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversalOnInterstitial) {
387 HTTPTestServer* server = StartHTTPServer(); 389 HTTPTestServer* server = StartHTTPServer();
388 390
389 // First we navigate to our test page. 391 // First we navigate to our test page.
390 GURL url = server->TestServerPageW(kSimplePage); 392 GURL url = server->TestServerPageW(kSimplePage);
391 ui_test_utils::NavigateToURL(browser(), url); 393 ui_test_utils::NavigateToURL(browser(), url);
392 394
393 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 395 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
394 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeView(hwnd); 396 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
395 views::FocusManager* focus_manager = 397 views::FocusManager* focus_manager =
396 views::FocusManager::GetFocusManager(hwnd); 398 views::FocusManager::GetFocusManager(hwnd);
397 399
398 // Focus should be on the page. 400 // Focus should be on the page.
399 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 401 EXPECT_EQ(browser_view->contents_container()->GetFocusView(),
400 focus_manager->GetFocusedView()); 402 focus_manager->GetFocusedView());
401 403
402 // Let's show an interstitial. 404 // Let's show an interstitial.
403 TestInterstitialPage* interstitial_page = 405 TestInterstitialPage* interstitial_page =
404 new TestInterstitialPage(browser()->GetSelectedTabContents(), 406 new TestInterstitialPage(browser()->GetSelectedTabContents(),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 481
480 // Focus stays on page with interstitials. 482 // Focus stays on page with interstitials.
481 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { 483 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) {
482 HTTPTestServer* server = StartHTTPServer(); 484 HTTPTestServer* server = StartHTTPServer();
483 485
484 // First we navigate to our test page. 486 // First we navigate to our test page.
485 GURL url = server->TestServerPageW(kSimplePage); 487 GURL url = server->TestServerPageW(kSimplePage);
486 ui_test_utils::NavigateToURL(browser(), url); 488 ui_test_utils::NavigateToURL(browser(), url);
487 489
488 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 490 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
489 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeView(hwnd); 491 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
490 views::FocusManager* focus_manager = 492 views::FocusManager* focus_manager =
491 views::FocusManager::GetFocusManager(hwnd); 493 views::FocusManager::GetFocusManager(hwnd);
492 494
493 // Page should have focus. 495 // Page should have focus.
494 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 496 EXPECT_EQ(browser_view->contents_container()->GetFocusView(),
495 focus_manager->GetFocusedView()); 497 focus_manager->GetFocusedView());
496 EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()-> 498 EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()->
497 HasFocus()); 499 HasFocus());
498 500
499 // Let's show an interstitial. 501 // Let's show an interstitial.
(...skipping 24 matching lines...) Expand all
524 526
525 // Make sure Find box can request focus, even when it is already open. 527 // Make sure Find box can request focus, even when it is already open.
526 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) { 528 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
527 HTTPTestServer* server = StartHTTPServer(); 529 HTTPTestServer* server = StartHTTPServer();
528 530
529 // Open some page (any page that doesn't steal focus). 531 // Open some page (any page that doesn't steal focus).
530 GURL url = server->TestServerPageW(kTypicalPage); 532 GURL url = server->TestServerPageW(kTypicalPage);
531 ui_test_utils::NavigateToURL(browser(), url); 533 ui_test_utils::NavigateToURL(browser(), url);
532 534
533 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 535 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
534 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeView(hwnd); 536 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
535 views::FocusManager* focus_manager = 537 views::FocusManager* focus_manager =
536 views::FocusManager::GetFocusManager(hwnd); 538 views::FocusManager::GetFocusManager(hwnd);
537 LocationBarView* location_bar = browser_view->GetLocationBarView(); 539 LocationBarView* location_bar = browser_view->GetLocationBarView();
538 540
539 // Press Ctrl+F, which will make the Find box open and request focus. 541 // Press Ctrl+F, which will make the Find box open and request focus.
540 static const int VK_F = 0x46; 542 static const int VK_F = 0x46;
541 ui_controls::SendKeyPressNotifyWhenDone(L'F', true, false, false, 543 ui_controls::SendKeyPressNotifyWhenDone(L'F', true, false, false,
542 new MessageLoop::QuitTask()); 544 new MessageLoop::QuitTask());
543 ui_test_utils::RunMessageLoop(); 545 ui_test_utils::RunMessageLoop();
544 546
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 597
596 focused_view = focus_manager->GetFocusedView(); 598 focused_view = focus_manager->GetFocusedView();
597 ASSERT_TRUE(focused_view != NULL); 599 ASSERT_TRUE(focused_view != NULL);
598 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); 600 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID());
599 } 601 }
600 602
601 // Makes sure the focus is in the right location when opening the different 603 // Makes sure the focus is in the right location when opening the different
602 // types of tabs. 604 // types of tabs.
603 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) { 605 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) {
604 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 606 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
605 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeView(hwnd); 607 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
606 ASSERT_TRUE(browser_view); 608 ASSERT_TRUE(browser_view);
607 views::FocusManager* focus_manager = 609 views::FocusManager* focus_manager =
608 views::FocusManager::GetFocusManager(hwnd); 610 views::FocusManager::GetFocusManager(hwnd);
609 ASSERT_TRUE(focus_manager); 611 ASSERT_TRUE(focus_manager);
610 612
611 // Open the history tab, focus should be on the tab contents. 613 // Open the history tab, focus should be on the tab contents.
612 browser()->ShowHistoryTab(); 614 browser()->ShowHistoryTab();
613 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 615 EXPECT_EQ(browser_view->contents_container()->GetFocusView(),
614 focus_manager->GetFocusedView()); 616 focus_manager->GetFocusedView());
615 617
616 // Open the new tab, focus should be on the location bar. 618 // Open the new tab, focus should be on the location bar.
617 browser()->NewTab(); 619 browser()->NewTab();
618 EXPECT_EQ(browser_view->GetLocationBarView(), 620 EXPECT_EQ(browser_view->GetLocationBarView(),
619 focus_manager->GetFocusedView()); 621 focus_manager->GetFocusedView());
620 622
621 // Open the download tab, focus should be on the tab contents. 623 // Open the download tab, focus should be on the tab contents.
622 browser()->ShowDownloadsTab(); 624 browser()->ShowDownloadsTab();
623 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 625 EXPECT_EQ(browser_view->contents_container()->GetFocusView(),
624 focus_manager->GetFocusedView()); 626 focus_manager->GetFocusedView());
625 } 627 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/dock_info_win.cc » ('j') | chrome/browser/views/browser_bubble_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698