| 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/common/cancelable_request.h" | 10 #include "chrome/browser/common/cancelable_request.h" |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 false, false, NULL)); | 464 false, false, NULL)); |
| 465 } | 465 } |
| 466 | 466 |
| 467 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. | 467 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. |
| 468 bool FocusedOnPage(WebContents* web_contents, std::string* result) | 468 bool FocusedOnPage(WebContents* web_contents, std::string* result) |
| 469 WARN_UNUSED_RESULT; | 469 WARN_UNUSED_RESULT; |
| 470 | 470 |
| 471 bool FocusedOnPage(WebContents* web_contents, std::string* result) { | 471 bool FocusedOnPage(WebContents* web_contents, std::string* result) { |
| 472 return content::ExecuteJavaScriptAndExtractString( | 472 return content::ExecuteJavaScriptAndExtractString( |
| 473 web_contents->GetRenderViewHost(), | 473 web_contents->GetRenderViewHost(), |
| 474 "", | 474 L"", |
| 475 "window.domAutomationController.send(getFocusedElement());", | 475 L"window.domAutomationController.send(getFocusedElement());", |
| 476 result); | 476 result); |
| 477 } | 477 } |
| 478 | 478 |
| 479 // This tests the FindInPage end-state, in other words: what is focused when you | 479 // This tests the FindInPage end-state, in other words: what is focused when you |
| 480 // close the Find box (ie. if you find within a link the link should be | 480 // close the Find box (ie. if you find within a link the link should be |
| 481 // focused). | 481 // focused). |
| 482 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { | 482 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { |
| 483 // First we navigate to our special focus tracking page. | 483 // First we navigate to our special focus tracking page. |
| 484 GURL url = GetURL(kEndState); | 484 GURL url = GetURL(kEndState); |
| 485 ui_test_utils::NavigateToURL(browser(), url); | 485 ui_test_utils::NavigateToURL(browser(), url); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 509 EXPECT_STREQ("link1", result.c_str()); | 509 EXPECT_STREQ("link1", result.c_str()); |
| 510 | 510 |
| 511 // Search for a text that exists within a link on the page. | 511 // Search for a text that exists within a link on the page. |
| 512 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Google", | 512 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Google", |
| 513 kFwd, kIgnoreCase, &ordinal)); | 513 kFwd, kIgnoreCase, &ordinal)); |
| 514 EXPECT_EQ(1, ordinal); | 514 EXPECT_EQ(1, ordinal); |
| 515 | 515 |
| 516 // Move the selection to link 1, after searching. | 516 // Move the selection to link 1, after searching. |
| 517 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 517 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 518 web_contents->GetRenderViewHost(), | 518 web_contents->GetRenderViewHost(), |
| 519 "", | 519 L"", |
| 520 "window.domAutomationController.send(selectLink1());", | 520 L"window.domAutomationController.send(selectLink1());", |
| 521 &result)); | 521 &result)); |
| 522 | 522 |
| 523 // End the find session. | 523 // End the find session. |
| 524 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage); | 524 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage); |
| 525 | 525 |
| 526 // Verify that link2 is not focused. | 526 // Verify that link2 is not focused. |
| 527 ASSERT_TRUE(FocusedOnPage(web_contents, &result)); | 527 ASSERT_TRUE(FocusedOnPage(web_contents, &result)); |
| 528 EXPECT_STREQ("", result.c_str()); | 528 EXPECT_STREQ("", result.c_str()); |
| 529 } | 529 } |
| 530 | 530 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 int ordinal = 0; | 583 int ordinal = 0; |
| 584 EXPECT_EQ(4, FindInPageWchar(web_contents, | 584 EXPECT_EQ(4, FindInPageWchar(web_contents, |
| 585 L"google", | 585 L"google", |
| 586 kFwd, kIgnoreCase, &ordinal)); | 586 kFwd, kIgnoreCase, &ordinal)); |
| 587 EXPECT_EQ(1, ordinal); | 587 EXPECT_EQ(1, ordinal); |
| 588 | 588 |
| 589 // Move the selection to link 1, after searching. | 589 // Move the selection to link 1, after searching. |
| 590 std::string result; | 590 std::string result; |
| 591 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 591 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 592 web_contents->GetRenderViewHost(), | 592 web_contents->GetRenderViewHost(), |
| 593 "", | 593 L"", |
| 594 "window.domAutomationController.send(selectLink1());", | 594 L"window.domAutomationController.send(selectLink1());", |
| 595 &result)); | 595 &result)); |
| 596 | 596 |
| 597 // Do a find-next after the selection. This should move forward | 597 // Do a find-next after the selection. This should move forward |
| 598 // from there to the 3rd instance of 'google'. | 598 // from there to the 3rd instance of 'google'. |
| 599 EXPECT_EQ(4, FindInPageWchar(web_contents, | 599 EXPECT_EQ(4, FindInPageWchar(web_contents, |
| 600 L"google", | 600 L"google", |
| 601 kFwd, kIgnoreCase, &ordinal)); | 601 kFwd, kIgnoreCase, &ordinal)); |
| 602 EXPECT_EQ(3, ordinal); | 602 EXPECT_EQ(3, ordinal); |
| 603 | 603 |
| 604 // End the find session. | 604 // End the find session. |
| 605 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage); | 605 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage); |
| 606 } | 606 } |
| 607 | 607 |
| 608 // This tests that we start searching after selected text. | 608 // This tests that we start searching after selected text. |
| 609 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 609 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
| 610 StartSearchAfterSelection) { | 610 StartSearchAfterSelection) { |
| 611 // First we navigate to our test content. | 611 // First we navigate to our test content. |
| 612 ui_test_utils::NavigateToURL(browser(), GetURL(kStartAfterSelection)); | 612 ui_test_utils::NavigateToURL(browser(), GetURL(kStartAfterSelection)); |
| 613 | 613 |
| 614 WebContents* web_contents = | 614 WebContents* web_contents = |
| 615 browser()->tab_strip_model()->GetActiveWebContents(); | 615 browser()->tab_strip_model()->GetActiveWebContents(); |
| 616 ASSERT_TRUE(web_contents != NULL); | 616 ASSERT_TRUE(web_contents != NULL); |
| 617 int ordinal = 0; | 617 int ordinal = 0; |
| 618 | 618 |
| 619 // Move the selection to the text span. | 619 // Move the selection to the text span. |
| 620 std::string result; | 620 std::string result; |
| 621 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 621 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 622 web_contents->GetRenderViewHost(), | 622 web_contents->GetRenderViewHost(), |
| 623 "", | 623 std::wstring(), |
| 624 "window.domAutomationController.send(selectSpan());", | 624 L"window.domAutomationController.send(selectSpan());", |
| 625 &result)); | 625 &result)); |
| 626 | 626 |
| 627 // Do a find-next after the selection. This should select the 2nd occurrence | 627 // Do a find-next after the selection. This should select the 2nd occurrence |
| 628 // of the word 'find'. | 628 // of the word 'find'. |
| 629 EXPECT_EQ(4, FindInPageWchar(web_contents, | 629 EXPECT_EQ(4, FindInPageWchar(web_contents, |
| 630 L"fi", | 630 L"fi", |
| 631 kFwd, kIgnoreCase, &ordinal)); | 631 kFwd, kIgnoreCase, &ordinal)); |
| 632 EXPECT_EQ(2, ordinal); | 632 EXPECT_EQ(2, ordinal); |
| 633 | 633 |
| 634 // Refine the search, current active match should not change. | 634 // Refine the search, current active match should not change. |
| (...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 content::RunAllPendingInMessageLoop(); // Needed on Linux. | 1498 content::RunAllPendingInMessageLoop(); // Needed on Linux. |
| 1499 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); | 1499 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); |
| 1500 | 1500 |
| 1501 ui_test_utils::NavigateToURLWithDisposition( | 1501 ui_test_utils::NavigateToURLWithDisposition( |
| 1502 browser(), url, NEW_FOREGROUND_TAB, | 1502 browser(), url, NEW_FOREGROUND_TAB, |
| 1503 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1503 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1504 chrome::CloseTab(browser()); | 1504 chrome::CloseTab(browser()); |
| 1505 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); | 1505 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); |
| 1506 EXPECT_EQ(position, position2); | 1506 EXPECT_EQ(position, position2); |
| 1507 } | 1507 } |
| OLD | NEW |