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

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

Issue 10533132: Add a test for FindInPage after selecting text. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: incorporated feedback + rebase Created 8 years, 6 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
« no previous file with comments | « no previous file | chrome/test/data/find_in_page/start_after_selection.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/string16.h" 6 #include "base/string16.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const std::string kFrameData = "framedata_general.html"; 46 const std::string kFrameData = "framedata_general.html";
47 const std::string kUserSelectPage = "user-select.html"; 47 const std::string kUserSelectPage = "user-select.html";
48 const std::string kCrashPage = "crash_1341577.html"; 48 const std::string kCrashPage = "crash_1341577.html";
49 const std::string kTooFewMatchesPage = "bug_1155639.html"; 49 const std::string kTooFewMatchesPage = "bug_1155639.html";
50 const std::string kLongTextareaPage = "large_textarea.html"; 50 const std::string kLongTextareaPage = "large_textarea.html";
51 const std::string kEndState = "end_state.html"; 51 const std::string kEndState = "end_state.html";
52 const std::string kPrematureEnd = "premature_end.html"; 52 const std::string kPrematureEnd = "premature_end.html";
53 const std::string kMoveIfOver = "move_if_obscuring.html"; 53 const std::string kMoveIfOver = "move_if_obscuring.html";
54 const std::string kBitstackCrash = "crash_14491.html"; 54 const std::string kBitstackCrash = "crash_14491.html";
55 const std::string kSelectChangesOrdinal = "select_changes_ordinal.html"; 55 const std::string kSelectChangesOrdinal = "select_changes_ordinal.html";
56 const std::string kStartAfterSelection = "start_after_selection.html";
56 const std::string kSimple = "simple.html"; 57 const std::string kSimple = "simple.html";
57 const std::string kLinkPage = "link.html"; 58 const std::string kLinkPage = "link.html";
58 59
59 const bool kBack = false; 60 const bool kBack = false;
60 const bool kFwd = true; 61 const bool kFwd = true;
61 62
62 const bool kIgnoreCase = false; 63 const bool kIgnoreCase = false;
63 const bool kCaseSensitive = true; 64 const bool kCaseSensitive = true;
64 65
65 const int kMoveIterations = 30; 66 const int kMoveIterations = 30;
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // from there to the 3rd instance of 'google'. 381 // from there to the 3rd instance of 'google'.
381 EXPECT_EQ(4, FindInPageWchar(tab, 382 EXPECT_EQ(4, FindInPageWchar(tab,
382 L"google", 383 L"google",
383 kFwd, kIgnoreCase, &ordinal)); 384 kFwd, kIgnoreCase, &ordinal));
384 EXPECT_EQ(3, ordinal); 385 EXPECT_EQ(3, ordinal);
385 386
386 // End the find session. 387 // End the find session.
387 tab->find_tab_helper()->StopFinding(FindBarController::kKeepSelectionOnPage); 388 tab->find_tab_helper()->StopFinding(FindBarController::kKeepSelectionOnPage);
388 } 389 }
389 390
391 // This tests that we start searching after selected text.
392 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
393 StartSearchAfterSelection) {
394 // First we navigate to our test content.
395 GURL url = GetURL(kStartAfterSelection);
Peter Kasting 2012/09/05 21:22:59 Nit: Can inline into next statement
mkosiba (inactive) 2012/09/10 18:45:23 Done.
396 ui_test_utils::NavigateToURL(browser(), url);
397
398 TabContents* tab = browser()->GetActiveTabContents();
399 ASSERT_TRUE(NULL != tab);
Peter Kasting 2012/09/05 21:22:59 Nit: "tab != NULL" (or ASSERT_FALSE(tab == NULL))
mkosiba (inactive) 2012/09/10 18:45:23 Done.
400 int ordinal = 0;
401
402 // Move the selection to the text span.
403 std::string result;
404 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
405 tab->web_contents()->GetRenderViewHost(),
406 L"",
Peter Kasting 2012/09/05 21:22:59 Nit: Use std::wstring()
mkosiba (inactive) 2012/09/10 18:45:23 Done.
407 L"window.domAutomationController.send(selectSpan());",
408 &result));
409
410 // Do a find-next after the selection. This should select the 2nd occurrence
411 // of the word 'find'.
412 EXPECT_EQ(4, FindInPageWchar(tab,
Peter Kasting 2012/09/05 21:22:59 Nit: Feel free to collapse args onto one line (3 p
mkosiba (inactive) 2012/09/10 18:45:23 Done.
413 L"fi",
414 kFwd, kIgnoreCase, &ordinal));
415 EXPECT_EQ(2, ordinal);
416
417 // Refine the search, current active match should not change (bug 129552).
Peter Kasting 2012/09/05 21:22:59 Nit: Don't bother with the bug number.
mkosiba (inactive) 2012/09/10 18:45:23 Done.
418 EXPECT_EQ(4, FindInPageWchar(tab,
419 L"find",
420 kFwd, kIgnoreCase, &ordinal));
421 EXPECT_EQ(2, ordinal);
422
423 // Refine the search to 'findMe'. The first new match is before the current
424 // active match, the second one is after it. This verifies that refining a
425 // search doesn't reset it.
426 EXPECT_EQ(2, FindInPageWchar(tab,
427 L"findMe",
428 kFwd, kIgnoreCase, &ordinal));
429 EXPECT_EQ(2, ordinal);
430 }
431
390 // This test loads a page with frames and makes sure the ordinal returned makes 432 // This test loads a page with frames and makes sure the ordinal returned makes
391 // sense. 433 // sense.
392 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { 434 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) {
393 // First we navigate to our page. 435 // First we navigate to our page.
394 GURL url = GetURL(kFramePage); 436 GURL url = GetURL(kFramePage);
395 ui_test_utils::NavigateToURL(browser(), url); 437 ui_test_utils::NavigateToURL(browser(), url);
396 438
397 // Search for 'a', which should make the first item active and return 439 // Search for 'a', which should make the first item active and return
398 // '1 in 7' (1st ordinal of a total of 7 matches). 440 // '1 in 7' (1st ordinal of a total of 7 matches).
399 TabContents* tab = browser()->GetActiveTabContents(); 441 TabContents* tab = browser()->GetActiveTabContents();
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 ui_test_utils::RunAllPendingInMessageLoop(); // Needed on Linux. 1286 ui_test_utils::RunAllPendingInMessageLoop(); // Needed on Linux.
1245 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); 1287 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL));
1246 1288
1247 ui_test_utils::NavigateToURLWithDisposition( 1289 ui_test_utils::NavigateToURLWithDisposition(
1248 browser(), url, NEW_FOREGROUND_TAB, 1290 browser(), url, NEW_FOREGROUND_TAB,
1249 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1291 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1250 browser()->CloseTab(); 1292 browser()->CloseTab();
1251 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); 1293 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL));
1252 EXPECT_EQ(position, position2); 1294 EXPECT_EQ(position, position2);
1253 } 1295 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/find_in_page/start_after_selection.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698