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/shell.h" | 6 #include "ash/shell.h" |
6 #include "ash/shell_window_ids.h" | 7 #include "ash/shell_window_ids.h" |
7 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
8 #include "base/bind.h" | 9 #include "base/bind.h" |
9 #include "base/event_types.h" | 10 #include "base/event_types.h" |
10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
11 #include "ui/aura/client/dispatcher_client.h" | 12 #include "ui/aura/client/dispatcher_client.h" |
12 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
13 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/base/accelerators/accelerator.h" | |
15 | 17 |
16 #if defined(USE_X11) | 18 #if defined(USE_X11) |
17 #include <X11/Xlib.h> | 19 #include <X11/Xlib.h> |
18 #include "ui/base/x/x11_util.h" | 20 #include "ui/base/x/x11_util.h" |
19 #endif // USE_X11 | 21 #endif // USE_X11 |
20 | 22 |
21 namespace ash { | 23 namespace ash { |
22 namespace test { | 24 namespace test { |
23 | 25 |
24 namespace { | 26 namespace { |
(...skipping 18 matching lines...) Expand all Loading... | |
43 num_key_events_dispatched_++; | 45 num_key_events_dispatched_++; |
44 return ui::IsNoopEvent(xev) ? MessagePumpDispatcher::EVENT_QUIT : | 46 return ui::IsNoopEvent(xev) ? MessagePumpDispatcher::EVENT_QUIT : |
45 MessagePumpDispatcher::EVENT_IGNORED; | 47 MessagePumpDispatcher::EVENT_IGNORED; |
46 } | 48 } |
47 #endif | 49 #endif |
48 | 50 |
49 private: | 51 private: |
50 int num_key_events_dispatched_; | 52 int num_key_events_dispatched_; |
51 }; | 53 }; |
52 | 54 |
53 void DispatchKeyEvent() { | 55 class TestTarget : public ui::AcceleratorTarget { |
56 public: | |
57 TestTarget() { | |
58 } | |
59 | |
60 // Overridden from ui::AcceleratorTarget: | |
61 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE { | |
62 return true; | |
63 } | |
64 virtual bool CanHandleAccelerators() const OVERRIDE { | |
65 return true; | |
66 } | |
67 | |
oshima
2012/02/29 19:28:42
private:
| |
68 DISALLOW_COPY_AND_ASSIGN(TestTarget); | |
69 }; | |
70 | |
71 void DispatchKeyReleaseA() { | |
54 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
55 MSG native_event = { NULL, WM_KEYUP, ui::VKEY_A, 0 }; | 73 MSG native_event = { NULL, WM_KEYUP, ui::VKEY_A, 0 }; |
56 ash::Shell::GetRootWindow()->PostNativeEvent(native_event); | 74 ash::Shell::GetRootWindow()->PostNativeEvent(native_event); |
57 #elif defined(USE_X11) | 75 #elif defined(USE_X11) |
58 XEvent native_event; | 76 XEvent native_event; |
59 ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED, | 77 ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED, |
60 ui::VKEY_A, | 78 ui::VKEY_A, |
61 0, | 79 0, |
62 &native_event); | 80 &native_event); |
63 ash::Shell::GetRootWindow()->PostNativeEvent(&native_event); | 81 ash::Shell::GetRootWindow()->PostNativeEvent(&native_event); |
64 #endif | 82 #endif |
65 | 83 |
66 // Send noop event to signal dispatcher to exit. | 84 // Send noop event to signal dispatcher to exit. |
67 ash::Shell::GetRootWindow()->PostNativeEvent(ui::CreateNoopEvent()); | 85 ash::Shell::GetRootWindow()->PostNativeEvent(ui::CreateNoopEvent()); |
68 } | 86 } |
69 | 87 |
70 } // namespace | 88 } // namespace |
71 | 89 |
72 typedef AshTestBase NestedDispatcherTest; | 90 typedef AshTestBase NestedDispatcherTest; |
73 | 91 |
74 // Aura window below lock screen in z order. | 92 // Aura window below lock screen in z order. |
75 TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) { | 93 TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) { |
76 MockDispatcher inner_dispatcher; | 94 MockDispatcher inner_dispatcher; |
77 aura::Window* default_container = Shell::GetInstance()->GetContainer( | 95 aura::Window* default_container = Shell::GetInstance()->GetContainer( |
78 ash::internal::kShellWindowId_DefaultContainer); | 96 internal::kShellWindowId_DefaultContainer); |
79 scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId( | 97 scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId( |
80 0, default_container)); | 98 0, default_container)); |
81 scoped_ptr<aura::Window>mock_lock_container( | 99 scoped_ptr<aura::Window>mock_lock_container( |
82 aura::test::CreateTestWindowWithId(0, default_container)); | 100 aura::test::CreateTestWindowWithId(0, default_container)); |
83 mock_lock_container->set_stops_event_propagation(true); | 101 mock_lock_container->set_stops_event_propagation(true); |
84 aura::test::CreateTestWindowWithId(0, mock_lock_container.get()); | 102 aura::test::CreateTestWindowWithId(0, mock_lock_container.get()); |
85 EXPECT_TRUE(aura::test::WindowIsAbove(mock_lock_container.get(), | 103 EXPECT_TRUE(aura::test::WindowIsAbove(mock_lock_container.get(), |
86 associated_window.get())); | 104 associated_window.get())); |
87 MessageLoop::current()->PostDelayedTask( | 105 MessageLoop::current()->PostDelayedTask( |
88 FROM_HERE, | 106 FROM_HERE, |
89 base::Bind(&DispatchKeyEvent), | 107 base::Bind(&DispatchKeyReleaseA), |
90 base::TimeDelta::FromMilliseconds(100)); | 108 base::TimeDelta::FromMilliseconds(100)); |
91 aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); | 109 aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); |
92 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | 110 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
93 &inner_dispatcher, | 111 &inner_dispatcher, |
94 associated_window.get(), | 112 associated_window.get(), |
95 true /* nestable_tasks_allowed */); | 113 true /* nestable_tasks_allowed */); |
96 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); | 114 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); |
97 } | 115 } |
98 | 116 |
99 // Aura window above lock screen in z order. | 117 // Aura window above lock screen in z order. |
100 TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) { | 118 TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) { |
101 MockDispatcher inner_dispatcher; | 119 MockDispatcher inner_dispatcher; |
102 | 120 |
103 aura::Window* default_container = Shell::GetInstance()->GetContainer( | 121 aura::Window* default_container = Shell::GetInstance()->GetContainer( |
104 ash::internal::kShellWindowId_DefaultContainer); | 122 internal::kShellWindowId_DefaultContainer); |
105 scoped_ptr<aura::Window>mock_lock_container( | 123 scoped_ptr<aura::Window>mock_lock_container( |
106 aura::test::CreateTestWindowWithId(0, default_container)); | 124 aura::test::CreateTestWindowWithId(0, default_container)); |
107 mock_lock_container->set_stops_event_propagation(true); | 125 mock_lock_container->set_stops_event_propagation(true); |
108 aura::test::CreateTestWindowWithId(0, mock_lock_container.get()); | 126 aura::test::CreateTestWindowWithId(0, mock_lock_container.get()); |
109 scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId( | 127 scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId( |
110 0, default_container)); | 128 0, default_container)); |
111 EXPECT_TRUE(aura::test::WindowIsAbove(associated_window.get(), | 129 EXPECT_TRUE(aura::test::WindowIsAbove(associated_window.get(), |
112 mock_lock_container.get())); | 130 mock_lock_container.get())); |
113 | 131 |
114 MessageLoop::current()->PostDelayedTask( | 132 MessageLoop::current()->PostDelayedTask( |
115 FROM_HERE, | 133 FROM_HERE, |
116 base::Bind(&DispatchKeyEvent), | 134 base::Bind(&DispatchKeyReleaseA), |
117 base::TimeDelta::FromMilliseconds(100)); | 135 base::TimeDelta::FromMilliseconds(100)); |
118 aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); | 136 aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); |
119 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | 137 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
120 &inner_dispatcher, | 138 &inner_dispatcher, |
121 associated_window.get(), | 139 associated_window.get(), |
122 true /* nestable_tasks_allowed */); | 140 true /* nestable_tasks_allowed */); |
123 EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched()); | 141 EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched()); |
124 } | 142 } |
125 | 143 |
144 // Test that the nested dispatcher handles accelerators. | |
145 TEST_F(NestedDispatcherTest, AcceleratorsHandled) { | |
146 MockDispatcher inner_dispatcher; | |
147 aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); | |
148 | |
149 ui::Accelerator accelerator(ui::VKEY_A, false, false, false); | |
150 accelerator.set_type(ui::ET_TRANSLATED_KEY_RELEASE); | |
151 TestTarget target; | |
152 Shell::GetInstance()->accelerator_controller()->Register(accelerator, | |
153 &target); | |
154 | |
155 MessageLoop::current()->PostDelayedTask( | |
156 FROM_HERE, | |
157 base::Bind(&DispatchKeyReleaseA), | |
158 base::TimeDelta::FromMilliseconds(100)); | |
159 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | |
160 &inner_dispatcher, | |
161 root_window, | |
162 true /* nestable_tasks_allowed */); | |
163 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); | |
oshima
2012/02/29 19:28:42
please check if the accelerator is pressed/handled
| |
164 } | |
165 | |
126 } // namespace test | 166 } // namespace test |
127 } // namespace ash | 167 } // namespace ash |
OLD | NEW |