2 * Copyright 2014 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.
8 * Class for testing hide keyboard key. Other than hide keyboard as the name
9 * suggested, hide keyboard key can also switch keyboard layout and lock/unlock
11 * @param {string=} opt_layout Optional name of the initial layout.
14 function HideKeyboardKeyTester(layout) {
19 HideKeyboardKeyTester.prototype = {
20 __proto__: SubtaskScheduler.prototype,
23 * The keyboard overlay element.
24 * @type {kb-keyboard-overlay}
28 $('keyboard').shadowRoot.querySelector('kb-keyboard-overlay');
29 assertTrue(!!overlay, 'Unable to find overlay container');
34 * Mocks tap/click on hide keyboard key. It should pop up the overlay menu.
35 * @param {string} keysetId Initial keyset.
37 tapHideKeyboard: function(keysetId) {
39 var mockEvent = {pointerId: 1};
40 mockEvent.stopPropagation = function() {};
42 Debug('Mock tap on hide keyboard key.');
45 $('keyboard').activeKeyset.querySelector('kb-hide-keyboard-key');
46 assertTrue(!!hideKey, 'Unable to find hide keyboard key.');
48 hideKey.down(mockEvent);
49 hideKey.up(mockEvent);
51 this.addWaitCondition(fn, keysetId);
53 this.verifyOverlayVisibilityChange(true);
57 * Mocks tap/click on the overlay menu. It should hide the overlay menu.
58 * @param {string} keysetId Initial keyset.
60 tapOverlay: function(keysetId) {
61 var mockEvent = {pointerId: 1};
62 mockEvent.stopPropagation = function() {};
65 Debug('Mock tap on overlay.');
66 var overlay = self.overlay;
67 overlay.up(mockEvent);
69 this.addWaitCondition(fn, keysetId);
71 this.verifyOverlayVisibilityChange(false);
75 * Mocks selection of lock/unlock button from the options menu.
76 * @param {string} keysetId Initial keyset.
77 * @param {boolean} expect Whether or not the keyboard should be locked.
79 selectLockUnlockButton: function(keysetId, expect) {
80 var mockEvent = {pointerId: 1};
81 mockEvent.stopPropagation = function() {};
84 Debug('mock keyup on lock/unlock button.');
86 var optionsMenu = self.overlay.shadowRoot.querySelector(
88 assertTrue(!!optionsMenu, 'Unable to find options menu.');
89 var lockUnlockButton = optionsMenu.shadowRoot.querySelector(
90 'kb-options-menu-toggle-lock-item');
91 assertTrue(!!lockUnlockButton, 'Unable to find lock/unlock button.');
92 // Should toggle lock.
93 chrome.virtualKeyboardPrivate.lockKeyboard.addExpectation(expect);
94 lockUnlockButton.up(mockEvent);
95 self.overlay.up(mockEvent);
97 this.addWaitCondition(fn, keysetId);
99 this.verifyOverlayVisibilityChange(false);
103 * Mocks selection of hide from the options menu.
104 * @param {string} keysetId Initial keyset.
106 selectHide: function(keysetId) {
107 var mockEvent = {pointerId: 1};
108 mockEvent.stopPropagation = function() {};
110 var fn = function() {
111 Debug('mock keyup on hide button.');
112 var optionsMenu = self.overlay.shadowRoot.querySelector(
114 assertTrue(!!optionsMenu, 'Unable to find options menu.');
115 var button = optionsMenu.shadowRoot.querySelector(
116 'kb-options-menu-item[layout=none]');
117 assertTrue(!!button, 'Unable to find hide button.');
118 // Expect hideKeyboard to be called.
119 chrome.virtualKeyboardPrivate.hideKeyboard.addExpectation();
120 // hideKeyboard in api_adapter also unlocks the keyboard.
121 chrome.virtualKeyboardPrivate.lockKeyboard.addExpectation(false);
122 button.up(mockEvent);
123 self.overlay.up(mockEvent);
125 this.addWaitCondition(fn, keysetId);
127 this.verifyOverlayVisibilityChange(false);
131 * Waits for the overlay to change visibility.
132 * @param {string} keysetId Initial keyset.
134 verifyOverlayVisibilityChange: function(visibility) {
135 var fn = function() {
137 Debug('Validated that overlay is now visible.');
139 Debug('Validated that overlay is now hidden.');
142 state: 'overlayVisibility',
150 * Tests that the overlay menu appears when the hide keyboard button is clicked
151 * and disappears when the overlay is then clicked.
152 * @param {Function} testDoneCallback The callback function on completion.
154 function testOverlayMenu(testDoneCallback) {
155 var tester = new HideKeyboardKeyTester(Layout.DEFAULT);
156 tester.tapHideKeyboard(Keyset.LOWER);
157 tester.tapOverlay(Keyset.LOWER);
158 tester.scheduleTest('testOverlayMenu', testDoneCallback);
162 * Tests that clicking hide in the overlay menu hides the keyboard.
163 * @param {Function} testDoneCallback The callback function on completion.
165 function testHideKeyboard(testDoneCallback) {
166 var tester = new HideKeyboardKeyTester(Layout.DEFAULT);
167 tester.tapHideKeyboard(Keyset.LOWER);
168 tester.selectHide(Keyset.LOWER);
169 tester.scheduleTest('testHideKeyboard', testDoneCallback);
173 * Tests that the lock keyboard in the overlay menu toggles.
174 * @param {Function} testDoneCallback The callback function on completion.
176 function testLockKeyboard(testDoneCallback) {
177 var tester = new HideKeyboardKeyTester(Layout.DEFAULT);
178 tester.tapHideKeyboard(Keyset.LOWER);
179 tester.selectLockUnlockButton(Keyset.LOWER, true);
181 tester.tapHideKeyboard(Keyset.LOWER);
182 tester.selectLockUnlockButton(Keyset.LOWER, false);
184 tester.scheduleTest('testLockKeyboard', testDoneCallback);