| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "components/mus/common/types.h" | 9 #include "components/mus/common/types.h" |
| 10 #include "components/mus/common/util.h" | 10 #include "components/mus/common/util.h" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 EXPECT_TRUE(connection1->NewWindow(child1)); | 382 EXPECT_TRUE(connection1->NewWindow(child1)); |
| 383 EXPECT_TRUE(connection1->AddWindow(embed_window_id, child1)); | 383 EXPECT_TRUE(connection1->AddWindow(embed_window_id, child1)); |
| 384 ServerWindow* v1 = connection1->GetWindow(child1); | 384 ServerWindow* v1 = connection1->GetWindow(child1); |
| 385 v1->SetVisible(true); | 385 v1->SetVisible(true); |
| 386 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); | 386 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); |
| 387 | 387 |
| 388 TestWindowTreeClient* connection1_client = last_window_tree_client(); | 388 TestWindowTreeClient* connection1_client = last_window_tree_client(); |
| 389 connection1_client->tracker()->changes()->clear(); | 389 connection1_client->tracker()->changes()->clear(); |
| 390 wm_client()->tracker()->changes()->clear(); | 390 wm_client()->tracker()->changes()->clear(); |
| 391 | 391 |
| 392 // Focus should not go to |child1| yet, since the parent still doesn't allow |
| 393 // active children. |
| 392 display_manager_delegate()->OnEvent(CreatePointerDownEvent(21, 22)); | 394 display_manager_delegate()->OnEvent(CreatePointerDownEvent(21, 22)); |
| 395 EXPECT_EQ(nullptr, connection1->GetHost()->GetFocusedWindow()); |
| 396 display_manager_delegate()->OnEvent(CreatePointerUpEvent(21, 22)); |
| 397 connection1_client->tracker()->changes()->clear(); |
| 398 wm_client()->tracker()->changes()->clear(); |
| 399 |
| 400 connection1->GetHost()->SetActivationParent( |
| 401 WindowIdToTransportId(embed_window_id), true); |
| 402 |
| 393 // Focus should go to child1. This result in notifying both the window | 403 // Focus should go to child1. This result in notifying both the window |
| 394 // manager and client connection being notified. | 404 // manager and client connection being notified. |
| 405 display_manager_delegate()->OnEvent(CreatePointerDownEvent(21, 22)); |
| 395 EXPECT_EQ(v1, connection1->GetHost()->GetFocusedWindow()); | 406 EXPECT_EQ(v1, connection1->GetHost()->GetFocusedWindow()); |
| 396 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u); | 407 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u); |
| 397 EXPECT_EQ("Focused id=2,1", | 408 EXPECT_EQ("Focused id=2,1", |
| 398 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 409 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 399 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u); | 410 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u); |
| 400 EXPECT_EQ( | 411 EXPECT_EQ( |
| 401 "Focused id=2,1", | 412 "Focused id=2,1", |
| 402 ChangesToDescription1(*connection1_client->tracker()->changes())[0]); | 413 ChangesToDescription1(*connection1_client->tracker()->changes())[0]); |
| 403 | 414 |
| 404 display_manager_delegate()->OnEvent(CreatePointerUpEvent(21, 22)); | 415 display_manager_delegate()->OnEvent(CreatePointerUpEvent(21, 22)); |
| 405 wm_client()->tracker()->changes()->clear(); | 416 wm_client()->tracker()->changes()->clear(); |
| 406 connection1_client->tracker()->changes()->clear(); | 417 connection1_client->tracker()->changes()->clear(); |
| 407 | 418 |
| 408 // Press outside of the embedded window. Focus should go to the root. Notice | 419 // Press outside of the embedded window. Focus should go to the root. Notice |
| 409 // the client1 doesn't see who has focus as the focused window (root) isn't | 420 // the client1 doesn't see who has focus as the focused window (root) isn't |
| 410 // visible to it. | 421 // visible to it. |
| 411 display_manager_delegate()->OnEvent(CreatePointerDownEvent(61, 22)); | 422 display_manager_delegate()->OnEvent(CreatePointerDownEvent(61, 22)); |
| 412 EXPECT_EQ(host_connection()->window_tree_host()->root_window(), | 423 EXPECT_EQ(nullptr, host_connection()->window_tree_host()->GetFocusedWindow()); |
| 413 host_connection()->window_tree_host()->GetFocusedWindow()); | |
| 414 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u); | 424 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u); |
| 415 EXPECT_EQ("Focused id=0,2", | 425 EXPECT_EQ("Focused id=null", |
| 416 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 426 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 417 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u); | 427 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u); |
| 418 EXPECT_EQ( | 428 EXPECT_EQ( |
| 419 "Focused id=null", | 429 "Focused id=null", |
| 420 ChangesToDescription1(*connection1_client->tracker()->changes())[0]); | 430 ChangesToDescription1(*connection1_client->tracker()->changes())[0]); |
| 421 | 431 |
| 422 display_manager_delegate()->OnEvent(CreatePointerUpEvent(21, 22)); | 432 display_manager_delegate()->OnEvent(CreatePointerUpEvent(21, 22)); |
| 423 wm_client()->tracker()->changes()->clear(); | 433 wm_client()->tracker()->changes()->clear(); |
| 424 connection1_client->tracker()->changes()->clear(); | 434 connection1_client->tracker()->changes()->clear(); |
| 425 | 435 |
| 426 // Press in the same location. Should not get a focus change event (only input | 436 // Press in the same location. Should not get a focus change event (only input |
| 427 // event). | 437 // event). |
| 428 display_manager_delegate()->OnEvent(CreatePointerDownEvent(61, 22)); | 438 display_manager_delegate()->OnEvent(CreatePointerDownEvent(61, 22)); |
| 429 EXPECT_EQ(host_connection()->window_tree_host()->root_window(), | 439 EXPECT_EQ(nullptr, host_connection()->window_tree_host()->GetFocusedWindow()); |
| 430 host_connection()->window_tree_host()->GetFocusedWindow()); | 440 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u) |
| 431 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u); | 441 << SingleChangeToDescription(*wm_client()->tracker()->changes()); |
| 432 EXPECT_EQ("InputEvent window=0,2 event_action=4", | 442 EXPECT_EQ("InputEvent window=0,2 event_action=4", |
| 433 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 443 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 434 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); | 444 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); |
| 435 } | 445 } |
| 436 | 446 |
| 437 TEST_F(WindowTreeTest, BasicInputEventTarget) { | 447 TEST_F(WindowTreeTest, BasicInputEventTarget) { |
| 438 const WindowId embed_window_id(wm_connection()->id(), 1); | 448 const WindowId embed_window_id(wm_connection()->id(), 1); |
| 439 EXPECT_TRUE(wm_connection()->NewWindow(embed_window_id)); | 449 EXPECT_TRUE(wm_connection()->NewWindow(embed_window_id)); |
| 440 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | 450 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
| 441 EXPECT_TRUE( | 451 EXPECT_TRUE( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 456 ASSERT_TRUE(connection1 != nullptr); | 466 ASSERT_TRUE(connection1 != nullptr); |
| 457 ASSERT_NE(connection1, wm_connection()); | 467 ASSERT_NE(connection1, wm_connection()); |
| 458 | 468 |
| 459 connection_manager() | 469 connection_manager() |
| 460 ->GetWindow(embed_window_id) | 470 ->GetWindow(embed_window_id) |
| 461 ->SetBounds(gfx::Rect(0, 0, 50, 50)); | 471 ->SetBounds(gfx::Rect(0, 0, 50, 50)); |
| 462 | 472 |
| 463 const WindowId child1(connection1->id(), 1); | 473 const WindowId child1(connection1->id(), 1); |
| 464 EXPECT_TRUE(connection1->NewWindow(child1)); | 474 EXPECT_TRUE(connection1->NewWindow(child1)); |
| 465 EXPECT_TRUE(connection1->AddWindow(embed_window_id, child1)); | 475 EXPECT_TRUE(connection1->AddWindow(embed_window_id, child1)); |
| 476 connection1->GetHost()->SetActivationParent( |
| 477 WindowIdToTransportId(embed_window_id), true); |
| 478 |
| 466 ServerWindow* v1 = connection1->GetWindow(child1); | 479 ServerWindow* v1 = connection1->GetWindow(child1); |
| 467 v1->SetVisible(true); | 480 v1->SetVisible(true); |
| 468 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); | 481 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); |
| 469 | 482 |
| 470 TestWindowTreeClient* embed_connection = last_window_tree_client(); | 483 TestWindowTreeClient* embed_connection = last_window_tree_client(); |
| 471 embed_connection->tracker()->changes()->clear(); | 484 embed_connection->tracker()->changes()->clear(); |
| 472 wm_client()->tracker()->changes()->clear(); | 485 wm_client()->tracker()->changes()->clear(); |
| 473 | 486 |
| 474 // Send an event to |v1|. |embed_connection| should get the event, not | 487 // Send an event to |v1|. |embed_connection| should get the event, not |
| 475 // |wm_client|, since |v1| lives inside an embedded window. | 488 // |wm_client|, since |v1| lives inside an embedded window. |
| 476 display_manager_delegate()->OnEvent(CreatePointerDownEvent(21, 22)); | 489 display_manager_delegate()->OnEvent(CreatePointerDownEvent(21, 22)); |
| 477 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 490 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 478 EXPECT_EQ("Focused id=2,1", | 491 EXPECT_EQ("Focused id=2,1", |
| 479 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 492 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 480 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); | 493 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); |
| 481 EXPECT_EQ("Focused id=2,1", | 494 EXPECT_EQ("Focused id=2,1", |
| 482 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); | 495 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); |
| 483 EXPECT_EQ("InputEvent window=2,1 event_action=4", | 496 EXPECT_EQ("InputEvent window=2,1 event_action=4", |
| 484 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); | 497 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); |
| 485 } | 498 } |
| 486 | 499 |
| 487 } // namespace ws | 500 } // namespace ws |
| 488 | 501 |
| 489 } // namespace mus | 502 } // namespace mus |
| OLD | NEW |