| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/keyboard_codes.h" | 5 #include "base/keyboard_codes.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
| 9 #include "chrome/browser/find_bar_controller.h" | 9 #include "chrome/browser/find_bar_controller.h" |
| 10 #include "chrome/browser/find_notification_details.h" | 10 #include "chrome/browser/find_notification_details.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 const bool kIgnoreCase = false; | 36 const bool kIgnoreCase = false; |
| 37 const bool kCaseSensitive = true; | 37 const bool kCaseSensitive = true; |
| 38 | 38 |
| 39 class FindInPageControllerTest : public InProcessBrowserTest { | 39 class FindInPageControllerTest : public InProcessBrowserTest { |
| 40 public: | 40 public: |
| 41 FindInPageControllerTest() { | 41 FindInPageControllerTest() { |
| 42 EnableDOMAutomation(); | 42 EnableDOMAutomation(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 protected: | 45 protected: |
| 46 void GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) { | 46 bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) { |
| 47 FindBarTesting* find_bar = | 47 FindBarTesting* find_bar = |
| 48 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); | 48 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); |
| 49 find_bar->GetFindBarWindowInfo(position, fully_visible); | 49 return find_bar->GetFindBarWindowInfo(position, fully_visible); |
| 50 } | 50 } |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // This test loads a page with frames and starts FindInPage requests. | 53 // This test loads a page with frames and starts FindInPage requests. |
| 54 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { | 54 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { |
| 55 HTTPTestServer* server = StartHTTPServer(); | 55 HTTPTestServer* server = StartHTTPServer(); |
| 56 | 56 |
| 57 // First we navigate to our frames page. | 57 // First we navigate to our frames page. |
| 58 GURL url = server->TestServerPageW(kFramePage); | 58 GURL url = server->TestServerPageW(kFramePage); |
| 59 ui_test_utils::NavigateToURL(browser(), url); | 59 ui_test_utils::NavigateToURL(browser(), url); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 ui_test_utils::NavigateToURL(browser(), url); | 467 ui_test_utils::NavigateToURL(browser(), url); |
| 468 | 468 |
| 469 // Open the Find window with animations disabled. | 469 // Open the Find window with animations disabled. |
| 470 FindBarHost::disable_animations_during_testing_ = true; | 470 FindBarHost::disable_animations_during_testing_ = true; |
| 471 browser()->ShowFindBar(); | 471 browser()->ShowFindBar(); |
| 472 | 472 |
| 473 gfx::Point position; | 473 gfx::Point position; |
| 474 bool fully_visible = false; | 474 bool fully_visible = false; |
| 475 | 475 |
| 476 // Make sure it is open. | 476 // Make sure it is open. |
| 477 GetFindBarWindowInfo(&position, &fully_visible); | 477 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
| 478 EXPECT_TRUE(fully_visible); | 478 EXPECT_TRUE(fully_visible); |
| 479 | 479 |
| 480 // Reload the tab and make sure Find window doesn't go away. | 480 // Reload the tab and make sure Find window doesn't go away. |
| 481 browser()->Reload(); | 481 browser()->Reload(); |
| 482 | 482 |
| 483 GetFindBarWindowInfo(&position, &fully_visible); | 483 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
| 484 EXPECT_TRUE(fully_visible); | 484 EXPECT_TRUE(fully_visible); |
| 485 | 485 |
| 486 // Navigate and make sure the Find window goes away. | 486 // Navigate and make sure the Find window goes away. |
| 487 ui_test_utils::NavigateToURL(browser(), url2); | 487 ui_test_utils::NavigateToURL(browser(), url2); |
| 488 | 488 |
| 489 GetFindBarWindowInfo(&position, &fully_visible); | 489 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
| 490 EXPECT_FALSE(fully_visible); | 490 EXPECT_FALSE(fully_visible); |
| 491 } | 491 } |
| 492 | 492 |
| 493 // Make sure Find box disappears when History/Downloads page is opened, and | 493 // Make sure Find box disappears when History/Downloads page is opened, and |
| 494 // when a New Tab is opened. | 494 // when a New Tab is opened. |
| 495 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 495 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
| 496 FindDisappearOnNewTabAndHistory) { | 496 FindDisappearOnNewTabAndHistory) { |
| 497 HTTPTestServer* server = StartHTTPServer(); | 497 HTTPTestServer* server = StartHTTPServer(); |
| 498 | 498 |
| 499 // First we navigate to our special focus tracking page. | 499 // First we navigate to our special focus tracking page. |
| 500 GURL url = server->TestServerPageW(kSimplePage); | 500 GURL url = server->TestServerPageW(kSimplePage); |
| 501 ui_test_utils::NavigateToURL(browser(), url); | 501 ui_test_utils::NavigateToURL(browser(), url); |
| 502 | 502 |
| 503 // Open the Find window with animations disabled. | 503 // Open the Find window with animations disabled. |
| 504 FindBarHost::disable_animations_during_testing_ = true; | 504 FindBarHost::disable_animations_during_testing_ = true; |
| 505 browser()->ShowFindBar(); | 505 browser()->ShowFindBar(); |
| 506 | 506 |
| 507 gfx::Point position; | 507 gfx::Point position; |
| 508 bool fully_visible = false; | 508 bool fully_visible = false; |
| 509 | 509 |
| 510 // Make sure it is open. | 510 // Make sure it is open. |
| 511 GetFindBarWindowInfo(&position, &fully_visible); | 511 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
| 512 EXPECT_TRUE(fully_visible); | 512 EXPECT_TRUE(fully_visible); |
| 513 | 513 |
| 514 // Open another tab (tab B). | 514 // Open another tab (tab B). |
| 515 browser()->NewTab(); | 515 browser()->NewTab(); |
| 516 ui_test_utils::NavigateToURL(browser(), url); | 516 ui_test_utils::NavigateToURL(browser(), url); |
| 517 | 517 |
| 518 // Make sure Find box is closed. | 518 // Make sure Find box is closed. |
| 519 GetFindBarWindowInfo(&position, &fully_visible); | 519 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
| 520 EXPECT_FALSE(fully_visible); | 520 EXPECT_FALSE(fully_visible); |
| 521 | 521 |
| 522 // Close tab B. | 522 // Close tab B. |
| 523 browser()->CloseTab(); | 523 browser()->CloseTab(); |
| 524 | 524 |
| 525 // Make sure Find window appears again. | 525 // Make sure Find window appears again. |
| 526 GetFindBarWindowInfo(&position, &fully_visible); | 526 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
| 527 EXPECT_TRUE(fully_visible); | 527 EXPECT_TRUE(fully_visible); |
| 528 | 528 |
| 529 browser()->ShowHistoryTab(); | 529 browser()->ShowHistoryTab(); |
| 530 | 530 |
| 531 // Make sure Find box is closed. | 531 // Make sure Find box is closed. |
| 532 GetFindBarWindowInfo(&position, &fully_visible); | 532 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
| 533 EXPECT_FALSE(fully_visible); | 533 EXPECT_FALSE(fully_visible); |
| 534 } | 534 } |
| 535 | 535 |
| 536 // Make sure Find box moves out of the way if it is obscuring the active match. | 536 // Make sure Find box moves out of the way if it is obscuring the active match. |
| 537 // Flaky, see http://crbug.com/16447. | 537 // Flaky, see http://crbug.com/16447. |
| 538 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 538 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
| 539 FLAKY_FindMovesWhenObscuring) { | 539 FLAKY_FindMovesWhenObscuring) { |
| 540 HTTPTestServer* server = StartHTTPServer(); | 540 HTTPTestServer* server = StartHTTPServer(); |
| 541 | 541 |
| 542 GURL url = server->TestServerPageW(kMoveIfOver); | 542 GURL url = server->TestServerPageW(kMoveIfOver); |
| 543 ui_test_utils::NavigateToURL(browser(), url); | 543 ui_test_utils::NavigateToURL(browser(), url); |
| 544 | 544 |
| 545 // Open the Find window with animations disabled. | 545 // Open the Find window with animations disabled. |
| 546 FindBarHost::disable_animations_during_testing_ = true; | 546 FindBarHost::disable_animations_during_testing_ = true; |
| 547 browser()->ShowFindBar(); | 547 browser()->ShowFindBar(); |
| 548 | 548 |
| 549 gfx::Point start_position; | 549 gfx::Point start_position; |
| 550 gfx::Point position; | 550 gfx::Point position; |
| 551 bool fully_visible = false; | 551 bool fully_visible = false; |
| 552 | 552 |
| 553 // Make sure it is open. | 553 // Make sure it is open. |
| 554 GetFindBarWindowInfo(&start_position, &fully_visible); | 554 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible)); |
| 555 EXPECT_TRUE(fully_visible); | 555 EXPECT_TRUE(fully_visible); |
| 556 | 556 |
| 557 // Search for 'dream' which the Find box is obscuring. | 557 // Search for 'dream' which the Find box is obscuring. |
| 558 int ordinal = 0; | 558 int ordinal = 0; |
| 559 TabContents* tab = browser()->GetSelectedTabContents(); | 559 TabContents* tab = browser()->GetSelectedTabContents(); |
| 560 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"dream", | 560 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"dream", |
| 561 kFwd, kIgnoreCase, &ordinal)); | 561 kFwd, kIgnoreCase, &ordinal)); |
| 562 EXPECT_EQ(1, ordinal); | 562 EXPECT_EQ(1, ordinal); |
| 563 | 563 |
| 564 // Make sure Find box has moved. | 564 // Make sure Find box has moved. |
| 565 GetFindBarWindowInfo(&position, &fully_visible); | 565 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
| 566 EXPECT_TRUE(fully_visible); |
| 566 EXPECT_EQ(start_position.y(), position.y()); | 567 EXPECT_EQ(start_position.y(), position.y()); |
| 568 if (start_position.x() == position.x()) { |
| 569 // Failure case. Try to gather more data. |
| 570 std::string debug_msg = "Position check failed once. "; |
| 571 if (!GetFindBarWindowInfo(&position, &fully_visible)) { |
| 572 debug_msg += "Get failed. "; |
| 573 } else { |
| 574 if (start_position.x() == position.x()) |
| 575 debug_msg += "Still the same. "; |
| 576 else |
| 577 debug_msg += "They now differ. "; |
| 578 } |
| 579 // Force the failure. |
| 580 EXPECT_STREQ("", debug_msg.c_str()); |
| 581 } |
| 567 EXPECT_NE(start_position.x(), position.x()); | 582 EXPECT_NE(start_position.x(), position.x()); |
| 568 EXPECT_TRUE(fully_visible); | |
| 569 | 583 |
| 570 // Search for 'Too much' which the Find box is not obscuring. | 584 // Search for 'Too much' which the Find box is not obscuring. |
| 571 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"Too much", | 585 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"Too much", |
| 572 kFwd, kIgnoreCase, &ordinal)); | 586 kFwd, kIgnoreCase, &ordinal)); |
| 573 EXPECT_EQ(1, ordinal); | 587 EXPECT_EQ(1, ordinal); |
| 574 | 588 |
| 575 // Make sure Find box has moved back to its original location. | 589 // Make sure Find box has moved back to its original location. |
| 576 GetFindBarWindowInfo(&position, &fully_visible); | 590 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
| 591 EXPECT_TRUE(fully_visible); |
| 577 EXPECT_EQ(start_position, position); | 592 EXPECT_EQ(start_position, position); |
| 578 EXPECT_TRUE(fully_visible); | |
| 579 } | 593 } |
| 580 | 594 |
| 581 // Make sure F3 in a new tab works if Find has previous string to search for. | 595 // Make sure F3 in a new tab works if Find has previous string to search for. |
| 582 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 596 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
| 583 FindNextInNewTabUsesPrepopulate) { | 597 FindNextInNewTabUsesPrepopulate) { |
| 584 HTTPTestServer* server = StartHTTPServer(); | 598 HTTPTestServer* server = StartHTTPServer(); |
| 585 | 599 |
| 586 // First we navigate to any page. | 600 // First we navigate to any page. |
| 587 GURL url = server->TestServerPageW(kSimplePage); | 601 GURL url = server->TestServerPageW(kSimplePage); |
| 588 ui_test_utils::NavigateToURL(browser(), url); | 602 ui_test_utils::NavigateToURL(browser(), url); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 // backspace, but that's been proven flaky in the past, so we go straight to | 682 // backspace, but that's been proven flaky in the past, so we go straight to |
| 669 // tab_contents. | 683 // tab_contents. |
| 670 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 684 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
| 671 // Stop the (non-existing) find operation, and clear the selection (which | 685 // Stop the (non-existing) find operation, and clear the selection (which |
| 672 // signals the UI is still active). | 686 // signals the UI is still active). |
| 673 tab_contents->StopFinding(true); | 687 tab_contents->StopFinding(true); |
| 674 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI | 688 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI |
| 675 // still responds to browser window resizing. | 689 // still responds to browser window resizing. |
| 676 ASSERT_TRUE(tab_contents->find_ui_active()); | 690 ASSERT_TRUE(tab_contents->find_ui_active()); |
| 677 } | 691 } |
| OLD | NEW |