Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: third_party/polymer/v1_0/components-chromium/iron-test-helpers/mock-interactions.js

Issue 1849403002: Update PolymerElements/iron-a11y-keys-behavior for ESC key fix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /** 1 /**
2 * @license 2 * @license
3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. 3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at http://polyme r.github.io/LICENSE.txt 4 * This code may only be used under the BSD style license found at http://polyme r.github.io/LICENSE.txt
5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS. txt 5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS. txt
6 * The complete set of contributors may be found at http://polymer.github.io/CON TRIBUTORS.txt 6 * The complete set of contributors may be found at http://polymer.github.io/CON TRIBUTORS.txt
7 * Code distributed by Google as part of the polymer project is also 7 * Code distributed by Google as part of the polymer project is also
8 * subject to an additional IP rights grant found at http://polymer.github.io/PA TENTS.txt 8 * subject to an additional IP rights grant found at http://polymer.github.io/PA TENTS.txt
9 */ 9 */
10 10
11 (function(global) { 11 (function(global) {
12 'use strict'; 12 'use strict';
13 13
14 var HAS_NEW_MOUSE = (function() { 14 var HAS_NEW_MOUSE = (function() {
15 var has = false; 15 var has = false;
16 try { 16 try {
17 has = Boolean(new MouseEvent('x')); 17 has = Boolean(new MouseEvent('x'));
18 } catch (_) {} 18 } catch (_) {}
19 return has; 19 return has;
20 })(); 20 })();
21 21
22 /* 22 /**
23 * Returns the (x,y) coordinates representing the middle of a node. 23 * Returns the (x,y) coordinates representing the middle of a node.
24 * 24 *
25 * @param {HTMLElement} node An element. 25 * @param {!HTMLElement} node An element.
26 */ 26 */
27 function middleOfNode(node) { 27 function middleOfNode(node) {
28 var bcr = node.getBoundingClientRect(); 28 var bcr = node.getBoundingClientRect();
29 return { 29 return {
30 y: bcr.top + (bcr.height / 2), 30 y: bcr.top + (bcr.height / 2),
31 x: bcr.left + (bcr.width / 2) 31 x: bcr.left + (bcr.width / 2)
32 }; 32 };
33 } 33 }
34 34
35 /* 35 /**
36 * Returns the (x,y) coordinates representing the top left corner of a node. 36 * Returns the (x,y) coordinates representing the top left corner of a node.
37 * 37 *
38 * @param {HTMLElement} node An element. 38 * @param {!HTMLElement} node An element.
39 */ 39 */
40 function topLeftOfNode(node) { 40 function topLeftOfNode(node) {
41 var bcr = node.getBoundingClientRect(); 41 var bcr = node.getBoundingClientRect();
42 return { 42 return {
43 y: bcr.top, 43 y: bcr.top,
44 x: bcr.left 44 x: bcr.left
45 }; 45 };
46 } 46 }
47 47
48 /* 48 /**
49 * Returns a list of Touch objects that correspond to an array of positions
50 * and a target node. The Touch instances will each have a unique Touch
51 * identifier.
52 *
53 * @param {!Array<{ x: number, y: number }>} xyList A list of (x,y) coordinate objects.
54 * @param {!HTMLElement} node A target element node.
55 */
56 function makeTouches(xyList, node) {
57 var id = 0;
58
59 return xyList.map(function(xy) {
60 var touchInit = {
61 identifier: id++,
62 target: node,
63 clientX: xy.x,
64 clientY: xy.y
65 };
66
67 return window.Touch ? new window.Touch(touchInit) : touchInit;
68 });
69 }
70
71 /**
72 * Generates and dispatches a TouchEvent of a given type, at a specified
73 * position of a target node.
74 *
75 * @param {string} type The type of TouchEvent to generate.
76 * @param {{ x: number, y: number }} xy An (x,y) coordinate for the generated
77 * TouchEvent.
78 * @param {!HTMLElement} node The target element node for the generated
79 * TouchEvent to be dispatched on.
80 */
81 function makeSoloTouchEvent(type, xy, node) {
82 xy = xy || middleOfNode(node);
83 var touches = makeTouches([xy], node);
84 var touchEventInit = {
85 touches: touches,
86 targetTouches: touches,
87 changedTouches: touches
88 };
89 var event;
90
91 if (window.TouchEvent) {
92 event = new TouchEvent(type, touchEventInit);
93 } else {
94 event = new CustomEvent(type, { bubbles: true, cancelable: true });
95 for (var property in touchEventInit) {
96 event[property] = touchEventInit[property];
97 }
98 }
99
100 node.dispatchEvent(event);
101 }
102
103 /**
49 * Fires a mouse event on a specific node, at a given set of coordinates. 104 * Fires a mouse event on a specific node, at a given set of coordinates.
50 * This event bubbles and is cancellable. 105 * This event bubbles and is cancellable.
51 * 106 *
52 * @param {String} type The type of mouse event (such as 'tap' or 'down'). 107 * @param {string} type The type of mouse event (such as 'tap' or 'down').
53 * @param {Object} xy The (x,y) coordinates the mouse event should be fired fr om. 108 * @param {{ x: number, y: number }} xy The (x,y) coordinates the mouse event should be fired from.
54 * @param {HTMLElement} node The node to fire the event on. 109 * @param {!HTMLElement} node The node to fire the event on.
55 */ 110 */
56 function makeEvent(type, xy, node) { 111 function makeMouseEvent(type, xy, node) {
57 var props = { 112 var props = {
58 bubbles: true, 113 bubbles: true,
59 cancelable: true, 114 cancelable: true,
60 clientX: xy.x, 115 clientX: xy.x,
61 clientY: xy.y, 116 clientY: xy.y,
62 // Make this a primary input. 117 // Make this a primary input.
63 buttons: 1 // http://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/b uttons 118 buttons: 1 // http://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/b uttons
64 }; 119 };
65 var e; 120 var e;
66 var mousetype = type === 'tap' ? 'click' : 'mouse' + type;
67 if (HAS_NEW_MOUSE) { 121 if (HAS_NEW_MOUSE) {
68 e = new MouseEvent(mousetype, props); 122 e = new MouseEvent(type, props);
69 } else { 123 } else {
70 e = document.createEvent('MouseEvent'); 124 e = document.createEvent('MouseEvent');
71 e.initMouseEvent( 125 e.initMouseEvent(
72 mousetype, props.bubbles, props.cancelable, 126 type, props.bubbles, props.cancelable,
73 null, /* view */ 127 null, /* view */
74 null, /* detail */ 128 null, /* detail */
75 0, /* screenX */ 129 0, /* screenX */
76 0, /* screenY */ 130 0, /* screenY */
77 props.clientX, props.clientY, 131 props.clientX, props.clientY,
78 false, /*ctrlKey */ 132 false, /*ctrlKey */
79 false, /*altKey */ 133 false, /*altKey */
80 false, /*shiftKey */ 134 false, /*shiftKey */
81 false, /*metaKey */ 135 false, /*metaKey */
82 0, /*button */ 136 0, /*button */
83 null /*relatedTarget*/); 137 null /*relatedTarget*/);
84 } 138 }
85 node.dispatchEvent(e); 139 node.dispatchEvent(e);
86 } 140 }
87 141
88 /* 142 /**
89 * Simulates a mouse move action by firing a `move` mouse event on a 143 * Simulates a mouse move action by firing a `move` mouse event on a
90 * specific node, between a set of coordinates. 144 * specific node, between a set of coordinates.
91 * 145 *
92 * @param {HTMLElement} node The node to fire the event on. 146 * @param {!HTMLElement} node The node to fire the event on.
93 * @param {Object} fromXY The (x,y) coordinates the dragging should start from . 147 * @param {Object} fromXY The (x,y) coordinates the dragging should start from .
94 * @param {Object} toXY The (x,y) coordinates the dragging should end at. 148 * @param {Object} toXY The (x,y) coordinates the dragging should end at.
95 * @param {Object} steps Optional. The numbers of steps in the move motion. 149 * @param {?number} steps Optional. The numbers of steps in the move motion.
96 * If not specified, the default is 5. 150 * If not specified, the default is 5.
97 */ 151 */
98 function move(node, fromXY, toXY, steps) { 152 function move(node, fromXY, toXY, steps) {
99 steps = steps || 5; 153 steps = steps || 5;
100 var dx = Math.round((fromXY.x - toXY.x) / steps); 154 var dx = Math.round((fromXY.x - toXY.x) / steps);
101 var dy = Math.round((fromXY.y - toXY.y) / steps); 155 var dy = Math.round((fromXY.y - toXY.y) / steps);
102 var xy = { 156 var xy = {
103 x: fromXY.x, 157 x: fromXY.x,
104 y: fromXY.y 158 y: fromXY.y
105 }; 159 };
106 for (var i = steps; i > 0; i--) { 160 for (var i = steps; i > 0; i--) {
107 makeEvent('move', xy, node); 161 makeMouseEvent('mousemove', xy, node);
108 xy.x += dx; 162 xy.x += dx;
109 xy.y += dy; 163 xy.y += dy;
110 } 164 }
111 makeEvent('move', { 165 makeMouseEvent('mousemove', {
112 x: toXY.x, 166 x: toXY.x,
113 y: toXY.y 167 y: toXY.y
114 }, node); 168 }, node);
115 } 169 }
116 170
117 /* 171 /**
118 * Simulates a mouse dragging action originating in the middle of a specific n ode. 172 * Simulates a mouse dragging action originating in the middle of a specific n ode.
119 * 173 *
120 * @param {HTMLElement} target The node to fire the event on. 174 * @param {!HTMLElement} target The node to fire the event on.
121 * @param {Number} dx The horizontal displacement. 175 * @param {?number} dx The horizontal displacement.
122 * @param {Object} dy The vertical displacement 176 * @param {?number} dy The vertical displacement
123 * @param {Object} steps Optional. The numbers of steps in the dragging motion . 177 * @param {?number} steps Optional. The numbers of steps in the dragging motio n.
124 * If not specified, the default is 5. 178 * If not specified, the default is 5.
125 */ 179 */
126 function track(target, dx, dy, steps) { 180 function track(target, dx, dy, steps) {
127 dx = dx | 0; 181 dx = dx | 0;
128 dy = dy | 0; 182 dy = dy | 0;
129 steps = steps || 5; 183 steps = steps || 5;
130 down(target); 184 down(target);
131 var xy = middleOfNode(target); 185 var xy = middleOfNode(target);
132 var xy2 = { 186 var xy2 = {
133 x: xy.x + dx, 187 x: xy.x + dx,
134 y: xy.y + dy 188 y: xy.y + dy
135 }; 189 };
136 move(target, xy, xy2, steps); 190 move(target, xy, xy2, steps);
137 up(target, xy2); 191 up(target, xy2);
138 } 192 }
139 193
140 /* 194 /**
141 * Fires a `down` mouse event on a specific node, at a given set of coordinate s. 195 * Fires a `down` mouse event on a specific node, at a given set of coordinate s.
142 * This event bubbles and is cancellable. If the (x,y) coordinates are 196 * This event bubbles and is cancellable. If the (x,y) coordinates are
143 * not specified, the middle of the node will be used instead. 197 * not specified, the middle of the node will be used instead.
144 * 198 *
145 * @param {HTMLElement} node The node to fire the event on. 199 * @param {!HTMLElement} node The node to fire the event on.
146 * @param {Object} xy Optional. The (x,y) coordinates the mouse event should b e fired from. 200 * @param {{ x: number, y: number }=} xy Optional. The (x,y) coordinates the m ouse event should be fired from.
147 */ 201 */
148 function down(node, xy) { 202 function down(node, xy) {
149 xy = xy || middleOfNode(node); 203 xy = xy || middleOfNode(node);
150 makeEvent('down', xy, node); 204 makeMouseEvent('mousedown', xy, node);
151 } 205 }
152 206
153 /* 207 /**
154 * Fires an `up` mouse event on a specific node, at a given set of coordinates . 208 * Fires an `up` mouse event on a specific node, at a given set of coordinates .
155 * This event bubbles and is cancellable. If the (x,y) coordinates are 209 * This event bubbles and is cancellable. If the (x,y) coordinates are
156 * not specified, the middle of the node will be used instead. 210 * not specified, the middle of the node will be used instead.
157 * 211 *
158 * @param {HTMLElement} node The node to fire the event on. 212 * @param {!HTMLElement} node The node to fire the event on.
159 * @param {Object} xy Optional. The (x,y) coordinates the mouse event should b e fired from. 213 * @param {{ x: number, y: number }=} xy Optional. The (x,y) coordinates the m ouse event should be fired from.
160 */ 214 */
161 function up(node, xy) { 215 function up(node, xy) {
162 xy = xy || middleOfNode(node); 216 xy = xy || middleOfNode(node);
163 makeEvent('up', xy, node); 217 makeMouseEvent('mouseup', xy, node);
164 } 218 }
165 219
166 /* 220 /**
221 * Generate a click event on a given node, optionally at a given coordinate.
222 * @param {!HTMLElement} node The node to fire the click event on.
223 * @param {{ x: number, y: number }=} xy Optional. The (x,y) coordinates the m ouse event should
224 * be fired from.
225 */
226 function click(node, xy) {
227 xy = xy || middleOfNode(node);
228 makeMouseEvent('click', xy, node);
229 }
230
231 /**
232 * Generate a touchstart event on a given node, optionally at a given coordina te.
233 * @param {!HTMLElement} node The node to fire the click event on.
234 * @param {{ x: number, y: number }=} xy Optional. The (x,y) coordinates the t ouch event should
235 * be fired from.
236 */
237 function touchstart(node, xy) {
238 xy = xy || middleOfNode(node);
239 makeSoloTouchEvent('touchstart', xy, node);
240 }
241
242
243 /**
244 * Generate a touchend event on a given node, optionally at a given coordinate .
245 * @param {!HTMLElement} node The node to fire the click event on.
246 * @param {{ x: number, y: number }=} xy Optional. The (x,y) coordinates the t ouch event should
247 * be fired from.
248 */
249 function touchend(node, xy) {
250 xy = xy || middleOfNode(node);
251 makeSoloTouchEvent('touchend', xy, node);
252 }
253
254 /**
167 * Simulates a complete mouse click by firing a `down` mouse event, followed 255 * Simulates a complete mouse click by firing a `down` mouse event, followed
168 * by an asynchronous `up` and `tap` events on a specific node. Calls the 256 * by an asynchronous `up` and `tap` events on a specific node. Calls the
169 *`callback` after the `tap` event is fired. 257 *`callback` after the `tap` event is fired.
170 * 258 *
171 * @param {HTMLElement} target The node to fire the event on. 259 * @param {!HTMLElement} target The node to fire the event on.
172 * @param {Object} callback Optional. The function to be called after the acti on ends. 260 * @param {?Function} callback Optional. The function to be called after the a ction ends.
261 * @param {?{
262 * emulateTouch: boolean
263 * }} options Optional. Configure the emulation fidelity of the mouse events.
173 */ 264 */
174 function downAndUp(target, callback) { 265 function downAndUp(target, callback, options) {
266 if (options && options.emulateTouch) {
267 touchstart(target);
268 touchend(target);
269 }
270
175 down(target); 271 down(target);
176 Polymer.Base.async(function() { 272 Polymer.Base.async(function() {
177 up(target); 273 up(target);
178 tap(target); 274 click(target);
179
180 callback && callback(); 275 callback && callback();
181 }); 276 });
182 } 277 }
183 278
184 /* 279 /**
185 * Fires a 'tap' mouse event on a specific node. This respects the pointer-eve nts 280 * Fires a 'tap' mouse event on a specific node. This respects the pointer-eve nts
186 * set on the node, and will not fire on disabled nodes. 281 * set on the node, and will not fire on disabled nodes.
187 * 282 *
188 * @param {HTMLElement} node The node to fire the event on. 283 * @param {!HTMLElement} node The node to fire the event on.
189 * @param {Object} xy Optional. The (x,y) coordinates the mouse event should b e fired from. 284 * @param {?{
285 * emulateTouch: boolean
286 * }} options Optional. Configure the emulation fidelity of the mouse event.
190 */ 287 */
191 function tap(node) { 288 function tap(node, options) {
192 // Respect nodes that are disabled in the UI. 289 // Respect nodes that are disabled in the UI.
193 if (window.getComputedStyle(node)['pointer-events'] === 'none') 290 if (window.getComputedStyle(node)['pointer-events'] === 'none')
194 return; 291 return;
292
195 var xy = middleOfNode(node); 293 var xy = middleOfNode(node);
294
295 if (options && options.emulateTouch) {
296 touchstart(node, xy);
297 touchend(node, xy);
298 }
299
196 down(node, xy); 300 down(node, xy);
197 up(node, xy); 301 up(node, xy);
198 makeEvent('tap', xy, node); 302 click(node, xy);
199 } 303 }
200 304
201 /* 305 /**
202 * Focuses a node by firing a `focus` event. This event does not bubble. 306 * Focuses a node by firing a `focus` event. This event does not bubble.
203 * 307 *
204 * @param {HTMLElement} target The node to fire the event on. 308 * @param {!HTMLElement} target The node to fire the event on.
205 */ 309 */
206 function focus(target) { 310 function focus(target) {
207 Polymer.Base.fire('focus', {}, { 311 Polymer.Base.fire('focus', {}, {
208 bubbles: false, 312 bubbles: false,
209 node: target 313 node: target
210 }); 314 });
211 } 315 }
212 316
213 /* 317 /**
214 * Blurs a node by firing a `blur` event. This event does not bubble. 318 * Blurs a node by firing a `blur` event. This event does not bubble.
215 * 319 *
216 * @param {HTMLElement} target The node to fire the event on. 320 * @param {!HTMLElement} target The node to fire the event on.
217 */ 321 */
218 function blur(target) { 322 function blur(target) {
219 Polymer.Base.fire('blur', {}, { 323 Polymer.Base.fire('blur', {}, {
220 bubbles: false, 324 bubbles: false,
221 node: target 325 node: target
222 }); 326 });
223 } 327 }
224 328
225 /* 329 /**
226 * Returns a keyboard event. This event bubbles and is cancellable. 330 * Returns a keyboard event. This event bubbles and is cancellable.
227 * 331 *
228 * @param {String} type The type of keyboard event (such as 'keyup' or 'keydow n'). 332 * @param {string} type The type of keyboard event (such as 'keyup' or 'keydow n').
229 * @param {Number} keyCode The keyCode for the event. 333 * @param {number} keyCode The keyCode for the event.
230 * @param {?String|[String]} modifiers The key modifiers for the event. 334 * @param {(string|Array<string>)=} modifiers The key modifiers for the event.
231 * Accepted values are shift, ctrl, alt, meta. 335 * Accepted values are shift, ctrl, alt, meta.
336 * @param {string=} key The KeyboardEvent.key value for the event.
232 */ 337 */
233 function keyboardEventFor(type, keyCode, modifiers) { 338 function keyboardEventFor(type, keyCode, modifiers, key) {
234 var event = new CustomEvent(type, { 339 var event = new CustomEvent(type, {
235 bubbles: true, 340 bubbles: true,
236 cancelable: true 341 cancelable: true
237 }); 342 });
238 343
239 event.keyCode = keyCode; 344 event.keyCode = keyCode;
240 event.code = keyCode; 345 event.code = keyCode;
241 346
242 modifiers = modifiers || []; 347 modifiers = modifiers || [];
243 if (typeof modifiers === 'string') { 348 if (typeof modifiers === 'string') {
244 modifiers = [modifiers]; 349 modifiers = [modifiers];
245 } 350 }
246 event.shiftKey = modifiers.indexOf('shift') !== -1; 351 event.shiftKey = modifiers.indexOf('shift') !== -1;
247 event.altKey = modifiers.indexOf('alt') !== -1; 352 event.altKey = modifiers.indexOf('alt') !== -1;
248 event.ctrlKey = modifiers.indexOf('ctrl') !== -1; 353 event.ctrlKey = modifiers.indexOf('ctrl') !== -1;
249 event.metaKey = modifiers.indexOf('meta') !== -1; 354 event.metaKey = modifiers.indexOf('meta') !== -1;
250 355
356 event.key = key;
357
251 return event; 358 return event;
252 } 359 }
253 360
254 /* 361 /**
255 * Fires a keyboard event on a specific node. This event bubbles and is cancel lable. 362 * Fires a keyboard event on a specific node. This event bubbles and is cancel lable.
256 * 363 *
257 * @param {HTMLElement} target The node to fire the event on. 364 * @param {!HTMLElement} target The node to fire the event on.
258 * @param {String} type The type of keyboard event (such as 'keyup' or 'keydow n'). 365 * @param {string} type The type of keyboard event (such as 'keyup' or 'keydow n').
259 * @param {Number} keyCode The keyCode for the event. 366 * @param {number} keyCode The keyCode for the event.
260 * @param {?String|[String]} modifiers The key modifiers for the event. 367 * @param {(string|Array<string>)=} modifiers The key modifiers for the event.
261 * Accepted values are shift, ctrl, alt, meta. 368 * Accepted values are shift, ctrl, alt, meta.
369 * @param {string=} key The KeyboardEvent.key value for the event.
262 */ 370 */
263 function keyEventOn(target, type, keyCode, modifiers) { 371 function keyEventOn(target, type, keyCode, modifiers, key) {
264 target.dispatchEvent(keyboardEventFor(type, keyCode, modifiers)); 372 target.dispatchEvent(keyboardEventFor(type, keyCode, modifiers, key));
265 } 373 }
266 374
267 /* 375 /**
268 * Fires a 'keydown' event on a specific node. This event bubbles and is cance llable. 376 * Fires a 'keydown' event on a specific node. This event bubbles and is cance llable.
269 * 377 *
270 * @param {HTMLElement} target The node to fire the event on. 378 * @param {!HTMLElement} target The node to fire the event on.
271 * @param {Number} keyCode The keyCode for the event. 379 * @param {number} keyCode The keyCode for the event.
272 * @param {?String|[String]} modifiers The key modifiers for the event. 380 * @param {(string|Array<string>)=} modifiers The key modifiers for the event.
273 * Accepted values are shift, ctrl, alt, meta. 381 * Accepted values are shift, ctrl, alt, meta.
382 * @param {string=} key The KeyboardEvent.key value for the event.
274 */ 383 */
275 function keyDownOn(target, keyCode, modifiers) { 384 function keyDownOn(target, keyCode, modifiers, key) {
276 keyEventOn(target, 'keydown', keyCode, modifiers); 385 keyEventOn(target, 'keydown', keyCode, modifiers, key);
277 } 386 }
278 387
279 /* 388 /**
280 * Fires a 'keyup' event on a specific node. This event bubbles and is cancell able. 389 * Fires a 'keyup' event on a specific node. This event bubbles and is cancell able.
281 * 390 *
282 * @param {HTMLElement} target The node to fire the event on. 391 * @param {!HTMLElement} target The node to fire the event on.
283 * @param {Number} keyCode The keyCode for the event. 392 * @param {number} keyCode The keyCode for the event.
284 * @param {?String|[String]} modifiers The key modifiers for the event. 393 * @param {(string|Array<string>)=} modifiers The key modifiers for the event.
285 * Accepted values are shift, ctrl, alt, meta. 394 * Accepted values are shift, ctrl, alt, meta.
395 * @param {string=} key The KeyboardEvent.key value for the event.
286 */ 396 */
287 function keyUpOn(target, keyCode, modifiers) { 397 function keyUpOn(target, keyCode, modifiers, key) {
288 keyEventOn(target, 'keyup', keyCode, modifiers); 398 keyEventOn(target, 'keyup', keyCode, modifiers, key);
289 } 399 }
290 400
291 /* 401 /**
292 * Simulates a complete key press by firing a `keydown` keyboard event, follow ed 402 * Simulates a complete key press by firing a `keydown` keyboard event, follow ed
293 * by an asynchronous `keyup` event on a specific node. 403 * by an asynchronous `keyup` event on a specific node.
294 * 404 *
295 * @param {HTMLElement} target The node to fire the event on. 405 * @param {!HTMLElement} target The node to fire the event on.
296 * @param {Number} keyCode The keyCode for the event. 406 * @param {number} keyCode The keyCode for the event.
297 * @param {?String|[String]} modifiers The key modifiers for the event. 407 * @param {(string|Array<string>)=} modifiers The key modifiers for the event.
298 * Accepted values are shift, ctrl, alt, meta. 408 * Accepted values are shift, ctrl, alt, meta.
409 * @param {string=} key The KeyboardEvent.key value for the event.
299 */ 410 */
300 function pressAndReleaseKeyOn(target, keyCode, modifiers) { 411 function pressAndReleaseKeyOn(target, keyCode, modifiers, key) {
301 keyDownOn(target, keyCode, modifiers); 412 keyDownOn(target, keyCode, modifiers, key);
302 Polymer.Base.async(function() { 413 Polymer.Base.async(function() {
303 keyUpOn(target, keyCode, modifiers); 414 keyUpOn(target, keyCode, modifiers, key);
304 }, 1); 415 }, 1);
305 } 416 }
306 417
307 /* 418 /**
308 * Simulates a complete 'enter' key press by firing a `keydown` keyboard event , 419 * Simulates a complete 'enter' key press by firing a `keydown` keyboard event ,
309 * followed by an asynchronous `keyup` event on a specific node. 420 * followed by an asynchronous `keyup` event on a specific node.
310 * 421 *
311 * @param {HTMLElement} target The node to fire the event on. 422 * @param {!HTMLElement} target The node to fire the event on.
312 */ 423 */
313 function pressEnter(target) { 424 function pressEnter(target) {
314 pressAndReleaseKeyOn(target, 13); 425 pressAndReleaseKeyOn(target, 13);
315 } 426 }
316 427
317 /* 428 /**
318 * Simulates a complete 'space' key press by firing a `keydown` keyboard event , 429 * Simulates a complete 'space' key press by firing a `keydown` keyboard event ,
319 * followed by an asynchronous `keyup` event on a specific node. 430 * followed by an asynchronous `keyup` event on a specific node.
320 * 431 *
321 * @param {HTMLElement} target The node to fire the event on. 432 * @param {!HTMLElement} target The node to fire the event on.
322 */ 433 */
323 function pressSpace(target) { 434 function pressSpace(target) {
324 pressAndReleaseKeyOn(target, 32); 435 pressAndReleaseKeyOn(target, 32);
325 } 436 }
326 437
327 global.MockInteractions = { 438 global.MockInteractions = {
328 focus: focus, 439 focus: focus,
329 blur: blur, 440 blur: blur,
330 down: down, 441 down: down,
331 up: up, 442 up: up,
332 downAndUp: downAndUp, 443 downAndUp: downAndUp,
333 tap: tap, 444 tap: tap,
334 track: track, 445 track: track,
335 pressAndReleaseKeyOn: pressAndReleaseKeyOn, 446 pressAndReleaseKeyOn: pressAndReleaseKeyOn,
336 pressEnter: pressEnter, 447 pressEnter: pressEnter,
337 pressSpace: pressSpace, 448 pressSpace: pressSpace,
338 keyDownOn: keyDownOn, 449 keyDownOn: keyDownOn,
339 keyUpOn: keyUpOn, 450 keyUpOn: keyUpOn,
451 keyboardEventFor: keyboardEventFor,
340 keyEventOn: keyEventOn, 452 keyEventOn: keyEventOn,
341 middleOfNode: middleOfNode, 453 middleOfNode: middleOfNode,
342 topLeftOfNode: topLeftOfNode 454 topLeftOfNode: topLeftOfNode
343 }; 455 };
344 })(this); 456 })(this);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698