diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-02 11:05:46 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-02 11:05:46 +0000 |
commit | 32af00b4ee05844f9699599c1762b2aeb6674bce (patch) | |
tree | c5346bad76e1c3e17da136cb5bda8683a1d1b8a9 /chrome | |
parent | 750d8373edacc3e0d4848aa60018f89be03379db (diff) | |
download | chromium_src-32af00b4ee05844f9699599c1762b2aeb6674bce.zip chromium_src-32af00b4ee05844f9699599c1762b2aeb6674bce.tar.gz chromium_src-32af00b4ee05844f9699599c1762b2aeb6674bce.tar.bz2 |
Fix Find regression: Match count was not cleared properly when
switching between tabs.
BUG=55594
TEST=We already have tests that test the contents of the Find
box (the search string) so I added a check for match count as well.
Review URL: http://codereview.chromium.org/5450001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67994 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/find_bar.h | 3 | ||||
-rw-r--r-- | chrome/browser/find_bar_host_browsertest.cc | 17 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.cc | 5 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/find_bar_bridge.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/find_bar_bridge.mm | 9 | ||||
-rw-r--r-- | chrome/browser/ui/views/find_bar_host.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/views/find_bar_host.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/find_bar_view.cc | 11 | ||||
-rw-r--r-- | chrome/browser/ui/views/find_bar_view.h | 6 |
10 files changed, 62 insertions, 2 deletions
diff --git a/chrome/browser/find_bar.h b/chrome/browser/find_bar.h index 041643f..9960895 100644 --- a/chrome/browser/find_bar.h +++ b/chrome/browser/find_bar.h @@ -90,6 +90,9 @@ class FindBarTesting { // Gets the search string currently visible in the Find box. virtual string16 GetFindText() = 0; + + // Gets the match count text (ie. 1 of 3) visible in the Find box. + virtual string16 GetMatchCountText() = 0; }; #endif // CHROME_BROWSER_FIND_BAR_H_ diff --git a/chrome/browser/find_bar_host_browsertest.cc b/chrome/browser/find_bar_host_browsertest.cc index 4b4ab16..e1c8993 100644 --- a/chrome/browser/find_bar_host_browsertest.cc +++ b/chrome/browser/find_bar_host_browsertest.cc @@ -90,6 +90,16 @@ class FindInPageControllerTest : public InProcessBrowserTest { return GetFindBarTextForBrowser(browser()); } + string16 GetFindBarMatchCountTextForBrowser(Browser* browser) { + FindBarTesting* find_bar = + browser->GetFindBarController()->find_bar()->GetFindBarTesting(); + return find_bar->GetMatchCountText(); + } + + string16 GetMatchCountText() { + return GetFindBarMatchCountTextForBrowser(browser()); + } + void EnsureFindBoxOpenForBrowser(Browser* browser) { browser->ShowFindBar(); gfx::Point position; @@ -870,6 +880,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) { EnsureFindBoxOpen(); EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); + EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); // Close the Find box. browser()->GetFindBarController()->EndFindSession( @@ -881,6 +892,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) { // After the Find box has been reopened, it should have been prepopulated with // the word "page" again. EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); + EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); } // This tests that whenever you open Find in a new tab it should prepopulate @@ -902,6 +914,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) { int ordinal = 0; TabContents* tab1 = browser()->GetSelectedTabContents(); EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); + EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); // Now create a second tab and load the same page. browser()->AddSelectedTabWithURL(url, PageTransition::TYPED); @@ -914,6 +927,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) { // The new tab should have "page" prepopulated, since that was the last search // in the first tab. EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); + // But it should not seem like a search has been issued. + EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText()); } // This makes sure that we can search for A in tabA, then for B in tabB and @@ -984,7 +999,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) { } // TODO(rohitrao): Searching in incognito tabs does not work in browser tests in -// linux views. Investigate and fix. http://crbug.com/40948 +// Linux views. Investigate and fix. http://crbug.com/40948 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) #define MAYBE_NoIncognitoPrepopulate DISABLED_NoIncognitoPrepopulate #else diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc index aa3429f..786990e 100644 --- a/chrome/browser/gtk/find_bar_gtk.cc +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -557,6 +557,11 @@ string16 FindBarGtk::GetFindText() { return UTF8ToUTF16(contents); } +string16 FindBarGtk::GetMatchCountText() { + std::string contents(gtk_label_get_text(GTK_LABEL(match_count_label_))); + return UTF8ToUTF16(contents); +} + void FindBarGtk::FindEntryTextInContents(bool forward_search) { TabContents* tab_contents = find_bar_controller_->tab_contents(); if (!tab_contents) diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h index ee9c0e5..f31e8b5 100644 --- a/chrome/browser/gtk/find_bar_gtk.h +++ b/chrome/browser/gtk/find_bar_gtk.h @@ -62,6 +62,7 @@ class FindBarGtk : public FindBar, virtual bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible); virtual string16 GetFindText(); + virtual string16 GetMatchCountText(); // Overridden from NotificationObserver: virtual void Observe(NotificationType type, diff --git a/chrome/browser/ui/cocoa/find_bar_bridge.h b/chrome/browser/ui/cocoa/find_bar_bridge.h index 05a1516..3a9c197 100644 --- a/chrome/browser/ui/cocoa/find_bar_bridge.h +++ b/chrome/browser/ui/cocoa/find_bar_bridge.h @@ -77,6 +77,7 @@ class FindBarBridge : public FindBar, virtual bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible); virtual string16 GetFindText(); + virtual string16 GetMatchCountText(); // Used to disable find bar animations when testing. static bool disable_animations_during_testing_; diff --git a/chrome/browser/ui/cocoa/find_bar_bridge.mm b/chrome/browser/ui/cocoa/find_bar_bridge.mm index dc9146c..07ace7e 100644 --- a/chrome/browser/ui/cocoa/find_bar_bridge.mm +++ b/chrome/browser/ui/cocoa/find_bar_bridge.mm @@ -94,3 +94,12 @@ string16 FindBarBridge::GetFindText() { NOTIMPLEMENTED(); return string16(); } + +string16 FindBarBridge::GetMatchCountText() { + // This function is currently only used in Windows and Linux specific browser + // tests (testing prepopulate values that Mac's don't rely on), but if we add + // more tests that are non-platform specific, we need to flesh out this + // function. + NOTIMPLEMENTED(); + return string16(); +} diff --git a/chrome/browser/ui/views/find_bar_host.cc b/chrome/browser/ui/views/find_bar_host.cc index e86e435..6dbea33 100644 --- a/chrome/browser/ui/views/find_bar_host.cc +++ b/chrome/browser/ui/views/find_bar_host.cc @@ -126,7 +126,11 @@ void FindBarHost::SetFindText(const string16& find_text) { } void FindBarHost::UpdateUIForFindResult(const FindNotificationDetails& result, - const string16& find_text) { + const string16& find_text) { + // Make sure match count is clear. It may get set again in UpdateForResult + // if enough data is available. + find_bar_view()->ClearMatchCount(); + if (!find_text.empty()) find_bar_view()->UpdateForResult(result, find_text); @@ -211,6 +215,10 @@ string16 FindBarHost::GetFindText() { return find_bar_view()->GetFindText(); } +string16 FindBarHost::GetMatchCountText() { + return find_bar_view()->GetMatchCountText(); +} + //////////////////////////////////////////////////////////////////////////////// // Overridden from DropdownBarHost: diff --git a/chrome/browser/ui/views/find_bar_host.h b/chrome/browser/ui/views/find_bar_host.h index cc52c87..130b876 100644 --- a/chrome/browser/ui/views/find_bar_host.h +++ b/chrome/browser/ui/views/find_bar_host.h @@ -72,6 +72,7 @@ class FindBarHost : public DropdownBarHost, virtual bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible); virtual string16 GetFindText(); + virtual string16 GetMatchCountText(); // Overridden from DropdownBarHost: // Returns the rectangle representing where to position the find bar. It uses diff --git a/chrome/browser/ui/views/find_bar_view.cc b/chrome/browser/ui/views/find_bar_view.cc index eea85a6..94d46ad 100644 --- a/chrome/browser/ui/views/find_bar_view.cc +++ b/chrome/browser/ui/views/find_bar_view.cc @@ -187,6 +187,10 @@ string16 FindBarView::GetFindText() const { return find_text_->text(); } +string16 FindBarView::GetMatchCountText() const { + return WideToUTF16Hack(match_count_text_->GetText()); +} + void FindBarView::UpdateForResult(const FindNotificationDetails& result, const string16& find_text) { bool have_valid_range = @@ -223,6 +227,13 @@ void FindBarView::UpdateForResult(const FindNotificationDetails& result, SchedulePaint(); } +void FindBarView::ClearMatchCount() { + match_count_text_->SetText(L""); + UpdateMatchCountAppearance(false); + Layout(); + SchedulePaint(); +} + void FindBarView::SetFocusAndSelection(bool select_all) { #if defined(OS_CHROMEOS) // TODO(altimofeev): this workaround is needed only when the FindBar was diff --git a/chrome/browser/ui/views/find_bar_view.h b/chrome/browser/ui/views/find_bar_view.h index a7a5e7f..f8197fe 100644 --- a/chrome/browser/ui/views/find_bar_view.h +++ b/chrome/browser/ui/views/find_bar_view.h @@ -47,11 +47,17 @@ class FindBarView : public DropdownBarView, string16 GetFindText() const; void SetFindText(const string16& find_text); + // Gets the match count text displayed in the text box. + string16 GetMatchCountText() const; + // Updates the label inside the Find text box that shows the ordinal of the // active item and how many matches were found. void UpdateForResult(const FindNotificationDetails& result, const string16& find_text); + // Clears the current Match Count value in the Find text box. + void ClearMatchCount(); + // Claims focus for the text field and selects its contents. virtual void SetFocusAndSelection(bool select_all); |