LEFT | RIGHT |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 | 2 |
3 <!-- | 3 <!-- |
4 | 4 |
5 Author: nicksantos@google.com (Nick Santos) | 5 Author: nicksantos@google.com (Nick Santos) |
6 --> | 6 --> |
7 | 7 |
8 <html> | 8 <html> |
9 <!-- | 9 <!-- |
10 Copyright 2009 The Closure Library Authors. All Rights Reserved. | 10 Copyright 2009 The Closure Library Authors. All Rights Reserved. |
11 | 11 |
12 Use of this source code is governed by the Apache License, Version 2.0. | 12 Use of this source code is governed by the Apache License, Version 2.0. |
13 See the COPYING file for details. | 13 See the COPYING file for details. |
14 --> | 14 --> |
15 <head> | 15 <head> |
16 <meta http-equiv="X-UA-Compatible" content="IE=edge"> | 16 <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
17 <title>JsUnit tests for goog.events.BrowserEvent</title> | 17 <title>JsUnit tests for goog.events.BrowserEvent</title> |
18 <script type='text/javascript' src='../base.js'></script> | 18 <script type='text/javascript' src='../base.js'></script> |
19 <script type='text/javascript'> | 19 <script type='text/javascript'> |
20 | 20 |
21 goog.require('goog.events.BrowserEvent'); | 21 goog.require('goog.events.BrowserEvent'); |
22 goog.require('goog.math.Coordinate'); | |
23 goog.require('goog.testing.PropertyReplacer'); | 22 goog.require('goog.testing.PropertyReplacer'); |
24 goog.require('goog.testing.jsunit'); | 23 goog.require('goog.testing.jsunit'); |
25 goog.require('goog.userAgent'); | 24 goog.require('goog.userAgent'); |
26 | 25 |
27 | 26 |
28 </script> | 27 </script> |
29 </head> | 28 </head> |
30 <body> | 29 <body> |
31 <script type='text/javascript'> | 30 <script type='text/javascript'> |
32 | 31 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 createMouseEvent('mousedown', 0), | 131 createMouseEvent('mousedown', 0), |
133 Button.LEFT, | 132 Button.LEFT, |
134 true); | 133 true); |
135 assertIsButton( | 134 assertIsButton( |
136 createMouseEvent('mousedown', 2, true), | 135 createMouseEvent('mousedown', 2, true), |
137 Button.RIGHT, | 136 Button.RIGHT, |
138 false); | 137 false); |
139 } | 138 } |
140 | 139 |
141 function testTouchEventHandling() { | 140 function testTouchEventHandling() { |
142 var clientCoords = new goog.math.Coordinate(5, 5); | 141 var clientCoords = [5, 5]; |
143 var screenCoords = new goog.math.Coordinate(10, 10); | 142 var screenCoords = [10, 10]; |
144 var target = document.body; | 143 var target = document.body; |
145 var touchStart = createTargetTouchEvent('touchstart', target, clientCoords, | 144 var touchStart = createTargetTouchEvent('touchstart', target, clientCoords, |
146 screenCoords); | 145 screenCoords); |
147 var touchMove = createTargetTouchEvent('touchmove', target, clientCoords, | 146 var touchMove = createTargetTouchEvent('touchmove', target, clientCoords, |
148 screenCoords); | 147 screenCoords); |
149 var touchEnd = createChangedTouchEvent('touchend', target, clientCoords, | 148 var touchEnd = createChangedTouchEvent('touchend', target, clientCoords, |
150 screenCoords); | 149 screenCoords); |
151 var touchCancel = createChangedTouchEvent('touchcancel', target, | 150 var touchCancel = createChangedTouchEvent('touchcancel', target, |
152 clientCoords, screenCoords); | 151 clientCoords, screenCoords); |
153 | 152 |
154 assertEquals(clientCoords.x, touchStart.clientX); | 153 assertEquals(clientCoords[0], touchStart.clientX); |
155 assertEquals(clientCoords.y, touchStart.clientY); | 154 assertEquals(clientCoords[1], touchStart.clientY); |
156 assertEquals(target, touchStart.target); | 155 assertEquals(target, touchStart.target); |
157 | 156 |
158 assertEquals(screenCoords.x, touchMove.screenX); | 157 assertEquals(screenCoords[0], touchMove.screenX); |
159 assertEquals(screenCoords.y, touchMove.screenY); | 158 assertEquals(screenCoords[1], touchMove.screenY); |
160 | 159 |
161 assertEquals(clientCoords.x, touchEnd.clientX); | 160 assertEquals(clientCoords[0], touchEnd.clientX); |
162 assertEquals(clientCoords.y, touchEnd.clientY); | 161 assertEquals(clientCoords[1], touchEnd.clientY); |
163 | 162 |
164 assertEquals(screenCoords.x, touchCancel.screenX); | 163 assertEquals(screenCoords[0], touchCancel.screenX); |
165 assertEquals(screenCoords.y, touchCancel.screenY); | 164 assertEquals(screenCoords[1], touchCancel.screenY); |
166 assertEquals(target, touchCancel.target); | 165 assertEquals(target, touchCancel.target); |
167 } | 166 } |
168 | 167 |
169 function createMouseEvent(type, button, opt_ctrlKey) { | 168 function createMouseEvent(type, button, opt_ctrlKey) { |
170 return new goog.events.BrowserEvent({ | 169 return new goog.events.BrowserEvent({ |
171 type: type, | 170 type: type, |
172 button: button, | 171 button: button, |
173 ctrlKey: !!opt_ctrlKey | 172 ctrlKey: !!opt_ctrlKey |
174 }); | 173 }); |
175 } | 174 } |
176 | 175 |
177 function createTargetTouchEvent(type, target, clientCoords, screenCoords) { | 176 function createTargetTouchEvent(type, target, clientCoords, screenCoords) { |
178 return new goog.events.BrowserEvent({ | 177 return new goog.events.BrowserEvent({ |
179 type: type, | 178 type: type, |
180 targetTouches: [{ | 179 targetTouches: [{ |
181 target: target, | 180 target: target, |
182 clientX: clientCoords.x, | 181 clientX: clientCoords[0], |
183 clientY: clientCoords.y, | 182 clientY: clientCoords[1], |
184 screenX: screenCoords.x, | 183 screenX: screenCoords[0], |
185 screenY: screenCoords.y | 184 screenY: screenCoords[1] |
186 }] | 185 }] |
187 }); | 186 }); |
188 } | 187 } |
189 | 188 |
190 function createChangedTouchEvent(type, target, clientCoords, screenCoords) { | 189 function createChangedTouchEvent(type, target, clientCoords, screenCoords) { |
191 return new goog.events.BrowserEvent({ | 190 return new goog.events.BrowserEvent({ |
192 type: type, | 191 type: type, |
193 changedTouches: [{ | 192 changedTouches: [{ |
194 target: target, | 193 target: target, |
195 clientX: clientCoords.x, | 194 clientX: clientCoords[0], |
196 clientY: clientCoords.y, | 195 clientY: clientCoords[1], |
197 screenX: screenCoords.x, | 196 screenX: screenCoords[0], |
198 screenY: screenCoords.y | 197 screenY: screenCoords[1] |
199 }] | 198 }] |
200 }); | 199 }); |
201 } | 200 } |
202 | 201 |
203 function assertIsButton(event, button, isActionButton) { | 202 function assertIsButton(event, button, isActionButton) { |
204 for (var key in Button) { | 203 for (var key in Button) { |
205 assertEquals( | 204 assertEquals( |
206 'Testing isButton(' + key + ') against ' + | 205 'Testing isButton(' + key + ') against ' + |
207 button + ' and type ' + event.type, | 206 button + ' and type ' + event.type, |
208 Button[key] == button, event.isButton(Button[key])); | 207 Button[key] == button, event.isButton(Button[key])); |
209 } | 208 } |
210 | 209 |
211 assertEquals(isActionButton, event.isMouseActionButton()); | 210 assertEquals(isActionButton, event.isMouseActionButton()); |
212 } | 211 } |
213 | 212 |
214 </script> | 213 </script> |
215 </body> | 214 </body> |
216 </html> | 215 </html> |
LEFT | RIGHT |