| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/sticky_keys/sticky_keys_controller.h" | 5 #include "ash/sticky_keys/sticky_keys_controller.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #undef None | 8 #undef None |
| 9 #undef Bool | 9 #undef Bool |
| 10 #undef RootWindow | 10 #undef RootWindow |
| 11 | 11 |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_event_dispatcher.h" | 18 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/events/event_handler.h" | 19 #include "ui/events/event_handler.h" |
| 20 #include "ui/events/event_processor.h" |
| 20 #include "ui/events/test/events_test_utils_x11.h" | 21 #include "ui/events/test/events_test_utils_x11.h" |
| 21 #include "ui/events/x/device_data_manager.h" | 22 #include "ui/events/x/device_data_manager.h" |
| 22 | 23 |
| 23 namespace ash { | 24 namespace ash { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // The device id of the test scroll device. | 28 // The device id of the test scroll device. |
| 28 const unsigned int kScrollDeviceId = 1; | 29 const unsigned int kScrollDeviceId = 1; |
| 29 | 30 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 257 |
| 257 void SendActivateStickyKeyPattern(StickyKeysHandler* handler, | 258 void SendActivateStickyKeyPattern(StickyKeysHandler* handler, |
| 258 ui::KeyboardCode key_code) { | 259 ui::KeyboardCode key_code) { |
| 259 scoped_ptr<ui::KeyEvent> ev; | 260 scoped_ptr<ui::KeyEvent> ev; |
| 260 ev.reset(GenerateKey(true, key_code)); | 261 ev.reset(GenerateKey(true, key_code)); |
| 261 handler->HandleKeyEvent(ev.get()); | 262 handler->HandleKeyEvent(ev.get()); |
| 262 ev.reset(GenerateKey(false, key_code)); | 263 ev.reset(GenerateKey(false, key_code)); |
| 263 handler->HandleKeyEvent(ev.get()); | 264 handler->HandleKeyEvent(ev.get()); |
| 264 } | 265 } |
| 265 | 266 |
| 266 void SendActivateStickyKeyPattern(aura::WindowEventDispatcher* dispatcher, | 267 void SendActivateStickyKeyPattern(ui::EventProcessor* dispatcher, |
| 267 ui::KeyboardCode key_code) { | 268 ui::KeyboardCode key_code) { |
| 268 scoped_ptr<ui::KeyEvent> ev; | 269 scoped_ptr<ui::KeyEvent> ev; |
| 269 ev.reset(GenerateKey(true, key_code)); | 270 ev.reset(GenerateKey(true, key_code)); |
| 270 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(ev.get()); | 271 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(ev.get()); |
| 271 CHECK(!details.dispatcher_destroyed); | 272 CHECK(!details.dispatcher_destroyed); |
| 272 ev.reset(GenerateKey(false, key_code)); | 273 ev.reset(GenerateKey(false, key_code)); |
| 273 details = dispatcher->OnEventFromSource(ev.get()); | 274 details = dispatcher->OnEventFromSource(ev.get()); |
| 274 CHECK(!details.dispatcher_destroyed); | 275 CHECK(!details.dispatcher_destroyed); |
| 275 } | 276 } |
| 276 | 277 |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 mev.reset(GenerateSynthesizedMouseEvent(false)); | 787 mev.reset(GenerateSynthesizedMouseEvent(false)); |
| 787 sticky_key.HandleMouseEvent(mev.get()); | 788 sticky_key.HandleMouseEvent(mev.get()); |
| 788 EXPECT_TRUE(mev->flags() & ui::EF_CONTROL_DOWN); | 789 EXPECT_TRUE(mev->flags() & ui::EF_CONTROL_DOWN); |
| 789 EXPECT_EQ(STICKY_KEY_STATE_DISABLED, sticky_key.current_state()); | 790 EXPECT_EQ(STICKY_KEY_STATE_DISABLED, sticky_key.current_state()); |
| 790 } | 791 } |
| 791 | 792 |
| 792 TEST_F(StickyKeysTest, KeyEventDispatchImpl) { | 793 TEST_F(StickyKeysTest, KeyEventDispatchImpl) { |
| 793 // Test the actual key event dispatch implementation. | 794 // Test the actual key event dispatch implementation. |
| 794 EventBuffer buffer; | 795 EventBuffer buffer; |
| 795 ScopedVector<ui::Event> events; | 796 ScopedVector<ui::Event> events; |
| 796 aura::WindowEventDispatcher* dispatcher = | 797 ui::EventProcessor* dispatcher = |
| 797 Shell::GetPrimaryRootWindow()->GetHost()->dispatcher(); | 798 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); |
| 798 Shell::GetInstance()->AddPreTargetHandler(&buffer); | 799 Shell::GetInstance()->AddPreTargetHandler(&buffer); |
| 799 Shell::GetInstance()->sticky_keys_controller()->Enable(true); | 800 Shell::GetInstance()->sticky_keys_controller()->Enable(true); |
| 800 | 801 |
| 801 SendActivateStickyKeyPattern(dispatcher, ui::VKEY_CONTROL); | 802 SendActivateStickyKeyPattern(dispatcher, ui::VKEY_CONTROL); |
| 802 scoped_ptr<ui::KeyEvent> ev; | 803 scoped_ptr<ui::KeyEvent> ev; |
| 803 buffer.PopEvents(&events); | 804 buffer.PopEvents(&events); |
| 804 | 805 |
| 805 // Test key press event is correctly modified and modifier release | 806 // Test key press event is correctly modified and modifier release |
| 806 // event is sent. | 807 // event is sent. |
| 807 ev.reset(GenerateKey(true, ui::VKEY_C)); | 808 ev.reset(GenerateKey(true, ui::VKEY_C)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 826 static_cast<ui::KeyEvent*>(events[0])->key_code()); | 827 static_cast<ui::KeyEvent*>(events[0])->key_code()); |
| 827 EXPECT_FALSE(events[0]->flags() & ui::EF_CONTROL_DOWN); | 828 EXPECT_FALSE(events[0]->flags() & ui::EF_CONTROL_DOWN); |
| 828 | 829 |
| 829 Shell::GetInstance()->RemovePreTargetHandler(&buffer); | 830 Shell::GetInstance()->RemovePreTargetHandler(&buffer); |
| 830 } | 831 } |
| 831 | 832 |
| 832 TEST_F(StickyKeysTest, MouseEventDispatchImpl) { | 833 TEST_F(StickyKeysTest, MouseEventDispatchImpl) { |
| 833 // Test the actual sticky mouse event dispatch implementation. | 834 // Test the actual sticky mouse event dispatch implementation. |
| 834 EventBuffer buffer; | 835 EventBuffer buffer; |
| 835 ScopedVector<ui::Event> events; | 836 ScopedVector<ui::Event> events; |
| 836 aura::WindowEventDispatcher* dispatcher = | 837 ui::EventProcessor* dispatcher = |
| 837 Shell::GetPrimaryRootWindow()->GetHost()->dispatcher(); | 838 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); |
| 838 Shell::GetInstance()->AddPreTargetHandler(&buffer); | 839 Shell::GetInstance()->AddPreTargetHandler(&buffer); |
| 839 Shell::GetInstance()->sticky_keys_controller()->Enable(true); | 840 Shell::GetInstance()->sticky_keys_controller()->Enable(true); |
| 840 | 841 |
| 841 scoped_ptr<ui::MouseEvent> ev; | 842 scoped_ptr<ui::MouseEvent> ev; |
| 842 SendActivateStickyKeyPattern(dispatcher, ui::VKEY_CONTROL); | 843 SendActivateStickyKeyPattern(dispatcher, ui::VKEY_CONTROL); |
| 843 buffer.PopEvents(&events); | 844 buffer.PopEvents(&events); |
| 844 | 845 |
| 845 // Test mouse press event is correctly modified. | 846 // Test mouse press event is correctly modified. |
| 846 ev.reset(GenerateMouseEvent(true)); | 847 ev.reset(GenerateMouseEvent(true)); |
| 847 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(ev.get()); | 848 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(ev.get()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 863 EXPECT_EQ(ui::VKEY_CONTROL, | 864 EXPECT_EQ(ui::VKEY_CONTROL, |
| 864 static_cast<ui::KeyEvent*>(events[1])->key_code()); | 865 static_cast<ui::KeyEvent*>(events[1])->key_code()); |
| 865 | 866 |
| 866 Shell::GetInstance()->RemovePreTargetHandler(&buffer); | 867 Shell::GetInstance()->RemovePreTargetHandler(&buffer); |
| 867 } | 868 } |
| 868 | 869 |
| 869 TEST_F(StickyKeysTest, MouseWheelEventDispatchImpl) { | 870 TEST_F(StickyKeysTest, MouseWheelEventDispatchImpl) { |
| 870 // Test the actual mouse wheel event dispatch implementation. | 871 // Test the actual mouse wheel event dispatch implementation. |
| 871 EventBuffer buffer; | 872 EventBuffer buffer; |
| 872 ScopedVector<ui::Event> events; | 873 ScopedVector<ui::Event> events; |
| 873 aura::WindowEventDispatcher* dispatcher = | 874 ui::EventProcessor* dispatcher = |
| 874 Shell::GetPrimaryRootWindow()->GetHost()->dispatcher(); | 875 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); |
| 875 Shell::GetInstance()->AddPreTargetHandler(&buffer); | 876 Shell::GetInstance()->AddPreTargetHandler(&buffer); |
| 876 Shell::GetInstance()->sticky_keys_controller()->Enable(true); | 877 Shell::GetInstance()->sticky_keys_controller()->Enable(true); |
| 877 | 878 |
| 878 scoped_ptr<ui::MouseWheelEvent> ev; | 879 scoped_ptr<ui::MouseWheelEvent> ev; |
| 879 SendActivateStickyKeyPattern(dispatcher, ui::VKEY_CONTROL); | 880 SendActivateStickyKeyPattern(dispatcher, ui::VKEY_CONTROL); |
| 880 buffer.PopEvents(&events); | 881 buffer.PopEvents(&events); |
| 881 | 882 |
| 882 // Test positive mouse wheel event is correctly modified and modifier release | 883 // Test positive mouse wheel event is correctly modified and modifier release |
| 883 // event is sent. | 884 // event is sent. |
| 884 ev.reset(GenerateMouseWheelEvent(ui::MouseWheelEvent::kWheelDelta)); | 885 ev.reset(GenerateMouseWheelEvent(ui::MouseWheelEvent::kWheelDelta)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 909 static_cast<ui::MouseWheelEvent*>(events[0])->y_offset()); | 910 static_cast<ui::MouseWheelEvent*>(events[0])->y_offset()); |
| 910 EXPECT_TRUE(events[0]->flags() & ui::EF_CONTROL_DOWN); | 911 EXPECT_TRUE(events[0]->flags() & ui::EF_CONTROL_DOWN); |
| 911 EXPECT_EQ(ui::ET_KEY_RELEASED, events[1]->type()); | 912 EXPECT_EQ(ui::ET_KEY_RELEASED, events[1]->type()); |
| 912 EXPECT_EQ(ui::VKEY_CONTROL, | 913 EXPECT_EQ(ui::VKEY_CONTROL, |
| 913 static_cast<ui::KeyEvent*>(events[1])->key_code()); | 914 static_cast<ui::KeyEvent*>(events[1])->key_code()); |
| 914 | 915 |
| 915 Shell::GetInstance()->RemovePreTargetHandler(&buffer); | 916 Shell::GetInstance()->RemovePreTargetHandler(&buffer); |
| 916 } | 917 } |
| 917 | 918 |
| 918 } // namespace ash | 919 } // namespace ash |
| OLD | NEW |