OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 observer.Wait(); | 592 observer.Wait(); |
593 } | 593 } |
594 content::RunAllPendingInMessageLoop(); | 594 content::RunAllPendingInMessageLoop(); |
595 | 595 |
596 { | 596 { |
597 content::WindowedNotificationObserver observer( | 597 content::WindowedNotificationObserver observer( |
598 content::NOTIFICATION_LOAD_STOP, | 598 content::NOTIFICATION_LOAD_STOP, |
599 content::Source<content::NavigationController>( | 599 content::Source<content::NavigationController>( |
600 &browser()->tab_strip_model()->GetActiveWebContents()-> | 600 &browser()->tab_strip_model()->GetActiveWebContents()-> |
601 GetController())); | 601 GetController())); |
602 chrome::Reload(browser(), CURRENT_TAB); | 602 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
603 observer.Wait(); | 603 observer.Wait(); |
604 } | 604 } |
605 // Focus should stay on the location bar. | 605 // Focus should stay on the location bar. |
606 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 606 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
607 | 607 |
608 // Open a regular page, focus the location bar, reload. | 608 // Open a regular page, focus the location bar, reload. |
609 ui_test_utils::NavigateToURL(browser(), | 609 ui_test_utils::NavigateToURL(browser(), |
610 embedded_test_server()->GetURL(kSimplePage)); | 610 embedded_test_server()->GetURL(kSimplePage)); |
611 chrome::FocusLocationBar(browser()); | 611 chrome::FocusLocationBar(browser()); |
612 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 612 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
613 { | 613 { |
614 content::WindowedNotificationObserver observer( | 614 content::WindowedNotificationObserver observer( |
615 content::NOTIFICATION_LOAD_STOP, | 615 content::NOTIFICATION_LOAD_STOP, |
616 content::Source<content::NavigationController>( | 616 content::Source<content::NavigationController>( |
617 &browser()->tab_strip_model()->GetActiveWebContents()-> | 617 &browser()->tab_strip_model()->GetActiveWebContents()-> |
618 GetController())); | 618 GetController())); |
619 chrome::Reload(browser(), CURRENT_TAB); | 619 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
620 observer.Wait(); | 620 observer.Wait(); |
621 } | 621 } |
622 | 622 |
623 // Focus should now be on the tab contents. | 623 // Focus should now be on the tab contents. |
624 chrome::ShowDownloads(browser()); | 624 chrome::ShowDownloads(browser()); |
625 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 625 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
626 } | 626 } |
627 | 627 |
628 // Tests that focus goes where expected when using reload on a crashed tab. | 628 // Tests that focus goes where expected when using reload on a crashed tab. |
629 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) { | 629 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) { |
630 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 630 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
631 | 631 |
632 // Open a regular page, crash, reload. | 632 // Open a regular page, crash, reload. |
633 ui_test_utils::NavigateToURL(browser(), | 633 ui_test_utils::NavigateToURL(browser(), |
634 embedded_test_server()->GetURL(kSimplePage)); | 634 embedded_test_server()->GetURL(kSimplePage)); |
635 content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents()); | 635 content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents()); |
636 { | 636 { |
637 content::WindowedNotificationObserver observer( | 637 content::WindowedNotificationObserver observer( |
638 content::NOTIFICATION_LOAD_STOP, | 638 content::NOTIFICATION_LOAD_STOP, |
639 content::Source<content::NavigationController>( | 639 content::Source<content::NavigationController>( |
640 &browser()->tab_strip_model()->GetActiveWebContents()-> | 640 &browser()->tab_strip_model()->GetActiveWebContents()-> |
641 GetController())); | 641 GetController())); |
642 chrome::Reload(browser(), CURRENT_TAB); | 642 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
643 observer.Wait(); | 643 observer.Wait(); |
644 } | 644 } |
645 | 645 |
646 // Focus should now be on the tab contents. | 646 // Focus should now be on the tab contents. |
647 chrome::ShowDownloads(browser()); | 647 chrome::ShowDownloads(browser()); |
648 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 648 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
649 } | 649 } |
650 | 650 |
651 // Tests that focus goes to frame after crashed tab. | 651 // Tests that focus goes to frame after crashed tab. |
652 // TODO(shrikant): Find out where the focus should be deterministically. | 652 // TODO(shrikant): Find out where the focus should be deterministically. |
653 // Currently focused_view after crash seem to be non null in debug mode | 653 // Currently focused_view after crash seem to be non null in debug mode |
654 // (invalidated pointer 0xcccccc). | 654 // (invalidated pointer 0xcccccc). |
655 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusAfterCrashedTab) { | 655 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusAfterCrashedTab) { |
656 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 656 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
657 | 657 |
658 content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents()); | 658 content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents()); |
659 | 659 |
660 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 660 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
661 } | 661 } |
662 | 662 |
663 // Tests that when a new tab is opened from the omnibox, the focus is moved from | 663 // Tests that when a new tab is opened from the omnibox, the focus is moved from |
664 // the omnibox for the current tab. | 664 // the omnibox for the current tab. |
665 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, NavigateFromOmniboxIntoNewTab) { | 665 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, NavigateFromOmniboxIntoNewTab) { |
666 GURL url("http://www.google.com/"); | 666 GURL url("http://www.google.com/"); |
667 GURL url2("http://maps.google.com/"); | 667 GURL url2("http://maps.google.com/"); |
668 | 668 |
669 // Navigate to url. | 669 // Navigate to url. |
670 chrome::NavigateParams p(browser(), url, ui::PAGE_TRANSITION_LINK); | 670 chrome::NavigateParams p(browser(), url, ui::PAGE_TRANSITION_LINK); |
671 p.window_action = chrome::NavigateParams::SHOW_WINDOW; | 671 p.window_action = chrome::NavigateParams::SHOW_WINDOW; |
672 p.disposition = CURRENT_TAB; | 672 p.disposition = WindowOpenDisposition::CURRENT_TAB; |
673 chrome::Navigate(&p); | 673 chrome::Navigate(&p); |
674 | 674 |
675 // Focus the omnibox. | 675 // Focus the omnibox. |
676 chrome::FocusLocationBar(browser()); | 676 chrome::FocusLocationBar(browser()); |
677 | 677 |
678 OmniboxEditController* controller = browser()->window()->GetLocationBar()-> | 678 OmniboxEditController* controller = browser()->window()->GetLocationBar()-> |
679 GetOmniboxView()->model()->controller(); | 679 GetOmniboxView()->model()->controller(); |
680 | 680 |
681 // Simulate an alt-enter. | 681 // Simulate an alt-enter. |
682 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB, | 682 controller->OnAutocompleteAccept( |
683 ui::PAGE_TRANSITION_TYPED, | 683 url2, WindowOpenDisposition::NEW_FOREGROUND_TAB, |
684 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 684 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
685 | 685 |
686 // Make sure the second tab is selected. | 686 // Make sure the second tab is selected. |
687 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | 687 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
688 | 688 |
689 // The tab contents should have the focus in the second tab. | 689 // The tab contents should have the focus in the second tab. |
690 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 690 EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
691 | 691 |
692 // Go back to the first tab. The focus should not be in the omnibox. | 692 // Go back to the first tab. The focus should not be in the omnibox. |
693 chrome::SelectPreviousTab(browser()); | 693 chrome::SelectPreviousTab(browser()); |
694 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 694 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
(...skipping 22 matching lines...) Expand all Loading... |
717 base::FilePath::kCurrentDirectory), base::FilePath(kEmptyFile))); | 717 base::FilePath::kCurrentDirectory), base::FilePath(kEmptyFile))); |
718 ui_test_utils::NavigateToURL(browser(), file_url); | 718 ui_test_utils::NavigateToURL(browser(), file_url); |
719 | 719 |
720 ClickOnView(VIEW_ID_TAB_CONTAINER); | 720 ClickOnView(VIEW_ID_TAB_CONTAINER); |
721 | 721 |
722 // Navigate back. Should focus the location bar. | 722 // Navigate back. Should focus the location bar. |
723 { | 723 { |
724 content::WindowedNotificationObserver back_nav_observer( | 724 content::WindowedNotificationObserver back_nav_observer( |
725 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 725 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
726 content::NotificationService::AllSources()); | 726 content::NotificationService::AllSources()); |
727 chrome::GoBack(browser(), CURRENT_TAB); | 727 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB); |
728 back_nav_observer.Wait(); | 728 back_nav_observer.Wait(); |
729 } | 729 } |
730 | 730 |
731 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 731 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
732 | 732 |
733 // Navigate forward. Shouldn't focus the location bar. | 733 // Navigate forward. Shouldn't focus the location bar. |
734 ClickOnView(VIEW_ID_TAB_CONTAINER); | 734 ClickOnView(VIEW_ID_TAB_CONTAINER); |
735 { | 735 { |
736 content::WindowedNotificationObserver forward_nav_observer( | 736 content::WindowedNotificationObserver forward_nav_observer( |
737 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 737 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
738 content::NotificationService::AllSources()); | 738 content::NotificationService::AllSources()); |
739 chrome::GoForward(browser(), CURRENT_TAB); | 739 chrome::GoForward(browser(), WindowOpenDisposition::CURRENT_TAB); |
740 forward_nav_observer.Wait(); | 740 forward_nav_observer.Wait(); |
741 } | 741 } |
742 | 742 |
743 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 743 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
744 } | 744 } |
745 | 745 |
746 // Ensure that crbug.com/567445 does not regress. This test checks that the | 746 // Ensure that crbug.com/567445 does not regress. This test checks that the |
747 // Omnibox does not get focused when loading about:blank in a case where it's | 747 // Omnibox does not get focused when loading about:blank in a case where it's |
748 // not the startup URL, e.g. when a page opens a popup to about:blank, with a | 748 // not the startup URL, e.g. when a page opens a popup to about:blank, with a |
749 // null opener, and then navigates it. This is a potential security issue; see | 749 // null opener, and then navigates it. This is a potential security issue; see |
(...skipping 12 matching lines...) Expand all Loading... |
762 ASSERT_TRUE(content::ExecuteScript(web_contents, spoof)); | 762 ASSERT_TRUE(content::ExecuteScript(web_contents, spoof)); |
763 EXPECT_EQ(url1, web_contents->GetVisibleURL()); | 763 EXPECT_EQ(url1, web_contents->GetVisibleURL()); |
764 // After running the spoof code, |GetActiveWebContents| returns the new tab, | 764 // After running the spoof code, |GetActiveWebContents| returns the new tab, |
765 // not the same as |web_contents|. | 765 // not the same as |web_contents|. |
766 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( | 766 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( |
767 browser()->tab_strip_model()->GetActiveWebContents())); | 767 browser()->tab_strip_model()->GetActiveWebContents())); |
768 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 768 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
769 } | 769 } |
770 | 770 |
771 } // namespace | 771 } // namespace |
OLD | NEW |