| OLD | NEW |
| 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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); | 497 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); |
| 498 views::FocusManager* focus_manager = | 498 views::FocusManager* focus_manager = |
| 499 views::FocusManager::GetFocusManagerForNativeView(hwnd); | 499 views::FocusManager::GetFocusManagerForNativeView(hwnd); |
| 500 | 500 |
| 501 // Page should have focus. | 501 // Page should have focus. |
| 502 EXPECT_EQ(browser_view->GetTabContentsContainerView(), | 502 EXPECT_EQ(browser_view->GetTabContentsContainerView(), |
| 503 focus_manager->GetFocusedView()); | 503 focus_manager->GetFocusedView()); |
| 504 EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()-> | 504 EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()-> |
| 505 HasFocus()); | 505 HasFocus()); |
| 506 | 506 |
| 507 // Let's show an interstitial.erstitial | 507 // Let's show an interstitial. |
| 508 TestInterstitialPage* interstitial_page = | 508 TestInterstitialPage* interstitial_page = |
| 509 new TestInterstitialPage(browser()->GetSelectedTabContents(), | 509 new TestInterstitialPage(browser()->GetSelectedTabContents(), |
| 510 true, GURL("http://interstitial.com")); | 510 true, GURL("http://interstitial.com")); |
| 511 interstitial_page->Show(); | 511 interstitial_page->Show(); |
| 512 // Give some time for the interstitial to show. | 512 // Give some time for the interstitial to show. |
| 513 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 513 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 514 new MessageLoop::QuitTask(), | 514 new MessageLoop::QuitTask(), |
| 515 1000); | 515 1000); |
| 516 ui_test_utils::RunMessageLoop(); | 516 ui_test_utils::RunMessageLoop(); |
| 517 | 517 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 browser()->ShowDownloadsTab(); | 630 browser()->ShowDownloadsTab(); |
| 631 EXPECT_EQ(browser_view->GetTabContentsContainerView(), | 631 EXPECT_EQ(browser_view->GetTabContentsContainerView(), |
| 632 focus_manager->GetFocusedView()); | 632 focus_manager->GetFocusedView()); |
| 633 | 633 |
| 634 // Open about:blank, focus should be on the location bar. | 634 // Open about:blank, focus should be on the location bar. |
| 635 browser()->AddTabWithURL(GURL("about:blank"), GURL(), PageTransition::LINK, | 635 browser()->AddTabWithURL(GURL("about:blank"), GURL(), PageTransition::LINK, |
| 636 true, -1, false, NULL); | 636 true, -1, false, NULL); |
| 637 EXPECT_EQ(browser_view->GetLocationBarView(), | 637 EXPECT_EQ(browser_view->GetLocationBarView(), |
| 638 focus_manager->GetFocusedView()); | 638 focus_manager->GetFocusedView()); |
| 639 } | 639 } |
| 640 |
| 641 // Tests that focus goes where expected when using reload. |
| 642 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { |
| 643 HTTPTestServer* server = StartHTTPServer(); |
| 644 |
| 645 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); |
| 646 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); |
| 647 ASSERT_TRUE(browser_view); |
| 648 views::FocusManager* focus_manager = |
| 649 views::FocusManager::GetFocusManagerForNativeView(hwnd); |
| 650 ASSERT_TRUE(focus_manager); |
| 651 |
| 652 // Open the new tab, reload. |
| 653 browser()->NewTab(); |
| 654 ui_test_utils::ReloadCurrentTab(browser()); |
| 655 // Focus should stay on the location bar. |
| 656 EXPECT_EQ(browser_view->GetLocationBarView(), |
| 657 focus_manager->GetFocusedView()); |
| 658 |
| 659 // Open a regular page, focus the location bar, reload. |
| 660 ui_test_utils::NavigateToURL(browser(), server->TestServerPageW(kSimplePage)); |
| 661 browser_view->GetLocationBarView()->FocusLocation(); |
| 662 EXPECT_EQ(browser_view->GetLocationBarView(), |
| 663 focus_manager->GetFocusedView()); |
| 664 ui_test_utils::ReloadCurrentTab(browser()); |
| 665 // Focus should now be on the tab contents. |
| 666 EXPECT_EQ(browser_view->GetTabContentsContainerView(), |
| 667 focus_manager->GetFocusedView()); |
| 668 } |
| 669 |
| 670 // Tests that focus goes where expected when using reload on a crashed tab. |
| 671 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReloadCrashedTab) { |
| 672 HTTPTestServer* server = StartHTTPServer(); |
| 673 |
| 674 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); |
| 675 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); |
| 676 ASSERT_TRUE(browser_view); |
| 677 views::FocusManager* focus_manager = |
| 678 views::FocusManager::GetFocusManagerForNativeView(hwnd); |
| 679 ASSERT_TRUE(focus_manager); |
| 680 |
| 681 // Open a regular page, crash, reload. |
| 682 ui_test_utils::NavigateToURL(browser(), server->TestServerPageW(kSimplePage)); |
| 683 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
| 684 ui_test_utils::ReloadCurrentTab(browser()); |
| 685 // Focus should now be on the tab contents. |
| 686 EXPECT_EQ(browser_view->GetTabContentsContainerView(), |
| 687 focus_manager->GetFocusedView()); |
| 688 } |
| OLD | NEW |