Chromium Code Reviews| 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 6bb654a15b58f2bf84fac0ded993a0b6cd45f212..569308d62c1ccb39de05e8f9257ce6c2f79974c6 100644 |
| --- a/content/browser/site_per_process_browsertest.cc |
| +++ b/content/browser/site_per_process_browsertest.cc |
| @@ -41,6 +41,7 @@ |
| #include "net/test/embedded_test_server/embedded_test_server.h" |
| #include "third_party/WebKit/public/web/WebInputEvent.h" |
| #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| +#include "ui/gfx/switches.h" |
| namespace content { |
| @@ -97,6 +98,147 @@ void NavigateNamedFrame(const ToRenderFrameHost& caller_frame, |
| EXPECT_TRUE(success); |
| } |
| +class RenderWidgetHostMouseEventMonitor { |
| + public: |
| + RenderWidgetHostMouseEventMonitor(RenderWidgetHost* host) |
|
sadrul
2015/11/03 18:00:00
explicit
lfg
2015/11/03 20:49:16
Done.
|
| + : host_(host), event_received(false) { |
| + host_->AddMouseEventCallback( |
| + base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback, |
| + base::Unretained(this))); |
| + } |
| + ~RenderWidgetHostMouseEventMonitor() { |
| + host_->RemoveMouseEventCallback( |
| + base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback, |
| + base::Unretained(this))); |
| + } |
| + bool EventWasReceived() { return event_received; } |
|
sadrul
2015/11/03 18:00:00
const
lfg
2015/11/03 20:49:16
Done.
|
| + void ResetEventReceived() { event_received = false; } |
| + const blink::WebMouseEvent& event() const { return event_; } |
| + |
| + private: |
| + bool MouseEventCallback(const blink::WebMouseEvent& event) { |
| + event_received = true; |
| + event_ = event; |
| + return false; |
| + } |
| + RenderWidgetHost* host_; |
| + bool event_received; |
|
sadrul
2015/11/03 18:00:00
event_received_
lfg
2015/11/03 20:49:16
Done.
|
| + blink::WebMouseEvent event_; |
| +}; |
|
sadrul
2015/11/03 18:00:00
DISALLOW_COPY_...
(I realize that you are just mo
lfg
2015/11/03 20:49:16
Done.
|
| + |
| +// Helper function that performs a surface hittest. |
| +void SurfaceHitTestTestHelper( |
| + Shell* shell, |
| + net::test_server::EmbeddedTestServer* embedded_test_server) { |
| + if (!UseSurfacesEnabled()) |
| + return; |
| + |
| + GURL main_url(embedded_test_server->GetURL( |
| + "/frame_tree/page_with_positioned_frame.html")); |
| + NavigateToURL(shell, main_url); |
| + |
| + // It is safe to obtain the root frame tree node here, as it doesn't change. |
| + FrameTreeNode* root = static_cast<WebContentsImpl*>(shell->web_contents()) |
| + ->GetFrameTree() |
| + ->root(); |
| + ASSERT_EQ(1U, root->child_count()); |
| + |
| + FrameTreeNode* child_node = root->child_at(0); |
| + GURL site_url(embedded_test_server->GetURL("baz.com", "/title1.html")); |
| + EXPECT_EQ(site_url, child_node->current_url()); |
| + EXPECT_NE(shell->web_contents()->GetSiteInstance(), |
| + child_node->current_frame_host()->GetSiteInstance()); |
| + |
| + // Create listeners for mouse events. |
| + RenderWidgetHostMouseEventMonitor main_frame_monitor( |
| + root->current_frame_host()->GetRenderWidgetHost()); |
| + RenderWidgetHostMouseEventMonitor child_frame_monitor( |
| + child_node->current_frame_host()->GetRenderWidgetHost()); |
| + |
| + RenderWidgetHostInputEventRouter* router = |
| + static_cast<WebContentsImpl*>(shell->web_contents()) |
| + ->GetInputEventRouter(); |
| + |
| + RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( |
| + root->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| + RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>( |
| + child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| + |
| + // We need to wait for a compositor frame from the child frame, at which |
| + // point its surface will be created. |
| + while (rwhv_child->RendererFrameNumber() <= 0) { |
| + // TODO(lazyboy): Find a better way to avoid sleeping like this. See |
| + // http://crbug.com/405282 for details. |
| + base::RunLoop run_loop; |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, run_loop.QuitClosure(), |
| + base::TimeDelta::FromMilliseconds(10)); |
| + run_loop.Run(); |
| + } |
|
sadrul
2015/11/03 18:00:00
This is still unfortunate. I have left a comment i
|
| + |
| + uint32_t cur_render_frame_number = root_view->RendererFrameNumber(); |
| + |
| + // Target input event to child frame. |
| + blink::WebMouseEvent child_event; |
| + child_event.type = blink::WebInputEvent::MouseDown; |
| + child_event.button = blink::WebPointerProperties::ButtonLeft; |
| + child_event.x = 75; |
| + child_event.y = 75; |
| + child_event.clickCount = 1; |
| + main_frame_monitor.ResetEventReceived(); |
| + child_frame_monitor.ResetEventReceived(); |
| + router->RouteMouseEvent(root_view, &child_event); |
| + |
| + while (!child_frame_monitor.EventWasReceived()) { |
| + // This is working around a big synchronization problem. It is very |
| + // difficult to know if we have received a compositor frame from the |
| + // main frame renderer *after* it received the child frame's surface |
| + // ID. Hit testing won't work until this happens. So if the hit test |
| + // fails then we wait for another frame to arrive and try again. |
| + // TODO(kenrb): We need a better way to do all of this, possibly coming |
| + // from http://crbug.com/405282. |
| + while (root_view->RendererFrameNumber() <= cur_render_frame_number) { |
| + base::RunLoop run_loop; |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, run_loop.QuitClosure(), |
| + base::TimeDelta::FromMilliseconds(10)); |
| + run_loop.Run(); |
| + } |
| + cur_render_frame_number = root_view->RendererFrameNumber(); |
| + child_event.type = blink::WebInputEvent::MouseDown; |
| + child_event.button = blink::WebPointerProperties::ButtonLeft; |
| + child_event.x = 75; |
| + child_event.y = 75; |
| + child_event.clickCount = 1; |
| + main_frame_monitor.ResetEventReceived(); |
| + child_frame_monitor.ResetEventReceived(); |
| + router->RouteMouseEvent(root_view, &child_event); |
| + } |
|
sadrul
2015/11/03 18:00:00
eugh ... this too! We really need to find a better
lfg
2015/11/03 20:49:16
I discussed an alternative to this with kenrb@, wh
|
| + |
| + EXPECT_TRUE(child_frame_monitor.EventWasReceived()); |
| + EXPECT_EQ(23, child_frame_monitor.event().x); |
| + EXPECT_EQ(23, child_frame_monitor.event().y); |
| + EXPECT_FALSE(main_frame_monitor.EventWasReceived()); |
| + |
| + child_frame_monitor.ResetEventReceived(); |
| + main_frame_monitor.ResetEventReceived(); |
| + |
| + // Target input event to main frame. |
| + blink::WebMouseEvent main_event; |
| + main_event.type = blink::WebInputEvent::MouseDown; |
| + main_event.button = blink::WebPointerProperties::ButtonLeft; |
| + main_event.x = 1; |
| + main_event.y = 1; |
| + main_event.clickCount = 1; |
| + // Ladies and gentlemen, THIS is the main_event! |
| + router->RouteMouseEvent(root_view, &main_event); |
| + |
| + EXPECT_FALSE(child_frame_monitor.EventWasReceived()); |
| + EXPECT_TRUE(main_frame_monitor.EventWasReceived()); |
| + EXPECT_EQ(1, main_frame_monitor.event().x); |
| + EXPECT_EQ(1, main_frame_monitor.event().y); |
| +} |
| + |
| class RedirectNotificationObserver : public NotificationObserver { |
| public: |
| // Register to listen for notifications of the given type from either a |
| @@ -317,6 +459,19 @@ void SitePerProcessBrowserTest::SetUpOnMainThread() { |
| SetupCrossSiteRedirector(embedded_test_server()); |
| } |
| +// |
| +// SitePerProcessHighDPIBrowserTest |
| +// |
| + |
| +SitePerProcessHighDPIBrowserTest::SitePerProcessHighDPIBrowserTest() {} |
| + |
| +void SitePerProcessHighDPIBrowserTest::SetUpCommandLine( |
| + base::CommandLine* command_line) { |
| + SitePerProcessBrowserTest::SetUpCommandLine(command_line); |
| + command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, |
| + base::StringPrintf("2")); |
| +}; |
| + |
| // Ensure that navigating subframes in --site-per-process mode works and the |
| // correct documents are committed. |
| IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { |
| @@ -446,34 +601,6 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { |
| DepictFrameTree(root)); |
| } |
| -class RenderWidgetHostMouseEventMonitor { |
| - public: |
| - RenderWidgetHostMouseEventMonitor(RenderWidgetHost* host) |
| - : host_(host), event_received(false) { |
| - host_->AddMouseEventCallback( |
| - base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback, |
| - base::Unretained(this))); |
| - } |
| - ~RenderWidgetHostMouseEventMonitor() { |
| - host_->RemoveMouseEventCallback( |
| - base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback, |
| - base::Unretained(this))); |
| - } |
| - bool EventWasReceived() { return event_received; } |
| - void ResetEventReceived() { event_received = false; } |
| - const blink::WebMouseEvent& event() const { return event_; } |
| - |
| - private: |
| - bool MouseEventCallback(const blink::WebMouseEvent& event) { |
| - event_received = true; |
| - event_ = event; |
| - return false; |
| - } |
| - RenderWidgetHost* host_; |
| - bool event_received; |
| - blink::WebMouseEvent event_; |
| -}; |
| - |
| // Test that mouse events are being routed to the correct RenderWidgetHostView |
| // based on coordinates. |
| #if defined(OS_ANDROID) |
| @@ -484,113 +611,21 @@ class RenderWidgetHostMouseEventMonitor { |
| #define MAYBE_SurfaceHitTestTest SurfaceHitTestTest |
| #endif |
| IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, MAYBE_SurfaceHitTestTest) { |
| - if (!UseSurfacesEnabled()) |
| - return; |
| - |
| - GURL main_url(embedded_test_server()->GetURL( |
| - "/frame_tree/page_with_positioned_frame.html")); |
| - NavigateToURL(shell(), main_url); |
| - |
| - // It is safe to obtain the root frame tree node here, as it doesn't change. |
| - FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| - ->GetFrameTree() |
| - ->root(); |
| - ASSERT_EQ(1U, root->child_count()); |
| - |
| - FrameTreeNode* child_node = root->child_at(0); |
| - GURL site_url(embedded_test_server()->GetURL("baz.com", "/title1.html")); |
| - EXPECT_EQ(site_url, child_node->current_url()); |
| - EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| - child_node->current_frame_host()->GetSiteInstance()); |
| - |
| - // Create listeners for mouse events. |
| - RenderWidgetHostMouseEventMonitor main_frame_monitor( |
| - root->current_frame_host()->GetRenderWidgetHost()); |
| - RenderWidgetHostMouseEventMonitor child_frame_monitor( |
| - child_node->current_frame_host()->GetRenderWidgetHost()); |
| - |
| - RenderWidgetHostInputEventRouter* router = |
| - static_cast<WebContentsImpl*>(shell()->web_contents()) |
| - ->GetInputEventRouter(); |
| - |
| - RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( |
| - root->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| - RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>( |
| - child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| - |
| - // We need to wait for a compositor frame from the child frame, at which |
| - // point its surface will be created. |
| - while (rwhv_child->RendererFrameNumber() <= 0) { |
| - // TODO(lazyboy): Find a better way to avoid sleeping like this. See |
| - // http://crbug.com/405282 for details. |
| - base::RunLoop run_loop; |
| - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| - FROM_HERE, run_loop.QuitClosure(), |
| - base::TimeDelta::FromMilliseconds(10)); |
| - run_loop.Run(); |
| - } |
| - |
| - uint32_t cur_render_frame_number = root_view->RendererFrameNumber(); |
| - |
| - // Target input event to child frame. |
| - blink::WebMouseEvent child_event; |
| - child_event.type = blink::WebInputEvent::MouseDown; |
| - child_event.button = blink::WebPointerProperties::ButtonLeft; |
| - child_event.x = 75; |
| - child_event.y = 75; |
| - child_event.clickCount = 1; |
| - main_frame_monitor.ResetEventReceived(); |
| - child_frame_monitor.ResetEventReceived(); |
| - router->RouteMouseEvent(root_view, &child_event); |
| - |
| - while (!child_frame_monitor.EventWasReceived()) { |
| - // This is working around a big synchronization problem. It is very |
| - // difficult to know if we have received a compositor frame from the |
| - // main frame renderer *after* it received the child frame's surface |
| - // ID. Hit testing won't work until this happens. So if the hit test |
| - // fails then we wait for another frame to arrive and try again. |
| - // TODO(kenrb): We need a better way to do all of this, possibly coming |
| - // from http://crbug.com/405282. |
| - while (root_view->RendererFrameNumber() <= cur_render_frame_number) { |
| - base::RunLoop run_loop; |
| - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| - FROM_HERE, run_loop.QuitClosure(), |
| - base::TimeDelta::FromMilliseconds(10)); |
| - run_loop.Run(); |
| - } |
| - cur_render_frame_number = root_view->RendererFrameNumber(); |
| - child_event.type = blink::WebInputEvent::MouseDown; |
| - child_event.button = blink::WebPointerProperties::ButtonLeft; |
| - child_event.x = 75; |
| - child_event.y = 75; |
| - child_event.clickCount = 1; |
| - main_frame_monitor.ResetEventReceived(); |
| - child_frame_monitor.ResetEventReceived(); |
| - router->RouteMouseEvent(root_view, &child_event); |
| - } |
| - |
| - EXPECT_TRUE(child_frame_monitor.EventWasReceived()); |
| - EXPECT_EQ(23, child_frame_monitor.event().x); |
| - EXPECT_EQ(23, child_frame_monitor.event().y); |
| - EXPECT_FALSE(main_frame_monitor.EventWasReceived()); |
| - |
| - child_frame_monitor.ResetEventReceived(); |
| - main_frame_monitor.ResetEventReceived(); |
| - |
| - // Target input event to main frame. |
| - blink::WebMouseEvent main_event; |
| - main_event.type = blink::WebInputEvent::MouseDown; |
| - main_event.button = blink::WebPointerProperties::ButtonLeft; |
| - main_event.x = 1; |
| - main_event.y = 1; |
| - main_event.clickCount = 1; |
| - // Ladies and gentlemen, THIS is the main_event! |
| - router->RouteMouseEvent(root_view, &main_event); |
| + SurfaceHitTestTestHelper(shell(), embedded_test_server()); |
| +} |
| - EXPECT_FALSE(child_frame_monitor.EventWasReceived()); |
| - EXPECT_TRUE(main_frame_monitor.EventWasReceived()); |
| - EXPECT_EQ(1, main_frame_monitor.event().x); |
| - EXPECT_EQ(1, main_frame_monitor.event().y); |
| +// Same test as above, but runs in high-dpi mode. |
| +#if defined(OS_ANDROID) || defined(OS_WIN) |
| +// Browser process hit testing is not implemented on Android. |
| +// https://crbug.com/491334 |
| +// Windows is disabled because of https://crbug.com/545547. |
| +#define MAYBE_HighDPISurfaceHitTestTest DISABLED_SurfaceHitTestTest |
| +#else |
| +#define MAYBE_HighDPISurfaceHitTestTest SurfaceHitTestTest |
| +#endif |
| +IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, |
| + MAYBE_HighDPISurfaceHitTestTest) { |
| + SurfaceHitTestTestHelper(shell(), embedded_test_server()); |
| } |
| // Tests OOPIF rendering by checking that the RWH of the iframe generates |