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..9308be18a2f83d85264a7242042e86354b51c60d 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,23 @@ class MockDispatcher : public MessageLoop::Dispatcher { |
int num_key_events_dispatched_; |
}; |
-void DispatchKeyEvent() { |
+class TestTarget : public ui::AcceleratorTarget { |
+ public: |
+ TestTarget() { |
+ } |
+ |
+ // Overridden from ui::AcceleratorTarget: |
+ virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE { |
+ return true; |
+ } |
+ virtual bool CanHandleAccelerators() const OVERRIDE { |
+ return true; |
+ } |
+ |
oshima
2012/02/29 19:28:42
private:
|
+ 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 +93,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 +104,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 +119,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 +131,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 +141,27 @@ 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)); |
+ aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
+ &inner_dispatcher, |
+ root_window, |
+ true /* nestable_tasks_allowed */); |
+ EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); |
oshima
2012/02/29 19:28:42
please check if the accelerator is pressed/handled
|
+} |
+ |
} // namespace test |
} // namespace ash |