| 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 265 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 266 child, "window.domAutomationController.send(mX);", &movementX)); | 266 child, "window.domAutomationController.send(mX);", &movementX)); |
| 267 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 267 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 268 child, "window.domAutomationController.send(mY);", &movementY)); | 268 child, "window.domAutomationController.send(mY);", &movementY)); |
| 269 EXPECT_EQ(14, x); | 269 EXPECT_EQ(14, x); |
| 270 EXPECT_EQ(15, y); | 270 EXPECT_EQ(15, y); |
| 271 EXPECT_EQ(16, movementX); | 271 EXPECT_EQ(16, movementX); |
| 272 EXPECT_EQ(17, movementY); | 272 EXPECT_EQ(17, movementY); |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Tests that the browser will not unlock the pointer if a RenderWidgetHostView | |
| 276 // that doesn't hold the pointer lock is destroyed. | |
| 277 IN_PROC_BROWSER_TEST_F(PointerLockBrowserTest, PointerLockChildFrameDetached) { | |
| 278 GURL main_url(embedded_test_server()->GetURL( | |
| 279 "a.com", "/cross_site_iframe_factory.html?a(b)")); | |
| 280 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
| 281 | |
| 282 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | |
| 283 | |
| 284 // Request a pointer lock on the root frame's body. | |
| 285 EXPECT_TRUE(ExecuteScript(root, "document.body.requestPointerLock()")); | |
| 286 | |
| 287 // Root frame should have been granted pointer lock. | |
| 288 bool locked = false; | |
| 289 EXPECT_TRUE(ExecuteScriptAndExtractBool(root, | |
| 290 "window.domAutomationController.send(" | |
| 291 "document.pointerLockElement == " | |
| 292 "document.body);", | |
| 293 &locked)); | |
| 294 EXPECT_TRUE(locked); | |
| 295 | |
| 296 // Root (platform) RenderWidgetHostView should have the pointer locked. | |
| 297 EXPECT_TRUE(root->current_frame_host()->GetView()->IsMouseLocked()); | |
| 298 EXPECT_EQ(root->current_frame_host()->GetRenderWidgetHost(), | |
| 299 web_contents()->GetMouseLockWidget()); | |
| 300 | |
| 301 // Detach the child frame. | |
| 302 EXPECT_TRUE(ExecuteScript(root, "document.querySelector('iframe').remove()")); | |
| 303 | |
| 304 // Root (platform) RenderWidgetHostView should still have the pointer locked. | |
| 305 EXPECT_TRUE(root->current_frame_host()->GetView()->IsMouseLocked()); | |
| 306 EXPECT_EQ(root->current_frame_host()->GetRenderWidgetHost(), | |
| 307 web_contents()->GetMouseLockWidget()); | |
| 308 } | |
| 309 | |
| 310 } // namespace content | 275 } // namespace content |
| OLD | NEW |