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