diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-22 20:28:12 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-22 20:28:12 +0000 |
commit | e491f1cb8247090047bd8c895e9bd2bf4de5ee5a (patch) | |
tree | df56a34ca44028d65cde514853cb3feda0c8b839 | |
parent | 44c875a167d5ce78000d8843190a8c22d2236e54 (diff) | |
download | chromium_src-e491f1cb8247090047bd8c895e9bd2bf4de5ee5a.zip chromium_src-e491f1cb8247090047bd8c895e9bd2bf4de5ee5a.tar.gz chromium_src-e491f1cb8247090047bd8c895e9bd2bf4de5ee5a.tar.bz2 |
Fix bug 12468 where F3 (FindNext) in a brand new tab was not using prepopulated search (what you have searched for in other tabs).
TEST=Covered by in-process-browser test now. To test manually: open a tab, search for something in FindInPage, Press Ctrl+T and then F3. It should search for the same thing in the newly opened tab.
BUG=12468
Review URL: http://codereview.chromium.org/115714
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16786 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser.cc | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/find_bar_cocoa_controller.mm | 6 | ||||
-rw-r--r-- | chrome/browser/find_backend_unittest.cc | 15 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.cc | 3 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 42 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 26 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_view.cc | 9 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_win_browsertest.cc | 167 |
8 files changed, 157 insertions, 114 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 1c9885c..618fb4a 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -2610,7 +2610,8 @@ void Browser::FindInPage(bool find_next, bool forward_direction) { ShowFindBar(); if (find_next) { GetSelectedTabContents()->StartFinding(string16(), - forward_direction); + forward_direction, + false); // Not case sensitive. } } diff --git a/chrome/browser/cocoa/find_bar_cocoa_controller.mm b/chrome/browser/cocoa/find_bar_cocoa_controller.mm index cedc89a..e9d38c9 100644 --- a/chrome/browser/cocoa/find_bar_cocoa_controller.mm +++ b/chrome/browser/cocoa/find_bar_cocoa_controller.mm @@ -42,14 +42,14 @@ if (findBarBridge_) findBarBridge_->GetFindBarController()->tab_contents()->StartFinding( base::SysNSStringToUTF16([findText_ stringValue]), - false); + false, false); } - (IBAction)nextResult:(id)sender { if (findBarBridge_) findBarBridge_->GetFindBarController()->tab_contents()->StartFinding( base::SysNSStringToUTF16([findText_ stringValue]), - true); + true, false); } // Positions the find bar view in the correct location based on the @@ -87,7 +87,7 @@ string16 findText = base::SysNSStringToUTF16([findText_ stringValue]); if (findText.length() > 0) { - tab_contents->StartFinding(findText, true); + tab_contents->StartFinding(findText, true, false); } else { // The textbox is empty so we reset. tab_contents->StopFinding(true); // true = clear selection on page. diff --git a/chrome/browser/find_backend_unittest.cc b/chrome/browser/find_backend_unittest.cc index 3b2cdcc..4179cc2 100644 --- a/chrome/browser/find_backend_unittest.cc +++ b/chrome/browser/find_backend_unittest.cc @@ -27,8 +27,9 @@ TEST_F(FindBackendTest, InternalState) { string16 search_term2 = L" but the economy "; string16 search_term3 = L" eated it. "; - // Start searching in the first TabContents. - contents()->StartFinding(search_term1, true); // true=forward. + // Start searching in the first TabContents, searching forwards but not case + // sensitive (as indicated by the last two params). + contents()->StartFinding(search_term1, true, false); // Pre-populate string should always match between the two, but find_text // should not. @@ -37,8 +38,9 @@ TEST_F(FindBackendTest, InternalState) { EXPECT_EQ(search_term1, contents2.find_prepopulate_text()); EXPECT_EQ(string16(), contents2.find_text()); - // Now search in the other TabContents. - contents2.StartFinding(search_term2, true); // true=forward. + // Now search in the other TabContents, searching forwards but not case + // sensitive (as indicated by the last two params). + contents2.StartFinding(search_term2, true, false); // Again, pre-populate string should always match between the two, but // find_text should not. @@ -47,8 +49,9 @@ TEST_F(FindBackendTest, InternalState) { EXPECT_EQ(search_term2, contents2.find_prepopulate_text()); EXPECT_EQ(search_term2, contents2.find_text()); - // Search again in the first TabContents. - contents()->StartFinding(search_term3, true); // true=forward. + // Search again in the first TabContents, searching forwards but not case + // sensitive (as indicated by the last two params). + contents()->StartFinding(search_term3, true, false); // Once more, pre-populate string should always match between the two, but // find_text should not. diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc index d4c3c9b..73f5c11 100644 --- a/chrome/browser/gtk/find_bar_gtk.cc +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -322,7 +322,8 @@ void FindBarGtk::FindEntryTextInContents(bool forward_search) { std::string new_contents(gtk_entry_get_text(GTK_ENTRY(text_entry_))); if (new_contents.length() > 0) { - tab_contents->StartFinding(UTF8ToUTF16(new_contents), forward_search); + tab_contents->StartFinding(UTF8ToUTF16(new_contents), forward_search, + false); // Not case sensitive. } else { // The textbox is empty so we reset. tab_contents->StopFinding(true); // true = clear selection on page. diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 776a5b5..0083ae2 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -241,8 +241,9 @@ TabContents::TabContents(Profile* profile, find_op_aborted_(false), current_find_request_id_(find_request_id_counter_++), find_text_(), - find_prepopulate_text_(NULL), - find_result_(), + last_search_case_sensitive_(false), + last_search_prepopulate_text_(NULL), + last_search_result_(), capturing_contents_(false), is_being_destroyed_(false), notify_disconnection_(false), @@ -276,7 +277,7 @@ TabContents::TabContents(Profile* profile, // Keep a global copy of the previous search string (if any). static string16 global_last_search = string16(); - find_prepopulate_text_ = &global_last_search; + last_search_prepopulate_text_ = &global_last_search; } TabContents::~TabContents() { @@ -1014,12 +1015,17 @@ void TabContents::DidMoveOrResize(ConstrainedWindow* window) { #endif } -void TabContents::StartFinding(const string16& find_text, - bool forward_direction) { +void TabContents::StartFinding(string16 find_text, + bool forward_direction, + bool case_sensitive) { // If find_text is empty, it means FindNext was pressed with a keyboard // shortcut so unless we have something to search for we return early. - if (find_text.empty() && find_text_.empty()) - return; + if (find_text.empty() && find_text_.empty()) { + if (last_search_prepopulate_text_->empty()) + return; + // Try whatever we searched for last in any tab. + find_text = *last_search_prepopulate_text_; + } // This is a FindNext operation if we are searching for the same text again, // or if the passed in search text is empty (FindNext keyboard shortcut). The @@ -1028,29 +1034,31 @@ void TabContents::StartFinding(const string16& find_text, // therefore treat FindNext after an aborted Find operation as a full fledged // Find. bool find_next = (find_text_ == find_text || find_text.empty()) && + (last_search_case_sensitive_ == case_sensitive) && !find_op_aborted_; if (!find_next) current_find_request_id_ = find_request_id_counter_++; if (!find_text.empty()) find_text_ = find_text; + last_search_case_sensitive_ = case_sensitive; find_op_aborted_ = false; // Keep track of what the last search was across the tabs. - *find_prepopulate_text_ = find_text; + *last_search_prepopulate_text_ = find_text; render_view_host()->StartFinding(current_find_request_id_, find_text_, forward_direction, - false, // case sensitive + case_sensitive, find_next); } void TabContents::StopFinding(bool clear_selection) { find_ui_active_ = false; find_op_aborted_ = true; - find_result_ = FindNotificationDetails(); + last_search_result_ = FindNotificationDetails(); render_view_host()->StopFinding(clear_selection); } @@ -2305,23 +2313,23 @@ void TabContents::OnFindReply(int request_id, return; if (number_of_matches == -1) - number_of_matches = find_result_.number_of_matches(); + number_of_matches = last_search_result_.number_of_matches(); if (active_match_ordinal == -1) - active_match_ordinal = find_result_.active_match_ordinal(); + active_match_ordinal = last_search_result_.active_match_ordinal(); gfx::Rect selection = selection_rect; if (selection.IsEmpty()) - selection = find_result_.selection_rect(); + selection = last_search_result_.selection_rect(); // Notify the UI, automation and any other observers that a find result was // found. - find_result_ = FindNotificationDetails(request_id, number_of_matches, - selection, active_match_ordinal, - final_update); + last_search_result_ = FindNotificationDetails(request_id, number_of_matches, + selection, active_match_ordinal, + final_update); NotificationService::current()->Notify( NotificationType::FIND_RESULT_AVAILABLE, Source<TabContents>(this), - Details<FindNotificationDetails>(&find_result_)); + Details<FindNotificationDetails>(&last_search_result_)); } bool TabContents::IsExternalTabContainer() const { diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 9667c70..195225c 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -469,7 +469,9 @@ class TabContents : public PageNavigator, // function does not block while a search is in progress. The controller will // receive the results through the notification mechanism. See Observe(...) // for details. - void StartFinding(const string16& find_text, bool forward_direction); + void StartFinding(string16 find_text, + bool forward_direction, + bool case_sensitive); // Stops the current Find operation. If |clear_selection| is true, it will // also clear the selection on the focused frame. @@ -486,9 +488,8 @@ class TabContents : public PageNavigator, find_op_aborted_ = find_op_aborted; } - // Used _only_ by testing to set the current request ID, since it calls - // StartFinding on the RenderViewHost directly, rather than by using - // StartFinding's more limited API. + // Used _only_ by testing to get or set the current request ID. + int current_find_request_id() { return current_find_request_id_; } void set_current_find_request_id(int current_find_request_id) { current_find_request_id_ = current_find_request_id; } @@ -497,12 +498,16 @@ class TabContents : public PageNavigator, // active searches. string16 find_text() const { return find_text_; } - // Accessor for find_prepopulate_text_. Used to access the last search + // Accessor for last_search_prepopulate_text_. Used to access the last search // string entered, whatever tab that search was performed in. - string16 find_prepopulate_text() const { return *find_prepopulate_text_; } + string16 find_prepopulate_text() const { + return *last_search_prepopulate_text_; + } // Accessor for find_result_. - const FindNotificationDetails& find_result() const { return find_result_; } + const FindNotificationDetails& find_result() const { + return last_search_result_; + } // Misc state & callbacks ---------------------------------------------------- @@ -1030,13 +1035,16 @@ class TabContents : public PageNavigator, // Find or a FindNext operation (FindNext should not increase the request id). string16 find_text_; + // Whether the last search was case sensitive or not. + bool last_search_case_sensitive_; + // Keeps track of the last search string that was used to search in any tab. - string16* find_prepopulate_text_; + string16* last_search_prepopulate_text_; // The last find result. This object contains details about the number of // matches, the find selection rectangle, etc. The UI can access this // information to build its presentation. - FindNotificationDetails find_result_; + FindNotificationDetails last_search_result_; // Data for Page Actions ----------------------------------------------------- diff --git a/chrome/browser/views/find_bar_view.cc b/chrome/browser/views/find_bar_view.cc index 2c62a27..c2db6d2 100644 --- a/chrome/browser/views/find_bar_view.cc +++ b/chrome/browser/views/find_bar_view.cc @@ -401,7 +401,8 @@ void FindBarView::ButtonPressed(views::Button* sender) { if (!find_text_->GetText().empty()) { container_->GetFindBarController()->tab_contents()->StartFinding( find_text_->GetText(), - sender->tag() == FIND_NEXT_TAG); + sender->tag() == FIND_NEXT_TAG, + false); // Not case sensitive. } // Move the focus back to the text-field, we don't want the button // focused. @@ -435,7 +436,8 @@ void FindBarView::ContentsChanged(views::TextField* sender, // if the textbox contains something we set it as the new search string and // initiate search (even though old searches might be in progress). if (!new_contents.empty()) { - controller->tab_contents()->StartFinding(new_contents, true); + // 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); @@ -462,7 +464,8 @@ bool FindBarView::HandleKeystroke(views::TextField* sender, // Search forwards for enter, backwards for shift-enter. container_->GetFindBarController()->tab_contents()->StartFinding( find_string, - GetKeyState(VK_SHIFT) >= 0); + GetKeyState(VK_SHIFT) >= 0, + false); // Not case sensitive. } } #endif diff --git a/chrome/browser/views/find_bar_win_browsertest.cc b/chrome/browser/views/find_bar_win_browsertest.cc index 2b173da..9363328 100644 --- a/chrome/browser/views/find_bar_win_browsertest.cc +++ b/chrome/browser/views/find_bar_win_browsertest.cc @@ -30,6 +30,7 @@ class FindInPageNotificationObserver : public NotificationObserver { : parent_tab_(parent_tab), active_match_ordinal_(-1), number_of_matches_(0) { + current_find_request_id_ = parent_tab->current_find_request_id(); registrar_.Add(this, NotificationType::FIND_RESULT_AVAILABLE, Source<TabContents>(parent_tab_)); ui_test_utils::RunMessageLoop(); @@ -43,7 +44,7 @@ class FindInPageNotificationObserver : public NotificationObserver { const NotificationDetails& details) { if (type == NotificationType::FIND_RESULT_AVAILABLE) { Details<FindNotificationDetails> find_details(details); - if (find_details->request_id() == kFindInPageRequestId) { + if (find_details->request_id() == current_find_request_id_) { // We get multiple responses and one of those will contain the ordinal. // This message comes to us before the final update is sent. if (find_details->active_match_ordinal() > -1) @@ -60,15 +61,6 @@ class FindInPageNotificationObserver : public NotificationObserver { } } - // The Find mechanism is over asynchronous IPC, so a search is kicked off and - // we wait for notification to find out what the results are. As the user is - // typing, new search requests can be issued and the Request ID helps us make - // sense of whether this is the current request or an old one. The unit tests, - // however, which uses this constant issues only one search at a time, so we - // don't need a rolling id to identify each search. But, we still need to - // specify one, so we just use a fixed one - its value does not matter. - static const int kFindInPageRequestId; - private: NotificationRegistrar registrar_; TabContents* parent_tab_; @@ -76,6 +68,9 @@ class FindInPageNotificationObserver : public NotificationObserver { // we need to preserve it so we can send it later. int active_match_ordinal_; int number_of_matches_; + // The id of the current find request, obtained from TabContents. Allows us + // to monitor when the search completes. + int current_find_request_id_; }; typedef enum FindInPageDirection { BACK = 0, FWD = 1 }; @@ -91,15 +86,11 @@ class FindInPageControllerTest : public InProcessBrowserTest { int FindInPage(const std::wstring& search_string, FindInPageDirection forward, FindInPageCase match_case, - bool find_next, int* ordinal) { TabContents* tab_contents = browser()->GetSelectedTabContents(); - tab_contents->set_current_find_request_id( - FindInPageNotificationObserver::kFindInPageRequestId); - tab_contents->render_view_host()->StartFinding( - FindInPageNotificationObserver::kFindInPageRequestId, - search_string, forward == FWD, match_case == CASE_SENSITIVE, - find_next); + tab_contents->StartFinding(search_string, forward == FWD, + match_case == CASE_SENSITIVE); + FindInPageNotificationObserver observer = FindInPageNotificationObserver(tab_contents); if (ordinal) @@ -124,59 +115,55 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { // Try incremental search (mimicking user typing in). int ordinal = 0; - EXPECT_EQ(18, FindInPage(L"g", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(18, FindInPage(L"g", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(11, FindInPage(L"go", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(11, FindInPage(L"go", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(04, FindInPage(L"goo", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(04, FindInPage(L"goo", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(03, FindInPage(L"goog", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(03, FindInPage(L"goog", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(02, FindInPage(L"googl", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(02, FindInPage(L"googl", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(01, FindInPage(L"google", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(01, FindInPage(L"google", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(00, FindInPage(L"google!", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(00, FindInPage(L"google!", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(0, ordinal); // Negative test (no matches should be found). - EXPECT_EQ(0, FindInPage(L"Non-existing string", FWD, IGNORE_CASE, - false, &ordinal)); + EXPECT_EQ(0, FindInPage(L"Non-existing string", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(0, ordinal); // 'horse' only exists in the three right frames. - EXPECT_EQ(3, FindInPage(L"horse", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(3, FindInPage(L"horse", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // 'cat' only exists in the first frame. - EXPECT_EQ(1, FindInPage(L"cat", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"cat", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // Try searching again, should still come up with 1 match. - EXPECT_EQ(1, FindInPage(L"cat", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"cat", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // Try searching backwards, ignoring case, should still come up with 1 match. - EXPECT_EQ(1, FindInPage(L"CAT", BACK, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"CAT", BACK, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // Try case sensitive, should NOT find it. - EXPECT_EQ(0, FindInPage(L"CAT", FWD, CASE_SENSITIVE, false, &ordinal)); + EXPECT_EQ(0, FindInPage(L"CAT", FWD, CASE_SENSITIVE, &ordinal)); EXPECT_EQ(0, ordinal); // Try again case sensitive, but this time with right case. - EXPECT_EQ(1, FindInPage(L"dog", FWD, CASE_SENSITIVE, false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"dog", FWD, CASE_SENSITIVE, &ordinal)); EXPECT_EQ(1, ordinal); // Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame). - EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, IGNORE_CASE, - false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, CASE_SENSITIVE, - false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, CASE_SENSITIVE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(0, FindInPage(L"hreggvi\u00F0ur", FWD, CASE_SENSITIVE, - false, &ordinal)); + EXPECT_EQ(0, FindInPage(L"hreggvi\u00F0ur", FWD, CASE_SENSITIVE, &ordinal)); EXPECT_EQ(0, ordinal); } @@ -208,7 +195,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { // Search for a text that exists within a link on the page. int ordinal = 0; - EXPECT_EQ(1, FindInPage(L"nk", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"nk", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // End the find session, which should set focus to the link. @@ -218,7 +205,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { EXPECT_STREQ("link1", FocusedOnPage(tab_contents).c_str()); // Search for a text that exists within a link on the page. - EXPECT_EQ(1, FindInPage(L"Google", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"Google", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // Move the selection to link 1, after searching. @@ -248,22 +235,22 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { // Search for 'o', which should make the first item active and return // '1 in 3' (1st ordinal of a total of 3 matches). int ordinal = 0; - EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(2, ordinal); - EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(3, ordinal); // Go back one match. - EXPECT_EQ(3, FindInPage(L"o", BACK, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, FindInPage(L"o", BACK, IGNORE_CASE, &ordinal)); EXPECT_EQ(2, ordinal); - EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(3, ordinal); // This should wrap to the top. - EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // This should go back to the end. - EXPECT_EQ(3, FindInPage(L"o", BACK, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, FindInPage(L"o", BACK, IGNORE_CASE, &ordinal)); EXPECT_EQ(3, ordinal); } @@ -279,30 +266,30 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { // Search for 'a', which should make the first item active and return // '1 in 7' (1st ordinal of a total of 7 matches). int ordinal = 0; - EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(2, ordinal); - EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(3, ordinal); - EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(4, ordinal); // Go back one, which should go back one frame. - EXPECT_EQ(7, FindInPage(L"a", BACK, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", BACK, IGNORE_CASE, &ordinal)); EXPECT_EQ(3, ordinal); - EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(4, ordinal); - EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(5, ordinal); - EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(6, ordinal); - EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(7, ordinal); // Now we should wrap back to frame 1. - EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // Now we should wrap back to frame last frame. - EXPECT_EQ(7, FindInPage(L"a", BACK, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, FindInPage(L"a", BACK, IGNORE_CASE, &ordinal)); EXPECT_EQ(7, ordinal); } @@ -317,17 +304,17 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { // Search for 'goa' three times (6 matches on page). int ordinal = 0; - EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(2, ordinal); - EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(3, ordinal); // Add space to search (should result in no matches). - EXPECT_EQ(0, FindInPage(L"goa ", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(0, FindInPage(L"goa ", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(0, ordinal); // Remove the space, should be back to '3 out of 6') - EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(3, ordinal); } @@ -340,10 +327,9 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnSelectableText) { ui_test_utils::NavigateToURL(browser(), url); int ordinal = 0; - EXPECT_EQ(0, FindInPage(L"text", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(0, FindInPage(L"text", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(-1, ordinal); // Nothing is selected. - EXPECT_EQ(0, FindInPage(L"Non-existing string", FWD, IGNORE_CASE, - false, &ordinal)); + EXPECT_EQ(0, FindInPage(L"Non-existing string", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(0, ordinal); } @@ -359,15 +345,15 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { // against the frame, otherwise an active frame pointer is set and it wont // produce the crash. int ordinal = 0; - EXPECT_EQ(1, FindInPage(L"\u0D4C", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"\u0D4C", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(1, FindInPage(L"\u0D4C", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(1, FindInPage(L"\u0D4C", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // This should work fine. - EXPECT_EQ(1, FindInPage(L"\u0D24\u0D46", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"\u0D24\u0D46", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); - EXPECT_EQ(0, FindInPage(L"nostring", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(0, FindInPage(L"nostring", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(0, ordinal); } @@ -389,7 +375,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { // 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, FindInPage(L"008.xml", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(5, FindInPage(L"008.xml", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); } @@ -408,7 +394,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, // Search for a text that exists within a link on the page. int ordinal = 0; - EXPECT_EQ(2, FindInPage(L"html ", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(2, FindInPage(L"html ", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); } @@ -509,7 +495,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) { // Search for 'dream' which the Find box is obscuring. int ordinal = 0; - EXPECT_EQ(1, FindInPage(L"dream", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"dream", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // Make sure Find box has moved. @@ -519,7 +505,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) { EXPECT_TRUE(fully_visible); // Search for 'Too much' which the Find box is not obscuring. - EXPECT_EQ(1, FindInPage(L"Too much", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, FindInPage(L"Too much", FWD, IGNORE_CASE, &ordinal)); EXPECT_EQ(1, ordinal); // Make sure Find box has moved back to its original location. @@ -527,3 +513,36 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) { EXPECT_EQ(start_position, position); EXPECT_TRUE(fully_visible); } + +// 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 our special focus tracking page. + GURL url = server->TestServerPageW(kSimplePage); + ui_test_utils::NavigateToURL(browser(), url); + + // Search for 'no_match'. No matches should be found. + int ordinal = 0; + EXPECT_EQ(0, FindInPage(L"no_match", FWD, IGNORE_CASE, &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, FindInPage(std::wstring(), FWD, IGNORE_CASE, &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, FindInPage(std::wstring(), FWD, IGNORE_CASE, &ordinal)); + EXPECT_EQ(0, ordinal); +} |