Chromium Code Reviews| Index: ash/accelerators/nested_dispatcher_controller_unittest.cc |
| diff --git a/ash/accelerators/nested_dispatcher_controller_unittest.cc b/ash/accelerators/nested_dispatcher_controller_unittest.cc |
| index 07f37607e8d23dc290ca8c588059c869e1e992bf..be9fcf3503b6d106fae909afa23d775a323f713c 100644 |
| --- a/ash/accelerators/nested_dispatcher_controller_unittest.cc |
| +++ b/ash/accelerators/nested_dispatcher_controller_unittest.cc |
| @@ -2,6 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "ash/accelerators/accelerator_controller.h" |
| #include "ash/shell.h" |
| #include "ash/shell_window_ids.h" |
| #include "ash/test/ash_test_base.h" |
| @@ -12,6 +13,7 @@ |
| #include "ui/aura/root_window.h" |
| #include "ui/aura/test/test_windows.h" |
| #include "ui/aura/window.h" |
| +#include "ui/base/accelerators/accelerator.h" |
| #if defined(USE_X11) |
| #include <X11/Xlib.h> |
| @@ -50,7 +52,31 @@ class MockDispatcher : public MessageLoop::Dispatcher { |
| int num_key_events_dispatched_; |
| }; |
| -void DispatchKeyEvent() { |
| +class TestTarget : public ui::AcceleratorTarget { |
| + public: |
| + TestTarget() : accelerator_pressed_count_(0) {}; |
|
sky
2012/02/29 22:04:18
nit: no ; here and next line.
|
| + virtual ~TestTarget() {}; |
| + |
| + int accelerator_pressed_count() const { |
| + return accelerator_pressed_count_; |
| + } |
| + |
| + // Overridden from ui::AcceleratorTarget: |
| + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE { |
| + accelerator_pressed_count_++; |
| + return true; |
| + } |
| + virtual bool CanHandleAccelerators() const OVERRIDE { |
| + return true; |
| + } |
| + |
| + private: |
| + int accelerator_pressed_count_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestTarget); |
| +}; |
| + |
| +void DispatchKeyReleaseA() { |
| #if defined(OS_WIN) |
| MSG native_event = { NULL, WM_KEYUP, ui::VKEY_A, 0 }; |
| ash::Shell::GetRootWindow()->PostNativeEvent(native_event); |
| @@ -75,7 +101,7 @@ typedef AshTestBase NestedDispatcherTest; |
| TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) { |
| MockDispatcher inner_dispatcher; |
| aura::Window* default_container = Shell::GetInstance()->GetContainer( |
| - ash::internal::kShellWindowId_DefaultContainer); |
| + internal::kShellWindowId_DefaultContainer); |
| scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId( |
| 0, default_container)); |
| scoped_ptr<aura::Window>mock_lock_container( |
| @@ -86,7 +112,7 @@ TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) { |
| associated_window.get())); |
| MessageLoop::current()->PostDelayedTask( |
| FROM_HERE, |
| - base::Bind(&DispatchKeyEvent), |
| + base::Bind(&DispatchKeyReleaseA), |
| base::TimeDelta::FromMilliseconds(100)); |
| aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); |
| aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
| @@ -101,7 +127,7 @@ TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) { |
| MockDispatcher inner_dispatcher; |
| aura::Window* default_container = Shell::GetInstance()->GetContainer( |
| - ash::internal::kShellWindowId_DefaultContainer); |
| + internal::kShellWindowId_DefaultContainer); |
| scoped_ptr<aura::Window>mock_lock_container( |
| aura::test::CreateTestWindowWithId(0, default_container)); |
| mock_lock_container->set_stops_event_propagation(true); |
| @@ -113,7 +139,7 @@ TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) { |
| MessageLoop::current()->PostDelayedTask( |
| FROM_HERE, |
| - base::Bind(&DispatchKeyEvent), |
| + base::Bind(&DispatchKeyReleaseA), |
| base::TimeDelta::FromMilliseconds(100)); |
| aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); |
| aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
| @@ -123,5 +149,28 @@ TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) { |
| EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched()); |
| } |
| +// Test that the nested dispatcher handles accelerators. |
| +TEST_F(NestedDispatcherTest, AcceleratorsHandled) { |
| + MockDispatcher inner_dispatcher; |
| + aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); |
| + |
| + ui::Accelerator accelerator(ui::VKEY_A, false, false, false); |
| + accelerator.set_type(ui::ET_TRANSLATED_KEY_RELEASE); |
| + TestTarget target; |
| + Shell::GetInstance()->accelerator_controller()->Register(accelerator, |
| + &target); |
| + |
| + MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&DispatchKeyReleaseA), |
| + base::TimeDelta::FromMilliseconds(100)); |
|
sky
2012/02/29 22:04:18
Why does this need to delay 100ms? Can't it use Po
pkotwicz
2012/03/01 23:56:37
The delay is arbitrary. However, I beleive the del
oshima
2012/03/02 00:12:21
Sorry I missed this in first review.
On 2012/03/0
|
| + aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
| + &inner_dispatcher, |
| + root_window, |
| + true /* nestable_tasks_allowed */); |
| + EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); |
| + EXPECT_EQ(1, target.accelerator_pressed_count()); |
| +} |
| + |
| } // namespace test |
| } // namespace ash |