OLD | NEW |
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. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 function testDefaultPrevented() { | 69 function testDefaultPrevented() { |
70 var event = {}; | 70 var event = {}; |
71 event.defaultPrevented = true; | 71 event.defaultPrevented = true; |
72 var bEvent = new goog.events.BrowserEvent(event); | 72 var bEvent = new goog.events.BrowserEvent(event); |
73 assertTrue(bEvent.defaultPrevented); | 73 assertTrue(bEvent.defaultPrevented); |
74 } | 74 } |
75 | 75 |
76 function testIsButtonIe() { | 76 function testIsButtonIe() { |
77 stubs.set(goog.events.BrowserFeature, 'HAS_W3C_BUTTON', false); | 77 stubs.set(goog.events.BrowserFeature, 'HAS_W3C_BUTTON', false); |
78 assertIsButton( | 78 assertIsButton( |
79 createBrowserEvent('mousedown', 1), | 79 createMouseEvent('mousedown', 1), |
80 Button.LEFT, | 80 Button.LEFT, |
81 true); | 81 true); |
82 assertIsButton( | 82 assertIsButton( |
83 createBrowserEvent('click', 0), | 83 createMouseEvent('click', 0), |
84 Button.LEFT, | 84 Button.LEFT, |
85 true); | 85 true); |
86 assertIsButton( | 86 assertIsButton( |
87 createBrowserEvent('mousedown', 2), | 87 createMouseEvent('mousedown', 2), |
88 Button.RIGHT, | 88 Button.RIGHT, |
89 false); | 89 false); |
90 assertIsButton( | 90 assertIsButton( |
91 createBrowserEvent('mousedown', 4), | 91 createMouseEvent('mousedown', 4), |
92 Button.MIDDLE, | 92 Button.MIDDLE, |
93 false); | 93 false); |
94 } | 94 } |
95 | 95 |
96 function testIsButtonWebkitMac() { | 96 function testIsButtonWebkitMac() { |
97 stubs.set(goog.events.BrowserFeature, 'HAS_W3C_BUTTON', true); | 97 stubs.set(goog.events.BrowserFeature, 'HAS_W3C_BUTTON', true); |
98 stubs.set(goog.userAgent, 'WEBKIT', true); | 98 stubs.set(goog.userAgent, 'WEBKIT', true); |
99 stubs.set(goog.userAgent, 'MAC', true); | 99 stubs.set(goog.userAgent, 'MAC', true); |
100 assertIsButton( | 100 assertIsButton( |
101 createBrowserEvent('mousedown', 0), | 101 createMouseEvent('mousedown', 0), |
102 Button.LEFT, | 102 Button.LEFT, |
103 true); | 103 true); |
104 assertIsButton( | 104 assertIsButton( |
105 createBrowserEvent('mousedown', 0, true), | 105 createMouseEvent('mousedown', 0, true), |
106 Button.LEFT, | 106 Button.LEFT, |
107 false); | 107 false); |
108 assertIsButton( | 108 assertIsButton( |
109 createBrowserEvent('mousedown', 2), | 109 createMouseEvent('mousedown', 2), |
110 Button.RIGHT, | 110 Button.RIGHT, |
111 false); | 111 false); |
112 assertIsButton( | 112 assertIsButton( |
113 createBrowserEvent('mousedown', 2, true), | 113 createMouseEvent('mousedown', 2, true), |
114 Button.RIGHT, | 114 Button.RIGHT, |
115 false); | 115 false); |
116 assertIsButton( | 116 assertIsButton( |
117 createBrowserEvent('mousedown', 1), | 117 createMouseEvent('mousedown', 1), |
118 Button.MIDDLE, | 118 Button.MIDDLE, |
119 false); | 119 false); |
120 assertIsButton( | 120 assertIsButton( |
121 createBrowserEvent('mousedown', 1, true), | 121 createMouseEvent('mousedown', 1, true), |
122 Button.MIDDLE, | 122 Button.MIDDLE, |
123 false); | 123 false); |
124 } | 124 } |
125 | 125 |
126 function testIsButtonGecko() { | 126 function testIsButtonGecko() { |
127 stubs.set(goog.events.BrowserFeature, 'HAS_W3C_BUTTON', true); | 127 stubs.set(goog.events.BrowserFeature, 'HAS_W3C_BUTTON', true); |
128 stubs.set(goog.userAgent, 'GECKO', true); | 128 stubs.set(goog.userAgent, 'GECKO', true); |
129 stubs.set(goog.userAgent, 'MAC', true); | 129 stubs.set(goog.userAgent, 'MAC', true); |
130 assertIsButton( | 130 assertIsButton( |
131 createBrowserEvent('mousedown', 0), | 131 createMouseEvent('mousedown', 0), |
132 Button.LEFT, | 132 Button.LEFT, |
133 true); | 133 true); |
134 assertIsButton( | 134 assertIsButton( |
135 createBrowserEvent('mousedown', 2, true), | 135 createMouseEvent('mousedown', 2, true), |
136 Button.RIGHT, | 136 Button.RIGHT, |
137 false); | 137 false); |
138 } | 138 } |
139 | 139 |
140 function createBrowserEvent(type, button, opt_ctrlKey) { | 140 function testTouchEventHandling() { |
| 141 var clientCoords = [5, 5]; |
| 142 var screenCoords = [10, 10]; |
| 143 var target = document.body; |
| 144 var touchStart = createTargetTouchEvent('touchstart', target, clientCoords, |
| 145 screenCoords); |
| 146 var touchMove = createTargetTouchEvent('touchmove', target, clientCoords, |
| 147 screenCoords); |
| 148 var touchEnd = createChangedTouchEvent('touchend', target, clientCoords, |
| 149 screenCoords); |
| 150 var touchCancel = createChangedTouchEvent('touchcancel', target, |
| 151 clientCoords, screenCoords); |
| 152 |
| 153 assertEquals(clientCoords[0], touchStart.clientX); |
| 154 assertEquals(clientCoords[1], touchStart.clientY); |
| 155 assertEquals(target, touchStart.target); |
| 156 |
| 157 assertEquals(screenCoords[0], touchMove.screenX); |
| 158 assertEquals(screenCoords[1], touchMove.screenY); |
| 159 |
| 160 assertEquals(clientCoords[0], touchEnd.clientX); |
| 161 assertEquals(clientCoords[1], touchEnd.clientY); |
| 162 |
| 163 assertEquals(screenCoords[0], touchCancel.screenX); |
| 164 assertEquals(screenCoords[1], touchCancel.screenY); |
| 165 assertEquals(target, touchCancel.target); |
| 166 } |
| 167 |
| 168 function createMouseEvent(type, button, opt_ctrlKey) { |
141 return new goog.events.BrowserEvent({ | 169 return new goog.events.BrowserEvent({ |
142 type: type, | 170 type: type, |
143 button: button, | 171 button: button, |
144 ctrlKey: !!opt_ctrlKey | 172 ctrlKey: !!opt_ctrlKey |
145 }); | 173 }); |
146 } | 174 } |
147 | 175 |
| 176 function createTargetTouchEvent(type, target, clientCoords, screenCoords) { |
| 177 return new goog.events.BrowserEvent({ |
| 178 type: type, |
| 179 targetTouches: [{ |
| 180 target: target, |
| 181 clientX: clientCoords[0], |
| 182 clientY: clientCoords[1], |
| 183 screenX: screenCoords[0], |
| 184 screenY: screenCoords[1] |
| 185 }] |
| 186 }); |
| 187 } |
| 188 |
| 189 function createChangedTouchEvent(type, target, clientCoords, screenCoords) { |
| 190 return new goog.events.BrowserEvent({ |
| 191 type: type, |
| 192 changedTouches: [{ |
| 193 target: target, |
| 194 clientX: clientCoords[0], |
| 195 clientY: clientCoords[1], |
| 196 screenX: screenCoords[0], |
| 197 screenY: screenCoords[1] |
| 198 }] |
| 199 }); |
| 200 } |
| 201 |
148 function assertIsButton(event, button, isActionButton) { | 202 function assertIsButton(event, button, isActionButton) { |
149 for (var key in Button) { | 203 for (var key in Button) { |
150 assertEquals( | 204 assertEquals( |
151 'Testing isButton(' + key + ') against ' + | 205 'Testing isButton(' + key + ') against ' + |
152 button + ' and type ' + event.type, | 206 button + ' and type ' + event.type, |
153 Button[key] == button, event.isButton(Button[key])); | 207 Button[key] == button, event.isButton(Button[key])); |
154 } | 208 } |
155 | 209 |
156 assertEquals(isActionButton, event.isMouseActionButton()); | 210 assertEquals(isActionButton, event.isMouseActionButton()); |
157 } | 211 } |
158 | 212 |
159 </script> | 213 </script> |
160 </body> | 214 </body> |
161 </html> | 215 </html> |
OLD | NEW |