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 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 | 652 |
653 // Only the capture window should be able to release capture | 653 // Only the capture window should be able to release capture |
654 mojom_window_tree->ReleaseCapture(++change_id, | 654 mojom_window_tree->ReleaseCapture(++change_id, |
655 WindowIdToTransportId(root_window->id())); | 655 WindowIdToTransportId(root_window->id())); |
656 EXPECT_EQ(window, display->GetCaptureWindow()); | 656 EXPECT_EQ(window, display->GetCaptureWindow()); |
657 mojom_window_tree->ReleaseCapture(++change_id, | 657 mojom_window_tree->ReleaseCapture(++change_id, |
658 WindowIdToTransportId(window->id())); | 658 WindowIdToTransportId(window->id())); |
659 EXPECT_EQ(nullptr, display->GetCaptureWindow()); | 659 EXPECT_EQ(nullptr, display->GetCaptureWindow()); |
660 } | 660 } |
661 | 661 |
| 662 // Tests that showing a modal window releases the capture if the capture is on a |
| 663 // descendant of the modal parent. |
| 664 TEST_F(WindowTreeTest, ShowModalWindowWithDescendantCapture) { |
| 665 TestWindowTreeClient* embed_connection = nullptr; |
| 666 WindowTree* tree = nullptr; |
| 667 ServerWindow* w1 = nullptr; |
| 668 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1)); |
| 669 |
| 670 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 671 const ServerWindow* root_window = *tree->roots().begin(); |
| 672 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); |
| 673 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); |
| 674 Display* display = tree->GetDisplay(w1); |
| 675 mojom::WindowTree* mojom_window_tree = tree; |
| 676 |
| 677 // Create |w11| as a child of |w1| and make it visible. |
| 678 ClientWindowId w11_id = BuildClientWindowId(tree, 11); |
| 679 ASSERT_TRUE(tree->NewWindow(w11_id, ServerWindow::Properties())); |
| 680 ServerWindow* w11 = tree->GetWindowByClientId(w11_id); |
| 681 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); |
| 682 ASSERT_TRUE(tree->AddWindow(w1_id, w11_id)); |
| 683 ASSERT_TRUE(tree->SetWindowVisibility(w11_id, true)); |
| 684 |
| 685 // Create |w2| as a child of |root_window| and modal to |w1| and leave it |
| 686 // hidden. |
| 687 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
| 688 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
| 689 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
| 690 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 691 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
| 692 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
| 693 ASSERT_TRUE(tree->SetAsModal(w2_id)); |
| 694 |
| 695 // Set capture to |w11|. |
| 696 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
| 697 uint32_t change_id = 42; |
| 698 mojom_window_tree->SetCapture(change_id, w11_id.id); |
| 699 EXPECT_EQ(w11, display->GetCaptureWindow()); |
| 700 AckPreviousEvent(); |
| 701 |
| 702 // Make |w2| visible. This should release capture as capture is set to a |
| 703 // descendant of the modal parent. |
| 704 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
| 705 EXPECT_EQ(nullptr, display->GetCaptureWindow()); |
| 706 } |
| 707 |
| 708 // Tests that setting a visible window as modal releases the capture if the |
| 709 // capture is on a descendant of the modal parent. |
| 710 TEST_F(WindowTreeTest, VisibleWindowToModalWithDescendantCapture) { |
| 711 TestWindowTreeClient* embed_connection = nullptr; |
| 712 WindowTree* tree = nullptr; |
| 713 ServerWindow* w1 = nullptr; |
| 714 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1)); |
| 715 |
| 716 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 717 const ServerWindow* root_window = *tree->roots().begin(); |
| 718 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); |
| 719 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); |
| 720 Display* display = tree->GetDisplay(w1); |
| 721 mojom::WindowTree* mojom_window_tree = tree; |
| 722 |
| 723 // Create |w11| as a child of |w1| and make it visible. |
| 724 ClientWindowId w11_id = BuildClientWindowId(tree, 11); |
| 725 ASSERT_TRUE(tree->NewWindow(w11_id, ServerWindow::Properties())); |
| 726 ServerWindow* w11 = tree->GetWindowByClientId(w11_id); |
| 727 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); |
| 728 ASSERT_TRUE(tree->AddWindow(w1_id, w11_id)); |
| 729 ASSERT_TRUE(tree->SetWindowVisibility(w11_id, true)); |
| 730 |
| 731 // Create |w2| as a child of |root_window| and make it visible. |
| 732 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
| 733 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
| 734 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
| 735 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 736 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
| 737 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
| 738 |
| 739 // Set capture to |w11|. |
| 740 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
| 741 uint32_t change_id = 42; |
| 742 mojom_window_tree->SetCapture(change_id, w11_id.id); |
| 743 EXPECT_EQ(w11, display->GetCaptureWindow()); |
| 744 AckPreviousEvent(); |
| 745 |
| 746 // Set |w2| modal to |w1|. This should release the capture as the capture is |
| 747 // set to a descendant of the modal parent. |
| 748 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
| 749 ASSERT_TRUE(tree->SetAsModal(w2_id)); |
| 750 EXPECT_EQ(nullptr, display->GetCaptureWindow()); |
| 751 } |
| 752 |
| 753 // Tests that showing a modal window does not change capture if the capture is |
| 754 // not on a descendant of the modal parent. |
| 755 TEST_F(WindowTreeTest, ShowModalWindowWithNonDescendantCapture) { |
| 756 TestWindowTreeClient* embed_connection = nullptr; |
| 757 WindowTree* tree = nullptr; |
| 758 ServerWindow* w1 = nullptr; |
| 759 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1)); |
| 760 |
| 761 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 762 const ServerWindow* root_window = *tree->roots().begin(); |
| 763 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); |
| 764 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); |
| 765 Display* display = tree->GetDisplay(w1); |
| 766 mojom::WindowTree* mojom_window_tree = tree; |
| 767 |
| 768 // Create |w2| as a child of |root_window| and modal to |w1| and leave it |
| 769 // hidden.. |
| 770 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
| 771 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
| 772 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
| 773 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 774 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
| 775 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
| 776 ASSERT_TRUE(tree->SetAsModal(w2_id)); |
| 777 |
| 778 // Create |w3| as a child of |root_window| and make it visible. |
| 779 ClientWindowId w3_id = BuildClientWindowId(tree, 3); |
| 780 ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties())); |
| 781 ServerWindow* w3 = tree->GetWindowByClientId(w3_id); |
| 782 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
| 783 ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id)); |
| 784 ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true)); |
| 785 |
| 786 // Set capture to |w3|. |
| 787 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
| 788 uint32_t change_id = 42; |
| 789 mojom_window_tree->SetCapture(change_id, w3_id.id); |
| 790 EXPECT_EQ(w3, display->GetCaptureWindow()); |
| 791 AckPreviousEvent(); |
| 792 |
| 793 // Make |w2| visible. This should not change the capture as the capture is not |
| 794 // set to a descendant of the modal parent. |
| 795 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
| 796 EXPECT_EQ(w3, display->GetCaptureWindow()); |
| 797 } |
| 798 |
| 799 // Tests that setting a visible window as modal does not change the capture if |
| 800 // the capture is not set to a descendant of the modal parent. |
| 801 TEST_F(WindowTreeTest, VisibleWindowToModalWithNonDescendantCapture) { |
| 802 TestWindowTreeClient* embed_connection = nullptr; |
| 803 WindowTree* tree = nullptr; |
| 804 ServerWindow* w1 = nullptr; |
| 805 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1)); |
| 806 |
| 807 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 808 const ServerWindow* root_window = *tree->roots().begin(); |
| 809 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); |
| 810 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); |
| 811 Display* display = tree->GetDisplay(w1); |
| 812 mojom::WindowTree* mojom_window_tree = tree; |
| 813 |
| 814 // Create |w2| and |w3| as children of |root_window| and make them visible. |
| 815 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
| 816 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
| 817 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
| 818 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 819 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
| 820 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
| 821 |
| 822 ClientWindowId w3_id = BuildClientWindowId(tree, 3); |
| 823 ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties())); |
| 824 ServerWindow* w3 = tree->GetWindowByClientId(w3_id); |
| 825 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
| 826 ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id)); |
| 827 ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true)); |
| 828 |
| 829 // Set capture to |w3|. |
| 830 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
| 831 uint32_t change_id = 42; |
| 832 mojom_window_tree->SetCapture(change_id, w3_id.id); |
| 833 EXPECT_EQ(w3, display->GetCaptureWindow()); |
| 834 AckPreviousEvent(); |
| 835 |
| 836 // Set |w2| modal to |w1|. This should not release the capture as the capture |
| 837 // is not set to a descendant of the modal parent. |
| 838 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
| 839 ASSERT_TRUE(tree->SetAsModal(w2_id)); |
| 840 EXPECT_EQ(w3, display->GetCaptureWindow()); |
| 841 } |
| 842 |
662 } // namespace test | 843 } // namespace test |
663 } // namespace ws | 844 } // namespace ws |
664 } // namespace mus | 845 } // namespace mus |
OLD | NEW |