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 #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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 510 |
511 #if defined(USE_XI2_MT) | 511 #if defined(USE_XI2_MT) |
512 // Verifies that the type of events from a disabled keyboard is ET_UNKNOWN, but | 512 // Verifies that the type of events from a disabled keyboard is ET_UNKNOWN, but |
513 // that an exception list of keys can still be processed. | 513 // that an exception list of keys can still be processed. |
514 TEST_F(EventsXTest, DisableKeyboard) { | 514 TEST_F(EventsXTest, DisableKeyboard) { |
515 DeviceDataManagerX11* device_data_manager = | 515 DeviceDataManagerX11* device_data_manager = |
516 static_cast<DeviceDataManagerX11*>( | 516 static_cast<DeviceDataManagerX11*>( |
517 DeviceDataManager::GetInstance()); | 517 DeviceDataManager::GetInstance()); |
518 unsigned int blocked_device_id = 1; | 518 unsigned int blocked_device_id = 1; |
519 unsigned int other_device_id = 2; | 519 unsigned int other_device_id = 2; |
520 unsigned int master_device_id = 3; | |
521 device_data_manager->DisableDevice(blocked_device_id); | 520 device_data_manager->DisableDevice(blocked_device_id); |
522 | 521 |
523 scoped_ptr<std::set<KeyboardCode> > excepted_keys(new std::set<KeyboardCode>); | 522 scoped_ptr<std::set<KeyboardCode> > excepted_keys(new std::set<KeyboardCode>); |
524 excepted_keys->insert(VKEY_B); | 523 excepted_keys->insert(VKEY_B); |
525 device_data_manager->SetDisabledKeyboardAllowedKeys(excepted_keys.Pass()); | 524 device_data_manager->SetDisabledKeyboardAllowedKeys(excepted_keys.Pass()); |
526 | 525 |
527 ScopedXI2Event xev; | 526 ScopedXI2Event xev; |
528 // A is not allowed on the blocked keyboard, and should return ET_UNKNOWN. | 527 // A is not allowed on the blocked keyboard, and should return ET_UNKNOWN. |
529 xev.InitGenericKeyEvent(master_device_id, | 528 xev.InitGenericKeyEvent(blocked_device_id, ui::ET_KEY_PRESSED, ui::VKEY_A, 0); |
530 blocked_device_id, | |
531 ui::ET_KEY_PRESSED, | |
532 ui::VKEY_A, | |
533 0); | |
534 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(xev)); | 529 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(xev)); |
535 | 530 |
536 // The B key is allowed as an exception, and should return KEY_PRESSED. | 531 // The B key is allowed as an exception, and should return KEY_PRESSED. |
537 xev.InitGenericKeyEvent(master_device_id, | 532 xev.InitGenericKeyEvent(blocked_device_id, ui::ET_KEY_PRESSED, ui::VKEY_B, 0); |
538 blocked_device_id, | |
539 ui::ET_KEY_PRESSED, | |
540 ui::VKEY_B, | |
541 0); | |
542 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); | 533 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); |
543 | 534 |
544 // Both A and B are allowed on an unblocked keyboard device. | 535 // Both A and B are allowed on an unblocked keyboard device. |
545 xev.InitGenericKeyEvent(master_device_id, | 536 xev.InitGenericKeyEvent(other_device_id, ui::ET_KEY_PRESSED, ui::VKEY_A, 0); |
546 other_device_id, | |
547 ui::ET_KEY_PRESSED, | |
548 ui::VKEY_A, | |
549 0); | |
550 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); | 537 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); |
551 xev.InitGenericKeyEvent(master_device_id, | 538 xev.InitGenericKeyEvent(other_device_id, ui::ET_KEY_PRESSED, ui::VKEY_B, 0); |
552 other_device_id, | |
553 ui::ET_KEY_PRESSED, | |
554 ui::VKEY_B, | |
555 0); | |
556 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); | 539 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); |
557 | 540 |
558 device_data_manager->EnableDevice(blocked_device_id); | 541 device_data_manager->EnableDevice(blocked_device_id); |
559 device_data_manager->SetDisabledKeyboardAllowedKeys( | 542 device_data_manager->SetDisabledKeyboardAllowedKeys( |
560 scoped_ptr<std::set<KeyboardCode> >()); | 543 scoped_ptr<std::set<KeyboardCode> >()); |
561 | 544 |
562 // A key returns KEY_PRESSED as per usual now that keyboard was re-enabled. | 545 // A key returns KEY_PRESSED as per usual now that keyboard was re-enabled. |
563 xev.InitGenericKeyEvent(master_device_id, | 546 xev.InitGenericKeyEvent(blocked_device_id, ui::ET_KEY_PRESSED, ui::VKEY_A, 0); |
564 blocked_device_id, | |
565 ui::ET_KEY_PRESSED, | |
566 ui::VKEY_A, | |
567 0); | |
568 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); | 547 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); |
569 } | 548 } |
570 | 549 |
571 // Verifies that the type of events from a disabled mouse is ET_UNKNOWN. | 550 // Verifies that the type of events from a disabled mouse is ET_UNKNOWN. |
572 TEST_F(EventsXTest, DisableMouse) { | 551 TEST_F(EventsXTest, DisableMouse) { |
573 DeviceDataManagerX11* device_data_manager = | 552 DeviceDataManagerX11* device_data_manager = |
574 static_cast<DeviceDataManagerX11*>( | 553 static_cast<DeviceDataManagerX11*>( |
575 DeviceDataManager::GetInstance()); | 554 DeviceDataManager::GetInstance()); |
576 unsigned int blocked_device_id = 1; | 555 unsigned int blocked_device_id = 1; |
577 unsigned int other_device_id = 2; | 556 unsigned int other_device_id = 2; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 KeyEventTestApi test_event(&key_event); | 612 KeyEventTestApi test_event(&key_event); |
634 test_event.set_is_char(true); | 613 test_event.set_is_char(true); |
635 } | 614 } |
636 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); | 615 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); |
637 } | 616 } |
638 } | 617 } |
639 } | 618 } |
640 #endif | 619 #endif |
641 | 620 |
642 } // namespace ui | 621 } // namespace ui |
OLD | NEW |