Index: chrome/test/data/chromeos/virtual_keyboard/hide_keyboard_key_test.js |
diff --git a/chrome/test/data/chromeos/virtual_keyboard/hide_keyboard_key_test.js b/chrome/test/data/chromeos/virtual_keyboard/hide_keyboard_key_test.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9fa5b20961a8d55b7db7cfb34f6b7e63241b2ce5 |
--- /dev/null |
+++ b/chrome/test/data/chromeos/virtual_keyboard/hide_keyboard_key_test.js |
@@ -0,0 +1,127 @@ |
+/* |
+ * 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. |
+ */ |
+ |
+/** |
+ * Class for testing hide keyboard key. Other than hide keyboard as the name |
+ * suggested, hide keyboard key can also switch keyboard layout and lock/unlock |
+ * keyboard. |
+ * @param {string=} opt_layout Optional name of the initial layout. |
+ * @constructor |
+ */ |
+function HideKeyboardKeyTester(layout) { |
+ this.layout = layout; |
+ this.subtasks = []; |
+} |
+ |
+HideKeyboardKeyTester.prototype = { |
+ __proto__: SubtaskScheduler.prototype, |
+ |
+ /** |
+ * The keyboard overlay element. |
+ * @type {kb-keyboard-overlay} |
+ */ |
+ get overlay() { |
+ var overlay = |
+ $('keyboard').webkitShadowRoot.querySelector('kb-keyboard-overlay'); |
+ assertTrue(!!overlay, 'Unable to find overlay container'); |
+ return overlay; |
+ }, |
+ |
+ /** |
+ * Mocks pressing on hide keyboard key. |
+ * @param {string} keysetId Initial keyset. |
+ */ |
+ keyPress: function(keysetId) { |
+ var self = this; |
+ var fn = function() { |
+ Debug('Mock keypress on hide keyboard key.'); |
+ |
+ // Verify that popup is initially hidden. |
+ var popup = self.overlay; |
+ assertTrue(!!popup && popup.hidden, |
+ 'Keyboard overlay should be hidden initially.'); |
+ |
+ var hideKey = |
+ $('keyboard').activeKeyset.querySelector('kb-hide-keyboard-key'); |
+ assertTrue(!!hideKey, 'Unable to find hide keyboard key.'); |
+ hideKey.down({pointerId: 1}); |
+ }; |
+ this.addWaitCondition(fn, keysetId); |
+ this.addSubtask(fn); |
+ }, |
+ |
+ /** |
+ * Mocks selection of lock/unlock button from the options menu. |
+ * @param {boolean} expect Whether or not the keyboard should be locked. |
+ */ |
+ selectLockUnlockButton: function(expect) { |
+ var self = this; |
+ var fn = function() { |
+ Debug('mock keyup on lock/unlock button.'); |
+ |
+ var optionsMenu = self.overlay.webkitShadowRoot.querySelector( |
+ 'kb-options-menu'); |
+ assertTrue(!!optionsMenu, 'Unable to find options menu.'); |
+ var lockUnlockButton = optionsMenu.webkitShadowRoot.querySelector( |
+ 'kb-options-menu-toggle-lock-item'); |
+ assertTrue(!!lockUnlockButton, 'Unable to find lock/unlock button.'); |
+ |
+ // should hide keyboard |
+ chrome.virtualKeyboardPrivate.lockKeyboard.addExpectation(expect); |
+ lockUnlockButton.up(); |
+ self.overlay.up(); |
+ }; |
+ fn.waitCondition = { |
+ state: 'overlayVisibility', |
+ value: true |
+ }; |
+ this.addSubtask(fn); |
+ }, |
+ |
+ /** |
+ * Waits for the overlay to close. |
+ */ |
+ verifyClosedOverlay: function() { |
+ var fn = function() { |
+ Debug('Validated that overlay has closed.'); |
+ }; |
+ fn.waitCondition = { |
+ state: 'overlayVisibility', |
+ value: false |
+ }; |
+ this.addSubtask(fn); |
+ } |
+}; |
+ |
+function testLockUnLockKeyboard(testDoneCallback) { |
SteveT
2013/12/17 15:43:56
nit: testLockUnLockKeyboard -> testLockUnlockKeybo
bshe
2013/12/17 16:15:58
Done.
|
+ var tester = new HideKeyboardKeyTester(Layout.DEFAULT); |
+ |
+ /** |
+ * Mocks type on hide keyboard key and select lock/unlock button. |
+ * @param {boolean} expect Whether or not the keyboard should be locked. |
+ */ |
+ var checkTypeLockUnLockKey = function(expect) { |
SteveT
2013/12/17 15:43:56
nit: UnLock -> Unlock
bshe
2013/12/17 16:15:58
Done.
|
+ tester.keyPress(Keyset.LOWER); |
+ tester.wait(1000, Keyset.LOWER); |
+ tester.selectLockUnlockButton(expect); |
+ tester.verifyClosedOverlay(); |
+ }; |
+ |
+ checkTypeLockUnLockKey(true); // Expect to lock keyboard. |
+ checkTypeLockUnLockKey(false); // Expect to unlock keyboard. |
+ |
+ checkTypeLockUnLockKey(true); // Expect to lock keyboard. |
+ var hideKey = |
+ $('keyboard').activeKeyset.querySelector('kb-hide-keyboard-key'); |
+ assertTrue(!!hideKey, 'Unable to find hide keyboard key.'); |
+ chrome.virtualKeyboardPrivate.hideKeyboard.addExpectation(); |
+ // Hide keyboard should unlock keyboard too. |
+ chrome.virtualKeyboardPrivate.lockKeyboard.addExpectation(false); |
+ hideKey.down({pointerId: 1}); |
+ hideKey.up({pointerId: 1}); |
+ |
+ tester.scheduleTest('testLockUnlockKeyboard', testDoneCallback); |
+} |