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

Side by Side Diff: ui/events/x/events_x_unittest.cc

Issue 404203003: Distinguish between keystroke and character events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IsCharFromNative() for Mac build Created 6 years, 5 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
« no previous file with comments | « ui/events/x/events_x.cc ('k') | ui/keyboard/keyboard_util.cc » ('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 <cstring> 5 #include <cstring>
6 #include <set> 6 #include <set>
7 7
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 #include <X11/Xlib.h> 9 #include <X11/Xlib.h>
10 #include <X11/Xutil.h> 10 #include <X11/Xutil.h>
11 #include <X11/XKBlib.h> 11 #include <X11/XKBlib.h>
12 12
13 // Generically-named #defines from Xlib that conflict with symbols in GTest. 13 // Generically-named #defines from Xlib that conflict with symbols in GTest.
14 #undef Bool 14 #undef Bool
15 #undef None 15 #undef None
16 16
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/events/event.h" 19 #include "ui/events/event.h"
20 #include "ui/events/event_constants.h" 20 #include "ui/events/event_constants.h"
21 #include "ui/events/event_utils.h" 21 #include "ui/events/event_utils.h"
22 #include "ui/events/test/events_test_utils.h"
22 #include "ui/events/test/events_test_utils_x11.h" 23 #include "ui/events/test/events_test_utils_x11.h"
23 #include "ui/events/x/device_data_manager_x11.h" 24 #include "ui/events/x/device_data_manager_x11.h"
24 #include "ui/events/x/touch_factory_x11.h" 25 #include "ui/events/x/touch_factory_x11.h"
25 #include "ui/gfx/point.h" 26 #include "ui/gfx/point.h"
26 27
27 namespace ui { 28 namespace ui {
28 29
29 namespace { 30 namespace {
30 31
31 // Initializes the passed-in Xlib event. 32 // Initializes the passed-in Xlib event.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 65 }
65 66
66 // Returns true if the keysym maps to a KeyEvent with the EF_FUNCTION_KEY 67 // Returns true if the keysym maps to a KeyEvent with the EF_FUNCTION_KEY
67 // flag set, or the keysym maps to a zero key code. 68 // flag set, or the keysym maps to a zero key code.
68 bool HasFunctionKeyFlagSetIfSupported(Display* display, int x_keysym) { 69 bool HasFunctionKeyFlagSetIfSupported(Display* display, int x_keysym) {
69 XEvent event; 70 XEvent event;
70 int x_keycode = XKeysymToKeycode(display, x_keysym); 71 int x_keycode = XKeysymToKeycode(display, x_keysym);
71 // Exclude keysyms for which the server has no corresponding keycode. 72 // Exclude keysyms for which the server has no corresponding keycode.
72 if (x_keycode) { 73 if (x_keycode) {
73 InitKeyEvent(display, &event, true, x_keycode, 0); 74 InitKeyEvent(display, &event, true, x_keycode, 0);
74 ui::KeyEvent ui_key_event(&event, false); 75 ui::KeyEvent ui_key_event(&event);
75 return (ui_key_event.flags() & ui::EF_FUNCTION_KEY); 76 return (ui_key_event.flags() & ui::EF_FUNCTION_KEY);
76 } 77 }
77 return true; 78 return true;
78 } 79 }
79 80
80 } // namespace 81 } // namespace
81 82
82 class EventsXTest : public testing::Test { 83 class EventsXTest : public testing::Test {
83 public: 84 public:
84 EventsXTest() {} 85 EventsXTest() {}
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 { false, XK_A }, 389 { false, XK_A },
389 }; 390 };
390 391
391 for (size_t k = 0; k < ARRAYSIZE_UNSAFE(keys); ++k) { 392 for (size_t k = 0; k < ARRAYSIZE_UNSAFE(keys); ++k) {
392 int x_keycode = XKeysymToKeycode(display, keys[k].x_keysym); 393 int x_keycode = XKeysymToKeycode(display, keys[k].x_keysym);
393 // Exclude keysyms for which the server has no corresponding keycode. 394 // Exclude keysyms for which the server has no corresponding keycode.
394 if (x_keycode) { 395 if (x_keycode) {
395 InitKeyEvent(display, &event, true, x_keycode, 0); 396 InitKeyEvent(display, &event, true, x_keycode, 0);
396 // int keysym = XLookupKeysym(&event.xkey, 0); 397 // int keysym = XLookupKeysym(&event.xkey, 0);
397 // if (keysym) { 398 // if (keysym) {
398 ui::KeyEvent ui_key_event(&event, false); 399 ui::KeyEvent ui_key_event(&event);
399 EXPECT_EQ(keys[k].is_numpad_key ? ui::EF_NUMPAD_KEY : 0, 400 EXPECT_EQ(keys[k].is_numpad_key ? ui::EF_NUMPAD_KEY : 0,
400 ui_key_event.flags() & ui::EF_NUMPAD_KEY); 401 ui_key_event.flags() & ui::EF_NUMPAD_KEY);
401 } 402 }
402 } 403 }
403 } 404 }
404 405
405 TEST_F(EventsXTest, FunctionKeyEvents) { 406 TEST_F(EventsXTest, FunctionKeyEvents) {
406 Display* display = gfx::GetXDisplay(); 407 Display* display = gfx::GetXDisplay();
407 408
408 // Min function key code minus 1. 409 // Min function key code minus 1.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 Display* display = gfx::GetXDisplay(); 513 Display* display = gfx::GetXDisplay();
513 514
514 unsigned int state_to_be_fabricated[] = { 515 unsigned int state_to_be_fabricated[] = {
515 0, ShiftMask, LockMask, ShiftMask | LockMask, 516 0, ShiftMask, LockMask, ShiftMask | LockMask,
516 }; 517 };
517 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(state_to_be_fabricated); ++i) { 518 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(state_to_be_fabricated); ++i) {
518 unsigned int state = state_to_be_fabricated[i]; 519 unsigned int state = state_to_be_fabricated[i];
519 for (int is_char = 0; is_char < 2; ++is_char) { 520 for (int is_char = 0; is_char < 2; ++is_char) {
520 XEvent x_event; 521 XEvent x_event;
521 InitKeyEvent(display, &x_event, true, 0, state); 522 InitKeyEvent(display, &x_event, true, 0, state);
522 ui::KeyEvent key_event(&x_event, is_char); 523 ui::KeyEvent key_event(&x_event);
524 if (is_char) {
525 KeyEventTestApi test_event(&key_event);
526 test_event.set_is_char(true);
527 }
523 EXPECT_TRUE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); 528 EXPECT_TRUE(key_event.flags() & ui::EF_IME_FABRICATED_KEY);
524 } 529 }
525 } 530 }
526 531
527 unsigned int state_to_be_not_fabricated[] = { 532 unsigned int state_to_be_not_fabricated[] = {
528 ControlMask, Mod1Mask, Mod2Mask, ShiftMask | ControlMask, 533 ControlMask, Mod1Mask, Mod2Mask, ShiftMask | ControlMask,
529 }; 534 };
530 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(state_to_be_not_fabricated); ++i) { 535 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(state_to_be_not_fabricated); ++i) {
531 unsigned int state = state_to_be_not_fabricated[i]; 536 unsigned int state = state_to_be_not_fabricated[i];
532 for (int is_char = 0; is_char < 2; ++is_char) { 537 for (int is_char = 0; is_char < 2; ++is_char) {
533 XEvent x_event; 538 XEvent x_event;
534 InitKeyEvent(display, &x_event, true, 0, state); 539 InitKeyEvent(display, &x_event, true, 0, state);
535 ui::KeyEvent key_event(&x_event, is_char); 540 ui::KeyEvent key_event(&x_event);
541 if (is_char) {
542 KeyEventTestApi test_event(&key_event);
543 test_event.set_is_char(true);
544 }
536 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); 545 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY);
537 } 546 }
538 } 547 }
539 } 548 }
540 #endif 549 #endif
541 550
542 } // namespace ui 551 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/x/events_x.cc ('k') | ui/keyboard/keyboard_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698