OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/keyboard_codes.h" | 5 #include "base/keyboard_codes.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
9 #include "chrome/browser/find_bar_controller.h" | 9 #include "chrome/browser/find_bar_controller.h" |
10 #include "chrome/browser/find_notification_details.h" | 10 #include "chrome/browser/find_notification_details.h" |
11 #include "chrome/browser/renderer_host/render_view_host.h" | 11 #include "chrome/browser/renderer_host/render_view_host.h" |
12 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
13 #include "chrome/browser/tab_contents/tab_contents_view.h" | 13 #include "chrome/browser/tab_contents/tab_contents_view.h" |
14 #include "chrome/browser/views/find_bar_host.h" | 14 #include "chrome/browser/views/find_bar_host.h" |
15 #include "chrome/common/notification_service.h" | 15 #include "chrome/common/notification_service.h" |
16 #include "chrome/test/in_process_browser_test.h" | 16 #include "chrome/test/in_process_browser_test.h" |
17 #include "chrome/test/ui_test_utils.h" | 17 #include "chrome/test/ui_test_utils.h" |
| 18 |
| 19 #if defined(TOOLKIT_VIEWS) |
18 #include "views/focus/focus_manager.h" | 20 #include "views/focus/focus_manager.h" |
| 21 #endif |
| 22 |
| 23 // http://crbug.com/37809 |
| 24 #if defined(OS_LINUX) && defined(TOOLKIT_GTK) |
| 25 #define FindDisappearOnNavigate DISABLED_FindDisappearOnNavigate |
| 26 #define FindDisappearOnNewTabAndHistory \ |
| 27 DISABLED_FindDisappearOnNewTabAndHistory |
| 28 #define FindMovesWhenObscuring DISABLED_FindMovesWhenObscuring |
| 29 #endif |
19 | 30 |
20 const std::wstring kSimplePage = L"404_is_enough_for_us.html"; | 31 const std::wstring kSimplePage = L"404_is_enough_for_us.html"; |
21 const std::wstring kFramePage = L"files/find_in_page/frames.html"; | 32 const std::wstring kFramePage = L"files/find_in_page/frames.html"; |
22 const std::wstring kFrameData = L"files/find_in_page/framedata_general.html"; | 33 const std::wstring kFrameData = L"files/find_in_page/framedata_general.html"; |
23 const std::wstring kUserSelectPage = L"files/find_in_page/user-select.html"; | 34 const std::wstring kUserSelectPage = L"files/find_in_page/user-select.html"; |
24 const std::wstring kCrashPage = L"files/find_in_page/crash_1341577.html"; | 35 const std::wstring kCrashPage = L"files/find_in_page/crash_1341577.html"; |
25 const std::wstring kTooFewMatchesPage = L"files/find_in_page/bug_1155639.html"; | 36 const std::wstring kTooFewMatchesPage = L"files/find_in_page/bug_1155639.html"; |
26 const std::wstring kEndState = L"files/find_in_page/end_state.html"; | 37 const std::wstring kEndState = L"files/find_in_page/end_state.html"; |
27 const std::wstring kPrematureEnd = L"files/find_in_page/premature_end.html"; | 38 const std::wstring kPrematureEnd = L"files/find_in_page/premature_end.html"; |
28 const std::wstring kMoveIfOver = L"files/find_in_page/move_if_obscuring.html"; | 39 const std::wstring kMoveIfOver = L"files/find_in_page/move_if_obscuring.html"; |
29 const std::wstring kBitstackCrash = L"files/find_in_page/crash_14491.html"; | 40 const std::wstring kBitstackCrash = L"files/find_in_page/crash_14491.html"; |
30 const std::wstring kSelectChangesOrdinal = | 41 const std::wstring kSelectChangesOrdinal = |
31 L"files/find_in_page/select_changes_ordinal.html"; | 42 L"files/find_in_page/select_changes_ordinal.html"; |
32 const std::wstring kSimple = L"files/find_in_page/simple.html"; | 43 const std::wstring kSimple = L"files/find_in_page/simple.html"; |
| 44 const std::wstring kLinkPage = L"files/find_in_page/link.html"; |
33 | 45 |
34 const bool kBack = false; | 46 const bool kBack = false; |
35 const bool kFwd = true; | 47 const bool kFwd = true; |
36 | 48 |
37 const bool kIgnoreCase = false; | 49 const bool kIgnoreCase = false; |
38 const bool kCaseSensitive = true; | 50 const bool kCaseSensitive = true; |
39 | 51 |
40 const int kMoveIterations = 30; | 52 const int kMoveIterations = 30; |
41 | 53 |
42 class FindInPageControllerTest : public InProcessBrowserTest { | 54 class FindInPageControllerTest : public InProcessBrowserTest { |
43 public: | 55 public: |
44 FindInPageControllerTest() { | 56 FindInPageControllerTest() { |
45 EnableDOMAutomation(); | 57 EnableDOMAutomation(); |
46 } | 58 } |
47 | 59 |
48 protected: | 60 protected: |
49 bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) { | 61 bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) { |
50 FindBarTesting* find_bar = | 62 FindBarTesting* find_bar = |
51 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); | 63 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); |
52 return find_bar->GetFindBarWindowInfo(position, fully_visible); | 64 return find_bar->GetFindBarWindowInfo(position, fully_visible); |
53 } | 65 } |
54 }; | 66 }; |
55 | 67 |
56 // Platform independent FindInPage that takes |const wchat_t*| | 68 // Platform independent FindInPage that takes |const wchar_t*| |
57 // as an input. | 69 // as an input. |
58 int FindInPageWchar(TabContents* tab, | 70 int FindInPageWchar(TabContents* tab, |
59 const wchar_t* search_str, | 71 const wchar_t* search_str, |
60 bool forward, | 72 bool forward, |
61 bool case_sensitive, | 73 bool case_sensitive, |
62 int* ordinal) { | 74 int* ordinal) { |
63 return ui_test_utils::FindInPage( | 75 return ui_test_utils::FindInPage( |
64 tab, WideToUTF16(std::wstring(search_str)), | 76 tab, WideToUTF16(std::wstring(search_str)), |
65 forward, case_sensitive, ordinal); | 77 forward, case_sensitive, ordinal); |
66 } | 78 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // Verify that nothing has focus. | 183 // Verify that nothing has focus. |
172 ASSERT_STREQ("{nothing focused}", FocusedOnPage(tab_contents).c_str()); | 184 ASSERT_STREQ("{nothing focused}", FocusedOnPage(tab_contents).c_str()); |
173 | 185 |
174 // Search for a text that exists within a link on the page. | 186 // Search for a text that exists within a link on the page. |
175 int ordinal = 0; | 187 int ordinal = 0; |
176 EXPECT_EQ(1, FindInPageWchar(tab_contents, L"nk", | 188 EXPECT_EQ(1, FindInPageWchar(tab_contents, L"nk", |
177 kFwd, kIgnoreCase, &ordinal)); | 189 kFwd, kIgnoreCase, &ordinal)); |
178 EXPECT_EQ(1, ordinal); | 190 EXPECT_EQ(1, ordinal); |
179 | 191 |
180 // End the find session, which should set focus to the link. | 192 // End the find session, which should set focus to the link. |
181 tab_contents->StopFinding(false); | 193 tab_contents->StopFinding(FindBarController::kKeepSelection); |
182 | 194 |
183 // Verify that the link is focused. | 195 // Verify that the link is focused. |
184 EXPECT_STREQ("link1", FocusedOnPage(tab_contents).c_str()); | 196 EXPECT_STREQ("link1", FocusedOnPage(tab_contents).c_str()); |
185 | 197 |
186 // Search for a text that exists within a link on the page. | 198 // Search for a text that exists within a link on the page. |
187 EXPECT_EQ(1, FindInPageWchar(tab_contents, L"Google", | 199 EXPECT_EQ(1, FindInPageWchar(tab_contents, L"Google", |
188 kFwd, kIgnoreCase, &ordinal)); | 200 kFwd, kIgnoreCase, &ordinal)); |
189 EXPECT_EQ(1, ordinal); | 201 EXPECT_EQ(1, ordinal); |
190 | 202 |
191 // Move the selection to link 1, after searching. | 203 // Move the selection to link 1, after searching. |
192 std::string result; | 204 std::string result; |
193 ui_test_utils::ExecuteJavaScriptAndExtractString( | 205 ui_test_utils::ExecuteJavaScriptAndExtractString( |
194 tab_contents->render_view_host(), | 206 tab_contents->render_view_host(), |
195 L"", | 207 L"", |
196 L"window.domAutomationController.send(selectLink1());", | 208 L"window.domAutomationController.send(selectLink1());", |
197 &result); | 209 &result); |
198 | 210 |
199 // End the find session. | 211 // End the find session. |
200 tab_contents->StopFinding(false); | 212 tab_contents->StopFinding(FindBarController::kKeepSelection); |
201 | 213 |
202 // Verify that link2 is not focused. | 214 // Verify that link2 is not focused. |
203 EXPECT_STREQ("", FocusedOnPage(tab_contents).c_str()); | 215 EXPECT_STREQ("", FocusedOnPage(tab_contents).c_str()); |
204 } | 216 } |
205 | 217 |
206 // This test loads a single-frame page and makes sure the ordinal returned makes | 218 // This test loads a single-frame page and makes sure the ordinal returned makes |
207 // sense as we FindNext over all the items. | 219 // sense as we FindNext over all the items. |
208 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { | 220 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { |
209 HTTPTestServer* server = StartHTTPServer(); | 221 HTTPTestServer* server = StartHTTPServer(); |
210 | 222 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 &result); | 283 &result); |
272 | 284 |
273 // Do a find-next after the selection. This should move forward | 285 // Do a find-next after the selection. This should move forward |
274 // from there to the 3rd instance of 'google'. | 286 // from there to the 3rd instance of 'google'. |
275 EXPECT_EQ(4, FindInPageWchar(tab, | 287 EXPECT_EQ(4, FindInPageWchar(tab, |
276 L"google", | 288 L"google", |
277 kFwd, kIgnoreCase, &ordinal)); | 289 kFwd, kIgnoreCase, &ordinal)); |
278 EXPECT_EQ(3, ordinal); | 290 EXPECT_EQ(3, ordinal); |
279 | 291 |
280 // End the find session. | 292 // End the find session. |
281 tab_contents->StopFinding(false); | 293 tab_contents->StopFinding(FindBarController::kKeepSelection); |
282 } | 294 } |
283 | 295 |
284 // This test loads a page with frames and makes sure the ordinal returned makes | 296 // This test loads a page with frames and makes sure the ordinal returned makes |
285 // sense. | 297 // sense. |
286 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { | 298 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { |
287 HTTPTestServer* server = StartHTTPServer(); | 299 HTTPTestServer* server = StartHTTPServer(); |
288 | 300 |
289 // First we navigate to our page. | 301 // First we navigate to our page. |
290 GURL url = server->TestServerPageW(kFramePage); | 302 GURL url = server->TestServerPageW(kFramePage); |
291 ui_test_utils::NavigateToURL(browser(), url); | 303 ui_test_utils::NavigateToURL(browser(), url); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 #define FindDisappearOnNavigate DISABLED_FindDisappearOnNavigate | 491 #define FindDisappearOnNavigate DISABLED_FindDisappearOnNavigate |
480 #endif | 492 #endif |
481 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { | 493 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { |
482 HTTPTestServer* server = StartHTTPServer(); | 494 HTTPTestServer* server = StartHTTPServer(); |
483 | 495 |
484 // First we navigate to our special focus tracking page. | 496 // First we navigate to our special focus tracking page. |
485 GURL url = server->TestServerPageW(kSimplePage); | 497 GURL url = server->TestServerPageW(kSimplePage); |
486 GURL url2 = server->TestServerPageW(kFramePage); | 498 GURL url2 = server->TestServerPageW(kFramePage); |
487 ui_test_utils::NavigateToURL(browser(), url); | 499 ui_test_utils::NavigateToURL(browser(), url); |
488 | 500 |
| 501 #if defined(TOOLKIT_VIEWS) |
489 // Open the Find window with animations disabled. | 502 // Open the Find window with animations disabled. |
490 DropdownBarHost::disable_animations_during_testing_ = true; | 503 DropdownBarHost::disable_animations_during_testing_ = true; |
| 504 #endif |
491 browser()->ShowFindBar(); | 505 browser()->ShowFindBar(); |
492 | 506 |
493 gfx::Point position; | 507 gfx::Point position; |
494 bool fully_visible = false; | 508 bool fully_visible = false; |
495 | 509 |
496 // Make sure it is open. | 510 // Make sure it is open. |
497 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | 511 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
498 EXPECT_TRUE(fully_visible); | 512 EXPECT_TRUE(fully_visible); |
499 | 513 |
500 // Reload the tab and make sure Find window doesn't go away. | 514 // Reload the tab and make sure Find window doesn't go away. |
(...skipping 12 matching lines...) Expand all Loading... |
513 // Make sure Find box disappears when History/Downloads page is opened, and | 527 // Make sure Find box disappears when History/Downloads page is opened, and |
514 // when a New Tab is opened. | 528 // when a New Tab is opened. |
515 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 529 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
516 FindDisappearOnNewTabAndHistory) { | 530 FindDisappearOnNewTabAndHistory) { |
517 HTTPTestServer* server = StartHTTPServer(); | 531 HTTPTestServer* server = StartHTTPServer(); |
518 | 532 |
519 // First we navigate to our special focus tracking page. | 533 // First we navigate to our special focus tracking page. |
520 GURL url = server->TestServerPageW(kSimplePage); | 534 GURL url = server->TestServerPageW(kSimplePage); |
521 ui_test_utils::NavigateToURL(browser(), url); | 535 ui_test_utils::NavigateToURL(browser(), url); |
522 | 536 |
| 537 #if defined(TOOLKIT_VIEWS) |
523 // Open the Find window with animations disabled. | 538 // Open the Find window with animations disabled. |
524 DropdownBarHost::disable_animations_during_testing_ = true; | 539 DropdownBarHost::disable_animations_during_testing_ = true; |
| 540 #endif |
525 browser()->ShowFindBar(); | 541 browser()->ShowFindBar(); |
526 | 542 |
527 gfx::Point position; | 543 gfx::Point position; |
528 bool fully_visible = false; | 544 bool fully_visible = false; |
529 | 545 |
530 // Make sure it is open. | 546 // Make sure it is open. |
531 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | 547 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
532 EXPECT_TRUE(fully_visible); | 548 EXPECT_TRUE(fully_visible); |
533 | 549 |
534 // Open another tab (tab B). | 550 // Open another tab (tab B). |
(...skipping 18 matching lines...) Expand all Loading... |
553 EXPECT_FALSE(fully_visible); | 569 EXPECT_FALSE(fully_visible); |
554 } | 570 } |
555 | 571 |
556 // Make sure Find box moves out of the way if it is obscuring the active match. | 572 // Make sure Find box moves out of the way if it is obscuring the active match. |
557 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) { | 573 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) { |
558 HTTPTestServer* server = StartHTTPServer(); | 574 HTTPTestServer* server = StartHTTPServer(); |
559 | 575 |
560 GURL url = server->TestServerPageW(kMoveIfOver); | 576 GURL url = server->TestServerPageW(kMoveIfOver); |
561 ui_test_utils::NavigateToURL(browser(), url); | 577 ui_test_utils::NavigateToURL(browser(), url); |
562 | 578 |
| 579 #if defined(TOOLKIT_VIEWS) |
563 // Open the Find window with animations disabled. | 580 // Open the Find window with animations disabled. |
564 DropdownBarHost::disable_animations_during_testing_ = true; | 581 DropdownBarHost::disable_animations_during_testing_ = true; |
| 582 #endif |
565 browser()->ShowFindBar(); | 583 browser()->ShowFindBar(); |
566 | 584 |
567 gfx::Point start_position; | 585 gfx::Point start_position; |
568 gfx::Point position; | 586 gfx::Point position; |
569 bool fully_visible = false; | 587 bool fully_visible = false; |
570 | 588 |
571 // Make sure it is open. | 589 // Make sure it is open. |
572 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible)); | 590 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible)); |
573 EXPECT_TRUE(fully_visible); | 591 EXPECT_TRUE(fully_visible); |
574 | 592 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 browser()->NewTab(); | 651 browser()->NewTab(); |
634 ui_test_utils::NavigateToURL(browser(), url); | 652 ui_test_utils::NavigateToURL(browser(), url); |
635 | 653 |
636 // Simulate what happens when you press F3 for FindNext. We should get a | 654 // Simulate what happens when you press F3 for FindNext. We should get a |
637 // response here (a hang means search was aborted). | 655 // response here (a hang means search was aborted). |
638 EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(), | 656 EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(), |
639 kFwd, kIgnoreCase, &ordinal)); | 657 kFwd, kIgnoreCase, &ordinal)); |
640 EXPECT_EQ(0, ordinal); | 658 EXPECT_EQ(0, ordinal); |
641 } | 659 } |
642 | 660 |
| 661 #if defined(TOOLKIT_VIEWS) |
643 // Make sure Find box grabs the Esc accelerator and restores it again. | 662 // Make sure Find box grabs the Esc accelerator and restores it again. |
644 #if defined(OS_LINUX) | 663 #if defined(OS_LINUX) |
645 // TODO(oshima): On Gtk/Linux, a focus out event is asynchronous and | 664 // TODO(oshima): On Gtk/Linux, a focus out event is asynchronous and |
646 // hiding a find bar does not immediately update the target | 665 // hiding a find bar does not immediately update the target |
647 // accelerator. The last condition fails in most cases due to this | 666 // accelerator. The last condition fails in most cases due to this |
648 // behavior. See http://crbug.com/26870. | 667 // behavior. See http://crbug.com/26870. |
649 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 668 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
650 DISABLED_AcceleratorRestoring) { | 669 DISABLED_AcceleratorRestoring) { |
651 #else | 670 #else |
652 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) { | 671 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) { |
(...skipping 21 matching lines...) Expand all Loading... |
674 | 693 |
675 views::FocusManager* focus_manager = | 694 views::FocusManager* focus_manager = |
676 views::FocusManager::GetFocusManagerForNativeView(browser_view); | 695 views::FocusManager::GetFocusManagerForNativeView(browser_view); |
677 | 696 |
678 // See where Escape is registered. | 697 // See where Escape is registered. |
679 views::Accelerator escape(base::VKEY_ESCAPE, false, false, false); | 698 views::Accelerator escape(base::VKEY_ESCAPE, false, false, false); |
680 views::AcceleratorTarget* old_target = | 699 views::AcceleratorTarget* old_target = |
681 focus_manager->GetCurrentTargetForAccelerator(escape); | 700 focus_manager->GetCurrentTargetForAccelerator(escape); |
682 EXPECT_TRUE(old_target != NULL); | 701 EXPECT_TRUE(old_target != NULL); |
683 | 702 |
| 703 #if defined(TOOLKIT_VIEWS) |
684 // Open the Find window with animations disabled. | 704 // Open the Find window with animations disabled. |
685 DropdownBarHost::disable_animations_during_testing_ = true; | 705 DropdownBarHost::disable_animations_during_testing_ = true; |
| 706 #endif |
686 browser()->ShowFindBar(); | 707 browser()->ShowFindBar(); |
687 | 708 |
688 // Our Find bar should be the new target. | 709 // Our Find bar should be the new target. |
689 views::AcceleratorTarget* new_target = | 710 views::AcceleratorTarget* new_target = |
690 focus_manager->GetCurrentTargetForAccelerator(escape); | 711 focus_manager->GetCurrentTargetForAccelerator(escape); |
691 | 712 |
692 EXPECT_TRUE(new_target != NULL); | 713 EXPECT_TRUE(new_target != NULL); |
693 EXPECT_NE(new_target, old_target); | 714 EXPECT_NE(new_target, old_target); |
694 | 715 |
695 // Close the Find box. | 716 // Close the Find box. |
696 browser()->GetFindBarController()->EndFindSession(); | 717 browser()->GetFindBarController()->EndFindSession( |
| 718 FindBarController::kKeepSelection); |
697 | 719 |
698 // The accelerator for Escape should be back to what it was before. | 720 // The accelerator for Escape should be back to what it was before. |
699 EXPECT_EQ(old_target, | 721 EXPECT_EQ(old_target, |
700 focus_manager->GetCurrentTargetForAccelerator(escape)); | 722 focus_manager->GetCurrentTargetForAccelerator(escape)); |
701 } | 723 } |
| 724 #endif // TOOLKIT_VIEWS |
702 | 725 |
703 // Make sure Find box does not become UI-inactive when no text is in the box as | 726 // Make sure Find box does not become UI-inactive when no text is in the box as |
704 // we switch to a tab contents with an empty find string. See issue 13570. | 727 // we switch to a tab contents with an empty find string. See issue 13570. |
705 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) { | 728 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) { |
706 HTTPTestServer* server = StartHTTPServer(); | 729 HTTPTestServer* server = StartHTTPServer(); |
707 | 730 |
708 // First we navigate to any page. | 731 // First we navigate to any page. |
709 GURL url = server->TestServerPageW(kSimplePage); | 732 GURL url = server->TestServerPageW(kSimplePage); |
710 ui_test_utils::NavigateToURL(browser(), url); | 733 ui_test_utils::NavigateToURL(browser(), url); |
711 | 734 |
| 735 #if defined(TOOLKIT_VIEWS) |
712 // Open the Find window with animations disabled. | 736 // Open the Find window with animations disabled. |
713 DropdownBarHost::disable_animations_during_testing_ = true; | 737 DropdownBarHost::disable_animations_during_testing_ = true; |
| 738 #endif |
714 browser()->ShowFindBar(); | 739 browser()->ShowFindBar(); |
715 | 740 |
716 // Simulate a user clearing the search string. Ideally, we should be | 741 // Simulate a user clearing the search string. Ideally, we should be |
717 // simulating keypresses here for searching for something and pressing | 742 // simulating keypresses here for searching for something and pressing |
718 // backspace, but that's been proven flaky in the past, so we go straight to | 743 // backspace, but that's been proven flaky in the past, so we go straight to |
719 // tab_contents. | 744 // tab_contents. |
720 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 745 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
721 // Stop the (non-existing) find operation, and clear the selection (which | 746 // Stop the (non-existing) find operation, and clear the selection (which |
722 // signals the UI is still active). | 747 // signals the UI is still active). |
723 tab_contents->StopFinding(true); | 748 tab_contents->StopFinding(FindBarController::kClearSelection); |
724 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI | 749 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI |
725 // still responds to browser window resizing. | 750 // still responds to browser window resizing. |
726 ASSERT_TRUE(tab_contents->find_ui_active()); | 751 ASSERT_TRUE(tab_contents->find_ui_active()); |
727 } | 752 } |
728 | 753 |
729 // Make sure F3 works after you FindNext a couple of times and end the Find | 754 // Make sure F3 works after you FindNext a couple of times and end the Find |
730 // session. See issue http://crbug.com/28306. | 755 // session. See issue http://crbug.com/28306. |
731 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { | 756 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { |
732 HTTPTestServer* server = StartHTTPServer(); | 757 HTTPTestServer* server = StartHTTPServer(); |
733 | 758 |
734 // First we navigate to a simple page. | 759 // First we navigate to a simple page. |
735 GURL url = server->TestServerPageW(kSimple); | 760 GURL url = server->TestServerPageW(kSimple); |
736 ui_test_utils::NavigateToURL(browser(), url); | 761 ui_test_utils::NavigateToURL(browser(), url); |
737 | 762 |
738 // Search for 'page'. Should have 1 match. | 763 // Search for 'page'. Should have 1 match. |
739 int ordinal = 0; | 764 int ordinal = 0; |
740 TabContents* tab = browser()->GetSelectedTabContents(); | 765 TabContents* tab = browser()->GetSelectedTabContents(); |
741 EXPECT_EQ(1, FindInPageWchar(tab, L"page", kFwd, kIgnoreCase, &ordinal)); | 766 EXPECT_EQ(1, FindInPageWchar(tab, L"page", kFwd, kIgnoreCase, &ordinal)); |
742 EXPECT_EQ(1, ordinal); | 767 EXPECT_EQ(1, ordinal); |
743 | 768 |
744 // Simulate what happens when you press F3 for FindNext. Still should show | 769 // Simulate what happens when you press F3 for FindNext. Still should show |
745 // one match. This cleared the pre-populate string at one point (see bug). | 770 // one match. This cleared the pre-populate string at one point (see bug). |
746 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, string16(), | 771 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, string16(), |
747 kFwd, kIgnoreCase, &ordinal)); | 772 kFwd, kIgnoreCase, &ordinal)); |
748 EXPECT_EQ(1, ordinal); | 773 EXPECT_EQ(1, ordinal); |
749 | 774 |
750 // End the Find session, thereby making the next F3 start afresh. | 775 // End the Find session, thereby making the next F3 start afresh. |
751 browser()->GetFindBarController()->EndFindSession(); | 776 browser()->GetFindBarController()->EndFindSession( |
| 777 FindBarController::kKeepSelection); |
752 | 778 |
753 // Simulate F3 while Find box is closed. Should have 1 match. | 779 // Simulate F3 while Find box is closed. Should have 1 match. |
754 EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal)); | 780 EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal)); |
755 EXPECT_EQ(1, ordinal); | 781 EXPECT_EQ(1, ordinal); |
756 } | 782 } |
757 | 783 |
758 // When re-opening the find bar with F3, the find bar should be re-populated | 784 // When re-opening the find bar with F3, the find bar should be re-populated |
759 // with the last search from the same tab rather than the last overall search. | 785 // with the last search from the same tab rather than the last overall search. |
760 // http://crbug.com/30006 | 786 // http://crbug.com/30006 |
761 #if defined(OS_CHROMEOS) | 787 #if defined(OS_CHROMEOS) |
762 #define PreferPreviousSearch FLAKY_PreferPreviousSearch | 788 #define PreferPreviousSearch FLAKY_PreferPreviousSearch |
763 #endif | 789 #endif |
764 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { | 790 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { |
765 HTTPTestServer* server = StartHTTPServer(); | 791 HTTPTestServer* server = StartHTTPServer(); |
766 | 792 |
| 793 #if defined(TOOLKIT_VIEWS) |
767 DropdownBarHost::disable_animations_during_testing_ = true; | 794 DropdownBarHost::disable_animations_during_testing_ = true; |
| 795 #endif |
768 | 796 |
769 // First we navigate to any page. | 797 // First we navigate to any page. |
770 GURL url = server->TestServerPageW(kSimplePage); | 798 GURL url = server->TestServerPageW(kSimplePage); |
771 ui_test_utils::NavigateToURL(browser(), url); | 799 ui_test_utils::NavigateToURL(browser(), url); |
772 | 800 |
773 // Find "Default". | 801 // Find "Default". |
774 int ordinal = 0; | 802 int ordinal = 0; |
775 TabContents* tab1 = browser()->GetSelectedTabContents(); | 803 TabContents* tab1 = browser()->GetSelectedTabContents(); |
776 EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal)); | 804 EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal)); |
777 | 805 |
778 // Create a second tab. | 806 // Create a second tab. |
779 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1, | 807 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1, |
780 false, NULL); | 808 false, NULL); |
781 browser()->SelectTabContentsAt(1, false); | 809 browser()->SelectTabContentsAt(1, false); |
782 TabContents* tab2 = browser()->GetSelectedTabContents(); | 810 TabContents* tab2 = browser()->GetSelectedTabContents(); |
783 EXPECT_NE(tab1, tab2); | 811 EXPECT_NE(tab1, tab2); |
784 | 812 |
785 // Find "given". | 813 // Find "given". |
786 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); | 814 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); |
787 | 815 |
788 // Switch back to first tab. | 816 // Switch back to first tab. |
789 browser()->SelectTabContentsAt(0, false); | 817 browser()->SelectTabContentsAt(0, false); |
790 browser()->GetFindBarController()->EndFindSession(); | 818 browser()->GetFindBarController()->EndFindSession( |
| 819 FindBarController::kKeepSelection); |
791 // Simulate F3. | 820 // Simulate F3. |
792 ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal); | 821 ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal); |
793 EXPECT_EQ(tab1->find_text(), WideToUTF16(L"Default")); | 822 EXPECT_EQ(tab1->find_text(), WideToUTF16(L"Default")); |
794 } | 823 } |
| 824 |
| 825 // This makes sure that dismissing the find bar with kActivateSelection works. |
| 826 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) { |
| 827 HTTPTestServer* server = StartHTTPServer(); |
| 828 |
| 829 #if defined(TOOLKIT_VIEWS) |
| 830 DropdownBarHost::disable_animations_during_testing_ = true; |
| 831 #endif |
| 832 |
| 833 // First we navigate to our test content. |
| 834 GURL url = server->TestServerPageW(kLinkPage); |
| 835 ui_test_utils::NavigateToURL(browser(), url); |
| 836 |
| 837 TabContents* tab = browser()->GetSelectedTabContents(); |
| 838 int ordinal = 0; |
| 839 FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal); |
| 840 EXPECT_EQ(ordinal, 1); |
| 841 |
| 842 // End the find session, click on the link. |
| 843 tab->StopFinding(FindBarController::kActivateSelection); |
| 844 EXPECT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
| 845 } |
OLD | NEW |