file_screenClientXYConst.html (4635B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=633602 5 --> 6 <head> 7 <title>Bug 633602 - constantXY.html</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"> 9 </script> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <script type="application/javascript" src="pointerlock_utils.js"></script> 12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 13 </head> 14 <body> 15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602"> 16 Mozilla Bug 633602 17 </a> 18 <div id="div"></div> 19 <script type="application/javascript"> 20 /* 21 * Test for Bug 633602 22 * Confirm that screenX/Y and clientX/Y are constants when the pointer 23 * is locked. 24 */ 25 26 SimpleTest.waitForExplicitFinish(); 27 SimpleTest.requestFlakyTimeout("We may need to wait for window's moving"); 28 29 var div 30 , divRect 31 , unLockedCoords 32 , lockedCoords 33 , mouseMoveIntervalID 34 , isUnlocked = false 35 , isLocked = false; 36 37 function runTests () { 38 ok(isUnlocked, "Pointer should be unlocked"); 39 ok(isLocked, "Pointer should be locked"); 40 41 // Confirm that pointer coords are constant while locked 42 is(unLockedCoords.clientX, lockedCoords.clientX, 43 "clientX should be equal to where the mouse was originaly locked"); 44 is(unLockedCoords.clientY, lockedCoords.clientY, 45 "clientY should be equal to where the mouse was originaly locked"); 46 is(unLockedCoords.screenX, lockedCoords.screenX, 47 "screenX should be equal to where the mouse was originaly locked"); 48 is(unLockedCoords.screenY, lockedCoords.screenY, 49 "screenY should be equal to where the mouse was originaly locked"); 50 } 51 52 function moveUnlocked(e) { 53 info("Got mousemove via moveUnlocked"); 54 clearInterval(mouseMoveIntervalID); 55 var firstCall = !unLockedCoords; 56 if (!firstCall) { 57 todo(false, "mousemove is fired twice."); 58 } 59 60 unLockedCoords = { 61 screenX: e.screenX, 62 screenY: e.screenY, 63 clientX: e.clientX, 64 clientY: e.clientY 65 }; 66 67 if (!firstCall) { 68 return; 69 } 70 71 isUnlocked = !document.pointerLockElement; 72 div.requestPointerLock(); 73 } 74 75 function moveLocked(e) { 76 info("Got mousemove via moveLocked"); 77 clearInterval(mouseMoveIntervalID); 78 div.removeEventListener("mousemove", moveLocked); 79 80 isLocked = !!document.pointerLockElement; 81 lockedCoords = { 82 screenX: e.screenX, 83 screenY: e.screenY, 84 clientX: e.clientX, 85 clientY: e.clientY 86 }; 87 88 addFullscreenChangeContinuation("exit", function() { 89 info("Got fullscreenchange for exiting"); 90 runTests(); 91 SimpleTest.finish(); 92 }); 93 document.exitFullscreen(); 94 } 95 96 document.addEventListener("pointerlockchange", function (e) { 97 if (document.pointerLockElement === div) { 98 info("Got pointerlockchange for entering"); 99 div.removeEventListener("mousemove", moveUnlocked); 100 div.addEventListener("mousemove", moveLocked); 101 divRect = div.getBoundingClientRect(); 102 // Bug 1295815 103 // Retrigger synthesizeNativeMouseEvent until it actually happens. 104 mouseMoveIntervalID = setInterval(() => { 105 synthesizeNativeMouseEvent({ 106 type: "mousemove", 107 target: div, 108 offsetX: (divRect.width / 4) * 3, 109 offsetY: (divRect.height / 4) * 3, 110 }); 111 }, 100); 112 } else { 113 info("Got pointerlockchange for exiting"); 114 } 115 }); 116 117 function start() { 118 div = document.getElementById("div"); 119 info("Requesting fullscreen on parent"); 120 addFullscreenChangeContinuation("enter", async () => { 121 info("Got fullscreenchange for entering"); 122 await promiseNativeMouseEvent({ 123 type: "mousemove", 124 target: div, 125 offsetX: 0, 126 offsetY: 0, 127 }); 128 div.addEventListener("mousemove", moveUnlocked); 129 // Bug 1295815 130 // Retrigger synthesizeNativeMouseEvent until it actually happens. 131 mouseMoveIntervalID = setInterval(() => { 132 synthesizeNativeMouseEvent({ 133 type: "mousemove", 134 target: div, 135 atCenter: true, 136 }); 137 }, 100); 138 }); 139 div.requestFullscreen(); 140 } 141 </script> 142 </body> 143 </html>