dom/tests/mochitest/pointerlock/file_retargetMouseEvents.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/pointerlock/file_retargetMouseEvents.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,179 @@
     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 - file_retargetMouseEvents.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 +
    1.22 +  <div id="parent">
    1.23 +    <div id="child" style="width: 100%; height: 100%;">
    1.24 +    </div>
    1.25 +  </div>
    1.26 +
    1.27 +  <pre id="test">
    1.28 +    <script type="application/javascript">
    1.29 +      /*
    1.30 +       * Test for Bug 633602
    1.31 +       * Retarget mouse events to the locked element
    1.32 +       */
    1.33 +
    1.34 +      SimpleTest.waitForExplicitFinish();
    1.35 +
    1.36 +      function MouseEventStats() {
    1.37 +        this.mouseMove = false;
    1.38 +        this.mouseDown = false;
    1.39 +        this.mouseUp = false;
    1.40 +        this.mouseClick = false;
    1.41 +        this.mouseScroll = false;
    1.42 +        this.wheel = false;
    1.43 +      }
    1.44 +
    1.45 +      var parent = document.getElementById("parent")
    1.46 +        , child = document.getElementById("child")
    1.47 +        , parentStats = new MouseEventStats()
    1.48 +        , childStats = new MouseEventStats();
    1.49 +
    1.50 +      function runTests () {
    1.51 +        is(childStats.mouseMove, false, "Child shound not receive mousemove event.");
    1.52 +        is(childStats.mouseDown, false, "Child should not receive mousedown event.");
    1.53 +        is(childStats.mouseUp, false, "Child should not receive mouseup event.");
    1.54 +        is(childStats.mouseClick, false, "Child should not receive click event.");
    1.55 +        is(childStats.mouseScroll, false, "Child should not receive DOMMouseScroll event.");
    1.56 +        is(childStats.wheel, false, "Child should not receive wheel event.");
    1.57 +
    1.58 +        ok(parentStats.mouseMove, "Parent should receive mousemove event.");
    1.59 +        ok(parentStats.mouseDown, "Parent should receive mousedown event.");
    1.60 +        ok(parentStats.mouseUp, "Parent should receive mouseup event.");
    1.61 +        ok(parentStats.mouseClick, "Parent should receive click event.");
    1.62 +        ok(parentStats.mouseScroll, "Parent should receive DOMMouseScroll event.");
    1.63 +        ok(parentStats.wheel, "Parent should receive wheel event.");
    1.64 +      }
    1.65 +
    1.66 +
    1.67 +      /**
    1.68 +       * The event listeners for the child element shouldn't be fired
    1.69 +       * Mouse events will only happen when the pointer is locked
    1.70 +       * and if the pointer is locked all the mouse events should be
    1.71 +       * retargetted to the locked element
    1.72 +       **/
    1.73 +      var childMoveTest = function() {
    1.74 +        childStats.mouseMove = true;
    1.75 +      }
    1.76 +
    1.77 +      var childDownTest = function() {
    1.78 +        childStats.mouseDown = true;
    1.79 +      };
    1.80 +
    1.81 +      var childUpTest = function() {
    1.82 +        childStats.mouseUp = true;
    1.83 +      };
    1.84 +
    1.85 +      var childClickTest = function() {
    1.86 +        childStats.mouseClick = true;
    1.87 +      };
    1.88 +
    1.89 +      var childScrollTest = function() {
    1.90 +        childStats.mouseScroll = true;
    1.91 +      };
    1.92 +
    1.93 +      var childWheelTest = function() {
    1.94 +        childStats.wheel = true;
    1.95 +      };
    1.96 +
    1.97 +      //  Event listeners for the parent element
    1.98 +      var startMouseTests = function() {
    1.99 +        parent.removeEventListener("mousemove", startMouseTests);
   1.100 +        parent.addEventListener("DOMMouseScroll", parentScrollTest);
   1.101 +        child.addEventListener("DOMMouseScroll", childScrollTest);
   1.102 +        synthesizeWheel(child, 5, 5, {'deltaY': 10, 'lineOrPageDeltaY': 10,
   1.103 +                                      'deltaMode': WheelEvent.DOM_DELTA_LINE});
   1.104 +      };
   1.105 +
   1.106 +      var parentScrollTest = function (e) {
   1.107 +        parentStats.mouseScroll = true;
   1.108 +        parent.removeEventListener("DOMMouseScroll", parentScrollTest);
   1.109 +        child.removeEventListener("DOMMouseScroll", childScrollTest);
   1.110 +        parent.addEventListener("wheel", parentWheelTest);
   1.111 +        child.addEventListener("wheel", childWheelTest);
   1.112 +        synthesizeWheel(child, 5, 5, {'deltaY': 10, 'lineOrPageDeltaY': 10,
   1.113 +                                      'deltaMode': WheelEvent.DOM_DELTA_LINE});
   1.114 +      };
   1.115 +
   1.116 +      var parentWheelTest = function (e) {
   1.117 +        parentStats.wheel = true;
   1.118 +        parent.removeEventListener("wheel", parentWheelTest);
   1.119 +        child.removeEventListener("wheel", childWheelTest);
   1.120 +        parent.addEventListener("mousedown", parentDownTest);
   1.121 +        child.addEventListener("mousedown", childDownTest);
   1.122 +        synthesizeMouseAtCenter(child, {type: "mousedown"}, window);
   1.123 +      };
   1.124 +
   1.125 +      var parentDownTest = function (e) {
   1.126 +        parentStats.mouseDown = true;
   1.127 +        parent.removeEventListener("mousedown", parentDownTest);
   1.128 +        child.removeEventListener("mousedown", childDownTest);
   1.129 +        parent.addEventListener("mouseup", parentUpTest);
   1.130 +        child.addEventListener("mouseup", childUpTest);
   1.131 +        synthesizeMouseAtCenter(child, {type: "mouseup"}, window);
   1.132 +      };
   1.133 +
   1.134 +      var parentUpTest = function (e) {
   1.135 +        parentStats.mouseUp = true;
   1.136 +        parent.removeEventListener("mouseup", parentUpTest);
   1.137 +        child.removeEventListener("mouseup", childUpTest);
   1.138 +        parent.addEventListener("click", parentClickTest);
   1.139 +        child.addEventListener("click", childClickTest);
   1.140 +        synthesizeMouseAtCenter(child, {type: "click"}, window);
   1.141 +      };
   1.142 +
   1.143 +      var parentClickTest = function (e) {
   1.144 +        parentStats.mouseClick = true;
   1.145 +        parent.removeEventListener("click", parentClickTest);
   1.146 +        child.removeEventListener("click", childClickTest);
   1.147 +        parent.addEventListener("mousemove", parentMoveTest);
   1.148 +        child.addEventListener("mousemove", childMoveTest);
   1.149 +        synthesizeMouseAtCenter(child, {type: "mousemove"}, window);
   1.150 +      };
   1.151 +
   1.152 +      var parentMoveTest = function (e) {
   1.153 +        parentStats.mouseMove = true;
   1.154 +        parent.removeEventListener("mousemove", parentMoveTest);
   1.155 +        child.removeEventListener("mousemove", childMoveTest);
   1.156 +        document.mozCancelFullScreen();
   1.157 +      }
   1.158 +
   1.159 +      document.addEventListener("mozpointerlockchange", function (e) {
   1.160 +        if (document.mozPointerLockElement === parent) {
   1.161 +          parent.addEventListener("mousemove", startMouseTests);
   1.162 +          child.addEventListener("mousemove", childMoveTest);
   1.163 +          synthesizeMouseAtCenter(parent, {type: "mousemove"}, window);
   1.164 +        }
   1.165 +      }, false);
   1.166 +
   1.167 +      document.addEventListener("mozfullscreenchange", function (e)  {
   1.168 +        if (document.mozFullScreenElement === parent) {
   1.169 +          parent.mozRequestPointerLock();
   1.170 +        } else {
   1.171 +          runTests();
   1.172 +          SimpleTest.finish();
   1.173 +        }
   1.174 +      }, false);
   1.175 +
   1.176 +      function start() {
   1.177 +        parent.mozRequestFullScreen();
   1.178 +      }
   1.179 +    </script>
   1.180 +  </pre>
   1.181 +</body>
   1.182 +</html>

mercurial