| OLD | NEW |
| 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 | 7 |
| 7 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
| 8 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 9 #include <X11/Xutil.h> | 10 #include <X11/Xutil.h> |
| 10 #include <X11/XKBlib.h> | 11 #include <X11/XKBlib.h> |
| 11 | 12 |
| 12 // Generically-named #defines from Xlib that conflict with symbols in GTest. | 13 // Generically-named #defines from Xlib that conflict with symbols in GTest. |
| 13 #undef Bool | 14 #undef Bool |
| 14 #undef None | 15 #undef None |
| 15 | 16 |
| 17 #include "base/memory/scoped_ptr.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 18 #include "ui/events/event_constants.h" | 20 #include "ui/events/event_constants.h" |
| 19 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
| 20 #include "ui/events/test/events_test_utils_x11.h" | 22 #include "ui/events/test/events_test_utils_x11.h" |
| 21 #include "ui/events/x/device_data_manager_x11.h" | 23 #include "ui/events/x/device_data_manager_x11.h" |
| 24 #include "ui/events/x/touch_factory_x11.h" |
| 22 #include "ui/gfx/point.h" | 25 #include "ui/gfx/point.h" |
| 23 | 26 |
| 24 namespace ui { | 27 namespace ui { |
| 25 | 28 |
| 26 namespace { | 29 namespace { |
| 27 | 30 |
| 28 // Initializes the passed-in Xlib event. | 31 // Initializes the passed-in Xlib event. |
| 29 void InitButtonEvent(XEvent* event, | 32 void InitButtonEvent(XEvent* event, |
| 30 bool is_press, | 33 bool is_press, |
| 31 const gfx::Point& location, | 34 const gfx::Point& location, |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F30)); | 440 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F30)); |
| 438 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F31)); | 441 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F31)); |
| 439 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F32)); | 442 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F32)); |
| 440 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F33)); | 443 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F33)); |
| 441 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F34)); | 444 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F34)); |
| 442 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F35)); | 445 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F35)); |
| 443 // Max function key code plus 1. | 446 // Max function key code plus 1. |
| 444 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F35 + 1)); | 447 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F35 + 1)); |
| 445 } | 448 } |
| 446 | 449 |
| 450 // Verifies that the type of events from a disabled keyboard is ET_UNKNOWN, but |
| 451 // that an exception list of keys can still be processed. |
| 452 TEST_F(EventsXTest, DisableKeyboard) { |
| 453 DeviceDataManagerX11* device_data_manager = |
| 454 static_cast<DeviceDataManagerX11*>( |
| 455 DeviceDataManager::GetInstance()); |
| 456 scoped_ptr<std::set<KeyboardCode> > excepted_keys(new std::set<KeyboardCode>); |
| 457 excepted_keys->insert(VKEY_B); |
| 458 device_data_manager->DisableKeyboard(excepted_keys.Pass()); |
| 459 |
| 460 Display* display = gfx::GetXDisplay(); |
| 461 XEvent event; |
| 462 |
| 463 // A is not allowed on the blocked keyboard, and should return ET_UNKNOWN. |
| 464 InitKeyEvent(display, &event, true, XKeysymToKeycode(display, XK_A), 0); |
| 465 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(&event)); |
| 466 |
| 467 // The B key is allowed as an exception, and should return KEY_PRESSED. |
| 468 InitKeyEvent(display, &event, true, XKeysymToKeycode(display, XK_B), 0); |
| 469 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(&event)); |
| 470 |
| 471 device_data_manager->EnableKeyboard(); |
| 472 |
| 473 // A key returns KEY_PRESSED as per usual now that keyboard was re-enabled. |
| 474 InitKeyEvent(display, &event, true, XKeysymToKeycode(display, XK_A), 0); |
| 475 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(&event)); |
| 476 } |
| 477 |
| 478 #if defined(USE_XI2_MT) |
| 479 // Verifies that the type of events from a disabled mouse is ET_UNKNOWN. |
| 480 TEST_F(EventsXTest, DisableMouse) { |
| 481 DeviceDataManagerX11* device_data_manager = |
| 482 static_cast<DeviceDataManagerX11*>( |
| 483 DeviceDataManager::GetInstance()); |
| 484 unsigned int blocked_device_id = 1; |
| 485 unsigned int other_device_id = 2; |
| 486 std::vector<unsigned int> device_list; |
| 487 device_list.push_back(blocked_device_id); |
| 488 device_list.push_back(other_device_id); |
| 489 TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); |
| 490 |
| 491 device_data_manager->DisableDevice(blocked_device_id); |
| 492 |
| 493 ScopedXI2Event xev; |
| 494 xev.InitGenericButtonEvent(blocked_device_id, ET_MOUSE_PRESSED, gfx::Point(), |
| 495 EF_LEFT_MOUSE_BUTTON); |
| 496 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(xev)); |
| 497 |
| 498 xev.InitGenericButtonEvent(other_device_id, ET_MOUSE_PRESSED, gfx::Point(), |
| 499 EF_LEFT_MOUSE_BUTTON); |
| 500 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(xev)); |
| 501 |
| 502 device_data_manager->EnableDevice(blocked_device_id); |
| 503 |
| 504 xev.InitGenericButtonEvent(blocked_device_id, ET_MOUSE_PRESSED, gfx::Point(), |
| 505 EF_LEFT_MOUSE_BUTTON); |
| 506 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(xev)); |
| 507 } |
| 508 #endif // defined(USE_XI2_MT) |
| 509 |
| 447 #if !defined(OS_CHROMEOS) | 510 #if !defined(OS_CHROMEOS) |
| 448 TEST_F(EventsXTest, ImeFabricatedKeyEvents) { | 511 TEST_F(EventsXTest, ImeFabricatedKeyEvents) { |
| 449 Display* display = gfx::GetXDisplay(); | 512 Display* display = gfx::GetXDisplay(); |
| 450 | 513 |
| 451 unsigned int state_to_be_fabricated[] = { | 514 unsigned int state_to_be_fabricated[] = { |
| 452 0, ShiftMask, LockMask, ShiftMask | LockMask, | 515 0, ShiftMask, LockMask, ShiftMask | LockMask, |
| 453 }; | 516 }; |
| 454 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(state_to_be_fabricated); ++i) { | 517 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(state_to_be_fabricated); ++i) { |
| 455 unsigned int state = state_to_be_fabricated[i]; | 518 unsigned int state = state_to_be_fabricated[i]; |
| 456 for (int is_char = 0; is_char < 2; ++is_char) { | 519 for (int is_char = 0; is_char < 2; ++is_char) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 470 XEvent x_event; | 533 XEvent x_event; |
| 471 InitKeyEvent(display, &x_event, true, 0, state); | 534 InitKeyEvent(display, &x_event, true, 0, state); |
| 472 ui::KeyEvent key_event(&x_event, is_char); | 535 ui::KeyEvent key_event(&x_event, is_char); |
| 473 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); | 536 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); |
| 474 } | 537 } |
| 475 } | 538 } |
| 476 } | 539 } |
| 477 #endif | 540 #endif |
| 478 | 541 |
| 479 } // namespace ui | 542 } // namespace ui |
| OLD | NEW |