Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: chrome/browser/ui/find_bar/find_bar_host_browsertest.cc

Issue 11753009: Simplify ExecuteJavaScript* functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update prerender_browsertest.cc. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 EXPECT_EQ(1, 462 EXPECT_EQ(1,
463 FindInPageWchar(web_contents, search_string.c_str(), 463 FindInPageWchar(web_contents, search_string.c_str(),
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::ExecuteScriptAndExtractString(
473 web_contents->GetRenderViewHost(), 473 web_contents,
474 "",
475 "window.domAutomationController.send(getFocusedElement());", 474 "window.domAutomationController.send(getFocusedElement());",
476 result); 475 result);
477 } 476 }
478 477
479 // This tests the FindInPage end-state, in other words: what is focused when you 478 // 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 479 // close the Find box (ie. if you find within a link the link should be
481 // focused). 480 // focused).
482 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { 481 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) {
483 // First we navigate to our special focus tracking page. 482 // First we navigate to our special focus tracking page.
484 GURL url = GetURL(kEndState); 483 GURL url = GetURL(kEndState);
(...skipping 22 matching lines...) Expand all
507 // Verify that the link is focused. 506 // Verify that the link is focused.
508 ASSERT_TRUE(FocusedOnPage(web_contents, &result)); 507 ASSERT_TRUE(FocusedOnPage(web_contents, &result));
509 EXPECT_STREQ("link1", result.c_str()); 508 EXPECT_STREQ("link1", result.c_str());
510 509
511 // Search for a text that exists within a link on the page. 510 // Search for a text that exists within a link on the page.
512 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Google", 511 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Google",
513 kFwd, kIgnoreCase, &ordinal)); 512 kFwd, kIgnoreCase, &ordinal));
514 EXPECT_EQ(1, ordinal); 513 EXPECT_EQ(1, ordinal);
515 514
516 // Move the selection to link 1, after searching. 515 // Move the selection to link 1, after searching.
517 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( 516 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
518 web_contents->GetRenderViewHost(), 517 web_contents,
519 "",
520 "window.domAutomationController.send(selectLink1());", 518 "window.domAutomationController.send(selectLink1());",
521 &result)); 519 &result));
522 520
523 // End the find session. 521 // End the find session.
524 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage); 522 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage);
525 523
526 // Verify that link2 is not focused. 524 // Verify that link2 is not focused.
527 ASSERT_TRUE(FocusedOnPage(web_contents, &result)); 525 ASSERT_TRUE(FocusedOnPage(web_contents, &result));
528 EXPECT_STREQ("", result.c_str()); 526 EXPECT_STREQ("", result.c_str());
529 } 527 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 FindTabHelper::FromWebContents(web_contents); 579 FindTabHelper::FromWebContents(web_contents);
582 580
583 int ordinal = 0; 581 int ordinal = 0;
584 EXPECT_EQ(4, FindInPageWchar(web_contents, 582 EXPECT_EQ(4, FindInPageWchar(web_contents,
585 L"google", 583 L"google",
586 kFwd, kIgnoreCase, &ordinal)); 584 kFwd, kIgnoreCase, &ordinal));
587 EXPECT_EQ(1, ordinal); 585 EXPECT_EQ(1, ordinal);
588 586
589 // Move the selection to link 1, after searching. 587 // Move the selection to link 1, after searching.
590 std::string result; 588 std::string result;
591 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( 589 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
592 web_contents->GetRenderViewHost(), 590 web_contents,
593 "",
594 "window.domAutomationController.send(selectLink1());", 591 "window.domAutomationController.send(selectLink1());",
595 &result)); 592 &result));
596 593
597 // Do a find-next after the selection. This should move forward 594 // Do a find-next after the selection. This should move forward
598 // from there to the 3rd instance of 'google'. 595 // from there to the 3rd instance of 'google'.
599 EXPECT_EQ(4, FindInPageWchar(web_contents, 596 EXPECT_EQ(4, FindInPageWchar(web_contents,
600 L"google", 597 L"google",
601 kFwd, kIgnoreCase, &ordinal)); 598 kFwd, kIgnoreCase, &ordinal));
602 EXPECT_EQ(3, ordinal); 599 EXPECT_EQ(3, ordinal);
603 600
604 // End the find session. 601 // End the find session.
605 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage); 602 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage);
606 } 603 }
607 604
608 // This tests that we start searching after selected text. 605 // This tests that we start searching after selected text.
609 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, 606 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
610 StartSearchAfterSelection) { 607 StartSearchAfterSelection) {
611 // First we navigate to our test content. 608 // First we navigate to our test content.
612 ui_test_utils::NavigateToURL(browser(), GetURL(kStartAfterSelection)); 609 ui_test_utils::NavigateToURL(browser(), GetURL(kStartAfterSelection));
613 610
614 WebContents* web_contents = 611 WebContents* web_contents =
615 browser()->tab_strip_model()->GetActiveWebContents(); 612 browser()->tab_strip_model()->GetActiveWebContents();
616 ASSERT_TRUE(web_contents != NULL); 613 ASSERT_TRUE(web_contents != NULL);
617 int ordinal = 0; 614 int ordinal = 0;
618 615
619 // Move the selection to the text span. 616 // Move the selection to the text span.
620 std::string result; 617 std::string result;
621 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( 618 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
622 web_contents->GetRenderViewHost(), 619 web_contents,
623 "",
624 "window.domAutomationController.send(selectSpan());", 620 "window.domAutomationController.send(selectSpan());",
625 &result)); 621 &result));
626 622
627 // Do a find-next after the selection. This should select the 2nd occurrence 623 // Do a find-next after the selection. This should select the 2nd occurrence
628 // of the word 'find'. 624 // of the word 'find'.
629 EXPECT_EQ(4, FindInPageWchar(web_contents, 625 EXPECT_EQ(4, FindInPageWchar(web_contents,
630 L"fi", 626 L"fi",
631 kFwd, kIgnoreCase, &ordinal)); 627 kFwd, kIgnoreCase, &ordinal));
632 EXPECT_EQ(2, ordinal); 628 EXPECT_EQ(2, ordinal);
633 629
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 content::RunAllPendingInMessageLoop(); // Needed on Linux. 1494 content::RunAllPendingInMessageLoop(); // Needed on Linux.
1499 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); 1495 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL));
1500 1496
1501 ui_test_utils::NavigateToURLWithDisposition( 1497 ui_test_utils::NavigateToURLWithDisposition(
1502 browser(), url, NEW_FOREGROUND_TAB, 1498 browser(), url, NEW_FOREGROUND_TAB,
1503 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1499 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1504 chrome::CloseTab(browser()); 1500 chrome::CloseTab(browser());
1505 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); 1501 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL));
1506 EXPECT_EQ(position, position2); 1502 EXPECT_EQ(position, position2);
1507 } 1503 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_focus_uitest.cc ('k') | chrome/browser/ui/panels/panel_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698