OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/wm/core/nested_accelerator_controller.h" | 5 #include "ui/wm/core/nested_accelerator_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/event_types.h" | 8 #include "base/event_types.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
11 #include "ui/aura/test/test_windows.h" | 11 #include "ui/aura/test/test_windows.h" |
12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
13 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
14 #include "ui/base/accelerators/accelerator.h" | 14 #include "ui/base/accelerators/accelerator.h" |
15 #include "ui/base/accelerators/accelerator.h" | 15 #include "ui/base/accelerators/accelerator.h" |
16 #include "ui/base/accelerators/accelerator_manager.h" | 16 #include "ui/base/accelerators/accelerator_manager.h" |
17 #include "ui/events/event_constants.h" | 17 #include "ui/events/event_constants.h" |
18 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
19 #include "ui/events/platform/platform_event_dispatcher.h" | 19 #include "ui/events/platform/platform_event_dispatcher.h" |
20 #include "ui/events/platform/platform_event_source.h" | 20 #include "ui/events/platform/platform_event_source.h" |
21 #include "ui/events/platform/scoped_event_dispatcher.h" | 21 #include "ui/events/platform/scoped_event_dispatcher.h" |
22 #include "ui/wm/core/nested_accelerator_delegate.h" | 22 #include "ui/wm/core/nested_accelerator_delegate.h" |
23 #include "ui/wm/public/dispatcher_client.h" | 23 #include "ui/wm/public/dispatcher_client.h" |
24 | 24 |
25 #if defined(USE_X11) | 25 #if defined(USE_X11) |
26 #include <X11/Xlib.h> | 26 #include <X11/Xlib.h> |
| 27 #include "ui/aura/test/x11_event_sender.h" |
27 #include "ui/events/test/events_test_utils_x11.h" | 28 #include "ui/events/test/events_test_utils_x11.h" |
28 #endif // USE_X11 | 29 #endif // USE_X11 |
29 | 30 |
30 namespace wm { | 31 namespace wm { |
31 namespace test { | 32 namespace test { |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 class MockDispatcher : public ui::PlatformEventDispatcher { | 36 class MockDispatcher : public ui::PlatformEventDispatcher { |
36 public: | 37 public: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 int accelerator_pressed_count_; | 73 int accelerator_pressed_count_; |
73 | 74 |
74 DISALLOW_COPY_AND_ASSIGN(TestTarget); | 75 DISALLOW_COPY_AND_ASSIGN(TestTarget); |
75 }; | 76 }; |
76 | 77 |
77 void DispatchKeyReleaseA(aura::Window* root_window) { | 78 void DispatchKeyReleaseA(aura::Window* root_window) { |
78 // Sending both keydown and keyup is necessary here because the accelerator | 79 // Sending both keydown and keyup is necessary here because the accelerator |
79 // manager only checks a keyup event following a keydown event. See | 80 // manager only checks a keyup event following a keydown event. See |
80 // ShouldHandle() in ui/base/accelerators/accelerator_manager.cc for details. | 81 // ShouldHandle() in ui/base/accelerators/accelerator_manager.cc for details. |
81 #if defined(OS_WIN) | 82 #if defined(OS_WIN) |
82 MSG native_event_down = {NULL, WM_KEYDOWN, ui::VKEY_A, 0}; | |
83 aura::WindowTreeHost* host = root_window->GetHost(); | 83 aura::WindowTreeHost* host = root_window->GetHost(); |
84 host->PostNativeEvent(native_event_down); | 84 HWND hwnd = host->GetAcceleratedWidget(); |
| 85 ::PostMessage(hwnd, WM_KEYDOWN, ui::VKEY_A, 0); |
85 MSG native_event_up = {NULL, WM_KEYUP, ui::VKEY_A, 0}; | 86 MSG native_event_up = {NULL, WM_KEYUP, ui::VKEY_A, 0}; |
86 host->PostNativeEvent(native_event_up); | 87 ::PostMessage(hwnd, WM_KEYUP, ui::VKEY_A, 0); |
87 #elif defined(USE_X11) | 88 #elif defined(USE_X11) |
88 ui::ScopedXI2Event native_event; | 89 ui::ScopedXI2Event native_event; |
89 native_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); | 90 native_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); |
90 aura::WindowTreeHost* host = root_window->GetHost(); | 91 aura::WindowTreeHost* host = root_window->GetHost(); |
91 host->PostNativeEvent(native_event); | 92 aura::test::PostEventToWindowTreeHost(*native_event, host); |
92 native_event.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, 0); | 93 native_event.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, 0); |
93 host->PostNativeEvent(native_event); | 94 aura::test::PostEventToWindowTreeHost(*native_event, host); |
94 #endif | 95 #endif |
95 // Make sure the inner message-loop terminates after dispatching the events. | 96 // Make sure the inner message-loop terminates after dispatching the events. |
96 base::MessageLoop::current()->PostTask( | 97 base::MessageLoop::current()->PostTask( |
97 FROM_HERE, base::MessageLoop::current()->QuitClosure()); | 98 FROM_HERE, base::MessageLoop::current()->QuitClosure()); |
98 } | 99 } |
99 | 100 |
100 class MockNestedAcceleratorDelegate : public NestedAcceleratorDelegate { | 101 class MockNestedAcceleratorDelegate : public NestedAcceleratorDelegate { |
101 public: | 102 public: |
102 MockNestedAcceleratorDelegate() | 103 MockNestedAcceleratorDelegate() |
103 : accelerator_manager_(new ui::AcceleratorManager) {} | 104 : accelerator_manager_(new ui::AcceleratorManager) {} |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 &inner_dispatcher); | 198 &inner_dispatcher); |
198 aura::client::DispatcherRunLoop run_loop( | 199 aura::client::DispatcherRunLoop run_loop( |
199 aura::client::GetDispatcherClient(root_window()), NULL); | 200 aura::client::GetDispatcherClient(root_window()), NULL); |
200 run_loop.Run(); | 201 run_loop.Run(); |
201 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); | 202 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); |
202 EXPECT_EQ(1, target.accelerator_pressed_count()); | 203 EXPECT_EQ(1, target.accelerator_pressed_count()); |
203 } | 204 } |
204 | 205 |
205 } // namespace test | 206 } // namespace test |
206 } // namespace wm | 207 } // namespace wm |
OLD | NEW |