dom/tests/mochitest/pointerlock/file_infiniteMovement.html

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:323335699fea
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 * This test checks if mozMovementX and mozMovementY
26 * are present in a 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 * This test will also test that the incremental movement is
31 * not constrained to the width of the screen.
32 */
33
34 SimpleTest.waitForExplicitFinish();
35
36 var div = document.getElementById("div")
37 , divCenterWidth = 0
38 , divCenterHeight = 0
39 , totalMovementX = 0
40 , totalMovementY = 0;
41
42 function runTests () {
43 ok(totalMovementX > div.getBoundingClientRect().width,
44 "Should have moved more than one screen's worth in width." +
45 "TotalX: " + totalMovementX + " Screensize X: " + div.getBoundingClientRect().width);
46 ok(totalMovementY > div.getBoundingClientRect().height,
47 "Should have moved more than one screen's worth in height." +
48 "TotalY: " + totalMovementY + " Screensize Y: " + div.getBoundingClientRect().height);
49 }
50
51 var firstMoveListener = function (e) {
52 div.removeEventListener("mousemove", firstMoveListener, false);
53 div.addEventListener("mousemove", secondMoveListener, false);
54
55 synthesizeMouse(div,(divCenterWidth/2) * 3,
56 (divCenterHeight/2) * 3, {
57 type: "mousemove"
58 }, window);
59 }
60
61 var secondMoveListener = function (e) {
62 totalMovementX = divCenterWidth + ((divCenterWidth / 2) * 3);
63 totalMovementY = divCenterHeight + ((divCenterHeight / 2) * 3);
64
65 div.removeEventListener("mousemove", secondMoveListener, false);
66 document.mozCancelFullScreen();
67 }
68
69 document.addEventListener("mozpointerlockchange", function (e) {
70 if (document.mozPointerLockElement === div) {
71 div.addEventListener("mousemove", firstMoveListener, false);
72
73 divCenterWidth = Math.round(div.getBoundingClientRect().width / 2);
74 divCenterHeight = Math.round(div.getBoundingClientRect().height / 2);
75
76 synthesizeMouse(div, divCenterWidth, divCenterHeight, {
77 type: "mousemove"
78 }, window);
79 }
80 }, false);
81
82 document.addEventListener("mozfullscreenchange", function() {
83 if (document.mozFullScreenElement === div) {
84 div.mozRequestPointerLock();
85 }
86 else {
87 runTests();
88 SimpleTest.finish();
89 }
90 }, false);
91
92 function start() {
93 div.mozRequestFullScreen();
94 }
95 </script>
96 </pre>
97 </body>
98 </html>

mercurial