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" |
10 #include "content/public/test/content_browser_test.h" | 11 #include "content/public/test/content_browser_test.h" |
11 #include "content/public/test/content_browser_test_utils.h" | 12 #include "content/public/test/content_browser_test_utils.h" |
12 #include "content/public/test/test_navigation_observer.h" | 13 #include "content/public/test/test_navigation_observer.h" |
13 #include "content/public/test/test_utils.h" | 14 #include "content/public/test/test_utils.h" |
14 #include "content/shell/browser/shell.h" | 15 #include "content/shell/browser/shell.h" |
15 #include "content/test/content_browser_test_utils_internal.h" | 16 #include "content/test/content_browser_test_utils_internal.h" |
16 #include "net/dns/mock_host_resolver.h" | 17 #include "net/dns/mock_host_resolver.h" |
17 #include "third_party/WebKit/public/web/WebFindOptions.h" | 18 #include "third_party/WebKit/public/web/WebFindOptions.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 | 470 |
470 // Remove a frame. | 471 // Remove a frame. |
471 FrameTreeNode* root = contents()->GetFrameTree()->root(); | 472 FrameTreeNode* root = contents()->GetFrameTree()->root(); |
472 root->RemoveChild(root->child_at(0)); | 473 root->RemoveChild(root->child_at(0)); |
473 | 474 |
474 // The number of matches and active match ordinal should update automatically | 475 // The number of matches and active match ordinal should update automatically |
475 // to exclude the matches from the removed frame. | 476 // to exclude the matches from the removed frame. |
476 results = delegate()->GetFindResults(); | 477 results = delegate()->GetFindResults(); |
477 EXPECT_EQ(12, results.number_of_matches); | 478 EXPECT_EQ(12, results.number_of_matches); |
478 EXPECT_EQ(8, results.active_match_ordinal); | 479 EXPECT_EQ(8, results.active_match_ordinal); |
| 480 } |
479 | 481 |
480 // TODO(paulemeyer): Once adding frames mid-session is handled, test that too. | 482 // Tests adding a frame during a find session. |
| 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); |
481 } | 598 } |
482 | 599 |
483 // Tests Searching in a hidden frame. Matches in the hidden frame should be | 600 // Tests Searching in a hidden frame. Matches in the hidden frame should be |
484 // ignored. | 601 // ignored. |
485 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(HiddenFrame)) { | 602 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(HiddenFrame)) { |
486 LoadAndWait("/find_in_hidden_frame.html"); | 603 LoadAndWait("/find_in_hidden_frame.html"); |
487 | 604 |
488 blink::WebFindOptions default_options; | 605 blink::WebFindOptions default_options; |
489 Find("hello", default_options); | 606 Find("hello", default_options); |
490 delegate()->WaitForFinalReply(); | 607 delegate()->WaitForFinalReply(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 LoadAndWait("/find_in_simple_page.html"); | 689 LoadAndWait("/find_in_simple_page.html"); |
573 | 690 |
574 Find("result", default_options); | 691 Find("result", default_options); |
575 delegate()->WaitForFinalReply(); | 692 delegate()->WaitForFinalReply(); |
576 | 693 |
577 // There should now be matches found. When the bug was present, there were | 694 // There should now be matches found. When the bug was present, there were |
578 // still no matches found. | 695 // still no matches found. |
579 results = delegate()->GetFindResults(); | 696 results = delegate()->GetFindResults(); |
580 EXPECT_EQ(last_request_id(), results.request_id); | 697 EXPECT_EQ(last_request_id(), results.request_id); |
581 EXPECT_EQ(5, results.number_of_matches); | 698 EXPECT_EQ(5, results.number_of_matches); |
582 EXPECT_EQ(1, results.active_match_ordinal); | |
583 } | 699 } |
584 | 700 |
585 #if defined(OS_ANDROID) | 701 #if defined(OS_ANDROID) |
586 // Tests requesting find match rects. | 702 // Tests requesting find match rects. |
587 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindMatchRects)) { | 703 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindMatchRects)) { |
588 LoadAndWait("/find_in_page.html"); | 704 LoadAndWait("/find_in_page.html"); |
589 | 705 |
590 blink::WebFindOptions default_options; | 706 blink::WebFindOptions default_options; |
591 Find("result", default_options); | 707 Find("result", default_options); |
592 delegate()->WaitForFinalReply(); | 708 delegate()->WaitForFinalReply(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 delegate()->MarkNextReply(); | 804 delegate()->MarkNextReply(); |
689 contents()->ActivateNearestFindResult( | 805 contents()->ActivateNearestFindResult( |
690 rects[order[i]].CenterPoint().x(), rects[order[i]].CenterPoint().y()); | 806 rects[order[i]].CenterPoint().x(), rects[order[i]].CenterPoint().y()); |
691 delegate()->WaitForNextReply(); | 807 delegate()->WaitForNextReply(); |
692 EXPECT_EQ(order[i] + 1, delegate()->GetFindResults().active_match_ordinal); | 808 EXPECT_EQ(order[i] + 1, delegate()->GetFindResults().active_match_ordinal); |
693 } | 809 } |
694 } | 810 } |
695 #endif // defined(OS_ANDROID) | 811 #endif // defined(OS_ANDROID) |
696 | 812 |
697 } // namespace content | 813 } // namespace content |
OLD | NEW |