OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/string16.h" | 7 #include "base/string16.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/cancelable_request.h" | 10 #include "chrome/browser/cancelable_request.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 const std::string kFrameData = "framedata_general.html"; | 56 const std::string kFrameData = "framedata_general.html"; |
57 const std::string kUserSelectPage = "user-select.html"; | 57 const std::string kUserSelectPage = "user-select.html"; |
58 const std::string kCrashPage = "crash_1341577.html"; | 58 const std::string kCrashPage = "crash_1341577.html"; |
59 const std::string kTooFewMatchesPage = "bug_1155639.html"; | 59 const std::string kTooFewMatchesPage = "bug_1155639.html"; |
60 const std::string kLongTextareaPage = "large_textarea.html"; | 60 const std::string kLongTextareaPage = "large_textarea.html"; |
61 const std::string kEndState = "end_state.html"; | 61 const std::string kEndState = "end_state.html"; |
62 const std::string kPrematureEnd = "premature_end.html"; | 62 const std::string kPrematureEnd = "premature_end.html"; |
63 const std::string kMoveIfOver = "move_if_obscuring.html"; | 63 const std::string kMoveIfOver = "move_if_obscuring.html"; |
64 const std::string kBitstackCrash = "crash_14491.html"; | 64 const std::string kBitstackCrash = "crash_14491.html"; |
65 const std::string kSelectChangesOrdinal = "select_changes_ordinal.html"; | 65 const std::string kSelectChangesOrdinal = "select_changes_ordinal.html"; |
| 66 const std::string kStartAfterSelection = "start_after_selection.html"; |
66 const std::string kSimple = "simple.html"; | 67 const std::string kSimple = "simple.html"; |
67 const std::string kLinkPage = "link.html"; | 68 const std::string kLinkPage = "link.html"; |
68 | 69 |
69 const bool kBack = false; | 70 const bool kBack = false; |
70 const bool kFwd = true; | 71 const bool kFwd = true; |
71 | 72 |
72 const bool kIgnoreCase = false; | 73 const bool kIgnoreCase = false; |
73 const bool kCaseSensitive = true; | 74 const bool kCaseSensitive = true; |
74 | 75 |
75 const int kMoveIterations = 30; | 76 const int kMoveIterations = 30; |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 // from there to the 3rd instance of 'google'. | 589 // from there to the 3rd instance of 'google'. |
589 EXPECT_EQ(4, FindInPageWchar(tab, | 590 EXPECT_EQ(4, FindInPageWchar(tab, |
590 L"google", | 591 L"google", |
591 kFwd, kIgnoreCase, &ordinal)); | 592 kFwd, kIgnoreCase, &ordinal)); |
592 EXPECT_EQ(3, ordinal); | 593 EXPECT_EQ(3, ordinal); |
593 | 594 |
594 // End the find session. | 595 // End the find session. |
595 tab->find_tab_helper()->StopFinding(FindBarController::kKeepSelectionOnPage); | 596 tab->find_tab_helper()->StopFinding(FindBarController::kKeepSelectionOnPage); |
596 } | 597 } |
597 | 598 |
| 599 // This tests that we start searching after selected text. |
| 600 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
| 601 StartSearchAfterSelection) { |
| 602 // First we navigate to our test content. |
| 603 ui_test_utils::NavigateToURL(browser(), GetURL(kStartAfterSelection)); |
| 604 |
| 605 TabContents* tab = chrome::GetActiveTabContents(browser()); |
| 606 ASSERT_TRUE(tab != NULL); |
| 607 int ordinal = 0; |
| 608 |
| 609 // Move the selection to the text span. |
| 610 std::string result; |
| 611 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 612 tab->web_contents()->GetRenderViewHost(), |
| 613 std::wstring(), |
| 614 L"window.domAutomationController.send(selectSpan());", |
| 615 &result)); |
| 616 |
| 617 // Do a find-next after the selection. This should select the 2nd occurrence |
| 618 // of the word 'find'. |
| 619 EXPECT_EQ(4, FindInPageWchar(tab, L"fi", kFwd, kIgnoreCase, &ordinal)); |
| 620 EXPECT_EQ(2, ordinal); |
| 621 |
| 622 // Refine the search, current active match should not change. |
| 623 EXPECT_EQ(4, FindInPageWchar(tab, L"find", kFwd, kIgnoreCase, &ordinal)); |
| 624 EXPECT_EQ(2, ordinal); |
| 625 |
| 626 // Refine the search to 'findMe'. The first new match is before the current |
| 627 // active match, the second one is after it. This verifies that refining a |
| 628 // search doesn't reset it. |
| 629 EXPECT_EQ(2, FindInPageWchar(tab, L"findMe", kFwd, kIgnoreCase, &ordinal)); |
| 630 EXPECT_EQ(2, ordinal); |
| 631 } |
| 632 |
598 // This test loads a page with frames and makes sure the ordinal returned makes | 633 // This test loads a page with frames and makes sure the ordinal returned makes |
599 // sense. | 634 // sense. |
600 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { | 635 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { |
601 // First we navigate to our page. | 636 // First we navigate to our page. |
602 GURL url = GetURL(kFramePage); | 637 GURL url = GetURL(kFramePage); |
603 ui_test_utils::NavigateToURL(browser(), url); | 638 ui_test_utils::NavigateToURL(browser(), url); |
604 | 639 |
605 // Search for 'a', which should make the first item active and return | 640 // Search for 'a', which should make the first item active and return |
606 // '1 in 7' (1st ordinal of a total of 7 matches). | 641 // '1 in 7' (1st ordinal of a total of 7 matches). |
607 TabContents* tab = chrome::GetActiveTabContents(browser()); | 642 TabContents* tab = chrome::GetActiveTabContents(browser()); |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 content::RunAllPendingInMessageLoop(); // Needed on Linux. | 1494 content::RunAllPendingInMessageLoop(); // Needed on Linux. |
1460 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); | 1495 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); |
1461 | 1496 |
1462 ui_test_utils::NavigateToURLWithDisposition( | 1497 ui_test_utils::NavigateToURLWithDisposition( |
1463 browser(), url, NEW_FOREGROUND_TAB, | 1498 browser(), url, NEW_FOREGROUND_TAB, |
1464 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1499 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1465 chrome::CloseTab(browser()); | 1500 chrome::CloseTab(browser()); |
1466 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); | 1501 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); |
1467 EXPECT_EQ(position, position2); | 1502 EXPECT_EQ(position, position2); |
1468 } | 1503 } |
OLD | NEW |