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

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

Issue 1135083004: Revert of Remove EF_FUNCTION_KEY and EF_NUMPAD_KEY. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « ui/events/x/events_x.cc ('k') | no next file » | 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>
(...skipping 29 matching lines...) Expand all
40 // We don't bother setting fields that the event code doesn't use, such as 40 // We don't bother setting fields that the event code doesn't use, such as
41 // x_root/y_root and window/root/subwindow. 41 // x_root/y_root and window/root/subwindow.
42 XButtonEvent* button_event = &(event->xbutton); 42 XButtonEvent* button_event = &(event->xbutton);
43 button_event->type = is_press ? ButtonPress : ButtonRelease; 43 button_event->type = is_press ? ButtonPress : ButtonRelease;
44 button_event->x = location.x(); 44 button_event->x = location.x();
45 button_event->y = location.y(); 45 button_event->y = location.y();
46 button_event->button = button; 46 button_event->button = button;
47 button_event->state = state; 47 button_event->state = state;
48 } 48 }
49 49
50 #if !defined(OS_CHROMEOS)
51 // Initializes the passed-in Xlib event. 50 // Initializes the passed-in Xlib event.
52 void InitKeyEvent(Display* display, 51 void InitKeyEvent(Display* display,
53 XEvent* event, 52 XEvent* event,
54 bool is_press, 53 bool is_press,
55 int keycode, 54 int keycode,
56 int state) { 55 int state) {
57 memset(event, 0, sizeof(*event)); 56 memset(event, 0, sizeof(*event));
58 57
59 // We don't bother setting fields that the event code doesn't use, such as 58 // We don't bother setting fields that the event code doesn't use, such as
60 // x_root/y_root and window/root/subwindow. 59 // x_root/y_root and window/root/subwindow.
61 XKeyEvent* key_event = &(event->xkey); 60 XKeyEvent* key_event = &(event->xkey);
62 key_event->display = display; 61 key_event->display = display;
63 key_event->type = is_press ? KeyPress : KeyRelease; 62 key_event->type = is_press ? KeyPress : KeyRelease;
64 key_event->keycode = keycode; 63 key_event->keycode = keycode;
65 key_event->state = state; 64 key_event->state = state;
66 } 65 }
67 #endif 66
67 // Returns true if the keysym maps to a KeyEvent with the EF_FUNCTION_KEY
68 // flag set, or the keysym maps to a zero key code.
69 bool HasFunctionKeyFlagSetIfSupported(Display* display, int x_keysym) {
70 XEvent event;
71 int x_keycode = XKeysymToKeycode(display, x_keysym);
72 // Exclude keysyms for which the server has no corresponding keycode.
73 if (x_keycode) {
74 InitKeyEvent(display, &event, true, x_keycode, 0);
75 ui::KeyEvent ui_key_event(&event);
76 return (ui_key_event.flags() & ui::EF_FUNCTION_KEY);
77 }
78 return true;
79 }
68 80
69 } // namespace 81 } // namespace
70 82
71 class EventsXTest : public testing::Test { 83 class EventsXTest : public testing::Test {
72 public: 84 public:
73 EventsXTest() {} 85 EventsXTest() {}
74 ~EventsXTest() override {} 86 ~EventsXTest() override {}
75 87
76 void SetUp() override { 88 void SetUp() override {
77 DeviceDataManagerX11::CreateInstance(); 89 DeviceDataManagerX11::CreateInstance();
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 ui::ScopedXI2Event xrelease0; 370 ui::ScopedXI2Event xrelease0;
359 xrelease0.InitTouchEvent(0, XI_TouchEnd, 0, gfx::Point(10, 10), valuators); 371 xrelease0.InitTouchEvent(0, XI_TouchEnd, 0, gfx::Point(10, 10), valuators);
360 ui::TouchEvent urelease0(xrelease0); 372 ui::TouchEvent urelease0(xrelease0);
361 { 373 {
362 // When the copy is destructed it should not attempt to remove the mapping. 374 // When the copy is destructed it should not attempt to remove the mapping.
363 // Exiting this scope should not cause a crash. 375 // Exiting this scope should not cause a crash.
364 ui::TouchEvent copy = urelease0; 376 ui::TouchEvent copy = urelease0;
365 } 377 }
366 } 378 }
367 379
380 TEST_F(EventsXTest, NumpadKeyEvents) {
381 XEvent event;
382 Display* display = gfx::GetXDisplay();
383
384 struct {
385 bool is_numpad_key;
386 int x_keysym;
387 } keys[] = {
388 // XK_KP_Space and XK_KP_Equal are the extrema in the conventional
389 // keysymdef.h numbering.
390 { true, XK_KP_Space },
391 { true, XK_KP_Equal },
392 // Other numpad keysyms. (This is actually exhaustive in the current list.)
393 { true, XK_KP_Tab },
394 { true, XK_KP_Enter },
395 { true, XK_KP_F1 },
396 { true, XK_KP_F2 },
397 { true, XK_KP_F3 },
398 { true, XK_KP_F4 },
399 { true, XK_KP_Home },
400 { true, XK_KP_Left },
401 { true, XK_KP_Up },
402 { true, XK_KP_Right },
403 { true, XK_KP_Down },
404 { true, XK_KP_Prior },
405 { true, XK_KP_Page_Up },
406 { true, XK_KP_Next },
407 { true, XK_KP_Page_Down },
408 { true, XK_KP_End },
409 { true, XK_KP_Begin },
410 { true, XK_KP_Insert },
411 { true, XK_KP_Delete },
412 { true, XK_KP_Multiply },
413 { true, XK_KP_Add },
414 { true, XK_KP_Separator },
415 { true, XK_KP_Subtract },
416 { true, XK_KP_Decimal },
417 { true, XK_KP_Divide },
418 { true, XK_KP_0 },
419 { true, XK_KP_1 },
420 { true, XK_KP_2 },
421 { true, XK_KP_3 },
422 { true, XK_KP_4 },
423 { true, XK_KP_5 },
424 { true, XK_KP_6 },
425 { true, XK_KP_7 },
426 { true, XK_KP_8 },
427 { true, XK_KP_9 },
428 // Largest keysym preceding XK_KP_Space.
429 { false, XK_Num_Lock },
430 // Smallest keysym following XK_KP_Equal.
431 { false, XK_F1 },
432 // Non-numpad analogues of numpad keysyms.
433 { false, XK_Tab },
434 { false, XK_Return },
435 { false, XK_F1 },
436 { false, XK_F2 },
437 { false, XK_F3 },
438 { false, XK_F4 },
439 { false, XK_Home },
440 { false, XK_Left },
441 { false, XK_Up },
442 { false, XK_Right },
443 { false, XK_Down },
444 { false, XK_Prior },
445 { false, XK_Page_Up },
446 { false, XK_Next },
447 { false, XK_Page_Down },
448 { false, XK_End },
449 { false, XK_Insert },
450 { false, XK_Delete },
451 { false, XK_multiply },
452 { false, XK_plus },
453 { false, XK_minus },
454 { false, XK_period },
455 { false, XK_slash },
456 { false, XK_0 },
457 { false, XK_1 },
458 { false, XK_2 },
459 { false, XK_3 },
460 { false, XK_4 },
461 { false, XK_5 },
462 { false, XK_6 },
463 { false, XK_7 },
464 { false, XK_8 },
465 { false, XK_9 },
466 // Miscellaneous other keysyms.
467 { false, XK_BackSpace },
468 { false, XK_Scroll_Lock },
469 { false, XK_Multi_key },
470 { false, XK_Select },
471 { false, XK_Num_Lock },
472 { false, XK_Shift_L },
473 { false, XK_space },
474 { false, XK_A },
475 };
476
477 for (size_t k = 0; k < arraysize(keys); ++k) {
478 int x_keycode = XKeysymToKeycode(display, keys[k].x_keysym);
479 // Exclude keysyms for which the server has no corresponding keycode.
480 if (x_keycode) {
481 InitKeyEvent(display, &event, true, x_keycode, 0);
482 // int keysym = XLookupKeysym(&event.xkey, 0);
483 // if (keysym) {
484 ui::KeyEvent ui_key_event(&event);
485 EXPECT_EQ(keys[k].is_numpad_key ? ui::EF_NUMPAD_KEY : 0,
486 ui_key_event.flags() & ui::EF_NUMPAD_KEY);
487 }
488 }
489 }
490
491 TEST_F(EventsXTest, FunctionKeyEvents) {
492 Display* display = gfx::GetXDisplay();
493
494 // Min function key code minus 1.
495 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F1 - 1));
496 // All function keys.
497 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F1));
498 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F2));
499 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F3));
500 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F4));
501 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F5));
502 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F6));
503 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F7));
504 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F8));
505 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F9));
506 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F10));
507 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F11));
508 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F12));
509 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F13));
510 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F14));
511 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F15));
512 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F16));
513 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F17));
514 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F18));
515 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F19));
516 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F20));
517 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F21));
518 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F22));
519 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F23));
520 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F24));
521 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F25));
522 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F26));
523 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F27));
524 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F28));
525 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F29));
526 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F30));
527 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F31));
528 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F32));
529 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F33));
530 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F34));
531 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F35));
532 // Max function key code plus 1.
533 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F35 + 1));
534 }
535
368 // Verifies that the type of events from a disabled keyboard is ET_UNKNOWN, but 536 // Verifies that the type of events from a disabled keyboard is ET_UNKNOWN, but
369 // that an exception list of keys can still be processed. 537 // that an exception list of keys can still be processed.
370 TEST_F(EventsXTest, DisableKeyboard) { 538 TEST_F(EventsXTest, DisableKeyboard) {
371 DeviceDataManagerX11* device_data_manager = 539 DeviceDataManagerX11* device_data_manager =
372 static_cast<DeviceDataManagerX11*>( 540 static_cast<DeviceDataManagerX11*>(
373 DeviceDataManager::GetInstance()); 541 DeviceDataManager::GetInstance());
374 int blocked_device_id = 1; 542 int blocked_device_id = 1;
375 int other_device_id = 2; 543 int other_device_id = 2;
376 int master_device_id = 3; 544 int master_device_id = 3;
377 device_data_manager->DisableDevice(blocked_device_id); 545 device_data_manager->DisableDevice(blocked_device_id);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 KeyEventTestApi test_event(&key_event); 655 KeyEventTestApi test_event(&key_event);
488 test_event.set_is_char(true); 656 test_event.set_is_char(true);
489 } 657 }
490 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); 658 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY);
491 } 659 }
492 } 660 }
493 } 661 }
494 #endif 662 #endif
495 663
496 } // namespace ui 664 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/x/events_x.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698