Chromium Code Reviews| Index: chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js |
| diff --git a/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js b/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js |
| index 83952c2ad018fdb43dac1dec437ff3ee16f9334d..ff2f894b8fc8d6e893b8ad9f27aa940446411e6f 100644 |
| --- a/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js |
| +++ b/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js |
| @@ -9,17 +9,6 @@ var mockTimer; |
| var setComposition; |
| var DEFAULT_CONTEXT_ID = 1; |
| -var CAPSLOCK_ID = "OsLeft"; |
| - |
| -/** |
| - * Key alignments. |
| - * @enum {string} |
| - */ |
| -var Alignment = { |
| - LEFT: 'left', |
| - RIGHT: 'right', |
| - CENTER: 'center' |
| -}; |
| /** |
| * Create mocks for the virtualKeyboardPrivate API. Any tests that trigger API |
| @@ -62,16 +51,88 @@ function tearDown() { |
| } |
| /** |
| - * Retrieves the key from the current keyset. |
| - * @param {String} char The character of the key. |
| - * @return {Object} The key. |
| - */ |
| -function getKey(char) { |
| - var key = document.querySelector('#Key' + char.toUpperCase()); |
| - assertTrue(!!key, "Cannot find key: " + char); |
| - return key; |
| +* Checks whether the element is currently being displayed on screen. |
| +* @param {Object} The object to check. |
| +* @return {boolean} |
| +*/ |
| +function isActive(el) { |
| + return window.getComputedStyle(el).display != "none"; |
| } |
| +(function(exports) { |
| + |
| + var KEY_IDS = { |
|
bshe
2014/05/12 13:24:27
Could you document why only these characters have
rsadam
2014/05/12 20:23:46
Done.
|
| + 'a' : { |
| + 'us' : '101kbd-k-29', |
| + 'us.compact' : 'compactkbd-k-key-10', |
| + }, |
| + 'c' : { |
| + 'us' : '101kbd-k-44', |
| + 'us.compact' : 'compactkbd-k-key-21', |
| + |
| + }, |
| + 'd' : { |
| + 'us' : '101kbd-k-31', |
| + 'us.compact' : 'compactkbd-k-key-12', |
| + |
| + }, |
| + 'l' : { |
| + 'us' : '101kbd-k-37', |
| + 'us.compact' : 'compactkbd-k-key-18', |
| + |
| + }, |
| + 'p' : { |
| + 'us' : '101kbd-k-24', |
| + 'us.compact' : 'compactkbd-k-key-9', |
| + }, |
| + 'leftshift' : { |
| + 'us' : '101kbd-k-41', |
| + 'us.compact' : 'compactkbd-k-21', |
| + }, |
| + "capslock" : { |
| + 'us' : '101kbd-k-28', |
| + } |
| + }; |
| + |
| + /** |
| + * Gets the key id of the specified character. |
| + * @param {string} layout The current keyboard layout. |
| + * @param {char} char The character to press. |
| + */ |
| + var getKeyId_ = function(layout, char) { |
| + var lower = char.toLowerCase(); |
| + assertTrue(!!KEY_IDS[lower], "Cannot find cached key id: " + char); |
| + assertTrue(!!KEY_IDS[lower][layout], |
| + "Cannot find cached key id: " + char + " in " + layout); |
| + return KEY_IDS[lower][layout]; |
| + } |
| + |
| + /** |
| + * Returns the current layout id. |
| + * @return {string} |
| + */ |
| + var getLayoutId_ = function() { |
| + // TODO(rsadam@): Generalize this. |
| + var id = window.location.search.split("id=")[1]; |
| + assertTrue(!!id, "No layout found."); |
| + return id; |
| + } |
| + |
| + /** |
| + * Returns the key object corresponding to the character. |
| + * @return {string} char The character. |
| + */ |
| + var getKey_ = function(char) { |
| + var layoutId = getLayoutId(); |
| + var key = document.getElementById(getKeyId_(layoutId, char)); |
| + assertTrue(!!key, "Key not present in layout: " + char); |
| + return key; |
| + } |
| + |
| + exports.getKey = getKey_; |
| + exports.getLayoutId = getLayoutId_; |
| +})(this); |
| + |
| /** |
| * Generates a mouse event and dispatches it on the target. |
| * @param target {Object} The target of the event. |
| @@ -123,7 +184,7 @@ function generateTouchEvent(target, type) { |
| /** |
| * Mocks a character type using touch. |
| - * @param {String} char The character to type. |
| + * @param {String} char The expected character. |
| */ |
| function mockTouchType(char) { |
| var send = chrome.input.ime.commitText; |
| @@ -135,26 +196,3 @@ function mockTouchType(char) { |
| generateTouchEvent(key, 'touchstart'); |
| generateTouchEvent(key, 'touchend'); |
| } |
| - |
| -/** |
| - * Retrieves the shift key from the current keyset. |
| - * @param {Alignment} align The alignment of the shift key. |
| - * @return {Object} The key. |
| - */ |
| -function getShiftKey(align) { |
| - var id; |
| - switch(align) { |
| - case Alignment.LEFT: |
| - id = 'ShiftLeft'; |
| - break; |
| - case Alignment.RIGHT: |
| - id = 'ShiftRight'; |
| - break; |
| - default: |
| - break; |
| - } |
| - assertTrue(!!id, "Invalid shift alignment option: " + align); |
| - var shift = document.querySelector('#' + id); |
| - assertTrue(!!shift, "Cannot find shift key with alignment: " + align); |
| - return shift; |
| -} |