| 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); | 315 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| 316 | 316 |
| 317 // Create an event outside the bounds of the client. | 317 // Create an event outside the bounds of the client. |
| 318 ui::PointerEvent pointer_down = CreatePointerDownEvent(5, 5); | 318 ui::PointerEvent pointer_down = CreatePointerDownEvent(5, 5); |
| 319 | 319 |
| 320 // Events are not watched before starting a watcher. | 320 // Events are not watched before starting a watcher. |
| 321 DispatchEventAndAckImmediately(pointer_down); | 321 DispatchEventAndAckImmediately(pointer_down); |
| 322 ASSERT_EQ(0u, client->tracker()->changes()->size()); | 322 ASSERT_EQ(0u, client->tracker()->changes()->size()); |
| 323 | 323 |
| 324 // Create a watcher for all events excluding move events. | 324 // Create a watcher for all events excluding move events. |
| 325 WindowTreeTestApi(tree).StartPointerWatcher(false, 111u); | 325 WindowTreeTestApi(tree).StartPointerWatcher(false); |
| 326 | 326 |
| 327 // Pointer-down events are sent to the client. | 327 // Pointer-down events are sent to the client. |
| 328 DispatchEventAndAckImmediately(pointer_down); | 328 DispatchEventAndAckImmediately(pointer_down); |
| 329 ASSERT_EQ(1u, client->tracker()->changes()->size()); | 329 ASSERT_EQ(1u, client->tracker()->changes()->size()); |
| 330 EXPECT_EQ( | 330 EXPECT_EQ("PointerWatcherEvent event_action=16 window=null", |
| 331 "PointerWatcherEvent event_action=16 pointer_watcher_id=111 window=null", | 331 ChangesToDescription1(*client->tracker()->changes())[0]); |
| 332 ChangesToDescription1(*client->tracker()->changes())[0]); | |
| 333 client->tracker()->changes()->clear(); | 332 client->tracker()->changes()->clear(); |
| 334 | 333 |
| 335 // Stopping the watcher stops sending events to the client. | 334 // Stopping the watcher stops sending events to the client. |
| 336 WindowTreeTestApi(tree).StopPointerWatcher(); | 335 WindowTreeTestApi(tree).StopPointerWatcher(); |
| 337 DispatchEventAndAckImmediately(pointer_down); | 336 DispatchEventAndAckImmediately(pointer_down); |
| 338 ASSERT_EQ(0u, client->tracker()->changes()->size()); | 337 ASSERT_EQ(0u, client->tracker()->changes()->size()); |
| 339 } | 338 } |
| 340 | 339 |
| 341 // Verifies PointerWatcher sees windows known to it. | 340 // Verifies PointerWatcher sees windows known to it. |
| 342 TEST_F(WindowTreeTest, PointerWatcherGetsWindow) { | 341 TEST_F(WindowTreeTest, PointerWatcherGetsWindow) { |
| 343 // Create an embedded client. | 342 // Create an embedded client. |
| 344 TestWindowTreeClient* client = nullptr; | 343 TestWindowTreeClient* client = nullptr; |
| 345 WindowTree* tree = nullptr; | 344 WindowTree* tree = nullptr; |
| 346 ServerWindow* window = nullptr; | 345 ServerWindow* window = nullptr; |
| 347 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); | 346 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| 348 | 347 |
| 349 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false, 111u); | 348 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false); |
| 350 | 349 |
| 351 // Create and dispatch an event that targets the embedded window. | 350 // Create and dispatch an event that targets the embedded window. |
| 352 ui::PointerEvent pointer_down = CreatePointerDownEvent(25, 25); | 351 ui::PointerEvent pointer_down = CreatePointerDownEvent(25, 25); |
| 353 DispatchEventAndAckImmediately(pointer_down); | 352 DispatchEventAndAckImmediately(pointer_down); |
| 354 | 353 |
| 355 // Expect two changes, the first is focus, the second the pointer watcher | 354 // Expect two changes, the first is focus, the second the pointer watcher |
| 356 // event. | 355 // event. |
| 357 ASSERT_EQ(2u, wm_client()->tracker()->changes()->size()); | 356 ASSERT_EQ(2u, wm_client()->tracker()->changes()->size()); |
| 358 EXPECT_EQ( | 357 EXPECT_EQ( |
| 359 "PointerWatcherEvent event_action=16 pointer_watcher_id=111 window=" + | 358 "PointerWatcherEvent event_action=16 window=" + |
| 360 ClientWindowIdToString(ClientWindowIdForWindow(wm_tree(), window)), | 359 ClientWindowIdToString(ClientWindowIdForWindow(wm_tree(), window)), |
| 361 ChangesToDescription1(*wm_client()->tracker()->changes())[1]); | 360 ChangesToDescription1(*wm_client()->tracker()->changes())[1]); |
| 362 } | 361 } |
| 363 | 362 |
| 364 // Tests that a client using a pointer watcher does not receive events that | 363 // Tests that a client using a pointer watcher does not receive events that |
| 365 // don't match the |want_moves| setting. | 364 // don't match the |want_moves| setting. |
| 366 TEST_F(WindowTreeTest, StartPointerWatcherNonMatching) { | 365 TEST_F(WindowTreeTest, StartPointerWatcherNonMatching) { |
| 367 // Create an embedded client. | 366 // Create an embedded client. |
| 368 TestWindowTreeClient* client = nullptr; | 367 TestWindowTreeClient* client = nullptr; |
| 369 WindowTree* tree = nullptr; | 368 WindowTree* tree = nullptr; |
| 370 ServerWindow* window = nullptr; | 369 ServerWindow* window = nullptr; |
| 371 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); | 370 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| 372 | 371 |
| 373 // Create a watcher for all events excluding move events. | 372 // Create a watcher for all events excluding move events. |
| 374 WindowTreeTestApi(tree).StartPointerWatcher(false, 111u); | 373 WindowTreeTestApi(tree).StartPointerWatcher(false); |
| 375 | 374 |
| 376 // Pointer-move events are not sent to the client, since they don't match. | 375 // Pointer-move events are not sent to the client, since they don't match. |
| 377 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); | 376 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); |
| 378 ASSERT_EQ(0u, client->tracker()->changes()->size()); | 377 ASSERT_EQ(0u, client->tracker()->changes()->size()); |
| 379 } | 378 } |
| 380 | 379 |
| 381 // Tests that an event that both hits a client window and matches a pointer | 380 // Tests that an event that both hits a client window and matches a pointer |
| 382 // watcher is sent only once to the client. | 381 // watcher is sent only once to the client. |
| 383 TEST_F(WindowTreeTest, StartPointerWatcherSendsOnce) { | 382 TEST_F(WindowTreeTest, StartPointerWatcherSendsOnce) { |
| 384 // Create an embedded client. | 383 // Create an embedded client. |
| 385 TestWindowTreeClient* client = nullptr; | 384 TestWindowTreeClient* client = nullptr; |
| 386 WindowTree* tree = nullptr; | 385 WindowTree* tree = nullptr; |
| 387 ServerWindow* window = nullptr; | 386 ServerWindow* window = nullptr; |
| 388 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); | 387 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| 389 | 388 |
| 390 // Create a watcher for all events excluding move events (which do not | 389 // Create a watcher for all events excluding move events (which do not |
| 391 // cause focus changes). | 390 // cause focus changes). |
| 392 WindowTreeTestApi(tree).StartPointerWatcher(false, 111u); | 391 WindowTreeTestApi(tree).StartPointerWatcher(false); |
| 393 | 392 |
| 394 // Create an event inside the bounds of the client. | 393 // Create an event inside the bounds of the client. |
| 395 ui::PointerEvent pointer_up = CreatePointerUpEvent(25, 25); | 394 ui::PointerEvent pointer_up = CreatePointerUpEvent(25, 25); |
| 396 | 395 |
| 397 // The event is dispatched once, with a flag set that it matched the pointer | 396 // The event is dispatched once, with a flag set that it matched the pointer |
| 398 // watcher. | 397 // watcher. |
| 399 DispatchEventAndAckImmediately(pointer_up); | 398 DispatchEventAndAckImmediately(pointer_up); |
| 400 ASSERT_EQ(1u, client->tracker()->changes()->size()); | 399 ASSERT_EQ(1u, client->tracker()->changes()->size()); |
| 401 EXPECT_EQ("InputEvent window=2,1 event_action=18 pointer_watcher_id=111", | 400 EXPECT_EQ("InputEvent window=2,1 event_action=18 matches_pointer_watcher", |
| 402 SingleChangeToDescription(*client->tracker()->changes())); | 401 SingleChangeToDescription(*client->tracker()->changes())); |
| 403 } | 402 } |
| 404 | 403 |
| 405 // Tests that events generated by user A are not watched by pointer watchers | 404 // Tests that events generated by user A are not watched by pointer watchers |
| 406 // for user B. | 405 // for user B. |
| 407 TEST_F(WindowTreeTest, StartPointerWatcherWrongUser) { | 406 TEST_F(WindowTreeTest, StartPointerWatcherWrongUser) { |
| 408 // Embed a window tree belonging to a different user. | 407 // Embed a window tree belonging to a different user. |
| 409 TestWindowTreeBinding* other_binding; | 408 TestWindowTreeBinding* other_binding; |
| 410 WindowTree* other_tree = CreateNewTree("other_user", &other_binding); | 409 WindowTree* other_tree = CreateNewTree("other_user", &other_binding); |
| 411 other_binding->client()->tracker()->changes()->clear(); | 410 other_binding->client()->tracker()->changes()->clear(); |
| 412 | 411 |
| 413 // Set pointer watchers on both the wm tree and the other user's tree. | 412 // Set pointer watchers on both the wm tree and the other user's tree. |
| 414 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false, 111u); | 413 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false); |
| 415 WindowTreeTestApi(other_tree).StartPointerWatcher(false, 222u); | 414 WindowTreeTestApi(other_tree).StartPointerWatcher(false); |
| 416 | 415 |
| 417 // An event is watched by the wm tree, but not by the other user's tree. | 416 // An event is watched by the wm tree, but not by the other user's tree. |
| 418 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); | 417 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); |
| 419 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 418 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 420 EXPECT_EQ("InputEvent window=0,3 event_action=18 pointer_watcher_id=111", | 419 EXPECT_EQ("InputEvent window=0,3 event_action=18 matches_pointer_watcher", |
| 421 SingleChangeToDescription(*wm_client()->tracker()->changes())); | 420 SingleChangeToDescription(*wm_client()->tracker()->changes())); |
| 422 ASSERT_EQ(0u, other_binding->client()->tracker()->changes()->size()); | 421 ASSERT_EQ(0u, other_binding->client()->tracker()->changes()->size()); |
| 423 } | 422 } |
| 424 | 423 |
| 425 // Tests that a pointer watcher cannot watch keystrokes. | 424 // Tests that a pointer watcher cannot watch keystrokes. |
| 426 TEST_F(WindowTreeTest, StartPointerWatcherKeyEventsDisallowed) { | 425 TEST_F(WindowTreeTest, StartPointerWatcherKeyEventsDisallowed) { |
| 427 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false, 111u); | 426 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false); |
| 428 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 427 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 429 DispatchEventAndAckImmediately(key_pressed); | 428 DispatchEventAndAckImmediately(key_pressed); |
| 430 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size()); | 429 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size()); |
| 431 | 430 |
| 432 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false, 222u); | 431 WindowTreeTestApi(wm_tree()).StartPointerWatcher(false); |
| 433 ui::KeyEvent key_released(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE); | 432 ui::KeyEvent key_released(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE); |
| 434 DispatchEventAndAckImmediately(key_released); | 433 DispatchEventAndAckImmediately(key_released); |
| 435 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size()); | 434 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size()); |
| 436 } | 435 } |
| 437 | 436 |
| 438 TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) { | 437 TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) { |
| 439 TestWindowTreeClient* embed_client = nullptr; | 438 TestWindowTreeClient* embed_client = nullptr; |
| 440 WindowTree* tree = nullptr; | 439 WindowTree* tree = nullptr; |
| 441 ServerWindow* window = nullptr; | 440 ServerWindow* window = nullptr; |
| 442 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); | 441 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1316 ClientWindowIdForWindow(owning_tree, FirstRoot(embed_tree)))); | 1315 ClientWindowIdForWindow(owning_tree, FirstRoot(embed_tree)))); |
| 1317 EXPECT_TRUE(wm_client()->tracker()->changes()->empty()); | 1316 EXPECT_TRUE(wm_client()->tracker()->changes()->empty()); |
| 1318 ASSERT_TRUE(!embed_client->tracker()->changes()->empty()); | 1317 ASSERT_TRUE(!embed_client->tracker()->changes()->empty()); |
| 1319 EXPECT_EQ("OnCaptureChanged new_window=null old_window=1,1", | 1318 EXPECT_EQ("OnCaptureChanged new_window=null old_window=1,1", |
| 1320 ChangesToDescription1(*embed_client->tracker()->changes())[0]); | 1319 ChangesToDescription1(*embed_client->tracker()->changes())[0]); |
| 1321 } | 1320 } |
| 1322 | 1321 |
| 1323 } // namespace test | 1322 } // namespace test |
| 1324 } // namespace ws | 1323 } // namespace ws |
| 1325 } // namespace ui | 1324 } // namespace ui |
| OLD | NEW |