Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(934)

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 2437213002: Fix crash where a pending pointer lock would trigger a CHECK. (Closed)
Patch Set: override Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 10 #include "content/browser/frame_host/navigation_entry_impl.h"
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 const GURL kImageUrl = embedded_test_server()->GetURL("/invalid.ico"); 1237 const GURL kImageUrl = embedded_test_server()->GetURL("/invalid.ico");
1238 shell()->LoadURL(GURL("about:blank")); 1238 shell()->LoadURL(GURL("about:blank"));
1239 base::RunLoop run_loop; 1239 base::RunLoop run_loop;
1240 shell()->web_contents()->DownloadImage( 1240 shell()->web_contents()->DownloadImage(
1241 kImageUrl, false, 2, false, 1241 kImageUrl, false, 2, false,
1242 base::Bind(&ExpectNoValidImageCallback, run_loop.QuitClosure())); 1242 base::Bind(&ExpectNoValidImageCallback, run_loop.QuitClosure()));
1243 1243
1244 run_loop.Run(); 1244 run_loop.Run();
1245 } 1245 }
1246 1246
1247 class MouseLockDelegate : public WebContentsDelegate {
1248 public:
1249 // WebContentsDelegate:
1250 void RequestToLockMouse(WebContents* web_contents,
1251 bool user_gesture,
1252 bool last_unlocked_by_target) override {
1253 request_to_lock_mouse_called_ = true;
1254 }
1255 bool request_to_lock_mouse_called_ = false;
1256 };
1257
1258 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1259 RenderWidgetDeletedWhileMouseLockPending) {
1260 host_resolver()->AddRule("*", "127.0.0.1");
1261 ASSERT_TRUE(embedded_test_server()->Start());
1262
1263 std::unique_ptr<MouseLockDelegate> delegate(new MouseLockDelegate());
1264 shell()->web_contents()->SetDelegate(delegate.get());
1265 ASSERT_TRUE(shell()->web_contents()->GetDelegate() == delegate.get());
1266
1267 NavigateToURL(shell(),
1268 embedded_test_server()->GetURL("a.com", "/title1.html"));
1269
1270 // Try to request pointer lock. WebContentsDelegate should get a notification.
1271 ASSERT_TRUE(ExecuteScript(shell(),
1272 "window.domAutomationController.send(document.body."
1273 "requestPointerLock());"));
1274 EXPECT_TRUE(delegate.get()->request_to_lock_mouse_called_);
1275
1276 // Make sure that the renderer didn't get the pointer lock, since the
1277 // WebContentsDelegate didn't approve the notification.
1278 bool locked = false;
1279 ASSERT_TRUE(ExecuteScriptAndExtractBool(shell(),
1280 "window.domAutomationController.send("
1281 "document.pointerLockElement == "
1282 "null);",
1283 &locked));
1284 EXPECT_TRUE(locked);
1285
1286 // Try to request the pointer lock again. Since there's a pending request in
1287 // WebContentsDelelgate, the WebContents shouldn't ask again.
1288 delegate.get()->request_to_lock_mouse_called_ = false;
1289 ASSERT_TRUE(ExecuteScript(shell(),
1290 "window.domAutomationController.send(document.body."
1291 "requestPointerLock());"));
1292 EXPECT_FALSE(delegate.get()->request_to_lock_mouse_called_);
1293
1294 // Force a cross-process navigation so that the RenderWidgetHost is deleted.
1295 NavigateToURL(shell(),
1296 embedded_test_server()->GetURL("b.com", "/title1.html"));
1297
1298 // Make sure the WebContents cleaned up the previous pending request. A new
1299 // request should be forwarded to the WebContentsDelegate.
1300 delegate.get()->request_to_lock_mouse_called_ = false;
1301 ASSERT_TRUE(ExecuteScript(shell(),
1302 "window.domAutomationController.send(document.body."
1303 "requestPointerLock());"));
1304 EXPECT_TRUE(delegate.get()->request_to_lock_mouse_called_);
1305 }
1306
1247 } // namespace content 1307 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698