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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 using mus::mojom::WindowDataPtr; | 43 using mus::mojom::WindowDataPtr; |
44 | 44 |
45 namespace mus { | 45 namespace mus { |
46 namespace ws { | 46 namespace ws { |
47 namespace { | 47 namespace { |
48 | 48 |
49 std::string WindowIdToString(const WindowId& id) { | 49 std::string WindowIdToString(const WindowId& id) { |
50 return base::StringPrintf("%d,%d", id.connection_id, id.window_id); | 50 return base::StringPrintf("%d,%d", id.connection_id, id.window_id); |
51 } | 51 } |
52 | 52 |
| 53 ClientWindowId BuildClientWindowId(WindowTreeImpl* tree, |
| 54 ConnectionSpecificId window_id) { |
| 55 return ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), window_id))); |
| 56 } |
| 57 |
| 58 ClientWindowId ClientWindowIdForWindow(WindowTreeImpl* tree, |
| 59 const ServerWindow* window) { |
| 60 ClientWindowId client_window_id; |
| 61 // If window isn't known we'll return 0, which should then error out. |
| 62 tree->IsWindowKnown(window, &client_window_id); |
| 63 return client_window_id; |
| 64 } |
| 65 |
53 class TestWindowManagerInternal : public mojom::WindowManagerInternal { | 66 class TestWindowManagerInternal : public mojom::WindowManagerInternal { |
54 public: | 67 public: |
55 TestWindowManagerInternal() | 68 TestWindowManagerInternal() |
56 : got_create_top_level_window_(false), change_id_(0u) {} | 69 : got_create_top_level_window_(false), change_id_(0u) {} |
57 ~TestWindowManagerInternal() override {} | 70 ~TestWindowManagerInternal() override {} |
58 | 71 |
59 bool did_call_create_top_level_window(uint32_t* change_id) { | 72 bool did_call_create_top_level_window(uint32_t* change_id) { |
60 if (!got_create_top_level_window_) | 73 if (!got_create_top_level_window_) |
61 return false; | 74 return false; |
62 | 75 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 return ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(x, y), | 385 return ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(x, y), |
373 gfx::Point(x, y), ui::EventTimeForNow(), | 386 gfx::Point(x, y), ui::EventTimeForNow(), |
374 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 387 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
375 } | 388 } |
376 | 389 |
377 const ServerWindow* FirstRoot(WindowTreeImpl* connection) { | 390 const ServerWindow* FirstRoot(WindowTreeImpl* connection) { |
378 return connection->roots().size() == 1u ? *(connection->roots().begin()) | 391 return connection->roots().size() == 1u ? *(connection->roots().begin()) |
379 : nullptr; | 392 : nullptr; |
380 } | 393 } |
381 | 394 |
| 395 ClientWindowId FirstRootId(WindowTreeImpl* connection) { |
| 396 return connection->roots().size() == 1u |
| 397 ? ClientWindowIdForWindow(connection, |
| 398 *(connection->roots().begin())) |
| 399 : ClientWindowId(); |
| 400 } |
| 401 |
382 } // namespace | 402 } // namespace |
383 | 403 |
384 // ----------------------------------------------------------------------------- | 404 // ----------------------------------------------------------------------------- |
385 | 405 |
386 class WindowTreeTest : public testing::Test { | 406 class WindowTreeTest : public testing::Test { |
387 public: | 407 public: |
388 WindowTreeTest() | 408 WindowTreeTest() |
389 : wm_client_(nullptr), | 409 : wm_client_(nullptr), |
390 cursor_id_(0), | 410 cursor_id_(0), |
391 display_manager_factory_(&cursor_id_) {} | 411 display_manager_factory_(&cursor_id_) {} |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 int32_t cursor_id_; | 490 int32_t cursor_id_; |
471 TestDisplayManagerFactory display_manager_factory_; | 491 TestDisplayManagerFactory display_manager_factory_; |
472 TestConnectionManagerDelegate delegate_; | 492 TestConnectionManagerDelegate delegate_; |
473 TestWindowTreeHostConnection* host_connection_; | 493 TestWindowTreeHostConnection* host_connection_; |
474 scoped_ptr<ConnectionManager> connection_manager_; | 494 scoped_ptr<ConnectionManager> connection_manager_; |
475 base::MessageLoop message_loop_; | 495 base::MessageLoop message_loop_; |
476 | 496 |
477 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest); | 497 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest); |
478 }; | 498 }; |
479 | 499 |
| 500 // Creates a new window in wm_connection(), adds it to the root, embeds a |
| 501 // new client in the window and creates a child of said window. |window| is |
| 502 // set to the child of |window_tree_connection| that is created. |
480 void WindowTreeTest::SetupEventTargeting( | 503 void WindowTreeTest::SetupEventTargeting( |
481 TestWindowTreeClient** out_client, | 504 TestWindowTreeClient** out_client, |
482 WindowTreeImpl** window_tree_connection, | 505 WindowTreeImpl** window_tree_connection, |
483 ServerWindow** window) { | 506 ServerWindow** window) { |
484 const WindowId embed_window_id(wm_connection()->id(), 1); | 507 const ClientWindowId embed_window_id = |
| 508 BuildClientWindowId(wm_connection(), 1); |
485 EXPECT_TRUE( | 509 EXPECT_TRUE( |
486 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 510 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); |
487 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | 511 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
488 ASSERT_TRUE(FirstRoot(wm_connection())); | 512 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()), |
489 EXPECT_TRUE(wm_connection()->AddWindow(FirstRoot(wm_connection())->id(), | |
490 embed_window_id)); | 513 embed_window_id)); |
491 host_connection()->window_tree_host()->root_window()->SetBounds( | 514 host_connection()->window_tree_host()->root_window()->SetBounds( |
492 gfx::Rect(0, 0, 100, 100)); | 515 gfx::Rect(0, 0, 100, 100)); |
493 mojom::WindowTreeClientPtr client; | 516 mojom::WindowTreeClientPtr client; |
494 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = | 517 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = |
495 GetProxy(&client); | 518 GetProxy(&client); |
496 wm_client()->Bind(std::move(client_request)); | 519 wm_client()->Bind(std::move(client_request)); |
497 ConnectionSpecificId connection_id = 0; | 520 ConnectionSpecificId connection_id = 0; |
498 wm_connection()->Embed(embed_window_id, std::move(client), | 521 wm_connection()->Embed(embed_window_id, std::move(client), |
499 mojom::WindowTree::kAccessPolicyDefault, | 522 mojom::WindowTree::kAccessPolicyDefault, |
500 &connection_id); | 523 &connection_id); |
501 WindowTreeImpl* connection1 = connection_manager()->GetConnectionWithRoot( | 524 ServerWindow* embed_window = |
502 GetWindowById(embed_window_id)); | 525 wm_connection()->GetWindowByClientId(embed_window_id); |
| 526 WindowTreeImpl* connection1 = |
| 527 connection_manager()->GetConnectionWithRoot(embed_window); |
503 ASSERT_TRUE(connection1 != nullptr); | 528 ASSERT_TRUE(connection1 != nullptr); |
504 ASSERT_NE(connection1, wm_connection()); | 529 ASSERT_NE(connection1, wm_connection()); |
505 | 530 |
506 connection_manager() | 531 embed_window->SetBounds(gfx::Rect(0, 0, 50, 50)); |
507 ->GetWindow(embed_window_id) | |
508 ->SetBounds(gfx::Rect(0, 0, 50, 50)); | |
509 | 532 |
510 const WindowId child1(connection1->id(), 1); | 533 const ClientWindowId child1_id(BuildClientWindowId(connection1, 1)); |
511 EXPECT_TRUE(connection1->NewWindow(child1, ServerWindow::Properties())); | 534 EXPECT_TRUE(connection1->NewWindow(child1_id, ServerWindow::Properties())); |
512 EXPECT_TRUE(connection1->AddWindow(embed_window_id, child1)); | 535 ServerWindow* child1 = connection1->GetWindowByClientId(child1_id); |
513 connection1->GetHost(GetWindowById(embed_window_id)) | 536 ASSERT_TRUE(child1); |
514 ->AddActivationParent(WindowIdToTransportId(embed_window_id)); | 537 EXPECT_TRUE(connection1->AddWindow( |
| 538 ClientWindowIdForWindow(connection1, embed_window), child1_id)); |
| 539 connection1->GetHost(embed_window)->AddActivationParent(embed_window_id.id); |
515 | 540 |
516 ServerWindow* v1 = connection1->GetWindow(child1); | 541 child1->SetVisible(true); |
517 v1->SetVisible(true); | 542 child1->SetBounds(gfx::Rect(20, 20, 20, 20)); |
518 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); | 543 EnableHitTest(child1); |
519 EnableHitTest(v1); | |
520 | 544 |
521 TestWindowTreeClient* embed_connection = last_window_tree_client(); | 545 TestWindowTreeClient* embed_connection = last_window_tree_client(); |
522 embed_connection->tracker()->changes()->clear(); | 546 embed_connection->tracker()->changes()->clear(); |
523 wm_client()->tracker()->changes()->clear(); | 547 wm_client()->tracker()->changes()->clear(); |
524 | 548 |
525 *out_client = embed_connection; | 549 *out_client = embed_connection; |
526 *window_tree_connection = connection1; | 550 *window_tree_connection = connection1; |
527 *window = v1; | 551 *window = child1; |
528 } | 552 } |
529 | 553 |
530 // Verifies focus correctly changes on pointer events. | 554 // Verifies focus correctly changes on pointer events. |
531 TEST_F(WindowTreeTest, FocusOnPointer) { | 555 TEST_F(WindowTreeTest, FocusOnPointer) { |
532 const WindowId embed_window_id(wm_connection()->id(), 1); | 556 const ClientWindowId embed_window_id = |
| 557 BuildClientWindowId(wm_connection(), 1); |
533 EXPECT_TRUE( | 558 EXPECT_TRUE( |
534 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 559 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); |
| 560 ServerWindow* embed_window = |
| 561 wm_connection()->GetWindowByClientId(embed_window_id); |
| 562 ASSERT_TRUE(embed_window); |
535 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | 563 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
536 ASSERT_TRUE(FirstRoot(wm_connection())); | 564 ASSERT_TRUE(FirstRoot(wm_connection())); |
537 EXPECT_TRUE(wm_connection()->AddWindow(FirstRoot(wm_connection())->id(), | 565 const ClientWindowId wm_root_id = FirstRootId(wm_connection()); |
538 embed_window_id)); | 566 EXPECT_TRUE(wm_connection()->AddWindow(wm_root_id, embed_window_id)); |
539 host_connection()->window_tree_host()->root_window()->SetBounds( | 567 host_connection()->window_tree_host()->root_window()->SetBounds( |
540 gfx::Rect(0, 0, 100, 100)); | 568 gfx::Rect(0, 0, 100, 100)); |
541 mojom::WindowTreeClientPtr client; | 569 mojom::WindowTreeClientPtr client; |
542 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = | 570 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = |
543 GetProxy(&client); | 571 GetProxy(&client); |
544 wm_client()->Bind(std::move(client_request)); | 572 wm_client()->Bind(std::move(client_request)); |
545 ConnectionSpecificId connection_id = 0; | 573 ConnectionSpecificId connection_id = 0; |
546 wm_connection()->Embed(embed_window_id, std::move(client), | 574 wm_connection()->Embed(embed_window_id, std::move(client), |
547 mojom::WindowTree::kAccessPolicyDefault, | 575 mojom::WindowTree::kAccessPolicyDefault, |
548 &connection_id); | 576 &connection_id); |
549 WindowTreeImpl* connection1 = connection_manager()->GetConnectionWithRoot( | 577 WindowTreeImpl* connection1 = |
550 GetWindowById(embed_window_id)); | 578 connection_manager()->GetConnectionWithRoot(embed_window); |
551 ASSERT_TRUE(connection1 != nullptr); | 579 ASSERT_TRUE(connection1 != nullptr); |
552 ASSERT_NE(connection1, wm_connection()); | 580 ASSERT_NE(connection1, wm_connection()); |
553 | 581 |
554 connection_manager() | 582 embed_window->SetBounds(gfx::Rect(0, 0, 50, 50)); |
555 ->GetWindow(embed_window_id) | |
556 ->SetBounds(gfx::Rect(0, 0, 50, 50)); | |
557 | 583 |
558 const WindowId child1(connection1->id(), 1); | 584 const ClientWindowId child1_id(BuildClientWindowId(connection1, 1)); |
559 EXPECT_TRUE(connection1->NewWindow(child1, ServerWindow::Properties())); | 585 EXPECT_TRUE(connection1->NewWindow(child1_id, ServerWindow::Properties())); |
560 EXPECT_TRUE(connection1->AddWindow(embed_window_id, child1)); | 586 EXPECT_TRUE(connection1->AddWindow( |
561 ServerWindow* v1 = connection1->GetWindow(child1); | 587 ClientWindowIdForWindow(connection1, embed_window), child1_id)); |
562 v1->SetVisible(true); | 588 ServerWindow* child1 = connection1->GetWindowByClientId(child1_id); |
563 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); | 589 ASSERT_TRUE(child1); |
564 EnableHitTest(v1); | 590 child1->SetVisible(true); |
| 591 child1->SetBounds(gfx::Rect(20, 20, 20, 20)); |
| 592 EnableHitTest(child1); |
565 | 593 |
566 TestWindowTreeClient* connection1_client = last_window_tree_client(); | 594 TestWindowTreeClient* connection1_client = last_window_tree_client(); |
567 connection1_client->tracker()->changes()->clear(); | 595 connection1_client->tracker()->changes()->clear(); |
568 wm_client()->tracker()->changes()->clear(); | 596 wm_client()->tracker()->changes()->clear(); |
569 | 597 |
570 // Focus should not go to |child1| yet, since the parent still doesn't allow | 598 // Focus should not go to |child1| yet, since the parent still doesn't allow |
571 // active children. | 599 // active children. |
572 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); | 600 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); |
573 WindowTreeHostImpl* host1 = | 601 WindowTreeHostImpl* host1 = connection1->GetHost(embed_window); |
574 connection1->GetHost(GetWindowById(embed_window_id)); | |
575 EXPECT_EQ(nullptr, host1->GetFocusedWindow()); | 602 EXPECT_EQ(nullptr, host1->GetFocusedWindow()); |
576 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); | 603 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); |
577 connection1_client->tracker()->changes()->clear(); | 604 connection1_client->tracker()->changes()->clear(); |
578 wm_client()->tracker()->changes()->clear(); | 605 wm_client()->tracker()->changes()->clear(); |
579 | 606 |
580 host1->AddActivationParent(WindowIdToTransportId(embed_window_id)); | 607 host1->AddActivationParent(embed_window_id.id); |
581 | 608 |
582 // Focus should go to child1. This result in notifying both the window | 609 // Focus should go to child1. This result in notifying both the window |
583 // manager and client connection being notified. | 610 // manager and client connection being notified. |
584 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); | 611 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); |
585 EXPECT_EQ(v1, host1->GetFocusedWindow()); | 612 EXPECT_EQ(child1, host1->GetFocusedWindow()); |
586 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u); | 613 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u); |
587 EXPECT_EQ("Focused id=2,1", | 614 EXPECT_EQ("Focused id=2,1", |
588 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 615 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
589 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u); | 616 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u); |
590 EXPECT_EQ( | 617 EXPECT_EQ( |
591 "Focused id=2,1", | 618 "Focused id=2,1", |
592 ChangesToDescription1(*connection1_client->tracker()->changes())[0]); | 619 ChangesToDescription1(*connection1_client->tracker()->changes())[0]); |
593 | 620 |
594 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); | 621 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); |
595 wm_client()->tracker()->changes()->clear(); | 622 wm_client()->tracker()->changes()->clear(); |
596 connection1_client->tracker()->changes()->clear(); | 623 connection1_client->tracker()->changes()->clear(); |
597 | 624 |
598 // Press outside of the embedded window. Note that root cannot be focused | 625 // Press outside of the embedded window. Note that root cannot be focused |
599 // (because it cannot be activated). So the focus would not move in this case. | 626 // (because it cannot be activated). So the focus would not move in this case. |
600 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); | 627 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); |
601 EXPECT_EQ(v1, host_connection()->window_tree_host()->GetFocusedWindow()); | 628 EXPECT_EQ(child1, host_connection()->window_tree_host()->GetFocusedWindow()); |
602 | 629 |
603 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); | 630 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); |
604 wm_client()->tracker()->changes()->clear(); | 631 wm_client()->tracker()->changes()->clear(); |
605 connection1_client->tracker()->changes()->clear(); | 632 connection1_client->tracker()->changes()->clear(); |
606 | 633 |
607 // Press in the same location. Should not get a focus change event (only input | 634 // Press in the same location. Should not get a focus change event (only input |
608 // event). | 635 // event). |
609 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); | 636 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); |
610 EXPECT_EQ(v1, host_connection()->window_tree_host()->GetFocusedWindow()); | 637 EXPECT_EQ(child1, host_connection()->window_tree_host()->GetFocusedWindow()); |
611 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u) | 638 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u) |
612 << SingleChangeToDescription(*wm_client()->tracker()->changes()); | 639 << SingleChangeToDescription(*wm_client()->tracker()->changes()); |
613 EXPECT_EQ("InputEvent window=0,2 event_action=4", | 640 EXPECT_EQ("InputEvent window=0,2 event_action=4", |
614 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 641 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
615 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); | 642 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); |
616 } | 643 } |
617 | 644 |
618 TEST_F(WindowTreeTest, BasicInputEventTarget) { | 645 TEST_F(WindowTreeTest, BasicInputEventTarget) { |
619 TestWindowTreeClient* embed_connection = nullptr; | 646 TestWindowTreeClient* embed_connection = nullptr; |
620 WindowTreeImpl* window_tree_connection = nullptr; | 647 WindowTreeImpl* window_tree_connection = nullptr; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 } | 769 } |
743 | 770 |
744 TEST_F(WindowTreeTest, WindowReorderingChangesCursor) { | 771 TEST_F(WindowTreeTest, WindowReorderingChangesCursor) { |
745 TestWindowTreeClient* embed_connection = nullptr; | 772 TestWindowTreeClient* embed_connection = nullptr; |
746 WindowTreeImpl* window_tree_connection = nullptr; | 773 WindowTreeImpl* window_tree_connection = nullptr; |
747 ServerWindow* window1 = nullptr; | 774 ServerWindow* window1 = nullptr; |
748 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting( | 775 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting( |
749 &embed_connection, &window_tree_connection, &window1)); | 776 &embed_connection, &window_tree_connection, &window1)); |
750 | 777 |
751 // Create a second window right over the first. | 778 // Create a second window right over the first. |
752 const WindowId embed_window_id(wm_connection()->id(), 1); | 779 const ClientWindowId embed_window_id(FirstRootId(window_tree_connection)); |
753 const WindowId child2(window_tree_connection->id(), 2); | 780 const ClientWindowId child2_id( |
| 781 BuildClientWindowId(window_tree_connection, 2)); |
754 EXPECT_TRUE( | 782 EXPECT_TRUE( |
755 window_tree_connection->NewWindow(child2, ServerWindow::Properties())); | 783 window_tree_connection->NewWindow(child2_id, ServerWindow::Properties())); |
756 EXPECT_TRUE(window_tree_connection->AddWindow(embed_window_id, child2)); | 784 ServerWindow* child2 = window_tree_connection->GetWindowByClientId(child2_id); |
757 window_tree_connection->GetHost( | 785 ASSERT_TRUE(child2); |
758 GetWindowById(WindowId(wm_connection()->id(), 1))) | 786 EXPECT_TRUE(window_tree_connection->AddWindow(embed_window_id, child2_id)); |
759 ->AddActivationParent(WindowIdToTransportId(embed_window_id)); | 787 child2->SetVisible(true); |
760 ServerWindow* window2 = window_tree_connection->GetWindow(child2); | 788 child2->SetBounds(gfx::Rect(20, 20, 20, 20)); |
761 window2->SetVisible(true); | 789 EnableHitTest(child2); |
762 window2->SetBounds(gfx::Rect(20, 20, 20, 20)); | |
763 EnableHitTest(window2); | |
764 | 790 |
765 // Give each window a different cursor. | 791 // Give each window a different cursor. |
766 window1->SetPredefinedCursor(mojom::Cursor::IBEAM); | 792 window1->SetPredefinedCursor(mojom::Cursor::IBEAM); |
767 window2->SetPredefinedCursor(mojom::Cursor::HAND); | 793 child2->SetPredefinedCursor(mojom::Cursor::HAND); |
768 | 794 |
769 // We expect window2 to be over window1 now. | 795 // We expect window2 to be over window1 now. |
770 DispatchEventAndAckImmediately(CreateMouseMoveEvent(22, 22)); | 796 DispatchEventAndAckImmediately(CreateMouseMoveEvent(22, 22)); |
771 EXPECT_EQ(mojom::Cursor::HAND, cursor_id()); | 797 EXPECT_EQ(mojom::Cursor::HAND, cursor_id()); |
772 | 798 |
773 // But when we put window2 at the bottom, we should adapt window1's cursor. | 799 // But when we put window2 at the bottom, we should adapt window1's cursor. |
774 window2->parent()->StackChildAtBottom(window2); | 800 child2->parent()->StackChildAtBottom(child2); |
775 EXPECT_EQ(mojom::Cursor::IBEAM, cursor_id()); | 801 EXPECT_EQ(mojom::Cursor::IBEAM, cursor_id()); |
776 } | 802 } |
777 | 803 |
778 TEST_F(WindowTreeTest, EventAck) { | 804 TEST_F(WindowTreeTest, EventAck) { |
779 const WindowId embed_window_id(wm_connection()->id(), 1); | 805 const ClientWindowId embed_window_id = |
| 806 BuildClientWindowId(wm_connection(), 1); |
780 EXPECT_TRUE( | 807 EXPECT_TRUE( |
781 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 808 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); |
782 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | 809 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
783 ASSERT_TRUE(FirstRoot(wm_connection())); | 810 ASSERT_TRUE(FirstRoot(wm_connection())); |
784 EXPECT_TRUE(wm_connection()->AddWindow(FirstRoot(wm_connection())->id(), | 811 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()), |
785 embed_window_id)); | 812 embed_window_id)); |
786 host_connection()->window_tree_host()->root_window()->SetBounds( | 813 host_connection()->window_tree_host()->root_window()->SetBounds( |
787 gfx::Rect(0, 0, 100, 100)); | 814 gfx::Rect(0, 0, 100, 100)); |
788 | 815 |
789 wm_client()->tracker()->changes()->clear(); | 816 wm_client()->tracker()->changes()->clear(); |
790 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); | 817 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); |
791 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 818 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
792 EXPECT_EQ("InputEvent window=0,2 event_action=5", | 819 EXPECT_EQ("InputEvent window=0,2 event_action=5", |
793 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 820 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
794 wm_client()->tracker()->changes()->clear(); | 821 wm_client()->tracker()->changes()->clear(); |
(...skipping 19 matching lines...) Expand all Loading... |
814 ServerWindow* window = nullptr; | 841 ServerWindow* window = nullptr; |
815 ASSERT_NO_FATAL_FAILURE( | 842 ASSERT_NO_FATAL_FAILURE( |
816 SetupEventTargeting(&embed_connection, &window_tree_connection, &window)); | 843 SetupEventTargeting(&embed_connection, &window_tree_connection, &window)); |
817 embed_connection->tracker()->changes()->clear(); | 844 embed_connection->tracker()->changes()->clear(); |
818 embed_connection->set_record_on_change_completed(true); | 845 embed_connection->set_record_on_change_completed(true); |
819 | 846 |
820 // Create a new top level window. | 847 // Create a new top level window. |
821 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties; | 848 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties; |
822 properties.mark_non_null(); | 849 properties.mark_non_null(); |
823 const uint32_t initial_change_id = 17; | 850 const uint32_t initial_change_id = 17; |
824 const WindowId embed_window_id2_in_child(window_tree_connection->id(), 101); | 851 // Explicitly use an id that does not contain the connection id. |
| 852 const ClientWindowId embed_window_id2_in_child(45 << 16 | 27); |
825 static_cast<mojom::WindowTree*>(window_tree_connection) | 853 static_cast<mojom::WindowTree*>(window_tree_connection) |
826 ->NewTopLevelWindow(initial_change_id, | 854 ->NewTopLevelWindow(initial_change_id, embed_window_id2_in_child.id, |
827 WindowIdToTransportId(embed_window_id2_in_child), | |
828 std::move(properties)); | 855 std::move(properties)); |
829 | 856 |
830 // The binding should be paused until the wm acks the change. | 857 // The binding should be paused until the wm acks the change. |
831 uint32_t wm_change_id = 0u; | 858 uint32_t wm_change_id = 0u; |
832 ASSERT_TRUE(wm_internal.did_call_create_top_level_window(&wm_change_id)); | 859 ASSERT_TRUE(wm_internal.did_call_create_top_level_window(&wm_change_id)); |
833 EXPECT_TRUE(last_client_connection()->is_paused()); | 860 EXPECT_TRUE(last_client_connection()->is_paused()); |
834 | 861 |
835 // Create the window for |embed_window_id2_in_child|. | 862 // Create the window for |embed_window_id2_in_child|. |
836 const WindowId embed_window_id2(wm_connection()->id(), 2); | 863 const ClientWindowId embed_window_id2 = |
| 864 BuildClientWindowId(wm_connection(), 2); |
837 EXPECT_TRUE( | 865 EXPECT_TRUE( |
838 wm_connection()->NewWindow(embed_window_id2, ServerWindow::Properties())); | 866 wm_connection()->NewWindow(embed_window_id2, ServerWindow::Properties())); |
839 EXPECT_TRUE(wm_connection()->AddWindow(FirstRoot(wm_connection())->id(), | 867 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()), |
840 embed_window_id2)); | 868 embed_window_id2)); |
841 | 869 |
842 // Ack the change, which should resume the binding. | 870 // Ack the change, which should resume the binding. |
843 static_cast<mojom::WindowManagerInternalClient*>(wm_connection()) | 871 static_cast<mojom::WindowManagerInternalClient*>(wm_connection()) |
844 ->OnWmCreatedTopLevelWindow(wm_change_id, | 872 ->OnWmCreatedTopLevelWindow(wm_change_id, embed_window_id2.id); |
845 WindowIdToTransportId(embed_window_id2)); | |
846 EXPECT_FALSE(last_client_connection()->is_paused()); | 873 EXPECT_FALSE(last_client_connection()->is_paused()); |
847 EXPECT_EQ("TopLevelCreated id=17 window_id=" + | 874 EXPECT_EQ("TopLevelCreated id=17 window_id=" + |
848 WindowIdToString(embed_window_id2_in_child), | 875 WindowIdToString( |
| 876 WindowIdFromTransportId(embed_window_id2_in_child.id)), |
849 SingleChangeToDescription(*embed_connection->tracker()->changes())); | 877 SingleChangeToDescription(*embed_connection->tracker()->changes())); |
850 embed_connection->tracker()->changes()->clear(); | 878 embed_connection->tracker()->changes()->clear(); |
851 | 879 |
852 // Change the visibility of the window from the owner and make sure the | 880 // Change the visibility of the window from the owner and make sure the |
853 // client sees the right id. | 881 // client sees the right id. |
854 ServerWindow* embed_window = wm_connection()->GetWindow(embed_window_id2); | 882 ServerWindow* embed_window = |
| 883 wm_connection()->GetWindowByClientId(embed_window_id2); |
855 ASSERT_TRUE(embed_window); | 884 ASSERT_TRUE(embed_window); |
856 EXPECT_FALSE(embed_window->visible()); | 885 EXPECT_FALSE(embed_window->visible()); |
857 ASSERT_TRUE(wm_connection()->SetWindowVisibility(embed_window->id(), true)); | 886 ASSERT_TRUE(wm_connection()->SetWindowVisibility( |
| 887 ClientWindowIdForWindow(wm_connection(), embed_window), true)); |
858 EXPECT_TRUE(embed_window->visible()); | 888 EXPECT_TRUE(embed_window->visible()); |
859 EXPECT_EQ("VisibilityChanged window=" + | 889 EXPECT_EQ("VisibilityChanged window=" + |
860 WindowIdToString(embed_window_id2_in_child) + " visible=true", | 890 WindowIdToString( |
| 891 WindowIdFromTransportId(embed_window_id2_in_child.id)) + |
| 892 " visible=true", |
861 SingleChangeToDescription(*embed_connection->tracker()->changes())); | 893 SingleChangeToDescription(*embed_connection->tracker()->changes())); |
862 | 894 |
863 // Set the visibility from the child using the client assigned id. | 895 // Set the visibility from the child using the client assigned id. |
864 ASSERT_TRUE(window_tree_connection->SetWindowVisibility( | 896 ASSERT_TRUE(window_tree_connection->SetWindowVisibility( |
865 embed_window_id2_in_child, false)); | 897 embed_window_id2_in_child, false)); |
866 EXPECT_FALSE(embed_window->visible()); | 898 EXPECT_FALSE(embed_window->visible()); |
867 } | 899 } |
868 | 900 |
869 } // namespace ws | 901 } // namespace ws |
870 } // namespace mus | 902 } // namespace mus |
OLD | NEW |