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

Side by Side Diff: chrome/test/data/chromeos/virtual_keyboard/control_keys_test.js

Issue 25305003: Automated tests for the shift key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added longpress and double click tests. Created 7 years, 2 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
(Empty)
1 /*
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
4 * found in the LICENSE file.
5 */
6
7 /**
8 * Gets all shift keys on the keyboard.
kevers 2013/09/30 21:58:28 This description does not appear to be consistent
rsadam 2013/09/30 22:52:09 Done.
9 * @param {string} alignment, Which of {left, right} shift keys to return.
kevers 2013/09/30 21:58:28 Nit. No punctuation between variable name and desc
rsadam 2013/09/30 22:52:09 Done.
10 * @return {{string: string}} a map from keyset to the shift key in it.
kevers 2013/09/30 21:58:28 {Object.<string, Object>} ?
rsadam 2013/09/30 22:52:09 Done.
11 */
12 function getShiftKeys(alignment) {
13 var layout = keyboard.layout;
14 var keysets = ['lower', 'upper'];
15
16 var result={};
17 for(var keysetIndex in keysets) {
18 var keysetId = keysets[keysetIndex];
19 // The keyset DOM object which contains a shift key.
20 var keyset = keyboard.querySelector('#' + layout + "-" + keysetId);
21 assertTrue(!!keyset, "Cannot find keyset: " + keyset);
22 var shiftKey = keyset.querySelector('kb-shift-key[align="' +
23 alignment + '"]');
24 assertTrue(!!shiftKey, "Keyset " + keysetId +
25 " does not have a shift key with " + alignment + " alignment");
26 result[keysetId] = shiftKey;
27 }
28 return result;
29 }
30
31 /**
32 * Tests chording with a single shift key.
33 * @param {Object} lowerShift, a shift key in the lower key set.
34 * @param {Object} uppserShift, the same shift key in the upper key set.
35 */
36 function checkShiftChording(lowerShift, upperShift) {
37 var lower = lowerShift.lowerCaseKeysetId;
38 var upper = lowerShift.upperCaseKeysetId;
39 // Check that we're testing from correct initial state.
40 assertTrue(keyboard.keyset == lower, "Start keyset should by: " +
kevers 2013/09/30 21:58:28 should by -> should be Use assertEquals here rath
rsadam 2013/09/30 22:52:09 Done.
41 lower + ". Was: " + keyboard.keyset);
42 var mockEvent = {pointerId:1, isPrimary:true};
43 lowerShift.down(mockEvent);
44 assertTrue(keyboard.keyset == upper,
45 "Did not transition to uppercase on shift key down. Expected: " +
46 upper + ". Was: " + keyboard.keyset);
47 // Some alphanumeric character
48 mockTypeCharacter('A', 0x41, true);
49 assertTrue(keyboard.keyset == upper,
50 "Did not remain in uppercase. Expected: " +
51 upper + ". Was: " + keyboard.keyset);
52 mockTimer.tick(1000);
53 upperShift.up(mockEvent);
54 assertTrue(keyboard.keyset == lower,
55 "Did not revert to lowercase after chording. Expected: " +
56 lower + ". Was: " + keyboard.keyset);
57 }
58
59 /**
60 * Tests a particular shift key for highlighting on tapping. The keyboard
61 * should temporarily transition to uppercase, and after a non-control tap,
62 * revert to lower case.
63 * @param {Object} lowerShift The shift key object on the lower keyset.
64 * @param {Object} upperShift The shift key object on the upper keyset.
65 */
66 function checkShiftHighlight(lowerShift, upperShift) {
67 assertTrue(!!keyboard.shift, "Shift key was not cached by keyboard");
68 var unlocked = lowerShift.lowerCaseKeysetId;
69 var locked = lowerShift.upperCaseKeysetId;
70 assertTrue(keyboard.keyset == unlocked,
71 "Initial keyboard keyset is not unlocked. Keyset: " +
kevers 2013/09/30 21:58:28 assertEquals
rsadam 2013/09/30 22:52:09 Done.
72 keyboard.keyset + " Expected: " + unlocked);
73 // Crashes if we don't give it a pointerId.
74 var mockEvent = { pointerId: 1};
75 // Tap shift key.
76 lowerShift.down(mockEvent);
77 upperShift.up(mockEvent);
78 // Tests that we are now in locked case.
79 assertTrue(keyboard.keyset == locked,
80 "Keyset is not locked on highlight. Keyset: " + keyboard.keyset +
81 " Expected: " + locked);
82 // Some alphanumeric character.
83 mockTypeCharacter('A', 0x41, true);
84 // Check that we've reverted to lower case.
85 assertTrue(keyboard.keyset == unlocked,
86 "Did not revert to lower case after highlight. Keyset: " +
87 keyboard.keyset + " Expected: " + unlocked);
88 // Check that we persist in lower case.
89 mockTypeCharacter('a', 0x41, false);
90 assertTrue(keyboard.keyset == unlocked,
91 "Did not stay in lower case after highlight. Keyset: " +
92 keyboard.keyset + " Expected: " + unlocked);
93 }
94
95 /**
96 * Tests that a particular shift key has been initialized correctly.
97 * @param {Object} shift The shift key.
98 */
99 function checkShiftInitialState(shift) {
100 //Checks that the unlocked case is lower.
101 var expectedUnlocked = 'lower';
102 assertTrue(shift.lowerCaseKeysetId == expectedUnlocked,
kevers 2013/09/30 21:58:28 assertEquals
rsadam 2013/09/30 22:52:09 Done.
103 "Expected unlocked case to be: " + expectedUnlocked + " was: " +
104 shift.lowerCaseKeysetId);
105 //Checks that the locked case is upper.
106 var expectedLocked = 'upper';
107 assertTrue(shift.upperCaseKeysetId == expectedLocked,
108 "Expected locked case to be: " + expectedLocked + " was: " +
109 shift.upperCaseKeysetId);
110 }
111
112 /**
113 * Tests that a particular shift key capitalizes on long press.
114 * @param {Object} shift The shift key.
115 */
116 function checkShiftLongPress(lowerShift, upperShift) {
117 // Check that keyboard is in expected start state.
118 assertTrue(!!keyboard.shift, "Shift key was not cached by keyboard");
119 var unlocked = lowerShift.lowerCaseKeysetId;
120 var locked = lowerShift.upperCaseKeysetId;
121 assertTrue(keyboard.keyset == unlocked,
kevers 2013/09/30 21:58:28 assertEquals
rsadam 2013/09/30 22:52:09 Done.
122 "Initial keyboard keyset is not unlocked. Keyset: " +
123 keyboard.keyset + " Expected: " + unlocked);
124 // Mocks a pointer event.
125 var mockEvent = { pointerId: 1};
126 lowerShift.down(mockEvent);
127 assertTrue(keyboard.keyset == locked,
128 "Did not transition to locked case on shift key down. Keyset: " +
129 keyboard.keyset + " Expected: " + locked);
130 // Long press should now be active.
131 mockTimer.tick(1000);
132 // Type any caps character, make sure we remain in caps mode.
133 upperShift.up(mockEvent);
134 mockTypeCharacter('A', 0x41, true);
135 assertTrue(keyboard.keyset == locked,
136 "Did not remain in locked case after long press. Keyset: " +
137 keyboard.keyset + " Expected: " + locked);
138 //Revert to lower case.
139 upperShift.down(mockEvent);
140 assertTrue(keyboard.keyset == unlocked,
141 "Did not revert to lower case on shift down. Keyset: " +
142 keyboard.keyset + " Expected: " + unlocked);
143 lowerShift.up(mockEvent);
144 }
145
146 function checkShiftDoubleClick(lowerShift, upperShift) {
147 // Check that keyboard is in expected start state.
148 assertTrue(!!keyboard.shift, "Shift key was not cached by keyboard");
149 var unlocked = lowerShift.lowerCaseKeysetId;
150 var locked = lowerShift.upperCaseKeysetId;
151 assertTrue(keyboard.keyset == unlocked,
kevers 2013/09/30 21:58:28 assertEquals
rsadam 2013/09/30 22:52:09 Done.
152 "Initial keyboard keyset is not unlocked. Keyset: " +
153 keyboard.keyset + " Expected: " + unlocked);
154 // Mocks a pointer event.
155 var mockEvent = { pointerId: 1};
156 lowerShift.down(mockEvent);
157 upperShift.up(mockEvent);
158 // Need to also mock a keyboard pointer up event.
159 keyboard.up(mockEvent);
160 upperShift.down(mockEvent);
161 upperShift.up(mockEvent);
162 keyboard.up(mockEvent);
163 // Check that we're capslocked.
164 assertTrue(keyboard.keyset == locked,
165 "Did not lock on double click. Keyset: " +
166 keyboard.keyset + " Expected: " + locked);
167 mockTypeCharacter('A', 0x41, true);
168 assertTrue(keyboard.keyset == locked,
169 "Did not remain in locked case after typing another key. Keyset: " +
170 keyboard.keyset + " Expected: " + locked);
171 // Reverts to lower case.
172 upperShift.down(mockEvent);
173 assertTrue(keyboard.keyset == unlocked,
174 "Did not revert to lower case on shift down. Keyset: " +
175 keyboard.keyset + " Expected: " + unlocked);
176 lowerShift.up(mockEvent);
177 }
178 /**
179 * Asynchronously tests highlighting of the left and right shift keys.
180 * @param {function} testDoneCallBack The callback function to be called
181 * on completion.
182 */
183 function testShiftHighlightAsync(testDoneCallback) {
184 var runTest = function() {
185 var alignments = ['left', 'right'];
186 for (var i in alignments) {
187 var alignment = alignments[i];
188 var shifts = getShiftKeys(alignment);
189 checkShiftHighlight(shifts['lower'], shifts['upper']);
190 }
191 };
192 onKeyboardReady('testShiftKeyHighlightAsync', runTest, testDoneCallback);
193 }
194
195 /**
196 * Asynchronously tests initialization of the left and right shift keys.
197 * @param {function} testDoneCallBack The callback function to be called
198 * on completion.
199 */
200 function testShiftKeyInitAsync(testDoneCallback) {
201 var runTest = function() {
202 var alignments = ['left', 'right'];
203 for (var i in alignments) {
204 var alignment = alignments[i];
205 var shifts = getShiftKeys(alignment);
206 checkShiftInitialState(shifts['lower']);
207 checkShiftInitialState(shifts['upper']);
208 }
209 };
210 onKeyboardReady('testShiftKeyInitAsync', runTest, testDoneCallback);
211 }
212
213 /**
214 * Asynchronously tests capitalization on double click of the left and
215 * right shift keys.
216 * @param {function} testDoneCallBack The callback function to be called
217 * on completion.
218 */
219 function testShiftDoubleClickAsync(testDoneCallback) {
220 var runTest = function() {
221 var alignments = ['left', 'right'];
222 for (var i in alignments) {
223 var alignment = alignments[i];
224 var shifts = getShiftKeys(alignment);
225 checkShiftDoubleClick(shifts['lower'], shifts['upper']);
226 }
227 };
228 onKeyboardReady('testShiftDoubleClickAsync', runTest, testDoneCallback);
229 }
230
231 /**
232 * Asynchronously tests capitalization on long press of the left and
233 * right shift keys.
234 * @param {function} testDoneCallBack The callback function to be called
235 * on completion.
236 */
237 function testShiftLongPressAsync(testDoneCallback) {
238 var runTest = function() {
239 var alignments = ['left', 'right'];
240 for (var i in alignments) {
241 var alignment = alignments[i];
242 var shifts = getShiftKeys(alignment);
243 checkShiftLongPress(shifts['lower'], shifts['upper']);
244 }
245 };
246 onKeyboardReady('testShiftLongPressAsync', runTest, testDoneCallback);
247 }
248
249 /**
250 * Asynchronously tests chording on the keyboard.
251 * @param {function} testDoneCallBack The callback function to be called
252 * on completion.
253 */
254 function testShiftChordingAsync(testDoneCallback) {
255 var runTest = function() {
256 var left = getShiftKeys('left');
257 var right = getShiftKeys('right');
258 checkShiftChording(left['lower'], left['upper']);
259 checkShiftChording(right['lower'], right['upper']);
260 }
261 onKeyboardReady('testShiftChordingAsync', runTest, testDoneCallback);
262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698