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.

     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 type="application/javascript" src="/tests/SimpleTest/SimpleTest.js">
     9   </script>
    10   <script type="text/javascript" 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        */
    26       SimpleTest.waitForExplicitFinish();
    28       var div
    29         , divRect
    30         , unLockedCoords
    31         , lockedCoords
    32         , isUnlocked = false
    33         , isLocked = false;
    35       function runTests () {
    36         ok(isUnlocked, "Pointer should be unlocked");
    37         ok(isLocked, "Pointer should be locked");
    39         // Confirm that pointer coords are constant while locked
    40         is(unLockedCoords.clientX, lockedCoords.clientX,
    41            "clientX should be equal to where the mouse was originaly locked");
    42         is(unLockedCoords.clientY, lockedCoords.clientY,
    43            "clientY should be equal to where the mouse was originaly locked");
    44         is(unLockedCoords.screenX, lockedCoords.screenX,
    45            "screenX should be equal to where the mouse was originaly locked");
    46         is(unLockedCoords.screenY, lockedCoords.screenY,
    47            "screenY should be equal to where the mouse was originaly locked");
    48       }
    50       function moveUnlocked(e) {
    51         var firstCall = !unLockedCoords;
    52         if (!firstCall) {
    53           todo(false, "mousemove is fired twice.");
    54         }
    56         isUnlocked = !document.mozPointerLockElement;
    57         unLockedCoords = {
    58           screenX: e.screenX,
    59           screenY: e.screenY,
    60           clientX: e.clientX,
    61           clientY: e.clientY
    62         };
    64         if (!firstCall) {
    65           return;
    66         }
    68         div.mozRequestPointerLock();
    69       }
    71       function moveLocked(e) {
    72         div.removeEventListener("mousemove", moveLocked, false);
    74         isLocked = !!document.mozPointerLockElement;
    75         lockedCoords = {
    76           screenX: e.screenX,
    77           screenY: e.screenY,
    78           clientX: e.clientX,
    79           clientY: e.clientY
    80         };
    82         document.mozCancelFullScreen();
    83       }
    85       document.addEventListener("mozpointerlockchange", function (e) {
    86         if (document.mozPointerLockElement === div) {
    87           div.removeEventListener("mousemove", moveUnlocked, false);
    88           div.addEventListener("mousemove", moveLocked, false);
    89           divRect = div.getBoundingClientRect();
    90           synthesizeMouse(div, (divRect.width / 4) * 3, (divRect.height / 4) * 3, {
    91             type: "mousemove"
    92           }, window);
    93         }
    94       }, false);
    96       function fullscreenchange() {
    97         var screenX = window.screenX;
    98         var screenY = window.screenY;
    99         if (document.mozFullScreenElement === div) {
   100           if (screenX != 0 || screenY != 0) {
   101             todo(screenX == 0 && screenY == 0,
   102               "We should only receive fullscreenchange once we've finished fullscreen transition " +
   103               "window.screenX=" + screenX + " window.screenY=" + screenY);
   104             setTimeout(fullscreenchange, 250);
   105             return;
   106           }
   107           div.addEventListener("mousemove", moveUnlocked, false);
   108           synthesizeMouseAtCenter(div, { type: "mousemove" }, window);
   109         } else {
   110           runTests();
   111           SimpleTest.finish();
   112         }
   113       }
   114       document.addEventListener("mozfullscreenchange", fullscreenchange, false);
   116       function start() {
   117         div = document.getElementById("div");
   118         div.mozRequestFullScreen();
   119       }
   120   </script>
   121 </body>
   122 </html>

mercurial