test_closewindow-with-pointerlock.html (1533B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Bug 1323983 - Auto-close window after holding pointerlock</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <script src="/tests/SimpleTest/EventUtils.js"></script> 8 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 9 </head> 10 <body style="width: 100vw; height: 100vh; margin: 0;"> 11 <script> 12 if (!opener) { 13 SimpleTest.waitForExplicitFinish(); 14 } 15 16 var newwin = null; 17 function finish() { 18 newwin.close() 19 setTimeout(function() { 20 SimpleTest.finish(); 21 }, 0); 22 } 23 24 addLoadEvent(function() { 25 SimpleTest.waitForFocus(function() { 26 if (!opener) { 27 newwin = window.open(location); 28 } else { 29 document.addEventListener("pointerlockchange", function() { 30 opener.is(document.pointerLockElement, document.body, 31 "Check we have locked the pointer"); 32 opener.finish(); 33 }, {once: true}); 34 document.addEventListener("pointerlockerror", function() { 35 opener.info("Fail to lock pointer"); 36 opener.finish(); 37 }); 38 document.addEventListener("click", function() { 39 opener.info("Clicked"); 40 document.body.requestPointerLock(); 41 }, {once: true}); 42 setTimeout(function() { 43 opener.info("Clicking"); 44 synthesizeMouseAtCenter(document.body, {}); 45 }, 0); 46 } 47 }); 48 }); 49 </script> 50 </body> 51 </html>