test_pointerlock_target_not_in_active_document.html (2101B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Bug 1646493 - test_pointerlock_target_not_in_active_document.html</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 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1646493">Mozilla Bug 1646493</a><br> 12 <iframe></iframe> 13 <script> 14 if (!opener) { 15 SimpleTest.waitForExplicitFinish(); 16 } 17 18 var newwin = null; 19 function finish() { 20 newwin.close() 21 setTimeout(function() { 22 SimpleTest.finish(); 23 }, 0); 24 } 25 26 function testUnfocusedDocument() { 27 opener.document.addEventListener("pointerlockchange", function() { 28 opener.ok(false, "Check we have locked the pointer"); 29 opener.document.exitPointerLock(); 30 opener.testInactiveTopLevelDocument(); 31 }, {once: true}); 32 33 opener.document.addEventListener("pointerlockerror", function() { 34 opener.ok(true, "Fail to lock pointer"); 35 opener.testInactiveTopLevelDocument(); 36 }, {once: true}); 37 38 SpecialPowers.wrap(opener.document).notifyUserGestureActivation(); 39 opener.document.body.requestPointerLock(); 40 } 41 42 function testInactiveTopLevelDocument() { 43 let iframeWin = newwin.frames[0]; 44 let iframeDoc = iframeWin.document; 45 46 iframeDoc.addEventListener("pointerlockchange", function() { 47 ok(false, "Check we have locked the pointer"); 48 iframeDoc.exitPointerLock(); 49 finish(); 50 }, {once: true}); 51 52 iframeDoc.addEventListener("pointerlockerror", function() { 53 ok(true, "Fail to lock pointer"); 54 finish(); 55 }, {once: true}); 56 57 SpecialPowers.wrap(iframeDoc).notifyUserGestureActivation(); 58 59 newwin.addEventListener("pagehide", function() { 60 iframeDoc.body.requestPointerLock(); 61 }, {once: true}); 62 newwin.location = "iframe_differentDOM.html"; 63 } 64 65 addLoadEvent(async function() { 66 await SimpleTest.promiseFocus(); 67 68 if (!opener) { 69 newwin = window.open(location); 70 return; 71 } 72 73 testUnfocusedDocument(); 74 }); 75 </script> 76 </body> 77 </html>