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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // |test_client|. The window is setup for processing input. | 43 // |test_client|. The window is setup for processing input. |
44 void CreateSecondaryTree(TestWindowTreeClient** test_client, | 44 void CreateSecondaryTree(TestWindowTreeClient** test_client, |
45 WindowTree** window_tree, | 45 WindowTree** window_tree, |
46 ServerWindow** server_window); | 46 ServerWindow** server_window); |
47 | 47 |
48 void DispatchInputEventToWindow(ServerWindow* target, | 48 void DispatchInputEventToWindow(ServerWindow* target, |
49 const ui::Event& event, | 49 const ui::Event& event, |
50 Accelerator* accelerator); | 50 Accelerator* accelerator); |
51 void OnEventAckTimeout(ClientSpecificId client_id); | 51 void OnEventAckTimeout(ClientSpecificId client_id); |
52 | 52 |
53 // This is the tree associated with the WindowManagerState. | 53 // This is the tree associated with the WindowManagerState. That is, this is |
| 54 // the WindowTree of the WindowManager. |
54 WindowTree* tree() { | 55 WindowTree* tree() { |
55 return window_event_targeting_helper_.window_server()->GetTreeWithId(1); | 56 return window_event_targeting_helper_.window_server()->GetTreeWithId(1); |
56 } | 57 } |
57 // This is *not* the tree associated with the WindowManagerState, use tree() | 58 // This is *not* the tree associated with the WindowManagerState, use tree() |
58 // if you need the window manager tree. | 59 // if you need the window manager tree. |
59 WindowTree* window_tree() { return window_tree_; } | 60 WindowTree* window_tree() { return window_tree_; } |
60 TestWindowTreeClient* window_tree_client() { return window_tree_client_; } | 61 TestWindowTreeClient* window_tree_client() { return window_tree_client_; } |
61 ServerWindow* window() { return window_; } | 62 ServerWindow* window() { return window_; } |
62 TestWindowManager* window_manager() { return &window_manager_; } | 63 TestWindowManager* window_manager() { return &window_manager_; } |
63 TestWindowTreeClient* wm_client() { | 64 TestWindowTreeClient* wm_client() { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); | 229 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
229 | 230 |
230 ASSERT_TRUE(window_manager_state()->event_dispatcher()->AddAccelerator( | 231 ASSERT_TRUE(window_manager_state()->event_dispatcher()->AddAccelerator( |
231 accelerator_id, std::move(matcher))); | 232 accelerator_id, std::move(matcher))); |
232 } | 233 } |
233 TestChangeTracker* tracker = wm_client()->tracker(); | 234 TestChangeTracker* tracker = wm_client()->tracker(); |
234 tracker->changes()->clear(); | 235 tracker->changes()->clear(); |
235 TestChangeTracker* tracker2 = window_tree_client()->tracker(); | 236 TestChangeTracker* tracker2 = window_tree_client()->tracker(); |
236 tracker2->changes()->clear(); | 237 tracker2->changes()->clear(); |
237 | 238 |
238 // Send an ensure only the pre accelerator is called. | 239 // Send and ensure only the pre accelerator is called. |
239 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 240 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
240 window_manager_state()->ProcessEvent(key, 0); | 241 window_manager_state()->ProcessEvent(key, 0); |
241 EXPECT_TRUE(window_manager()->on_accelerator_called()); | 242 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
242 EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id()); | 243 EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id()); |
243 EXPECT_TRUE(tracker->changes()->empty()); | 244 EXPECT_TRUE(tracker->changes()->empty()); |
244 EXPECT_TRUE(tracker2->changes()->empty()); | 245 EXPECT_TRUE(tracker2->changes()->empty()); |
245 | 246 |
246 // Ack the accelerator, saying we consumed it. | 247 // Ack the accelerator, saying we consumed it. |
247 WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::HANDLED); | 248 WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::HANDLED); |
248 // Nothing should change. | 249 // Nothing should change. |
249 EXPECT_TRUE(tracker->changes()->empty()); | 250 EXPECT_TRUE(tracker->changes()->empty()); |
250 EXPECT_TRUE(tracker2->changes()->empty()); | 251 EXPECT_TRUE(tracker2->changes()->empty()); |
251 | 252 |
252 window_manager()->ClearAcceleratorCalled(); | 253 window_manager()->ClearAcceleratorCalled(); |
253 | 254 |
254 // Repeat, but respond with UNHANDLED. | 255 // Repeat, but respond with UNHANDLED. |
255 window_manager_state()->ProcessEvent(key, 0); | 256 window_manager_state()->ProcessEvent(key, 0); |
256 EXPECT_TRUE(window_manager()->on_accelerator_called()); | 257 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
257 EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id()); | 258 EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id()); |
258 EXPECT_TRUE(tracker->changes()->empty()); | 259 EXPECT_TRUE(tracker->changes()->empty()); |
259 EXPECT_TRUE(tracker2->changes()->empty()); | 260 EXPECT_TRUE(tracker2->changes()->empty()); |
260 WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::UNHANDLED); | 261 WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::UNHANDLED); |
261 | 262 |
262 EXPECT_TRUE(tracker->changes()->empty()); | 263 EXPECT_TRUE(tracker->changes()->empty()); |
263 // The focused window should get the event. | 264 // The focused window should get the event. |
264 EXPECT_EQ("InputEvent window=0,11 event_action=7", | 265 EXPECT_EQ("InputEvent window=0,11 event_action=7", |
265 SingleChangeToDescription(*tracker2->changes())); | 266 SingleChangeToDescription(*tracker2->changes())); |
266 } | 267 } |
267 | 268 |
| 269 TEST_F(WindowManagerStateTest, AckWithProperties) { |
| 270 // Set up two trees with focus on a child in the second. |
| 271 const ClientWindowId child_window_id(11); |
| 272 window_tree()->NewWindow(child_window_id, ServerWindow::Properties()); |
| 273 ServerWindow* child_window = |
| 274 window_tree()->GetWindowByClientId(child_window_id); |
| 275 window_tree()->AddWindow(FirstRootId(window_tree()), child_window_id); |
| 276 child_window->SetVisible(true); |
| 277 SetCanFocusUp(child_window); |
| 278 tree()->GetDisplay(child_window)->AddActivationParent(child_window->parent()); |
| 279 ASSERT_TRUE(window_tree()->SetFocus(child_window_id)); |
| 280 |
| 281 // Register a pre-accelerator. |
| 282 uint32_t accelerator_id = 11; |
| 283 { |
| 284 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
| 285 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| 286 |
| 287 ASSERT_TRUE(window_manager_state()->event_dispatcher()->AddAccelerator( |
| 288 accelerator_id, std::move(matcher))); |
| 289 } |
| 290 TestChangeTracker* tracker = wm_client()->tracker(); |
| 291 tracker->changes()->clear(); |
| 292 TestChangeTracker* tracker2 = window_tree_client()->tracker(); |
| 293 tracker2->changes()->clear(); |
| 294 |
| 295 // Send and ensure only the pre accelerator is called. |
| 296 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 297 window_manager_state()->ProcessEvent(key, 0); |
| 298 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
| 299 EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id()); |
| 300 EXPECT_TRUE(tracker->changes()->empty()); |
| 301 EXPECT_TRUE(tracker2->changes()->empty()); |
| 302 |
| 303 // Ack the accelerator, with unhandled. |
| 304 std::unordered_map<std::string, std::vector<uint8_t>> event_properties; |
| 305 const std::string property_key = "x"; |
| 306 const std::vector<uint8_t> property_value(2, 0xAB); |
| 307 event_properties[property_key] = property_value; |
| 308 EXPECT_TRUE(tracker->changes()->empty()); |
| 309 EXPECT_TRUE(tracker2->changes()->empty()); |
| 310 WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::UNHANDLED, |
| 311 event_properties); |
| 312 |
| 313 // The focused window should get the event. |
| 314 EXPECT_EQ("InputEvent window=0,11 event_action=7", |
| 315 SingleChangeToDescription(*tracker2->changes())); |
| 316 ASSERT_EQ(1u, tracker2->changes()->size()); |
| 317 EXPECT_EQ(1u, (*tracker2->changes())[0].key_event_properties.size()); |
| 318 EXPECT_EQ(event_properties, (*tracker2->changes())[0].key_event_properties); |
| 319 |
| 320 WindowTreeTestApi(window_tree()).AckLastEvent(mojom::EventResult::HANDLED); |
| 321 tracker2->changes()->clear(); |
| 322 |
| 323 // Send the event again, and ack with no properties. Ensure client gets no |
| 324 // properties. |
| 325 window_manager()->ClearAcceleratorCalled(); |
| 326 window_manager_state()->ProcessEvent(key, 0); |
| 327 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
| 328 EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id()); |
| 329 EXPECT_TRUE(tracker->changes()->empty()); |
| 330 EXPECT_TRUE(tracker2->changes()->empty()); |
| 331 |
| 332 // Ack the accelerator with unhandled. |
| 333 WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::UNHANDLED); |
| 334 |
| 335 // The focused window should get the event. |
| 336 EXPECT_EQ("InputEvent window=0,11 event_action=7", |
| 337 SingleChangeToDescription(*tracker2->changes())); |
| 338 ASSERT_EQ(1u, tracker2->changes()->size()); |
| 339 EXPECT_TRUE((*tracker2->changes())[0].key_event_properties.empty()); |
| 340 } |
| 341 |
268 // Tests that when a client handles an event that post target accelerators are | 342 // Tests that when a client handles an event that post target accelerators are |
269 // not called. | 343 // not called. |
270 TEST_F(WindowManagerStateTest, ClientHandlesEvent) { | 344 TEST_F(WindowManagerStateTest, ClientHandlesEvent) { |
271 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 345 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
272 std::unique_ptr<Accelerator> accelerator = CreateAccelerator(); | 346 std::unique_ptr<Accelerator> accelerator = CreateAccelerator(); |
273 | 347 |
274 ServerWindow* target = window(); | 348 ServerWindow* target = window(); |
275 DispatchInputEventToWindow(target, key, accelerator.get()); | 349 DispatchInputEventToWindow(target, key, accelerator.get()); |
276 TestChangeTracker* tracker = window_tree_client()->tracker(); | 350 TestChangeTracker* tracker = window_tree_client()->tracker(); |
277 ASSERT_EQ(1u, tracker->changes()->size()); | 351 ASSERT_EQ(1u, tracker->changes()->size()); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 base::TimeTicks()); | 657 base::TimeTicks()); |
584 window_manager_state()->ProcessEvent(move, 0); | 658 window_manager_state()->ProcessEvent(move, 0); |
585 // The event isn't over a valid target, which should trigger resetting the | 659 // The event isn't over a valid target, which should trigger resetting the |
586 // cursor to POINTER. | 660 // cursor to POINTER. |
587 EXPECT_EQ(ui::mojom::Cursor::POINTER, display_test_api.last_cursor()); | 661 EXPECT_EQ(ui::mojom::Cursor::POINTER, display_test_api.last_cursor()); |
588 } | 662 } |
589 | 663 |
590 } // namespace test | 664 } // namespace test |
591 } // namespace ws | 665 } // namespace ws |
592 } // namespace ui | 666 } // namespace ui |
OLD | NEW |