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

Side by Side Diff: ui/events/event_unittest.cc

Issue 494813002: events: keycodes: Remove the stateless singleton instance of KeycodeConverter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/input_injector_win.cc ('k') | ui/events/keycodes/dom4/keycode_converter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/events/event.h" 7 #include "ui/events/event.h"
8 #include "ui/events/event_utils.h" 8 #include "ui/events/event_utils.h"
9 #include "ui/events/keycodes/dom4/keycode_converter.h" 9 #include "ui/events/keycodes/dom4/keycode_converter.h"
10 #include "ui/events/test/events_test_utils.h" 10 #include "ui/events/test/events_test_utils.h"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 322 }
323 323
324 TEST(EventTest, KeyEventCopy) { 324 TEST(EventTest, KeyEventCopy) {
325 KeyEvent key(ET_KEY_PRESSED, VKEY_A, EF_NONE); 325 KeyEvent key(ET_KEY_PRESSED, VKEY_A, EF_NONE);
326 scoped_ptr<KeyEvent> copied_key(new KeyEvent(key)); 326 scoped_ptr<KeyEvent> copied_key(new KeyEvent(key));
327 EXPECT_EQ(copied_key->type(), key.type()); 327 EXPECT_EQ(copied_key->type(), key.type());
328 EXPECT_EQ(copied_key->key_code(), key.key_code()); 328 EXPECT_EQ(copied_key->key_code(), key.key_code());
329 } 329 }
330 330
331 TEST(EventTest, KeyEventCode) { 331 TEST(EventTest, KeyEventCode) {
332 KeycodeConverter* conv = KeycodeConverter::GetInstance();
333
334 const char kCodeForSpace[] = "Space"; 332 const char kCodeForSpace[] = "Space";
335 const uint16 kNativeCodeSpace = conv->CodeToNativeKeycode(kCodeForSpace); 333 const uint16 kNativeCodeSpace =
336 ASSERT_NE(conv->InvalidNativeKeycode(), kNativeCodeSpace); 334 ui::KeycodeConverter::CodeToNativeKeycode(kCodeForSpace);
335 ASSERT_NE(ui::KeycodeConverter::InvalidNativeKeycode(), kNativeCodeSpace);
337 336
338 { 337 {
339 KeyEvent key(ET_KEY_PRESSED, VKEY_SPACE, kCodeForSpace, EF_NONE); 338 KeyEvent key(ET_KEY_PRESSED, VKEY_SPACE, kCodeForSpace, EF_NONE);
340 EXPECT_EQ(kCodeForSpace, key.code()); 339 EXPECT_EQ(kCodeForSpace, key.code());
341 } 340 }
342 { 341 {
343 // Regardless the KeyEvent.key_code (VKEY_RETURN), code should be 342 // Regardless the KeyEvent.key_code (VKEY_RETURN), code should be
344 // the specified value. 343 // the specified value.
345 KeyEvent key(ET_KEY_PRESSED, VKEY_RETURN, kCodeForSpace, EF_NONE); 344 KeyEvent key(ET_KEY_PRESSED, VKEY_RETURN, kCodeForSpace, EF_NONE);
346 EXPECT_EQ(kCodeForSpace, key.code()); 345 EXPECT_EQ(kCodeForSpace, key.code());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 KeyEvent key(native_event); 384 KeyEvent key(native_event);
386 385
387 // KeyEvent converts from the native keycode (scan code) to the code. 386 // KeyEvent converts from the native keycode (scan code) to the code.
388 EXPECT_EQ(kCodeForHome, key.code()); 387 EXPECT_EQ(kCodeForHome, key.code());
389 } 388 }
390 #endif // OS_WIN 389 #endif // OS_WIN
391 } 390 }
392 391
393 #if defined(USE_X11) || defined(OS_WIN) 392 #if defined(USE_X11) || defined(OS_WIN)
394 TEST(EventTest, AutoRepeat) { 393 TEST(EventTest, AutoRepeat) {
395 KeycodeConverter* conv = KeycodeConverter::GetInstance(); 394 const uint16 kNativeCodeA = ui::KeycodeConverter::CodeToNativeKeycode("KeyA");
396 395 const uint16 kNativeCodeB = ui::KeycodeConverter::CodeToNativeKeycode("KeyB");
397 const uint16 kNativeCodeA = conv->CodeToNativeKeycode("KeyA");
398 const uint16 kNativeCodeB = conv->CodeToNativeKeycode("KeyB");
399 #if defined(USE_X11) 396 #if defined(USE_X11)
400 ScopedXI2Event native_event_a_pressed; 397 ScopedXI2Event native_event_a_pressed;
401 native_event_a_pressed.InitKeyEvent(ET_KEY_PRESSED, VKEY_A, kNativeCodeA); 398 native_event_a_pressed.InitKeyEvent(ET_KEY_PRESSED, VKEY_A, kNativeCodeA);
402 ScopedXI2Event native_event_a_released; 399 ScopedXI2Event native_event_a_released;
403 native_event_a_released.InitKeyEvent(ET_KEY_RELEASED, VKEY_A, kNativeCodeA); 400 native_event_a_released.InitKeyEvent(ET_KEY_RELEASED, VKEY_A, kNativeCodeA);
404 ScopedXI2Event native_event_b_pressed; 401 ScopedXI2Event native_event_b_pressed;
405 native_event_b_pressed.InitKeyEvent(ET_KEY_PRESSED, VKEY_B, kNativeCodeB); 402 native_event_b_pressed.InitKeyEvent(ET_KEY_PRESSED, VKEY_B, kNativeCodeB);
406 ScopedXI2Event native_event_a_pressed_nonstandard_state; 403 ScopedXI2Event native_event_a_pressed_nonstandard_state;
407 native_event_a_pressed_nonstandard_state.InitKeyEvent( 404 native_event_a_pressed_nonstandard_state.InitKeyEvent(
408 ET_KEY_PRESSED, VKEY_A, kNativeCodeA); 405 ET_KEY_PRESSED, VKEY_A, kNativeCodeA);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 EXPECT_FALSE(key_a4_pressed.IsRepeat()); 443 EXPECT_FALSE(key_a4_pressed.IsRepeat());
447 444
448 KeyEvent key_a4_pressed_nonstandard_state( 445 KeyEvent key_a4_pressed_nonstandard_state(
449 native_event_a_pressed_nonstandard_state); 446 native_event_a_pressed_nonstandard_state);
450 EXPECT_FALSE(key_a4_pressed_nonstandard_state.IsRepeat()); 447 EXPECT_FALSE(key_a4_pressed_nonstandard_state.IsRepeat());
451 #endif 448 #endif
452 } 449 }
453 #endif // USE_X11 || OS_WIN 450 #endif // USE_X11 || OS_WIN
454 451
455 } // namespace ui 452 } // namespace ui
OLDNEW
« no previous file with comments | « remoting/host/input_injector_win.cc ('k') | ui/events/keycodes/dom4/keycode_converter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698