| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "content/browser/web_contents/web_contents_impl.h" | 7 #include "content/browser/web_contents/web_contents_impl.h" |
| 8 #include "content/public/browser/notification_types.h" | 8 #include "content/public/browser/notification_types.h" |
| 9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
| 10 #include "content/public/test/browser_test_utils.h" | |
| 11 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
| 12 #include "content/public/test/content_browser_test_utils.h" | 11 #include "content/public/test/content_browser_test_utils.h" |
| 13 #include "content/public/test/test_navigation_observer.h" | 12 #include "content/public/test/test_navigation_observer.h" |
| 14 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
| 15 #include "content/shell/browser/shell.h" | 14 #include "content/shell/browser/shell.h" |
| 16 #include "content/test/content_browser_test_utils_internal.h" | 15 #include "content/test/content_browser_test_utils_internal.h" |
| 17 #include "net/dns/mock_host_resolver.h" | 16 #include "net/dns/mock_host_resolver.h" |
| 18 #include "third_party/WebKit/public/web/WebFindOptions.h" | 17 #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 19 | 18 |
| 20 namespace content { | 19 namespace content { |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 469 |
| 471 // Remove a frame. | 470 // Remove a frame. |
| 472 FrameTreeNode* root = contents()->GetFrameTree()->root(); | 471 FrameTreeNode* root = contents()->GetFrameTree()->root(); |
| 473 root->RemoveChild(root->child_at(0)); | 472 root->RemoveChild(root->child_at(0)); |
| 474 | 473 |
| 475 // The number of matches and active match ordinal should update automatically | 474 // The number of matches and active match ordinal should update automatically |
| 476 // to exclude the matches from the removed frame. | 475 // to exclude the matches from the removed frame. |
| 477 results = delegate()->GetFindResults(); | 476 results = delegate()->GetFindResults(); |
| 478 EXPECT_EQ(12, results.number_of_matches); | 477 EXPECT_EQ(12, results.number_of_matches); |
| 479 EXPECT_EQ(8, results.active_match_ordinal); | 478 EXPECT_EQ(8, results.active_match_ordinal); |
| 480 } | |
| 481 | 479 |
| 482 // Tests adding a frame during a find session. | 480 // TODO(paulemeyer): Once adding frames mid-session is handled, test that too. |
| 483 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(AddFrame)) { | |
| 484 LoadMultiFramePage(2 /* height */, GetParam() /* cross_process */); | |
| 485 | |
| 486 blink::WebFindOptions options; | |
| 487 Find("result", options); | |
| 488 options.findNext = true; | |
| 489 Find("result", options); | |
| 490 Find("result", options); | |
| 491 Find("result", options); | |
| 492 Find("result", options); | |
| 493 delegate()->WaitForFinalReply(); | |
| 494 | |
| 495 FindResults results = delegate()->GetFindResults(); | |
| 496 EXPECT_EQ(last_request_id(), results.request_id); | |
| 497 EXPECT_EQ(21, results.number_of_matches); | |
| 498 EXPECT_EQ(5, results.active_match_ordinal); | |
| 499 | |
| 500 // Add a frame. It contains 5 new matches. | |
| 501 std::string url = embedded_test_server()->GetURL( | |
| 502 GetParam() ? "b.com" : "a.com", "/find_in_simple_page.html").spec(); | |
| 503 std::string script = std::string() + | |
| 504 "var frame = document.createElement('iframe');" + | |
| 505 "frame.src = '" + url + "';" + | |
| 506 "document.body.appendChild(frame);"; | |
| 507 delegate()->MarkNextReply(); | |
| 508 ASSERT_TRUE(ExecuteScript(shell(), script)); | |
| 509 delegate()->WaitForNextReply(); | |
| 510 | |
| 511 // The number of matches should update automatically to include the matches | |
| 512 // from the newly added frame. | |
| 513 results = delegate()->GetFindResults(); | |
| 514 EXPECT_EQ(26, results.number_of_matches); | |
| 515 EXPECT_EQ(5, results.active_match_ordinal); | |
| 516 } | |
| 517 | |
| 518 // Tests adding a frame during a find session where there were previously no | |
| 519 // matches. | |
| 520 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(AddFrameAfterNoMatches)) { | |
| 521 TestNavigationObserver navigation_observer(contents()); | |
| 522 NavigateToURL(shell(), GURL("about:blank")); | |
| 523 EXPECT_TRUE(navigation_observer.last_navigation_succeeded()); | |
| 524 | |
| 525 blink::WebFindOptions default_options; | |
| 526 Find("result", default_options); | |
| 527 delegate()->WaitForFinalReply(); | |
| 528 | |
| 529 // Initially, there are no matches on the page. | |
| 530 FindResults results = delegate()->GetFindResults(); | |
| 531 EXPECT_EQ(last_request_id(), results.request_id); | |
| 532 EXPECT_EQ(0, results.number_of_matches); | |
| 533 EXPECT_EQ(0, results.active_match_ordinal); | |
| 534 | |
| 535 // Add a frame. It contains 5 new matches. | |
| 536 std::string url = | |
| 537 embedded_test_server()->GetURL("/find_in_simple_page.html").spec(); | |
| 538 std::string script = std::string() + | |
| 539 "var frame = document.createElement('iframe');" + | |
| 540 "frame.src = '" + url + "';" + | |
| 541 "document.body.appendChild(frame);"; | |
| 542 delegate()->MarkNextReply(); | |
| 543 ASSERT_TRUE(ExecuteScript(shell(), script)); | |
| 544 delegate()->WaitForNextReply(); | |
| 545 | |
| 546 // The matches from the new frame should be found automatically, and the first | |
| 547 // match in the frame should be activated. | |
| 548 results = delegate()->GetFindResults(); | |
| 549 EXPECT_EQ(5, results.number_of_matches); | |
| 550 EXPECT_EQ(1, results.active_match_ordinal); | |
| 551 } | |
| 552 | |
| 553 // Tests a frame navigating to a different page during a find session. | |
| 554 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(NavigateFrame)) { | |
| 555 LoadMultiFramePage(2 /* height */, GetParam() /* cross_process */); | |
| 556 | |
| 557 blink::WebFindOptions options; | |
| 558 Find("result", options); | |
| 559 options.findNext = true; | |
| 560 options.forward = false; | |
| 561 Find("result", options); | |
| 562 Find("result", options); | |
| 563 Find("result", options); | |
| 564 delegate()->WaitForFinalReply(); | |
| 565 | |
| 566 FindResults results = delegate()->GetFindResults(); | |
| 567 EXPECT_EQ(last_request_id(), results.request_id); | |
| 568 EXPECT_EQ(21, results.number_of_matches); | |
| 569 EXPECT_EQ(19, results.active_match_ordinal); | |
| 570 | |
| 571 // Navigate one of the empty frames to a page with 5 matches. | |
| 572 FrameTreeNode* root = | |
| 573 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 574 GetFrameTree()->root(); | |
| 575 GURL url(embedded_test_server()->GetURL( | |
| 576 GetParam() ? "b.com" : "a.com", "/find_in_simple_page.html")); | |
| 577 delegate()->MarkNextReply(); | |
| 578 TestNavigationObserver navigation_observer(contents()); | |
| 579 NavigateFrameToURL(root->child_at(0)->child_at(1)->child_at(0), url); | |
| 580 EXPECT_TRUE(navigation_observer.last_navigation_succeeded()); | |
| 581 delegate()->WaitForNextReply(); | |
| 582 | |
| 583 // The navigation results in an extra reply before the one we care about. This | |
| 584 // extra reply happens because the RenderFrameHost changes before it navigates | |
| 585 // (because the navigation is cross-origin). The first reply will not change | |
| 586 // the number of matches because the frame that is navigating was empty | |
| 587 // before. | |
| 588 if (delegate()->GetFindResults().number_of_matches == 21) { | |
| 589 delegate()->MarkNextReply(); | |
| 590 delegate()->WaitForNextReply(); | |
| 591 } | |
| 592 | |
| 593 // The number of matches and the active match ordinal should update | |
| 594 // automatically to include the new matches. | |
| 595 results = delegate()->GetFindResults(); | |
| 596 EXPECT_EQ(26, results.number_of_matches); | |
| 597 EXPECT_EQ(24, results.active_match_ordinal); | |
| 598 } | 481 } |
| 599 | 482 |
| 600 // Tests Searching in a hidden frame. Matches in the hidden frame should be | 483 // Tests Searching in a hidden frame. Matches in the hidden frame should be |
| 601 // ignored. | 484 // ignored. |
| 602 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(HiddenFrame)) { | 485 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(HiddenFrame)) { |
| 603 LoadAndWait("/find_in_hidden_frame.html"); | 486 LoadAndWait("/find_in_hidden_frame.html"); |
| 604 | 487 |
| 605 blink::WebFindOptions default_options; | 488 blink::WebFindOptions default_options; |
| 606 Find("hello", default_options); | 489 Find("hello", default_options); |
| 607 delegate()->WaitForFinalReply(); | 490 delegate()->WaitForFinalReply(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 LoadAndWait("/find_in_simple_page.html"); | 572 LoadAndWait("/find_in_simple_page.html"); |
| 690 | 573 |
| 691 Find("result", default_options); | 574 Find("result", default_options); |
| 692 delegate()->WaitForFinalReply(); | 575 delegate()->WaitForFinalReply(); |
| 693 | 576 |
| 694 // There should now be matches found. When the bug was present, there were | 577 // There should now be matches found. When the bug was present, there were |
| 695 // still no matches found. | 578 // still no matches found. |
| 696 results = delegate()->GetFindResults(); | 579 results = delegate()->GetFindResults(); |
| 697 EXPECT_EQ(last_request_id(), results.request_id); | 580 EXPECT_EQ(last_request_id(), results.request_id); |
| 698 EXPECT_EQ(5, results.number_of_matches); | 581 EXPECT_EQ(5, results.number_of_matches); |
| 582 EXPECT_EQ(1, results.active_match_ordinal); |
| 699 } | 583 } |
| 700 | 584 |
| 701 #if defined(OS_ANDROID) | 585 #if defined(OS_ANDROID) |
| 702 // Tests requesting find match rects. | 586 // Tests requesting find match rects. |
| 703 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindMatchRects)) { | 587 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindMatchRects)) { |
| 704 LoadAndWait("/find_in_page.html"); | 588 LoadAndWait("/find_in_page.html"); |
| 705 | 589 |
| 706 blink::WebFindOptions default_options; | 590 blink::WebFindOptions default_options; |
| 707 Find("result", default_options); | 591 Find("result", default_options); |
| 708 delegate()->WaitForFinalReply(); | 592 delegate()->WaitForFinalReply(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 delegate()->MarkNextReply(); | 688 delegate()->MarkNextReply(); |
| 805 contents()->ActivateNearestFindResult( | 689 contents()->ActivateNearestFindResult( |
| 806 rects[order[i]].CenterPoint().x(), rects[order[i]].CenterPoint().y()); | 690 rects[order[i]].CenterPoint().x(), rects[order[i]].CenterPoint().y()); |
| 807 delegate()->WaitForNextReply(); | 691 delegate()->WaitForNextReply(); |
| 808 EXPECT_EQ(order[i] + 1, delegate()->GetFindResults().active_match_ordinal); | 692 EXPECT_EQ(order[i] + 1, delegate()->GetFindResults().active_match_ordinal); |
| 809 } | 693 } |
| 810 } | 694 } |
| 811 #endif // defined(OS_ANDROID) | 695 #endif // defined(OS_ANDROID) |
| 812 | 696 |
| 813 } // namespace content | 697 } // namespace content |
| OLD | NEW |