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

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

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/string16.h" 6 #include "base/string16.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h" 11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/browser_navigator.h" 12 #include "chrome/browser/ui/browser_navigator.h"
13 #include "chrome/browser/ui/browser_tabstrip.h"
13 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/chrome_pages.h" 15 #include "chrome/browser/ui/chrome_pages.h"
15 #include "chrome/browser/ui/find_bar/find_bar.h" 16 #include "chrome/browser/ui/find_bar/find_bar.h"
16 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 17 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
17 #include "chrome/browser/ui/find_bar/find_notification_details.h" 18 #include "chrome/browser/ui/find_bar/find_notification_details.h"
18 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 19 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/in_process_browser_test.h" 23 #include "chrome/test/base/in_process_browser_test.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 }; 178 };
178 179
179 // This test loads a page with frames and starts FindInPage requests. 180 // This test loads a page with frames and starts FindInPage requests.
180 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { 181 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) {
181 // First we navigate to our frames page. 182 // First we navigate to our frames page.
182 GURL url = GetURL(kFramePage); 183 GURL url = GetURL(kFramePage);
183 ui_test_utils::NavigateToURL(browser(), url); 184 ui_test_utils::NavigateToURL(browser(), url);
184 185
185 // Try incremental search (mimicking user typing in). 186 // Try incremental search (mimicking user typing in).
186 int ordinal = 0; 187 int ordinal = 0;
187 TabContents* tab = browser()->GetActiveTabContents(); 188 TabContents* tab = chrome::GetActiveTabContents(browser());
188 EXPECT_EQ(18, FindInPageWchar(tab, L"g", 189 EXPECT_EQ(18, FindInPageWchar(tab, L"g",
189 kFwd, kIgnoreCase, &ordinal)); 190 kFwd, kIgnoreCase, &ordinal));
190 EXPECT_EQ(1, ordinal); 191 EXPECT_EQ(1, ordinal);
191 EXPECT_EQ(11, FindInPageWchar(tab, L"go", 192 EXPECT_EQ(11, FindInPageWchar(tab, L"go",
192 kFwd, kIgnoreCase, &ordinal)); 193 kFwd, kIgnoreCase, &ordinal));
193 EXPECT_EQ(1, ordinal); 194 EXPECT_EQ(1, ordinal);
194 EXPECT_EQ(04, FindInPageWchar(tab, L"goo", 195 EXPECT_EQ(04, FindInPageWchar(tab, L"goo",
195 kFwd, kIgnoreCase, &ordinal)); 196 kFwd, kIgnoreCase, &ordinal));
196 EXPECT_EQ(1, ordinal); 197 EXPECT_EQ(1, ordinal);
197 EXPECT_EQ(03, FindInPageWchar(tab, L"goog", 198 EXPECT_EQ(03, FindInPageWchar(tab, L"goog",
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 268 }
268 269
269 // This tests the FindInPage end-state, in other words: what is focused when you 270 // This tests the FindInPage end-state, in other words: what is focused when you
270 // close the Find box (ie. if you find within a link the link should be 271 // close the Find box (ie. if you find within a link the link should be
271 // focused). 272 // focused).
272 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { 273 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) {
273 // First we navigate to our special focus tracking page. 274 // First we navigate to our special focus tracking page.
274 GURL url = GetURL(kEndState); 275 GURL url = GetURL(kEndState);
275 ui_test_utils::NavigateToURL(browser(), url); 276 ui_test_utils::NavigateToURL(browser(), url);
276 277
277 TabContents* tab_contents = browser()->GetActiveTabContents(); 278 TabContents* tab_contents = chrome::GetActiveTabContents(browser());
278 ASSERT_TRUE(NULL != tab_contents); 279 ASSERT_TRUE(NULL != tab_contents);
279 280
280 // Verify that nothing has focus. 281 // Verify that nothing has focus.
281 std::string result; 282 std::string result;
282 ASSERT_TRUE(FocusedOnPage(tab_contents->web_contents(), &result)); 283 ASSERT_TRUE(FocusedOnPage(tab_contents->web_contents(), &result));
283 ASSERT_STREQ("{nothing focused}", result.c_str()); 284 ASSERT_STREQ("{nothing focused}", result.c_str());
284 285
285 // Search for a text that exists within a link on the page. 286 // Search for a text that exists within a link on the page.
286 int ordinal = 0; 287 int ordinal = 0;
287 EXPECT_EQ(1, FindInPageWchar(tab_contents, L"nk", 288 EXPECT_EQ(1, FindInPageWchar(tab_contents, L"nk",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 320
320 // This test loads a single-frame page and makes sure the ordinal returned makes 321 // This test loads a single-frame page and makes sure the ordinal returned makes
321 // sense as we FindNext over all the items. 322 // sense as we FindNext over all the items.
322 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { 323 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) {
323 // First we navigate to our page. 324 // First we navigate to our page.
324 GURL url = GetURL(kFrameData); 325 GURL url = GetURL(kFrameData);
325 ui_test_utils::NavigateToURL(browser(), url); 326 ui_test_utils::NavigateToURL(browser(), url);
326 327
327 // Search for 'o', which should make the first item active and return 328 // Search for 'o', which should make the first item active and return
328 // '1 in 3' (1st ordinal of a total of 3 matches). 329 // '1 in 3' (1st ordinal of a total of 3 matches).
329 TabContents* tab = browser()->GetActiveTabContents(); 330 TabContents* tab = chrome::GetActiveTabContents(browser());
330 int ordinal = 0; 331 int ordinal = 0;
331 EXPECT_EQ(3, FindInPageWchar(tab, L"o", 332 EXPECT_EQ(3, FindInPageWchar(tab, L"o",
332 kFwd, kIgnoreCase, &ordinal)); 333 kFwd, kIgnoreCase, &ordinal));
333 EXPECT_EQ(1, ordinal); 334 EXPECT_EQ(1, ordinal);
334 EXPECT_EQ(3, FindInPageWchar(tab, L"o", 335 EXPECT_EQ(3, FindInPageWchar(tab, L"o",
335 kFwd, kIgnoreCase, &ordinal)); 336 kFwd, kIgnoreCase, &ordinal));
336 EXPECT_EQ(2, ordinal); 337 EXPECT_EQ(2, ordinal);
337 EXPECT_EQ(3, FindInPageWchar(tab, L"o", 338 EXPECT_EQ(3, FindInPageWchar(tab, L"o",
338 kFwd, kIgnoreCase, &ordinal)); 339 kFwd, kIgnoreCase, &ordinal));
339 EXPECT_EQ(3, ordinal); 340 EXPECT_EQ(3, ordinal);
(...skipping 15 matching lines...) Expand all
355 } 356 }
356 357
357 // This tests that the ordinal is correctly adjusted after a selection 358 // This tests that the ordinal is correctly adjusted after a selection
358 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, 359 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
359 SelectChangesOrdinal_Issue20883) { 360 SelectChangesOrdinal_Issue20883) {
360 // First we navigate to our test content. 361 // First we navigate to our test content.
361 GURL url = GetURL(kSelectChangesOrdinal); 362 GURL url = GetURL(kSelectChangesOrdinal);
362 ui_test_utils::NavigateToURL(browser(), url); 363 ui_test_utils::NavigateToURL(browser(), url);
363 364
364 // Search for a text that exists within a link on the page. 365 // Search for a text that exists within a link on the page.
365 TabContents* tab = browser()->GetActiveTabContents(); 366 TabContents* tab = chrome::GetActiveTabContents(browser());
366 ASSERT_TRUE(NULL != tab); 367 ASSERT_TRUE(NULL != tab);
367 int ordinal = 0; 368 int ordinal = 0;
368 EXPECT_EQ(4, FindInPageWchar(tab, 369 EXPECT_EQ(4, FindInPageWchar(tab,
369 L"google", 370 L"google",
370 kFwd, kIgnoreCase, &ordinal)); 371 kFwd, kIgnoreCase, &ordinal));
371 EXPECT_EQ(1, ordinal); 372 EXPECT_EQ(1, ordinal);
372 373
373 // Move the selection to link 1, after searching. 374 // Move the selection to link 1, after searching.
374 std::string result; 375 std::string result;
375 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 376 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
(...skipping 15 matching lines...) Expand all
391 392
392 // This test loads a page with frames and makes sure the ordinal returned makes 393 // This test loads a page with frames and makes sure the ordinal returned makes
393 // sense. 394 // sense.
394 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { 395 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) {
395 // First we navigate to our page. 396 // First we navigate to our page.
396 GURL url = GetURL(kFramePage); 397 GURL url = GetURL(kFramePage);
397 ui_test_utils::NavigateToURL(browser(), url); 398 ui_test_utils::NavigateToURL(browser(), url);
398 399
399 // Search for 'a', which should make the first item active and return 400 // Search for 'a', which should make the first item active and return
400 // '1 in 7' (1st ordinal of a total of 7 matches). 401 // '1 in 7' (1st ordinal of a total of 7 matches).
401 TabContents* tab = browser()->GetActiveTabContents(); 402 TabContents* tab = chrome::GetActiveTabContents(browser());
402 int ordinal = 0; 403 int ordinal = 0;
403 EXPECT_EQ(7, 404 EXPECT_EQ(7,
404 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 405 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
405 EXPECT_EQ(1, ordinal); 406 EXPECT_EQ(1, ordinal);
406 EXPECT_EQ(7, 407 EXPECT_EQ(7,
407 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 408 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
408 EXPECT_EQ(2, ordinal); 409 EXPECT_EQ(2, ordinal);
409 EXPECT_EQ(7, 410 EXPECT_EQ(7,
410 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); 411 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
411 EXPECT_EQ(3, ordinal); 412 EXPECT_EQ(3, ordinal);
(...skipping 28 matching lines...) Expand all
440 441
441 // We could get ordinals out of whack when restarting search in subframes. 442 // We could get ordinals out of whack when restarting search in subframes.
442 // See http://crbug.com/5132. 443 // See http://crbug.com/5132.
443 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { 444 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) {
444 // First we navigate to our page. 445 // First we navigate to our page.
445 GURL url = GetURL(kFramePage); 446 GURL url = GetURL(kFramePage);
446 ui_test_utils::NavigateToURL(browser(), url); 447 ui_test_utils::NavigateToURL(browser(), url);
447 448
448 // Search for 'goa' three times (6 matches on page). 449 // Search for 'goa' three times (6 matches on page).
449 int ordinal = 0; 450 int ordinal = 0;
450 TabContents* tab = browser()->GetActiveTabContents(); 451 TabContents* tab = chrome::GetActiveTabContents(browser());
451 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", 452 EXPECT_EQ(6, FindInPageWchar(tab, L"goa",
452 kFwd, kIgnoreCase, &ordinal)); 453 kFwd, kIgnoreCase, &ordinal));
453 EXPECT_EQ(1, ordinal); 454 EXPECT_EQ(1, ordinal);
454 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", 455 EXPECT_EQ(6, FindInPageWchar(tab, L"goa",
455 kFwd, kIgnoreCase, &ordinal)); 456 kFwd, kIgnoreCase, &ordinal));
456 EXPECT_EQ(2, ordinal); 457 EXPECT_EQ(2, ordinal);
457 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", 458 EXPECT_EQ(6, FindInPageWchar(tab, L"goa",
458 kFwd, kIgnoreCase, &ordinal)); 459 kFwd, kIgnoreCase, &ordinal));
459 EXPECT_EQ(3, ordinal); 460 EXPECT_EQ(3, ordinal);
460 // Add space to search (should result in no matches). 461 // Add space to search (should result in no matches).
(...skipping 21 matching lines...) Expand all
482 GURL url = GetURL(kSimple); 483 GURL url = GetURL(kSimple);
483 ui_test_utils::NavigateToURL(browser(), url); 484 ui_test_utils::NavigateToURL(browser(), url);
484 485
485 // Open the Find box. In most tests we can just search without opening the 486 // Open the Find box. In most tests we can just search without opening the
486 // box first, but in this case we are testing functionality triggered by 487 // box first, but in this case we are testing functionality triggered by
487 // NOTIFICATION_NAV_ENTRY_COMMITTED in the FindBarController and the observer 488 // NOTIFICATION_NAV_ENTRY_COMMITTED in the FindBarController and the observer
488 // for that event isn't setup unless the box is open. 489 // for that event isn't setup unless the box is open.
489 EnsureFindBoxOpen(); 490 EnsureFindBoxOpen();
490 491
491 // Search for a text that exists within a link on the page. 492 // Search for a text that exists within a link on the page.
492 TabContents* tab = browser()->GetActiveTabContents(); 493 TabContents* tab = chrome::GetActiveTabContents(browser());
493 ASSERT_TRUE(NULL != tab); 494 ASSERT_TRUE(NULL != tab);
494 int ordinal = 0; 495 int ordinal = 0;
495 EXPECT_EQ(8, FindInPageWchar(tab, 496 EXPECT_EQ(8, FindInPageWchar(tab,
496 L"e", 497 L"e",
497 kFwd, kIgnoreCase, &ordinal)); 498 kFwd, kIgnoreCase, &ordinal));
498 EXPECT_EQ(1, ordinal); 499 EXPECT_EQ(1, ordinal);
499 500
500 // Then navigate away (to any page). 501 // Then navigate away (to any page).
501 url = GetURL(kLinkPage); 502 url = GetURL(kLinkPage);
502 ui_test_utils::NavigateToURL(browser(), url); 503 ui_test_utils::NavigateToURL(browser(), url);
503 504
504 // Open the Find box again. 505 // Open the Find box again.
505 EnsureFindBoxOpen(); 506 EnsureFindBoxOpen();
506 507
507 EXPECT_EQ(ASCIIToUTF16("e"), GetFindBarText()); 508 EXPECT_EQ(ASCIIToUTF16("e"), GetFindBarText());
508 EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText()); 509 EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText());
509 } 510 }
510 511
511 // Load a page with no selectable text and make sure we don't crash. 512 // Load a page with no selectable text and make sure we don't crash.
512 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnselectableText) { 513 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnselectableText) {
513 // First we navigate to our page. 514 // First we navigate to our page.
514 GURL url = GetURL(kUserSelectPage); 515 GURL url = GetURL(kUserSelectPage);
515 ui_test_utils::NavigateToURL(browser(), url); 516 ui_test_utils::NavigateToURL(browser(), url);
516 517
517 int ordinal = 0; 518 int ordinal = 0;
518 TabContents* tab = browser()->GetActiveTabContents(); 519 TabContents* tab = chrome::GetActiveTabContents(browser());
519 EXPECT_EQ(1, FindInPageWchar(tab, L"text", kFwd, kIgnoreCase, &ordinal)); 520 EXPECT_EQ(1, FindInPageWchar(tab, L"text", kFwd, kIgnoreCase, &ordinal));
520 EXPECT_EQ(1, ordinal); 521 EXPECT_EQ(1, ordinal);
521 } 522 }
522 523
523 // Try to reproduce the crash seen in issue 1341577. 524 // Try to reproduce the crash seen in issue 1341577.
524 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { 525 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) {
525 // First we navigate to our page. 526 // First we navigate to our page.
526 GURL url = GetURL(kCrashPage); 527 GURL url = GetURL(kCrashPage);
527 ui_test_utils::NavigateToURL(browser(), url); 528 ui_test_utils::NavigateToURL(browser(), url);
528 529
529 // This would crash the tab. These must be the first two find requests issued 530 // This would crash the tab. These must be the first two find requests issued
530 // against the frame, otherwise an active frame pointer is set and it wont 531 // against the frame, otherwise an active frame pointer is set and it wont
531 // produce the crash. 532 // produce the crash.
532 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does 533 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does
533 // not find a stand-alone dependent vowel sign of Indic scripts. So, the 534 // not find a stand-alone dependent vowel sign of Indic scripts. So, the
534 // exptected values are all 0. To make this test pass regardless of 535 // exptected values are all 0. To make this test pass regardless of
535 // ICU version, we just call FiP and see if there's any crash. 536 // ICU version, we just call FiP and see if there's any crash.
536 // TODO(jungshik): According to a native Malayalam speaker, it's ok not 537 // TODO(jungshik): According to a native Malayalam speaker, it's ok not
537 // to find U+0D4C. Still need to investigate further this issue. 538 // to find U+0D4C. Still need to investigate further this issue.
538 int ordinal = 0; 539 int ordinal = 0;
539 TabContents* tab = browser()->GetActiveTabContents(); 540 TabContents* tab = chrome::GetActiveTabContents(browser());
540 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); 541 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal);
541 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); 542 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal);
542 543
543 // This should work fine. 544 // This should work fine.
544 EXPECT_EQ(1, FindInPageWchar(tab, L"\u0D24\u0D46", 545 EXPECT_EQ(1, FindInPageWchar(tab, L"\u0D24\u0D46",
545 kFwd, kIgnoreCase, &ordinal)); 546 kFwd, kIgnoreCase, &ordinal));
546 EXPECT_EQ(1, ordinal); 547 EXPECT_EQ(1, ordinal);
547 EXPECT_EQ(0, FindInPageWchar(tab, L"nostring", 548 EXPECT_EQ(0, FindInPageWchar(tab, L"nostring",
548 kFwd, kIgnoreCase, &ordinal)); 549 kFwd, kIgnoreCase, &ordinal));
549 EXPECT_EQ(0, ordinal); 550 EXPECT_EQ(0, ordinal);
550 } 551 }
551 552
552 // Try to reproduce the crash seen in http://crbug.com/14491, where an assert 553 // Try to reproduce the crash seen in http://crbug.com/14491, where an assert
553 // hits in the BitStack size comparison in WebKit. 554 // hits in the BitStack size comparison in WebKit.
554 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { 555 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) {
555 // First we navigate to our page. 556 // First we navigate to our page.
556 GURL url = GetURL(kBitstackCrash); 557 GURL url = GetURL(kBitstackCrash);
557 ui_test_utils::NavigateToURL(browser(), url); 558 ui_test_utils::NavigateToURL(browser(), url);
558 559
559 // This used to crash the tab. 560 // This used to crash the tab.
560 int ordinal = 0; 561 int ordinal = 0;
561 EXPECT_EQ(0, FindInPageWchar(browser()->GetActiveTabContents(), 562 EXPECT_EQ(0, FindInPageWchar(chrome::GetActiveTabContents(browser()),
562 L"s", kFwd, kIgnoreCase, &ordinal)); 563 L"s", kFwd, kIgnoreCase, &ordinal));
563 EXPECT_EQ(0, ordinal); 564 EXPECT_EQ(0, ordinal);
564 } 565 }
565 566
566 // Test to make sure Find does the right thing when restarting from a timeout. 567 // Test to make sure Find does the right thing when restarting from a timeout.
567 // We used to have a problem where we'd stop finding matches when all of the 568 // We used to have a problem where we'd stop finding matches when all of the
568 // following conditions were true: 569 // following conditions were true:
569 // 1) The page has a lot of text to search. 570 // 1) The page has a lot of text to search.
570 // 2) The page contains more than one match. 571 // 2) The page contains more than one match.
571 // 3) It takes longer than the time-slice given to each Find operation (100 572 // 3) It takes longer than the time-slice given to each Find operation (100
572 // ms) to find one or more of those matches (so Find times out and has to try 573 // ms) to find one or more of those matches (so Find times out and has to try
573 // again from where it left off). 574 // again from where it left off).
574 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { 575 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) {
575 // First we navigate to our page. 576 // First we navigate to our page.
576 GURL url = GetURL(kTooFewMatchesPage); 577 GURL url = GetURL(kTooFewMatchesPage);
577 ui_test_utils::NavigateToURL(browser(), url); 578 ui_test_utils::NavigateToURL(browser(), url);
578 579
579 // This string appears 5 times at the bottom of a long page. If Find restarts 580 // This string appears 5 times at the bottom of a long page. If Find restarts
580 // properly after a timeout, it will find 5 matches, not just 1. 581 // properly after a timeout, it will find 5 matches, not just 1.
581 int ordinal = 0; 582 int ordinal = 0;
582 EXPECT_EQ(5, FindInPageWchar(browser()->GetActiveTabContents(), 583 EXPECT_EQ(5, FindInPageWchar(chrome::GetActiveTabContents(browser()),
583 L"008.xml", 584 L"008.xml",
584 kFwd, kIgnoreCase, &ordinal)); 585 kFwd, kIgnoreCase, &ordinal));
585 EXPECT_EQ(1, ordinal); 586 EXPECT_EQ(1, ordinal);
586 } 587 }
587 588
588 // Make sure we don't get into an infinite loop when text box contains very 589 // Make sure we don't get into an infinite loop when text box contains very
589 // large amount of text. 590 // large amount of text.
590 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue70505) { 591 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue70505) {
591 // First we navigate to our page. 592 // First we navigate to our page.
592 GURL url = GetURL(kLongTextareaPage); 593 GURL url = GetURL(kLongTextareaPage);
593 ui_test_utils::NavigateToURL(browser(), url); 594 ui_test_utils::NavigateToURL(browser(), url);
594 595
595 // If this test hangs on the FindInPage call, then it might be a regression 596 // If this test hangs on the FindInPage call, then it might be a regression
596 // such as the one found in issue http://crbug.com/70505. 597 // such as the one found in issue http://crbug.com/70505.
597 int ordinal = 0; 598 int ordinal = 0;
598 FindInPageWchar(browser()->GetActiveTabContents(), 599 FindInPageWchar(chrome::GetActiveTabContents(browser()),
599 L"a", kFwd, kIgnoreCase, &ordinal); 600 L"a", kFwd, kIgnoreCase, &ordinal);
600 EXPECT_EQ(1, ordinal); 601 EXPECT_EQ(1, ordinal);
601 // TODO(finnur): We cannot reliably get the matchcount for this Find call 602 // TODO(finnur): We cannot reliably get the matchcount for this Find call
602 // until we fix issue http://crbug.com/71176. 603 // until we fix issue http://crbug.com/71176.
603 } 604 }
604 605
605 // This tests bug 11761: FindInPage terminates search prematurely. 606 // This tests bug 11761: FindInPage terminates search prematurely.
606 // This test is not expected to pass until bug 11761 is fixed. 607 // This test is not expected to pass until bug 11761 is fixed.
607 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, 608 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
608 DISABLED_FindInPagePrematureEnd) { 609 DISABLED_FindInPagePrematureEnd) {
609 // First we navigate to our special focus tracking page. 610 // First we navigate to our special focus tracking page.
610 GURL url = GetURL(kPrematureEnd); 611 GURL url = GetURL(kPrematureEnd);
611 ui_test_utils::NavigateToURL(browser(), url); 612 ui_test_utils::NavigateToURL(browser(), url);
612 613
613 TabContents* tab_contents = browser()->GetActiveTabContents(); 614 TabContents* tab_contents = chrome::GetActiveTabContents(browser());
614 ASSERT_TRUE(NULL != tab_contents); 615 ASSERT_TRUE(NULL != tab_contents);
615 616
616 // Search for a text that exists within a link on the page. 617 // Search for a text that exists within a link on the page.
617 int ordinal = 0; 618 int ordinal = 0;
618 EXPECT_EQ(2, FindInPageWchar(tab_contents, L"html ", 619 EXPECT_EQ(2, FindInPageWchar(tab_contents, L"html ",
619 kFwd, kIgnoreCase, &ordinal)); 620 kFwd, kIgnoreCase, &ordinal));
620 EXPECT_EQ(1, ordinal); 621 EXPECT_EQ(1, ordinal);
621 } 622 }
622 623
623 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { 624 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) {
624 // First we navigate to our special focus tracking page. 625 // First we navigate to our special focus tracking page.
625 GURL url = GetURL(kSimple); 626 GURL url = GetURL(kSimple);
626 GURL url2 = GetURL(kFramePage); 627 GURL url2 = GetURL(kFramePage);
627 ui_test_utils::NavigateToURL(browser(), url); 628 ui_test_utils::NavigateToURL(browser(), url);
628 629
629 chrome::ShowFindBar(browser()); 630 chrome::ShowFindBar(browser());
630 631
631 gfx::Point position; 632 gfx::Point position;
632 bool fully_visible = false; 633 bool fully_visible = false;
633 634
634 // Make sure it is open. 635 // Make sure it is open.
635 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 636 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
636 EXPECT_TRUE(fully_visible); 637 EXPECT_TRUE(fully_visible);
637 638
638 // Reload the tab and make sure Find window doesn't go away. 639 // Reload the tab and make sure Find window doesn't go away.
639 ui_test_utils::WindowedNotificationObserver observer( 640 ui_test_utils::WindowedNotificationObserver observer(
640 content::NOTIFICATION_LOAD_STOP, 641 content::NOTIFICATION_LOAD_STOP,
641 content::Source<NavigationController>( 642 content::Source<NavigationController>(
642 &browser()->GetActiveTabContents()->web_contents()-> 643 &chrome::GetActiveTabContents(browser())->web_contents()->
643 GetController())); 644 GetController()));
644 chrome::Reload(browser(), CURRENT_TAB); 645 chrome::Reload(browser(), CURRENT_TAB);
645 observer.Wait(); 646 observer.Wait();
646 647
647 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); 648 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
648 EXPECT_TRUE(fully_visible); 649 EXPECT_TRUE(fully_visible);
649 650
650 // Navigate and make sure the Find window goes away. 651 // Navigate and make sure the Find window goes away.
651 ui_test_utils::NavigateToURL(browser(), url2); 652 ui_test_utils::NavigateToURL(browser(), url2);
652 653
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 736
736 gfx::Point start_position; 737 gfx::Point start_position;
737 gfx::Point position; 738 gfx::Point position;
738 bool fully_visible = false; 739 bool fully_visible = false;
739 int ordinal = 0; 740 int ordinal = 0;
740 741
741 // Make sure it is open. 742 // Make sure it is open.
742 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible)); 743 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible));
743 EXPECT_TRUE(fully_visible); 744 EXPECT_TRUE(fully_visible);
744 745
745 TabContents* tab = browser()->GetActiveTabContents(); 746 TabContents* tab = chrome::GetActiveTabContents(browser());
746 747
747 int moved_x_coord = FindInPageTillBoxMoves(tab, start_position.x(), 748 int moved_x_coord = FindInPageTillBoxMoves(tab, start_position.x(),
748 L"Chromium", kMoveIterations); 749 L"Chromium", kMoveIterations);
749 // The find box should have moved. 750 // The find box should have moved.
750 EXPECT_TRUE(moved_x_coord != start_position.x()); 751 EXPECT_TRUE(moved_x_coord != start_position.x());
751 752
752 // Search for something guaranteed not to be obscured by the Find box. 753 // Search for something guaranteed not to be obscured by the Find box.
753 EXPECT_EQ(1, FindInPageWchar(tab, L"Done", 754 EXPECT_EQ(1, FindInPageWchar(tab, L"Done",
754 kFwd, kIgnoreCase, &ordinal)); 755 kFwd, kIgnoreCase, &ordinal));
755 // Check the position. 756 // Check the position.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 793
793 // Make sure F3 in a new tab works if Find has previous string to search for. 794 // Make sure F3 in a new tab works if Find has previous string to search for.
794 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, 795 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
795 MAYBE_FindNextInNewTabUsesPrepopulate) { 796 MAYBE_FindNextInNewTabUsesPrepopulate) {
796 // First we navigate to any page. 797 // First we navigate to any page.
797 GURL url = GetURL(kSimple); 798 GURL url = GetURL(kSimple);
798 ui_test_utils::NavigateToURL(browser(), url); 799 ui_test_utils::NavigateToURL(browser(), url);
799 800
800 // Search for 'no_match'. No matches should be found. 801 // Search for 'no_match'. No matches should be found.
801 int ordinal = 0; 802 int ordinal = 0;
802 TabContents* tab = browser()->GetActiveTabContents(); 803 TabContents* tab = chrome::GetActiveTabContents(browser());
803 EXPECT_EQ(0, FindInPageWchar(tab, L"no_match", 804 EXPECT_EQ(0, FindInPageWchar(tab, L"no_match",
804 kFwd, kIgnoreCase, &ordinal)); 805 kFwd, kIgnoreCase, &ordinal));
805 EXPECT_EQ(0, ordinal); 806 EXPECT_EQ(0, ordinal);
806 807
807 // Open another tab (tab B). 808 // Open another tab (tab B).
808 chrome::NewTab(browser()); 809 chrome::NewTab(browser());
809 ui_test_utils::NavigateToURL(browser(), url); 810 ui_test_utils::NavigateToURL(browser(), url);
810 811
811 // Simulate what happens when you press F3 for FindNext. We should get a 812 // Simulate what happens when you press F3 for FindNext. We should get a
812 // response here (a hang means search was aborted). 813 // response here (a hang means search was aborted).
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 GURL url = GetURL(kSimple); 877 GURL url = GetURL(kSimple);
877 ui_test_utils::NavigateToURL(browser(), url); 878 ui_test_utils::NavigateToURL(browser(), url);
878 879
879 chrome::ShowFindBar(browser()); 880 chrome::ShowFindBar(browser());
880 881
881 // Simulate a user clearing the search string. Ideally, we should be 882 // Simulate a user clearing the search string. Ideally, we should be
882 // simulating keypresses here for searching for something and pressing 883 // simulating keypresses here for searching for something and pressing
883 // backspace, but that's been proven flaky in the past, so we go straight to 884 // backspace, but that's been proven flaky in the past, so we go straight to
884 // tab_contents. 885 // tab_contents.
885 FindTabHelper* find_tab_helper = 886 FindTabHelper* find_tab_helper =
886 browser()->GetActiveTabContents()->find_tab_helper(); 887 chrome::GetActiveTabContents(browser())->find_tab_helper();
887 // Stop the (non-existing) find operation, and clear the selection (which 888 // Stop the (non-existing) find operation, and clear the selection (which
888 // signals the UI is still active). 889 // signals the UI is still active).
889 find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage); 890 find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage);
890 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI 891 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI
891 // still responds to browser window resizing. 892 // still responds to browser window resizing.
892 ASSERT_TRUE(find_tab_helper->find_ui_active()); 893 ASSERT_TRUE(find_tab_helper->find_ui_active());
893 } 894 }
894 895
895 // Make sure F3 works after you FindNext a couple of times and end the Find 896 // Make sure F3 works after you FindNext a couple of times and end the Find
896 // session. See issue http://crbug.com/28306. 897 // session. See issue http://crbug.com/28306.
897 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { 898 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) {
898 // First we navigate to a simple page. 899 // First we navigate to a simple page.
899 GURL url = GetURL(kSimple); 900 GURL url = GetURL(kSimple);
900 ui_test_utils::NavigateToURL(browser(), url); 901 ui_test_utils::NavigateToURL(browser(), url);
901 902
902 // Search for 'page'. Should have 1 match. 903 // Search for 'page'. Should have 1 match.
903 int ordinal = 0; 904 int ordinal = 0;
904 TabContents* tab = browser()->GetActiveTabContents(); 905 TabContents* tab = chrome::GetActiveTabContents(browser());
905 EXPECT_EQ(1, FindInPageWchar(tab, L"page", kFwd, kIgnoreCase, &ordinal)); 906 EXPECT_EQ(1, FindInPageWchar(tab, L"page", kFwd, kIgnoreCase, &ordinal));
906 EXPECT_EQ(1, ordinal); 907 EXPECT_EQ(1, ordinal);
907 908
908 // Simulate what happens when you press F3 for FindNext. Still should show 909 // Simulate what happens when you press F3 for FindNext. Still should show
909 // one match. This cleared the pre-populate string at one point (see bug). 910 // one match. This cleared the pre-populate string at one point (see bug).
910 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, string16(), 911 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, string16(),
911 kFwd, kIgnoreCase, &ordinal)); 912 kFwd, kIgnoreCase, &ordinal));
912 EXPECT_EQ(1, ordinal); 913 EXPECT_EQ(1, ordinal);
913 914
914 // End the Find session, thereby making the next F3 start afresh. 915 // End the Find session, thereby making the next F3 start afresh.
915 browser()->GetFindBarController()->EndFindSession( 916 browser()->GetFindBarController()->EndFindSession(
916 FindBarController::kKeepSelectionOnPage, 917 FindBarController::kKeepSelectionOnPage,
917 FindBarController::kKeepResultsInFindBox); 918 FindBarController::kKeepResultsInFindBox);
918 919
919 // Simulate F3 while Find box is closed. Should have 1 match. 920 // Simulate F3 while Find box is closed. Should have 1 match.
920 EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal)); 921 EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal));
921 EXPECT_EQ(1, ordinal); 922 EXPECT_EQ(1, ordinal);
922 } 923 }
923 924
924 // When re-opening the find bar with F3, the find bar should be re-populated 925 // When re-opening the find bar with F3, the find bar should be re-populated
925 // with the last search from the same tab rather than the last overall search. 926 // with the last search from the same tab rather than the last overall search.
926 // http://crbug.com/30006 927 // http://crbug.com/30006
927 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { 928 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) {
928 // First we navigate to any page. 929 // First we navigate to any page.
929 GURL url = GetURL(kSimple); 930 GURL url = GetURL(kSimple);
930 ui_test_utils::NavigateToURL(browser(), url); 931 ui_test_utils::NavigateToURL(browser(), url);
931 932
932 // Find "Default". 933 // Find "Default".
933 int ordinal = 0; 934 int ordinal = 0;
934 TabContents* tab1 = browser()->GetActiveTabContents(); 935 TabContents* tab1 = chrome::GetActiveTabContents(browser());
935 EXPECT_EQ(1, FindInPageWchar(tab1, L"text", kFwd, kIgnoreCase, &ordinal)); 936 EXPECT_EQ(1, FindInPageWchar(tab1, L"text", kFwd, kIgnoreCase, &ordinal));
936 937
937 // Create a second tab. 938 // Create a second tab.
938 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It 939 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It
939 // could be some delicate assumption about the tab starting off unselected or 940 // could be some delicate assumption about the tab starting off unselected or
940 // something relating to user gesture. 941 // something relating to user gesture.
941 browser()->AddBlankTab(true); 942 browser()->AddBlankTab(true);
942 ui_test_utils::NavigateToURL(browser(), url); 943 ui_test_utils::NavigateToURL(browser(), url);
943 TabContents* tab2 = browser()->GetActiveTabContents(); 944 TabContents* tab2 = chrome::GetActiveTabContents(browser());
944 EXPECT_NE(tab1, tab2); 945 EXPECT_NE(tab1, tab2);
945 946
946 // Find "given". 947 // Find "given".
947 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); 948 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal);
948 949
949 // Switch back to first tab. 950 // Switch back to first tab.
950 browser()->ActivateTabAt(0, false); 951 chrome::ActivateTabAt(browser(), 0, false);
951 browser()->GetFindBarController()->EndFindSession( 952 browser()->GetFindBarController()->EndFindSession(
952 FindBarController::kKeepSelectionOnPage, 953 FindBarController::kKeepSelectionOnPage,
953 FindBarController::kKeepResultsInFindBox); 954 FindBarController::kKeepResultsInFindBox);
954 // Simulate F3. 955 // Simulate F3.
955 ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal); 956 ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal);
956 EXPECT_EQ(tab1->find_tab_helper()->find_text(), WideToUTF16(L"text")); 957 EXPECT_EQ(tab1->find_tab_helper()->find_text(), WideToUTF16(L"text"));
957 } 958 }
958 959
959 // This tests that whenever you close and reopen the Find bar, it should show 960 // This tests that whenever you close and reopen the Find bar, it should show
960 // the last search entered in that tab. http://crbug.com/40121. 961 // the last search entered in that tab. http://crbug.com/40121.
961 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) { 962 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) {
962 #if defined(OS_MACOSX) 963 #if defined(OS_MACOSX)
963 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 964 // FindInPage on Mac doesn't use prepopulated values. Search there is global.
964 return; 965 return;
965 #endif 966 #endif
966 967
967 // First we navigate to any page. 968 // First we navigate to any page.
968 GURL url = GetURL(kSimple); 969 GURL url = GetURL(kSimple);
969 ui_test_utils::NavigateToURL(browser(), url); 970 ui_test_utils::NavigateToURL(browser(), url);
970 971
971 // Search for the word "page". 972 // Search for the word "page".
972 int ordinal = 0; 973 int ordinal = 0;
973 TabContents* tab1 = browser()->GetActiveTabContents(); 974 TabContents* tab1 = chrome::GetActiveTabContents(browser());
974 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); 975 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
975 976
976 // Open the Find box. 977 // Open the Find box.
977 EnsureFindBoxOpen(); 978 EnsureFindBoxOpen();
978 979
979 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 980 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
980 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); 981 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
981 982
982 // Close the Find box. 983 // Close the Find box.
983 browser()->GetFindBarController()->EndFindSession( 984 browser()->GetFindBarController()->EndFindSession(
(...skipping 17 matching lines...) Expand all
1001 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 1002 // FindInPage on Mac doesn't use prepopulated values. Search there is global.
1002 return; 1003 return;
1003 #endif 1004 #endif
1004 1005
1005 // First we navigate to any page. 1006 // First we navigate to any page.
1006 GURL url = GetURL(kSimple); 1007 GURL url = GetURL(kSimple);
1007 ui_test_utils::NavigateToURL(browser(), url); 1008 ui_test_utils::NavigateToURL(browser(), url);
1008 1009
1009 // Search for the word "page". 1010 // Search for the word "page".
1010 int ordinal = 0; 1011 int ordinal = 0;
1011 TabContents* tab1 = browser()->GetActiveTabContents(); 1012 TabContents* tab1 = chrome::GetActiveTabContents(browser());
1012 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); 1013 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
1013 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); 1014 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1014 1015
1015 // Now create a second tab and load the same page. 1016 // Now create a second tab and load the same page.
1016 browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); 1017 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
1017 TabContents* tab2 = browser()->GetActiveTabContents(); 1018 TabContents* tab2 = chrome::GetActiveTabContents(browser());
1018 EXPECT_NE(tab1, tab2); 1019 EXPECT_NE(tab1, tab2);
1019 1020
1020 // Open the Find box. 1021 // Open the Find box.
1021 EnsureFindBoxOpen(); 1022 EnsureFindBoxOpen();
1022 1023
1023 // The new tab should have "page" prepopulated, since that was the last search 1024 // The new tab should have "page" prepopulated, since that was the last search
1024 // in the first tab. 1025 // in the first tab.
1025 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 1026 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1026 // But it should not seem like a search has been issued. 1027 // But it should not seem like a search has been issued.
1027 EXPECT_EQ(string16(), GetMatchCountText()); 1028 EXPECT_EQ(string16(), GetMatchCountText());
1028 } 1029 }
1029 1030
1030 // This makes sure that we can search for A in tabA, then for B in tabB and 1031 // This makes sure that we can search for A in tabA, then for B in tabB and
1031 // when we come back to tabA we should still see A (because that was the last 1032 // when we come back to tabA we should still see A (because that was the last
1032 // search in that tab). 1033 // search in that tab).
1033 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) { 1034 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) {
1034 #if defined(OS_MACOSX) 1035 #if defined(OS_MACOSX)
1035 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 1036 // FindInPage on Mac doesn't use prepopulated values. Search there is global.
1036 return; 1037 return;
1037 #endif 1038 #endif
1038 1039
1039 // First we navigate to any page. 1040 // First we navigate to any page.
1040 GURL url = GetURL(kSimple); 1041 GURL url = GetURL(kSimple);
1041 ui_test_utils::NavigateToURL(browser(), url); 1042 ui_test_utils::NavigateToURL(browser(), url);
1042 1043
1043 // Search for the word "page". 1044 // Search for the word "page".
1044 int ordinal = 0; 1045 int ordinal = 0;
1045 TabContents* tab1 = browser()->GetActiveTabContents(); 1046 TabContents* tab1 = chrome::GetActiveTabContents(browser());
1046 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); 1047 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
1047 1048
1048 // Open the Find box. 1049 // Open the Find box.
1049 EnsureFindBoxOpen(); 1050 EnsureFindBoxOpen();
1050 1051
1051 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 1052 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1052 1053
1053 // Close the Find box. 1054 // Close the Find box.
1054 browser()->GetFindBarController()->EndFindSession( 1055 browser()->GetFindBarController()->EndFindSession(
1055 FindBarController::kKeepSelectionOnPage, 1056 FindBarController::kKeepSelectionOnPage,
1056 FindBarController::kKeepResultsInFindBox); 1057 FindBarController::kKeepResultsInFindBox);
1057 1058
1058 // Now create a second tab and load the same page. 1059 // Now create a second tab and load the same page.
1059 browser()->AddBlankTab(true); 1060 browser()->AddBlankTab(true);
1060 ui_test_utils::NavigateToURL(browser(), url); 1061 ui_test_utils::NavigateToURL(browser(), url);
1061 TabContents* tab2 = browser()->GetActiveTabContents(); 1062 TabContents* tab2 = chrome::GetActiveTabContents(browser());
1062 EXPECT_NE(tab1, tab2); 1063 EXPECT_NE(tab1, tab2);
1063 1064
1064 // Search for the word "text". 1065 // Search for the word "text".
1065 FindInPageWchar(tab2, L"text", kFwd, kIgnoreCase, &ordinal); 1066 FindInPageWchar(tab2, L"text", kFwd, kIgnoreCase, &ordinal);
1066 1067
1067 // Go back to the first tab and make sure we have NOT switched the prepopulate 1068 // Go back to the first tab and make sure we have NOT switched the prepopulate
1068 // text to "text". 1069 // text to "text".
1069 browser()->ActivateTabAt(0, false); 1070 chrome::ActivateTabAt(browser(), 0, false);
1070 1071
1071 // Open the Find box. 1072 // Open the Find box.
1072 EnsureFindBoxOpen(); 1073 EnsureFindBoxOpen();
1073 1074
1074 // After the Find box has been reopened, it should have been prepopulated with 1075 // After the Find box has been reopened, it should have been prepopulated with
1075 // the word "page" again, since that was the last search in that tab. 1076 // the word "page" again, since that was the last search in that tab.
1076 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText()); 1077 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1077 1078
1078 // Close the Find box. 1079 // Close the Find box.
1079 browser()->GetFindBarController()->EndFindSession( 1080 browser()->GetFindBarController()->EndFindSession(
(...skipping 26 matching lines...) Expand all
1106 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 1107 // FindInPage on Mac doesn't use prepopulated values. Search there is global.
1107 return; 1108 return;
1108 #endif 1109 #endif
1109 1110
1110 // First we navigate to the "simple" test page. 1111 // First we navigate to the "simple" test page.
1111 GURL url = GetURL(kSimple); 1112 GURL url = GetURL(kSimple);
1112 ui_test_utils::NavigateToURL(browser(), url); 1113 ui_test_utils::NavigateToURL(browser(), url);
1113 1114
1114 // Search for the word "page" in the normal browser tab. 1115 // Search for the word "page" in the normal browser tab.
1115 int ordinal = 0; 1116 int ordinal = 0;
1116 TabContents* tab1 = browser()->GetActiveTabContents(); 1117 TabContents* tab1 = chrome::GetActiveTabContents(browser());
1117 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); 1118 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
1118 1119
1119 // Open the Find box. 1120 // Open the Find box.
1120 EnsureFindBoxOpenForBrowser(browser()); 1121 EnsureFindBoxOpenForBrowser(browser());
1121 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); 1122 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
1122 1123
1123 // Close the Find box. 1124 // Close the Find box.
1124 browser()->GetFindBarController()->EndFindSession( 1125 browser()->GetFindBarController()->EndFindSession(
1125 FindBarController::kKeepSelectionOnPage, 1126 FindBarController::kKeepSelectionOnPage,
1126 FindBarController::kKeepResultsInFindBox); 1127 FindBarController::kKeepResultsInFindBox);
1127 1128
1128 // Open a new incognito window and navigate to the same page. 1129 // Open a new incognito window and navigate to the same page.
1129 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); 1130 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
1130 Browser* incognito_browser = Browser::Create(incognito_profile); 1131 Browser* incognito_browser = Browser::Create(incognito_profile);
1131 ui_test_utils::WindowedNotificationObserver observer( 1132 ui_test_utils::WindowedNotificationObserver observer(
1132 content::NOTIFICATION_LOAD_STOP, 1133 content::NOTIFICATION_LOAD_STOP,
1133 content::NotificationService::AllSources()); 1134 content::NotificationService::AllSources());
1134 incognito_browser->AddSelectedTabWithURL( 1135 chrome::AddSelectedTabWithURL(incognito_browser, url,
1135 url, content::PAGE_TRANSITION_START_PAGE); 1136 content::PAGE_TRANSITION_START_PAGE);
1136 observer.Wait(); 1137 observer.Wait();
1137 incognito_browser->window()->Show(); 1138 incognito_browser->window()->Show();
1138 1139
1139 // Open the find box and make sure that it is prepopulated with "page". 1140 // Open the find box and make sure that it is prepopulated with "page".
1140 EnsureFindBoxOpenForBrowser(incognito_browser); 1141 EnsureFindBoxOpenForBrowser(incognito_browser);
1141 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser)); 1142 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser));
1142 1143
1143 // Search for the word "text" in the incognito tab. 1144 // Search for the word "text" in the incognito tab.
1144 TabContents* incognito_tab = 1145 TabContents* incognito_tab = chrome::GetActiveTabContents(incognito_browser);
1145 incognito_browser->GetActiveTabContents();
1146 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text", 1146 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text",
1147 kFwd, kIgnoreCase, &ordinal)); 1147 kFwd, kIgnoreCase, &ordinal));
1148 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser)); 1148 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser));
1149 1149
1150 // Close the Find box. 1150 // Close the Find box.
1151 incognito_browser->GetFindBarController()->EndFindSession( 1151 incognito_browser->GetFindBarController()->EndFindSession(
1152 FindBarController::kKeepSelectionOnPage, 1152 FindBarController::kKeepSelectionOnPage,
1153 FindBarController::kKeepResultsInFindBox); 1153 FindBarController::kKeepResultsInFindBox);
1154 1154
1155 // Now open a new tab in the original (non-incognito) browser. 1155 // Now open a new tab in the original (non-incognito) browser.
1156 browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); 1156 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
1157 TabContents* tab2 = browser()->GetActiveTabContents(); 1157 TabContents* tab2 = chrome::GetActiveTabContents(browser());
1158 EXPECT_NE(tab1, tab2); 1158 EXPECT_NE(tab1, tab2);
1159 1159
1160 // Open the Find box and make sure it is prepopulated with the search term 1160 // Open the Find box and make sure it is prepopulated with the search term
1161 // from the original browser, not the search term from the incognito window. 1161 // from the original browser, not the search term from the incognito window.
1162 EnsureFindBoxOpenForBrowser(browser()); 1162 EnsureFindBoxOpenForBrowser(browser());
1163 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); 1163 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
1164 } 1164 }
1165 1165
1166 // This makes sure that dismissing the find bar with kActivateSelection works. 1166 // This makes sure that dismissing the find bar with kActivateSelection works.
1167 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) { 1167 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) {
1168 // First we navigate to our test content. 1168 // First we navigate to our test content.
1169 GURL url = GetURL(kLinkPage); 1169 GURL url = GetURL(kLinkPage);
1170 ui_test_utils::NavigateToURL(browser(), url); 1170 ui_test_utils::NavigateToURL(browser(), url);
1171 1171
1172 TabContents* tab = browser()->GetActiveTabContents(); 1172 TabContents* tab = chrome::GetActiveTabContents(browser());
1173 int ordinal = 0; 1173 int ordinal = 0;
1174 FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal); 1174 FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal);
1175 EXPECT_EQ(ordinal, 1); 1175 EXPECT_EQ(ordinal, 1);
1176 1176
1177 // End the find session, click on the link. 1177 // End the find session, click on the link.
1178 ui_test_utils::WindowedNotificationObserver observer( 1178 ui_test_utils::WindowedNotificationObserver observer(
1179 content::NOTIFICATION_LOAD_STOP, 1179 content::NOTIFICATION_LOAD_STOP,
1180 content::Source<NavigationController>( 1180 content::Source<NavigationController>(
1181 &tab->web_contents()->GetController())); 1181 &tab->web_contents()->GetController()));
1182 tab->find_tab_helper()->StopFinding( 1182 tab->find_tab_helper()->StopFinding(
1183 FindBarController::kActivateSelectionOnPage); 1183 FindBarController::kActivateSelectionOnPage);
1184 observer.Wait(); 1184 observer.Wait();
1185 } 1185 }
1186 1186
1187 // Tests that FindBar fits within a narrow browser window. 1187 // Tests that FindBar fits within a narrow browser window.
1188 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FitWindow) { 1188 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FitWindow) {
1189 Browser::CreateParams params(Browser::TYPE_POPUP, browser()->profile()); 1189 Browser::CreateParams params(Browser::TYPE_POPUP, browser()->profile());
1190 params.initial_bounds = gfx::Rect(0, 0, 250, 500); 1190 params.initial_bounds = gfx::Rect(0, 0, 250, 500);
1191 Browser* popup = Browser::CreateWithParams(params); 1191 Browser* popup = Browser::CreateWithParams(params);
1192 ui_test_utils::WindowedNotificationObserver observer( 1192 ui_test_utils::WindowedNotificationObserver observer(
1193 content::NOTIFICATION_LOAD_STOP, 1193 content::NOTIFICATION_LOAD_STOP,
1194 content::NotificationService::AllSources()); 1194 content::NotificationService::AllSources());
1195 popup->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), 1195 chrome::AddSelectedTabWithURL(popup, GURL(chrome::kAboutBlankURL),
1196 content::PAGE_TRANSITION_LINK); 1196 content::PAGE_TRANSITION_LINK);
1197 // Wait for the page to finish loading. 1197 // Wait for the page to finish loading.
1198 observer.Wait(); 1198 observer.Wait();
1199 popup->window()->Show(); 1199 popup->window()->Show();
1200 1200
1201 // On GTK, bounds change is asynchronous. 1201 // On GTK, bounds change is asynchronous.
1202 MessageLoop::current()->RunAllPending(); 1202 MessageLoop::current()->RunAllPending();
1203 1203
1204 EnsureFindBoxOpenForBrowser(popup); 1204 EnsureFindBoxOpenForBrowser(popup);
1205 1205
1206 // GTK adjusts FindBar size asynchronously. 1206 // GTK adjusts FindBar size asynchronously.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 ui_test_utils::RunAllPendingInMessageLoop(); // Needed on Linux. 1246 ui_test_utils::RunAllPendingInMessageLoop(); // Needed on Linux.
1247 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); 1247 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL));
1248 1248
1249 ui_test_utils::NavigateToURLWithDisposition( 1249 ui_test_utils::NavigateToURLWithDisposition(
1250 browser(), url, NEW_FOREGROUND_TAB, 1250 browser(), url, NEW_FOREGROUND_TAB,
1251 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1251 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1252 chrome::CloseTab(browser()); 1252 chrome::CloseTab(browser());
1253 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); 1253 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL));
1254 EXPECT_EQ(position, position2); 1254 EXPECT_EQ(position, position2);
1255 } 1255 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/extensions/shell_window.cc ('k') | chrome/browser/ui/fullscreen_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698