summaryrefslogtreecommitdiffstats
path: root/chrome/browser/find_bar_host_browsertest.cc
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 17:08:07 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 17:08:07 +0000
commit726bdbd79ab870b8f2d1b37ba72895cb68447a14 (patch)
tree0d7504dc32dff8f2cd48c9973a1bc9f41518787d /chrome/browser/find_bar_host_browsertest.cc
parent1456dad368c8998eaee08a30965c41ae55a32274 (diff)
downloadchromium_src-726bdbd79ab870b8f2d1b37ba72895cb68447a14.zip
chromium_src-726bdbd79ab870b8f2d1b37ba72895cb68447a14.tar.gz
chromium_src-726bdbd79ab870b8f2d1b37ba72895cb68447a14.tar.bz2
Fix prepopulate value for Find and add browser tests for it.
Notable changes: FindBarController now sets the prepopulate text during Show for the Find dialog, to fix regression 40121. It also checks not just the current find string (find_text()) but the previous one also (previous_find_text()) in MaybeSetPrepopulateText() because the current find string is blanked out when closing the Find window. And TabContents now makes sure previous_find_text() is never overwritten with an empty find_text value (to prevent the last search from being cleared if you open Find, close it without searching and open it again). This changelist also adds automated tests for the codepaths above, which results in adding a GetFindText method to the FindBarTesting interface, to allow the tests to check what string is being shown to the user when the Find box opens. BUG=40121 TEST=FindInPageControllerTest.Prepopulate* (three tests) Review URL: http://codereview.chromium.org/1560012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43620 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/find_bar_host_browsertest.cc')
-rw-r--r--chrome/browser/find_bar_host_browsertest.cc151
1 files changed, 150 insertions, 1 deletions
diff --git a/chrome/browser/find_bar_host_browsertest.cc b/chrome/browser/find_bar_host_browsertest.cc
index c6ff0d7..d168e7e 100644
--- a/chrome/browser/find_bar_host_browsertest.cc
+++ b/chrome/browser/find_bar_host_browsertest.cc
@@ -60,7 +60,6 @@ class FindInPageControllerTest : public InProcessBrowserTest {
#elif defined(OS_MACOSX)
FindBarBridge::disable_animations_during_testing_ = true;
#endif
-
}
protected:
@@ -69,6 +68,20 @@ class FindInPageControllerTest : public InProcessBrowserTest {
browser()->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetFindBarWindowInfo(position, fully_visible);
}
+
+ string16 GetFindBarText() {
+ FindBarTesting* find_bar =
+ browser()->GetFindBarController()->find_bar()->GetFindBarTesting();
+ return find_bar->GetFindText();
+ }
+
+ void EnsureFindBoxOpen() {
+ browser()->ShowFindBar();
+ gfx::Point position;
+ bool fully_visible = false;
+ EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
+ EXPECT_TRUE(fully_visible);
+ }
};
// Platform independent FindInPage that takes |const wchar_t*|
@@ -810,6 +823,142 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) {
EXPECT_EQ(tab1->find_text(), WideToUTF16(L"Default"));
}
+// This tests that whenever you close and reopen the Find bar, it should show
+// the last search entered in that tab. http://crbug.com/40121.
+IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) {
+#if defined(OS_MACOSX)
+ // FindInPage on Mac doesn't use prepopulated values. Search there is global.
+ return;
+#endif
+
+ HTTPTestServer* server = StartHTTPServer();
+
+ // First we navigate to any page.
+ GURL url = server->TestServerPageW(kSimple);
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ // Find the word "page".
+ int ordinal = 0;
+ TabContents* tab1 = browser()->GetSelectedTabContents();
+ EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
+
+ // Open the Find box.
+ EnsureFindBoxOpen();
+
+ EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
+
+ // Close the Find box.
+ browser()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
+
+ // Open the Find box again.
+ EnsureFindBoxOpen();
+
+ // After the Find box has been reopened, it should have been prepopulated with
+ // the word "page" again.
+ EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
+}
+
+// This tests that whenever you open Find in a new tab it should prepopulate
+// with a previous search term (in any tab), if a search has not been issued in
+// this tab before.
+IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) {
+#if defined(OS_MACOSX)
+ // FindInPage on Mac doesn't use prepopulated values. Search there is global.
+ return;
+#endif
+
+ HTTPTestServer* server = StartHTTPServer();
+
+ // First we navigate to any page.
+ GURL url = server->TestServerPageW(kSimple);
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ // Find the word "page".
+ int ordinal = 0;
+ TabContents* tab1 = browser()->GetSelectedTabContents();
+ EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
+
+ // Now create a second tab and load the same page.
+ browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1,
+ false, NULL);
+ browser()->SelectTabContentsAt(1, false);
+ TabContents* tab2 = browser()->GetSelectedTabContents();
+ EXPECT_NE(tab1, tab2);
+
+ // Open the Find box.
+ EnsureFindBoxOpen();
+
+ // The new tab should have "page" prepopulated, since that was the last search
+ // in the first tab.
+ EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
+}
+
+// This makes sure that we can search for A in tabA, then for B in tabB and
+// when we come back to tabA we should still see A (because that was the last
+// search in that tab).
+IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) {
+#if defined(OS_MACOSX)
+ // FindInPage on Mac doesn't use prepopulated values. Search there is global.
+ return;
+#endif
+
+ HTTPTestServer* server = StartHTTPServer();
+
+ // First we navigate to any page.
+ GURL url = server->TestServerPageW(kSimple);
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ // Find the word "page".
+ int ordinal = 0;
+ TabContents* tab1 = browser()->GetSelectedTabContents();
+ EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
+
+ // Open the Find box.
+ EnsureFindBoxOpen();
+
+ EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
+
+ // Close the Find box.
+ browser()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
+
+ // Now create a second tab and load the same page.
+ browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1,
+ false, NULL);
+ browser()->SelectTabContentsAt(1, false);
+ TabContents* tab2 = browser()->GetSelectedTabContents();
+ EXPECT_NE(tab1, tab2);
+
+ // Find "text".
+ FindInPageWchar(tab2, L"text", kFwd, kIgnoreCase, &ordinal);
+
+ // Go back to the first tab and make sure we have NOT switched the prepopulate
+ // text to "text".
+ browser()->SelectTabContentsAt(0, false);
+
+ // Open the Find box.
+ EnsureFindBoxOpen();
+
+ // After the Find box has been reopened, it should have been prepopulated with
+ // the word "page" again, since that was the last search in that tab.
+ EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
+
+ // Close the Find box.
+ browser()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
+
+ // Re-open the Find box.
+ // This is a special case: previous search in TabContents used to get cleared
+ // if you opened and closed the FindBox, which would cause the global
+ // prepopulate value to show instead of last search in this tab.
+ EnsureFindBoxOpen();
+
+ // After the Find box has been reopened, it should have been prepopulated with
+ // the word "page" again, since that was the last search in that tab.
+ EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
+}
+
// This makes sure that dismissing the find bar with kActivateSelection works.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) {
HTTPTestServer* server = StartHTTPServer();