OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The Chromium Authors. All rights reserved. | 2 * Copyright 2013 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /** | 7 /** |
8 * Mock typing of basic keys. Each keystroke should trigger a pair of | |
9 * API calls to send viritual key events. | |
10 * @param {string} label The character being typed. | |
11 * @param {number} keyCode The legacy key code for the character. | |
12 * @param {boolean} shiftModifier Indicates if the shift key is being | |
13 * virtually pressed. | |
14 * @param {number=} opt_unicode Optional unicode value for the character. Only | |
15 * required if it cannot be directly calculated from the label. | |
16 */ | |
17 function mockTypeCharacter(label, keyCode, shiftModifier, opt_unicode) { | |
18 var key = findKey(label); | |
19 assertTrue(!!key, 'Unable to find key labelled "' + label + '".'); | |
20 var unicodeValue = opt_unicode | label.charCodeAt(0); | |
21 var send = chrome.virtualKeyboardPrivate.sendKeyEvent; | |
22 send.addExpectation({ | |
23 type: 'keydown', | |
24 charValue: unicodeValue, | |
25 keyCode: keyCode, | |
26 shiftKey: shiftModifier | |
27 }); | |
28 send.addExpectation({ | |
29 type: 'keyup', | |
30 charValue: unicodeValue, | |
31 keyCode: keyCode, | |
32 shiftKey: shiftModifier | |
33 }); | |
34 // Fake typing the key. | |
35 key.down(); | |
36 key.up(); | |
37 } | |
38 | |
39 /** | |
40 * Mocks using the longpress candidate window to enter an alternate character. | 8 * Mocks using the longpress candidate window to enter an alternate character. |
41 * @param {string} label The label on the key. | 9 * @param {string} label The label on the key. |
42 * @param {string} candidateLabel The alternate character being typed. | 10 * @param {string} candidateLabel The alternate character being typed. |
43 * @param {number} keyCode The keyCode for the alternate character, which may | 11 * @param {number} keyCode The keyCode for the alternate character, which may |
44 * be zero for characters not found on a QWERTY keyboard. | 12 * be zero for characters not found on a QWERTY keyboard. |
45 * @param {boolean} shiftModifier Indicates the state of the shift key when | 13 * @param {boolean} shiftModifier Indicates the state of the shift key when |
46 * entering the character. | 14 * entering the character. |
47 */ | 15 */ |
48 function mockLongPressType(label, candidateLabel, keyCode, shiftModifier) { | 16 function mockLongPressType(label, candidateLabel, keyCode, shiftModifier) { |
49 // Verify that candidates popup window is initally hidden. | 17 // Verify that candidates popup window is initally hidden. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // accented letters. | 101 // accented letters. |
134 // Type lowercase E acute. | 102 // Type lowercase E acute. |
135 mockLongPressType('e', '\u00E9', 0, false); | 103 mockLongPressType('e', '\u00E9', 0, false); |
136 // Type the digit '3' (hintText on the 'e' key). | 104 // Type the digit '3' (hintText on the 'e' key). |
137 mockLongPressType('e', '3', 0x33, false); | 105 mockLongPressType('e', '3', 0x33, false); |
138 }; | 106 }; |
139 onKeyboardReady('testLongPressTypeAccentedCharacterAsync', | 107 onKeyboardReady('testLongPressTypeAccentedCharacterAsync', |
140 runTest, | 108 runTest, |
141 testDoneCallback); | 109 testDoneCallback); |
142 } | 110 } |
OLD | NEW |