| 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" |
| 23 #include "ui/events/x/device_data_manager.h" |
| 24 #include "ui/events/x/touch_factory_x11.h" |
| 21 #include "ui/gfx/point.h" | 25 #include "ui/gfx/point.h" |
| 22 | 26 |
| 23 namespace ui { | 27 namespace ui { |
| 24 | 28 |
| 25 namespace { | 29 namespace { |
| 26 | 30 |
| 27 // Initializes the passed-in Xlib event. | 31 // Initializes the passed-in Xlib event. |
| 28 void InitButtonEvent(XEvent* event, | 32 void InitButtonEvent(XEvent* event, |
| 29 bool is_press, | 33 bool is_press, |
| 30 const gfx::Point& location, | 34 const gfx::Point& location, |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F30)); | 426 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F30)); |
| 423 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F31)); | 427 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F31)); |
| 424 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F32)); | 428 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F32)); |
| 425 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F33)); | 429 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F33)); |
| 426 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F34)); | 430 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F34)); |
| 427 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F35)); | 431 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F35)); |
| 428 // Max function key code plus 1. | 432 // Max function key code plus 1. |
| 429 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F35 + 1)); | 433 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F35 + 1)); |
| 430 } | 434 } |
| 431 | 435 |
| 436 // Verifies that the type of events from a disabled keyboard is ET_UNKNOWN, but |
| 437 // that an exception list of keys can still be processed. |
| 438 TEST(EventsXTest, DisableKeyboard) { |
| 439 DeviceDataManager* device_data_manager = DeviceDataManager::GetInstance(); |
| 440 scoped_ptr<std::set<KeyboardCode> > excepted_keys(new std::set<KeyboardCode>); |
| 441 excepted_keys->insert(VKEY_B); |
| 442 device_data_manager->DisableKeyboard(excepted_keys.Pass()); |
| 443 |
| 444 Display* display = gfx::GetXDisplay(); |
| 445 XEvent event; |
| 446 |
| 447 // A is not allowed on the blocked keyboard, and should return ET_UNKNOWN. |
| 448 InitKeyEvent(display, &event, true, XKeysymToKeycode(display, XK_A), 0); |
| 449 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(&event)); |
| 450 |
| 451 // The B key is allowed as an exception, and should return KEY_PRESSED. |
| 452 InitKeyEvent(display, &event, true, XKeysymToKeycode(display, XK_B), 0); |
| 453 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(&event)); |
| 454 |
| 455 device_data_manager->EnableKeyboard(); |
| 456 |
| 457 // A key returns KEY_PRESSED as per usual now that keyboard was re-enabled. |
| 458 InitKeyEvent(display, &event, true, XKeysymToKeycode(display, XK_A), 0); |
| 459 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(&event)); |
| 460 } |
| 461 |
| 462 #if defined(USE_XI2_MT) |
| 463 // Verifies that the type of events from a disabled mouse is ET_UNKNOWN. |
| 464 TEST(EventsXTest, DisableMouse) { |
| 465 DeviceDataManager* device_data_manager = DeviceDataManager::GetInstance(); |
| 466 unsigned int blocked_device_id = 1; |
| 467 unsigned int other_device_id = 2; |
| 468 std::vector<unsigned int> device_list; |
| 469 device_list.push_back(blocked_device_id); |
| 470 device_list.push_back(other_device_id); |
| 471 TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); |
| 472 |
| 473 device_data_manager->DisableDevice(blocked_device_id); |
| 474 |
| 475 ScopedXI2Event xev; |
| 476 xev.InitGenericButtonEvent(blocked_device_id, ET_MOUSE_PRESSED, gfx::Point(), |
| 477 EF_LEFT_MOUSE_BUTTON); |
| 478 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(xev)); |
| 479 |
| 480 xev.InitGenericButtonEvent(other_device_id, ET_MOUSE_PRESSED, gfx::Point(), |
| 481 EF_LEFT_MOUSE_BUTTON); |
| 482 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(xev)); |
| 483 |
| 484 device_data_manager->EnableDevice(blocked_device_id); |
| 485 |
| 486 xev.InitGenericButtonEvent(blocked_device_id, ET_MOUSE_PRESSED, gfx::Point(), |
| 487 EF_LEFT_MOUSE_BUTTON); |
| 488 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(xev)); |
| 489 } |
| 490 #endif |
| 491 |
| 432 } // namespace ui | 492 } // namespace ui |
| OLD | NEW |