Index: chrome/test/data/chromeos/virtual_keyboard/control_keys_test.js |
diff --git a/chrome/test/data/chromeos/virtual_keyboard/control_keys_test.js b/chrome/test/data/chromeos/virtual_keyboard/control_keys_test.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8cf31da40aa890c2781c56b0d81a04590a609afa |
--- /dev/null |
+++ b/chrome/test/data/chromeos/virtual_keyboard/control_keys_test.js |
@@ -0,0 +1,262 @@ |
+/* |
+ * Copyright 2013 The Chromium Authors. All rights reserved. |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+/** |
+ * 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.
|
+ * @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.
|
+ * @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.
|
+ */ |
+function getShiftKeys(alignment) { |
+ var layout = keyboard.layout; |
+ var keysets = ['lower', 'upper']; |
+ |
+ var result={}; |
+ for(var keysetIndex in keysets) { |
+ var keysetId = keysets[keysetIndex]; |
+ // The keyset DOM object which contains a shift key. |
+ var keyset = keyboard.querySelector('#' + layout + "-" + keysetId); |
+ assertTrue(!!keyset, "Cannot find keyset: " + keyset); |
+ var shiftKey = keyset.querySelector('kb-shift-key[align="' + |
+ alignment + '"]'); |
+ assertTrue(!!shiftKey, "Keyset " + keysetId + |
+ " does not have a shift key with " + alignment + " alignment"); |
+ result[keysetId] = shiftKey; |
+ } |
+ return result; |
+} |
+ |
+/** |
+ * Tests chording with a single shift key. |
+ * @param {Object} lowerShift, a shift key in the lower key set. |
+ * @param {Object} uppserShift, the same shift key in the upper key set. |
+ */ |
+function checkShiftChording(lowerShift, upperShift) { |
+ var lower = lowerShift.lowerCaseKeysetId; |
+ var upper = lowerShift.upperCaseKeysetId; |
+ // Check that we're testing from correct initial state. |
+ 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.
|
+ lower + ". Was: " + keyboard.keyset); |
+ var mockEvent = {pointerId:1, isPrimary:true}; |
+ lowerShift.down(mockEvent); |
+ assertTrue(keyboard.keyset == upper, |
+ "Did not transition to uppercase on shift key down. Expected: " + |
+ upper + ". Was: " + keyboard.keyset); |
+ // Some alphanumeric character |
+ mockTypeCharacter('A', 0x41, true); |
+ assertTrue(keyboard.keyset == upper, |
+ "Did not remain in uppercase. Expected: " + |
+ upper + ". Was: " + keyboard.keyset); |
+ mockTimer.tick(1000); |
+ upperShift.up(mockEvent); |
+ assertTrue(keyboard.keyset == lower, |
+ "Did not revert to lowercase after chording. Expected: " + |
+ lower + ". Was: " + keyboard.keyset); |
+} |
+ |
+/** |
+ * Tests a particular shift key for highlighting on tapping. The keyboard |
+ * should temporarily transition to uppercase, and after a non-control tap, |
+ * revert to lower case. |
+ * @param {Object} lowerShift The shift key object on the lower keyset. |
+ * @param {Object} upperShift The shift key object on the upper keyset. |
+ */ |
+function checkShiftHighlight(lowerShift, upperShift) { |
+ assertTrue(!!keyboard.shift, "Shift key was not cached by keyboard"); |
+ var unlocked = lowerShift.lowerCaseKeysetId; |
+ var locked = lowerShift.upperCaseKeysetId; |
+ assertTrue(keyboard.keyset == unlocked, |
+ "Initial keyboard keyset is not unlocked. Keyset: " + |
kevers
2013/09/30 21:58:28
assertEquals
rsadam
2013/09/30 22:52:09
Done.
|
+ keyboard.keyset + " Expected: " + unlocked); |
+ // Crashes if we don't give it a pointerId. |
+ var mockEvent = { pointerId: 1}; |
+ // Tap shift key. |
+ lowerShift.down(mockEvent); |
+ upperShift.up(mockEvent); |
+ // Tests that we are now in locked case. |
+ assertTrue(keyboard.keyset == locked, |
+ "Keyset is not locked on highlight. Keyset: " + keyboard.keyset + |
+ " Expected: " + locked); |
+ // Some alphanumeric character. |
+ mockTypeCharacter('A', 0x41, true); |
+ // Check that we've reverted to lower case. |
+ assertTrue(keyboard.keyset == unlocked, |
+ "Did not revert to lower case after highlight. Keyset: " + |
+ keyboard.keyset + " Expected: " + unlocked); |
+ // Check that we persist in lower case. |
+ mockTypeCharacter('a', 0x41, false); |
+ assertTrue(keyboard.keyset == unlocked, |
+ "Did not stay in lower case after highlight. Keyset: " + |
+ keyboard.keyset + " Expected: " + unlocked); |
+} |
+ |
+/** |
+ * Tests that a particular shift key has been initialized correctly. |
+ * @param {Object} shift The shift key. |
+ */ |
+function checkShiftInitialState(shift) { |
+ //Checks that the unlocked case is lower. |
+ var expectedUnlocked = 'lower'; |
+ assertTrue(shift.lowerCaseKeysetId == expectedUnlocked, |
kevers
2013/09/30 21:58:28
assertEquals
rsadam
2013/09/30 22:52:09
Done.
|
+ "Expected unlocked case to be: " + expectedUnlocked + " was: " + |
+ shift.lowerCaseKeysetId); |
+ //Checks that the locked case is upper. |
+ var expectedLocked = 'upper'; |
+ assertTrue(shift.upperCaseKeysetId == expectedLocked, |
+ "Expected locked case to be: " + expectedLocked + " was: " + |
+ shift.upperCaseKeysetId); |
+} |
+ |
+/** |
+ * Tests that a particular shift key capitalizes on long press. |
+ * @param {Object} shift The shift key. |
+ */ |
+function checkShiftLongPress(lowerShift, upperShift) { |
+ // Check that keyboard is in expected start state. |
+ assertTrue(!!keyboard.shift, "Shift key was not cached by keyboard"); |
+ var unlocked = lowerShift.lowerCaseKeysetId; |
+ var locked = lowerShift.upperCaseKeysetId; |
+ assertTrue(keyboard.keyset == unlocked, |
kevers
2013/09/30 21:58:28
assertEquals
rsadam
2013/09/30 22:52:09
Done.
|
+ "Initial keyboard keyset is not unlocked. Keyset: " + |
+ keyboard.keyset + " Expected: " + unlocked); |
+ // Mocks a pointer event. |
+ var mockEvent = { pointerId: 1}; |
+ lowerShift.down(mockEvent); |
+ assertTrue(keyboard.keyset == locked, |
+ "Did not transition to locked case on shift key down. Keyset: " + |
+ keyboard.keyset + " Expected: " + locked); |
+ // Long press should now be active. |
+ mockTimer.tick(1000); |
+ // Type any caps character, make sure we remain in caps mode. |
+ upperShift.up(mockEvent); |
+ mockTypeCharacter('A', 0x41, true); |
+ assertTrue(keyboard.keyset == locked, |
+ "Did not remain in locked case after long press. Keyset: " + |
+ keyboard.keyset + " Expected: " + locked); |
+ //Revert to lower case. |
+ upperShift.down(mockEvent); |
+ assertTrue(keyboard.keyset == unlocked, |
+ "Did not revert to lower case on shift down. Keyset: " + |
+ keyboard.keyset + " Expected: " + unlocked); |
+ lowerShift.up(mockEvent); |
+} |
+ |
+function checkShiftDoubleClick(lowerShift, upperShift) { |
+ // Check that keyboard is in expected start state. |
+ assertTrue(!!keyboard.shift, "Shift key was not cached by keyboard"); |
+ var unlocked = lowerShift.lowerCaseKeysetId; |
+ var locked = lowerShift.upperCaseKeysetId; |
+ assertTrue(keyboard.keyset == unlocked, |
kevers
2013/09/30 21:58:28
assertEquals
rsadam
2013/09/30 22:52:09
Done.
|
+ "Initial keyboard keyset is not unlocked. Keyset: " + |
+ keyboard.keyset + " Expected: " + unlocked); |
+ // Mocks a pointer event. |
+ var mockEvent = { pointerId: 1}; |
+ lowerShift.down(mockEvent); |
+ upperShift.up(mockEvent); |
+ // Need to also mock a keyboard pointer up event. |
+ keyboard.up(mockEvent); |
+ upperShift.down(mockEvent); |
+ upperShift.up(mockEvent); |
+ keyboard.up(mockEvent); |
+ // Check that we're capslocked. |
+ assertTrue(keyboard.keyset == locked, |
+ "Did not lock on double click. Keyset: " + |
+ keyboard.keyset + " Expected: " + locked); |
+ mockTypeCharacter('A', 0x41, true); |
+ assertTrue(keyboard.keyset == locked, |
+ "Did not remain in locked case after typing another key. Keyset: " + |
+ keyboard.keyset + " Expected: " + locked); |
+ // Reverts to lower case. |
+ upperShift.down(mockEvent); |
+ assertTrue(keyboard.keyset == unlocked, |
+ "Did not revert to lower case on shift down. Keyset: " + |
+ keyboard.keyset + " Expected: " + unlocked); |
+ lowerShift.up(mockEvent); |
+} |
+/** |
+ * Asynchronously tests highlighting of the left and right shift keys. |
+ * @param {function} testDoneCallBack The callback function to be called |
+ * on completion. |
+ */ |
+function testShiftHighlightAsync(testDoneCallback) { |
+ var runTest = function() { |
+ var alignments = ['left', 'right']; |
+ for (var i in alignments) { |
+ var alignment = alignments[i]; |
+ var shifts = getShiftKeys(alignment); |
+ checkShiftHighlight(shifts['lower'], shifts['upper']); |
+ } |
+ }; |
+ onKeyboardReady('testShiftKeyHighlightAsync', runTest, testDoneCallback); |
+} |
+ |
+/** |
+ * Asynchronously tests initialization of the left and right shift keys. |
+ * @param {function} testDoneCallBack The callback function to be called |
+ * on completion. |
+ */ |
+function testShiftKeyInitAsync(testDoneCallback) { |
+ var runTest = function() { |
+ var alignments = ['left', 'right']; |
+ for (var i in alignments) { |
+ var alignment = alignments[i]; |
+ var shifts = getShiftKeys(alignment); |
+ checkShiftInitialState(shifts['lower']); |
+ checkShiftInitialState(shifts['upper']); |
+ } |
+ }; |
+ onKeyboardReady('testShiftKeyInitAsync', runTest, testDoneCallback); |
+} |
+ |
+/** |
+ * Asynchronously tests capitalization on double click of the left and |
+ * right shift keys. |
+ * @param {function} testDoneCallBack The callback function to be called |
+ * on completion. |
+ */ |
+function testShiftDoubleClickAsync(testDoneCallback) { |
+ var runTest = function() { |
+ var alignments = ['left', 'right']; |
+ for (var i in alignments) { |
+ var alignment = alignments[i]; |
+ var shifts = getShiftKeys(alignment); |
+ checkShiftDoubleClick(shifts['lower'], shifts['upper']); |
+ } |
+ }; |
+ onKeyboardReady('testShiftDoubleClickAsync', runTest, testDoneCallback); |
+} |
+ |
+/** |
+ * Asynchronously tests capitalization on long press of the left and |
+ * right shift keys. |
+ * @param {function} testDoneCallBack The callback function to be called |
+ * on completion. |
+ */ |
+function testShiftLongPressAsync(testDoneCallback) { |
+ var runTest = function() { |
+ var alignments = ['left', 'right']; |
+ for (var i in alignments) { |
+ var alignment = alignments[i]; |
+ var shifts = getShiftKeys(alignment); |
+ checkShiftLongPress(shifts['lower'], shifts['upper']); |
+ } |
+ }; |
+ onKeyboardReady('testShiftLongPressAsync', runTest, testDoneCallback); |
+} |
+ |
+/** |
+ * Asynchronously tests chording on the keyboard. |
+ * @param {function} testDoneCallBack The callback function to be called |
+ * on completion. |
+ */ |
+function testShiftChordingAsync(testDoneCallback) { |
+ var runTest = function() { |
+ var left = getShiftKeys('left'); |
+ var right = getShiftKeys('right'); |
+ checkShiftChording(left['lower'], left['upper']); |
+ checkShiftChording(right['lower'], right['upper']); |
+ } |
+ onKeyboardReady('testShiftChordingAsync', runTest, testDoneCallback); |
+} |