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" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 MSG native_event_down = { NULL, WM_KEYDOWN, ui::VKEY_A, 0 }; | 81 MSG native_event_down = { NULL, WM_KEYDOWN, ui::VKEY_A, 0 }; |
82 ash::Shell::GetPrimaryRootWindow()->PostNativeEvent(native_event_down); | 82 ash::Shell::GetPrimaryRootWindow()->PostNativeEvent(native_event_down); |
83 MSG native_event_up = { NULL, WM_KEYUP, ui::VKEY_A, 0 }; | 83 MSG native_event_up = { NULL, WM_KEYUP, ui::VKEY_A, 0 }; |
84 ash::Shell::GetPrimaryRootWindow()->PostNativeEvent(native_event_up); | 84 ash::Shell::GetPrimaryRootWindow()->PostNativeEvent(native_event_up); |
85 #elif defined(USE_X11) | 85 #elif defined(USE_X11) |
86 XEvent native_event; | 86 XEvent native_event; |
87 ui::InitXKeyEventForTesting(ui::ET_KEY_PRESSED, | 87 ui::InitXKeyEventForTesting(ui::ET_KEY_PRESSED, |
88 ui::VKEY_A, | 88 ui::VKEY_A, |
89 0, | 89 0, |
90 &native_event); | 90 &native_event); |
91 ash::Shell::GetPrimaryRootWindow()->PostNativeEvent(&native_event); | 91 aura::WindowEventDispatcher* dispatcher = |
| 92 ash::Shell::GetPrimaryRootWindow()->GetDispatcher(); |
| 93 dispatcher->PostNativeEvent(&native_event); |
92 ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED, | 94 ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED, |
93 ui::VKEY_A, | 95 ui::VKEY_A, |
94 0, | 96 0, |
95 &native_event); | 97 &native_event); |
96 ash::Shell::GetPrimaryRootWindow()->PostNativeEvent(&native_event); | 98 dispatcher->PostNativeEvent(&native_event); |
97 #endif | 99 #endif |
98 | 100 |
99 // Send noop event to signal dispatcher to exit. | 101 // Send noop event to signal dispatcher to exit. |
100 ash::Shell::GetPrimaryRootWindow()->PostNativeEvent(ui::CreateNoopEvent()); | 102 dispatcher->PostNativeEvent(ui::CreateNoopEvent()); |
101 } | 103 } |
102 | 104 |
103 } // namespace | 105 } // namespace |
104 | 106 |
105 typedef AshTestBase NestedDispatcherTest; | 107 typedef AshTestBase NestedDispatcherTest; |
106 | 108 |
107 // Aura window below lock screen in z order. | 109 // Aura window below lock screen in z order. |
108 TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) { | 110 TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) { |
109 MockDispatcher inner_dispatcher; | 111 MockDispatcher inner_dispatcher; |
110 scoped_ptr<aura::Window> associated_window(CreateTestWindowInShellWithId(0)); | 112 scoped_ptr<aura::Window> associated_window(CreateTestWindowInShellWithId(0)); |
111 | 113 |
112 Shell::GetInstance()->session_state_delegate()->LockScreen(); | 114 Shell::GetInstance()->session_state_delegate()->LockScreen(); |
113 DispatchKeyReleaseA(); | 115 DispatchKeyReleaseA(); |
114 aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow(); | 116 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); |
115 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | 117 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
116 &inner_dispatcher, | 118 &inner_dispatcher, |
117 associated_window.get(), | 119 associated_window.get(), |
118 true /* nestable_tasks_allowed */); | 120 true /* nestable_tasks_allowed */); |
119 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); | 121 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); |
120 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); | 122 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); |
121 } | 123 } |
122 | 124 |
123 // Aura window above lock screen in z order. | 125 // Aura window above lock screen in z order. |
124 TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) { | 126 TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) { |
125 MockDispatcher inner_dispatcher; | 127 MockDispatcher inner_dispatcher; |
126 | 128 |
127 scoped_ptr<aura::Window>mock_lock_container( | 129 scoped_ptr<aura::Window>mock_lock_container( |
128 CreateTestWindowInShellWithId(0)); | 130 CreateTestWindowInShellWithId(0)); |
129 aura::test::CreateTestWindowWithId(0, mock_lock_container.get()); | 131 aura::test::CreateTestWindowWithId(0, mock_lock_container.get()); |
130 scoped_ptr<aura::Window> associated_window(CreateTestWindowInShellWithId(0)); | 132 scoped_ptr<aura::Window> associated_window(CreateTestWindowInShellWithId(0)); |
131 EXPECT_TRUE(aura::test::WindowIsAbove(associated_window.get(), | 133 EXPECT_TRUE(aura::test::WindowIsAbove(associated_window.get(), |
132 mock_lock_container.get())); | 134 mock_lock_container.get())); |
133 | 135 |
134 DispatchKeyReleaseA(); | 136 DispatchKeyReleaseA(); |
135 aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow(); | 137 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); |
136 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | 138 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
137 &inner_dispatcher, | 139 &inner_dispatcher, |
138 associated_window.get(), | 140 associated_window.get(), |
139 true /* nestable_tasks_allowed */); | 141 true /* nestable_tasks_allowed */); |
140 EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched()); | 142 EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched()); |
141 } | 143 } |
142 | 144 |
143 // Test that the nested dispatcher handles accelerators. | 145 // Test that the nested dispatcher handles accelerators. |
144 TEST_F(NestedDispatcherTest, AcceleratorsHandled) { | 146 TEST_F(NestedDispatcherTest, AcceleratorsHandled) { |
145 MockDispatcher inner_dispatcher; | 147 MockDispatcher inner_dispatcher; |
146 aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow(); | 148 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); |
147 | 149 |
148 ui::Accelerator accelerator(ui::VKEY_A, ui::EF_NONE); | 150 ui::Accelerator accelerator(ui::VKEY_A, ui::EF_NONE); |
149 accelerator.set_type(ui::ET_KEY_RELEASED); | 151 accelerator.set_type(ui::ET_KEY_RELEASED); |
150 TestTarget target; | 152 TestTarget target; |
151 Shell::GetInstance()->accelerator_controller()->Register(accelerator, | 153 Shell::GetInstance()->accelerator_controller()->Register(accelerator, |
152 &target); | 154 &target); |
153 | 155 |
154 DispatchKeyReleaseA(); | 156 DispatchKeyReleaseA(); |
155 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | 157 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
156 &inner_dispatcher, | 158 &inner_dispatcher, |
157 root_window, | 159 root_window, |
158 true /* nestable_tasks_allowed */); | 160 true /* nestable_tasks_allowed */); |
159 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); | 161 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); |
160 EXPECT_EQ(1, target.accelerator_pressed_count()); | 162 EXPECT_EQ(1, target.accelerator_pressed_count()); |
161 } | 163 } |
162 | 164 |
163 } // namespace test | 165 } // namespace test |
164 } // namespace ash | 166 } // namespace ash |
OLD | NEW |