OLD | NEW |
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 "base/keyboard_codes.h" | 5 #include "base/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_window.h" | 10 #include "chrome/browser/browser_window.h" |
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 // First we navigate to any page. | 828 // First we navigate to any page. |
829 GURL url = server->TestServerPage(kSimplePage); | 829 GURL url = server->TestServerPage(kSimplePage); |
830 ui_test_utils::NavigateToURL(browser(), url); | 830 ui_test_utils::NavigateToURL(browser(), url); |
831 | 831 |
832 // Find "Default". | 832 // Find "Default". |
833 int ordinal = 0; | 833 int ordinal = 0; |
834 TabContents* tab1 = browser()->GetSelectedTabContents(); | 834 TabContents* tab1 = browser()->GetSelectedTabContents(); |
835 EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal)); | 835 EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal)); |
836 | 836 |
837 // Create a second tab. | 837 // Create a second tab. |
| 838 Browser* browser_used = NULL; |
838 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, | 839 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, |
839 TabStripModel::ADD_SELECTED, NULL, std::string()); | 840 TabStripModel::ADD_SELECTED, NULL, std::string(), |
| 841 &browser_used); |
| 842 EXPECT_EQ(browser(), browser_used); |
840 browser()->SelectTabContentsAt(1, false); | 843 browser()->SelectTabContentsAt(1, false); |
841 TabContents* tab2 = browser()->GetSelectedTabContents(); | 844 TabContents* tab2 = browser()->GetSelectedTabContents(); |
842 EXPECT_NE(tab1, tab2); | 845 EXPECT_NE(tab1, tab2); |
843 | 846 |
844 // Find "given". | 847 // Find "given". |
845 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); | 848 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); |
846 | 849 |
847 // Switch back to first tab. | 850 // Switch back to first tab. |
848 browser()->SelectTabContentsAt(0, false); | 851 browser()->SelectTabContentsAt(0, false); |
849 browser()->GetFindBarController()->EndFindSession( | 852 browser()->GetFindBarController()->EndFindSession( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 // First we navigate to any page. | 908 // First we navigate to any page. |
906 GURL url = server->TestServerPage(kSimple); | 909 GURL url = server->TestServerPage(kSimple); |
907 ui_test_utils::NavigateToURL(browser(), url); | 910 ui_test_utils::NavigateToURL(browser(), url); |
908 | 911 |
909 // Search for the word "page". | 912 // Search for the word "page". |
910 int ordinal = 0; | 913 int ordinal = 0; |
911 TabContents* tab1 = browser()->GetSelectedTabContents(); | 914 TabContents* tab1 = browser()->GetSelectedTabContents(); |
912 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); | 915 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); |
913 | 916 |
914 // Now create a second tab and load the same page. | 917 // Now create a second tab and load the same page. |
| 918 Browser* browser_used = NULL; |
915 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, | 919 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, |
916 TabStripModel::ADD_SELECTED, NULL, std::string()); | 920 TabStripModel::ADD_SELECTED, NULL, std::string(), |
| 921 &browser_used); |
| 922 EXPECT_EQ(browser(), browser_used); |
917 browser()->SelectTabContentsAt(1, false); | 923 browser()->SelectTabContentsAt(1, false); |
918 TabContents* tab2 = browser()->GetSelectedTabContents(); | 924 TabContents* tab2 = browser()->GetSelectedTabContents(); |
919 EXPECT_NE(tab1, tab2); | 925 EXPECT_NE(tab1, tab2); |
920 | 926 |
921 // Open the Find box. | 927 // Open the Find box. |
922 EnsureFindBoxOpen(); | 928 EnsureFindBoxOpen(); |
923 | 929 |
924 // The new tab should have "page" prepopulated, since that was the last search | 930 // The new tab should have "page" prepopulated, since that was the last search |
925 // in the first tab. | 931 // in the first tab. |
926 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); | 932 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); |
(...skipping 23 matching lines...) Expand all Loading... |
950 // Open the Find box. | 956 // Open the Find box. |
951 EnsureFindBoxOpen(); | 957 EnsureFindBoxOpen(); |
952 | 958 |
953 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); | 959 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); |
954 | 960 |
955 // Close the Find box. | 961 // Close the Find box. |
956 browser()->GetFindBarController()->EndFindSession( | 962 browser()->GetFindBarController()->EndFindSession( |
957 FindBarController::kKeepSelection); | 963 FindBarController::kKeepSelection); |
958 | 964 |
959 // Now create a second tab and load the same page. | 965 // Now create a second tab and load the same page. |
| 966 Browser* browser_used = NULL; |
960 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, | 967 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, |
961 TabStripModel::ADD_SELECTED, NULL, std::string()); | 968 TabStripModel::ADD_SELECTED, NULL, std::string(), |
| 969 &browser_used); |
| 970 EXPECT_EQ(browser(), browser_used); |
962 browser()->SelectTabContentsAt(1, false); | 971 browser()->SelectTabContentsAt(1, false); |
963 TabContents* tab2 = browser()->GetSelectedTabContents(); | 972 TabContents* tab2 = browser()->GetSelectedTabContents(); |
964 EXPECT_NE(tab1, tab2); | 973 EXPECT_NE(tab1, tab2); |
965 | 974 |
966 // Search for the word "text". | 975 // Search for the word "text". |
967 FindInPageWchar(tab2, L"text", kFwd, kIgnoreCase, &ordinal); | 976 FindInPageWchar(tab2, L"text", kFwd, kIgnoreCase, &ordinal); |
968 | 977 |
969 // Go back to the first tab and make sure we have NOT switched the prepopulate | 978 // Go back to the first tab and make sure we have NOT switched the prepopulate |
970 // text to "text". | 979 // text to "text". |
971 browser()->SelectTabContentsAt(0, false); | 980 browser()->SelectTabContentsAt(0, false); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 EnsureFindBoxOpenForBrowser(browser()); | 1036 EnsureFindBoxOpenForBrowser(browser()); |
1028 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); | 1037 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); |
1029 | 1038 |
1030 // Close the Find box. | 1039 // Close the Find box. |
1031 browser()->GetFindBarController()->EndFindSession( | 1040 browser()->GetFindBarController()->EndFindSession( |
1032 FindBarController::kKeepSelection); | 1041 FindBarController::kKeepSelection); |
1033 | 1042 |
1034 // Open a new incognito window and navigate to the same page. | 1043 // Open a new incognito window and navigate to the same page. |
1035 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); | 1044 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); |
1036 Browser* incognito_browser = Browser::Create(incognito_profile); | 1045 Browser* incognito_browser = Browser::Create(incognito_profile); |
| 1046 Browser* browser_used = NULL; |
1037 incognito_browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE, -1, | 1047 incognito_browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE, -1, |
1038 TabStripModel::ADD_SELECTED, NULL, | 1048 TabStripModel::ADD_SELECTED, NULL, |
1039 std::string()); | 1049 std::string(), &browser_used); |
| 1050 EXPECT_EQ(incognito_browser, browser_used); |
1040 ui_test_utils::WaitForNavigation( | 1051 ui_test_utils::WaitForNavigation( |
1041 &incognito_browser->GetSelectedTabContents()->controller()); | 1052 &incognito_browser->GetSelectedTabContents()->controller()); |
1042 incognito_browser->window()->Show(); | 1053 incognito_browser->window()->Show(); |
1043 | 1054 |
1044 // Open the find box and make sure that it is prepopulated with "page". | 1055 // Open the find box and make sure that it is prepopulated with "page". |
1045 EnsureFindBoxOpenForBrowser(incognito_browser); | 1056 EnsureFindBoxOpenForBrowser(incognito_browser); |
1046 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser)); | 1057 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser)); |
1047 | 1058 |
1048 // Search for the word "text" in the incognito tab. | 1059 // Search for the word "text" in the incognito tab. |
1049 TabContents* incognito_tab = incognito_browser->GetSelectedTabContents(); | 1060 TabContents* incognito_tab = incognito_browser->GetSelectedTabContents(); |
1050 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text", | 1061 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text", |
1051 kFwd, kIgnoreCase, &ordinal)); | 1062 kFwd, kIgnoreCase, &ordinal)); |
1052 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser)); | 1063 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser)); |
1053 | 1064 |
1054 // Close the Find box. | 1065 // Close the Find box. |
1055 incognito_browser->GetFindBarController()->EndFindSession( | 1066 incognito_browser->GetFindBarController()->EndFindSession( |
1056 FindBarController::kKeepSelection); | 1067 FindBarController::kKeepSelection); |
1057 | 1068 |
1058 // Now open a new tab in the original (non-incognito) browser. | 1069 // Now open a new tab in the original (non-incognito) browser. |
1059 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, | 1070 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, |
1060 TabStripModel::ADD_SELECTED, NULL, std::string()); | 1071 TabStripModel::ADD_SELECTED, NULL, std::string(), |
| 1072 &browser_used); |
| 1073 EXPECT_EQ(browser(), browser_used); |
1061 browser()->SelectTabContentsAt(1, false); | 1074 browser()->SelectTabContentsAt(1, false); |
1062 TabContents* tab2 = browser()->GetSelectedTabContents(); | 1075 TabContents* tab2 = browser()->GetSelectedTabContents(); |
1063 EXPECT_NE(tab1, tab2); | 1076 EXPECT_NE(tab1, tab2); |
1064 | 1077 |
1065 // Open the Find box and make sure it is prepopulated with the search term | 1078 // Open the Find box and make sure it is prepopulated with the search term |
1066 // from the original browser, not the search term from the incognito window. | 1079 // from the original browser, not the search term from the incognito window. |
1067 EnsureFindBoxOpenForBrowser(browser()); | 1080 EnsureFindBoxOpenForBrowser(browser()); |
1068 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); | 1081 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); |
1069 } | 1082 } |
1070 | 1083 |
(...skipping 15 matching lines...) Expand all Loading... |
1086 | 1099 |
1087 TabContents* tab = browser()->GetSelectedTabContents(); | 1100 TabContents* tab = browser()->GetSelectedTabContents(); |
1088 int ordinal = 0; | 1101 int ordinal = 0; |
1089 FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal); | 1102 FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal); |
1090 EXPECT_EQ(ordinal, 1); | 1103 EXPECT_EQ(ordinal, 1); |
1091 | 1104 |
1092 // End the find session, click on the link. | 1105 // End the find session, click on the link. |
1093 tab->StopFinding(FindBarController::kActivateSelection); | 1106 tab->StopFinding(FindBarController::kActivateSelection); |
1094 EXPECT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | 1107 EXPECT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
1095 } | 1108 } |
OLD | NEW |