find_bar_host_browsertest.cc revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "base/message_loop.h" 6#include "base/string_util.h" 7#include "base/utf_string_conversions.h" 8#include "chrome/browser/profiles/profile.h" 9#include "chrome/browser/tabs/tab_strip_model.h" 10#include "chrome/browser/ui/browser.h" 11#include "chrome/browser/ui/browser_navigator.h" 12#include "chrome/browser/ui/browser_window.h" 13#include "chrome/browser/ui/find_bar/find_bar.h" 14#include "chrome/browser/ui/find_bar/find_bar_controller.h" 15#include "chrome/browser/ui/find_bar/find_notification_details.h" 16#include "chrome/browser/ui/find_bar/find_tab_helper.h" 17#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 18#include "chrome/test/in_process_browser_test.h" 19#include "chrome/test/ui_test_utils.h" 20#include "content/browser/renderer_host/render_view_host.h" 21#include "content/browser/tab_contents/tab_contents.h" 22#include "content/browser/tab_contents/tab_contents_view.h" 23#include "net/test/test_server.h" 24#include "ui/base/keycodes/keyboard_codes.h" 25 26#if defined(TOOLKIT_VIEWS) 27#include "chrome/browser/ui/views/find_bar_host.h" 28#include "views/focus/focus_manager.h" 29#elif defined(TOOLKIT_GTK) 30#include "chrome/browser/ui/gtk/slide_animator_gtk.h" 31#elif defined(OS_MACOSX) 32#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 33#endif 34 35const std::string kSimplePage = "404_is_enough_for_us.html"; 36const std::string kFramePage = "files/find_in_page/frames.html"; 37const std::string kFrameData = "files/find_in_page/framedata_general.html"; 38const std::string kUserSelectPage = "files/find_in_page/user-select.html"; 39const std::string kCrashPage = "files/find_in_page/crash_1341577.html"; 40const std::string kTooFewMatchesPage = "files/find_in_page/bug_1155639.html"; 41const std::string kLongTextareaPage = "files/find_in_page/large_textarea.html"; 42const std::string kEndState = "files/find_in_page/end_state.html"; 43const std::string kPrematureEnd = "files/find_in_page/premature_end.html"; 44const std::string kMoveIfOver = "files/find_in_page/move_if_obscuring.html"; 45const std::string kBitstackCrash = "files/find_in_page/crash_14491.html"; 46const std::string kSelectChangesOrdinal = 47 "files/find_in_page/select_changes_ordinal.html"; 48const std::string kSimple = "files/find_in_page/simple.html"; 49const std::string kLinkPage = "files/find_in_page/link.html"; 50 51const bool kBack = false; 52const bool kFwd = true; 53 54const bool kIgnoreCase = false; 55const bool kCaseSensitive = true; 56 57const int kMoveIterations = 30; 58 59class FindInPageControllerTest : public InProcessBrowserTest { 60 public: 61 FindInPageControllerTest() { 62 EnableDOMAutomation(); 63 64#if defined(TOOLKIT_VIEWS) 65 DropdownBarHost::disable_animations_during_testing_ = true; 66#elif defined(TOOLKIT_GTK) 67 SlideAnimatorGtk::SetAnimationsForTesting(false); 68#elif defined(OS_MACOSX) 69 FindBarBridge::disable_animations_during_testing_ = true; 70#endif 71 } 72 73 protected: 74 bool GetFindBarWindowInfoForBrowser( 75 Browser* browser, gfx::Point* position, bool* fully_visible) { 76 FindBarTesting* find_bar = 77 browser->GetFindBarController()->find_bar()->GetFindBarTesting(); 78 return find_bar->GetFindBarWindowInfo(position, fully_visible); 79 } 80 81 bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) { 82 return GetFindBarWindowInfoForBrowser(browser(), position, fully_visible); 83 } 84 85 string16 GetFindBarTextForBrowser(Browser* browser) { 86 FindBarTesting* find_bar = 87 browser->GetFindBarController()->find_bar()->GetFindBarTesting(); 88 return find_bar->GetFindText(); 89 } 90 91 string16 GetFindBarText() { 92 return GetFindBarTextForBrowser(browser()); 93 } 94 95 string16 GetFindBarMatchCountTextForBrowser(Browser* browser) { 96 FindBarTesting* find_bar = 97 browser->GetFindBarController()->find_bar()->GetFindBarTesting(); 98 return find_bar->GetMatchCountText(); 99 } 100 101 string16 GetMatchCountText() { 102 return GetFindBarMatchCountTextForBrowser(browser()); 103 } 104 105 void EnsureFindBoxOpenForBrowser(Browser* browser) { 106 browser->ShowFindBar(); 107 gfx::Point position; 108 bool fully_visible = false; 109 EXPECT_TRUE(GetFindBarWindowInfoForBrowser( 110 browser, &position, &fully_visible)); 111 EXPECT_TRUE(fully_visible); 112 } 113 114 void EnsureFindBoxOpen() { 115 EnsureFindBoxOpenForBrowser(browser()); 116 } 117}; 118 119// Platform independent FindInPage that takes |const wchar_t*| 120// as an input. 121int FindInPageWchar(TabContentsWrapper* tab, 122 const wchar_t* search_str, 123 bool forward, 124 bool case_sensitive, 125 int* ordinal) { 126 return ui_test_utils::FindInPage( 127 tab, WideToUTF16(std::wstring(search_str)), 128 forward, case_sensitive, ordinal); 129} 130 131// This test loads a page with frames and starts FindInPage requests. 132IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { 133 ASSERT_TRUE(test_server()->Start()); 134 135 // First we navigate to our frames page. 136 GURL url = test_server()->GetURL(kFramePage); 137 ui_test_utils::NavigateToURL(browser(), url); 138 139 // Try incremental search (mimicking user typing in). 140 int ordinal = 0; 141 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 142 EXPECT_EQ(18, FindInPageWchar(tab, L"g", 143 kFwd, kIgnoreCase, &ordinal)); 144 EXPECT_EQ(1, ordinal); 145 EXPECT_EQ(11, FindInPageWchar(tab, L"go", 146 kFwd, kIgnoreCase, &ordinal)); 147 EXPECT_EQ(1, ordinal); 148 EXPECT_EQ(04, FindInPageWchar(tab, L"goo", 149 kFwd, kIgnoreCase, &ordinal)); 150 EXPECT_EQ(1, ordinal); 151 EXPECT_EQ(03, FindInPageWchar(tab, L"goog", 152 kFwd, kIgnoreCase, &ordinal)); 153 EXPECT_EQ(1, ordinal); 154 EXPECT_EQ(02, FindInPageWchar(tab, L"googl", 155 kFwd, kIgnoreCase, &ordinal)); 156 EXPECT_EQ(1, ordinal); 157 EXPECT_EQ(01, FindInPageWchar(tab, L"google", 158 kFwd, kIgnoreCase, &ordinal)); 159 EXPECT_EQ(1, ordinal); 160 EXPECT_EQ(00, FindInPageWchar(tab, L"google!", 161 kFwd, kIgnoreCase, &ordinal)); 162 EXPECT_EQ(0, ordinal); 163 164 // Negative test (no matches should be found). 165 EXPECT_EQ(0, FindInPageWchar(tab, L"Non-existing string", 166 kFwd, kIgnoreCase, &ordinal)); 167 EXPECT_EQ(0, ordinal); 168 169 // 'horse' only exists in the three right frames. 170 EXPECT_EQ(3, FindInPageWchar(tab, L"horse", 171 kFwd, kIgnoreCase, &ordinal)); 172 EXPECT_EQ(1, ordinal); 173 174 // 'cat' only exists in the first frame. 175 EXPECT_EQ(1, FindInPageWchar(tab, L"cat", 176 kFwd, kIgnoreCase, &ordinal)); 177 EXPECT_EQ(1, ordinal); 178 179 // Try searching again, should still come up with 1 match. 180 EXPECT_EQ(1, FindInPageWchar(tab, L"cat", 181 kFwd, kIgnoreCase, &ordinal)); 182 EXPECT_EQ(1, ordinal); 183 184 // Try searching backwards, ignoring case, should still come up with 1 match. 185 EXPECT_EQ(1, FindInPageWchar(tab, L"CAT", 186 kBack, kIgnoreCase, &ordinal)); 187 EXPECT_EQ(1, ordinal); 188 189 // Try case sensitive, should NOT find it. 190 EXPECT_EQ(0, FindInPageWchar(tab, L"CAT", 191 kFwd, kCaseSensitive, &ordinal)); 192 EXPECT_EQ(0, ordinal); 193 194 // Try again case sensitive, but this time with right case. 195 EXPECT_EQ(1, FindInPageWchar(tab, L"dog", 196 kFwd, kCaseSensitive, &ordinal)); 197 EXPECT_EQ(1, ordinal); 198 199 // Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame). 200 EXPECT_EQ(1, FindInPageWchar(tab, L"Hreggvi\u00F0ur", 201 kFwd, kIgnoreCase, &ordinal)); 202 EXPECT_EQ(1, ordinal); 203 EXPECT_EQ(1, FindInPageWchar(tab, L"Hreggvi\u00F0ur", 204 kFwd, kCaseSensitive, &ordinal)); 205 EXPECT_EQ(1, ordinal); 206 EXPECT_EQ(0, FindInPageWchar(tab, L"hreggvi\u00F0ur", 207 kFwd, kCaseSensitive, &ordinal)); 208 EXPECT_EQ(0, ordinal); 209} 210 211// Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. 212bool FocusedOnPage(TabContents* tab_contents, std::string* result) 213 WARN_UNUSED_RESULT; 214 215bool FocusedOnPage(TabContents* tab_contents, std::string* result) { 216 return ui_test_utils::ExecuteJavaScriptAndExtractString( 217 tab_contents->render_view_host(), 218 L"", 219 L"window.domAutomationController.send(getFocusedElement());", 220 result); 221} 222 223// This tests the FindInPage end-state, in other words: what is focused when you 224// close the Find box (ie. if you find within a link the link should be 225// focused). 226IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { 227 ASSERT_TRUE(test_server()->Start()); 228 229 // First we navigate to our special focus tracking page. 230 GURL url = test_server()->GetURL(kEndState); 231 ui_test_utils::NavigateToURL(browser(), url); 232 233 TabContentsWrapper* tab_contents = browser()->GetSelectedTabContentsWrapper(); 234 ASSERT_TRUE(NULL != tab_contents); 235 236 // Verify that nothing has focus. 237 std::string result; 238 ASSERT_TRUE(FocusedOnPage(tab_contents->tab_contents(), &result)); 239 ASSERT_STREQ("{nothing focused}", result.c_str()); 240 241 // Search for a text that exists within a link on the page. 242 int ordinal = 0; 243 EXPECT_EQ(1, FindInPageWchar(tab_contents, L"nk", 244 kFwd, kIgnoreCase, &ordinal)); 245 EXPECT_EQ(1, ordinal); 246 247 // End the find session, which should set focus to the link. 248 tab_contents-> 249 find_tab_helper()->StopFinding(FindBarController::kKeepSelection); 250 251 // Verify that the link is focused. 252 ASSERT_TRUE(FocusedOnPage(tab_contents->tab_contents(), &result)); 253 EXPECT_STREQ("link1", result.c_str()); 254 255 // Search for a text that exists within a link on the page. 256 EXPECT_EQ(1, FindInPageWchar(tab_contents, L"Google", 257 kFwd, kIgnoreCase, &ordinal)); 258 EXPECT_EQ(1, ordinal); 259 260 // Move the selection to link 1, after searching. 261 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 262 tab_contents->render_view_host(), 263 L"", 264 L"window.domAutomationController.send(selectLink1());", 265 &result)); 266 267 // End the find session. 268 tab_contents-> 269 find_tab_helper()->StopFinding(FindBarController::kKeepSelection); 270 271 // Verify that link2 is not focused. 272 ASSERT_TRUE(FocusedOnPage(tab_contents->tab_contents(), &result)); 273 EXPECT_STREQ("", result.c_str()); 274} 275 276// This test loads a single-frame page and makes sure the ordinal returned makes 277// sense as we FindNext over all the items. 278IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { 279 ASSERT_TRUE(test_server()->Start()); 280 281 // First we navigate to our page. 282 GURL url = test_server()->GetURL(kFrameData); 283 ui_test_utils::NavigateToURL(browser(), url); 284 285 // Search for 'o', which should make the first item active and return 286 // '1 in 3' (1st ordinal of a total of 3 matches). 287 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 288 int ordinal = 0; 289 EXPECT_EQ(3, FindInPageWchar(tab, L"o", 290 kFwd, kIgnoreCase, &ordinal)); 291 EXPECT_EQ(1, ordinal); 292 EXPECT_EQ(3, FindInPageWchar(tab, L"o", 293 kFwd, kIgnoreCase, &ordinal)); 294 EXPECT_EQ(2, ordinal); 295 EXPECT_EQ(3, FindInPageWchar(tab, L"o", 296 kFwd, kIgnoreCase, &ordinal)); 297 EXPECT_EQ(3, ordinal); 298 // Go back one match. 299 EXPECT_EQ(3, FindInPageWchar(tab, L"o", 300 kBack, kIgnoreCase, &ordinal)); 301 EXPECT_EQ(2, ordinal); 302 EXPECT_EQ(3, FindInPageWchar(tab, L"o", 303 kFwd, kIgnoreCase, &ordinal)); 304 EXPECT_EQ(3, ordinal); 305 // This should wrap to the top. 306 EXPECT_EQ(3, FindInPageWchar(tab, L"o", 307 kFwd, kIgnoreCase, &ordinal)); 308 EXPECT_EQ(1, ordinal); 309 // This should go back to the end. 310 EXPECT_EQ(3, FindInPageWchar(tab, L"o", 311 kBack, kIgnoreCase, &ordinal)); 312 EXPECT_EQ(3, ordinal); 313} 314 315// This tests that the ordinal is correctly adjusted after a selection 316IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, 317 SelectChangesOrdinal_Issue20883) { 318 ASSERT_TRUE(test_server()->Start()); 319 320 // First we navigate to our test content. 321 GURL url = test_server()->GetURL(kSelectChangesOrdinal); 322 ui_test_utils::NavigateToURL(browser(), url); 323 324 // Search for a text that exists within a link on the page. 325 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 326 ASSERT_TRUE(NULL != tab); 327 int ordinal = 0; 328 EXPECT_EQ(4, FindInPageWchar(tab, 329 L"google", 330 kFwd, kIgnoreCase, &ordinal)); 331 EXPECT_EQ(1, ordinal); 332 333 // Move the selection to link 1, after searching. 334 std::string result; 335 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 336 tab->render_view_host(), 337 L"", 338 L"window.domAutomationController.send(selectLink1());", 339 &result)); 340 341 // Do a find-next after the selection. This should move forward 342 // from there to the 3rd instance of 'google'. 343 EXPECT_EQ(4, FindInPageWchar(tab, 344 L"google", 345 kFwd, kIgnoreCase, &ordinal)); 346 EXPECT_EQ(3, ordinal); 347 348 // End the find session. 349 tab->find_tab_helper()->StopFinding(FindBarController::kKeepSelection); 350} 351 352// This test loads a page with frames and makes sure the ordinal returned makes 353// sense. 354IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { 355 ASSERT_TRUE(test_server()->Start()); 356 357 // First we navigate to our page. 358 GURL url = test_server()->GetURL(kFramePage); 359 ui_test_utils::NavigateToURL(browser(), url); 360 361 // Search for 'a', which should make the first item active and return 362 // '1 in 7' (1st ordinal of a total of 7 matches). 363 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 364 int ordinal = 0; 365 EXPECT_EQ(7, 366 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 367 EXPECT_EQ(1, ordinal); 368 EXPECT_EQ(7, 369 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 370 EXPECT_EQ(2, ordinal); 371 EXPECT_EQ(7, 372 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 373 EXPECT_EQ(3, ordinal); 374 EXPECT_EQ(7, 375 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 376 EXPECT_EQ(4, ordinal); 377 // Go back one, which should go back one frame. 378 EXPECT_EQ(7, 379 FindInPageWchar(tab, L"a", kBack, kIgnoreCase, &ordinal)); 380 EXPECT_EQ(3, ordinal); 381 EXPECT_EQ(7, 382 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 383 EXPECT_EQ(4, ordinal); 384 EXPECT_EQ(7, 385 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 386 EXPECT_EQ(5, ordinal); 387 EXPECT_EQ(7, 388 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 389 EXPECT_EQ(6, ordinal); 390 EXPECT_EQ(7, 391 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 392 EXPECT_EQ(7, ordinal); 393 // Now we should wrap back to frame 1. 394 EXPECT_EQ(7, 395 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 396 EXPECT_EQ(1, ordinal); 397 // Now we should wrap back to frame last frame. 398 EXPECT_EQ(7, 399 FindInPageWchar(tab, L"a", kBack, kIgnoreCase, &ordinal)); 400 EXPECT_EQ(7, ordinal); 401} 402 403// We could get ordinals out of whack when restarting search in subframes. 404// See http://crbug.com/5132. 405IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { 406 ASSERT_TRUE(test_server()->Start()); 407 408 // First we navigate to our page. 409 GURL url = test_server()->GetURL(kFramePage); 410 ui_test_utils::NavigateToURL(browser(), url); 411 412 // Search for 'goa' three times (6 matches on page). 413 int ordinal = 0; 414 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 415 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", 416 kFwd, kIgnoreCase, &ordinal)); 417 EXPECT_EQ(1, ordinal); 418 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", 419 kFwd, kIgnoreCase, &ordinal)); 420 EXPECT_EQ(2, ordinal); 421 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", 422 kFwd, kIgnoreCase, &ordinal)); 423 EXPECT_EQ(3, ordinal); 424 // Add space to search (should result in no matches). 425 EXPECT_EQ(0, FindInPageWchar(tab, L"goa ", 426 kFwd, kIgnoreCase, &ordinal)); 427 EXPECT_EQ(0, ordinal); 428 // Remove the space, should be back to '3 out of 6') 429 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", 430 kFwd, kIgnoreCase, &ordinal)); 431 EXPECT_EQ(3, ordinal); 432} 433 434// Load a page with no selectable text and make sure we don't crash. 435IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnselectableText) { 436 ASSERT_TRUE(test_server()->Start()); 437 438 // First we navigate to our page. 439 GURL url = test_server()->GetURL(kUserSelectPage); 440 ui_test_utils::NavigateToURL(browser(), url); 441 442 int ordinal = 0; 443 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 444 EXPECT_EQ(1, FindInPageWchar(tab, L"text", kFwd, kIgnoreCase, &ordinal)); 445 EXPECT_EQ(1, ordinal); 446} 447 448// Try to reproduce the crash seen in issue 1341577. 449IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { 450 ASSERT_TRUE(test_server()->Start()); 451 452 // First we navigate to our page. 453 GURL url = test_server()->GetURL(kCrashPage); 454 ui_test_utils::NavigateToURL(browser(), url); 455 456 // This would crash the tab. These must be the first two find requests issued 457 // against the frame, otherwise an active frame pointer is set and it wont 458 // produce the crash. 459 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does 460 // not find a stand-alone dependent vowel sign of Indic scripts. So, the 461 // exptected values are all 0. To make this test pass regardless of 462 // ICU version, we just call FiP and see if there's any crash. 463 // TODO(jungshik): According to a native Malayalam speaker, it's ok not 464 // to find U+0D4C. Still need to investigate further this issue. 465 int ordinal = 0; 466 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 467 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); 468 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); 469 470 // This should work fine. 471 EXPECT_EQ(1, FindInPageWchar(tab, L"\u0D24\u0D46", 472 kFwd, kIgnoreCase, &ordinal)); 473 EXPECT_EQ(1, ordinal); 474 EXPECT_EQ(0, FindInPageWchar(tab, L"nostring", 475 kFwd, kIgnoreCase, &ordinal)); 476 EXPECT_EQ(0, ordinal); 477} 478 479// Try to reproduce the crash seen in http://crbug.com/14491, where an assert 480// hits in the BitStack size comparison in WebKit. 481IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { 482 ASSERT_TRUE(test_server()->Start()); 483 484 // First we navigate to our page. 485 GURL url = test_server()->GetURL(kBitstackCrash); 486 ui_test_utils::NavigateToURL(browser(), url); 487 488 // This used to crash the tab. 489 int ordinal = 0; 490 EXPECT_EQ(0, FindInPageWchar(browser()->GetSelectedTabContentsWrapper(), 491 L"s", kFwd, kIgnoreCase, &ordinal)); 492 EXPECT_EQ(0, ordinal); 493} 494 495// Test to make sure Find does the right thing when restarting from a timeout. 496// We used to have a problem where we'd stop finding matches when all of the 497// following conditions were true: 498// 1) The page has a lot of text to search. 499// 2) The page contains more than one match. 500// 3) It takes longer than the time-slice given to each Find operation (100 501// ms) to find one or more of those matches (so Find times out and has to try 502// again from where it left off). 503IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { 504 ASSERT_TRUE(test_server()->Start()); 505 506 // First we navigate to our page. 507 GURL url = test_server()->GetURL(kTooFewMatchesPage); 508 ui_test_utils::NavigateToURL(browser(), url); 509 510 // This string appears 5 times at the bottom of a long page. If Find restarts 511 // properly after a timeout, it will find 5 matches, not just 1. 512 int ordinal = 0; 513 EXPECT_EQ(5, FindInPageWchar(browser()->GetSelectedTabContentsWrapper(), 514 L"008.xml", 515 kFwd, kIgnoreCase, &ordinal)); 516 EXPECT_EQ(1, ordinal); 517} 518 519// Make sure we don't get into an infinite loop when text box contains very 520// large amount of text. 521IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue70505) { 522 ASSERT_TRUE(test_server()->Start()); 523 524 // First we navigate to our page. 525 GURL url = test_server()->GetURL(kLongTextareaPage); 526 ui_test_utils::NavigateToURL(browser(), url); 527 528 // If this test hangs on the FindInPage call, then it might be a regression 529 // such as the one found in issue http://crbug.com/70505. 530 int ordinal = 0; 531 FindInPageWchar(browser()->GetSelectedTabContentsWrapper(), 532 L"a", kFwd, kIgnoreCase, &ordinal); 533 EXPECT_EQ(1, ordinal); 534 // TODO(finnur): We cannot reliably get the matchcount for this Find call 535 // until we fix issue http://crbug.com/71176. 536} 537 538// This tests bug 11761: FindInPage terminates search prematurely. 539// This test is not expected to pass until bug 11761 is fixed. 540IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, 541 DISABLED_FindInPagePrematureEnd) { 542 ASSERT_TRUE(test_server()->Start()); 543 544 // First we navigate to our special focus tracking page. 545 GURL url = test_server()->GetURL(kPrematureEnd); 546 ui_test_utils::NavigateToURL(browser(), url); 547 548 TabContentsWrapper* tab_contents = browser()->GetSelectedTabContentsWrapper(); 549 ASSERT_TRUE(NULL != tab_contents); 550 551 // Search for a text that exists within a link on the page. 552 int ordinal = 0; 553 EXPECT_EQ(2, FindInPageWchar(tab_contents, L"html ", 554 kFwd, kIgnoreCase, &ordinal)); 555 EXPECT_EQ(1, ordinal); 556} 557 558IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { 559 ASSERT_TRUE(test_server()->Start()); 560 561 // First we navigate to our special focus tracking page. 562 GURL url = test_server()->GetURL(kSimplePage); 563 GURL url2 = test_server()->GetURL(kFramePage); 564 ui_test_utils::NavigateToURL(browser(), url); 565 566 browser()->ShowFindBar(); 567 568 gfx::Point position; 569 bool fully_visible = false; 570 571 // Make sure it is open. 572 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 573 EXPECT_TRUE(fully_visible); 574 575 // Reload the tab and make sure Find window doesn't go away. 576 browser()->Reload(CURRENT_TAB); 577 ui_test_utils::WaitForNavigationInCurrentTab(browser()); 578 579 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 580 EXPECT_TRUE(fully_visible); 581 582 // Navigate and make sure the Find window goes away. 583 ui_test_utils::NavigateToURL(browser(), url2); 584 585 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 586 EXPECT_FALSE(fully_visible); 587} 588 589#if defined(OS_MACOSX) 590// FindDisappearOnNewTabAndHistory is flaky, at least on Mac. 591// See http://crbug.com/43072 592#define FindDisappearOnNewTabAndHistory FLAKY_FindDisappearOnNewTabAndHistory 593#endif 594 595// Make sure Find box disappears when History/Downloads page is opened, and 596// when a New Tab is opened. 597IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, 598 FindDisappearOnNewTabAndHistory) { 599 ASSERT_TRUE(test_server()->Start()); 600 601 // First we navigate to our special focus tracking page. 602 GURL url = test_server()->GetURL(kSimplePage); 603 ui_test_utils::NavigateToURL(browser(), url); 604 605 browser()->ShowFindBar(); 606 607 gfx::Point position; 608 bool fully_visible = false; 609 610 // Make sure it is open. 611 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 612 EXPECT_TRUE(fully_visible); 613 614 // Open another tab (tab B). 615 browser()->NewTab(); 616 ui_test_utils::NavigateToURL(browser(), url); 617 618 // Make sure Find box is closed. 619 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 620 EXPECT_FALSE(fully_visible); 621 622 // Close tab B. 623 browser()->CloseTab(); 624 625 // Make sure Find window appears again. 626 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 627 EXPECT_TRUE(fully_visible); 628 629 browser()->ShowHistoryTab(); 630 631 // Make sure Find box is closed. 632 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 633 EXPECT_FALSE(fully_visible); 634} 635 636// TODO(rohitrao): The FindMovesWhenObscuring test does not pass on mac. 637// http://crbug.com/22036 638#if defined(OS_MACOSX) 639#define MAYBE_FindMovesWhenObscuring FAILS_FindMovesWhenObscuring 640#else 641#define MAYBE_FindMovesWhenObscuring FindMovesWhenObscuring 642#endif 643 644// Make sure Find box moves out of the way if it is obscuring the active match. 645IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_FindMovesWhenObscuring) { 646 ASSERT_TRUE(test_server()->Start()); 647 648 GURL url = test_server()->GetURL(kMoveIfOver); 649 ui_test_utils::NavigateToURL(browser(), url); 650 651 browser()->ShowFindBar(); 652 653 // This is needed on GTK because the reposition operation is asynchronous. 654 MessageLoop::current()->RunAllPending(); 655 656 gfx::Point start_position; 657 gfx::Point position; 658 bool fully_visible = false; 659 660 // Make sure it is open. 661 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible)); 662 EXPECT_TRUE(fully_visible); 663 664 // Search for 'Chromium' which the Find box is obscuring. 665 int ordinal = 0; 666 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 667 int index = 0; 668 for (; index < kMoveIterations; ++index) { 669 EXPECT_EQ(kMoveIterations, FindInPageWchar(tab, L"Chromium", 670 kFwd, kIgnoreCase, &ordinal)); 671 672 // Check the position. 673 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 674 EXPECT_TRUE(fully_visible); 675 676 // If the Find box has moved then we are done. 677 if (position.x() != start_position.x()) 678 break; 679 } 680 681 // We should not have reached the end. 682 ASSERT_GT(kMoveIterations, index); 683 684 // Search for something guaranteed not to be obscured by the Find box. 685 EXPECT_EQ(1, FindInPageWchar(tab, L"Done", 686 kFwd, kIgnoreCase, &ordinal)); 687 // Check the position. 688 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 689 EXPECT_TRUE(fully_visible); 690 691 // Make sure Find box has moved back to its original location. 692 EXPECT_EQ(position.x(), start_position.x()); 693} 694 695#if defined(OS_MACOSX) 696// FindNextInNewTabUsesPrepopulate times-out, at least on Mac. 697// See http://crbug.com/43070 698#define FindNextInNewTabUsesPrepopulate DISABLED_FindNextInNewTabUsesPrepopulate 699#endif 700 701// Make sure F3 in a new tab works if Find has previous string to search for. 702IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, 703 FindNextInNewTabUsesPrepopulate) { 704 ASSERT_TRUE(test_server()->Start()); 705 706 // First we navigate to any page. 707 GURL url = test_server()->GetURL(kSimplePage); 708 ui_test_utils::NavigateToURL(browser(), url); 709 710 // Search for 'no_match'. No matches should be found. 711 int ordinal = 0; 712 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 713 EXPECT_EQ(0, FindInPageWchar(tab, L"no_match", 714 kFwd, kIgnoreCase, &ordinal)); 715 EXPECT_EQ(0, ordinal); 716 717 // Open another tab (tab B). 718 browser()->NewTab(); 719 ui_test_utils::NavigateToURL(browser(), url); 720 721 // Simulate what happens when you press F3 for FindNext. We should get a 722 // response here (a hang means search was aborted). 723 EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(), 724 kFwd, kIgnoreCase, &ordinal)); 725 EXPECT_EQ(0, ordinal); 726 727 // Open another tab (tab C). 728 browser()->NewTab(); 729 ui_test_utils::NavigateToURL(browser(), url); 730 731 // Simulate what happens when you press F3 for FindNext. We should get a 732 // response here (a hang means search was aborted). 733 EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(), 734 kFwd, kIgnoreCase, &ordinal)); 735 EXPECT_EQ(0, ordinal); 736} 737 738#if defined(TOOLKIT_VIEWS) 739// Make sure Find box grabs the Esc accelerator and restores it again. 740#if defined(OS_LINUX) 741// TODO(oshima): On Gtk/Linux, a focus out event is asynchronous and 742// hiding a find bar does not immediately update the target 743// accelerator. The last condition fails in most cases due to this 744// behavior. See http://crbug.com/26870. 745IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, 746 DISABLED_AcceleratorRestoring) { 747#else 748 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) { 749#endif 750 ASSERT_TRUE(test_server()->Start()); 751 752 // First we navigate to any page. 753 GURL url = test_server()->GetURL(kSimplePage); 754 ui_test_utils::NavigateToURL(browser(), url); 755 756 views::FocusManager* focus_manager = 757 views::FocusManager::GetFocusManagerForNativeWindow( 758 browser()->window()->GetNativeHandle()); 759 760 // See where Escape is registered. 761 views::Accelerator escape(ui::VKEY_ESCAPE, false, false, false); 762 views::AcceleratorTarget* old_target = 763 focus_manager->GetCurrentTargetForAccelerator(escape); 764 EXPECT_TRUE(old_target != NULL); 765 766 browser()->ShowFindBar(); 767 768 // Our Find bar should be the new target. 769 views::AcceleratorTarget* new_target = 770 focus_manager->GetCurrentTargetForAccelerator(escape); 771 772 EXPECT_TRUE(new_target != NULL); 773 EXPECT_NE(new_target, old_target); 774 775 // Close the Find box. 776 browser()->GetFindBarController()->EndFindSession( 777 FindBarController::kKeepSelection); 778 779 // The accelerator for Escape should be back to what it was before. 780 EXPECT_EQ(old_target, 781 focus_manager->GetCurrentTargetForAccelerator(escape)); 782} 783#endif // TOOLKIT_VIEWS 784 785// Make sure Find box does not become UI-inactive when no text is in the box as 786// we switch to a tab contents with an empty find string. See issue 13570. 787IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) { 788 ASSERT_TRUE(test_server()->Start()); 789 790 // First we navigate to any page. 791 GURL url = test_server()->GetURL(kSimplePage); 792 ui_test_utils::NavigateToURL(browser(), url); 793 794 browser()->ShowFindBar(); 795 796 // Simulate a user clearing the search string. Ideally, we should be 797 // simulating keypresses here for searching for something and pressing 798 // backspace, but that's been proven flaky in the past, so we go straight to 799 // tab_contents. 800 FindTabHelper* find_tab_helper = 801 browser()->GetSelectedTabContentsWrapper()->find_tab_helper(); 802 // Stop the (non-existing) find operation, and clear the selection (which 803 // signals the UI is still active). 804 find_tab_helper->StopFinding(FindBarController::kClearSelection); 805 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI 806 // still responds to browser window resizing. 807 ASSERT_TRUE(find_tab_helper->find_ui_active()); 808} 809 810// Make sure F3 works after you FindNext a couple of times and end the Find 811// session. See issue http://crbug.com/28306. 812IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { 813 ASSERT_TRUE(test_server()->Start()); 814 815 // First we navigate to a simple page. 816 GURL url = test_server()->GetURL(kSimple); 817 ui_test_utils::NavigateToURL(browser(), url); 818 819 // Search for 'page'. Should have 1 match. 820 int ordinal = 0; 821 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 822 EXPECT_EQ(1, FindInPageWchar(tab, L"page", kFwd, kIgnoreCase, &ordinal)); 823 EXPECT_EQ(1, ordinal); 824 825 // Simulate what happens when you press F3 for FindNext. Still should show 826 // one match. This cleared the pre-populate string at one point (see bug). 827 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, string16(), 828 kFwd, kIgnoreCase, &ordinal)); 829 EXPECT_EQ(1, ordinal); 830 831 // End the Find session, thereby making the next F3 start afresh. 832 browser()->GetFindBarController()->EndFindSession( 833 FindBarController::kKeepSelection); 834 835 // Simulate F3 while Find box is closed. Should have 1 match. 836 EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal)); 837 EXPECT_EQ(1, ordinal); 838} 839 840// When re-opening the find bar with F3, the find bar should be re-populated 841// with the last search from the same tab rather than the last overall search. 842// http://crbug.com/30006 843IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { 844 ASSERT_TRUE(test_server()->Start()); 845 846 // First we navigate to any page. 847 GURL url = test_server()->GetURL(kSimplePage); 848 ui_test_utils::NavigateToURL(browser(), url); 849 850 // Find "Default". 851 int ordinal = 0; 852 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); 853 EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal)); 854 855 // Create a second tab. 856 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It 857 // could be some delicate assumption about the tab starting off unselected or 858 // something relating to user gesture. 859 browser::NavigateParams params(browser(), url, PageTransition::TYPED); 860 params.disposition = NEW_BACKGROUND_TAB; 861 params.tabstrip_add_types = TabStripModel::ADD_NONE; 862 browser::Navigate(¶ms); 863 browser()->SelectTabContentsAt(1, false); 864 TabContentsWrapper* tab2 = browser()->GetSelectedTabContentsWrapper(); 865 EXPECT_NE(tab1, tab2); 866 867 // Find "given". 868 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); 869 870 // Switch back to first tab. 871 browser()->SelectTabContentsAt(0, false); 872 browser()->GetFindBarController()->EndFindSession( 873 FindBarController::kKeepSelection); 874 // Simulate F3. 875 ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal); 876 EXPECT_EQ(tab1->find_tab_helper()->find_text(), WideToUTF16(L"Default")); 877} 878 879// This tests that whenever you close and reopen the Find bar, it should show 880// the last search entered in that tab. http://crbug.com/40121. 881IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) { 882#if defined(OS_MACOSX) 883 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 884 return; 885#endif 886 887 ASSERT_TRUE(test_server()->Start()); 888 889 // First we navigate to any page. 890 GURL url = test_server()->GetURL(kSimple); 891 ui_test_utils::NavigateToURL(browser(), url); 892 893 // Search for the word "page". 894 int ordinal = 0; 895 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); 896 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); 897 898 // Open the Find box. 899 EnsureFindBoxOpen(); 900 901 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 902 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); 903 904 // Close the Find box. 905 browser()->GetFindBarController()->EndFindSession( 906 FindBarController::kKeepSelection); 907 908 // Open the Find box again. 909 EnsureFindBoxOpen(); 910 911 // After the Find box has been reopened, it should have been prepopulated with 912 // the word "page" again. 913 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 914 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); 915} 916 917// This tests that whenever you open Find in a new tab it should prepopulate 918// with a previous search term (in any tab), if a search has not been issued in 919// this tab before. 920IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) { 921#if defined(OS_MACOSX) 922 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 923 return; 924#endif 925 926 ASSERT_TRUE(test_server()->Start()); 927 928 // First we navigate to any page. 929 GURL url = test_server()->GetURL(kSimple); 930 ui_test_utils::NavigateToURL(browser(), url); 931 932 // Search for the word "page". 933 int ordinal = 0; 934 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); 935 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); 936 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); 937 938 // Now create a second tab and load the same page. 939 browser()->AddSelectedTabWithURL(url, PageTransition::TYPED); 940 TabContentsWrapper* tab2 = browser()->GetSelectedTabContentsWrapper(); 941 EXPECT_NE(tab1, tab2); 942 943 // Open the Find box. 944 EnsureFindBoxOpen(); 945 946 // The new tab should have "page" prepopulated, since that was the last search 947 // in the first tab. 948 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 949 // But it should not seem like a search has been issued. 950 EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText()); 951} 952 953// This makes sure that we can search for A in tabA, then for B in tabB and 954// when we come back to tabA we should still see A (because that was the last 955// search in that tab). 956IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) { 957#if defined(OS_MACOSX) 958 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 959 return; 960#endif 961 962 ASSERT_TRUE(test_server()->Start()); 963 964 // First we navigate to any page. 965 GURL url = test_server()->GetURL(kSimple); 966 ui_test_utils::NavigateToURL(browser(), url); 967 968 // Search for the word "page". 969 int ordinal = 0; 970 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); 971 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); 972 973 // Open the Find box. 974 EnsureFindBoxOpen(); 975 976 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 977 978 // Close the Find box. 979 browser()->GetFindBarController()->EndFindSession( 980 FindBarController::kKeepSelection); 981 982 // Now create a second tab and load the same page. 983 browser::NavigateParams params(browser(), url, PageTransition::TYPED); 984 params.disposition = NEW_BACKGROUND_TAB; 985 params.tabstrip_add_types = TabStripModel::ADD_NONE; 986 browser::Navigate(¶ms); 987 browser()->SelectTabContentsAt(1, false); 988 TabContentsWrapper* tab2 = browser()->GetSelectedTabContentsWrapper(); 989 EXPECT_NE(tab1, tab2); 990 991 // Search for the word "text". 992 FindInPageWchar(tab2, L"text", kFwd, kIgnoreCase, &ordinal); 993 994 // Go back to the first tab and make sure we have NOT switched the prepopulate 995 // text to "text". 996 browser()->SelectTabContentsAt(0, false); 997 998 // Open the Find box. 999 EnsureFindBoxOpen(); 1000 1001 // After the Find box has been reopened, it should have been prepopulated with 1002 // the word "page" again, since that was the last search in that tab. 1003 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 1004 1005 // Close the Find box. 1006 browser()->GetFindBarController()->EndFindSession( 1007 FindBarController::kKeepSelection); 1008 1009 // Re-open the Find box. 1010 // This is a special case: previous search in TabContents used to get cleared 1011 // if you opened and closed the FindBox, which would cause the global 1012 // prepopulate value to show instead of last search in this tab. 1013 EnsureFindBoxOpen(); 1014 1015 // After the Find box has been reopened, it should have been prepopulated with 1016 // the word "page" again, since that was the last search in that tab. 1017 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 1018} 1019 1020// TODO(rohitrao): Searching in incognito tabs does not work in browser tests in 1021// Linux views. Investigate and fix. http://crbug.com/40948 1022#if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) 1023#define MAYBE_NoIncognitoPrepopulate DISABLED_NoIncognitoPrepopulate 1024#else 1025#define MAYBE_NoIncognitoPrepopulate NoIncognitoPrepopulate 1026#endif 1027 1028// This tests that search terms entered into an incognito find bar are not used 1029// as prepopulate terms for non-incognito windows. 1030IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) { 1031#if defined(OS_MACOSX) 1032 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 1033 return; 1034#endif 1035 1036 ASSERT_TRUE(test_server()->Start()); 1037 1038 // First we navigate to the "simple" test page. 1039 GURL url = test_server()->GetURL(kSimple); 1040 ui_test_utils::NavigateToURL(browser(), url); 1041 1042 // Search for the word "page" in the normal browser tab. 1043 int ordinal = 0; 1044 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); 1045 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); 1046 1047 // Open the Find box. 1048 EnsureFindBoxOpenForBrowser(browser()); 1049 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); 1050 1051 // Close the Find box. 1052 browser()->GetFindBarController()->EndFindSession( 1053 FindBarController::kKeepSelection); 1054 1055 // Open a new incognito window and navigate to the same page. 1056 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); 1057 Browser* incognito_browser = Browser::Create(incognito_profile); 1058 incognito_browser->AddSelectedTabWithURL(url, PageTransition::START_PAGE); 1059 ui_test_utils::WaitForNavigation( 1060 &incognito_browser->GetSelectedTabContents()->controller()); 1061 incognito_browser->window()->Show(); 1062 1063 // Open the find box and make sure that it is prepopulated with "page". 1064 EnsureFindBoxOpenForBrowser(incognito_browser); 1065 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser)); 1066 1067 // Search for the word "text" in the incognito tab. 1068 TabContentsWrapper* incognito_tab = 1069 incognito_browser->GetSelectedTabContentsWrapper(); 1070 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text", 1071 kFwd, kIgnoreCase, &ordinal)); 1072 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser)); 1073 1074 // Close the Find box. 1075 incognito_browser->GetFindBarController()->EndFindSession( 1076 FindBarController::kKeepSelection); 1077 1078 // Now open a new tab in the original (non-incognito) browser. 1079 browser()->AddSelectedTabWithURL(url, PageTransition::TYPED); 1080 TabContentsWrapper* tab2 = browser()->GetSelectedTabContentsWrapper(); 1081 EXPECT_NE(tab1, tab2); 1082 1083 // Open the Find box and make sure it is prepopulated with the search term 1084 // from the original browser, not the search term from the incognito window. 1085 EnsureFindBoxOpenForBrowser(browser()); 1086 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); 1087} 1088 1089// This makes sure that dismissing the find bar with kActivateSelection works. 1090IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) { 1091 ASSERT_TRUE(test_server()->Start()); 1092 1093 // First we navigate to our test content. 1094 GURL url = test_server()->GetURL(kLinkPage); 1095 ui_test_utils::NavigateToURL(browser(), url); 1096 1097 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); 1098 int ordinal = 0; 1099 FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal); 1100 EXPECT_EQ(ordinal, 1); 1101 1102 // End the find session, click on the link. 1103 tab->find_tab_helper()->StopFinding(FindBarController::kActivateSelection); 1104 EXPECT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); 1105} 1106