dom/tests/mochitest/pointerlock/file_screenClientXYConst.html
author Nils Maier <maierman@web.de>
Wed, 28 Nov 2012 13:13:13 -0500
changeset 114378 0e5ca55005ae8ef9002ac12472740104fb79fd47
parent 94531 72a43b68ec95cd151b1933491d47b2dfe45b03f5
child 145464 fb8dac49d9dca3f4079bc2b866029eb96c0c9d8f
permissions -rw-r--r--
Bug 719180: Part 2 - Add jar channel unit tests; r=taras

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=633602
-->
<head>
  <title>Bug 633602 - constantXY.html</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js">
  </script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="application/javascript" src="pointerlock_utils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602">
    Mozilla Bug 633602
  </a>
  <div id="div"></div>
  <script type="application/javascript">
      /*
       * Test for Bug 633602
       * Confirm that screenX/Y and clientX/Y are constants when the pointer
       * is locked.
       */

      SimpleTest.waitForExplicitFinish();

      var div
        , divRect
        , unLockedCoords
        , lockedCoords
        , isUnlocked = false
        , isLocked = false;

      function runTests () {
        ok(isUnlocked, "Pointer should be unlocked");
        ok(isLocked, "Pointer should be locked");

        // Confirm that pointer coords are constant while locked
        is(unLockedCoords.clientX, lockedCoords.clientX,
           "clientX should be equal to where the mouse was originaly locked");
        is(unLockedCoords.clientY, lockedCoords.clientY,
           "clientY should be equal to where the mouse was originaly locked");
        is(unLockedCoords.screenX, lockedCoords.screenX,
           "screenX should be equal to where the mouse was originaly locked");
        is(unLockedCoords.screenY, lockedCoords.screenY,
           "screenY should be equal to where the mouse was originaly locked");
      }

      function moveUnlocked(e) {
        div.removeEventListener("mousemove", moveUnlocked, false);

        isUnlocked = !document.mozPointerLockElement;
        unLockedCoords = {
          screenX: e.screenX,
          screenY: e.screenY,
          clientX: e.clientX,
          clientY: e.clientY
        };

        div.mozRequestPointerLock();
      }

      function moveLocked(e) {
        div.removeEventListener("mousemove", moveLocked, false);

        isLocked = !!document.mozPointerLockElement;
        lockedCoords = {
          screenX: e.screenX,
          screenY: e.screenY,
          clientX: e.clientX,
          clientY: e.clientY
        };

        document.mozCancelFullScreen();
      }

      document.addEventListener("mozpointerlockchange", function (e) {
        if (document.mozPointerLockElement === div) {
          div.addEventListener("mousemove", moveLocked, false);
          divRect = div.getBoundingClientRect();
          synthesizeMouse(div, (divRect.width / 4) * 3, (divRect.height / 4) * 3, {
            type: "mousemove"
          }, window);
        }
      }, false);

      function fullscreenchange() {
        var screenX = window.screenX;
        var screenY = window.screenY;
        if (document.mozFullScreenElement === div) {
          if (screenX != 0 || screenY != 0) {
            todo(screenX == 0 && screenY == 0,
              "We should only receive fullscreenchange once we've finished fullscreen transition " +
              "window.screenX=" + screenX + " window.screenY=" + screenY);
            setTimeout(fullscreenchange, 250);
            return;
          }
          div.addEventListener("mousemove", moveUnlocked, false);
          synthesizeMouseAtCenter(div, { type: "mousemove" }, window);
        } else {
          runTests();
          SimpleTest.finish();
        }
      }
      document.addEventListener("mozfullscreenchange", fullscreenchange, false);

      function start() {
        div = document.getElementById("div");
        div.mozRequestFullScreen();
      }
  </script>
</body>
</html>