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