Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=633602
5 -->
6 <head>
7 <title>Bug 633602 - file_movementXY.html</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js">
9 </script>
10 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js">
11 </script>
12 <script type="application/javascript" src="pointerlock_utils.js"></script>
13 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
14 </head>
15 <body>
16 <a target="_blank"
17 href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602">
18 Mozilla Bug 633602
19 </a>
20 <div id="div"></div>
21 <pre id="test">
22 <script type="application/javascript">
23 /*
24 * Test for Bug 633602
25 * Checks if mozMovementX and mozMovementY are present
26 * in the mouse event object.
27 * It also checks the values for mozMovementXY.
28 * They should be equal to the current screenXY minus
29 * the last screenXY
30 */
32 SimpleTest.waitForExplicitFinish();
34 function MouseMovementStats() {
35 this.screenX = false;
36 this.screenY = false;
37 this.mozMovementX = false;
38 this.mozMovementY = false;
39 }
41 var div = document.getElementById("div")
42 , divCenterWidth = 0
43 , divCenterHeight = 0
44 , mozMovementX = false
45 , mozMovementY = false
46 , firstMove = new MouseMovementStats()
47 , secondMove = new MouseMovementStats();
49 function runTests () {
50 ok(mozMovementX && mozMovementY, "mozMovementX and " +
51 "mozMovementY should exist in mouse events objects.");
52 is(secondMove.mozMovementX, secondMove.screenX - firstMove.screenX,
53 "mozMovementX should be equal to eNow.screenX-ePrevious.screenX");
54 is(secondMove.mozMovementY, secondMove.screenY - firstMove.screenY,
55 "mozMovementY should be equal to eNow.screenY-ePrevious.screenY");
56 }
58 var moveMouse = function(e) {
59 mozMovementX = ("mozMovementX" in e);
60 mozMovementY = ("mozMovementY" in e);
62 div.removeEventListener("mousemove", moveMouse, false);
63 div.addEventListener("mousemove", moveMouseAgain, false);
65 firstMove.screenX = e.screenX;
66 firstMove.screenY = e.screenY;
68 divCenterWidth = Math.round(div.getBoundingClientRect().width / 2);
69 divCenterHeight = Math.round(div.getBoundingClientRect().height / 2);
71 synthesizeMouse(div, (divCenterWidth + 10), (divCenterHeight + 10), {
72 type: "mousemove"
73 }, window);
74 };
76 var moveMouseAgain = function(e) {
77 secondMove.screenX = e.screenX;
78 secondMove.screenY = e.screenY;
79 secondMove.mozMovementX = e.mozMovementX;
80 secondMove.mozMovementY = e.mozMovementY;
82 div.removeEventListener("mousemove", moveMouseAgain, false);
83 document.mozCancelFullScreen();
84 };
86 function fullscreenchange() {
87 if (document.mozFullScreenElement === div) {
88 var screenX = window.screenX;
89 var screenY = window.screenY;
90 if (screenX != 0 || screenY != 0) {
91 todo(screenX == 0 && screenY == 0,
92 "We should only receive fullscreenchange once we've finished fullscreen transition");
93 setTimeout(fullscreenchange, 250);
94 return;
95 }
96 div.addEventListener("mousemove", moveMouse, false);
97 synthesizeMouseAtCenter(div, {type: "mousemove"}, window);
98 }
99 else {
100 runTests();
101 SimpleTest.finish();
102 }
103 }
105 document.addEventListener("mozfullscreenchange", fullscreenchange, false);
107 function start() {
108 div.mozRequestFullScreen();
109 }
110 </script>
111 </pre>
112 </body>
113 </html>