Index: content/browser/find_request_manager_browsertest.cc |
diff --git a/content/browser/find_request_manager_browsertest.cc b/content/browser/find_request_manager_browsertest.cc |
index dce46635ca2be1e9c2bfb767a1121cd05a45a4de..499d4e4e717671239f47d3551fa138696ef43e7a 100644 |
--- a/content/browser/find_request_manager_browsertest.cc |
+++ b/content/browser/find_request_manager_browsertest.cc |
@@ -7,6 +7,7 @@ |
#include "content/browser/web_contents/web_contents_impl.h" |
#include "content/public/browser/notification_types.h" |
#include "content/public/common/content_switches.h" |
+#include "content/public/test/browser_test_utils.h" |
#include "content/public/test/content_browser_test.h" |
#include "content/public/test/content_browser_test_utils.h" |
#include "content/public/test/test_navigation_observer.h" |
@@ -476,8 +477,124 @@ IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RemoveFrame)) { |
results = delegate()->GetFindResults(); |
EXPECT_EQ(12, results.number_of_matches); |
EXPECT_EQ(8, results.active_match_ordinal); |
+} |
+ |
+// Tests adding a frame during a find session. |
+IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(AddFrame)) { |
+ LoadMultiFramePage(2 /* height */, GetParam() /* cross_process */); |
- // TODO(paulemeyer): Once adding frames mid-session is handled, test that too. |
+ blink::WebFindOptions options; |
+ Find("result", options); |
+ options.findNext = true; |
+ Find("result", options); |
+ Find("result", options); |
+ Find("result", options); |
+ Find("result", options); |
+ delegate()->WaitForFinalReply(); |
+ |
+ FindResults results = delegate()->GetFindResults(); |
+ EXPECT_EQ(last_request_id(), results.request_id); |
+ EXPECT_EQ(21, results.number_of_matches); |
+ EXPECT_EQ(5, results.active_match_ordinal); |
+ |
+ // Add a frame. It contains 5 new matches. |
+ std::string url = embedded_test_server()->GetURL( |
+ GetParam() ? "b.com" : "a.com", "/find_in_simple_page.html").spec(); |
+ std::string script = std::string() + |
+ "var frame = document.createElement('iframe');" + |
+ "frame.src = '" + url + "';" + |
+ "document.body.appendChild(frame);"; |
+ delegate()->MarkNextReply(); |
+ ASSERT_TRUE(ExecuteScript(shell(), script)); |
+ delegate()->WaitForNextReply(); |
+ |
+ // The number of matches should update automatically to include the matches |
+ // from the newly added frame. |
+ results = delegate()->GetFindResults(); |
+ EXPECT_EQ(26, results.number_of_matches); |
+ EXPECT_EQ(5, results.active_match_ordinal); |
+} |
+ |
+// Tests adding a frame during a find session where there were previously no |
+// matches. |
+IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(AddFrameAfterNoMatches)) { |
+ TestNavigationObserver navigation_observer(contents()); |
+ NavigateToURL(shell(), GURL("about:blank")); |
+ EXPECT_TRUE(navigation_observer.last_navigation_succeeded()); |
+ |
+ blink::WebFindOptions default_options; |
+ Find("result", default_options); |
+ delegate()->WaitForFinalReply(); |
+ |
+ // Initially, there are no matches on the page. |
+ FindResults results = delegate()->GetFindResults(); |
+ EXPECT_EQ(last_request_id(), results.request_id); |
+ EXPECT_EQ(0, results.number_of_matches); |
+ EXPECT_EQ(0, results.active_match_ordinal); |
+ |
+ // Add a frame. It contains 5 new matches. |
+ std::string url = |
+ embedded_test_server()->GetURL("/find_in_simple_page.html").spec(); |
+ std::string script = std::string() + |
+ "var frame = document.createElement('iframe');" + |
+ "frame.src = '" + url + "';" + |
+ "document.body.appendChild(frame);"; |
+ delegate()->MarkNextReply(); |
+ ASSERT_TRUE(ExecuteScript(shell(), script)); |
+ delegate()->WaitForNextReply(); |
+ |
+ // The matches from the new frame should be found automatically, and the first |
+ // match in the frame should be activated. |
+ results = delegate()->GetFindResults(); |
+ EXPECT_EQ(5, results.number_of_matches); |
+ EXPECT_EQ(1, results.active_match_ordinal); |
+} |
+ |
+// Tests a frame navigating to a different page during a find session. |
+IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(NavigateFrame)) { |
+ LoadMultiFramePage(2 /* height */, GetParam() /* cross_process */); |
+ |
+ blink::WebFindOptions options; |
+ Find("result", options); |
+ options.findNext = true; |
+ options.forward = false; |
+ Find("result", options); |
+ Find("result", options); |
+ Find("result", options); |
+ delegate()->WaitForFinalReply(); |
+ |
+ FindResults results = delegate()->GetFindResults(); |
+ EXPECT_EQ(last_request_id(), results.request_id); |
+ EXPECT_EQ(21, results.number_of_matches); |
+ EXPECT_EQ(19, results.active_match_ordinal); |
+ |
+ // Navigate one of the empty frames to a page with 5 matches. |
+ FrameTreeNode* root = |
+ static_cast<WebContentsImpl*>(shell()->web_contents())-> |
+ GetFrameTree()->root(); |
+ GURL url(embedded_test_server()->GetURL( |
+ GetParam() ? "b.com" : "a.com", "/find_in_simple_page.html")); |
+ delegate()->MarkNextReply(); |
+ TestNavigationObserver navigation_observer(contents()); |
+ NavigateFrameToURL(root->child_at(0)->child_at(1)->child_at(0), url); |
+ EXPECT_TRUE(navigation_observer.last_navigation_succeeded()); |
+ delegate()->WaitForNextReply(); |
+ |
+ // The navigation results in an extra reply before the one we care about. This |
+ // extra reply happens because the RenderFrameHost changes before it navigates |
+ // (because the navigation is cross-origin). The first reply will not change |
+ // the number of matches because the frame that is navigating was empty |
+ // before. |
+ if (delegate()->GetFindResults().number_of_matches == 21) { |
+ delegate()->MarkNextReply(); |
+ delegate()->WaitForNextReply(); |
+ } |
+ |
+ // The number of matches and the active match ordinal should update |
+ // automatically to include the new matches. |
+ results = delegate()->GetFindResults(); |
+ EXPECT_EQ(26, results.number_of_matches); |
+ EXPECT_EQ(24, results.active_match_ordinal); |
} |
// Tests Searching in a hidden frame. Matches in the hidden frame should be |
@@ -579,7 +696,6 @@ IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindInPage_Issue644448)) { |
results = delegate()->GetFindResults(); |
EXPECT_EQ(last_request_id(), results.request_id); |
EXPECT_EQ(5, results.number_of_matches); |
- EXPECT_EQ(1, results.active_match_ordinal); |
} |
#if defined(OS_ANDROID) |