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

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

Issue 3834002: Make all browser code use browser::Navigate to open tabs.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/keyboard_codes.h" 5 #include "app/keyboard_codes.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_navigator.h"
10 #include "chrome/browser/browser_window.h" 11 #include "chrome/browser/browser_window.h"
11 #include "chrome/browser/find_bar.h" 12 #include "chrome/browser/find_bar.h"
12 #include "chrome/browser/find_bar_controller.h" 13 #include "chrome/browser/find_bar_controller.h"
13 #include "chrome/browser/find_notification_details.h" 14 #include "chrome/browser/find_notification_details.h"
14 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
15 #include "chrome/browser/renderer_host/render_view_host.h" 16 #include "chrome/browser/renderer_host/render_view_host.h"
16 #include "chrome/browser/tab_contents/tab_contents.h" 17 #include "chrome/browser/tab_contents/tab_contents.h"
17 #include "chrome/browser/tab_contents/tab_contents_view.h" 18 #include "chrome/browser/tab_contents/tab_contents_view.h"
18 #include "chrome/browser/tabs/tab_strip_model.h" 19 #include "chrome/browser/tabs/tab_strip_model.h"
19 #include "chrome/common/notification_service.h" 20 #include "chrome/common/notification_service.h"
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 // First we navigate to any page. 817 // First we navigate to any page.
817 GURL url = test_server()->GetURL(kSimplePage); 818 GURL url = test_server()->GetURL(kSimplePage);
818 ui_test_utils::NavigateToURL(browser(), url); 819 ui_test_utils::NavigateToURL(browser(), url);
819 820
820 // Find "Default". 821 // Find "Default".
821 int ordinal = 0; 822 int ordinal = 0;
822 TabContents* tab1 = browser()->GetSelectedTabContents(); 823 TabContents* tab1 = browser()->GetSelectedTabContents();
823 EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal)); 824 EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal));
824 825
825 // Create a second tab. 826 // Create a second tab.
826 Browser::AddTabWithURLParams params(url, PageTransition::TYPED); 827 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It
827 browser()->AddTabWithURL(&params); 828 // could be some delicate assumption about the tab starting off unselected or
828 EXPECT_EQ(browser(), params.target); 829 // something relating to user gesture.
830 browser::NavigateParams params(browser(), url, PageTransition::TYPED);
831 params.disposition = NEW_BACKGROUND_TAB;
832 params.tabstrip_add_types = TabStripModel::ADD_NONE;
833 browser::Navigate(&params);
829 browser()->SelectTabContentsAt(1, false); 834 browser()->SelectTabContentsAt(1, false);
830 TabContents* tab2 = browser()->GetSelectedTabContents(); 835 TabContents* tab2 = browser()->GetSelectedTabContents();
831 EXPECT_NE(tab1, tab2); 836 EXPECT_NE(tab1, tab2);
832 837
833 // Find "given". 838 // Find "given".
834 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); 839 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal);
835 840
836 // Switch back to first tab. 841 // Switch back to first tab.
837 browser()->SelectTabContentsAt(0, false); 842 browser()->SelectTabContentsAt(0, false);
838 browser()->GetFindBarController()->EndFindSession( 843 browser()->GetFindBarController()->EndFindSession(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 // First we navigate to any page. 897 // First we navigate to any page.
893 GURL url = test_server()->GetURL(kSimple); 898 GURL url = test_server()->GetURL(kSimple);
894 ui_test_utils::NavigateToURL(browser(), url); 899 ui_test_utils::NavigateToURL(browser(), url);
895 900
896 // Search for the word "page". 901 // Search for the word "page".
897 int ordinal = 0; 902 int ordinal = 0;
898 TabContents* tab1 = browser()->GetSelectedTabContents(); 903 TabContents* tab1 = browser()->GetSelectedTabContents();
899 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); 904 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
900 905
901 // Now create a second tab and load the same page. 906 // Now create a second tab and load the same page.
902 Browser::AddTabWithURLParams params(url, PageTransition::TYPED); 907 browser()->AddSelectedTabWithURL(url, PageTransition::TYPED);
903 browser()->AddTabWithURL(&params);
904 EXPECT_EQ(browser(), params.target);
905 browser()->SelectTabContentsAt(1, false);
906 TabContents* tab2 = browser()->GetSelectedTabContents(); 908 TabContents* tab2 = browser()->GetSelectedTabContents();
907 EXPECT_NE(tab1, tab2); 909 EXPECT_NE(tab1, tab2);
908 910
909 // Open the Find box. 911 // Open the Find box.
910 EnsureFindBoxOpen(); 912 EnsureFindBoxOpen();
911 913
912 // The new tab should have "page" prepopulated, since that was the last search 914 // The new tab should have "page" prepopulated, since that was the last search
913 // in the first tab. 915 // in the first tab.
914 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 916 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
915 } 917 }
(...skipping 21 matching lines...) Expand all
937 // Open the Find box. 939 // Open the Find box.
938 EnsureFindBoxOpen(); 940 EnsureFindBoxOpen();
939 941
940 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 942 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
941 943
942 // Close the Find box. 944 // Close the Find box.
943 browser()->GetFindBarController()->EndFindSession( 945 browser()->GetFindBarController()->EndFindSession(
944 FindBarController::kKeepSelection); 946 FindBarController::kKeepSelection);
945 947
946 // Now create a second tab and load the same page. 948 // Now create a second tab and load the same page.
947 Browser::AddTabWithURLParams params(url, PageTransition::TYPED); 949 browser::NavigateParams params(browser(), url, PageTransition::TYPED);
948 browser()->AddTabWithURL(&params); 950 params.disposition = NEW_BACKGROUND_TAB;
949 EXPECT_EQ(browser(), params.target); 951 params.tabstrip_add_types = TabStripModel::ADD_NONE;
952 browser::Navigate(&params);
950 browser()->SelectTabContentsAt(1, false); 953 browser()->SelectTabContentsAt(1, false);
951 TabContents* tab2 = browser()->GetSelectedTabContents(); 954 TabContents* tab2 = browser()->GetSelectedTabContents();
952 EXPECT_NE(tab1, tab2); 955 EXPECT_NE(tab1, tab2);
953 956
954 // Search for the word "text". 957 // Search for the word "text".
955 FindInPageWchar(tab2, L"text", kFwd, kIgnoreCase, &ordinal); 958 FindInPageWchar(tab2, L"text", kFwd, kIgnoreCase, &ordinal);
956 959
957 // Go back to the first tab and make sure we have NOT switched the prepopulate 960 // Go back to the first tab and make sure we have NOT switched the prepopulate
958 // text to "text". 961 // text to "text".
959 browser()->SelectTabContentsAt(0, false); 962 browser()->SelectTabContentsAt(0, false);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 EnsureFindBoxOpenForBrowser(browser()); 1014 EnsureFindBoxOpenForBrowser(browser());
1012 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); 1015 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
1013 1016
1014 // Close the Find box. 1017 // Close the Find box.
1015 browser()->GetFindBarController()->EndFindSession( 1018 browser()->GetFindBarController()->EndFindSession(
1016 FindBarController::kKeepSelection); 1019 FindBarController::kKeepSelection);
1017 1020
1018 // Open a new incognito window and navigate to the same page. 1021 // Open a new incognito window and navigate to the same page.
1019 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); 1022 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
1020 Browser* incognito_browser = Browser::Create(incognito_profile); 1023 Browser* incognito_browser = Browser::Create(incognito_profile);
1021 Browser::AddTabWithURLParams params1(url, PageTransition::START_PAGE); 1024 incognito_browser->AddSelectedTabWithURL(url, PageTransition::START_PAGE);
1022 incognito_browser->AddTabWithURL(&params1);
1023 EXPECT_EQ(incognito_browser, params1.target);
1024 ui_test_utils::WaitForNavigation( 1025 ui_test_utils::WaitForNavigation(
1025 &incognito_browser->GetSelectedTabContents()->controller()); 1026 &incognito_browser->GetSelectedTabContents()->controller());
1026 incognito_browser->window()->Show(); 1027 incognito_browser->window()->Show();
1027 1028
1028 // Open the find box and make sure that it is prepopulated with "page". 1029 // Open the find box and make sure that it is prepopulated with "page".
1029 EnsureFindBoxOpenForBrowser(incognito_browser); 1030 EnsureFindBoxOpenForBrowser(incognito_browser);
1030 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser)); 1031 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser));
1031 1032
1032 // Search for the word "text" in the incognito tab. 1033 // Search for the word "text" in the incognito tab.
1033 TabContents* incognito_tab = incognito_browser->GetSelectedTabContents(); 1034 TabContents* incognito_tab = incognito_browser->GetSelectedTabContents();
1034 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text", 1035 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text",
1035 kFwd, kIgnoreCase, &ordinal)); 1036 kFwd, kIgnoreCase, &ordinal));
1036 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser)); 1037 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser));
1037 1038
1038 // Close the Find box. 1039 // Close the Find box.
1039 incognito_browser->GetFindBarController()->EndFindSession( 1040 incognito_browser->GetFindBarController()->EndFindSession(
1040 FindBarController::kKeepSelection); 1041 FindBarController::kKeepSelection);
1041 1042
1042 // Now open a new tab in the original (non-incognito) browser. 1043 // Now open a new tab in the original (non-incognito) browser.
1043 Browser::AddTabWithURLParams params2(url, PageTransition::TYPED); 1044 browser()->AddSelectedTabWithURL(url, PageTransition::TYPED);
1044 browser()->AddTabWithURL(&params2);
1045 EXPECT_EQ(browser(), params2.target);
1046 browser()->SelectTabContentsAt(1, false);
1047 TabContents* tab2 = browser()->GetSelectedTabContents(); 1045 TabContents* tab2 = browser()->GetSelectedTabContents();
1048 EXPECT_NE(tab1, tab2); 1046 EXPECT_NE(tab1, tab2);
1049 1047
1050 // Open the Find box and make sure it is prepopulated with the search term 1048 // Open the Find box and make sure it is prepopulated with the search term
1051 // from the original browser, not the search term from the incognito window. 1049 // from the original browser, not the search term from the incognito window.
1052 EnsureFindBoxOpenForBrowser(browser()); 1050 EnsureFindBoxOpenForBrowser(browser());
1053 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); 1051 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
1054 } 1052 }
1055 1053
1056 // This makes sure that dismissing the find bar with kActivateSelection works. 1054 // This makes sure that dismissing the find bar with kActivateSelection works.
1057 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) { 1055 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) {
1058 ASSERT_TRUE(test_server()->Start()); 1056 ASSERT_TRUE(test_server()->Start());
1059 1057
1060 // First we navigate to our test content. 1058 // First we navigate to our test content.
1061 GURL url = test_server()->GetURL(kLinkPage); 1059 GURL url = test_server()->GetURL(kLinkPage);
1062 ui_test_utils::NavigateToURL(browser(), url); 1060 ui_test_utils::NavigateToURL(browser(), url);
1063 1061
1064 TabContents* tab = browser()->GetSelectedTabContents(); 1062 TabContents* tab = browser()->GetSelectedTabContents();
1065 int ordinal = 0; 1063 int ordinal = 0;
1066 FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal); 1064 FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal);
1067 EXPECT_EQ(ordinal, 1); 1065 EXPECT_EQ(ordinal, 1);
1068 1066
1069 // End the find session, click on the link. 1067 // End the find session, click on the link.
1070 tab->StopFinding(FindBarController::kActivateSelection); 1068 tab->StopFinding(FindBarController::kActivateSelection);
1071 EXPECT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); 1069 EXPECT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
1072 } 1070 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tabs_module.cc ('k') | chrome/browser/gtk/bookmark_bar_gtk_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698