dom/tests/mochitest/pointerlock/file_screenClientXYConst.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:a4e15a10f15e
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=633602
5 -->
6 <head>
7 <title>Bug 633602 - constantXY.html</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js">
9 </script>
10 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
11 <script type="application/javascript" src="pointerlock_utils.js"></script>
12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
13 </head>
14 <body>
15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602">
16 Mozilla Bug 633602
17 </a>
18 <div id="div"></div>
19 <script type="application/javascript">
20 /*
21 * Test for Bug 633602
22 * Confirm that screenX/Y and clientX/Y are constants when the pointer
23 * is locked.
24 */
25
26 SimpleTest.waitForExplicitFinish();
27
28 var div
29 , divRect
30 , unLockedCoords
31 , lockedCoords
32 , isUnlocked = false
33 , isLocked = false;
34
35 function runTests () {
36 ok(isUnlocked, "Pointer should be unlocked");
37 ok(isLocked, "Pointer should be locked");
38
39 // Confirm that pointer coords are constant while locked
40 is(unLockedCoords.clientX, lockedCoords.clientX,
41 "clientX should be equal to where the mouse was originaly locked");
42 is(unLockedCoords.clientY, lockedCoords.clientY,
43 "clientY should be equal to where the mouse was originaly locked");
44 is(unLockedCoords.screenX, lockedCoords.screenX,
45 "screenX should be equal to where the mouse was originaly locked");
46 is(unLockedCoords.screenY, lockedCoords.screenY,
47 "screenY should be equal to where the mouse was originaly locked");
48 }
49
50 function moveUnlocked(e) {
51 var firstCall = !unLockedCoords;
52 if (!firstCall) {
53 todo(false, "mousemove is fired twice.");
54 }
55
56 isUnlocked = !document.mozPointerLockElement;
57 unLockedCoords = {
58 screenX: e.screenX,
59 screenY: e.screenY,
60 clientX: e.clientX,
61 clientY: e.clientY
62 };
63
64 if (!firstCall) {
65 return;
66 }
67
68 div.mozRequestPointerLock();
69 }
70
71 function moveLocked(e) {
72 div.removeEventListener("mousemove", moveLocked, false);
73
74 isLocked = !!document.mozPointerLockElement;
75 lockedCoords = {
76 screenX: e.screenX,
77 screenY: e.screenY,
78 clientX: e.clientX,
79 clientY: e.clientY
80 };
81
82 document.mozCancelFullScreen();
83 }
84
85 document.addEventListener("mozpointerlockchange", function (e) {
86 if (document.mozPointerLockElement === div) {
87 div.removeEventListener("mousemove", moveUnlocked, false);
88 div.addEventListener("mousemove", moveLocked, false);
89 divRect = div.getBoundingClientRect();
90 synthesizeMouse(div, (divRect.width / 4) * 3, (divRect.height / 4) * 3, {
91 type: "mousemove"
92 }, window);
93 }
94 }, false);
95
96 function fullscreenchange() {
97 var screenX = window.screenX;
98 var screenY = window.screenY;
99 if (document.mozFullScreenElement === div) {
100 if (screenX != 0 || screenY != 0) {
101 todo(screenX == 0 && screenY == 0,
102 "We should only receive fullscreenchange once we've finished fullscreen transition " +
103 "window.screenX=" + screenX + " window.screenY=" + screenY);
104 setTimeout(fullscreenchange, 250);
105 return;
106 }
107 div.addEventListener("mousemove", moveUnlocked, false);
108 synthesizeMouseAtCenter(div, { type: "mousemove" }, window);
109 } else {
110 runTests();
111 SimpleTest.finish();
112 }
113 }
114 document.addEventListener("mozfullscreenchange", fullscreenchange, false);
115
116 function start() {
117 div = document.getElementById("div");
118 div.mozRequestFullScreen();
119 }
120 </script>
121 </body>
122 </html>

mercurial