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 // Flaky on Mac. See comment on https://codereview.chromium.org/2760343002. |
| 276 #if defined(OS_MACOSX) |
| 277 #define MAYBE_PointerLockChildFrameDetached \ |
| 278 DISABLED_PointerLockChildFrameDetached |
| 279 #else |
| 280 #define MAYBE_PointerLockChildFrameDetached PointerLockChildFrameDetached |
| 281 #endif |
| 282 // Tests that the browser will not unlock the pointer if a RenderWidgetHostView |
| 283 // that doesn't hold the pointer lock is destroyed. |
| 284 IN_PROC_BROWSER_TEST_F(PointerLockBrowserTest, |
| 285 MAYBE_PointerLockChildFrameDetached) { |
| 286 GURL main_url(embedded_test_server()->GetURL( |
| 287 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
| 288 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 289 |
| 290 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 291 |
| 292 // Request a pointer lock on the root frame's body. |
| 293 EXPECT_TRUE(ExecuteScript(root, "document.body.requestPointerLock()")); |
| 294 |
| 295 // Root frame should have been granted pointer lock. |
| 296 bool locked = false; |
| 297 EXPECT_TRUE(ExecuteScriptAndExtractBool(root, |
| 298 "window.domAutomationController.send(" |
| 299 "document.pointerLockElement == " |
| 300 "document.body);", |
| 301 &locked)); |
| 302 EXPECT_TRUE(locked); |
| 303 |
| 304 // Root (platform) RenderWidgetHostView should 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 // Detach the child frame. |
| 310 EXPECT_TRUE(ExecuteScript(root, "document.querySelector('iframe').remove()")); |
| 311 |
| 312 // Root (platform) RenderWidgetHostView should still have the pointer locked. |
| 313 EXPECT_TRUE(root->current_frame_host()->GetView()->IsMouseLocked()); |
| 314 EXPECT_EQ(root->current_frame_host()->GetRenderWidgetHost(), |
| 315 web_contents()->GetMouseLockWidget()); |
| 316 } |
| 317 |
275 } // namespace content | 318 } // namespace content |
OLD | NEW |