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

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

Issue 122002: Moving the WM_SETFOCUS message processing out of FocusManager (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
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/browser_window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 private: 90 private:
91 std::string html_contents_; 91 std::string html_contents_;
92 92
93 bool waiting_for_dom_response_; 93 bool waiting_for_dom_response_;
94 std::string dom_response_; 94 std::string dom_response_;
95 95
96 }; 96 };
97 } // namespace 97 } // namespace
98 98
99 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) { 99 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, 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::GetBrowserViewForNativeWindow(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->GetTabContentsContainerView(),
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
119 // using Windows API. 119 // using Windows API.
120 ::ShowWindow(hwnd, SW_HIDE); 120 ::ShowWindow(hwnd, SW_HIDE);
121 ::ShowWindow(hwnd, SW_SHOW); 121 ::ShowWindow(hwnd, SW_SHOW);
122 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 122 EXPECT_EQ(browser_view->GetTabContentsContainerView(),
123 focus_manager->GetFocusedView()); 123 focus_manager->GetFocusedView());
124 124
125 // Click on the location bar. 125 // Click on the location bar.
126 LocationBarView* location_bar = browser_view->GetLocationBarView(); 126 LocationBarView* location_bar = browser_view->GetLocationBarView();
127 ui_controls::MoveMouseToCenterAndPress(location_bar, 127 ui_controls::MoveMouseToCenterAndPress(location_bar,
128 ui_controls::LEFT, 128 ui_controls::LEFT,
129 ui_controls::DOWN | ui_controls::UP, 129 ui_controls::DOWN | ui_controls::UP,
130 new MessageLoop::QuitTask()); 130 new MessageLoop::QuitTask());
131 ui_test_utils::RunMessageLoop(); 131 ui_test_utils::RunMessageLoop();
132 // Location bar should have focus. 132 // Location bar should have focus.
(...skipping 11 matching lines...) Expand all
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 = 148 BrowserView* browser_view2 =
149 BrowserView::GetBrowserViewForNativeWindow(hwnd2); 149 BrowserView::GetBrowserViewForNativeWindow(hwnd2);
150 ASSERT_TRUE(browser_view2); 150 ASSERT_TRUE(browser_view2);
151 views::FocusManager* focus_manager2 = 151 views::FocusManager* focus_manager2 =
152 views::FocusManager::GetFocusManager(hwnd2); 152 views::FocusManager::GetFocusManager(hwnd2);
153 ASSERT_TRUE(focus_manager2); 153 ASSERT_TRUE(focus_manager2);
154 EXPECT_EQ(browser_view2->contents_container()->GetFocusView(), 154 EXPECT_EQ(browser_view2->GetTabContentsContainerView(),
155 focus_manager2->GetFocusedView()); 155 focus_manager2->GetFocusedView());
156 156
157 // 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
158 // bar and the second browser should have nothing focused. 158 // bar and the second browser should have nothing focused.
159 browser()->window()->Activate(); 159 browser()->window()->Activate();
160 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); 160 EXPECT_EQ(location_bar, focus_manager->GetFocusedView());
161 EXPECT_EQ(NULL, focus_manager2->GetFocusedView()); 161 EXPECT_EQ(NULL, focus_manager2->GetFocusedView());
162 162
163 // Switch back to the second browser, focus should still be on the page. 163 // Switch back to the second browser, focus should still be on the page.
164 browser2->window()->Activate(); 164 browser2->window()->Activate();
165 EXPECT_EQ(NULL, focus_manager->GetFocusedView()); 165 EXPECT_EQ(NULL, focus_manager->GetFocusedView());
166 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 166 EXPECT_EQ(browser_view2->GetTabContentsContainerView(),
167 focus_manager2->GetFocusedView()); 167 focus_manager2->GetFocusedView());
168 168
169 // Close the 2nd browser to avoid a DCHECK(). 169 // Close the 2nd browser to avoid a DCHECK().
170 browser_view2->Close(); 170 browser_view2->Close();
171 } 171 }
172 172
173 // Tabs remember focus. 173 // Tabs remember focus.
174 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) { 174 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) {
175 HTTPTestServer* server = StartHTTPServer(); 175 HTTPTestServer* server = StartHTTPServer();
176 176
(...skipping 21 matching lines...) Expand all
198 { false, false, false, false, false }, 198 { false, false, false, false, false },
199 { false, true, false, true, false } 199 { false, true, false, true, false }
200 }; 200 };
201 201
202 for (int i = 1; i < 3; i++) { 202 for (int i = 1; i < 3; i++) {
203 for (int j = 0; j < 5; j++) { 203 for (int j = 0; j < 5; j++) {
204 // Activate the tab. 204 // Activate the tab.
205 browser()->SelectTabContentsAt(j, true); 205 browser()->SelectTabContentsAt(j, true);
206 206
207 // Activate the location bar or the page. 207 // Activate the location bar or the page.
208 views::View* view_to_focus = kFocusPage[i][j] ? 208 views::View* view_to_focus;
209 browser_view->contents_container()->GetFocusView() : 209 if (kFocusPage[i][j]) {
210 browser_view->GetLocationBarView(); 210 view_to_focus = browser_view->GetTabContentsContainerView();
211 } else {
212 view_to_focus = browser_view->GetLocationBarView();
213 }
211 214
212 ui_controls::MoveMouseToCenterAndPress(view_to_focus, 215 ui_controls::MoveMouseToCenterAndPress(view_to_focus,
213 ui_controls::LEFT, 216 ui_controls::LEFT,
214 ui_controls::DOWN | 217 ui_controls::DOWN |
215 ui_controls::UP, 218 ui_controls::UP,
216 new MessageLoop::QuitTask()); 219 new MessageLoop::QuitTask());
217 ui_test_utils::RunMessageLoop(); 220 ui_test_utils::RunMessageLoop();
218 } 221 }
219 222
220 // Now come back to the tab and check the right view is focused. 223 // Now come back to the tab and check the right view is focused.
221 for (int j = 0; j < 5; j++) { 224 for (int j = 0; j < 5; j++) {
222 // Activate the tab. 225 // Activate the tab.
223 browser()->SelectTabContentsAt(j, true); 226 browser()->SelectTabContentsAt(j, true);
224 227
225 // Activate the location bar or the page. 228 // Activate the location bar or the page.
226 views::View* view = kFocusPage[i][j] ? 229 views::View* view;
227 browser_view->contents_container()->GetFocusView() : 230 if (kFocusPage[i][j]) {
228 browser_view->GetLocationBarView(); 231 view = browser_view->GetTabContentsContainerView();
232 } else {
233 view = browser_view->GetLocationBarView();
234 }
229 EXPECT_EQ(view, focus_manager->GetFocusedView()); 235 EXPECT_EQ(view, focus_manager->GetFocusedView());
230 } 236 }
231 } 237 }
232 } 238 }
233 239
234 // Background window does not steal focus. 240 // Background window does not steal focus.
235 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { 241 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) {
236 HTTPTestServer* server = StartHTTPServer(); 242 HTTPTestServer* server = StartHTTPServer();
237 243
238 // First we navigate to our test page. 244 // First we navigate to our test page.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // First we navigate to our test page. 397 // First we navigate to our test page.
392 GURL url = server->TestServerPageW(kSimplePage); 398 GURL url = server->TestServerPageW(kSimplePage);
393 ui_test_utils::NavigateToURL(browser(), url); 399 ui_test_utils::NavigateToURL(browser(), url);
394 400
395 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 401 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
396 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); 402 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
397 views::FocusManager* focus_manager = 403 views::FocusManager* focus_manager =
398 views::FocusManager::GetFocusManager(hwnd); 404 views::FocusManager::GetFocusManager(hwnd);
399 405
400 // Focus should be on the page. 406 // Focus should be on the page.
401 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 407 EXPECT_EQ(browser_view->GetTabContentsContainerView(),
402 focus_manager->GetFocusedView()); 408 focus_manager->GetFocusedView());
403 409
404 // Let's show an interstitial. 410 // Let's show an interstitial.
405 TestInterstitialPage* interstitial_page = 411 TestInterstitialPage* interstitial_page =
406 new TestInterstitialPage(browser()->GetSelectedTabContents(), 412 new TestInterstitialPage(browser()->GetSelectedTabContents(),
407 true, GURL("http://interstitial.com")); 413 true, GURL("http://interstitial.com"));
408 interstitial_page->Show(); 414 interstitial_page->Show();
409 // Give some time for the interstitial to show. 415 // Give some time for the interstitial to show.
410 MessageLoop::current()->PostDelayedTask(FROM_HERE, 416 MessageLoop::current()->PostDelayedTask(FROM_HERE,
411 new MessageLoop::QuitTask(), 417 new MessageLoop::QuitTask(),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 // First we navigate to our test page. 492 // First we navigate to our test page.
487 GURL url = server->TestServerPageW(kSimplePage); 493 GURL url = server->TestServerPageW(kSimplePage);
488 ui_test_utils::NavigateToURL(browser(), url); 494 ui_test_utils::NavigateToURL(browser(), url);
489 495
490 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 496 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
491 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); 497 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
492 views::FocusManager* focus_manager = 498 views::FocusManager* focus_manager =
493 views::FocusManager::GetFocusManager(hwnd); 499 views::FocusManager::GetFocusManager(hwnd);
494 500
495 // Page should have focus. 501 // Page should have focus.
496 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 502 EXPECT_EQ(browser_view->GetTabContentsContainerView(),
497 focus_manager->GetFocusedView()); 503 focus_manager->GetFocusedView());
498 EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()-> 504 EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()->
499 HasFocus()); 505 HasFocus());
500 506
501 // Let's show an interstitial. 507 // Let's show an interstitial.erstitial
502 TestInterstitialPage* interstitial_page = 508 TestInterstitialPage* interstitial_page =
503 new TestInterstitialPage(browser()->GetSelectedTabContents(), 509 new TestInterstitialPage(browser()->GetSelectedTabContents(),
504 true, GURL("http://interstitial.com")); 510 true, GURL("http://interstitial.com"));
505 interstitial_page->Show(); 511 interstitial_page->Show();
506 // Give some time for the interstitial to show. 512 // Give some time for the interstitial to show.
507 MessageLoop::current()->PostDelayedTask(FROM_HERE, 513 MessageLoop::current()->PostDelayedTask(FROM_HERE,
508 new MessageLoop::QuitTask(), 514 new MessageLoop::QuitTask(),
509 1000); 515 1000);
510 ui_test_utils::RunMessageLoop(); 516 ui_test_utils::RunMessageLoop();
511 517
512 // The interstitial should have focus now. 518 // The interstitial should have focus now.
513 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 519 EXPECT_EQ(browser_view->GetTabContentsContainerView(),
514 focus_manager->GetFocusedView()); 520 focus_manager->GetFocusedView());
515 EXPECT_TRUE(interstitial_page->HasFocus()); 521 EXPECT_TRUE(interstitial_page->HasFocus());
516 522
517 // Hide the interstitial. 523 // Hide the interstitial.
518 interstitial_page->DontProceed(); 524 interstitial_page->DontProceed();
519 525
520 // Focus should be back on the original page. 526 // Focus should be back on the original page.
521 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 527 EXPECT_EQ(browser_view->GetTabContentsContainerView(),
522 focus_manager->GetFocusedView()); 528 focus_manager->GetFocusedView());
523 EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()-> 529 EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()->
524 HasFocus()); 530 HasFocus());
525 } 531 }
526 532
527 // Make sure Find box can request focus, even when it is already open. 533 // Make sure Find box can request focus, even when it is already open.
528 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) { 534 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
529 HTTPTestServer* server = StartHTTPServer(); 535 HTTPTestServer* server = StartHTTPServer();
530 536
531 // Open some page (any page that doesn't steal focus). 537 // Open some page (any page that doesn't steal focus).
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 // Now press Ctrl+F again and focus should move to the Find box. 576 // Now press Ctrl+F again and focus should move to the Find box.
571 ui_controls::SendKeyPressNotifyWhenDone(L'F', true, false, false, 577 ui_controls::SendKeyPressNotifyWhenDone(L'F', true, false, false,
572 new MessageLoop::QuitTask()); 578 new MessageLoop::QuitTask());
573 ui_test_utils::RunMessageLoop(); 579 ui_test_utils::RunMessageLoop();
574 focused_view = focus_manager->GetFocusedView(); 580 focused_view = focus_manager->GetFocusedView();
575 ASSERT_TRUE(focused_view != NULL); 581 ASSERT_TRUE(focused_view != NULL);
576 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); 582 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID());
577 583
578 // Set focus to the page. 584 // Set focus to the page.
579 ui_controls::MoveMouseToCenterAndPress( 585 ui_controls::MoveMouseToCenterAndPress(
580 browser_view->contents_container()->GetFocusView(), 586 browser_view->GetTabContentsContainerView(),
581 ui_controls::LEFT, 587 ui_controls::LEFT,
582 ui_controls::DOWN | ui_controls::UP, 588 ui_controls::DOWN | ui_controls::UP,
583 new MessageLoop::QuitTask()); 589 new MessageLoop::QuitTask());
584 ui_test_utils::RunMessageLoop(); 590 ui_test_utils::RunMessageLoop();
585 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 591 EXPECT_EQ(browser_view->GetTabContentsContainerView(),
586 focus_manager->GetFocusedView()); 592 focus_manager->GetFocusedView());
587 593
588 // Now press Ctrl+F again and focus should move to the Find box. 594 // Now press Ctrl+F again and focus should move to the Find box.
589 ui_controls::SendKeyPressNotifyWhenDone(VK_F, true, false, false, 595 ui_controls::SendKeyPressNotifyWhenDone(VK_F, true, false, false,
590 new MessageLoop::QuitTask()); 596 new MessageLoop::QuitTask());
591 ui_test_utils::RunMessageLoop(); 597 ui_test_utils::RunMessageLoop();
592 598
593 // See remark above on why we wait. 599 // See remark above on why we wait.
594 ::Sleep(kActionDelayMs); 600 ::Sleep(kActionDelayMs);
595 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); 601 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
596 ui_test_utils::RunMessageLoop(); 602 ui_test_utils::RunMessageLoop();
597 603
598 focused_view = focus_manager->GetFocusedView(); 604 focused_view = focus_manager->GetFocusedView();
599 ASSERT_TRUE(focused_view != NULL); 605 ASSERT_TRUE(focused_view != NULL);
600 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); 606 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID());
601 } 607 }
602 608
603 // Makes sure the focus is in the right location when opening the different 609 // Makes sure the focus is in the right location when opening the different
604 // types of tabs. 610 // types of tabs.
605 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) { 611 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) {
606 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); 612 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
607 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); 613 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
608 ASSERT_TRUE(browser_view); 614 ASSERT_TRUE(browser_view);
609 views::FocusManager* focus_manager = 615 views::FocusManager* focus_manager =
610 views::FocusManager::GetFocusManager(hwnd); 616 views::FocusManager::GetFocusManager(hwnd);
611 ASSERT_TRUE(focus_manager); 617 ASSERT_TRUE(focus_manager);
612 618
613 // Open the history tab, focus should be on the tab contents. 619 // Open the history tab, focus should be on the tab contents.
614 browser()->ShowHistoryTab(); 620 browser()->ShowHistoryTab();
615 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 621 EXPECT_EQ(browser_view->GetTabContentsContainerView(),
616 focus_manager->GetFocusedView()); 622 focus_manager->GetFocusedView());
617 623
618 // Open the new tab, focus should be on the location bar. 624 // Open the new tab, focus should be on the location bar.
619 browser()->NewTab(); 625 browser()->NewTab();
620 EXPECT_EQ(browser_view->GetLocationBarView(), 626 EXPECT_EQ(browser_view->GetLocationBarView(),
621 focus_manager->GetFocusedView()); 627 focus_manager->GetFocusedView());
622 628
623 // Open the download tab, focus should be on the tab contents. 629 // Open the download tab, focus should be on the tab contents.
624 browser()->ShowDownloadsTab(); 630 browser()->ShowDownloadsTab();
625 EXPECT_EQ(browser_view->contents_container()->GetFocusView(), 631 EXPECT_EQ(browser_view->GetTabContentsContainerView(),
626 focus_manager->GetFocusedView()); 632 focus_manager->GetFocusedView());
627 } 633 }
OLDNEW
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/browser_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698