OLD | NEW |
---|---|
(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 * 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 | |
10 * keyboard. | |
11 * @param {string=} opt_layout Optional name of the initial layout. | |
12 * @constructor | |
13 */ | |
14 function HideKeyboardKeyTester(layout) { | |
15 this.layout = layout; | |
16 this.subtasks = []; | |
17 } | |
18 | |
19 HideKeyboardKeyTester.prototype = { | |
20 __proto__: SubtaskScheduler.prototype, | |
21 | |
22 /** | |
23 * The keyboard overlay element. | |
24 * @type {kb-keyboard-overlay} | |
25 */ | |
26 get overlay() { | |
27 var overlay = | |
28 $('keyboard').webkitShadowRoot.querySelector('kb-keyboard-overlay'); | |
29 assertTrue(!!overlay, 'Unable to find overlay container'); | |
30 return overlay; | |
31 }, | |
32 | |
33 /** | |
34 * Mocks pressing on hide keyboard key. | |
35 * @param {string} keysetId Initial keyset. | |
36 */ | |
37 keyPress: function(keysetId) { | |
38 var self = this; | |
39 var fn = function() { | |
40 Debug('Mock keypress on hide keyboard key.'); | |
41 | |
42 // Verify that popup is initially hidden. | |
43 var popup = self.overlay; | |
44 assertTrue(!!popup && popup.hidden, | |
45 'Keyboard overlay should be hidden initially.'); | |
46 | |
47 var hideKey = | |
48 $('keyboard').activeKeyset.querySelector('kb-hide-keyboard-key'); | |
49 assertTrue(!!hideKey, 'Unable to find hide keyboard key.'); | |
50 hideKey.down({pointerId: 1}); | |
51 }; | |
52 this.addWaitCondition(fn, keysetId); | |
53 this.addSubtask(fn); | |
54 }, | |
55 | |
56 /** | |
57 * Mocks selection of lock/unlock button from the options menu. | |
58 * @param {boolean} expect Whether or not the keyboard should be locked. | |
59 */ | |
60 selectLockUnlockButton: function(expect) { | |
61 var self = this; | |
62 var fn = function() { | |
63 Debug('mock keyup on lock/unlock button.'); | |
64 | |
65 var optionsMenu = self.overlay.webkitShadowRoot.querySelector( | |
66 'kb-options-menu'); | |
67 assertTrue(!!optionsMenu, 'Unable to find options menu.'); | |
68 var lockUnlockButton = optionsMenu.webkitShadowRoot.querySelector( | |
69 'kb-options-menu-toggle-lock-item'); | |
70 assertTrue(!!lockUnlockButton, 'Unable to find lock/unlock button.'); | |
71 | |
72 // should hide keyboard | |
73 chrome.virtualKeyboardPrivate.lockKeyboard.addExpectation(expect); | |
74 lockUnlockButton.up(); | |
75 self.overlay.up(); | |
76 }; | |
77 fn.waitCondition = { | |
78 state: 'overlayVisibility', | |
79 value: true | |
80 }; | |
81 this.addSubtask(fn); | |
82 }, | |
83 | |
84 /** | |
85 * Waits for the overlay to close. | |
86 */ | |
87 verifyClosedOverlay: function() { | |
88 var fn = function() { | |
89 Debug('Validated that overlay has closed.'); | |
90 }; | |
91 fn.waitCondition = { | |
92 state: 'overlayVisibility', | |
93 value: false | |
94 }; | |
95 this.addSubtask(fn); | |
96 } | |
97 }; | |
98 | |
99 function testLockUnLockKeyboard(testDoneCallback) { | |
SteveT
2013/12/17 15:43:56
nit: testLockUnLockKeyboard -> testLockUnlockKeybo
bshe
2013/12/17 16:15:58
Done.
| |
100 var tester = new HideKeyboardKeyTester(Layout.DEFAULT); | |
101 | |
102 /** | |
103 * Mocks type on hide keyboard key and select lock/unlock button. | |
104 * @param {boolean} expect Whether or not the keyboard should be locked. | |
105 */ | |
106 var checkTypeLockUnLockKey = function(expect) { | |
SteveT
2013/12/17 15:43:56
nit: UnLock -> Unlock
bshe
2013/12/17 16:15:58
Done.
| |
107 tester.keyPress(Keyset.LOWER); | |
108 tester.wait(1000, Keyset.LOWER); | |
109 tester.selectLockUnlockButton(expect); | |
110 tester.verifyClosedOverlay(); | |
111 }; | |
112 | |
113 checkTypeLockUnLockKey(true); // Expect to lock keyboard. | |
114 checkTypeLockUnLockKey(false); // Expect to unlock keyboard. | |
115 | |
116 checkTypeLockUnLockKey(true); // Expect to lock keyboard. | |
117 var hideKey = | |
118 $('keyboard').activeKeyset.querySelector('kb-hide-keyboard-key'); | |
119 assertTrue(!!hideKey, 'Unable to find hide keyboard key.'); | |
120 chrome.virtualKeyboardPrivate.hideKeyboard.addExpectation(); | |
121 // Hide keyboard should unlock keyboard too. | |
122 chrome.virtualKeyboardPrivate.lockKeyboard.addExpectation(false); | |
123 hideKey.down({pointerId: 1}); | |
124 hideKey.up({pointerId: 1}); | |
125 | |
126 tester.scheduleTest('testLockUnlockKeyboard', testDoneCallback); | |
127 } | |
OLD | NEW |