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

Unified Diff: content/browser/site_per_process_browsertest.cc

Issue 1370013003: OOPIF: Clear old focused frame when focus moves to a cross-process frame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/site_per_process_browsertest.cc
diff --git a/content/browser/site_per_process_browsertest.cc b/content/browser/site_per_process_browsertest.cc
index 1f5d7333c9346541e1621332f269fa752e63913c..2eb23548f2760b4378851abf42573972ca207018 100644
--- a/content/browser/site_per_process_browsertest.cc
+++ b/content/browser/site_per_process_browsertest.cc
@@ -3455,4 +3455,72 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
navigation_observer.Wait();
}
+// Check that when a cross-process frame acquires focus, the old focused frame
+// loses focus and fires blur events. Starting on a page with a cross-site
+// subframe, simulate mouse clicks to switch focus from root frame to subframe
+// and then back to root frame.
+IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
+ CrossProcessFocusChangeFiresBlurEvents) {
+ GURL main_url(
+ embedded_test_server()->GetURL("a.com", "/page_with_input_field.html"));
+ EXPECT_TRUE(NavigateToURL(shell(), main_url));
+
+ FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
+ ->GetFrameTree()
+ ->root();
+
+ EXPECT_EQ(
+ " Site A ------------ proxies for B\n"
+ " +--Site B ------- proxies for A\n"
+ "Where A = http://a.com/\n"
+ " B = http://b.com/",
+ DepictFrameTree(root));
+
+ // Focus the main frame's text field. The return value "focused"
Charlie Reis 2015/09/29 23:50:44 "input-focus"?
alexmos 2015/09/30 16:48:20 Done.
+ // indicates that the focus event was fired correctly.
+ std::string result;
+ EXPECT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(),
+ "focusInputField()", &result));
+ EXPECT_EQ(result, "input-focus");
+
+ // The main frame should be focused.
+ EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame());
+
+ DOMMessageQueue msg_queue;
+
+ // Click on the cross-process subframe.
+ blink::WebMouseEvent mouse_event;
+ mouse_event.type = blink::WebInputEvent::MouseDown;
+ mouse_event.button = blink::WebPointerProperties::ButtonLeft;
+ mouse_event.x = 1;
+ mouse_event.y = 1;
+ RenderWidgetHost* rwh_child =
+ root->child_at(0)->current_frame_host()->GetRenderWidgetHost();
+ rwh_child->ForwardMouseEvent(mouse_event);
Charlie Reis 2015/09/29 23:50:44 Sanity check: Is this the right way to send input
alexmos 2015/09/30 16:48:20 I've double-checked with Ken that this should be f
+
+ // Check that the main frame lost focus and fired blur event on the input
+ // text field.
+ std::string status;
+ while (msg_queue.WaitForMessage(&status)) {
+ if (status == "\"input-blur\"")
+ break;
+ }
+
+ // The subframe should now be focused.
+ EXPECT_EQ(root->child_at(0), root->frame_tree()->GetFocusedFrame());
+
+ // Click on the root frame.
+ shell()->web_contents()->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
+
+ // Check that the subframe lost focus and fired blur event on its
+ // document's body.
+ while (msg_queue.WaitForMessage(&status)) {
+ if (status == "\"document-blur\"")
+ break;
+ }
+
+ // The root frame should be focused again.
+ EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698