| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/ws/window_manager_state.h" | 5 #include "services/ui/ws/window_manager_state.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 // |test_client|. The window is setup for processing input. | 46 // |test_client|. The window is setup for processing input. |
| 47 void CreateSecondaryTree(TestWindowTreeClient** test_client, | 47 void CreateSecondaryTree(TestWindowTreeClient** test_client, |
| 48 WindowTree** window_tree, | 48 WindowTree** window_tree, |
| 49 ServerWindow** server_window); | 49 ServerWindow** server_window); |
| 50 | 50 |
| 51 void DispatchInputEventToWindow(ServerWindow* target, | 51 void DispatchInputEventToWindow(ServerWindow* target, |
| 52 const ui::Event& event, | 52 const ui::Event& event, |
| 53 Accelerator* accelerator); | 53 Accelerator* accelerator); |
| 54 void OnEventAckTimeout(ClientSpecificId client_id); | 54 void OnEventAckTimeout(ClientSpecificId client_id); |
| 55 | 55 |
| 56 // This is the tree associated with the WindowManagerState. |
| 56 WindowTree* tree() { | 57 WindowTree* tree() { |
| 57 return window_event_targeting_helper_.window_server()->GetTreeWithId(1); | 58 return window_event_targeting_helper_.window_server()->GetTreeWithId(1); |
| 58 } | 59 } |
| 60 // This is *not* the tree associated with the WindowManagerState, use tree() |
| 61 // if you need the window manager tree. |
| 59 WindowTree* window_tree() { return window_tree_; } | 62 WindowTree* window_tree() { return window_tree_; } |
| 60 TestWindowTreeClient* window_tree_client() { return window_tree_client_; } | 63 TestWindowTreeClient* window_tree_client() { return window_tree_client_; } |
| 61 ServerWindow* window() { return window_; } | 64 ServerWindow* window() { return window_; } |
| 62 TestWindowManager* window_manager() { return &window_manager_; } | 65 TestWindowManager* window_manager() { return &window_manager_; } |
| 63 TestWindowTreeClient* wm_client() { | 66 TestWindowTreeClient* wm_client() { |
| 64 return window_event_targeting_helper_.wm_client(); | 67 return window_event_targeting_helper_.wm_client(); |
| 65 } | 68 } |
| 66 TestWindowTreeClient* last_tree_client() { | 69 TestWindowTreeClient* last_tree_client() { |
| 67 return window_event_targeting_helper_.last_window_tree_client(); | 70 return window_event_targeting_helper_.last_window_tree_client(); |
| 68 } | 71 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 window_tree_ = window_event_targeting_helper_.last_binding()->tree(); | 157 window_tree_ = window_event_targeting_helper_.last_binding()->tree(); |
| 155 window_tree_client_ = | 158 window_tree_client_ = |
| 156 window_event_targeting_helper_.last_window_tree_client(); | 159 window_event_targeting_helper_.last_window_tree_client(); |
| 157 DCHECK(window_tree_->HasRoot(window_)); | 160 DCHECK(window_tree_->HasRoot(window_)); |
| 158 | 161 |
| 159 WindowTreeTestApi(tree()).set_window_manager_internal(&window_manager_); | 162 WindowTreeTestApi(tree()).set_window_manager_internal(&window_manager_); |
| 160 wm_client()->tracker()->changes()->clear(); | 163 wm_client()->tracker()->changes()->clear(); |
| 161 window_tree_client_->tracker()->changes()->clear(); | 164 window_tree_client_->tracker()->changes()->clear(); |
| 162 } | 165 } |
| 163 | 166 |
| 167 void SetCanFocusUp(ServerWindow* window) { |
| 168 while (window) { |
| 169 window->set_can_focus(true); |
| 170 window = window->parent(); |
| 171 } |
| 172 } |
| 173 |
| 164 // Tests that when an event is dispatched with no accelerator, that post target | 174 // Tests that when an event is dispatched with no accelerator, that post target |
| 165 // accelerator is not triggered. | 175 // accelerator is not triggered. |
| 166 TEST_F(WindowManagerStateTest, NullAccelerator) { | 176 TEST_F(WindowManagerStateTest, NullAccelerator) { |
| 167 WindowManagerState* state = window_manager_state(); | 177 WindowManagerState* state = window_manager_state(); |
| 168 EXPECT_TRUE(state); | 178 EXPECT_TRUE(state); |
| 169 | 179 |
| 170 ServerWindow* target = window(); | 180 ServerWindow* target = window(); |
| 171 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 181 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 172 DispatchInputEventToWindow(target, key, nullptr); | 182 DispatchInputEventToWindow(target, key, nullptr); |
| 173 WindowTree* target_tree = window_tree(); | 183 WindowTree* target_tree = window_tree(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 191 TestChangeTracker* tracker = window_tree_client()->tracker(); | 201 TestChangeTracker* tracker = window_tree_client()->tracker(); |
| 192 ASSERT_EQ(1u, tracker->changes()->size()); | 202 ASSERT_EQ(1u, tracker->changes()->size()); |
| 193 EXPECT_EQ("InputEvent window=1,1 event_action=7", | 203 EXPECT_EQ("InputEvent window=1,1 event_action=7", |
| 194 ChangesToDescription1(*tracker->changes())[0]); | 204 ChangesToDescription1(*tracker->changes())[0]); |
| 195 | 205 |
| 196 WindowTreeTestApi(window_tree()).AckOldestEvent(); | 206 WindowTreeTestApi(window_tree()).AckOldestEvent(); |
| 197 EXPECT_TRUE(window_manager()->on_accelerator_called()); | 207 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
| 198 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); | 208 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); |
| 199 } | 209 } |
| 200 | 210 |
| 211 // Tests that if a pre target accelerator consumes the event no other processing |
| 212 // is done. |
| 213 TEST_F(WindowManagerStateTest, PreTargetConsumed) { |
| 214 // Set up two trees with focus on a child in the second. |
| 215 const ClientWindowId child_window_id(11); |
| 216 window_tree()->NewWindow(child_window_id, ServerWindow::Properties()); |
| 217 ServerWindow* child_window = |
| 218 window_tree()->GetWindowByClientId(child_window_id); |
| 219 window_tree()->AddWindow(FirstRootId(window_tree()), child_window_id); |
| 220 child_window->SetVisible(true); |
| 221 SetCanFocusUp(child_window); |
| 222 tree()->GetDisplay(child_window)->AddActivationParent(child_window->parent()); |
| 223 ASSERT_TRUE(window_tree()->SetFocus(child_window_id)); |
| 224 |
| 225 // Register a pre-accelerator. |
| 226 uint32_t accelerator_id = 11; |
| 227 { |
| 228 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
| 229 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| 230 ASSERT_TRUE(window_manager_state()->event_dispatcher()->AddAccelerator( |
| 231 accelerator_id, std::move(matcher))); |
| 232 } |
| 233 TestChangeTracker* tracker = wm_client()->tracker(); |
| 234 tracker->changes()->clear(); |
| 235 TestChangeTracker* tracker2 = window_tree_client()->tracker(); |
| 236 tracker2->changes()->clear(); |
| 237 |
| 238 // Send an ensure only the pre accelerator is called. |
| 239 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 240 window_manager_state()->ProcessEvent(key); |
| 241 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
| 242 EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id()); |
| 243 EXPECT_TRUE(tracker->changes()->empty()); |
| 244 EXPECT_TRUE(tracker2->changes()->empty()); |
| 245 |
| 246 // Ack the accelerator, saying we consumed it. |
| 247 WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::HANDLED); |
| 248 // Nothing should change. |
| 249 EXPECT_TRUE(tracker->changes()->empty()); |
| 250 EXPECT_TRUE(tracker2->changes()->empty()); |
| 251 |
| 252 window_manager()->ClearAcceleratorCalled(); |
| 253 |
| 254 // Repeat, but respond with UNHANDLED. |
| 255 window_manager_state()->ProcessEvent(key); |
| 256 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
| 257 EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id()); |
| 258 EXPECT_TRUE(tracker->changes()->empty()); |
| 259 EXPECT_TRUE(tracker2->changes()->empty()); |
| 260 WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::UNHANDLED); |
| 261 |
| 262 EXPECT_TRUE(tracker->changes()->empty()); |
| 263 // The focused window should get the event. |
| 264 EXPECT_EQ("InputEvent window=0,11 event_action=7", |
| 265 SingleChangeToDescription(*tracker2->changes())); |
| 266 } |
| 267 |
| 201 // Tests that when a client handles an event that post target accelerators are | 268 // Tests that when a client handles an event that post target accelerators are |
| 202 // not called. | 269 // not called. |
| 203 TEST_F(WindowManagerStateTest, ClientHandlesEvent) { | 270 TEST_F(WindowManagerStateTest, ClientHandlesEvent) { |
| 204 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 271 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 205 std::unique_ptr<Accelerator> accelerator = CreateAccelerator(); | 272 std::unique_ptr<Accelerator> accelerator = CreateAccelerator(); |
| 206 | 273 |
| 207 ServerWindow* target = window(); | 274 ServerWindow* target = window(); |
| 208 DispatchInputEventToWindow(target, key, accelerator.get()); | 275 DispatchInputEventToWindow(target, key, accelerator.get()); |
| 209 TestChangeTracker* tracker = window_tree_client()->tracker(); | 276 TestChangeTracker* tracker = window_tree_client()->tracker(); |
| 210 ASSERT_EQ(1u, tracker->changes()->size()); | 277 ASSERT_EQ(1u, tracker->changes()->size()); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, | 477 EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, |
| 411 (*embedder_client->tracker()->changes())[0].type); | 478 (*embedder_client->tracker()->changes())[0].type); |
| 412 WindowTreeTestApi(embedder_tree) | 479 WindowTreeTestApi(embedder_tree) |
| 413 .AckLastEvent(mojom::EventResult::UNHANDLED); | 480 .AckLastEvent(mojom::EventResult::UNHANDLED); |
| 414 } | 481 } |
| 415 } | 482 } |
| 416 | 483 |
| 417 } // namespace test | 484 } // namespace test |
| 418 } // namespace ws | 485 } // namespace ws |
| 419 } // namespace ui | 486 } // namespace ui |
| OLD | NEW |