| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); | 280 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); |
| 281 wm_client()->tracker()->changes()->clear(); | 281 wm_client()->tracker()->changes()->clear(); |
| 282 tree1_client->tracker()->changes()->clear(); | 282 tree1_client->tracker()->changes()->clear(); |
| 283 | 283 |
| 284 // Press in the same location. Should not get a focus change event (only input | 284 // Press in the same location. Should not get a focus change event (only input |
| 285 // event). | 285 // event). |
| 286 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); | 286 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); |
| 287 EXPECT_EQ(child1, display()->GetFocusedWindow()); | 287 EXPECT_EQ(child1, display()->GetFocusedWindow()); |
| 288 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()) | 288 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()) |
| 289 << SingleChangeToDescription(*wm_client()->tracker()->changes()); | 289 << SingleChangeToDescription(*wm_client()->tracker()->changes()); |
| 290 EXPECT_EQ("InputEvent window=0,3 event_action=16", | 290 EXPECT_EQ("InputEvent window=0,3 event_action=16 event_root_location=61,22", |
| 291 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 291 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 292 EXPECT_TRUE(tree1_client->tracker()->changes()->empty()); | 292 EXPECT_TRUE(tree1_client->tracker()->changes()->empty()); |
| 293 } | 293 } |
| 294 | 294 |
| 295 TEST_F(WindowTreeTest, BasicInputEventTarget) { | 295 TEST_F(WindowTreeTest, BasicInputEventTarget) { |
| 296 TestWindowTreeClient* embed_client = nullptr; | 296 TestWindowTreeClient* embed_client = nullptr; |
| 297 WindowTree* tree = nullptr; | 297 WindowTree* tree = nullptr; |
| 298 ServerWindow* window = nullptr; | 298 ServerWindow* window = nullptr; |
| 299 EXPECT_NO_FATAL_FAILURE( | 299 EXPECT_NO_FATAL_FAILURE( |
| 300 SetupEventTargeting(&embed_client, &tree, &window)); | 300 SetupEventTargeting(&embed_client, &tree, &window)); |
| 301 | 301 |
| 302 // Send an event to |v1|. |embed_client| should get the event, not | 302 // Send an event to |v1|. |embed_client| should get the event, not |
| 303 // |wm_client|, since |v1| lives inside an embedded window. | 303 // |wm_client|, since |v1| lives inside an embedded window. |
| 304 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); | 304 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); |
| 305 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 305 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 306 EXPECT_EQ("Focused id=2,1", | 306 EXPECT_EQ("Focused id=2,1", |
| 307 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 307 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 308 ASSERT_EQ(2u, embed_client->tracker()->changes()->size()); | 308 ASSERT_EQ(2u, embed_client->tracker()->changes()->size()); |
| 309 EXPECT_EQ("Focused id=2,1", | 309 EXPECT_EQ("Focused id=2,1", |
| 310 ChangesToDescription1(*embed_client->tracker()->changes())[0]); | 310 ChangesToDescription1(*embed_client->tracker()->changes())[0]); |
| 311 EXPECT_EQ("InputEvent window=2,1 event_action=16", | 311 EXPECT_EQ("InputEvent window=2,1 event_action=16 event_root_location=21,22", |
| 312 ChangesToDescription1(*embed_client->tracker()->changes())[1]); | 312 ChangesToDescription1(*embed_client->tracker()->changes())[1]); |
| 313 } | 313 } |
| 314 | 314 |
| 315 // Tests that a client can watch for events outside its bounds. | 315 // Tests that a client can watch for events outside its bounds. |
| 316 TEST_F(WindowTreeTest, StartPointerWatcher) { | 316 TEST_F(WindowTreeTest, StartPointerWatcher) { |
| 317 // Create an embedded client. | 317 // Create an embedded client. |
| 318 TestWindowTreeClient* client = nullptr; | 318 TestWindowTreeClient* client = nullptr; |
| 319 WindowTree* tree = nullptr; | 319 WindowTree* tree = nullptr; |
| 320 ServerWindow* window = nullptr; | 320 ServerWindow* window = nullptr; |
| 321 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); | 321 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 // cause focus changes). | 417 // cause focus changes). |
| 418 WindowTreeTestApi(tree).StartPointerWatcher(false); | 418 WindowTreeTestApi(tree).StartPointerWatcher(false); |
| 419 | 419 |
| 420 // Create an event inside the bounds of the client. | 420 // Create an event inside the bounds of the client. |
| 421 ui::PointerEvent pointer_up = CreatePointerUpEvent(25, 25); | 421 ui::PointerEvent pointer_up = CreatePointerUpEvent(25, 25); |
| 422 | 422 |
| 423 // The event is dispatched once, with a flag set that it matched the pointer | 423 // The event is dispatched once, with a flag set that it matched the pointer |
| 424 // watcher. | 424 // watcher. |
| 425 DispatchEventAndAckImmediately(pointer_up); | 425 DispatchEventAndAckImmediately(pointer_up); |
| 426 ASSERT_EQ(1u, client->tracker()->changes()->size()); | 426 ASSERT_EQ(1u, client->tracker()->changes()->size()); |
| 427 EXPECT_EQ("InputEvent window=2,1 event_action=18 matches_pointer_watcher", | 427 EXPECT_EQ( |
| 428 SingleChangeToDescription(*client->tracker()->changes())); | 428 "InputEvent window=2,1 event_action=18 matches_pointer_watcher" |
| 429 " event_root_location=25,25", |
| 430 SingleChangeToDescription(*client->tracker()->changes())); |
| 429 } | 431 } |
| 430 | 432 |
| 431 // Tests that events generated by user A are not watched by pointer watchers | 433 // Tests that events generated by user A are not watched by pointer watchers |
| 432 // for user B. | 434 // for user B. |
| 433 TEST_F(WindowTreeTest, StartPointerWatcherWrongUser) { | 435 TEST_F(WindowTreeTest, StartPointerWatcherWrongUser) { |
| 434 // Embed a window tree belonging to a different user. | 436 // Embed a window tree belonging to a different user. |
| 435 TestWindowTreeBinding* other_binding; | 437 TestWindowTreeBinding* other_binding; |
| 436 WindowTree* other_tree = CreateNewTree("other_user", &other_binding); | 438 WindowTree* other_tree = CreateNewTree("other_user", &other_binding); |
| 437 other_binding->client()->tracker()->changes()->clear(); | 439 other_binding->client()->tracker()->changes()->clear(); |
| 438 | 440 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 ServerWindow* wm_root = FirstRoot(wm_tree()); | 642 ServerWindow* wm_root = FirstRoot(wm_tree()); |
| 641 ASSERT_TRUE(wm_root); | 643 ASSERT_TRUE(wm_root); |
| 642 wm_root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 644 wm_root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 643 // This tests expects |wm_root| to be a possible target. | 645 // This tests expects |wm_root| to be a possible target. |
| 644 wm_root->set_event_targeting_policy( | 646 wm_root->set_event_targeting_policy( |
| 645 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS); | 647 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS); |
| 646 | 648 |
| 647 wm_client()->tracker()->changes()->clear(); | 649 wm_client()->tracker()->changes()->clear(); |
| 648 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); | 650 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); |
| 649 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 651 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 650 EXPECT_EQ("InputEvent window=0,3 event_action=17", | 652 EXPECT_EQ("InputEvent window=0,3 event_action=17 event_root_location=21,22", |
| 651 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 653 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 652 wm_client()->tracker()->changes()->clear(); | 654 wm_client()->tracker()->changes()->clear(); |
| 653 | 655 |
| 654 // Send another event. This event shouldn't reach the client. | 656 // Send another event. This event shouldn't reach the client. |
| 655 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); | 657 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); |
| 656 ASSERT_EQ(0u, wm_client()->tracker()->changes()->size()); | 658 ASSERT_EQ(0u, wm_client()->tracker()->changes()->size()); |
| 657 | 659 |
| 658 // Ack the first event. That should trigger the dispatch of the second event. | 660 // Ack the first event. That should trigger the dispatch of the second event. |
| 659 AckPreviousEvent(); | 661 AckPreviousEvent(); |
| 660 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 662 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 661 EXPECT_EQ("InputEvent window=0,3 event_action=17", | 663 EXPECT_EQ("InputEvent window=0,3 event_action=17 event_root_location=21,22", |
| 662 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 664 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 663 } | 665 } |
| 664 | 666 |
| 665 // Establish client, call NewTopLevelWindow(), make sure get id, and make | 667 // Establish client, call NewTopLevelWindow(), make sure get id, and make |
| 666 // sure client paused. | 668 // sure client paused. |
| 667 TEST_F(WindowTreeTest, NewTopLevelWindow) { | 669 TEST_F(WindowTreeTest, NewTopLevelWindow) { |
| 668 TestWindowManager wm_internal; | 670 TestWindowManager wm_internal; |
| 669 set_window_manager_internal(wm_tree(), &wm_internal); | 671 set_window_manager_internal(wm_tree(), &wm_internal); |
| 670 | 672 |
| 671 TestWindowTreeBinding* child_binding; | 673 TestWindowTreeBinding* child_binding; |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 client->tracker()->changes()->clear(); | 1422 client->tracker()->changes()->clear(); |
| 1421 } | 1423 } |
| 1422 | 1424 |
| 1423 // Client should not have got any messages after shutdown. | 1425 // Client should not have got any messages after shutdown. |
| 1424 EXPECT_TRUE(client->tracker()->changes()->empty()); | 1426 EXPECT_TRUE(client->tracker()->changes()->empty()); |
| 1425 } | 1427 } |
| 1426 | 1428 |
| 1427 } // namespace test | 1429 } // namespace test |
| 1428 } // namespace ws | 1430 } // namespace ws |
| 1429 } // namespace ui | 1431 } // namespace ui |
| OLD | NEW |