| 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 "ash/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller.h" |
| 6 #include "ash/session_state_delegate.h" | 6 #include "ash/session_state_delegate.h" |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/event_types.h" | 11 #include "base/event_types.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "ui/aura/test/test_windows.h" | 13 #include "ui/aura/test/test_windows.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
| 16 #include "ui/base/accelerators/accelerator.h" | 16 #include "ui/base/accelerators/accelerator.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" |
| 20 #include "ui/events/platform/platform_event_source.h" |
| 21 #include "ui/events/platform/scoped_event_dispatcher.h" |
| 19 #include "ui/wm/public/dispatcher_client.h" | 22 #include "ui/wm/public/dispatcher_client.h" |
| 20 | 23 |
| 21 #if defined(USE_X11) | 24 #if defined(USE_X11) |
| 22 #include <X11/Xlib.h> | 25 #include <X11/Xlib.h> |
| 23 #include "ui/events/test/events_test_utils_x11.h" | 26 #include "ui/events/test/events_test_utils_x11.h" |
| 24 #endif // USE_X11 | 27 #endif // USE_X11 |
| 25 | 28 |
| 26 namespace ash { | 29 namespace ash { |
| 27 namespace test { | 30 namespace test { |
| 28 | 31 |
| 29 namespace { | 32 namespace { |
| 30 | 33 |
| 31 class MockDispatcher : public base::MessagePumpDispatcher { | 34 class MockDispatcher : public ui::PlatformEventDispatcher { |
| 32 public: | 35 public: |
| 33 MockDispatcher() : num_key_events_dispatched_(0) { | 36 MockDispatcher() : num_key_events_dispatched_(0) { |
| 34 } | 37 } |
| 35 | 38 |
| 36 int num_key_events_dispatched() { return num_key_events_dispatched_; } | 39 int num_key_events_dispatched() { return num_key_events_dispatched_; } |
| 37 | 40 |
| 38 virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE { | 41 private: |
| 42 // ui::PlatformEventDispatcher: |
| 43 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
| 44 return true; |
| 45 } |
| 46 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
| 39 if (ui::EventTypeFromNative(event) == ui::ET_KEY_RELEASED) | 47 if (ui::EventTypeFromNative(event) == ui::ET_KEY_RELEASED) |
| 40 num_key_events_dispatched_++; | 48 num_key_events_dispatched_++; |
| 41 return POST_DISPATCH_NONE; | 49 return ui::POST_DISPATCH_NONE; |
| 42 } | 50 } |
| 43 | 51 |
| 44 private: | |
| 45 int num_key_events_dispatched_; | 52 int num_key_events_dispatched_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(MockDispatcher); |
| 46 }; | 55 }; |
| 47 | 56 |
| 48 class TestTarget : public ui::AcceleratorTarget { | 57 class TestTarget : public ui::AcceleratorTarget { |
| 49 public: | 58 public: |
| 50 TestTarget() : accelerator_pressed_count_(0) { | 59 TestTarget() : accelerator_pressed_count_(0) { |
| 51 } | 60 } |
| 52 virtual ~TestTarget() { | 61 virtual ~TestTarget() { |
| 53 } | 62 } |
| 54 | 63 |
| 55 int accelerator_pressed_count() const { | 64 int accelerator_pressed_count() const { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 113 |
| 105 scoped_ptr<aura::Window> mock_lock_container( | 114 scoped_ptr<aura::Window> mock_lock_container( |
| 106 CreateTestWindowInShellWithId(0)); | 115 CreateTestWindowInShellWithId(0)); |
| 107 aura::test::CreateTestWindowWithId(1, mock_lock_container.get()); | 116 aura::test::CreateTestWindowWithId(1, mock_lock_container.get()); |
| 108 scoped_ptr<aura::Window> associated_window(CreateTestWindowInShellWithId(2)); | 117 scoped_ptr<aura::Window> associated_window(CreateTestWindowInShellWithId(2)); |
| 109 EXPECT_TRUE(aura::test::WindowIsAbove(associated_window.get(), | 118 EXPECT_TRUE(aura::test::WindowIsAbove(associated_window.get(), |
| 110 mock_lock_container.get())); | 119 mock_lock_container.get())); |
| 111 | 120 |
| 112 DispatchKeyReleaseA(); | 121 DispatchKeyReleaseA(); |
| 113 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); | 122 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); |
| 114 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | 123 scoped_ptr<ui::ScopedEventDispatcher> override_dispatcher = |
| 115 &inner_dispatcher); | 124 ui::PlatformEventSource::GetInstance()->OverrideDispatcher( |
| 125 &inner_dispatcher); |
| 126 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher(NULL); |
| 116 EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched()); | 127 EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched()); |
| 117 } | 128 } |
| 118 | 129 |
| 119 // Test that the nested dispatcher handles accelerators. | 130 // Test that the nested dispatcher handles accelerators. |
| 120 TEST_F(NestedDispatcherTest, AcceleratorsHandled) { | 131 TEST_F(NestedDispatcherTest, AcceleratorsHandled) { |
| 121 MockDispatcher inner_dispatcher; | 132 MockDispatcher inner_dispatcher; |
| 122 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); | 133 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); |
| 123 | 134 |
| 124 ui::Accelerator accelerator(ui::VKEY_A, ui::EF_NONE); | 135 ui::Accelerator accelerator(ui::VKEY_A, ui::EF_NONE); |
| 125 accelerator.set_type(ui::ET_KEY_RELEASED); | 136 accelerator.set_type(ui::ET_KEY_RELEASED); |
| 126 TestTarget target; | 137 TestTarget target; |
| 127 Shell::GetInstance()->accelerator_controller()->Register(accelerator, | 138 Shell::GetInstance()->accelerator_controller()->Register(accelerator, |
| 128 &target); | 139 &target); |
| 129 | 140 |
| 130 DispatchKeyReleaseA(); | 141 DispatchKeyReleaseA(); |
| 131 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | 142 scoped_ptr<ui::ScopedEventDispatcher> override_dispatcher = |
| 132 &inner_dispatcher); | 143 ui::PlatformEventSource::GetInstance()->OverrideDispatcher( |
| 144 &inner_dispatcher); |
| 145 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher(NULL); |
| 133 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); | 146 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); |
| 134 EXPECT_EQ(1, target.accelerator_pressed_count()); | 147 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 135 } | 148 } |
| 136 | 149 |
| 137 } // namespace test | 150 } // namespace test |
| 138 } // namespace ash | 151 } // namespace ash |
| OLD | NEW |