From 820c22f3b79c9af3f6c6c876ae515ec65606a43b Mon Sep 17 00:00:00 2001 From: Michael Wasserman Date: Tue, 15 Mar 2016 13:40:03 -0700 Subject: [PATCH] [M50 Merge] Disable Find-In-Page buttons when no text is entered This CL fixes a regression caused by https://crrev.com/1660273003 which enables the buttons of the Find-In-Page bar even if no text is entered or no search was issued yet. R=msw@chromium.org BUG=594097 TEST=FindInPageTest.ButtonsDisabledWithoutText Review URL: https://codereview.chromium.org/1785033004 Cr-Commit-Position: refs/heads/master@{#381074} (cherry picked from commit afc0733e0630499bea163c4f3cf826c945e7baaf) Review URL: https://codereview.chromium.org/1801313003 . Cr-Commit-Position: refs/branch-heads/2661@{#248} Cr-Branched-From: ef6f6ae5e4c96622286b563658d5cd62a6cf1197-refs/heads/master@{#378081} --- chrome/browser/ui/views/find_bar_host.cc | 6 ++---- chrome/browser/ui/views/find_bar_view.cc | 4 +--- .../find_bar_views_interactive_uitest.cc | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/chrome/browser/ui/views/find_bar_host.cc b/chrome/browser/ui/views/find_bar_host.cc index 283d963c919ac..a3fde9eca25b9 100644 --- a/chrome/browser/ui/views/find_bar_host.cc +++ b/chrome/browser/ui/views/find_bar_host.cc @@ -141,12 +141,10 @@ gfx::Range FindBarHost::GetSelectedRange() { void FindBarHost::UpdateUIForFindResult(const FindNotificationDetails& result, const base::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); + else + find_bar_view()->ClearMatchCount(); // We now need to check if the window is obscuring the search results. MoveWindowIfNecessary(result.selection_rect()); diff --git a/chrome/browser/ui/views/find_bar_view.cc b/chrome/browser/ui/views/find_bar_view.cc index 7cf53c30ff545..40b16b7009903 100644 --- a/chrome/browser/ui/views/find_bar_view.cc +++ b/chrome/browser/ui/views/find_bar_view.cc @@ -605,9 +605,7 @@ void FindBarView::Find(const base::string16& search_text) { } void FindBarView::UpdateMatchCountAppearance(bool no_match) { - // Enable the buttons if there is a match or if there is a match count text - // set (from a prepopulated view). - bool enable_buttons = !match_count_text_->text().empty() || !no_match; + bool enable_buttons = !match_count_text_->text().empty() && !no_match; find_previous_button_->SetEnabled(enable_buttons); find_next_button_->SetEnabled(enable_buttons); diff --git a/chrome/browser/ui/views/find_bar_views_interactive_uitest.cc b/chrome/browser/ui/views/find_bar_views_interactive_uitest.cc index b77ba95d9e35e..b3acc50f10012 100644 --- a/chrome/browser/ui/views/find_bar_views_interactive_uitest.cc +++ b/chrome/browser/ui/views/find_bar_views_interactive_uitest.cc @@ -162,6 +162,27 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, DISABLED_NavigationByMouse) { VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); } +IN_PROC_BROWSER_TEST_F(FindInPageTest, ButtonsDisabledWithoutText) { + ASSERT_TRUE(embedded_test_server()->Start()); + // Make sure Chrome is in the foreground, otherwise sending input + // won't do anything and the test will hang. + ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); + // First we navigate to any page. + ui_test_utils::NavigateToURL(browser(), + embedded_test_server()->GetURL(kSimplePage)); + // Show the Find bar. + browser()->GetFindBarController()->Show(); + EXPECT_TRUE( + ui_test_utils::IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); + + // The buttons should be disabled as there is no text entered in the find bar + // and no search has been issued yet. + ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, false, + false, false, false)); + EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), + VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON)); +} + #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) // TODO(erg): linux_aura bringup: http://crbug.com/163931 #define MAYBE_FocusRestore DISABLED_FocusRestore