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

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: Fixed nits. 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
133 /**
134 * Tests that a particular shift key capitalizes on double click.
135 * @param {Object} lowerShift The shift key in the lower keyset.
136 * @param {Object} upperShift The shift key in the upper keyset.
137 */
138 function checkShiftDoubleClick(lowerShift, upperShift) {
139 // Check that keyboard is in expected start state.
140 assertTrue(!!keyboard.shift, "Shift key was not cached by keyboard");
141 var unlocked = lowerShift.lowerCaseKeysetId;
142 var locked = lowerShift.upperCaseKeysetId;
143 assertEquals(unlocked, keyboard.keyset,
144 "Invalid initial keyboard keyset.");
145 // Mocks a pointer event.
146 var mockEvent = {pointerId: 1};
147 lowerShift.down(mockEvent);
148 upperShift.up(mockEvent);
149 // Need to also mock a keyboard pointer up event.
150 keyboard.up(mockEvent);
151 upperShift.down(mockEvent);
152 upperShift.up(mockEvent);
153 keyboard.up(mockEvent);
154 // Check that we're capslocked.
155 assertEquals(locked, keyboard.keyset,
156 "Did not lock on double click.");
157 mockTypeCharacter('A', 0x41, true);
158 assertEquals(locked, keyboard.keyset,
159 "Did not remain in locked case after typing another key.");
160 // Reverts to lower case.
161 upperShift.down(mockEvent);
162 assertEquals(unlocked, keyboard.keyset,
163 "Did not revert to lower case on shift down.");
164 lowerShift.up(mockEvent);
165 }
166 /**
167 * Asynchronously tests highlighting of the left and right shift keys.
168 * @param {function} testDoneCallBack The function to be called
169 * on completion.
170 */
171 function testShiftHighlightAsync(testDoneCallback) {
172 var runTest = function() {
173 var alignments = ['left', 'right'];
174 for (var i in alignments) {
175 var alignment = alignments[i];
176 var shifts = getShiftKeys(alignment);
177 checkShiftHighlight(shifts['lower'], shifts['upper']);
178 }
179 };
180 onKeyboardReady('testShiftKeyHighlightAsync', runTest, testDoneCallback);
181 }
182
183 /**
184 * Asynchronously tests initialization of the left and right shift keys.
185 * @param {function} testDoneCallBack The function to be called
186 * on completion.
187 */
188 function testShiftKeyInitAsync(testDoneCallback) {
189 var runTest = function() {
190 var alignments = ['left', 'right'];
191 for (var i in alignments) {
192 var alignment = alignments[i];
193 var shifts = getShiftKeys(alignment);
194 checkShiftInitialState(shifts['lower']);
195 checkShiftInitialState(shifts['upper']);
196 }
197 };
198 onKeyboardReady('testShiftKeyInitAsync', runTest, testDoneCallback);
199 }
200
201 /**
202 * Asynchronously tests capitalization on double click of the left and
203 * right shift keys.
204 * @param {function} testDoneCallBack The function to be called
205 * on completion.
206 */
207 function testShiftDoubleClickAsync(testDoneCallback) {
208 var runTest = function() {
209 var alignments = ['left', 'right'];
210 for (var i in alignments) {
211 var alignment = alignments[i];
212 var shifts = getShiftKeys(alignment);
213 checkShiftDoubleClick(shifts['lower'], shifts['upper']);
214 }
215 };
216 onKeyboardReady('testShiftDoubleClickAsync', runTest, testDoneCallback);
217 }
218
219 /**
220 * Asynchronously tests capitalization on long press of the left and
221 * right shift keys.
222 * @param {function} testDoneCallBack The callback function to be called
223 * on completion.
224 */
225 function testShiftLongPressAsync(testDoneCallback) {
226 var runTest = function() {
227 var alignments = ['left', 'right'];
228 for (var i in alignments) {
229 var alignment = alignments[i];
230 var shifts = getShiftKeys(alignment);
231 checkShiftLongPress(shifts['lower'], shifts['upper']);
232 }
233 };
234 onKeyboardReady('testShiftLongPressAsync', runTest, testDoneCallback);
235 }
236
237 /**
238 * Asynchronously tests chording on the keyboard.
239 * @param {function} testDoneCallBack The callback function to be called
240 * on completion.
241 */
242 function testShiftChordingAsync(testDoneCallback) {
243 var runTest = function() {
244 var left = getShiftKeys('left');
245 var right = getShiftKeys('right');
246 checkShiftChording(left['lower'], left['upper']);
247 checkShiftChording(right['lower'], right['upper']);
248 }
249 onKeyboardReady('testShiftChordingAsync', runTest, testDoneCallback);
250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698