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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 int ordinal = 0; | 1174 int ordinal = 0; |
1175 WebContents* web_contents = | 1175 WebContents* web_contents = |
1176 browser()->tab_strip_model()->GetActiveWebContents(); | 1176 browser()->tab_strip_model()->GetActiveWebContents(); |
1177 EXPECT_EQ(1, FindInPageASCII(web_contents, "page", | 1177 EXPECT_EQ(1, FindInPageASCII(web_contents, "page", |
1178 kFwd, kIgnoreCase, &ordinal)); | 1178 kFwd, kIgnoreCase, &ordinal)); |
1179 | 1179 |
1180 // Open the Find box. | 1180 // Open the Find box. |
1181 EnsureFindBoxOpen(); | 1181 EnsureFindBoxOpen(); |
1182 | 1182 |
1183 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); | 1183 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); |
1184 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); | 1184 EXPECT_EQ(ASCIIToUTF16("1/1"), GetMatchCountText()); |
1185 | 1185 |
1186 // Close the Find box. | 1186 // Close the Find box. |
1187 browser()->GetFindBarController()->EndFindSession( | 1187 browser()->GetFindBarController()->EndFindSession( |
1188 FindBarController::kKeepSelectionOnPage, | 1188 FindBarController::kKeepSelectionOnPage, |
1189 FindBarController::kKeepResultsInFindBox); | 1189 FindBarController::kKeepResultsInFindBox); |
1190 | 1190 |
1191 // Open the Find box again. | 1191 // Open the Find box again. |
1192 EnsureFindBoxOpen(); | 1192 EnsureFindBoxOpen(); |
1193 | 1193 |
1194 // After the Find box has been reopened, it should have been prepopulated with | 1194 // After the Find box has been reopened, it should have been prepopulated with |
1195 // the word "page" again. | 1195 // the word "page" again. |
1196 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); | 1196 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); |
1197 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); | 1197 EXPECT_EQ(ASCIIToUTF16("1/1"), GetMatchCountText()); |
1198 } | 1198 } |
1199 | 1199 |
1200 // This tests that whenever you open Find in a new tab it should prepopulate | 1200 // This tests that whenever you open Find in a new tab it should prepopulate |
1201 // with a previous search term (in any tab), if a search has not been issued in | 1201 // with a previous search term (in any tab), if a search has not been issued in |
1202 // this tab before. | 1202 // this tab before. |
1203 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) { | 1203 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) { |
1204 // First we navigate to any page. | 1204 // First we navigate to any page. |
1205 GURL url = GetURL(kSimple); | 1205 GURL url = GetURL(kSimple); |
1206 ui_test_utils::NavigateToURL(browser(), url); | 1206 ui_test_utils::NavigateToURL(browser(), url); |
1207 | 1207 |
1208 // Search for the word "page". | 1208 // Search for the word "page". |
1209 int ordinal = 0; | 1209 int ordinal = 0; |
1210 WebContents* web_contents_1 = | 1210 WebContents* web_contents_1 = |
1211 browser()->tab_strip_model()->GetActiveWebContents(); | 1211 browser()->tab_strip_model()->GetActiveWebContents(); |
1212 EXPECT_EQ(1, FindInPageASCII(web_contents_1, "page", | 1212 EXPECT_EQ(1, FindInPageASCII(web_contents_1, "page", |
1213 kFwd, kIgnoreCase, &ordinal)); | 1213 kFwd, kIgnoreCase, &ordinal)); |
1214 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); | 1214 EXPECT_EQ(ASCIIToUTF16("1/1"), GetMatchCountText()); |
1215 | 1215 |
1216 // Now create a second tab and load the same page. | 1216 // Now create a second tab and load the same page. |
1217 chrome::AddSelectedTabWithURL(browser(), url, ui::PAGE_TRANSITION_TYPED); | 1217 chrome::AddSelectedTabWithURL(browser(), url, ui::PAGE_TRANSITION_TYPED); |
1218 WebContents* web_contents_2 = | 1218 WebContents* web_contents_2 = |
1219 browser()->tab_strip_model()->GetActiveWebContents(); | 1219 browser()->tab_strip_model()->GetActiveWebContents(); |
1220 EXPECT_NE(web_contents_1, web_contents_2); | 1220 EXPECT_NE(web_contents_1, web_contents_2); |
1221 | 1221 |
1222 // Open the Find box. | 1222 // Open the Find box. |
1223 EnsureFindBoxOpen(); | 1223 EnsureFindBoxOpen(); |
1224 | 1224 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 1467 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
1468 GlobalPasteBoardClearMatches) { | 1468 GlobalPasteBoardClearMatches) { |
1469 FindBar* find_bar = browser()->GetFindBarController()->find_bar(); | 1469 FindBar* find_bar = browser()->GetFindBarController()->find_bar(); |
1470 if (!find_bar->HasGlobalFindPasteboard()) | 1470 if (!find_bar->HasGlobalFindPasteboard()) |
1471 return; | 1471 return; |
1472 | 1472 |
1473 // First we navigate to any page. | 1473 // First we navigate to any page. |
1474 GURL url = GetURL(kSimple); | 1474 GURL url = GetURL(kSimple); |
1475 ui_test_utils::NavigateToURL(browser(), url); | 1475 ui_test_utils::NavigateToURL(browser(), url); |
1476 | 1476 |
1477 // Change the match count on the first tab to "1 of 1". | 1477 // Change the match count on the first tab to "1/1". |
1478 int ordinal = 0; | 1478 int ordinal = 0; |
1479 WebContents* web_contents_1 = | 1479 WebContents* web_contents_1 = |
1480 browser()->tab_strip_model()->GetActiveWebContents(); | 1480 browser()->tab_strip_model()->GetActiveWebContents(); |
1481 EXPECT_EQ(1, FindInPageASCII(web_contents_1, "page", | 1481 EXPECT_EQ(1, FindInPageASCII(web_contents_1, "page", |
1482 kFwd, kIgnoreCase, &ordinal)); | 1482 kFwd, kIgnoreCase, &ordinal)); |
1483 EnsureFindBoxOpen(); | 1483 EnsureFindBoxOpen(); |
1484 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); | 1484 EXPECT_EQ(ASCIIToUTF16("1/1"), GetMatchCountText()); |
1485 | 1485 |
1486 // Next, do a search in a second tab. | 1486 // Next, do a search in a second tab. |
1487 chrome::AddTabAt(browser(), GURL(), -1, true); | 1487 chrome::AddTabAt(browser(), GURL(), -1, true); |
1488 ui_test_utils::NavigateToURL(browser(), url); | 1488 ui_test_utils::NavigateToURL(browser(), url); |
1489 WebContents* web_contents_2 = | 1489 WebContents* web_contents_2 = |
1490 browser()->tab_strip_model()->GetActiveWebContents(); | 1490 browser()->tab_strip_model()->GetActiveWebContents(); |
1491 FindInPageASCII(web_contents_2, "text", kFwd, kIgnoreCase, &ordinal); | 1491 FindInPageASCII(web_contents_2, "text", kFwd, kIgnoreCase, &ordinal); |
1492 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); | 1492 EXPECT_EQ(ASCIIToUTF16("1/1"), GetMatchCountText()); |
1493 | 1493 |
1494 // Go back to the first tab and verify that the match text is cleared. | 1494 // Go back to the first tab and verify that the match text is cleared. |
1495 // text to "text". | 1495 // text to "text". |
1496 browser()->tab_strip_model()->ActivateTabAt(0, false); | 1496 browser()->tab_strip_model()->ActivateTabAt(0, false); |
1497 EXPECT_TRUE(GetMatchCountText().empty()); | 1497 EXPECT_TRUE(GetMatchCountText().empty()); |
1498 } | 1498 } |
1499 | 1499 |
1500 // Verify that Incognito window doesn't propagate find string to other widows. | 1500 // Verify that Incognito window doesn't propagate find string to other widows. |
1501 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, GlobalPasteboardIncognito) { | 1501 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, GlobalPasteboardIncognito) { |
1502 Browser* browser_incognito = CreateIncognitoBrowser(); | 1502 Browser* browser_incognito = CreateIncognitoBrowser(); |
(...skipping 18 matching lines...) Expand all Loading... |
1521 FindInPageASCII(web_contents, "bar", kFwd, kIgnoreCase, NULL); | 1521 FindInPageASCII(web_contents, "bar", kFwd, kIgnoreCase, NULL); |
1522 | 1522 |
1523 Browser* browser_incognito = CreateIncognitoBrowser(); | 1523 Browser* browser_incognito = CreateIncognitoBrowser(); |
1524 ui_test_utils::NavigateToURL(browser_incognito, | 1524 ui_test_utils::NavigateToURL(browser_incognito, |
1525 GURL("data:text/plain,barfoofoo")); | 1525 GURL("data:text/plain,barfoofoo")); |
1526 WebContents* web_contents_incognito = | 1526 WebContents* web_contents_incognito = |
1527 browser_incognito->tab_strip_model()->GetActiveWebContents(); | 1527 browser_incognito->tab_strip_model()->GetActiveWebContents(); |
1528 FindInPageASCII(web_contents_incognito, "foo", true, kIgnoreCase, NULL); | 1528 FindInPageASCII(web_contents_incognito, "foo", true, kIgnoreCase, NULL); |
1529 EXPECT_EQ(ASCIIToUTF16("foo"), | 1529 EXPECT_EQ(ASCIIToUTF16("foo"), |
1530 GetFindBarTextForBrowser(browser_incognito)); | 1530 GetFindBarTextForBrowser(browser_incognito)); |
1531 EXPECT_EQ(ASCIIToUTF16("1 of 2"), | 1531 EXPECT_EQ(ASCIIToUTF16("1/2"), |
1532 GetFindBarMatchCountTextForBrowser(browser_incognito)); | 1532 GetFindBarMatchCountTextForBrowser(browser_incognito)); |
1533 | 1533 |
1534 // Close the find bar. | 1534 // Close the find bar. |
1535 FindTabHelper* find_tab_helper = | 1535 FindTabHelper* find_tab_helper = |
1536 FindTabHelper::FromWebContents(web_contents_incognito); | 1536 FindTabHelper::FromWebContents(web_contents_incognito); |
1537 find_tab_helper->StopFinding(FindBarController::kActivateSelectionOnPage); | 1537 find_tab_helper->StopFinding(FindBarController::kActivateSelectionOnPage); |
1538 | 1538 |
1539 // Cmd + G triggers IDC_FIND_NEXT command. Thus we test FindInPage() | 1539 // Cmd + G triggers IDC_FIND_NEXT command. Thus we test FindInPage() |
1540 // method from browser_commands.cc. FindInPage16() bypasses it. | 1540 // method from browser_commands.cc. FindInPage16() bypasses it. |
1541 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT)); | 1541 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT)); |
1542 ui_test_utils::FindInPageNotificationObserver observer( | 1542 ui_test_utils::FindInPageNotificationObserver observer( |
1543 web_contents_incognito); | 1543 web_contents_incognito); |
1544 observer.Wait(); | 1544 observer.Wait(); |
1545 EXPECT_EQ(ASCIIToUTF16("foo"), | 1545 EXPECT_EQ(ASCIIToUTF16("foo"), |
1546 GetFindBarTextForBrowser(browser_incognito)); | 1546 GetFindBarTextForBrowser(browser_incognito)); |
1547 EXPECT_EQ(ASCIIToUTF16("2 of 2"), | 1547 EXPECT_EQ(ASCIIToUTF16("2/2"), |
1548 GetFindBarMatchCountTextForBrowser(browser_incognito)); | 1548 GetFindBarMatchCountTextForBrowser(browser_incognito)); |
1549 } | 1549 } |
1550 | 1550 |
1551 // Find text in regular window, send IDC_FIND_NEXT to incognito. It should | 1551 // Find text in regular window, send IDC_FIND_NEXT to incognito. It should |
1552 // search for the first phrase. | 1552 // search for the first phrase. |
1553 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, IncognitoFindNextShared) { | 1553 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, IncognitoFindNextShared) { |
1554 WebContents* web_contents = | 1554 WebContents* web_contents = |
1555 browser()->tab_strip_model()->GetActiveWebContents(); | 1555 browser()->tab_strip_model()->GetActiveWebContents(); |
1556 // On Mac this updates the find pboard. | 1556 // On Mac this updates the find pboard. |
1557 FindInPageASCII(web_contents, "bar", kFwd, kIgnoreCase, NULL); | 1557 FindInPageASCII(web_contents, "bar", kFwd, kIgnoreCase, NULL); |
1558 | 1558 |
1559 Browser* browser_incognito = CreateIncognitoBrowser(); | 1559 Browser* browser_incognito = CreateIncognitoBrowser(); |
1560 ui_test_utils::NavigateToURL(browser_incognito, | 1560 ui_test_utils::NavigateToURL(browser_incognito, |
1561 GURL("data:text/plain,bar")); | 1561 GURL("data:text/plain,bar")); |
1562 | 1562 |
1563 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT)); | 1563 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT)); |
1564 WebContents* web_contents_incognito = | 1564 WebContents* web_contents_incognito = |
1565 browser_incognito->tab_strip_model()->GetActiveWebContents(); | 1565 browser_incognito->tab_strip_model()->GetActiveWebContents(); |
1566 ui_test_utils::FindInPageNotificationObserver observer( | 1566 ui_test_utils::FindInPageNotificationObserver observer( |
1567 web_contents_incognito); | 1567 web_contents_incognito); |
1568 observer.Wait(); | 1568 observer.Wait(); |
1569 EXPECT_EQ(ASCIIToUTF16("bar"), | 1569 EXPECT_EQ(ASCIIToUTF16("bar"), |
1570 GetFindBarTextForBrowser(browser_incognito)); | 1570 GetFindBarTextForBrowser(browser_incognito)); |
1571 } | 1571 } |
OLD | NEW |