diff options
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/find_bar_host.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_host_browsertest.cc | 794 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_host_interactive_uitest.cc | 9 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_view.cc | 6 |
4 files changed, 10 insertions, 801 deletions
diff --git a/chrome/browser/views/find_bar_host.cc b/chrome/browser/views/find_bar_host.cc index 4a7a553..4fb10b2 100644 --- a/chrome/browser/views/find_bar_host.cc +++ b/chrome/browser/views/find_bar_host.cc @@ -96,7 +96,7 @@ bool FindBarHost::AcceleratorPressed(const views::Accelerator& accelerator) { // This will end the Find session and hide the window, causing it to loose // focus and in the process unregister us as the handler for the Escape // accelerator through the FocusWillChange event. - find_bar_controller_->EndFindSession(); + find_bar_controller_->EndFindSession(FindBarController::kKeepSelection); return true; } diff --git a/chrome/browser/views/find_bar_host_browsertest.cc b/chrome/browser/views/find_bar_host_browsertest.cc deleted file mode 100644 index 21bf7b5..0000000 --- a/chrome/browser/views/find_bar_host_browsertest.cc +++ /dev/null @@ -1,794 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/keyboard_codes.h" -#include "base/message_loop.h" -#include "chrome/browser/browser.h" -#include "chrome/browser/browser_window.h" -#include "chrome/browser/find_bar_controller.h" -#include "chrome/browser/find_notification_details.h" -#include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/tab_contents/tab_contents_view.h" -#include "chrome/browser/views/find_bar_host.h" -#include "chrome/common/notification_service.h" -#include "chrome/test/in_process_browser_test.h" -#include "chrome/test/ui_test_utils.h" -#include "views/focus/focus_manager.h" - -const std::wstring kSimplePage = L"404_is_enough_for_us.html"; -const std::wstring kFramePage = L"files/find_in_page/frames.html"; -const std::wstring kFrameData = L"files/find_in_page/framedata_general.html"; -const std::wstring kUserSelectPage = L"files/find_in_page/user-select.html"; -const std::wstring kCrashPage = L"files/find_in_page/crash_1341577.html"; -const std::wstring kTooFewMatchesPage = L"files/find_in_page/bug_1155639.html"; -const std::wstring kEndState = L"files/find_in_page/end_state.html"; -const std::wstring kPrematureEnd = L"files/find_in_page/premature_end.html"; -const std::wstring kMoveIfOver = L"files/find_in_page/move_if_obscuring.html"; -const std::wstring kBitstackCrash = L"files/find_in_page/crash_14491.html"; -const std::wstring kSelectChangesOrdinal = - L"files/find_in_page/select_changes_ordinal.html"; -const std::wstring kSimple = L"files/find_in_page/simple.html"; - -const bool kBack = false; -const bool kFwd = true; - -const bool kIgnoreCase = false; -const bool kCaseSensitive = true; - -const int kMoveIterations = 30; - -class FindInPageControllerTest : public InProcessBrowserTest { - public: - FindInPageControllerTest() { - EnableDOMAutomation(); - } - - protected: - bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) { - FindBarTesting* find_bar = - browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); - return find_bar->GetFindBarWindowInfo(position, fully_visible); - } -}; - -// Platform independent FindInPage that takes |const wchat_t*| -// as an input. -int FindInPageWchar(TabContents* tab, - const wchar_t* search_str, - bool forward, - bool case_sensitive, - int* ordinal) { - return ui_test_utils::FindInPage( - tab, WideToUTF16(std::wstring(search_str)), - forward, case_sensitive, ordinal); -} - -// This test loads a page with frames and starts FindInPage requests. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our frames page. - GURL url = server->TestServerPageW(kFramePage); - ui_test_utils::NavigateToURL(browser(), url); - - // Try incremental search (mimicking user typing in). - int ordinal = 0; - TabContents* tab = browser()->GetSelectedTabContents(); - EXPECT_EQ(18, FindInPageWchar(tab, L"g", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(11, FindInPageWchar(tab, L"go", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(04, FindInPageWchar(tab, L"goo", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(03, FindInPageWchar(tab, L"goog", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(02, FindInPageWchar(tab, L"googl", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(01, FindInPageWchar(tab, L"google", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(00, FindInPageWchar(tab, L"google!", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(0, ordinal); - - // Negative test (no matches should be found). - EXPECT_EQ(0, FindInPageWchar(tab, L"Non-existing string", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(0, ordinal); - - // 'horse' only exists in the three right frames. - EXPECT_EQ(3, FindInPageWchar(tab, L"horse", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - - // 'cat' only exists in the first frame. - EXPECT_EQ(1, FindInPageWchar(tab, L"cat", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - - // Try searching again, should still come up with 1 match. - EXPECT_EQ(1, FindInPageWchar(tab, L"cat", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - - // Try searching backwards, ignoring case, should still come up with 1 match. - EXPECT_EQ(1, FindInPageWchar(tab, L"CAT", - kBack, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - - // Try case sensitive, should NOT find it. - EXPECT_EQ(0, FindInPageWchar(tab, L"CAT", - kFwd, kCaseSensitive, &ordinal)); - EXPECT_EQ(0, ordinal); - - // Try again case sensitive, but this time with right case. - EXPECT_EQ(1, FindInPageWchar(tab, L"dog", - kFwd, kCaseSensitive, &ordinal)); - EXPECT_EQ(1, ordinal); - - // Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame). - EXPECT_EQ(1, FindInPageWchar(tab, L"Hreggvi\u00F0ur", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(1, FindInPageWchar(tab, L"Hreggvi\u00F0ur", - kFwd, kCaseSensitive, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(0, FindInPageWchar(tab, L"hreggvi\u00F0ur", - kFwd, kCaseSensitive, &ordinal)); - EXPECT_EQ(0, ordinal); -} - -std::string FocusedOnPage(TabContents* tab_contents) { - std::string result; - ui_test_utils::ExecuteJavaScriptAndExtractString( - tab_contents->render_view_host(), - L"", - L"window.domAutomationController.send(getFocusedElement());", - &result); - return result; -} - -// This tests the FindInPage end-state, in other words: what is focused when you -// close the Find box (ie. if you find within a link the link should be -// focused). -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our special focus tracking page. - GURL url = server->TestServerPageW(kEndState); - ui_test_utils::NavigateToURL(browser(), url); - - TabContents* tab_contents = browser()->GetSelectedTabContents(); - ASSERT_TRUE(NULL != tab_contents); - - // Verify that nothing has focus. - ASSERT_STREQ("{nothing focused}", FocusedOnPage(tab_contents).c_str()); - - // Search for a text that exists within a link on the page. - int ordinal = 0; - EXPECT_EQ(1, FindInPageWchar(tab_contents, L"nk", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - - // End the find session, which should set focus to the link. - tab_contents->StopFinding(false); - - // Verify that the link is focused. - EXPECT_STREQ("link1", FocusedOnPage(tab_contents).c_str()); - - // Search for a text that exists within a link on the page. - EXPECT_EQ(1, FindInPageWchar(tab_contents, L"Google", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - - // Move the selection to link 1, after searching. - std::string result; - ui_test_utils::ExecuteJavaScriptAndExtractString( - tab_contents->render_view_host(), - L"", - L"window.domAutomationController.send(selectLink1());", - &result); - - // End the find session. - tab_contents->StopFinding(false); - - // Verify that link2 is not focused. - EXPECT_STREQ("", FocusedOnPage(tab_contents).c_str()); -} - -// This test loads a single-frame page and makes sure the ordinal returned makes -// sense as we FindNext over all the items. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our page. - GURL url = server->TestServerPageW(kFrameData); - ui_test_utils::NavigateToURL(browser(), url); - - // Search for 'o', which should make the first item active and return - // '1 in 3' (1st ordinal of a total of 3 matches). - TabContents* tab = browser()->GetSelectedTabContents(); - int ordinal = 0; - EXPECT_EQ(3, FindInPageWchar(tab, L"o", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(3, FindInPageWchar(tab, L"o", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(2, ordinal); - EXPECT_EQ(3, FindInPageWchar(tab, L"o", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(3, ordinal); - // Go back one match. - EXPECT_EQ(3, FindInPageWchar(tab, L"o", - kBack, kIgnoreCase, &ordinal)); - EXPECT_EQ(2, ordinal); - EXPECT_EQ(3, FindInPageWchar(tab, L"o", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(3, ordinal); - // This should wrap to the top. - EXPECT_EQ(3, FindInPageWchar(tab, L"o", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - // This should go back to the end. - EXPECT_EQ(3, FindInPageWchar(tab, L"o", - kBack, kIgnoreCase, &ordinal)); - EXPECT_EQ(3, ordinal); -} - -// This tests that the ordinal is correctly adjusted after a selection -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, - SelectChangesOrdinal_Issue20883) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our test content. - GURL url = server->TestServerPageW(kSelectChangesOrdinal); - ui_test_utils::NavigateToURL(browser(), url); - - TabContents* tab_contents = browser()->GetSelectedTabContents(); - ASSERT_TRUE(NULL != tab_contents); - - // Search for a text that exists within a link on the page. - TabContents* tab = browser()->GetSelectedTabContents(); - int ordinal = 0; - EXPECT_EQ(4, FindInPageWchar(tab_contents, - L"google", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - - // Move the selection to link 1, after searching. - std::string result; - ui_test_utils::ExecuteJavaScriptAndExtractString( - tab_contents->render_view_host(), - L"", - L"window.domAutomationController.send(selectLink1());", - &result); - - // Do a find-next after the selection. This should move forward - // from there to the 3rd instance of 'google'. - EXPECT_EQ(4, FindInPageWchar(tab, - L"google", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(3, ordinal); - - // End the find session. - tab_contents->StopFinding(false); -} - -// This test loads a page with frames and makes sure the ordinal returned makes -// sense. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our page. - GURL url = server->TestServerPageW(kFramePage); - ui_test_utils::NavigateToURL(browser(), url); - - // Search for 'a', which should make the first item active and return - // '1 in 7' (1st ordinal of a total of 7 matches). - TabContents* tab = browser()->GetSelectedTabContents(); - int ordinal = 0; - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(2, ordinal); - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(3, ordinal); - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(4, ordinal); - // Go back one, which should go back one frame. - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kBack, kIgnoreCase, &ordinal)); - EXPECT_EQ(3, ordinal); - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(4, ordinal); - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(5, ordinal); - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(6, ordinal); - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(7, ordinal); - // Now we should wrap back to frame 1. - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - // Now we should wrap back to frame last frame. - EXPECT_EQ(7, - FindInPageWchar(tab, L"a", kBack, kIgnoreCase, &ordinal)); - EXPECT_EQ(7, ordinal); -} - -// We could get ordinals out of whack when restarting search in subframes. -// See http://crbug.com/5132. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our page. - GURL url = server->TestServerPageW(kFramePage); - ui_test_utils::NavigateToURL(browser(), url); - - // Search for 'goa' three times (6 matches on page). - int ordinal = 0; - TabContents* tab = browser()->GetSelectedTabContents(); - EXPECT_EQ(6, FindInPageWchar(tab, L"goa", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(6, FindInPageWchar(tab, L"goa", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(2, ordinal); - EXPECT_EQ(6, FindInPageWchar(tab, L"goa", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(3, ordinal); - // Add space to search (should result in no matches). - EXPECT_EQ(0, FindInPageWchar(tab, L"goa ", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(0, ordinal); - // Remove the space, should be back to '3 out of 6') - EXPECT_EQ(6, FindInPageWchar(tab, L"goa", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(3, ordinal); -} - -// Load a page with no selectable text and make sure we don't crash. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnSelectableText) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our page. - GURL url = server->TestServerPageW(kUserSelectPage); - ui_test_utils::NavigateToURL(browser(), url); - - int ordinal = 0; - TabContents* tab = browser()->GetSelectedTabContents(); - EXPECT_EQ(0, FindInPageWchar(tab, L"text", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(-1, ordinal); // Nothing is selected. - EXPECT_EQ(0, FindInPageWchar(tab, L"Non-existing string", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(0, ordinal); -} - -// Try to reproduce the crash seen in issue 1341577. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our page. - GURL url = server->TestServerPageW(kCrashPage); - ui_test_utils::NavigateToURL(browser(), url); - - // This would crash the tab. These must be the first two find requests issued - // against the frame, otherwise an active frame pointer is set and it wont - // produce the crash. - // We used to check the return value and |ordinal|. With ICU 4.2, FiP does - // not find a stand-alone dependent vowel sign of Indic scripts. So, the - // exptected values are all 0. To make this test pass regardless of - // ICU version, we just call FiP and see if there's any crash. - // TODO(jungshik): According to a native Malayalam speaker, it's ok not - // to find U+0D4C. Still need to investigate further this issue. - int ordinal = 0; - TabContents* tab = browser()->GetSelectedTabContents(); - FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); - FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); - - // This should work fine. - EXPECT_EQ(1, FindInPageWchar(tab, L"\u0D24\u0D46", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - EXPECT_EQ(0, FindInPageWchar(tab, L"nostring", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(0, ordinal); -} - -// Try to reproduce the crash seen in http://crbug.com/14491, where an assert -// hits in the BitStack size comparison in WebKit. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our page. - GURL url = server->TestServerPageW(kBitstackCrash); - ui_test_utils::NavigateToURL(browser(), url); - - // This used to crash the tab. - int ordinal = 0; - EXPECT_EQ(0, FindInPageWchar(browser()->GetSelectedTabContents(), - L"s", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(0, ordinal); -} - -// Test to make sure Find does the right thing when restarting from a timeout. -// We used to have a problem where we'd stop finding matches when all of the -// following conditions were true: -// 1) The page has a lot of text to search. -// 2) The page contains more than one match. -// 3) It takes longer than the time-slice given to each Find operation (100 -// ms) to find one or more of those matches (so Find times out and has to try -// again from where it left off). -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our page. - GURL url = server->TestServerPageW(kTooFewMatchesPage); - ui_test_utils::NavigateToURL(browser(), url); - - // This string appears 5 times at the bottom of a long page. If Find restarts - // properly after a timeout, it will find 5 matches, not just 1. - int ordinal = 0; - EXPECT_EQ(5, FindInPageWchar(browser()->GetSelectedTabContents(), - L"008.xml", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); -} - -// This tests bug 11761: FindInPage terminates search prematurely. -// This test will be enabled once the bug is fixed. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, - DISABLED_FindInPagePrematureEnd) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our special focus tracking page. - GURL url = server->TestServerPageW(kPrematureEnd); - ui_test_utils::NavigateToURL(browser(), url); - - TabContents* tab_contents = browser()->GetSelectedTabContents(); - ASSERT_TRUE(NULL != tab_contents); - - // Search for a text that exists within a link on the page. - int ordinal = 0; - EXPECT_EQ(2, FindInPageWchar(tab_contents, L"html ", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); -} - -// Make sure Find box disappears on Navigate but not on Refresh. -#if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) -// The last EXPECT_FALSE(fully_visible) is failing all the time on -// the linux_views bot. See bug: http://crbug.com/28629. -#define FindDisappearOnNavigate DISABLED_FindDisappearOnNavigate -#endif -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our special focus tracking page. - GURL url = server->TestServerPageW(kSimplePage); - GURL url2 = server->TestServerPageW(kFramePage); - ui_test_utils::NavigateToURL(browser(), url); - - // Open the Find window with animations disabled. - DropdownBarHost::disable_animations_during_testing_ = true; - browser()->ShowFindBar(); - - gfx::Point position; - bool fully_visible = false; - - // Make sure it is open. - EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); - EXPECT_TRUE(fully_visible); - - // Reload the tab and make sure Find window doesn't go away. - browser()->Reload(); - - EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); - EXPECT_TRUE(fully_visible); - - // Navigate and make sure the Find window goes away. - ui_test_utils::NavigateToURL(browser(), url2); - - EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); - EXPECT_FALSE(fully_visible); -} - -// Make sure Find box disappears when History/Downloads page is opened, and -// when a New Tab is opened. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, - FindDisappearOnNewTabAndHistory) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to our special focus tracking page. - GURL url = server->TestServerPageW(kSimplePage); - ui_test_utils::NavigateToURL(browser(), url); - - // Open the Find window with animations disabled. - DropdownBarHost::disable_animations_during_testing_ = true; - browser()->ShowFindBar(); - - gfx::Point position; - bool fully_visible = false; - - // Make sure it is open. - EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); - EXPECT_TRUE(fully_visible); - - // Open another tab (tab B). - browser()->NewTab(); - ui_test_utils::NavigateToURL(browser(), url); - - // Make sure Find box is closed. - EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); - EXPECT_FALSE(fully_visible); - - // Close tab B. - browser()->CloseTab(); - - // Make sure Find window appears again. - EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); - EXPECT_TRUE(fully_visible); - - browser()->ShowHistoryTab(); - - // Make sure Find box is closed. - EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); - EXPECT_FALSE(fully_visible); -} - -// Make sure Find box moves out of the way if it is obscuring the active match. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) { - HTTPTestServer* server = StartHTTPServer(); - - GURL url = server->TestServerPageW(kMoveIfOver); - ui_test_utils::NavigateToURL(browser(), url); - - // Open the Find window with animations disabled. - DropdownBarHost::disable_animations_during_testing_ = true; - browser()->ShowFindBar(); - - gfx::Point start_position; - gfx::Point position; - bool fully_visible = false; - - // Make sure it is open. - EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible)); - EXPECT_TRUE(fully_visible); - - // Search for 'Chromium' which the Find box is obscuring. - int ordinal = 0; - TabContents* tab = browser()->GetSelectedTabContents(); - int index = 0; - for (; index < kMoveIterations; ++index) { - EXPECT_EQ(kMoveIterations, FindInPageWchar(tab, L"Chromium", - kFwd, kIgnoreCase, &ordinal)); - - // Check the position. - EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); - EXPECT_TRUE(fully_visible); - - // If the Find box has moved then we are done. - if (position.x() != start_position.x()) - break; - } - - // We should not have reached the end. - ASSERT_GT(kMoveIterations, index); - - // Search for something guaranteed not to be obscured by the Find box. - EXPECT_EQ(1, FindInPageWchar(tab, L"Done", - kFwd, kIgnoreCase, &ordinal)); - // Check the position. - EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); - EXPECT_TRUE(fully_visible); - - // Make sure Find box has moved back to its original location. - EXPECT_EQ(position.x(), start_position.x()); -} - -// Make sure F3 in a new tab works if Find has previous string to search for. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, - FindNextInNewTabUsesPrepopulate) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to any page. - GURL url = server->TestServerPageW(kSimplePage); - ui_test_utils::NavigateToURL(browser(), url); - - // Search for 'no_match'. No matches should be found. - int ordinal = 0; - TabContents* tab = browser()->GetSelectedTabContents(); - EXPECT_EQ(0, FindInPageWchar(tab, L"no_match", - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(0, ordinal); - - // Open another tab (tab B). - browser()->NewTab(); - ui_test_utils::NavigateToURL(browser(), url); - - // Simulate what happens when you press F3 for FindNext. We should get a - // response here (a hang means search was aborted). - EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(), - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(0, ordinal); - - // Open another tab (tab C). - browser()->NewTab(); - ui_test_utils::NavigateToURL(browser(), url); - - // Simulate what happens when you press F3 for FindNext. We should get a - // response here (a hang means search was aborted). - EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(), - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(0, ordinal); -} - -// Make sure Find box grabs the Esc accelerator and restores it again. -#if defined(OS_LINUX) -// TODO(oshima): On Gtk/Linux, a focus out event is asynchronous and -// hiding a find bar does not immediately update the target -// accelerator. The last condition fails in most cases due to this -// behavior. See http://crbug.com/26870. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, - DISABLED_AcceleratorRestoring) { -#else - IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) { -#endif - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to any page. - GURL url = server->TestServerPageW(kSimplePage); - ui_test_utils::NavigateToURL(browser(), url); - -#if defined(OS_WIN) - // TODO(oshima): Windows code assumes that NativeView is - // assignable from NativeWindow, which is not true on other platforms. - // This has to be fixed, probably by having explicit - // GetNativeView / GetNativewWindow methods on BrowserWindow. - // See http://crbug.com/26873. - gfx::NativeView browser_view = browser()->window()->GetNativeHandle(); -#elif defined(OS_LINUX) - gfx::NativeView browser_view = - GTK_WIDGET(browser()->window()->GetNativeHandle()); -#else - // Mac does not use views. - NOTREACHED(); -#endif - - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManagerForNativeView(browser_view); - - // See where Escape is registered. - views::Accelerator escape(base::VKEY_ESCAPE, false, false, false); - views::AcceleratorTarget* old_target = - focus_manager->GetCurrentTargetForAccelerator(escape); - EXPECT_TRUE(old_target != NULL); - - // Open the Find window with animations disabled. - DropdownBarHost::disable_animations_during_testing_ = true; - browser()->ShowFindBar(); - - // Our Find bar should be the new target. - views::AcceleratorTarget* new_target = - focus_manager->GetCurrentTargetForAccelerator(escape); - - EXPECT_TRUE(new_target != NULL); - EXPECT_NE(new_target, old_target); - - // Close the Find box. - browser()->GetFindBarController()->EndFindSession(); - - // The accelerator for Escape should be back to what it was before. - EXPECT_EQ(old_target, - focus_manager->GetCurrentTargetForAccelerator(escape)); -} - -// Make sure Find box does not become UI-inactive when no text is in the box as -// we switch to a tab contents with an empty find string. See issue 13570. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to any page. - GURL url = server->TestServerPageW(kSimplePage); - ui_test_utils::NavigateToURL(browser(), url); - - // Open the Find window with animations disabled. - DropdownBarHost::disable_animations_during_testing_ = true; - browser()->ShowFindBar(); - - // Simulate a user clearing the search string. Ideally, we should be - // simulating keypresses here for searching for something and pressing - // backspace, but that's been proven flaky in the past, so we go straight to - // tab_contents. - TabContents* tab_contents = browser()->GetSelectedTabContents(); - // Stop the (non-existing) find operation, and clear the selection (which - // signals the UI is still active). - tab_contents->StopFinding(true); - // Make sure the Find UI flag hasn't been cleared, it must be so that the UI - // still responds to browser window resizing. - ASSERT_TRUE(tab_contents->find_ui_active()); -} - -// Make sure F3 works after you FindNext a couple of times and end the Find -// session. See issue http://crbug.com/28306. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { - HTTPTestServer* server = StartHTTPServer(); - - // First we navigate to a simple page. - GURL url = server->TestServerPageW(kSimple); - ui_test_utils::NavigateToURL(browser(), url); - - // Search for 'page'. Should have 1 match. - int ordinal = 0; - TabContents* tab = browser()->GetSelectedTabContents(); - EXPECT_EQ(1, FindInPageWchar(tab, L"page", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - - // Simulate what happens when you press F3 for FindNext. Still should show - // one match. This cleared the pre-populate string at one point (see bug). - EXPECT_EQ(1, ui_test_utils::FindInPage(tab, string16(), - kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); - - // End the Find session, thereby making the next F3 start afresh. - browser()->GetFindBarController()->EndFindSession(); - - // Simulate F3 while Find box is closed. Should have 1 match. - EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal)); - EXPECT_EQ(1, ordinal); -} - -// When re-opening the find bar with F3, the find bar should be re-populated -// with the last search from the same tab rather than the last overall search. -// http://crbug.com/30006 -#if defined(OS_CHROMEOS) -#define PreferPreviousSearch FLAKY_PreferPreviousSearch -#endif -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { - HTTPTestServer* server = StartHTTPServer(); - - DropdownBarHost::disable_animations_during_testing_ = true; - - // First we navigate to any page. - GURL url = server->TestServerPageW(kSimplePage); - ui_test_utils::NavigateToURL(browser(), url); - - // Find "Default". - int ordinal = 0; - TabContents* tab1 = browser()->GetSelectedTabContents(); - EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal)); - - // Create a second tab. - browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1, - false, NULL); - browser()->SelectTabContentsAt(1, false); - TabContents* tab2 = browser()->GetSelectedTabContents(); - EXPECT_NE(tab1, tab2); - - // Find "given". - FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); - - // Switch back to first tab. - browser()->SelectTabContentsAt(0, false); - browser()->GetFindBarController()->EndFindSession(); - // Simulate F3. - ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal); - EXPECT_EQ(tab1->find_text(), WideToUTF16(L"Default")); -} diff --git a/chrome/browser/views/find_bar_host_interactive_uitest.cc b/chrome/browser/views/find_bar_host_interactive_uitest.cc index 3e6e48a..0b66cc9 100644 --- a/chrome/browser/views/find_bar_host_interactive_uitest.cc +++ b/chrome/browser/views/find_bar_host_interactive_uitest.cc @@ -125,7 +125,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) { // Ensure the creation of the find bar controller. browser()->GetFindBarController()->Show(); EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID()); - browser()->GetFindBarController()->EndFindSession(); + browser()->GetFindBarController()->EndFindSession( + FindBarController::kKeepSelection); EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID()); // Focus the location bar, find something on the page, close the find box, @@ -135,7 +136,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) { EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID()); ui_test_utils::FindInPage(browser()->GetSelectedTabContents(), L"a", true, false, NULL); - browser()->GetFindBarController()->EndFindSession(); + browser()->GetFindBarController()->EndFindSession( + FindBarController::kKeepSelection); EXPECT_EQ(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW, GetFocusedViewID()); // Focus the location bar, open and close the find box, focus should return to @@ -145,6 +147,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) { EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID()); browser()->GetFindBarController()->Show(); EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID()); - browser()->GetFindBarController()->EndFindSession(); + browser()->GetFindBarController()->EndFindSession( + FindBarController::kKeepSelection); EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID()); } diff --git a/chrome/browser/views/find_bar_view.cc b/chrome/browser/views/find_bar_view.cc index 8eb432d..a8cb944 100644 --- a/chrome/browser/views/find_bar_view.cc +++ b/chrome/browser/views/find_bar_view.cc @@ -406,7 +406,8 @@ void FindBarView::ButtonPressed( } break; case CLOSE_TAG: - find_bar_host()->GetFindBarController()->EndFindSession(); + find_bar_host()->GetFindBarController()->EndFindSession( + FindBarController::kKeepSelection); break; default: NOTREACHED() << L"Unknown button"; @@ -434,8 +435,7 @@ void FindBarView::ContentsChanged(views::Textfield* sender, // The last two params here are forward (true) and case sensitive (false). controller->tab_contents()->StartFinding(new_contents, true, false); } else { - // The textbox is empty so we reset. true = clear selection on page. - controller->tab_contents()->StopFinding(true); + controller->tab_contents()->StopFinding(FindBarController::kClearSelection); UpdateForResult(controller->tab_contents()->find_result(), string16()); } } |