Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: chrome/browser/resources/chromeos/braille_ime/braille_ime_unittest.gtestjs

Issue 271723002: Make Braille IME send space bar as an empty cell instead of letting propagate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ime
Patch Set: Simplify a check. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Unit test for the Braille IME. 6 * @fileoverview Unit test for the Braille IME.
7 */ 7 */
8 8
9 /** 9 /**
10 * Mock Chrome event supporting one listener. 10 * Mock Chrome event supporting one listener.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 this.ime.init(); 115 this.ime.init();
116 }, 116 },
117 117
118 activateIme: function() { 118 activateIme: function() {
119 this.onActivate.dispatch(ENGINE_ID); 119 this.onActivate.dispatch(ENGINE_ID);
120 assertThat(this.port.messages, 120 assertThat(this.port.messages,
121 eqJSON([{type: 'activeState', active: true}])); 121 eqJSON([{type: 'activeState', active: true}]));
122 this.port.messages.length = 0; 122 this.port.messages.length = 0;
123 }, 123 },
124 124
125 sendKeyDown: function(code) { 125 sendKeyDown: function(code, extra) {
126 return this.onKeyEvent.dispatch(ENGINE_ID, {code: code, type: 'keydown'}); 126 var event = {code: code, type: 'keydown'};
127 for (var key in extra) {
128 event[key] = extra[key];
129 }
130 return this.onKeyEvent.dispatch(ENGINE_ID, event);
127 }, 131 },
128 132
129 sendKeyUp: function(code) { 133 sendKeyUp: function(code, extra) {
130 return this.onKeyEvent.dispatch(ENGINE_ID, {code: code, type: 'keyup'}); 134 var event = {code: code, type: 'keyup'};
135 for (var key in extra) {
136 event[key] = extra[key];
137 }
138 return this.onKeyEvent.dispatch(ENGINE_ID, event);
131 }, 139 },
132 }; 140 };
133 141
134 TEST_F('BrailleImeUnitTest', 'KeysWhenStandardKeyboardDisabled', function() { 142 TEST_F('BrailleImeUnitTest', 'KeysWhenStandardKeyboardDisabled', function() {
135 this.activateIme(); 143 this.activateIme();
136 expectFalse(this.sendKeyDown('KeyF')); 144 expectFalse(this.sendKeyDown('KeyF'));
137 expectFalse(this.sendKeyDown('KeyD')); 145 expectFalse(this.sendKeyDown('KeyD'));
138 expectFalse(this.sendKeyUp('KeyD')); 146 expectFalse(this.sendKeyUp('KeyD'));
139 expectFalse(this.sendKeyUp('KeyF')); 147 expectFalse(this.sendKeyUp('KeyF'));
140 expectEquals(0, this.port.messages.length); 148 expectEquals(0, this.port.messages.length);
141 }); 149 });
142 150
143 TEST_F('BrailleImeUnitTest', 'KeysWhenStandardKeysEnabled', function() { 151 TEST_F('BrailleImeUnitTest', 'KeysWhenStandardKeysEnabled', function() {
144 this.activateIme(); 152 this.activateIme();
145 assertFalse(this.menuItems[0].checked); 153 assertFalse(this.menuItems[0].checked);
146 this.onMenuItemActivated.dispatch(ENGINE_ID, this.menuItems[0].id); 154 this.onMenuItemActivated.dispatch(ENGINE_ID, this.menuItems[0].id);
147 assertTrue(this.menuItems[0].checked); 155 assertTrue(this.menuItems[0].checked);
148 // Type the letters 'b' and 'c' and verify the right dots get sent. 156 // Type the letters 'b' and 'c' and verify the right dots get sent.
149 expectTrue(this.sendKeyDown('KeyF')); 157 expectTrue(this.sendKeyDown('KeyF'));
150 expectTrue(this.sendKeyDown('KeyD')); 158 expectTrue(this.sendKeyDown('KeyD'));
151 expectTrue(this.sendKeyUp('KeyD')); 159 expectTrue(this.sendKeyUp('KeyD'));
152 expectTrue(this.sendKeyUp('KeyF')); 160 expectTrue(this.sendKeyUp('KeyF'));
153 expectTrue(this.sendKeyDown('KeyJ')); 161 expectTrue(this.sendKeyDown('KeyJ'));
154 expectTrue(this.sendKeyDown('KeyF')); 162 expectTrue(this.sendKeyDown('KeyF'));
155 expectTrue(this.sendKeyUp('KeyJ')); 163 expectTrue(this.sendKeyUp('KeyJ'));
156 expectTrue(this.sendKeyUp('KeyF')); 164 expectTrue(this.sendKeyUp('KeyF'));
165
157 // Make sure that other keys are not handled, either by themselves or while 166 // Make sure that other keys are not handled, either by themselves or while
158 // one of the 'braille keys' is pressed. 167 // one of the 'braille keys' is pressed.
159 expectFalse(this.sendKeyDown('KeyX')); 168 expectFalse(this.sendKeyDown('KeyX'));
160 expectFalse(this.sendKeyUp('KeyX')); 169 expectFalse(this.sendKeyUp('KeyX'));
161 170
162 expectTrue(this.sendKeyDown('KeyS')); // Dot 3 171 expectTrue(this.sendKeyDown('KeyS')); // Dot 3
163 expectFalse(this.sendKeyDown('KeyG')); // To the right of dot 1. 172 expectFalse(this.sendKeyDown('KeyG')); // To the right of dot 1.
164 expectTrue(this.sendKeyUp('KeyS')); 173 expectTrue(this.sendKeyUp('KeyS'));
165 expectFalse(this.sendKeyUp('KeyG')); 174 expectFalse(this.sendKeyUp('KeyG'));
166 175
176 // Keys like Ctrl L should not be handled, despite L being a dot key.
177 var ctrlFlag = {ctrlKey: true};
178 expectFalse(this.sendKeyDown('ControlLeft', ctrlFlag));
179 expectFalse(this.sendKeyDown('KeyL', ctrlFlag));
180 expectFalse(this.sendKeyUp('KeyL', ctrlFlag));
181 expectFalse(this.sendKeyUp('ControlLeft', ctrlFlag))
182
183 // Space key by itself should send a blank cell.
184 expectTrue(this.sendKeyDown('Space'));
185 expectTrue(this.sendKeyUp('Space'));
186
187 // Space and braille dots results in no event.
188 expectTrue(this.sendKeyDown('Space'));
189 expectTrue(this.sendKeyDown('KeyF'));
190 expectTrue(this.sendKeyUp('Space'));
191 expectTrue(this.sendKeyUp('KeyF'));
192 // Send the braille key first, still no event should be produced.
193 expectTrue(this.sendKeyDown('KeyF'));
194 expectTrue(this.sendKeyDown('Space'));
195 expectTrue(this.sendKeyUp('Space'));
196 expectTrue(this.sendKeyUp('KeyF'));
197
167 assertThat(this.port.messages, 198 assertThat(this.port.messages,
168 eqJSON([{type: 'brailleDots', dots: 0x03}, 199 eqJSON([{type: 'brailleDots', dots: 0x03},
169 {type: 'brailleDots', dots: 0x09}])); 200 {type: 'brailleDots', dots: 0x09},
201 {type: 'brailleDots', dots: 0}]));
170 }); 202 });
171 203
172 TEST_F('BrailleImeUnitTest', 'UseStandardKeyboardSettingPreserved', function() { 204 TEST_F('BrailleImeUnitTest', 'UseStandardKeyboardSettingPreserved', function() {
173 this.activateIme(); 205 this.activateIme();
174 assertFalse(this.menuItems[0].checked); 206 assertFalse(this.menuItems[0].checked);
175 this.onMenuItemActivated.dispatch(ENGINE_ID, this.menuItems[0].id); 207 this.onMenuItemActivated.dispatch(ENGINE_ID, this.menuItems[0].id);
176 assertTrue(this.menuItems[0].checked); 208 assertTrue(this.menuItems[0].checked);
177 // Create a new instance and make sure the setting is still turned on. 209 // Create a new instance and make sure the setting is still turned on.
178 console.log('localStorage: ' + JSON.stringify(localStorage));
179 this.createIme(); 210 this.createIme();
180 this.activateIme(); 211 this.activateIme();
181 assertTrue(this.menuItems[0].checked); 212 assertTrue(this.menuItems[0].checked);
182 }); 213 });
183 214
184 TEST_F('BrailleImeUnitTest', 'ReplaceText', function() { 215 TEST_F('BrailleImeUnitTest', 'ReplaceText', function() {
185 var CONTEXT_ID = 1; 216 var CONTEXT_ID = 1;
186 var hasSelection = false; 217 var hasSelection = false;
187 var text = 'Hi, '; 218 var text = 'Hi, ';
188 chrome.input.ime.commitText = function(params) { 219 chrome.input.ime.commitText = function(params) {
(...skipping 18 matching lines...) Expand all
207 deleteBefore: deleteBefore, newText: newText}); 238 deleteBefore: deleteBefore, newText: newText});
208 }.bind(this); 239 }.bind(this);
209 this.activateIme(); 240 this.activateIme();
210 sendReplaceText(0, 'hello!'); 241 sendReplaceText(0, 'hello!');
211 assertEquals('Hi, hello!', text); 242 assertEquals('Hi, hello!', text);
212 hasSelection = true; 243 hasSelection = true;
213 sendReplaceText('hello!'.length, 'good bye!'); 244 sendReplaceText('hello!'.length, 'good bye!');
214 assertFalse(hasSelection); 245 assertFalse(hasSelection);
215 assertEquals('Hi, good bye!', text); 246 assertEquals('Hi, good bye!', text);
216 }); 247 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698