OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/pointer_lock_browsertest.h" | 5 #include "content/browser/pointer_lock_browsertest.h" |
6 | 6 |
7 #include "content/browser/frame_host/frame_tree.h" | 7 #include "content/browser/frame_host/frame_tree.h" |
8 #include "content/browser/renderer_host/render_widget_host_impl.h" | 8 #include "content/browser/renderer_host/render_widget_host_impl.h" |
9 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 9 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 300 |
301 // Detach the child frame. | 301 // Detach the child frame. |
302 EXPECT_TRUE(ExecuteScript(root, "document.querySelector('iframe').remove()")); | 302 EXPECT_TRUE(ExecuteScript(root, "document.querySelector('iframe').remove()")); |
303 | 303 |
304 // Root (platform) RenderWidgetHostView should still have the pointer locked. | 304 // Root (platform) RenderWidgetHostView should still have the pointer locked. |
305 EXPECT_TRUE(root->current_frame_host()->GetView()->IsMouseLocked()); | 305 EXPECT_TRUE(root->current_frame_host()->GetView()->IsMouseLocked()); |
306 EXPECT_EQ(root->current_frame_host()->GetRenderWidgetHost(), | 306 EXPECT_EQ(root->current_frame_host()->GetRenderWidgetHost(), |
307 web_contents()->GetMouseLockWidget()); | 307 web_contents()->GetMouseLockWidget()); |
308 } | 308 } |
309 | 309 |
| 310 IN_PROC_BROWSER_TEST_F(PointerLockBrowserTest, PointerLockWheelEventRouting) { |
| 311 GURL main_url(embedded_test_server()->GetURL( |
| 312 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
| 313 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 314 |
| 315 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 316 FrameTreeNode* child = root->child_at(0); |
| 317 RenderWidgetHostInputEventRouter* router = |
| 318 web_contents()->GetInputEventRouter(); |
| 319 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( |
| 320 root->current_frame_host()->GetView()); |
| 321 RenderWidgetHostViewBase* child_view = static_cast<RenderWidgetHostViewBase*>( |
| 322 child->current_frame_host()->GetView()); |
| 323 |
| 324 // Request a pointer lock on the root frame's body. |
| 325 EXPECT_TRUE(ExecuteScript(root, "document.body.requestPointerLock()")); |
| 326 |
| 327 // Root frame should have been granted pointer lock. |
| 328 bool locked = false; |
| 329 EXPECT_TRUE(ExecuteScriptAndExtractBool(root, |
| 330 "window.domAutomationController.send(" |
| 331 "document.pointerLockElement == " |
| 332 "document.body);", |
| 333 &locked)); |
| 334 EXPECT_TRUE(locked); |
| 335 |
| 336 // Add a mouse move wheel event listener to the root frame. |
| 337 EXPECT_TRUE(ExecuteScript( |
| 338 root, |
| 339 "var x; var y; var mX; var mY; document.addEventListener('mousewheel', " |
| 340 "function(e) {x = e.x; y = e.y; dX = e.deltaX; dY = e.deltaY;});")); |
| 341 MainThreadFrameObserver root_observer(root_view->GetRenderWidgetHost()); |
| 342 root_observer.Wait(); |
| 343 |
| 344 blink::WebMouseWheelEvent wheel_event( |
| 345 blink::WebInputEvent::MouseWheel, blink::WebInputEvent::NoModifiers, |
| 346 blink::WebInputEvent::TimeStampForTesting); |
| 347 wheel_event.x = 10; |
| 348 wheel_event.y = 11; |
| 349 wheel_event.deltaX = -12; |
| 350 wheel_event.deltaY = -13; |
| 351 router->RouteMouseWheelEvent(root_view, &wheel_event, ui::LatencyInfo()); |
| 352 |
| 353 // Make sure that the renderer handled the input event. |
| 354 root_observer.Wait(); |
| 355 |
| 356 int x, y, deltaX, deltaY; |
| 357 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 358 root, "window.domAutomationController.send(x);", &x)); |
| 359 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 360 root, "window.domAutomationController.send(y);", &y)); |
| 361 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 362 root, "window.domAutomationController.send(dX);", &deltaX)); |
| 363 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 364 root, "window.domAutomationController.send(dY);", &deltaY)); |
| 365 EXPECT_EQ(10, x); |
| 366 EXPECT_EQ(11, y); |
| 367 EXPECT_EQ(12, deltaX); |
| 368 EXPECT_EQ(13, deltaY); |
| 369 |
| 370 // Release pointer lock on root frame. |
| 371 EXPECT_TRUE(ExecuteScript(root, "document.exitPointerLock()")); |
| 372 |
| 373 // Request a pointer lock on the child frame's body. |
| 374 EXPECT_TRUE(ExecuteScript(child, "document.body.requestPointerLock()")); |
| 375 |
| 376 // Child frame should have been granted pointer lock. |
| 377 EXPECT_TRUE(ExecuteScriptAndExtractBool(child, |
| 378 "window.domAutomationController.send(" |
| 379 "document.pointerLockElement == " |
| 380 "document.body);", |
| 381 &locked)); |
| 382 EXPECT_TRUE(locked); |
| 383 |
| 384 // Add a mouse move event listener to the child frame. |
| 385 EXPECT_TRUE(ExecuteScript( |
| 386 child, |
| 387 "var x; var y; var mX; var mY; document.addEventListener('mousewheel', " |
| 388 "function(e) {x = e.x; y = e.y; dX = e.deltaX; dY = e.deltaY;});")); |
| 389 MainThreadFrameObserver child_observer(child_view->GetRenderWidgetHost()); |
| 390 child_observer.Wait(); |
| 391 |
| 392 gfx::Point transformed_point; |
| 393 root_view->TransformPointToCoordSpaceForView(gfx::Point(0, 0), child_view, |
| 394 &transformed_point); |
| 395 |
| 396 wheel_event.x = -transformed_point.x() + 14; |
| 397 wheel_event.y = -transformed_point.y() + 15; |
| 398 wheel_event.deltaX = -16; |
| 399 wheel_event.deltaY = -17; |
| 400 // We use root_view intentionally as the RenderWidgetHostInputEventRouter is |
| 401 // responsible for correctly routing the event to the child frame. |
| 402 router->RouteMouseWheelEvent(root_view, &wheel_event, ui::LatencyInfo()); |
| 403 |
| 404 // Make sure that the renderer handled the input event. |
| 405 child_observer.Wait(); |
| 406 |
| 407 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 408 child, "window.domAutomationController.send(x);", &x)); |
| 409 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 410 child, "window.domAutomationController.send(y);", &y)); |
| 411 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 412 child, "window.domAutomationController.send(dX);", &deltaX)); |
| 413 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 414 child, "window.domAutomationController.send(dY);", &deltaY)); |
| 415 EXPECT_EQ(14, x); |
| 416 EXPECT_EQ(15, y); |
| 417 EXPECT_EQ(16, deltaX); |
| 418 EXPECT_EQ(17, deltaY); |
| 419 } |
| 420 |
310 } // namespace content | 421 } // namespace content |
OLD | NEW |