| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_tree.h" | 5 #include "services/ui/ws/window_tree.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 83 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 84 ui::EF_LEFT_MOUSE_BUTTON)); | 84 ui::EF_LEFT_MOUSE_BUTTON)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 ServerWindow* GetCaptureWindow(Display* display) { | 87 ServerWindow* GetCaptureWindow(Display* display) { |
| 88 return display->GetActiveWindowManagerDisplayRoot() | 88 return display->GetActiveWindowManagerDisplayRoot() |
| 89 ->window_manager_state() | 89 ->window_manager_state() |
| 90 ->capture_window(); | 90 ->capture_window(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 mojom::EventMatcherPtr CreateEventMatcher(ui::mojom::EventType type) { | |
| 94 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); | |
| 95 matcher->type_matcher = mojom::EventTypeMatcher::New(); | |
| 96 matcher->type_matcher->type = type; | |
| 97 return matcher; | |
| 98 } | |
| 99 | |
| 100 class TestMoveLoopWindowManager : public TestWindowManager { | 93 class TestMoveLoopWindowManager : public TestWindowManager { |
| 101 public: | 94 public: |
| 102 TestMoveLoopWindowManager(WindowTree* tree) : tree_(tree) {} | 95 TestMoveLoopWindowManager(WindowTree* tree) : tree_(tree) {} |
| 103 ~TestMoveLoopWindowManager() override {} | 96 ~TestMoveLoopWindowManager() override {} |
| 104 | 97 |
| 105 void WmPerformMoveLoop(uint32_t change_id, | 98 void WmPerformMoveLoop(uint32_t change_id, |
| 106 uint32_t window_id, | 99 uint32_t window_id, |
| 107 mojom::MoveLoopSource source, | 100 mojom::MoveLoopSource source, |
| 108 const gfx::Point& cursor_location) override { | 101 const gfx::Point& cursor_location) override { |
| 109 static_cast<mojom::WindowManagerClient*>(tree_)->WmResponse( | 102 static_cast<mojom::WindowManagerClient*>(tree_)->WmResponse( |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 295 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 303 EXPECT_EQ("Focused id=2,1", | 296 EXPECT_EQ("Focused id=2,1", |
| 304 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 297 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 305 ASSERT_EQ(2u, embed_client->tracker()->changes()->size()); | 298 ASSERT_EQ(2u, embed_client->tracker()->changes()->size()); |
| 306 EXPECT_EQ("Focused id=2,1", | 299 EXPECT_EQ("Focused id=2,1", |
| 307 ChangesToDescription1(*embed_client->tracker()->changes())[0]); | 300 ChangesToDescription1(*embed_client->tracker()->changes())[0]); |
| 308 EXPECT_EQ("InputEvent window=2,1 event_action=16", | 301 EXPECT_EQ("InputEvent window=2,1 event_action=16", |
| 309 ChangesToDescription1(*embed_client->tracker()->changes())[1]); | 302 ChangesToDescription1(*embed_client->tracker()->changes())[1]); |
| 310 } | 303 } |
| 311 | 304 |
| 312 // Tests that a client can observe events outside its bounds. | 305 // Tests that a client can watch for events outside its bounds. |
| 313 TEST_F(WindowTreeTest, SetEventObserver) { | 306 TEST_F(WindowTreeTest, StartPointerWatcher) { |
| 314 // Create an embedded client. | 307 // Create an embedded client. |
| 315 TestWindowTreeClient* client = nullptr; | 308 TestWindowTreeClient* client = nullptr; |
| 316 WindowTree* tree = nullptr; | 309 WindowTree* tree = nullptr; |
| 317 ServerWindow* window = nullptr; | 310 ServerWindow* window = nullptr; |
| 318 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); | 311 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| 319 | 312 |
| 320 // Create an event outside the bounds of the client. | 313 // Create an event outside the bounds of the client. |
| 321 ui::PointerEvent pointer_down = CreatePointerDownEvent(5, 5); | 314 ui::PointerEvent pointer_down = CreatePointerDownEvent(5, 5); |
| 322 | 315 |
| 323 // Events are not observed before setting an observer. | 316 // Events are not watched before starting a watcher. |
| 324 DispatchEventAndAckImmediately(pointer_down); | 317 DispatchEventAndAckImmediately(pointer_down); |
| 325 ASSERT_EQ(0u, client->tracker()->changes()->size()); | 318 ASSERT_EQ(0u, client->tracker()->changes()->size()); |
| 326 | 319 |
| 327 // Create an observer for pointer-down events. | 320 // Create a watcher for all events excluding move events. |
| 328 WindowTreeTestApi(tree).SetEventObserver( | 321 WindowTreeTestApi(tree).StartPointerWatcher(false, 111u); |
| 329 CreateEventMatcher(ui::mojom::EventType::POINTER_DOWN), 111u); | |
| 330 | 322 |
| 331 // Pointer-down events are sent to the client. | 323 // Pointer-down events are sent to the client. |
| 332 DispatchEventAndAckImmediately(pointer_down); | 324 DispatchEventAndAckImmediately(pointer_down); |
| 333 ASSERT_EQ(1u, client->tracker()->changes()->size()); | 325 ASSERT_EQ(1u, client->tracker()->changes()->size()); |
| 334 EXPECT_EQ("EventObserved event_action=16 event_observer_id=111", | 326 EXPECT_EQ("PointerWatcherEvent event_action=16 pointer_watcher_id=111", |
| 335 ChangesToDescription1(*client->tracker()->changes())[0]); | 327 ChangesToDescription1(*client->tracker()->changes())[0]); |
| 336 client->tracker()->changes()->clear(); | 328 client->tracker()->changes()->clear(); |
| 337 | 329 |
| 338 // Clearing the observer stops sending events to the client. | 330 // Stopping the watcher stops sending events to the client. |
| 339 WindowTreeTestApi(tree).SetEventObserver(nullptr, 0u); | 331 WindowTreeTestApi(tree).StopPointerWatcher(); |
| 340 DispatchEventAndAckImmediately(pointer_down); | 332 DispatchEventAndAckImmediately(pointer_down); |
| 341 ASSERT_EQ(0u, client->tracker()->changes()->size()); | 333 ASSERT_EQ(0u, client->tracker()->changes()->size()); |
| 342 } | 334 } |
| 343 | 335 |
| 344 // Tests that a client using an event observer does not receive events that | 336 // Tests that a client using a pointer watcher does not receive events that |
| 345 // don't match the EventMatcher spec. | 337 // don't match the |want_moves| setting. |
| 346 TEST_F(WindowTreeTest, SetEventObserverNonMatching) { | 338 TEST_F(WindowTreeTest, StartPointerWatcherNonMatching) { |
| 347 // Create an embedded client. | 339 // Create an embedded client. |
| 348 TestWindowTreeClient* client = nullptr; | 340 TestWindowTreeClient* client = nullptr; |
| 349 WindowTree* tree = nullptr; | 341 WindowTree* tree = nullptr; |
| 350 ServerWindow* window = nullptr; | 342 ServerWindow* window = nullptr; |
| 351 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); | 343 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| 352 | 344 |
| 353 // Create an observer for pointer-down events. | 345 // Create a watcher for all events excluding move events. |
| 354 WindowTreeTestApi(tree).SetEventObserver( | 346 WindowTreeTestApi(tree).StartPointerWatcher(false, 111u); |
| 355 CreateEventMatcher(ui::mojom::EventType::POINTER_DOWN), 111u); | |
| 356 | 347 |
| 357 // Pointer-up events are not sent to the client, since they don't match. | 348 // Pointer-move events are not sent to the client, since they don't match. |
| 358 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); | 349 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); |
| 359 ASSERT_EQ(0u, client->tracker()->changes()->size()); | 350 ASSERT_EQ(0u, client->tracker()->changes()->size()); |
| 360 } | 351 } |
| 361 | 352 |
| 362 // Tests that an event that both hits a client window and matches an event | 353 // Tests that an event that both hits a client window and matches a pointer |
| 363 // observer is sent only once to the client. | 354 // watcher is sent only once to the client. |
| 364 TEST_F(WindowTreeTest, SetEventObserverSendsOnce) { | 355 TEST_F(WindowTreeTest, StartPointerWatcherSendsOnce) { |
| 365 // Create an embedded client. | 356 // Create an embedded client. |
| 366 TestWindowTreeClient* client = nullptr; | 357 TestWindowTreeClient* client = nullptr; |
| 367 WindowTree* tree = nullptr; | 358 WindowTree* tree = nullptr; |
| 368 ServerWindow* window = nullptr; | 359 ServerWindow* window = nullptr; |
| 369 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); | 360 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| 370 | 361 |
| 371 // Create an observer for pointer-up events (which do not cause focus | 362 // Create a watcher for all events excluding move events (which do not |
| 372 // changes). | 363 // cause focus changes). |
| 373 WindowTreeTestApi(tree).SetEventObserver( | 364 WindowTreeTestApi(tree).StartPointerWatcher(false, 111u); |
| 374 CreateEventMatcher(ui::mojom::EventType::POINTER_UP), 111u); | |
| 375 | 365 |
| 376 // Create an event inside the bounds of the client. | 366 // Create an event inside the bounds of the client. |
| 377 ui::PointerEvent pointer_up = CreatePointerUpEvent(25, 25); | 367 ui::PointerEvent pointer_up = CreatePointerUpEvent(25, 25); |
| 378 | 368 |
| 379 // The event is dispatched once, with a flag set that it matched the event | 369 // The event is dispatched once, with a flag set that it matched the pointer |
| 380 // observer. | 370 // watcher. |
| 381 DispatchEventAndAckImmediately(pointer_up); | 371 DispatchEventAndAckImmediately(pointer_up); |
| 382 ASSERT_EQ(1u, client->tracker()->changes()->size()); | 372 ASSERT_EQ(1u, client->tracker()->changes()->size()); |
| 383 EXPECT_EQ("InputEvent window=2,1 event_action=18 event_observer_id=111", | 373 EXPECT_EQ("InputEvent window=2,1 event_action=18 pointer_watcher_id=111", |
| 384 SingleChangeToDescription(*client->tracker()->changes())); | 374 SingleChangeToDescription(*client->tracker()->changes())); |
| 385 } | 375 } |
| 386 | 376 |
| 387 // Tests that events generated by user A are not observed by event observers for | 377 // Tests that events generated by user A are not watched by pointer watchers |
| 388 // user B. | 378 // for user B. |
| 389 TEST_F(WindowTreeTest, SetEventObserverWrongUser) { | 379 TEST_F(WindowTreeTest, StartPointerWatcherWrongUser) { |
| 390 // Embed a window tree belonging to a different user. | 380 // Embed a window tree belonging to a different user. |
| 391 TestWindowTreeBinding* other_binding; | 381 TestWindowTreeBinding* other_binding; |
| 392 WindowTree* other_tree = CreateNewTree("other_user", &other_binding); | 382 WindowTree* other_tree = CreateNewTree("other_user", &other_binding); |
| 393 other_binding->client()->tracker()->changes()->clear(); | 383 other_binding->client()->tracker()->changes()->clear(); |
| 394 | 384 |
| 395 // Set event observers on both the wm tree and the other user's tree. | 385 // Set pointer watchers on both the wm tree and the other user's tree. |
| 396 WindowTreeTestApi(wm_tree()).SetEventObserver( | 386 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false, 111u); |
| 397 CreateEventMatcher(ui::mojom::EventType::POINTER_UP), 111u); | 387 WindowTreeTestApi(other_tree).StartPointerWatcher(false, 222u); |
| 398 WindowTreeTestApi(other_tree) | |
| 399 .SetEventObserver(CreateEventMatcher(ui::mojom::EventType::POINTER_UP), | |
| 400 222u); | |
| 401 | 388 |
| 402 // An event is observed by the wm tree, but not by the other user's tree. | 389 // An event is watched by the wm tree, but not by the other user's tree. |
| 403 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); | 390 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); |
| 404 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 391 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 405 EXPECT_EQ("InputEvent window=0,3 event_action=18 event_observer_id=111", | 392 EXPECT_EQ("InputEvent window=0,3 event_action=18 pointer_watcher_id=111", |
| 406 SingleChangeToDescription(*wm_client()->tracker()->changes())); | 393 SingleChangeToDescription(*wm_client()->tracker()->changes())); |
| 407 ASSERT_EQ(0u, other_binding->client()->tracker()->changes()->size()); | 394 ASSERT_EQ(0u, other_binding->client()->tracker()->changes()->size()); |
| 408 } | 395 } |
| 409 | 396 |
| 410 // Tests that an event observer cannot observe keystrokes. | 397 // Tests that a pointer watcher cannot watch keystrokes. |
| 411 TEST_F(WindowTreeTest, SetEventObserverKeyEventsDisallowed) { | 398 TEST_F(WindowTreeTest, StartPointerWatcherKeyEventsDisallowed) { |
| 412 WindowTreeTestApi(wm_tree()).SetEventObserver( | 399 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false, 111u); |
| 413 CreateEventMatcher(ui::mojom::EventType::KEY_PRESSED), 111u); | |
| 414 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 400 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 415 DispatchEventAndAckImmediately(key_pressed); | 401 DispatchEventAndAckImmediately(key_pressed); |
| 416 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size()); | 402 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size()); |
| 417 | 403 |
| 418 WindowTreeTestApi(wm_tree()).SetEventObserver( | 404 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false, 222u); |
| 419 CreateEventMatcher(ui::mojom::EventType::KEY_RELEASED), 222u); | |
| 420 ui::KeyEvent key_released(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE); | 405 ui::KeyEvent key_released(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE); |
| 421 DispatchEventAndAckImmediately(key_released); | 406 DispatchEventAndAckImmediately(key_released); |
| 422 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size()); | 407 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size()); |
| 423 } | 408 } |
| 424 | 409 |
| 425 TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) { | 410 TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) { |
| 426 TestWindowTreeClient* embed_client = nullptr; | 411 TestWindowTreeClient* embed_client = nullptr; |
| 427 WindowTree* tree = nullptr; | 412 WindowTree* tree = nullptr; |
| 428 ServerWindow* window = nullptr; | 413 ServerWindow* window = nullptr; |
| 429 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); | 414 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 | 1238 |
| 1254 EXPECT_TRUE(window->can_accept_events()); | 1239 EXPECT_TRUE(window->can_accept_events()); |
| 1255 WindowTreeTestApi(tree).SetCanAcceptEvents( | 1240 WindowTreeTestApi(tree).SetCanAcceptEvents( |
| 1256 ClientWindowIdForWindow(tree, window).id, false); | 1241 ClientWindowIdForWindow(tree, window).id, false); |
| 1257 EXPECT_FALSE(window->can_accept_events()); | 1242 EXPECT_FALSE(window->can_accept_events()); |
| 1258 } | 1243 } |
| 1259 | 1244 |
| 1260 } // namespace test | 1245 } // namespace test |
| 1261 } // namespace ws | 1246 } // namespace ws |
| 1262 } // namespace ui | 1247 } // namespace ui |
| OLD | NEW |