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

Side by Side Diff: chrome/browser/extensions/api/braille_display_private/braille_display_private_apitest.cc

Issue 297833015: Support standard keyboard keys emulated by the braille drivers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Fix typos and clarify some docs. Created 6 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef USE_BRLAPI 5 #ifndef USE_BRLAPI
6 #error This test requires brlapi. 6 #error This test requires brlapi.
7 #endif 7 #endif
8 8
9 #include <deque> 9 #include <deque>
10 10
(...skipping 24 matching lines...) Expand all
35 using content::BrowserThread; 35 using content::BrowserThread;
36 36
37 namespace extensions { 37 namespace extensions {
38 namespace api { 38 namespace api {
39 namespace braille_display_private { 39 namespace braille_display_private {
40 40
41 namespace { 41 namespace {
42 42
43 const char kTestUserName[] = "owner@invalid.domain"; 43 const char kTestUserName[] = "owner@invalid.domain";
44 44
45 // Used to make ReadKeys return an error.
46 brlapi_keyCode_t kErrorKeyCode = BRLAPI_KEY_MAX;
47
45 } // namespace 48 } // namespace
46 49
47 // Data maintained by the mock BrlapiConnection. This data lives throughout 50 // Data maintained by the mock BrlapiConnection. This data lives throughout
48 // a test, while the api implementation takes ownership of the connection 51 // a test, while the api implementation takes ownership of the connection
49 // itself. 52 // itself.
50 struct MockBrlapiConnectionData { 53 struct MockBrlapiConnectionData {
51 bool connected; 54 bool connected;
52 size_t display_size; 55 size_t display_size;
53 brlapi_error_t error; 56 brlapi_error_t error;
54 std::vector<std::string> written_content; 57 std::vector<std::string> written_content;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 110
108 virtual bool WriteDots(const unsigned char* cells) OVERRIDE { 111 virtual bool WriteDots(const unsigned char* cells) OVERRIDE {
109 std::string written(reinterpret_cast<const char*>(cells), 112 std::string written(reinterpret_cast<const char*>(cells),
110 data_->display_size); 113 data_->display_size);
111 data_->written_content.push_back(written); 114 data_->written_content.push_back(written);
112 return true; 115 return true;
113 } 116 }
114 117
115 virtual int ReadKey(brlapi_keyCode_t* key_code) OVERRIDE { 118 virtual int ReadKey(brlapi_keyCode_t* key_code) OVERRIDE {
116 if (!data_->pending_keys.empty()) { 119 if (!data_->pending_keys.empty()) {
117 int queued_key_code = data_->pending_keys.front(); 120 brlapi_keyCode_t queued_key_code = data_->pending_keys.front();
118 data_->pending_keys.pop_front(); 121 data_->pending_keys.pop_front();
119 if (queued_key_code < 0) { 122 if (queued_key_code == kErrorKeyCode) {
120 data_->error.brlerrno = BRLAPI_ERROR_EOF; 123 data_->error.brlerrno = BRLAPI_ERROR_EOF;
121 return -1; // Signal error. 124 return -1; // Signal error.
122 } 125 }
123 *key_code = queued_key_code; 126 *key_code = queued_key_code;
124 return 1; 127 return 1;
125 } else { 128 } else {
126 return 0; 129 return 0;
127 } 130 }
128 } 131 }
129 132
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 ASSERT_EQ(std::string( 190 ASSERT_EQ(std::string(
188 connection_data_.display_size, 191 connection_data_.display_size,
189 static_cast<char>(i)), 192 static_cast<char>(i)),
190 connection_data_.written_content[i]) 193 connection_data_.written_content[i])
191 << "String " << i << " doesn't match"; 194 << "String " << i << " doesn't match";
192 } 195 }
193 } 196 }
194 197
195 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, KeyEvents) { 198 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, KeyEvents) {
196 connection_data_.display_size = 11; 199 connection_data_.display_size = 11;
200
201 // Braille navigation commands.
197 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | 202 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD |
198 BRLAPI_KEY_CMD_LNUP); 203 BRLAPI_KEY_CMD_LNUP);
199 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | 204 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD |
200 BRLAPI_KEY_CMD_LNDN); 205 BRLAPI_KEY_CMD_LNDN);
201 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | 206 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD |
202 BRLAPI_KEY_CMD_FWINLT); 207 BRLAPI_KEY_CMD_FWINLT);
203 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | 208 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD |
204 BRLAPI_KEY_CMD_FWINRT); 209 BRLAPI_KEY_CMD_FWINRT);
205 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | 210 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD |
206 BRLAPI_KEY_CMD_TOP); 211 BRLAPI_KEY_CMD_TOP);
207 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | 212 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD |
208 BRLAPI_KEY_CMD_BOT); 213 BRLAPI_KEY_CMD_BOT);
209 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | 214 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD |
210 BRLAPI_KEY_CMD_ROUTE | 5); 215 BRLAPI_KEY_CMD_ROUTE | 5);
211 // Space (0) and all combinations of dots. 216
217 // Braille display standard keyboard emulation.
218
219 // An ascii character.
220 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_SYM | 'A');
221 // A non-ascii 'latin1' character. Small letter a with ring above.
222 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_SYM | 0xE5);
223 // A non-latin1 Unicode character. LATIN SMALL LETTER A WITH MACRON.
224 connection_data_.pending_keys.push_back(
225 BRLAPI_KEY_TYPE_SYM | BRLAPI_KEY_SYM_UNICODE | 0x100);
226 // A Unicode character outside the BMP. CAT FACE WITH TEARS OF JOY.
227 // With anticipation for the first emoji-enabled braille display.
228 connection_data_.pending_keys.push_back(
229 BRLAPI_KEY_TYPE_SYM | BRLAPI_KEY_SYM_UNICODE | 0x1F639);
230 // Invalid Unicode character.
231 connection_data_.pending_keys.push_back(
232 BRLAPI_KEY_TYPE_SYM | BRLAPI_KEY_SYM_UNICODE | 0x110000);
233
234 // Non-alphanumeric function keys.
235
236 // Backspace.
237 connection_data_.pending_keys.push_back(
238 BRLAPI_KEY_TYPE_SYM | BRLAPI_KEY_SYM_BACKSPACE);
239 // Shift+Tab.
240 connection_data_.pending_keys.push_back(
241 BRLAPI_KEY_TYPE_SYM | BRLAPI_KEY_FLG_SHIFT | BRLAPI_KEY_SYM_TAB);
242 // Alt+F3. (0-based).
243 connection_data_.pending_keys.push_back(
244 BRLAPI_KEY_TYPE_SYM | BRLAPI_KEY_FLG_META |
245 (BRLAPI_KEY_SYM_FUNCTION + 2));
246
247 // ctrl+dot1+dot2.
248 connection_data_.pending_keys.push_back(
249 BRLAPI_KEY_TYPE_CMD | BRLAPI_KEY_FLG_CONTROL | BRLAPI_KEY_CMD_PASSDOTS |
250 BRLAPI_DOT1 | BRLAPI_DOT2);
251
252 // Braille dot keys, all combinations including space (0).
212 for (int i = 0; i < 256; ++i) { 253 for (int i = 0; i < 256; ++i) {
213 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | 254 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD |
214 BRLAPI_KEY_CMD_PASSDOTS | i); 255 BRLAPI_KEY_CMD_PASSDOTS | i);
215 } 256 }
257
216 ASSERT_TRUE(RunComponentExtensionTest("braille_display_private/key_events")); 258 ASSERT_TRUE(RunComponentExtensionTest("braille_display_private/key_events"));
217 } 259 }
218 260
219 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, DisplayStateChanges) { 261 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, DisplayStateChanges) {
220 connection_data_.display_size = 11; 262 connection_data_.display_size = 11;
221 connection_data_.pending_keys.push_back(-1); 263 connection_data_.pending_keys.push_back(kErrorKeyCode);
222 connection_data_.reappear_on_disconnect = true; 264 connection_data_.reappear_on_disconnect = true;
223 ASSERT_TRUE(RunComponentExtensionTest( 265 ASSERT_TRUE(RunComponentExtensionTest(
224 "braille_display_private/display_state_changes")); 266 "braille_display_private/display_state_changes"));
225 } 267 }
226 268
227 class BrailleDisplayPrivateAPIUserTest : public BrailleDisplayPrivateApiTest { 269 class BrailleDisplayPrivateAPIUserTest : public BrailleDisplayPrivateApiTest {
228 public: 270 public:
229 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 271 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
230 command_line->AppendSwitch(chromeos::switches::kLoginManager); 272 command_line->AppendSwitch(chromeos::switches::kLoginManager);
231 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, 273 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 DismissLockScreen(tester.get()); 363 DismissLockScreen(tester.get());
322 signin_api.OnBrailleKeyEvent(key_event); 364 signin_api.OnBrailleKeyEvent(key_event);
323 user_api.OnBrailleKeyEvent(key_event); 365 user_api.OnBrailleKeyEvent(key_event);
324 EXPECT_EQ(1, signin_delegate->GetEventCount()); 366 EXPECT_EQ(1, signin_delegate->GetEventCount());
325 EXPECT_EQ(2, user_delegate->GetEventCount()); 367 EXPECT_EQ(2, user_delegate->GetEventCount());
326 } 368 }
327 369
328 } // namespace braille_display_private 370 } // namespace braille_display_private
329 } // namespace api 371 } // namespace api
330 } // namespace extensions 372 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698