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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 }; | 185 }; |
186 | 186 |
187 // This test loads a page with frames and starts FindInPage requests. | 187 // This test loads a page with frames and starts FindInPage requests. |
188 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { | 188 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { |
189 // First we navigate to our frames page. | 189 // First we navigate to our frames page. |
190 GURL url = GetURL(kFramePage); | 190 GURL url = GetURL(kFramePage); |
191 ui_test_utils::NavigateToURL(browser(), url); | 191 ui_test_utils::NavigateToURL(browser(), url); |
192 | 192 |
193 // Try incremental search (mimicking user typing in). | 193 // Try incremental search (mimicking user typing in). |
194 int ordinal = 0; | 194 int ordinal = 0; |
195 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 195 WebContents* web_contents = |
| 196 browser()->tab_strip_model()->GetActiveWebContents(); |
196 EXPECT_EQ(18, FindInPageWchar(web_contents, L"g", | 197 EXPECT_EQ(18, FindInPageWchar(web_contents, L"g", |
197 kFwd, kIgnoreCase, &ordinal)); | 198 kFwd, kIgnoreCase, &ordinal)); |
198 EXPECT_EQ(1, ordinal); | 199 EXPECT_EQ(1, ordinal); |
199 EXPECT_EQ(11, FindInPageWchar(web_contents, L"go", | 200 EXPECT_EQ(11, FindInPageWchar(web_contents, L"go", |
200 kFwd, kIgnoreCase, &ordinal)); | 201 kFwd, kIgnoreCase, &ordinal)); |
201 EXPECT_EQ(1, ordinal); | 202 EXPECT_EQ(1, ordinal); |
202 EXPECT_EQ(4, FindInPageWchar(web_contents, L"goo", | 203 EXPECT_EQ(4, FindInPageWchar(web_contents, L"goo", |
203 kFwd, kIgnoreCase, &ordinal)); | 204 kFwd, kIgnoreCase, &ordinal)); |
204 EXPECT_EQ(1, ordinal); | 205 EXPECT_EQ(1, ordinal); |
205 EXPECT_EQ(3, FindInPageWchar(web_contents, L"goog", | 206 EXPECT_EQ(3, FindInPageWchar(web_contents, L"goog", |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 kFwd, kCaseSensitive, &ordinal)); | 262 kFwd, kCaseSensitive, &ordinal)); |
262 EXPECT_EQ(0, ordinal); | 263 EXPECT_EQ(0, ordinal); |
263 } | 264 } |
264 | 265 |
265 // Verify search for text within various forms and text areas. | 266 // Verify search for text within various forms and text areas. |
266 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFormsTextAreas) { | 267 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFormsTextAreas) { |
267 std::vector<GURL> urls; | 268 std::vector<GURL> urls; |
268 urls.push_back(GetURL("textintextarea.html")); | 269 urls.push_back(GetURL("textintextarea.html")); |
269 urls.push_back(GetURL("smalltextarea.html")); | 270 urls.push_back(GetURL("smalltextarea.html")); |
270 urls.push_back(GetURL("populatedform.html")); | 271 urls.push_back(GetURL("populatedform.html")); |
271 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 272 WebContents* web_contents = |
| 273 browser()->tab_strip_model()->GetActiveWebContents(); |
272 | 274 |
273 for (size_t i = 0; i < urls.size(); ++i) { | 275 for (size_t i = 0; i < urls.size(); ++i) { |
274 ui_test_utils::NavigateToURL(browser(), urls[i]); | 276 ui_test_utils::NavigateToURL(browser(), urls[i]); |
275 EXPECT_EQ(1, FindInPageWchar(web_contents, L"cat", | 277 EXPECT_EQ(1, FindInPageWchar(web_contents, L"cat", |
276 kFwd, kIgnoreCase, NULL)); | 278 kFwd, kIgnoreCase, NULL)); |
277 EXPECT_EQ(0, FindInPageWchar(web_contents, L"bat", | 279 EXPECT_EQ(0, FindInPageWchar(web_contents, L"bat", |
278 kFwd, kIgnoreCase, NULL)); | 280 kFwd, kIgnoreCase, NULL)); |
279 } | 281 } |
280 } | 282 } |
281 | 283 |
282 // Verify search for text within special URLs such as chrome:history, | 284 // Verify search for text within special URLs such as chrome:history, |
283 // chrome://downloads, data directory | 285 // chrome://downloads, data directory |
284 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SearchWithinSpecialURL) { | 286 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SearchWithinSpecialURL) { |
285 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 287 WebContents* web_contents = |
| 288 browser()->tab_strip_model()->GetActiveWebContents(); |
286 | 289 |
287 FilePath data_dir = ui_test_utils::GetTestFilePath(FilePath(), FilePath()); | 290 FilePath data_dir = ui_test_utils::GetTestFilePath(FilePath(), FilePath()); |
288 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(data_dir)); | 291 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(data_dir)); |
289 EXPECT_EQ(1, FindInPageWchar(web_contents, L"downloads", | 292 EXPECT_EQ(1, FindInPageWchar(web_contents, L"downloads", |
290 kFwd, kIgnoreCase, NULL)); | 293 kFwd, kIgnoreCase, NULL)); |
291 | 294 |
292 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL)); | 295 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL)); |
293 | 296 |
294 // The history page does an async request to the history service and then | 297 // The history page does an async request to the history service and then |
295 // updates the renderer. So we make a query as well, and by the time it comes | 298 // updates the renderer. So we make a query as well, and by the time it comes |
(...skipping 17 matching lines...) Expand all Loading... |
313 ASCIIToWide(download_url.spec()).c_str(), kFwd, | 316 ASCIIToWide(download_url.spec()).c_str(), kFwd, |
314 kIgnoreCase, NULL)); | 317 kIgnoreCase, NULL)); |
315 } | 318 } |
316 | 319 |
317 // Verify search selection coordinates. The data file used is set-up such that | 320 // Verify search selection coordinates. The data file used is set-up such that |
318 // the text occurs on the same line, and we verify their positions by verifying | 321 // the text occurs on the same line, and we verify their positions by verifying |
319 // their relative positions. | 322 // their relative positions. |
320 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageSpecialURLs) { | 323 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageSpecialURLs) { |
321 std::wstring search_string(L"\u5728\u897f\u660c\u536b\u661f\u53d1"); | 324 std::wstring search_string(L"\u5728\u897f\u660c\u536b\u661f\u53d1"); |
322 gfx::Rect first, second, first_reverse; | 325 gfx::Rect first, second, first_reverse; |
323 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 326 WebContents* web_contents = |
| 327 browser()->tab_strip_model()->GetActiveWebContents(); |
324 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html")); | 328 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html")); |
325 ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string), | 329 ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string), |
326 kFwd, kIgnoreCase, NULL, &first); | 330 kFwd, kIgnoreCase, NULL, &first); |
327 ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string), | 331 ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string), |
328 kFwd, kIgnoreCase, NULL, &second); | 332 kFwd, kIgnoreCase, NULL, &second); |
329 | 333 |
330 // We have search occurrence in the same row, so top-bottom coordinates should | 334 // We have search occurrence in the same row, so top-bottom coordinates should |
331 // be the same even for second search. | 335 // be the same even for second search. |
332 ASSERT_EQ(first.y(), second.y()); | 336 ASSERT_EQ(first.y(), second.y()); |
333 ASSERT_EQ(first.bottom(), second.bottom()); | 337 ASSERT_EQ(first.bottom(), second.bottom()); |
334 ASSERT_LT(first.x(), second.x()); | 338 ASSERT_LT(first.x(), second.x()); |
335 ASSERT_LT(first.right(), second.right()); | 339 ASSERT_LT(first.right(), second.right()); |
336 | 340 |
337 ui_test_utils::FindInPage( | 341 ui_test_utils::FindInPage( |
338 web_contents, WideToUTF16(search_string), kBack, kIgnoreCase, NULL, | 342 web_contents, WideToUTF16(search_string), kBack, kIgnoreCase, NULL, |
339 &first_reverse); | 343 &first_reverse); |
340 // We find next and we go back so find coordinates should be the same as | 344 // We find next and we go back so find coordinates should be the same as |
341 // previous ones. | 345 // previous ones. |
342 ASSERT_EQ(first, first_reverse); | 346 ASSERT_EQ(first, first_reverse); |
343 } | 347 } |
344 | 348 |
345 // Verifies that comments and meta data are not searchable. | 349 // Verifies that comments and meta data are not searchable. |
346 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 350 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
347 CommentsAndMetaDataNotSearchable) { | 351 CommentsAndMetaDataNotSearchable) { |
348 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 352 WebContents* web_contents = |
| 353 browser()->tab_strip_model()->GetActiveWebContents(); |
349 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html")); | 354 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html")); |
350 | 355 |
351 std::wstring search_string = | 356 std::wstring search_string = |
352 L"\u4e2d\u65b0\u793e\u8bb0\u8005\u5b8b\u5409\u6cb3\u6444\u4e2d\u65b0\u7f51
"; | 357 L"\u4e2d\u65b0\u793e\u8bb0\u8005\u5b8b\u5409\u6cb3\u6444\u4e2d\u65b0\u7f51
"; |
353 EXPECT_EQ(0, ui_test_utils::FindInPage( | 358 EXPECT_EQ(0, ui_test_utils::FindInPage( |
354 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL)); | 359 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL)); |
355 } | 360 } |
356 | 361 |
357 // Verifies that span and lists are searchable. | 362 // Verifies that span and lists are searchable. |
358 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SpanAndListsSearchable) { | 363 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SpanAndListsSearchable) { |
359 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 364 WebContents* web_contents = |
| 365 browser()->tab_strip_model()->GetActiveWebContents(); |
360 ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html")); | 366 ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html")); |
361 | 367 |
362 std::wstring search_string = L"has light blue eyes and my father has dark"; | 368 std::wstring search_string = L"has light blue eyes and my father has dark"; |
363 EXPECT_EQ(1, ui_test_utils::FindInPage( | 369 EXPECT_EQ(1, ui_test_utils::FindInPage( |
364 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL)); | 370 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL)); |
365 | 371 |
366 search_string = L"Google\nApple\nandroid"; | 372 search_string = L"Google\nApple\nandroid"; |
367 EXPECT_EQ(1, ui_test_utils::FindInPage( | 373 EXPECT_EQ(1, ui_test_utils::FindInPage( |
368 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL)); | 374 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL)); |
369 } | 375 } |
370 | 376 |
371 // Find in a very large page. | 377 // Find in a very large page. |
372 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, LargePage) { | 378 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, LargePage) { |
373 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 379 WebContents* web_contents = |
| 380 browser()->tab_strip_model()->GetActiveWebContents(); |
374 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html")); | 381 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html")); |
375 | 382 |
376 std::wstring search_string = L"daughter of Prince"; | 383 std::wstring search_string = L"daughter of Prince"; |
377 EXPECT_EQ(373, | 384 EXPECT_EQ(373, |
378 FindInPageWchar(web_contents, search_string.c_str(), | 385 FindInPageWchar(web_contents, search_string.c_str(), |
379 kFwd, kIgnoreCase, NULL)); | 386 kFwd, kIgnoreCase, NULL)); |
380 } | 387 } |
381 | 388 |
382 // Find a very long string in a large page. | 389 // Find a very long string in a large page. |
383 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindLongString) { | 390 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindLongString) { |
384 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 391 WebContents* web_contents = |
| 392 browser()->tab_strip_model()->GetActiveWebContents(); |
385 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html")); | 393 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html")); |
386 | 394 |
387 FilePath path = ui_test_utils::GetTestFilePath( | 395 FilePath path = ui_test_utils::GetTestFilePath( |
388 FilePath().AppendASCII("find_in_page"), | 396 FilePath().AppendASCII("find_in_page"), |
389 FilePath().AppendASCII("LongFind.txt")); | 397 FilePath().AppendASCII("LongFind.txt")); |
390 std::string query; | 398 std::string query; |
391 file_util::ReadFileToString(path, &query); | 399 file_util::ReadFileToString(path, &query); |
392 std::wstring search_string = UTF8ToWide(query); | 400 std::wstring search_string = UTF8ToWide(query); |
393 EXPECT_EQ(1, | 401 EXPECT_EQ(1, |
394 FindInPageWchar(web_contents, search_string.c_str(), | 402 FindInPageWchar(web_contents, search_string.c_str(), |
395 kFwd, kIgnoreCase, NULL)); | 403 kFwd, kIgnoreCase, NULL)); |
396 } | 404 } |
397 | 405 |
398 // Find a big font string in a page. | 406 // Find a big font string in a page. |
399 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, BigString) { | 407 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, BigString) { |
400 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 408 WebContents* web_contents = |
| 409 browser()->tab_strip_model()->GetActiveWebContents(); |
401 ui_test_utils::NavigateToURL(browser(), GetURL("BigText.html")); | 410 ui_test_utils::NavigateToURL(browser(), GetURL("BigText.html")); |
402 EXPECT_EQ(1, | 411 EXPECT_EQ(1, |
403 FindInPageWchar(web_contents, L"SomeLargeString", | 412 FindInPageWchar(web_contents, L"SomeLargeString", |
404 kFwd, kIgnoreCase, NULL)); | 413 kFwd, kIgnoreCase, NULL)); |
405 } | 414 } |
406 | 415 |
407 // Search Back and Forward on a single occurrence. | 416 // Search Back and Forward on a single occurrence. |
408 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SingleOccurrence) { | 417 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SingleOccurrence) { |
409 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 418 WebContents* web_contents = |
| 419 browser()->tab_strip_model()->GetActiveWebContents(); |
410 ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html")); | 420 ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html")); |
411 | 421 |
412 gfx::Rect first_rect; | 422 gfx::Rect first_rect; |
413 EXPECT_EQ(1, | 423 EXPECT_EQ(1, |
414 ui_test_utils::FindInPage(web_contents, | 424 ui_test_utils::FindInPage(web_contents, |
415 ASCIIToUTF16("2010 Pro Bowl"), kFwd, | 425 ASCIIToUTF16("2010 Pro Bowl"), kFwd, |
416 kIgnoreCase, NULL, &first_rect)); | 426 kIgnoreCase, NULL, &first_rect)); |
417 | 427 |
418 gfx::Rect second_rect; | 428 gfx::Rect second_rect; |
419 EXPECT_EQ(1, | 429 EXPECT_EQ(1, |
(...skipping 13 matching lines...) Expand all Loading... |
433 kIgnoreCase, NULL, &first_rect)); | 443 kIgnoreCase, NULL, &first_rect)); |
434 EXPECT_EQ(1, | 444 EXPECT_EQ(1, |
435 ui_test_utils::FindInPage(web_contents, | 445 ui_test_utils::FindInPage(web_contents, |
436 ASCIIToUTF16("2010 Pro Bowl"), kBack, | 446 ASCIIToUTF16("2010 Pro Bowl"), kBack, |
437 kIgnoreCase, NULL, &second_rect)); | 447 kIgnoreCase, NULL, &second_rect)); |
438 ASSERT_EQ(first_rect, second_rect); | 448 ASSERT_EQ(first_rect, second_rect); |
439 } | 449 } |
440 | 450 |
441 // Find the whole text file page and find count should be 1. | 451 // Find the whole text file page and find count should be 1. |
442 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindWholeFileContent) { | 452 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindWholeFileContent) { |
443 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 453 WebContents* web_contents = |
| 454 browser()->tab_strip_model()->GetActiveWebContents(); |
444 | 455 |
445 FilePath path = ui_test_utils::GetTestFilePath( | 456 FilePath path = ui_test_utils::GetTestFilePath( |
446 FilePath().AppendASCII("find_in_page"), | 457 FilePath().AppendASCII("find_in_page"), |
447 FilePath().AppendASCII("find_test.txt")); | 458 FilePath().AppendASCII("find_test.txt")); |
448 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(path)); | 459 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(path)); |
449 | 460 |
450 std::string query; | 461 std::string query; |
451 file_util::ReadFileToString(path, &query); | 462 file_util::ReadFileToString(path, &query); |
452 std::wstring search_string = UTF8ToWide(query); | 463 std::wstring search_string = UTF8ToWide(query); |
453 EXPECT_EQ(1, | 464 EXPECT_EQ(1, |
(...skipping 14 matching lines...) Expand all Loading... |
468 } | 479 } |
469 | 480 |
470 // This tests the FindInPage end-state, in other words: what is focused when you | 481 // This tests the FindInPage end-state, in other words: what is focused when you |
471 // close the Find box (ie. if you find within a link the link should be | 482 // close the Find box (ie. if you find within a link the link should be |
472 // focused). | 483 // focused). |
473 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { | 484 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { |
474 // First we navigate to our special focus tracking page. | 485 // First we navigate to our special focus tracking page. |
475 GURL url = GetURL(kEndState); | 486 GURL url = GetURL(kEndState); |
476 ui_test_utils::NavigateToURL(browser(), url); | 487 ui_test_utils::NavigateToURL(browser(), url); |
477 | 488 |
478 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 489 WebContents* web_contents = |
| 490 browser()->tab_strip_model()->GetActiveWebContents(); |
479 ASSERT_TRUE(NULL != web_contents); | 491 ASSERT_TRUE(NULL != web_contents); |
480 FindTabHelper* find_tab_helper = | 492 FindTabHelper* find_tab_helper = |
481 FindTabHelper::FromWebContents(web_contents); | 493 FindTabHelper::FromWebContents(web_contents); |
482 | 494 |
483 // Verify that nothing has focus. | 495 // Verify that nothing has focus. |
484 std::string result; | 496 std::string result; |
485 ASSERT_TRUE(FocusedOnPage(web_contents, &result)); | 497 ASSERT_TRUE(FocusedOnPage(web_contents, &result)); |
486 ASSERT_STREQ("{nothing focused}", result.c_str()); | 498 ASSERT_STREQ("{nothing focused}", result.c_str()); |
487 | 499 |
488 // Search for a text that exists within a link on the page. | 500 // Search for a text that exists within a link on the page. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 | 532 |
521 // This test loads a single-frame page and makes sure the ordinal returned makes | 533 // This test loads a single-frame page and makes sure the ordinal returned makes |
522 // sense as we FindNext over all the items. | 534 // sense as we FindNext over all the items. |
523 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { | 535 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { |
524 // First we navigate to our page. | 536 // First we navigate to our page. |
525 GURL url = GetURL(kFrameData); | 537 GURL url = GetURL(kFrameData); |
526 ui_test_utils::NavigateToURL(browser(), url); | 538 ui_test_utils::NavigateToURL(browser(), url); |
527 | 539 |
528 // Search for 'o', which should make the first item active and return | 540 // Search for 'o', which should make the first item active and return |
529 // '1 in 3' (1st ordinal of a total of 3 matches). | 541 // '1 in 3' (1st ordinal of a total of 3 matches). |
530 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 542 WebContents* web_contents = |
| 543 browser()->tab_strip_model()->GetActiveWebContents(); |
531 int ordinal = 0; | 544 int ordinal = 0; |
532 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o", | 545 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o", |
533 kFwd, kIgnoreCase, &ordinal)); | 546 kFwd, kIgnoreCase, &ordinal)); |
534 EXPECT_EQ(1, ordinal); | 547 EXPECT_EQ(1, ordinal); |
535 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o", | 548 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o", |
536 kFwd, kIgnoreCase, &ordinal)); | 549 kFwd, kIgnoreCase, &ordinal)); |
537 EXPECT_EQ(2, ordinal); | 550 EXPECT_EQ(2, ordinal); |
538 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o", | 551 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o", |
539 kFwd, kIgnoreCase, &ordinal)); | 552 kFwd, kIgnoreCase, &ordinal)); |
540 EXPECT_EQ(3, ordinal); | 553 EXPECT_EQ(3, ordinal); |
(...skipping 15 matching lines...) Expand all Loading... |
556 } | 569 } |
557 | 570 |
558 // This tests that the ordinal is correctly adjusted after a selection | 571 // This tests that the ordinal is correctly adjusted after a selection |
559 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 572 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
560 SelectChangesOrdinal_Issue20883) { | 573 SelectChangesOrdinal_Issue20883) { |
561 // First we navigate to our test content. | 574 // First we navigate to our test content. |
562 GURL url = GetURL(kSelectChangesOrdinal); | 575 GURL url = GetURL(kSelectChangesOrdinal); |
563 ui_test_utils::NavigateToURL(browser(), url); | 576 ui_test_utils::NavigateToURL(browser(), url); |
564 | 577 |
565 // Search for a text that exists within a link on the page. | 578 // Search for a text that exists within a link on the page. |
566 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 579 WebContents* web_contents = |
| 580 browser()->tab_strip_model()->GetActiveWebContents(); |
567 ASSERT_TRUE(NULL != web_contents); | 581 ASSERT_TRUE(NULL != web_contents); |
568 FindTabHelper* find_tab_helper = | 582 FindTabHelper* find_tab_helper = |
569 FindTabHelper::FromWebContents(web_contents); | 583 FindTabHelper::FromWebContents(web_contents); |
570 | 584 |
571 int ordinal = 0; | 585 int ordinal = 0; |
572 EXPECT_EQ(4, FindInPageWchar(web_contents, | 586 EXPECT_EQ(4, FindInPageWchar(web_contents, |
573 L"google", | 587 L"google", |
574 kFwd, kIgnoreCase, &ordinal)); | 588 kFwd, kIgnoreCase, &ordinal)); |
575 EXPECT_EQ(1, ordinal); | 589 EXPECT_EQ(1, ordinal); |
576 | 590 |
(...skipping 15 matching lines...) Expand all Loading... |
592 // End the find session. | 606 // End the find session. |
593 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage); | 607 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage); |
594 } | 608 } |
595 | 609 |
596 // This tests that we start searching after selected text. | 610 // This tests that we start searching after selected text. |
597 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 611 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
598 StartSearchAfterSelection) { | 612 StartSearchAfterSelection) { |
599 // First we navigate to our test content. | 613 // First we navigate to our test content. |
600 ui_test_utils::NavigateToURL(browser(), GetURL(kStartAfterSelection)); | 614 ui_test_utils::NavigateToURL(browser(), GetURL(kStartAfterSelection)); |
601 | 615 |
602 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 616 WebContents* web_contents = |
| 617 browser()->tab_strip_model()->GetActiveWebContents(); |
603 ASSERT_TRUE(web_contents != NULL); | 618 ASSERT_TRUE(web_contents != NULL); |
604 int ordinal = 0; | 619 int ordinal = 0; |
605 | 620 |
606 // Move the selection to the text span. | 621 // Move the selection to the text span. |
607 std::string result; | 622 std::string result; |
608 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 623 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
609 web_contents->GetRenderViewHost(), | 624 web_contents->GetRenderViewHost(), |
610 std::wstring(), | 625 std::wstring(), |
611 L"window.domAutomationController.send(selectSpan());", | 626 L"window.domAutomationController.send(selectSpan());", |
612 &result)); | 627 &result)); |
(...skipping 22 matching lines...) Expand all Loading... |
635 | 650 |
636 // This test loads a page with frames and makes sure the ordinal returned makes | 651 // This test loads a page with frames and makes sure the ordinal returned makes |
637 // sense. | 652 // sense. |
638 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { | 653 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { |
639 // First we navigate to our page. | 654 // First we navigate to our page. |
640 GURL url = GetURL(kFramePage); | 655 GURL url = GetURL(kFramePage); |
641 ui_test_utils::NavigateToURL(browser(), url); | 656 ui_test_utils::NavigateToURL(browser(), url); |
642 | 657 |
643 // Search for 'a', which should make the first item active and return | 658 // Search for 'a', which should make the first item active and return |
644 // '1 in 7' (1st ordinal of a total of 7 matches). | 659 // '1 in 7' (1st ordinal of a total of 7 matches). |
645 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 660 WebContents* web_contents = |
| 661 browser()->tab_strip_model()->GetActiveWebContents(); |
646 int ordinal = 0; | 662 int ordinal = 0; |
647 EXPECT_EQ(7, | 663 EXPECT_EQ(7, |
648 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal)); | 664 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal)); |
649 EXPECT_EQ(1, ordinal); | 665 EXPECT_EQ(1, ordinal); |
650 EXPECT_EQ(7, | 666 EXPECT_EQ(7, |
651 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal)); | 667 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal)); |
652 EXPECT_EQ(2, ordinal); | 668 EXPECT_EQ(2, ordinal); |
653 EXPECT_EQ(7, | 669 EXPECT_EQ(7, |
654 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal)); | 670 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal)); |
655 EXPECT_EQ(3, ordinal); | 671 EXPECT_EQ(3, ordinal); |
(...skipping 28 matching lines...) Expand all Loading... |
684 | 700 |
685 // We could get ordinals out of whack when restarting search in subframes. | 701 // We could get ordinals out of whack when restarting search in subframes. |
686 // See http://crbug.com/5132. | 702 // See http://crbug.com/5132. |
687 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { | 703 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { |
688 // First we navigate to our page. | 704 // First we navigate to our page. |
689 GURL url = GetURL(kFramePage); | 705 GURL url = GetURL(kFramePage); |
690 ui_test_utils::NavigateToURL(browser(), url); | 706 ui_test_utils::NavigateToURL(browser(), url); |
691 | 707 |
692 // Search for 'goa' three times (6 matches on page). | 708 // Search for 'goa' three times (6 matches on page). |
693 int ordinal = 0; | 709 int ordinal = 0; |
694 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 710 WebContents* web_contents = |
| 711 browser()->tab_strip_model()->GetActiveWebContents(); |
695 EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa", | 712 EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa", |
696 kFwd, kIgnoreCase, &ordinal)); | 713 kFwd, kIgnoreCase, &ordinal)); |
697 EXPECT_EQ(1, ordinal); | 714 EXPECT_EQ(1, ordinal); |
698 EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa", | 715 EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa", |
699 kFwd, kIgnoreCase, &ordinal)); | 716 kFwd, kIgnoreCase, &ordinal)); |
700 EXPECT_EQ(2, ordinal); | 717 EXPECT_EQ(2, ordinal); |
701 EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa", | 718 EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa", |
702 kFwd, kIgnoreCase, &ordinal)); | 719 kFwd, kIgnoreCase, &ordinal)); |
703 EXPECT_EQ(3, ordinal); | 720 EXPECT_EQ(3, ordinal); |
704 // Add space to search (should result in no matches). | 721 // Add space to search (should result in no matches). |
(...skipping 21 matching lines...) Expand all Loading... |
726 GURL url = GetURL(kSimple); | 743 GURL url = GetURL(kSimple); |
727 ui_test_utils::NavigateToURL(browser(), url); | 744 ui_test_utils::NavigateToURL(browser(), url); |
728 | 745 |
729 // Open the Find box. In most tests we can just search without opening the | 746 // Open the Find box. In most tests we can just search without opening the |
730 // box first, but in this case we are testing functionality triggered by | 747 // box first, but in this case we are testing functionality triggered by |
731 // NOTIFICATION_NAV_ENTRY_COMMITTED in the FindBarController and the observer | 748 // NOTIFICATION_NAV_ENTRY_COMMITTED in the FindBarController and the observer |
732 // for that event isn't setup unless the box is open. | 749 // for that event isn't setup unless the box is open. |
733 EnsureFindBoxOpen(); | 750 EnsureFindBoxOpen(); |
734 | 751 |
735 // Search for a text that exists within a link on the page. | 752 // Search for a text that exists within a link on the page. |
736 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 753 WebContents* web_contents = |
| 754 browser()->tab_strip_model()->GetActiveWebContents(); |
737 ASSERT_TRUE(NULL != web_contents); | 755 ASSERT_TRUE(NULL != web_contents); |
738 int ordinal = 0; | 756 int ordinal = 0; |
739 EXPECT_EQ(8, FindInPageWchar(web_contents, | 757 EXPECT_EQ(8, FindInPageWchar(web_contents, |
740 L"e", | 758 L"e", |
741 kFwd, kIgnoreCase, &ordinal)); | 759 kFwd, kIgnoreCase, &ordinal)); |
742 EXPECT_EQ(1, ordinal); | 760 EXPECT_EQ(1, ordinal); |
743 | 761 |
744 // Then navigate away (to any page). | 762 // Then navigate away (to any page). |
745 url = GetURL(kLinkPage); | 763 url = GetURL(kLinkPage); |
746 ui_test_utils::NavigateToURL(browser(), url); | 764 ui_test_utils::NavigateToURL(browser(), url); |
747 | 765 |
748 // Open the Find box again. | 766 // Open the Find box again. |
749 EnsureFindBoxOpen(); | 767 EnsureFindBoxOpen(); |
750 | 768 |
751 EXPECT_EQ(ASCIIToUTF16("e"), GetFindBarText()); | 769 EXPECT_EQ(ASCIIToUTF16("e"), GetFindBarText()); |
752 EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText()); | 770 EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText()); |
753 } | 771 } |
754 | 772 |
755 // Load a page with no selectable text and make sure we don't crash. | 773 // Load a page with no selectable text and make sure we don't crash. |
756 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnselectableText) { | 774 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnselectableText) { |
757 // First we navigate to our page. | 775 // First we navigate to our page. |
758 GURL url = GetURL(kUserSelectPage); | 776 GURL url = GetURL(kUserSelectPage); |
759 ui_test_utils::NavigateToURL(browser(), url); | 777 ui_test_utils::NavigateToURL(browser(), url); |
760 | 778 |
761 int ordinal = 0; | 779 int ordinal = 0; |
762 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 780 WebContents* web_contents = |
| 781 browser()->tab_strip_model()->GetActiveWebContents(); |
763 EXPECT_EQ(1, FindInPageWchar(web_contents, | 782 EXPECT_EQ(1, FindInPageWchar(web_contents, |
764 L"text", | 783 L"text", |
765 kFwd, kIgnoreCase, &ordinal)); | 784 kFwd, kIgnoreCase, &ordinal)); |
766 EXPECT_EQ(1, ordinal); | 785 EXPECT_EQ(1, ordinal); |
767 } | 786 } |
768 | 787 |
769 // Try to reproduce the crash seen in issue 1341577. | 788 // Try to reproduce the crash seen in issue 1341577. |
770 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { | 789 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { |
771 // First we navigate to our page. | 790 // First we navigate to our page. |
772 GURL url = GetURL(kCrashPage); | 791 GURL url = GetURL(kCrashPage); |
773 ui_test_utils::NavigateToURL(browser(), url); | 792 ui_test_utils::NavigateToURL(browser(), url); |
774 | 793 |
775 // This would crash the tab. These must be the first two find requests issued | 794 // This would crash the tab. These must be the first two find requests issued |
776 // against the frame, otherwise an active frame pointer is set and it wont | 795 // against the frame, otherwise an active frame pointer is set and it wont |
777 // produce the crash. | 796 // produce the crash. |
778 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does | 797 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does |
779 // not find a stand-alone dependent vowel sign of Indic scripts. So, the | 798 // not find a stand-alone dependent vowel sign of Indic scripts. So, the |
780 // exptected values are all 0. To make this test pass regardless of | 799 // exptected values are all 0. To make this test pass regardless of |
781 // ICU version, we just call FiP and see if there's any crash. | 800 // ICU version, we just call FiP and see if there's any crash. |
782 // TODO(jungshik): According to a native Malayalam speaker, it's ok not | 801 // TODO(jungshik): According to a native Malayalam speaker, it's ok not |
783 // to find U+0D4C. Still need to investigate further this issue. | 802 // to find U+0D4C. Still need to investigate further this issue. |
784 int ordinal = 0; | 803 int ordinal = 0; |
785 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 804 WebContents* web_contents = |
| 805 browser()->tab_strip_model()->GetActiveWebContents(); |
786 FindInPageWchar(web_contents, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); | 806 FindInPageWchar(web_contents, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); |
787 FindInPageWchar(web_contents, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); | 807 FindInPageWchar(web_contents, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); |
788 | 808 |
789 // This should work fine. | 809 // This should work fine. |
790 EXPECT_EQ(1, FindInPageWchar(web_contents, L"\u0D24\u0D46", | 810 EXPECT_EQ(1, FindInPageWchar(web_contents, L"\u0D24\u0D46", |
791 kFwd, kIgnoreCase, &ordinal)); | 811 kFwd, kIgnoreCase, &ordinal)); |
792 EXPECT_EQ(1, ordinal); | 812 EXPECT_EQ(1, ordinal); |
793 EXPECT_EQ(0, FindInPageWchar(web_contents, L"nostring", | 813 EXPECT_EQ(0, FindInPageWchar(web_contents, L"nostring", |
794 kFwd, kIgnoreCase, &ordinal)); | 814 kFwd, kIgnoreCase, &ordinal)); |
795 EXPECT_EQ(0, ordinal); | 815 EXPECT_EQ(0, ordinal); |
796 } | 816 } |
797 | 817 |
798 // Try to reproduce the crash seen in http://crbug.com/14491, where an assert | 818 // Try to reproduce the crash seen in http://crbug.com/14491, where an assert |
799 // hits in the BitStack size comparison in WebKit. | 819 // hits in the BitStack size comparison in WebKit. |
800 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { | 820 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { |
801 // First we navigate to our page. | 821 // First we navigate to our page. |
802 GURL url = GetURL(kBitstackCrash); | 822 GURL url = GetURL(kBitstackCrash); |
803 ui_test_utils::NavigateToURL(browser(), url); | 823 ui_test_utils::NavigateToURL(browser(), url); |
804 | 824 |
805 // This used to crash the tab. | 825 // This used to crash the tab. |
806 int ordinal = 0; | 826 int ordinal = 0; |
807 EXPECT_EQ(0, FindInPageWchar(chrome::GetActiveWebContents(browser()), | 827 EXPECT_EQ(0, FindInPageWchar(browser()->tab_strip_model()-> |
| 828 GetActiveWebContents(), |
808 L"s", kFwd, kIgnoreCase, &ordinal)); | 829 L"s", kFwd, kIgnoreCase, &ordinal)); |
809 EXPECT_EQ(0, ordinal); | 830 EXPECT_EQ(0, ordinal); |
810 } | 831 } |
811 | 832 |
812 // Test to make sure Find does the right thing when restarting from a timeout. | 833 // Test to make sure Find does the right thing when restarting from a timeout. |
813 // We used to have a problem where we'd stop finding matches when all of the | 834 // We used to have a problem where we'd stop finding matches when all of the |
814 // following conditions were true: | 835 // following conditions were true: |
815 // 1) The page has a lot of text to search. | 836 // 1) The page has a lot of text to search. |
816 // 2) The page contains more than one match. | 837 // 2) The page contains more than one match. |
817 // 3) It takes longer than the time-slice given to each Find operation (100 | 838 // 3) It takes longer than the time-slice given to each Find operation (100 |
818 // ms) to find one or more of those matches (so Find times out and has to try | 839 // ms) to find one or more of those matches (so Find times out and has to try |
819 // again from where it left off). | 840 // again from where it left off). |
820 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { | 841 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { |
821 // First we navigate to our page. | 842 // First we navigate to our page. |
822 GURL url = GetURL(kTooFewMatchesPage); | 843 GURL url = GetURL(kTooFewMatchesPage); |
823 ui_test_utils::NavigateToURL(browser(), url); | 844 ui_test_utils::NavigateToURL(browser(), url); |
824 | 845 |
825 // This string appears 5 times at the bottom of a long page. If Find restarts | 846 // This string appears 5 times at the bottom of a long page. If Find restarts |
826 // properly after a timeout, it will find 5 matches, not just 1. | 847 // properly after a timeout, it will find 5 matches, not just 1. |
827 int ordinal = 0; | 848 int ordinal = 0; |
828 EXPECT_EQ(5, FindInPageWchar(chrome::GetActiveWebContents(browser()), | 849 EXPECT_EQ(5, FindInPageWchar(browser()->tab_strip_model()-> |
| 850 GetActiveWebContents(), |
829 L"008.xml", | 851 L"008.xml", |
830 kFwd, kIgnoreCase, &ordinal)); | 852 kFwd, kIgnoreCase, &ordinal)); |
831 EXPECT_EQ(1, ordinal); | 853 EXPECT_EQ(1, ordinal); |
832 } | 854 } |
833 | 855 |
834 // Make sure we don't get into an infinite loop when text box contains very | 856 // Make sure we don't get into an infinite loop when text box contains very |
835 // large amount of text. | 857 // large amount of text. |
836 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue70505) { | 858 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue70505) { |
837 // First we navigate to our page. | 859 // First we navigate to our page. |
838 GURL url = GetURL(kLongTextareaPage); | 860 GURL url = GetURL(kLongTextareaPage); |
839 ui_test_utils::NavigateToURL(browser(), url); | 861 ui_test_utils::NavigateToURL(browser(), url); |
840 | 862 |
841 // If this test hangs on the FindInPage call, then it might be a regression | 863 // If this test hangs on the FindInPage call, then it might be a regression |
842 // such as the one found in issue http://crbug.com/70505. | 864 // such as the one found in issue http://crbug.com/70505. |
843 int ordinal = 0; | 865 int ordinal = 0; |
844 FindInPageWchar(chrome::GetActiveWebContents(browser()), | 866 FindInPageWchar(browser()->tab_strip_model()->GetActiveWebContents(), |
845 L"a", kFwd, kIgnoreCase, &ordinal); | 867 L"a", kFwd, kIgnoreCase, &ordinal); |
846 EXPECT_EQ(1, ordinal); | 868 EXPECT_EQ(1, ordinal); |
847 // TODO(finnur): We cannot reliably get the matchcount for this Find call | 869 // TODO(finnur): We cannot reliably get the matchcount for this Find call |
848 // until we fix issue http://crbug.com/71176. | 870 // until we fix issue http://crbug.com/71176. |
849 } | 871 } |
850 | 872 |
851 // This tests bug 11761: FindInPage terminates search prematurely. | 873 // This tests bug 11761: FindInPage terminates search prematurely. |
852 // This test is not expected to pass until bug 11761 is fixed. | 874 // This test is not expected to pass until bug 11761 is fixed. |
853 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 875 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
854 DISABLED_FindInPagePrematureEnd) { | 876 DISABLED_FindInPagePrematureEnd) { |
855 // First we navigate to our special focus tracking page. | 877 // First we navigate to our special focus tracking page. |
856 GURL url = GetURL(kPrematureEnd); | 878 GURL url = GetURL(kPrematureEnd); |
857 ui_test_utils::NavigateToURL(browser(), url); | 879 ui_test_utils::NavigateToURL(browser(), url); |
858 | 880 |
859 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 881 WebContents* web_contents = |
| 882 browser()->tab_strip_model()->GetActiveWebContents(); |
860 ASSERT_TRUE(NULL != web_contents); | 883 ASSERT_TRUE(NULL != web_contents); |
861 | 884 |
862 // Search for a text that exists within a link on the page. | 885 // Search for a text that exists within a link on the page. |
863 int ordinal = 0; | 886 int ordinal = 0; |
864 EXPECT_EQ(2, FindInPageWchar(web_contents, L"html ", | 887 EXPECT_EQ(2, FindInPageWchar(web_contents, L"html ", |
865 kFwd, kIgnoreCase, &ordinal)); | 888 kFwd, kIgnoreCase, &ordinal)); |
866 EXPECT_EQ(1, ordinal); | 889 EXPECT_EQ(1, ordinal); |
867 } | 890 } |
868 | 891 |
869 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { | 892 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { |
870 // First we navigate to our special focus tracking page. | 893 // First we navigate to our special focus tracking page. |
871 GURL url = GetURL(kSimple); | 894 GURL url = GetURL(kSimple); |
872 GURL url2 = GetURL(kFramePage); | 895 GURL url2 = GetURL(kFramePage); |
873 ui_test_utils::NavigateToURL(browser(), url); | 896 ui_test_utils::NavigateToURL(browser(), url); |
874 | 897 |
875 chrome::ShowFindBar(browser()); | 898 chrome::ShowFindBar(browser()); |
876 | 899 |
877 gfx::Point position; | 900 gfx::Point position; |
878 bool fully_visible = false; | 901 bool fully_visible = false; |
879 | 902 |
880 // Make sure it is open. | 903 // Make sure it is open. |
881 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | 904 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
882 EXPECT_TRUE(fully_visible); | 905 EXPECT_TRUE(fully_visible); |
883 | 906 |
884 // Reload the tab and make sure Find window doesn't go away. | 907 // Reload the tab and make sure Find window doesn't go away. |
885 content::WindowedNotificationObserver observer( | 908 content::WindowedNotificationObserver observer( |
886 content::NOTIFICATION_LOAD_STOP, | 909 content::NOTIFICATION_LOAD_STOP, |
887 content::Source<NavigationController>( | 910 content::Source<NavigationController>( |
888 &chrome::GetActiveWebContents(browser())->GetController())); | 911 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 912 GetController())); |
889 chrome::Reload(browser(), CURRENT_TAB); | 913 chrome::Reload(browser(), CURRENT_TAB); |
890 observer.Wait(); | 914 observer.Wait(); |
891 | 915 |
892 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | 916 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
893 EXPECT_TRUE(fully_visible); | 917 EXPECT_TRUE(fully_visible); |
894 | 918 |
895 // Navigate and make sure the Find window goes away. | 919 // Navigate and make sure the Find window goes away. |
896 ui_test_utils::NavigateToURL(browser(), url2); | 920 ui_test_utils::NavigateToURL(browser(), url2); |
897 | 921 |
898 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | 922 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 | 1004 |
981 gfx::Point start_position; | 1005 gfx::Point start_position; |
982 gfx::Point position; | 1006 gfx::Point position; |
983 bool fully_visible = false; | 1007 bool fully_visible = false; |
984 int ordinal = 0; | 1008 int ordinal = 0; |
985 | 1009 |
986 // Make sure it is open. | 1010 // Make sure it is open. |
987 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible)); | 1011 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible)); |
988 EXPECT_TRUE(fully_visible); | 1012 EXPECT_TRUE(fully_visible); |
989 | 1013 |
990 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1014 WebContents* web_contents = |
| 1015 browser()->tab_strip_model()->GetActiveWebContents(); |
991 | 1016 |
992 int moved_x_coord = FindInPageTillBoxMoves(web_contents, start_position.x(), | 1017 int moved_x_coord = FindInPageTillBoxMoves(web_contents, start_position.x(), |
993 L"Chromium", kMoveIterations); | 1018 L"Chromium", kMoveIterations); |
994 // The find box should have moved. | 1019 // The find box should have moved. |
995 EXPECT_TRUE(moved_x_coord != start_position.x()); | 1020 EXPECT_TRUE(moved_x_coord != start_position.x()); |
996 | 1021 |
997 // Search for something guaranteed not to be obscured by the Find box. | 1022 // Search for something guaranteed not to be obscured by the Find box. |
998 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Done", | 1023 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Done", |
999 kFwd, kIgnoreCase, &ordinal)); | 1024 kFwd, kIgnoreCase, &ordinal)); |
1000 // Check the position. | 1025 // Check the position. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 | 1062 |
1038 // Make sure F3 in a new tab works if Find has previous string to search for. | 1063 // Make sure F3 in a new tab works if Find has previous string to search for. |
1039 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 1064 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
1040 MAYBE_FindNextInNewTabUsesPrepopulate) { | 1065 MAYBE_FindNextInNewTabUsesPrepopulate) { |
1041 // First we navigate to any page. | 1066 // First we navigate to any page. |
1042 GURL url = GetURL(kSimple); | 1067 GURL url = GetURL(kSimple); |
1043 ui_test_utils::NavigateToURL(browser(), url); | 1068 ui_test_utils::NavigateToURL(browser(), url); |
1044 | 1069 |
1045 // Search for 'no_match'. No matches should be found. | 1070 // Search for 'no_match'. No matches should be found. |
1046 int ordinal = 0; | 1071 int ordinal = 0; |
1047 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1072 WebContents* web_contents = |
| 1073 browser()->tab_strip_model()->GetActiveWebContents(); |
1048 EXPECT_EQ(0, FindInPageWchar(web_contents, L"no_match", | 1074 EXPECT_EQ(0, FindInPageWchar(web_contents, L"no_match", |
1049 kFwd, kIgnoreCase, &ordinal)); | 1075 kFwd, kIgnoreCase, &ordinal)); |
1050 EXPECT_EQ(0, ordinal); | 1076 EXPECT_EQ(0, ordinal); |
1051 | 1077 |
1052 // Open another tab (tab B). | 1078 // Open another tab (tab B). |
1053 chrome::NewTab(browser()); | 1079 chrome::NewTab(browser()); |
1054 ui_test_utils::NavigateToURL(browser(), url); | 1080 ui_test_utils::NavigateToURL(browser(), url); |
1055 | 1081 |
1056 // Simulate what happens when you press F3 for FindNext. We should get a | 1082 // Simulate what happens when you press F3 for FindNext. We should get a |
1057 // response here (a hang means search was aborted). | 1083 // response here (a hang means search was aborted). |
(...skipping 18 matching lines...) Expand all Loading... |
1076 // First we navigate to any page. | 1102 // First we navigate to any page. |
1077 GURL url = GetURL(kSimple); | 1103 GURL url = GetURL(kSimple); |
1078 ui_test_utils::NavigateToURL(browser(), url); | 1104 ui_test_utils::NavigateToURL(browser(), url); |
1079 | 1105 |
1080 chrome::ShowFindBar(browser()); | 1106 chrome::ShowFindBar(browser()); |
1081 | 1107 |
1082 // Simulate a user clearing the search string. Ideally, we should be | 1108 // Simulate a user clearing the search string. Ideally, we should be |
1083 // simulating keypresses here for searching for something and pressing | 1109 // simulating keypresses here for searching for something and pressing |
1084 // backspace, but that's been proven flaky in the past, so we go straight to | 1110 // backspace, but that's been proven flaky in the past, so we go straight to |
1085 // tab_contents. | 1111 // tab_contents. |
1086 FindTabHelper* find_tab_helper = | 1112 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents( |
1087 FindTabHelper::FromWebContents(chrome::GetActiveWebContents(browser())); | 1113 browser()->tab_strip_model()->GetActiveWebContents()); |
1088 // Stop the (non-existing) find operation, and clear the selection (which | 1114 // Stop the (non-existing) find operation, and clear the selection (which |
1089 // signals the UI is still active). | 1115 // signals the UI is still active). |
1090 find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage); | 1116 find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage); |
1091 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI | 1117 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI |
1092 // still responds to browser window resizing. | 1118 // still responds to browser window resizing. |
1093 ASSERT_TRUE(find_tab_helper->find_ui_active()); | 1119 ASSERT_TRUE(find_tab_helper->find_ui_active()); |
1094 } | 1120 } |
1095 | 1121 |
1096 // Make sure F3 works after you FindNext a couple of times and end the Find | 1122 // Make sure F3 works after you FindNext a couple of times and end the Find |
1097 // session. See issue http://crbug.com/28306. | 1123 // session. See issue http://crbug.com/28306. |
1098 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { | 1124 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { |
1099 // First we navigate to a simple page. | 1125 // First we navigate to a simple page. |
1100 GURL url = GetURL(kSimple); | 1126 GURL url = GetURL(kSimple); |
1101 ui_test_utils::NavigateToURL(browser(), url); | 1127 ui_test_utils::NavigateToURL(browser(), url); |
1102 | 1128 |
1103 // Search for 'page'. Should have 1 match. | 1129 // Search for 'page'. Should have 1 match. |
1104 int ordinal = 0; | 1130 int ordinal = 0; |
1105 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1131 WebContents* web_contents = |
| 1132 browser()->tab_strip_model()->GetActiveWebContents(); |
1106 EXPECT_EQ(1, FindInPageWchar(web_contents, L"page", | 1133 EXPECT_EQ(1, FindInPageWchar(web_contents, L"page", |
1107 kFwd, kIgnoreCase, &ordinal)); | 1134 kFwd, kIgnoreCase, &ordinal)); |
1108 EXPECT_EQ(1, ordinal); | 1135 EXPECT_EQ(1, ordinal); |
1109 | 1136 |
1110 // Simulate what happens when you press F3 for FindNext. Still should show | 1137 // Simulate what happens when you press F3 for FindNext. Still should show |
1111 // one match. This cleared the pre-populate string at one point (see bug). | 1138 // one match. This cleared the pre-populate string at one point (see bug). |
1112 EXPECT_EQ(1, ui_test_utils::FindInPage(web_contents, string16(), | 1139 EXPECT_EQ(1, ui_test_utils::FindInPage(web_contents, string16(), |
1113 kFwd, kIgnoreCase, &ordinal, NULL)); | 1140 kFwd, kIgnoreCase, &ordinal, NULL)); |
1114 EXPECT_EQ(1, ordinal); | 1141 EXPECT_EQ(1, ordinal); |
1115 | 1142 |
(...skipping 10 matching lines...) Expand all Loading... |
1126 // When re-opening the find bar with F3, the find bar should be re-populated | 1153 // When re-opening the find bar with F3, the find bar should be re-populated |
1127 // with the last search from the same tab rather than the last overall search. | 1154 // with the last search from the same tab rather than the last overall search. |
1128 // http://crbug.com/30006 | 1155 // http://crbug.com/30006 |
1129 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { | 1156 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { |
1130 // First we navigate to any page. | 1157 // First we navigate to any page. |
1131 GURL url = GetURL(kSimple); | 1158 GURL url = GetURL(kSimple); |
1132 ui_test_utils::NavigateToURL(browser(), url); | 1159 ui_test_utils::NavigateToURL(browser(), url); |
1133 | 1160 |
1134 // Find "Default". | 1161 // Find "Default". |
1135 int ordinal = 0; | 1162 int ordinal = 0; |
1136 WebContents* web_contents_1 = chrome::GetActiveWebContents(browser()); | 1163 WebContents* web_contents_1 = |
| 1164 browser()->tab_strip_model()->GetActiveWebContents(); |
1137 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"text", | 1165 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"text", |
1138 kFwd, kIgnoreCase, &ordinal)); | 1166 kFwd, kIgnoreCase, &ordinal)); |
1139 | 1167 |
1140 // Create a second tab. | 1168 // Create a second tab. |
1141 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It | 1169 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It |
1142 // could be some delicate assumption about the tab starting off unselected or | 1170 // could be some delicate assumption about the tab starting off unselected or |
1143 // something relating to user gesture. | 1171 // something relating to user gesture. |
1144 chrome::AddBlankTabAt(browser(), -1, true); | 1172 chrome::AddBlankTabAt(browser(), -1, true); |
1145 ui_test_utils::NavigateToURL(browser(), url); | 1173 ui_test_utils::NavigateToURL(browser(), url); |
1146 WebContents* web_contents_2 = chrome::GetActiveWebContents(browser()); | 1174 WebContents* web_contents_2 = |
| 1175 browser()->tab_strip_model()->GetActiveWebContents(); |
1147 EXPECT_NE(web_contents_1, web_contents_2); | 1176 EXPECT_NE(web_contents_1, web_contents_2); |
1148 | 1177 |
1149 // Find "given". | 1178 // Find "given". |
1150 FindInPageWchar(web_contents_2, L"given", kFwd, kIgnoreCase, &ordinal); | 1179 FindInPageWchar(web_contents_2, L"given", kFwd, kIgnoreCase, &ordinal); |
1151 | 1180 |
1152 // Switch back to first tab. | 1181 // Switch back to first tab. |
1153 chrome::ActivateTabAt(browser(), 0, false); | 1182 browser()->tab_strip_model()->ActivateTabAt(0, false); |
1154 browser()->GetFindBarController()->EndFindSession( | 1183 browser()->GetFindBarController()->EndFindSession( |
1155 FindBarController::kKeepSelectionOnPage, | 1184 FindBarController::kKeepSelectionOnPage, |
1156 FindBarController::kKeepResultsInFindBox); | 1185 FindBarController::kKeepResultsInFindBox); |
1157 // Simulate F3. | 1186 // Simulate F3. |
1158 ui_test_utils::FindInPage(web_contents_1, string16(), | 1187 ui_test_utils::FindInPage(web_contents_1, string16(), |
1159 kFwd, kIgnoreCase, &ordinal, NULL); | 1188 kFwd, kIgnoreCase, &ordinal, NULL); |
1160 EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1)->find_text(), | 1189 EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1)->find_text(), |
1161 WideToUTF16(L"text")); | 1190 WideToUTF16(L"text")); |
1162 } | 1191 } |
1163 | 1192 |
1164 // This tests that whenever you close and reopen the Find bar, it should show | 1193 // This tests that whenever you close and reopen the Find bar, it should show |
1165 // the last search entered in that tab. http://crbug.com/40121. | 1194 // the last search entered in that tab. http://crbug.com/40121. |
1166 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) { | 1195 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) { |
1167 #if defined(OS_MACOSX) | 1196 #if defined(OS_MACOSX) |
1168 // FindInPage on Mac doesn't use prepopulated values. Search there is global. | 1197 // FindInPage on Mac doesn't use prepopulated values. Search there is global. |
1169 return; | 1198 return; |
1170 #endif | 1199 #endif |
1171 | 1200 |
1172 // First we navigate to any page. | 1201 // First we navigate to any page. |
1173 GURL url = GetURL(kSimple); | 1202 GURL url = GetURL(kSimple); |
1174 ui_test_utils::NavigateToURL(browser(), url); | 1203 ui_test_utils::NavigateToURL(browser(), url); |
1175 | 1204 |
1176 // Search for the word "page". | 1205 // Search for the word "page". |
1177 int ordinal = 0; | 1206 int ordinal = 0; |
1178 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1207 WebContents* web_contents = |
| 1208 browser()->tab_strip_model()->GetActiveWebContents(); |
1179 EXPECT_EQ(1, FindInPageWchar(web_contents, L"page", | 1209 EXPECT_EQ(1, FindInPageWchar(web_contents, L"page", |
1180 kFwd, kIgnoreCase, &ordinal)); | 1210 kFwd, kIgnoreCase, &ordinal)); |
1181 | 1211 |
1182 // Open the Find box. | 1212 // Open the Find box. |
1183 EnsureFindBoxOpen(); | 1213 EnsureFindBoxOpen(); |
1184 | 1214 |
1185 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); | 1215 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); |
1186 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); | 1216 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); |
1187 | 1217 |
1188 // Close the Find box. | 1218 // Close the Find box. |
(...skipping 18 matching lines...) Expand all Loading... |
1207 // FindInPage on Mac doesn't use prepopulated values. Search there is global. | 1237 // FindInPage on Mac doesn't use prepopulated values. Search there is global. |
1208 return; | 1238 return; |
1209 #endif | 1239 #endif |
1210 | 1240 |
1211 // First we navigate to any page. | 1241 // First we navigate to any page. |
1212 GURL url = GetURL(kSimple); | 1242 GURL url = GetURL(kSimple); |
1213 ui_test_utils::NavigateToURL(browser(), url); | 1243 ui_test_utils::NavigateToURL(browser(), url); |
1214 | 1244 |
1215 // Search for the word "page". | 1245 // Search for the word "page". |
1216 int ordinal = 0; | 1246 int ordinal = 0; |
1217 WebContents* web_contents_1 = chrome::GetActiveWebContents(browser()); | 1247 WebContents* web_contents_1 = |
| 1248 browser()->tab_strip_model()->GetActiveWebContents(); |
1218 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page", | 1249 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page", |
1219 kFwd, kIgnoreCase, &ordinal)); | 1250 kFwd, kIgnoreCase, &ordinal)); |
1220 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); | 1251 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); |
1221 | 1252 |
1222 // Now create a second tab and load the same page. | 1253 // Now create a second tab and load the same page. |
1223 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED); | 1254 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED); |
1224 WebContents* web_contents_2 = chrome::GetActiveWebContents(browser()); | 1255 WebContents* web_contents_2 = |
| 1256 browser()->tab_strip_model()->GetActiveWebContents(); |
1225 EXPECT_NE(web_contents_1, web_contents_2); | 1257 EXPECT_NE(web_contents_1, web_contents_2); |
1226 | 1258 |
1227 // Open the Find box. | 1259 // Open the Find box. |
1228 EnsureFindBoxOpen(); | 1260 EnsureFindBoxOpen(); |
1229 | 1261 |
1230 // The new tab should have "page" prepopulated, since that was the last search | 1262 // The new tab should have "page" prepopulated, since that was the last search |
1231 // in the first tab. | 1263 // in the first tab. |
1232 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); | 1264 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); |
1233 // But it should not seem like a search has been issued. | 1265 // But it should not seem like a search has been issued. |
1234 EXPECT_EQ(string16(), GetMatchCountText()); | 1266 EXPECT_EQ(string16(), GetMatchCountText()); |
1235 } | 1267 } |
1236 | 1268 |
1237 // This makes sure that we can search for A in tabA, then for B in tabB and | 1269 // This makes sure that we can search for A in tabA, then for B in tabB and |
1238 // when we come back to tabA we should still see A (because that was the last | 1270 // when we come back to tabA we should still see A (because that was the last |
1239 // search in that tab). | 1271 // search in that tab). |
1240 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) { | 1272 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) { |
1241 #if defined(OS_MACOSX) | 1273 #if defined(OS_MACOSX) |
1242 // FindInPage on Mac doesn't use prepopulated values. Search there is global. | 1274 // FindInPage on Mac doesn't use prepopulated values. Search there is global. |
1243 return; | 1275 return; |
1244 #endif | 1276 #endif |
1245 | 1277 |
1246 // First we navigate to any page. | 1278 // First we navigate to any page. |
1247 GURL url = GetURL(kSimple); | 1279 GURL url = GetURL(kSimple); |
1248 ui_test_utils::NavigateToURL(browser(), url); | 1280 ui_test_utils::NavigateToURL(browser(), url); |
1249 | 1281 |
1250 // Search for the word "page". | 1282 // Search for the word "page". |
1251 int ordinal = 0; | 1283 int ordinal = 0; |
1252 WebContents* web_contents_1 = chrome::GetActiveWebContents(browser()); | 1284 WebContents* web_contents_1 = |
| 1285 browser()->tab_strip_model()->GetActiveWebContents(); |
1253 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page", | 1286 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page", |
1254 kFwd, kIgnoreCase, &ordinal)); | 1287 kFwd, kIgnoreCase, &ordinal)); |
1255 | 1288 |
1256 // Open the Find box. | 1289 // Open the Find box. |
1257 EnsureFindBoxOpen(); | 1290 EnsureFindBoxOpen(); |
1258 | 1291 |
1259 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); | 1292 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); |
1260 | 1293 |
1261 // Close the Find box. | 1294 // Close the Find box. |
1262 browser()->GetFindBarController()->EndFindSession( | 1295 browser()->GetFindBarController()->EndFindSession( |
1263 FindBarController::kKeepSelectionOnPage, | 1296 FindBarController::kKeepSelectionOnPage, |
1264 FindBarController::kKeepResultsInFindBox); | 1297 FindBarController::kKeepResultsInFindBox); |
1265 | 1298 |
1266 // Now create a second tab and load the same page. | 1299 // Now create a second tab and load the same page. |
1267 chrome::AddBlankTabAt(browser(), -1, true); | 1300 chrome::AddBlankTabAt(browser(), -1, true); |
1268 ui_test_utils::NavigateToURL(browser(), url); | 1301 ui_test_utils::NavigateToURL(browser(), url); |
1269 WebContents* web_contents_2 = chrome::GetActiveWebContents(browser()); | 1302 WebContents* web_contents_2 = |
| 1303 browser()->tab_strip_model()->GetActiveWebContents(); |
1270 EXPECT_NE(web_contents_1, web_contents_2); | 1304 EXPECT_NE(web_contents_1, web_contents_2); |
1271 | 1305 |
1272 // Search for the word "text". | 1306 // Search for the word "text". |
1273 FindInPageWchar(web_contents_2, L"text", kFwd, kIgnoreCase, &ordinal); | 1307 FindInPageWchar(web_contents_2, L"text", kFwd, kIgnoreCase, &ordinal); |
1274 | 1308 |
1275 // Go back to the first tab and make sure we have NOT switched the prepopulate | 1309 // Go back to the first tab and make sure we have NOT switched the prepopulate |
1276 // text to "text". | 1310 // text to "text". |
1277 chrome::ActivateTabAt(browser(), 0, false); | 1311 browser()->tab_strip_model()->ActivateTabAt(0, false); |
1278 | 1312 |
1279 // Open the Find box. | 1313 // Open the Find box. |
1280 EnsureFindBoxOpen(); | 1314 EnsureFindBoxOpen(); |
1281 | 1315 |
1282 // After the Find box has been reopened, it should have been prepopulated with | 1316 // After the Find box has been reopened, it should have been prepopulated with |
1283 // the word "page" again, since that was the last search in that tab. | 1317 // the word "page" again, since that was the last search in that tab. |
1284 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); | 1318 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); |
1285 | 1319 |
1286 // Close the Find box. | 1320 // Close the Find box. |
1287 browser()->GetFindBarController()->EndFindSession( | 1321 browser()->GetFindBarController()->EndFindSession( |
(...skipping 26 matching lines...) Expand all Loading... |
1314 // FindInPage on Mac doesn't use prepopulated values. Search there is global. | 1348 // FindInPage on Mac doesn't use prepopulated values. Search there is global. |
1315 return; | 1349 return; |
1316 #endif | 1350 #endif |
1317 | 1351 |
1318 // First we navigate to the "simple" test page. | 1352 // First we navigate to the "simple" test page. |
1319 GURL url = GetURL(kSimple); | 1353 GURL url = GetURL(kSimple); |
1320 ui_test_utils::NavigateToURL(browser(), url); | 1354 ui_test_utils::NavigateToURL(browser(), url); |
1321 | 1355 |
1322 // Search for the word "page" in the normal browser tab. | 1356 // Search for the word "page" in the normal browser tab. |
1323 int ordinal = 0; | 1357 int ordinal = 0; |
1324 WebContents* web_contents_1 = chrome::GetActiveWebContents(browser()); | 1358 WebContents* web_contents_1 = |
| 1359 browser()->tab_strip_model()->GetActiveWebContents(); |
1325 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page", | 1360 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page", |
1326 kFwd, kIgnoreCase, &ordinal)); | 1361 kFwd, kIgnoreCase, &ordinal)); |
1327 | 1362 |
1328 // Open the Find box. | 1363 // Open the Find box. |
1329 EnsureFindBoxOpenForBrowser(browser()); | 1364 EnsureFindBoxOpenForBrowser(browser()); |
1330 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); | 1365 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); |
1331 | 1366 |
1332 // Close the Find box. | 1367 // Close the Find box. |
1333 browser()->GetFindBarController()->EndFindSession( | 1368 browser()->GetFindBarController()->EndFindSession( |
1334 FindBarController::kKeepSelectionOnPage, | 1369 FindBarController::kKeepSelectionOnPage, |
1335 FindBarController::kKeepResultsInFindBox); | 1370 FindBarController::kKeepResultsInFindBox); |
1336 | 1371 |
1337 // Open a new incognito window and navigate to the same page. | 1372 // Open a new incognito window and navigate to the same page. |
1338 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); | 1373 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); |
1339 Browser* incognito_browser = | 1374 Browser* incognito_browser = |
1340 new Browser(Browser::CreateParams(incognito_profile)); | 1375 new Browser(Browser::CreateParams(incognito_profile)); |
1341 content::WindowedNotificationObserver observer( | 1376 content::WindowedNotificationObserver observer( |
1342 content::NOTIFICATION_LOAD_STOP, | 1377 content::NOTIFICATION_LOAD_STOP, |
1343 content::NotificationService::AllSources()); | 1378 content::NotificationService::AllSources()); |
1344 chrome::AddSelectedTabWithURL(incognito_browser, url, | 1379 chrome::AddSelectedTabWithURL(incognito_browser, url, |
1345 content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 1380 content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
1346 observer.Wait(); | 1381 observer.Wait(); |
1347 incognito_browser->window()->Show(); | 1382 incognito_browser->window()->Show(); |
1348 | 1383 |
1349 // Open the find box and make sure that it is prepopulated with "page". | 1384 // Open the find box and make sure that it is prepopulated with "page". |
1350 EnsureFindBoxOpenForBrowser(incognito_browser); | 1385 EnsureFindBoxOpenForBrowser(incognito_browser); |
1351 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser)); | 1386 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser)); |
1352 | 1387 |
1353 // Search for the word "text" in the incognito tab. | 1388 // Search for the word "text" in the incognito tab. |
1354 WebContents* incognito_tab = chrome::GetActiveWebContents(incognito_browser); | 1389 WebContents* incognito_tab = |
| 1390 incognito_browser->tab_strip_model()->GetActiveWebContents(); |
1355 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text", | 1391 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text", |
1356 kFwd, kIgnoreCase, &ordinal)); | 1392 kFwd, kIgnoreCase, &ordinal)); |
1357 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser)); | 1393 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser)); |
1358 | 1394 |
1359 // Close the Find box. | 1395 // Close the Find box. |
1360 incognito_browser->GetFindBarController()->EndFindSession( | 1396 incognito_browser->GetFindBarController()->EndFindSession( |
1361 FindBarController::kKeepSelectionOnPage, | 1397 FindBarController::kKeepSelectionOnPage, |
1362 FindBarController::kKeepResultsInFindBox); | 1398 FindBarController::kKeepResultsInFindBox); |
1363 | 1399 |
1364 // Now open a new tab in the original (non-incognito) browser. | 1400 // Now open a new tab in the original (non-incognito) browser. |
1365 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED); | 1401 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED); |
1366 WebContents* web_contents_2 = chrome::GetActiveWebContents(browser()); | 1402 WebContents* web_contents_2 = |
| 1403 browser()->tab_strip_model()->GetActiveWebContents(); |
1367 EXPECT_NE(web_contents_1, web_contents_2); | 1404 EXPECT_NE(web_contents_1, web_contents_2); |
1368 | 1405 |
1369 // Open the Find box and make sure it is prepopulated with the search term | 1406 // Open the Find box and make sure it is prepopulated with the search term |
1370 // from the original browser, not the search term from the incognito window. | 1407 // from the original browser, not the search term from the incognito window. |
1371 EnsureFindBoxOpenForBrowser(browser()); | 1408 EnsureFindBoxOpenForBrowser(browser()); |
1372 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); | 1409 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); |
1373 } | 1410 } |
1374 | 1411 |
1375 // This makes sure that dismissing the find bar with kActivateSelection works. | 1412 // This makes sure that dismissing the find bar with kActivateSelection works. |
1376 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) { | 1413 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) { |
1377 // First we navigate to our test content. | 1414 // First we navigate to our test content. |
1378 GURL url = GetURL(kLinkPage); | 1415 GURL url = GetURL(kLinkPage); |
1379 ui_test_utils::NavigateToURL(browser(), url); | 1416 ui_test_utils::NavigateToURL(browser(), url); |
1380 | 1417 |
1381 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1418 WebContents* web_contents = |
| 1419 browser()->tab_strip_model()->GetActiveWebContents(); |
1382 FindTabHelper* find_tab_helper = | 1420 FindTabHelper* find_tab_helper = |
1383 FindTabHelper::FromWebContents(web_contents); | 1421 FindTabHelper::FromWebContents(web_contents); |
1384 | 1422 |
1385 int ordinal = 0; | 1423 int ordinal = 0; |
1386 FindInPageWchar(web_contents, L"link", kFwd, kIgnoreCase, &ordinal); | 1424 FindInPageWchar(web_contents, L"link", kFwd, kIgnoreCase, &ordinal); |
1387 EXPECT_EQ(ordinal, 1); | 1425 EXPECT_EQ(ordinal, 1); |
1388 | 1426 |
1389 // End the find session, click on the link. | 1427 // End the find session, click on the link. |
1390 content::WindowedNotificationObserver observer( | 1428 content::WindowedNotificationObserver observer( |
1391 content::NOTIFICATION_LOAD_STOP, | 1429 content::NOTIFICATION_LOAD_STOP, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 content::RunAllPendingInMessageLoop(); // Needed on Linux. | 1500 content::RunAllPendingInMessageLoop(); // Needed on Linux. |
1463 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); | 1501 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); |
1464 | 1502 |
1465 ui_test_utils::NavigateToURLWithDisposition( | 1503 ui_test_utils::NavigateToURLWithDisposition( |
1466 browser(), url, NEW_FOREGROUND_TAB, | 1504 browser(), url, NEW_FOREGROUND_TAB, |
1467 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1505 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1468 chrome::CloseTab(browser()); | 1506 chrome::CloseTab(browser()); |
1469 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); | 1507 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); |
1470 EXPECT_EQ(position, position2); | 1508 EXPECT_EQ(position, position2); |
1471 } | 1509 } |
OLD | NEW |