dom/tests/mochitest/pointerlock/file_screenClientXYConst.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/pointerlock/file_screenClientXYConst.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,122 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=633602
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Bug 633602 - constantXY.html</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js">
    1.12 +  </script>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +  <script type="application/javascript" src="pointerlock_utils.js"></script>
    1.15 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.16 +</head>
    1.17 +<body>
    1.18 +  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602">
    1.19 +    Mozilla Bug 633602
    1.20 +  </a>
    1.21 +  <div id="div"></div>
    1.22 +  <script type="application/javascript">
    1.23 +      /*
    1.24 +       * Test for Bug 633602
    1.25 +       * Confirm that screenX/Y and clientX/Y are constants when the pointer
    1.26 +       * is locked.
    1.27 +       */
    1.28 +
    1.29 +      SimpleTest.waitForExplicitFinish();
    1.30 +
    1.31 +      var div
    1.32 +        , divRect
    1.33 +        , unLockedCoords
    1.34 +        , lockedCoords
    1.35 +        , isUnlocked = false
    1.36 +        , isLocked = false;
    1.37 +
    1.38 +      function runTests () {
    1.39 +        ok(isUnlocked, "Pointer should be unlocked");
    1.40 +        ok(isLocked, "Pointer should be locked");
    1.41 +
    1.42 +        // Confirm that pointer coords are constant while locked
    1.43 +        is(unLockedCoords.clientX, lockedCoords.clientX,
    1.44 +           "clientX should be equal to where the mouse was originaly locked");
    1.45 +        is(unLockedCoords.clientY, lockedCoords.clientY,
    1.46 +           "clientY should be equal to where the mouse was originaly locked");
    1.47 +        is(unLockedCoords.screenX, lockedCoords.screenX,
    1.48 +           "screenX should be equal to where the mouse was originaly locked");
    1.49 +        is(unLockedCoords.screenY, lockedCoords.screenY,
    1.50 +           "screenY should be equal to where the mouse was originaly locked");
    1.51 +      }
    1.52 +
    1.53 +      function moveUnlocked(e) {
    1.54 +        var firstCall = !unLockedCoords;
    1.55 +        if (!firstCall) {
    1.56 +          todo(false, "mousemove is fired twice.");
    1.57 +        }
    1.58 +
    1.59 +        isUnlocked = !document.mozPointerLockElement;
    1.60 +        unLockedCoords = {
    1.61 +          screenX: e.screenX,
    1.62 +          screenY: e.screenY,
    1.63 +          clientX: e.clientX,
    1.64 +          clientY: e.clientY
    1.65 +        };
    1.66 +
    1.67 +        if (!firstCall) {
    1.68 +          return;
    1.69 +        }
    1.70 +
    1.71 +        div.mozRequestPointerLock();
    1.72 +      }
    1.73 +
    1.74 +      function moveLocked(e) {
    1.75 +        div.removeEventListener("mousemove", moveLocked, false);
    1.76 +
    1.77 +        isLocked = !!document.mozPointerLockElement;
    1.78 +        lockedCoords = {
    1.79 +          screenX: e.screenX,
    1.80 +          screenY: e.screenY,
    1.81 +          clientX: e.clientX,
    1.82 +          clientY: e.clientY
    1.83 +        };
    1.84 +
    1.85 +        document.mozCancelFullScreen();
    1.86 +      }
    1.87 +
    1.88 +      document.addEventListener("mozpointerlockchange", function (e) {
    1.89 +        if (document.mozPointerLockElement === div) {
    1.90 +          div.removeEventListener("mousemove", moveUnlocked, false);
    1.91 +          div.addEventListener("mousemove", moveLocked, false);
    1.92 +          divRect = div.getBoundingClientRect();
    1.93 +          synthesizeMouse(div, (divRect.width / 4) * 3, (divRect.height / 4) * 3, {
    1.94 +            type: "mousemove"
    1.95 +          }, window);
    1.96 +        }
    1.97 +      }, false);
    1.98 +
    1.99 +      function fullscreenchange() {
   1.100 +        var screenX = window.screenX;
   1.101 +        var screenY = window.screenY;
   1.102 +        if (document.mozFullScreenElement === div) {
   1.103 +          if (screenX != 0 || screenY != 0) {
   1.104 +            todo(screenX == 0 && screenY == 0,
   1.105 +              "We should only receive fullscreenchange once we've finished fullscreen transition " +
   1.106 +              "window.screenX=" + screenX + " window.screenY=" + screenY);
   1.107 +            setTimeout(fullscreenchange, 250);
   1.108 +            return;
   1.109 +          }
   1.110 +          div.addEventListener("mousemove", moveUnlocked, false);
   1.111 +          synthesizeMouseAtCenter(div, { type: "mousemove" }, window);
   1.112 +        } else {
   1.113 +          runTests();
   1.114 +          SimpleTest.finish();
   1.115 +        }
   1.116 +      }
   1.117 +      document.addEventListener("mozfullscreenchange", fullscreenchange, false);
   1.118 +
   1.119 +      function start() {
   1.120 +        div = document.getElementById("div");
   1.121 +        div.mozRequestFullScreen();
   1.122 +      }
   1.123 +  </script>
   1.124 +</body>
   1.125 +</html>

mercurial