| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 RenderWidgetHostInputEventRouter* router = | 190 RenderWidgetHostInputEventRouter* router = |
| 191 static_cast<WebContentsImpl*>(shell->web_contents()) | 191 static_cast<WebContentsImpl*>(shell->web_contents()) |
| 192 ->GetInputEventRouter(); | 192 ->GetInputEventRouter(); |
| 193 | 193 |
| 194 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( | 194 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( |
| 195 root->current_frame_host()->GetRenderWidgetHost()->GetView()); | 195 root->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 196 RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>( | 196 RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>( |
| 197 child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); | 197 child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 198 | 198 |
| 199 // We need to wait for a compositor frame from the child frame, at which | 199 SurfaceHitTestReadyNotifier notifier( |
| 200 // point its surface will be created. | 200 static_cast<RenderWidgetHostViewChildFrame*>(rwhv_child)); |
| 201 while (rwhv_child->RendererFrameNumber() <= 0) { | 201 notifier.WaitForSurfaceReady(); |
| 202 // TODO(lazyboy): Find a better way to avoid sleeping like this. See | |
| 203 // http://crbug.com/405282 for details. | |
| 204 base::RunLoop run_loop; | |
| 205 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 206 FROM_HERE, run_loop.QuitClosure(), | |
| 207 base::TimeDelta::FromMilliseconds(10)); | |
| 208 run_loop.Run(); | |
| 209 } | |
| 210 | |
| 211 uint32_t cur_render_frame_number = root_view->RendererFrameNumber(); | |
| 212 | 202 |
| 213 // Target input event to child frame. | 203 // Target input event to child frame. |
| 214 blink::WebMouseEvent child_event; | 204 blink::WebMouseEvent child_event; |
| 215 child_event.type = blink::WebInputEvent::MouseDown; | 205 child_event.type = blink::WebInputEvent::MouseDown; |
| 216 child_event.button = blink::WebPointerProperties::ButtonLeft; | 206 child_event.button = blink::WebPointerProperties::ButtonLeft; |
| 217 child_event.x = 75; | 207 child_event.x = 75; |
| 218 child_event.y = 75; | 208 child_event.y = 75; |
| 219 child_event.clickCount = 1; | 209 child_event.clickCount = 1; |
| 220 main_frame_monitor.ResetEventReceived(); | 210 main_frame_monitor.ResetEventReceived(); |
| 221 child_frame_monitor.ResetEventReceived(); | 211 child_frame_monitor.ResetEventReceived(); |
| 222 router->RouteMouseEvent(root_view, &child_event); | 212 router->RouteMouseEvent(root_view, &child_event); |
| 223 | 213 |
| 224 while (!child_frame_monitor.EventWasReceived()) { | |
| 225 // This is working around a big synchronization problem. It is very | |
| 226 // difficult to know if we have received a compositor frame from the | |
| 227 // main frame renderer *after* it received the child frame's surface | |
| 228 // ID. Hit testing won't work until this happens. So if the hit test | |
| 229 // fails then we wait for another frame to arrive and try again. | |
| 230 // TODO(kenrb): We need a better way to do all of this, possibly coming | |
| 231 // from http://crbug.com/405282. | |
| 232 while (root_view->RendererFrameNumber() <= cur_render_frame_number) { | |
| 233 base::RunLoop run_loop; | |
| 234 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 235 FROM_HERE, run_loop.QuitClosure(), | |
| 236 base::TimeDelta::FromMilliseconds(10)); | |
| 237 run_loop.Run(); | |
| 238 } | |
| 239 cur_render_frame_number = root_view->RendererFrameNumber(); | |
| 240 child_event.type = blink::WebInputEvent::MouseDown; | |
| 241 child_event.button = blink::WebPointerProperties::ButtonLeft; | |
| 242 child_event.x = 75; | |
| 243 child_event.y = 75; | |
| 244 child_event.clickCount = 1; | |
| 245 main_frame_monitor.ResetEventReceived(); | |
| 246 child_frame_monitor.ResetEventReceived(); | |
| 247 router->RouteMouseEvent(root_view, &child_event); | |
| 248 } | |
| 249 | |
| 250 EXPECT_TRUE(child_frame_monitor.EventWasReceived()); | 214 EXPECT_TRUE(child_frame_monitor.EventWasReceived()); |
| 251 EXPECT_EQ(23, child_frame_monitor.event().x); | 215 EXPECT_EQ(23, child_frame_monitor.event().x); |
| 252 EXPECT_EQ(23, child_frame_monitor.event().y); | 216 EXPECT_EQ(23, child_frame_monitor.event().y); |
| 253 EXPECT_FALSE(main_frame_monitor.EventWasReceived()); | 217 EXPECT_FALSE(main_frame_monitor.EventWasReceived()); |
| 254 | 218 |
| 255 child_frame_monitor.ResetEventReceived(); | 219 child_frame_monitor.ResetEventReceived(); |
| 256 main_frame_monitor.ResetEventReceived(); | 220 main_frame_monitor.ResetEventReceived(); |
| 257 | 221 |
| 258 // Target input event to main frame. | 222 // Target input event to main frame. |
| 259 blink::WebMouseEvent main_event; | 223 blink::WebMouseEvent main_event; |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 | 780 |
| 817 RenderWidgetHostInputEventRouter* router = | 781 RenderWidgetHostInputEventRouter* router = |
| 818 static_cast<WebContentsImpl*>(shell()->web_contents()) | 782 static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 819 ->GetInputEventRouter(); | 783 ->GetInputEventRouter(); |
| 820 | 784 |
| 821 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( | 785 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( |
| 822 root->current_frame_host()->GetRenderWidgetHost()->GetView()); | 786 root->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 823 RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>( | 787 RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>( |
| 824 child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); | 788 child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 825 | 789 |
| 826 // We need to wait for a compositor frame from the child frame, at which | 790 SurfaceHitTestReadyNotifier notifier( |
| 827 // point its surface will be created. | 791 static_cast<RenderWidgetHostViewChildFrame*>(rwhv_child)); |
| 828 while (rwhv_child->RendererFrameNumber() <= 0) { | 792 notifier.WaitForSurfaceReady(); |
| 829 // TODO(lazyboy): Find a better way to avoid sleeping like this. See | |
| 830 // http://crbug.com/405282 for details. | |
| 831 base::RunLoop run_loop; | |
| 832 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 833 FROM_HERE, run_loop.QuitClosure(), | |
| 834 base::TimeDelta::FromMilliseconds(10)); | |
| 835 run_loop.Run(); | |
| 836 } | |
| 837 | 793 |
| 838 // Target input event to child frame. | 794 // Target input event to child frame. |
| 839 blink::WebMouseEvent child_event; | 795 blink::WebMouseEvent child_event; |
| 840 child_event.type = blink::WebInputEvent::MouseDown; | 796 child_event.type = blink::WebInputEvent::MouseDown; |
| 841 child_event.button = blink::WebPointerProperties::ButtonLeft; | 797 child_event.button = blink::WebPointerProperties::ButtonLeft; |
| 842 child_event.x = 75; | 798 child_event.x = 75; |
| 843 child_event.y = 75; | 799 child_event.y = 75; |
| 844 child_event.clickCount = 1; | 800 child_event.clickCount = 1; |
| 845 main_frame_monitor.ResetEventReceived(); | 801 main_frame_monitor.ResetEventReceived(); |
| 846 child_frame_monitor.ResetEventReceived(); | 802 child_frame_monitor.ResetEventReceived(); |
| (...skipping 4541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5388 | 5344 |
| 5389 // Force the renderer to generate a new frame. | 5345 // Force the renderer to generate a new frame. |
| 5390 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 5346 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
| 5391 "document.body.style.background = 'black'")); | 5347 "document.body.style.background = 'black'")); |
| 5392 | 5348 |
| 5393 // Waits for the next frame. | 5349 // Waits for the next frame. |
| 5394 observer->Wait(); | 5350 observer->Wait(); |
| 5395 } | 5351 } |
| 5396 | 5352 |
| 5397 } // namespace content | 5353 } // namespace content |
| OLD | NEW |