Commit 4263cfcc authored by W. James MacLean's avatar W. James MacLean Committed by Commit Bot

Fix MouseLeave for BP-based guests.

The MouseEnter/Leave logic in RenderWidgetHostInputEventRouter expects
child frames to return a non-null GetParentView(), but children that are
RenderWidgetHostViewGuests currently return null, causing the logic to
fail.

This CL fixes that.

Bug: 835566
Change-Id: I0792772872e10134f4c79b8f929bc4271543f00e
Reviewed-on: https://chromium-review.googlesource.com/1050613Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarCharlie Reis <creis@chromium.org>
Reviewed-by: default avatardsinclair <dsinclair@chromium.org>
Commit-Queue: James MacLean <wjmaclean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557538}
parent e3d54350
......@@ -1632,6 +1632,61 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, CtrlWheelInvokesCustomZoom) {
#endif // defined(OS_MACOSX)
IN_PROC_BROWSER_TEST_P(PDFExtensionHitTestTest, MouseLeave) {
GURL url = embedded_test_server()->GetURL("/pdf/pdf_embed.html");
// Load page with embedded PDF and make sure it succeeds.
ASSERT_TRUE(LoadPdf(url));
WebContents* guest_contents = nullptr;
WebContents* embedder_contents = GetActiveWebContents();
content::BrowserPluginGuestManager* guest_manager =
embedder_contents->GetBrowserContext()->GetGuestManager();
ASSERT_NO_FATAL_FAILURE(guest_manager->ForEachGuest(
embedder_contents, base::Bind(&GetGuestCallback, &guest_contents)));
ASSERT_NE(nullptr, guest_contents);
#if defined(USE_AURA)
// TODO(wjmaclean): In theory this should be used to make sure the hit testing
// for routing to the guest process works as intended. Not sure if not having
// this on Mac is an issue.
content::WaitForGuestSurfaceReady(guest_contents);
#endif
gfx::Point point_in_parent(250, 25);
gfx::Point point_in_pdf(250, 250);
// Inject script to count MouseLeaves in the PDF.
ASSERT_TRUE(content::ExecuteScript(
guest_contents,
"var enter_count = 0;\n"
"var leave_count = 0;\n"
"document.addEventListener('mouseenter', function (){\n"
" enter_count++;"
"});\n"
"document.addEventListener('mouseleave', function (){\n"
" leave_count++;"
"});"));
// Inject some MouseMoves to invoke a MouseLeave in the PDF.
content::SimulateRoutedMouseEvent(
embedder_contents, blink::WebInputEvent::kMouseMove, point_in_parent);
content::SimulateRoutedMouseEvent(
embedder_contents, blink::WebInputEvent::kMouseMove, point_in_pdf);
content::SimulateRoutedMouseEvent(
embedder_contents, blink::WebInputEvent::kMouseMove, point_in_parent);
// Verify MouseEnter, MouseLeave received.
int leave_count = 0;
do {
ASSERT_TRUE(ExecuteScriptAndExtractInt(
guest_contents, "window.domAutomationController.send(leave_count);",
&leave_count));
} while (!leave_count);
int enter_count = 0;
ASSERT_TRUE(ExecuteScriptAndExtractInt(
guest_contents, "window.domAutomationController.send(enter_count);",
&enter_count));
EXPECT_EQ(1, enter_count);
}
IN_PROC_BROWSER_TEST_P(PDFExtensionHitTestTest, ContextMenuCoordinates) {
GURL url = embedded_test_server()->GetURL("/pdf/pdf_embed.html");
......
......@@ -96,6 +96,10 @@ RenderWidgetHostViewBase* RenderWidgetHostViewGuest::GetRootView(
return rwhv;
}
RenderWidgetHostViewBase* RenderWidgetHostViewGuest::GetParentView() {
return GetOwnerRenderWidgetHostView();
}
RenderWidgetHostViewGuest::RenderWidgetHostViewGuest(
RenderWidgetHost* widget_host,
BrowserPluginGuest* guest,
......
......@@ -62,6 +62,9 @@ class CONTENT_EXPORT RenderWidgetHostViewGuest
// Called when this RenderWidgetHostViewGuest is attached.
void OnAttached();
// RenderWidgetHostViewChildFrame implementation.
RenderWidgetHostViewBase* GetParentView() override;
// RenderWidgetHostView implementation.
bool OnMessageReceived(const IPC::Message& msg) override;
void InitAsChild(gfx::NativeView parent_view) override;
......
......@@ -221,7 +221,7 @@ class CONTENT_EXPORT RenderWidgetHostViewChildFrame
// Returns the view into which this view is directly embedded. This can
// return nullptr when this view's associated child frame is not connected
// to the frame tree.
RenderWidgetHostViewBase* GetParentView();
virtual RenderWidgetHostViewBase* GetParentView();
void RegisterFrameSinkId();
void UnregisterFrameSinkId();
......
......@@ -751,6 +751,25 @@ void SimulateMouseEvent(WebContents* web_contents,
mouse_event);
}
void SimulateRoutedMouseEvent(WebContents* web_contents,
blink::WebInputEvent::Type type,
const gfx::Point& point) {
content::WebContentsImpl* web_contents_impl =
static_cast<content::WebContentsImpl*>(web_contents);
content::RenderWidgetHostViewBase* rwhvb =
static_cast<content::RenderWidgetHostViewBase*>(
web_contents->GetRenderWidgetHostView());
blink::WebMouseEvent mouse_event(type, 0, ui::EventTimeForNow());
mouse_event.SetPositionInWidget(point.x(), point.y());
// Mac needs positionInScreen for events to plugins.
gfx::Rect offset = web_contents->GetContainerBounds();
mouse_event.SetPositionInScreen(point.x() + offset.x(),
point.y() + offset.y());
web_contents_impl->GetInputEventRouter()->RouteMouseEvent(rwhvb, &mouse_event,
ui::LatencyInfo());
}
void SimulateMouseWheelEvent(WebContents* web_contents,
const gfx::Point& point,
const gfx::Vector2d& delta,
......
......@@ -160,6 +160,12 @@ void SimulateMouseEvent(WebContents* web_contents,
blink::WebInputEvent::Type type,
const gfx::Point& point);
// Same as SimulateMouseEvent() except it forces the mouse event to go through
// RenderWidgetHostInputEventRouter.
void SimulateRoutedMouseEvent(WebContents* web_contents,
blink::WebInputEvent::Type type,
const gfx::Point& point);
// Simulate a mouse wheel event.
void SimulateMouseWheelEvent(WebContents* web_contents,
const gfx::Point& point,
......
......@@ -26,6 +26,7 @@
#### Compositor Frame Observation Timeouts
# WaitForChildFrameSurfaceReady crashes crbug.com/787945
-PDFExtensionHitTestTest.ContextMenuCoordinates*
-PDFExtensionHitTestTest.MouseLeave*
-SitePerProcessDevToolsSanityTest.InputDispatchEventsToOOPIF
-WebViewTest.InterstitialPageFocusedWidget
-WebViewTest.ReloadAfterCrash
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment