Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(852)

Side by Side Diff: services/ui/ws/window_tree_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698