dom/tests/mochitest/pointerlock/file_screenClientXYConst.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=633602
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Bug 633602 - constantXY.html</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js">
michael@0 9 </script>
michael@0 10 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 11 <script type="application/javascript" src="pointerlock_utils.js"></script>
michael@0 12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 13 </head>
michael@0 14 <body>
michael@0 15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602">
michael@0 16 Mozilla Bug 633602
michael@0 17 </a>
michael@0 18 <div id="div"></div>
michael@0 19 <script type="application/javascript">
michael@0 20 /*
michael@0 21 * Test for Bug 633602
michael@0 22 * Confirm that screenX/Y and clientX/Y are constants when the pointer
michael@0 23 * is locked.
michael@0 24 */
michael@0 25
michael@0 26 SimpleTest.waitForExplicitFinish();
michael@0 27
michael@0 28 var div
michael@0 29 , divRect
michael@0 30 , unLockedCoords
michael@0 31 , lockedCoords
michael@0 32 , isUnlocked = false
michael@0 33 , isLocked = false;
michael@0 34
michael@0 35 function runTests () {
michael@0 36 ok(isUnlocked, "Pointer should be unlocked");
michael@0 37 ok(isLocked, "Pointer should be locked");
michael@0 38
michael@0 39 // Confirm that pointer coords are constant while locked
michael@0 40 is(unLockedCoords.clientX, lockedCoords.clientX,
michael@0 41 "clientX should be equal to where the mouse was originaly locked");
michael@0 42 is(unLockedCoords.clientY, lockedCoords.clientY,
michael@0 43 "clientY should be equal to where the mouse was originaly locked");
michael@0 44 is(unLockedCoords.screenX, lockedCoords.screenX,
michael@0 45 "screenX should be equal to where the mouse was originaly locked");
michael@0 46 is(unLockedCoords.screenY, lockedCoords.screenY,
michael@0 47 "screenY should be equal to where the mouse was originaly locked");
michael@0 48 }
michael@0 49
michael@0 50 function moveUnlocked(e) {
michael@0 51 var firstCall = !unLockedCoords;
michael@0 52 if (!firstCall) {
michael@0 53 todo(false, "mousemove is fired twice.");
michael@0 54 }
michael@0 55
michael@0 56 isUnlocked = !document.mozPointerLockElement;
michael@0 57 unLockedCoords = {
michael@0 58 screenX: e.screenX,
michael@0 59 screenY: e.screenY,
michael@0 60 clientX: e.clientX,
michael@0 61 clientY: e.clientY
michael@0 62 };
michael@0 63
michael@0 64 if (!firstCall) {
michael@0 65 return;
michael@0 66 }
michael@0 67
michael@0 68 div.mozRequestPointerLock();
michael@0 69 }
michael@0 70
michael@0 71 function moveLocked(e) {
michael@0 72 div.removeEventListener("mousemove", moveLocked, false);
michael@0 73
michael@0 74 isLocked = !!document.mozPointerLockElement;
michael@0 75 lockedCoords = {
michael@0 76 screenX: e.screenX,
michael@0 77 screenY: e.screenY,
michael@0 78 clientX: e.clientX,
michael@0 79 clientY: e.clientY
michael@0 80 };
michael@0 81
michael@0 82 document.mozCancelFullScreen();
michael@0 83 }
michael@0 84
michael@0 85 document.addEventListener("mozpointerlockchange", function (e) {
michael@0 86 if (document.mozPointerLockElement === div) {
michael@0 87 div.removeEventListener("mousemove", moveUnlocked, false);
michael@0 88 div.addEventListener("mousemove", moveLocked, false);
michael@0 89 divRect = div.getBoundingClientRect();
michael@0 90 synthesizeMouse(div, (divRect.width / 4) * 3, (divRect.height / 4) * 3, {
michael@0 91 type: "mousemove"
michael@0 92 }, window);
michael@0 93 }
michael@0 94 }, false);
michael@0 95
michael@0 96 function fullscreenchange() {
michael@0 97 var screenX = window.screenX;
michael@0 98 var screenY = window.screenY;
michael@0 99 if (document.mozFullScreenElement === div) {
michael@0 100 if (screenX != 0 || screenY != 0) {
michael@0 101 todo(screenX == 0 && screenY == 0,
michael@0 102 "We should only receive fullscreenchange once we've finished fullscreen transition " +
michael@0 103 "window.screenX=" + screenX + " window.screenY=" + screenY);
michael@0 104 setTimeout(fullscreenchange, 250);
michael@0 105 return;
michael@0 106 }
michael@0 107 div.addEventListener("mousemove", moveUnlocked, false);
michael@0 108 synthesizeMouseAtCenter(div, { type: "mousemove" }, window);
michael@0 109 } else {
michael@0 110 runTests();
michael@0 111 SimpleTest.finish();
michael@0 112 }
michael@0 113 }
michael@0 114 document.addEventListener("mozfullscreenchange", fullscreenchange, false);
michael@0 115
michael@0 116 function start() {
michael@0 117 div = document.getElementById("div");
michael@0 118 div.mozRequestFullScreen();
michael@0 119 }
michael@0 120 </script>
michael@0 121 </body>
michael@0 122 </html>

mercurial