|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=633602 |
|
5 --> |
|
6 <head> |
|
7 <title>Bug 633602 - file_retargetMouseEvents.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 |
|
19 <div id="parent"> |
|
20 <div id="child" style="width: 100%; height: 100%;"> |
|
21 </div> |
|
22 </div> |
|
23 |
|
24 <pre id="test"> |
|
25 <script type="application/javascript"> |
|
26 /* |
|
27 * Test for Bug 633602 |
|
28 * Retarget mouse events to the locked element |
|
29 */ |
|
30 |
|
31 SimpleTest.waitForExplicitFinish(); |
|
32 |
|
33 function MouseEventStats() { |
|
34 this.mouseMove = false; |
|
35 this.mouseDown = false; |
|
36 this.mouseUp = false; |
|
37 this.mouseClick = false; |
|
38 this.mouseScroll = false; |
|
39 this.wheel = false; |
|
40 } |
|
41 |
|
42 var parent = document.getElementById("parent") |
|
43 , child = document.getElementById("child") |
|
44 , parentStats = new MouseEventStats() |
|
45 , childStats = new MouseEventStats(); |
|
46 |
|
47 function runTests () { |
|
48 is(childStats.mouseMove, false, "Child shound not receive mousemove event."); |
|
49 is(childStats.mouseDown, false, "Child should not receive mousedown event."); |
|
50 is(childStats.mouseUp, false, "Child should not receive mouseup event."); |
|
51 is(childStats.mouseClick, false, "Child should not receive click event."); |
|
52 is(childStats.mouseScroll, false, "Child should not receive DOMMouseScroll event."); |
|
53 is(childStats.wheel, false, "Child should not receive wheel event."); |
|
54 |
|
55 ok(parentStats.mouseMove, "Parent should receive mousemove event."); |
|
56 ok(parentStats.mouseDown, "Parent should receive mousedown event."); |
|
57 ok(parentStats.mouseUp, "Parent should receive mouseup event."); |
|
58 ok(parentStats.mouseClick, "Parent should receive click event."); |
|
59 ok(parentStats.mouseScroll, "Parent should receive DOMMouseScroll event."); |
|
60 ok(parentStats.wheel, "Parent should receive wheel event."); |
|
61 } |
|
62 |
|
63 |
|
64 /** |
|
65 * The event listeners for the child element shouldn't be fired |
|
66 * Mouse events will only happen when the pointer is locked |
|
67 * and if the pointer is locked all the mouse events should be |
|
68 * retargetted to the locked element |
|
69 **/ |
|
70 var childMoveTest = function() { |
|
71 childStats.mouseMove = true; |
|
72 } |
|
73 |
|
74 var childDownTest = function() { |
|
75 childStats.mouseDown = true; |
|
76 }; |
|
77 |
|
78 var childUpTest = function() { |
|
79 childStats.mouseUp = true; |
|
80 }; |
|
81 |
|
82 var childClickTest = function() { |
|
83 childStats.mouseClick = true; |
|
84 }; |
|
85 |
|
86 var childScrollTest = function() { |
|
87 childStats.mouseScroll = true; |
|
88 }; |
|
89 |
|
90 var childWheelTest = function() { |
|
91 childStats.wheel = true; |
|
92 }; |
|
93 |
|
94 // Event listeners for the parent element |
|
95 var startMouseTests = function() { |
|
96 parent.removeEventListener("mousemove", startMouseTests); |
|
97 parent.addEventListener("DOMMouseScroll", parentScrollTest); |
|
98 child.addEventListener("DOMMouseScroll", childScrollTest); |
|
99 synthesizeWheel(child, 5, 5, {'deltaY': 10, 'lineOrPageDeltaY': 10, |
|
100 'deltaMode': WheelEvent.DOM_DELTA_LINE}); |
|
101 }; |
|
102 |
|
103 var parentScrollTest = function (e) { |
|
104 parentStats.mouseScroll = true; |
|
105 parent.removeEventListener("DOMMouseScroll", parentScrollTest); |
|
106 child.removeEventListener("DOMMouseScroll", childScrollTest); |
|
107 parent.addEventListener("wheel", parentWheelTest); |
|
108 child.addEventListener("wheel", childWheelTest); |
|
109 synthesizeWheel(child, 5, 5, {'deltaY': 10, 'lineOrPageDeltaY': 10, |
|
110 'deltaMode': WheelEvent.DOM_DELTA_LINE}); |
|
111 }; |
|
112 |
|
113 var parentWheelTest = function (e) { |
|
114 parentStats.wheel = true; |
|
115 parent.removeEventListener("wheel", parentWheelTest); |
|
116 child.removeEventListener("wheel", childWheelTest); |
|
117 parent.addEventListener("mousedown", parentDownTest); |
|
118 child.addEventListener("mousedown", childDownTest); |
|
119 synthesizeMouseAtCenter(child, {type: "mousedown"}, window); |
|
120 }; |
|
121 |
|
122 var parentDownTest = function (e) { |
|
123 parentStats.mouseDown = true; |
|
124 parent.removeEventListener("mousedown", parentDownTest); |
|
125 child.removeEventListener("mousedown", childDownTest); |
|
126 parent.addEventListener("mouseup", parentUpTest); |
|
127 child.addEventListener("mouseup", childUpTest); |
|
128 synthesizeMouseAtCenter(child, {type: "mouseup"}, window); |
|
129 }; |
|
130 |
|
131 var parentUpTest = function (e) { |
|
132 parentStats.mouseUp = true; |
|
133 parent.removeEventListener("mouseup", parentUpTest); |
|
134 child.removeEventListener("mouseup", childUpTest); |
|
135 parent.addEventListener("click", parentClickTest); |
|
136 child.addEventListener("click", childClickTest); |
|
137 synthesizeMouseAtCenter(child, {type: "click"}, window); |
|
138 }; |
|
139 |
|
140 var parentClickTest = function (e) { |
|
141 parentStats.mouseClick = true; |
|
142 parent.removeEventListener("click", parentClickTest); |
|
143 child.removeEventListener("click", childClickTest); |
|
144 parent.addEventListener("mousemove", parentMoveTest); |
|
145 child.addEventListener("mousemove", childMoveTest); |
|
146 synthesizeMouseAtCenter(child, {type: "mousemove"}, window); |
|
147 }; |
|
148 |
|
149 var parentMoveTest = function (e) { |
|
150 parentStats.mouseMove = true; |
|
151 parent.removeEventListener("mousemove", parentMoveTest); |
|
152 child.removeEventListener("mousemove", childMoveTest); |
|
153 document.mozCancelFullScreen(); |
|
154 } |
|
155 |
|
156 document.addEventListener("mozpointerlockchange", function (e) { |
|
157 if (document.mozPointerLockElement === parent) { |
|
158 parent.addEventListener("mousemove", startMouseTests); |
|
159 child.addEventListener("mousemove", childMoveTest); |
|
160 synthesizeMouseAtCenter(parent, {type: "mousemove"}, window); |
|
161 } |
|
162 }, false); |
|
163 |
|
164 document.addEventListener("mozfullscreenchange", function (e) { |
|
165 if (document.mozFullScreenElement === parent) { |
|
166 parent.mozRequestPointerLock(); |
|
167 } else { |
|
168 runTests(); |
|
169 SimpleTest.finish(); |
|
170 } |
|
171 }, false); |
|
172 |
|
173 function start() { |
|
174 parent.mozRequestFullScreen(); |
|
175 } |
|
176 </script> |
|
177 </pre> |
|
178 </body> |
|
179 </html> |