SHARE
TWEET

moveMouseOutsideBrowser

a guest Dec 16th, 2011 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=633602
  5. -->
  6. <head>
  7.   <title>Test for Bug 633602</title>
  8.   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9.   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  10.   <!--<script type="text/javascript" src="mouselock_util.js"></script>-->
  11.   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  12. </head>
  13. <body onload="start();">
  14.   <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602">Mozilla Bug 633602</a>
  15.   <p id="display"></p>
  16.   <div id="content" style="display: none">
  17.   </div>
  18.  
  19.   <div id="div"></div>
  20.  
  21.   <pre id="test">
  22.     <script type="application/javascript">
  23.       /** Test for Bug 633602 **/
  24.       /**
  25.       The mouse is moved when it's not locked
  26.       Then the mouse is moved when it is locked
  27.       When the mouse isn't locked, the clientXY and screenXY should
  28.       have values representing their respectives positions on the screen
  29.       However, when the mouse is locked, they all should be equal to zero
  30.       **/
  31.       SimpleTest.waitForExplicitFinish();
  32.  
  33.       var pointer = navigator.pointer;
  34.       var div;
  35.       var countMoves = 0;
  36.       // The width and height of a div element
  37.       // These values will be used to move the mouse
  38.       var divWidth = 0;
  39.       var divHeight = 0;
  40.  
  41.  
  42.       SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only",
  43.                                   false);
  44.  
  45.  
  46.  
  47.       var moveFirst = function (e) {
  48.  
  49.         console.log("moveFirst");
  50.         console.log("e.screenX: " + e.screenX + " e.screenY: " + e.screenY);
  51.         console.log("e.clientX: " + e.clientX + " e.clientY:  " + e.clientY);
  52.         console.log("e.movementX: " + e.movementX + " e.movementY:  " + e.movementY);
  53.  
  54.         // Remove the current mousemove listener from "div" and add a new one
  55.         div.removeEventListener("mousemove", moveFirst, false);
  56.         div.addEventListener("mousemove", moveAgain, false);
  57.  
  58.           synthesizeMouse(div, div.offsetWidth-10, div.offsetHeight-10, {
  59.             type: "mousemove"
  60.           }, window);
  61.       };
  62.  
  63.       var moveAgain = function (e) {
  64.  
  65.         console.log("moveAgain");
  66.         console.log("e.screenX: " + e.screenX + " e.screenY: " + e.screenY);
  67.         console.log("e.clientX: " + e.clientX + " e.clientY:  " + e.clientY);
  68.         console.log("e.movementX: " + e.movementX + " e.movementY:  " + e.movementY);
  69.  
  70.  
  71.         // Remove the current mousemove listener from "div" and add a new one
  72.         div.removeEventListener("mousemove", moveAgain, false);
  73.         div.addEventListener("mousemove", moveLast, false);
  74.  
  75.           synthesizeMouse(div, 10, 10, {
  76.             type: "mousemove"
  77.           }, window);
  78.       };
  79.  
  80.  
  81.       var moveLast = function (e) {
  82.  
  83.         console.log("moveLast");
  84.         console.log("e.screenX: " + e.screenX + " e.screenY: " + e.screenY);
  85.         console.log("e.clientX: " + e.clientX + " e.clientY:  " + e.clientY);
  86.         console.log("e.movementX: " + e.movementX + " e.movementY:  " + e.movementY);
  87.  
  88.         document.mozCancelFullScreen();
  89.       };
  90.  
  91.  
  92.  
  93.       document.addEventListener("mozfullscreenchange", function() {
  94.         if (document.mozFullScreenElement === div) {
  95.           // Set the values for divWidth and divHeight
  96.           // It's dividing by two to make sure the value is a valid coord
  97.           // The value is being rounded since it's not possible to move
  98.           // the mouse to broken values
  99.           divWidth = Math.round(div.offsetWidth / 2);
  100.           divHeight = Math.round(div.offsetHeight / 2);
  101.           console.log("div.oofsetHeight: "  + div.offsetHeight);
  102.           console.log("div.oofsetWidth: "  + div.offsetWidth);
  103.           console.log("divWidth: "  + divWidth);
  104.           console.log("divHeight: "  + divHeight);
  105.           // Moving the mouse when the pointer is not locked
  106.           synthesizeMouse(div, divWidth, divHeight, {
  107.             type: "mousemove"
  108.           }, window);
  109.         } else {
  110.           SimpleTest.finish();
  111.         }
  112.       }, false);
  113.  
  114.       function start() {
  115.         console.log("start");
  116.         div = document.getElementById("div");
  117.         console.log("start");
  118.         div.addEventListener("mousemove", moveFirst, false);
  119.  
  120.         SimpleTest.waitForFocus(function() {
  121.           div.mozRequestFullScreen();
  122.         });
  123.       }
  124.     </script>
  125.   </pre>
  126. </body>
  127. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top