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

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

Powered by Google App Engine
This is Rietveld 408576698