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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 | 658 |
659 // Only the capture window should be able to release capture | 659 // Only the capture window should be able to release capture |
660 mojom_window_tree->ReleaseCapture(++change_id, | 660 mojom_window_tree->ReleaseCapture(++change_id, |
661 WindowIdToTransportId(root_window->id())); | 661 WindowIdToTransportId(root_window->id())); |
662 EXPECT_EQ(window, GetCaptureWindow(display)); | 662 EXPECT_EQ(window, GetCaptureWindow(display)); |
663 mojom_window_tree->ReleaseCapture(++change_id, | 663 mojom_window_tree->ReleaseCapture(++change_id, |
664 WindowIdToTransportId(window->id())); | 664 WindowIdToTransportId(window->id())); |
665 EXPECT_EQ(nullptr, GetCaptureWindow(display)); | 665 EXPECT_EQ(nullptr, GetCaptureWindow(display)); |
666 } | 666 } |
667 | 667 |
| 668 // Tests that showing a modal window releases the capture if the capture is on a |
| 669 // descendant of the modal parent. |
| 670 TEST_F(WindowTreeTest, ShowModalWindowWithDescendantCapture) { |
| 671 TestWindowTreeClient* embed_connection = nullptr; |
| 672 WindowTree* tree = nullptr; |
| 673 ServerWindow* w1 = nullptr; |
| 674 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1)); |
| 675 |
| 676 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 677 const ServerWindow* root_window = *tree->roots().begin(); |
| 678 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); |
| 679 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); |
| 680 Display* display = tree->GetDisplay(w1); |
| 681 |
| 682 // Create |w11| as a child of |w1| and make it visible. |
| 683 ClientWindowId w11_id = BuildClientWindowId(tree, 11); |
| 684 ASSERT_TRUE(tree->NewWindow(w11_id, ServerWindow::Properties())); |
| 685 ServerWindow* w11 = tree->GetWindowByClientId(w11_id); |
| 686 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); |
| 687 ASSERT_TRUE(tree->AddWindow(w1_id, w11_id)); |
| 688 ASSERT_TRUE(tree->SetWindowVisibility(w11_id, true)); |
| 689 |
| 690 // Create |w2| as a child of |root_window| and modal to |w1| and leave it |
| 691 // hidden. |
| 692 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
| 693 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
| 694 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
| 695 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 696 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
| 697 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
| 698 ASSERT_TRUE(tree->SetModal(w2_id)); |
| 699 |
| 700 // Set capture to |w11|. |
| 701 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
| 702 ASSERT_TRUE(tree->SetCapture(w11_id)); |
| 703 EXPECT_EQ(w11, GetCaptureWindow(display)); |
| 704 AckPreviousEvent(); |
| 705 |
| 706 // Make |w2| visible. This should release capture as capture is set to a |
| 707 // descendant of the modal parent. |
| 708 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
| 709 EXPECT_EQ(nullptr, GetCaptureWindow(display)); |
| 710 } |
| 711 |
| 712 // Tests that setting a visible window as modal releases the capture if the |
| 713 // capture is on a descendant of the modal parent. |
| 714 TEST_F(WindowTreeTest, VisibleWindowToModalWithDescendantCapture) { |
| 715 TestWindowTreeClient* embed_connection = nullptr; |
| 716 WindowTree* tree = nullptr; |
| 717 ServerWindow* w1 = nullptr; |
| 718 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1)); |
| 719 |
| 720 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 721 const ServerWindow* root_window = *tree->roots().begin(); |
| 722 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); |
| 723 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); |
| 724 Display* display = tree->GetDisplay(w1); |
| 725 |
| 726 // Create |w11| as a child of |w1| and make it visible. |
| 727 ClientWindowId w11_id = BuildClientWindowId(tree, 11); |
| 728 ASSERT_TRUE(tree->NewWindow(w11_id, ServerWindow::Properties())); |
| 729 ServerWindow* w11 = tree->GetWindowByClientId(w11_id); |
| 730 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); |
| 731 ASSERT_TRUE(tree->AddWindow(w1_id, w11_id)); |
| 732 ASSERT_TRUE(tree->SetWindowVisibility(w11_id, true)); |
| 733 |
| 734 // Create |w2| as a child of |root_window| and make it visible. |
| 735 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
| 736 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
| 737 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
| 738 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 739 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
| 740 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
| 741 |
| 742 // Set capture to |w11|. |
| 743 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
| 744 ASSERT_TRUE(tree->SetCapture(w11_id)); |
| 745 EXPECT_EQ(w11, GetCaptureWindow(display)); |
| 746 AckPreviousEvent(); |
| 747 |
| 748 // Set |w2| modal to |w1|. This should release the capture as the capture is |
| 749 // set to a descendant of the modal parent. |
| 750 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
| 751 ASSERT_TRUE(tree->SetModal(w2_id)); |
| 752 EXPECT_EQ(nullptr, GetCaptureWindow(display)); |
| 753 } |
| 754 |
| 755 // Tests that showing a modal window does not change capture if the capture is |
| 756 // not on a descendant of the modal parent. |
| 757 TEST_F(WindowTreeTest, ShowModalWindowWithNonDescendantCapture) { |
| 758 TestWindowTreeClient* embed_connection = nullptr; |
| 759 WindowTree* tree = nullptr; |
| 760 ServerWindow* w1 = nullptr; |
| 761 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1)); |
| 762 |
| 763 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 764 const ServerWindow* root_window = *tree->roots().begin(); |
| 765 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); |
| 766 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); |
| 767 Display* display = tree->GetDisplay(w1); |
| 768 |
| 769 // Create |w2| as a child of |root_window| and modal to |w1| and leave it |
| 770 // hidden.. |
| 771 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
| 772 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
| 773 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
| 774 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 775 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
| 776 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
| 777 ASSERT_TRUE(tree->SetModal(w2_id)); |
| 778 |
| 779 // Create |w3| as a child of |root_window| and make it visible. |
| 780 ClientWindowId w3_id = BuildClientWindowId(tree, 3); |
| 781 ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties())); |
| 782 ServerWindow* w3 = tree->GetWindowByClientId(w3_id); |
| 783 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
| 784 ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id)); |
| 785 ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true)); |
| 786 |
| 787 // Set capture to |w3|. |
| 788 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
| 789 ASSERT_TRUE(tree->SetCapture(w3_id)); |
| 790 EXPECT_EQ(w3, GetCaptureWindow(display)); |
| 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, GetCaptureWindow(display)); |
| 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 |
| 813 // Create |w2| and |w3| as children of |root_window| and make them visible. |
| 814 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
| 815 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
| 816 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
| 817 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 818 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
| 819 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
| 820 |
| 821 ClientWindowId w3_id = BuildClientWindowId(tree, 3); |
| 822 ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties())); |
| 823 ServerWindow* w3 = tree->GetWindowByClientId(w3_id); |
| 824 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
| 825 ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id)); |
| 826 ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true)); |
| 827 |
| 828 // Set capture to |w3|. |
| 829 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
| 830 ASSERT_TRUE(tree->SetCapture(w3_id)); |
| 831 EXPECT_EQ(w3, GetCaptureWindow(display)); |
| 832 AckPreviousEvent(); |
| 833 |
| 834 // Set |w2| modal to |w1|. This should not release the capture as the capture |
| 835 // is not set to a descendant of the modal parent. |
| 836 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
| 837 ASSERT_TRUE(tree->SetModal(w2_id)); |
| 838 EXPECT_EQ(w3, GetCaptureWindow(display)); |
| 839 } |
| 840 |
| 841 // Tests that moving the capture window to a modal parent releases the capture |
| 842 // as capture cannot be blocked by a modal window. |
| 843 TEST_F(WindowTreeTest, MoveCaptureWindowToModalParent) { |
| 844 TestWindowTreeClient* embed_connection = nullptr; |
| 845 WindowTree* tree = nullptr; |
| 846 ServerWindow* w1 = nullptr; |
| 847 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1)); |
| 848 |
| 849 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 850 const ServerWindow* root_window = *tree->roots().begin(); |
| 851 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); |
| 852 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); |
| 853 Display* display = tree->GetDisplay(w1); |
| 854 |
| 855 // Create |w2| and |w3| as children of |root_window| and make them visible. |
| 856 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
| 857 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
| 858 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
| 859 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 860 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
| 861 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
| 862 |
| 863 ClientWindowId w3_id = BuildClientWindowId(tree, 3); |
| 864 ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties())); |
| 865 ServerWindow* w3 = tree->GetWindowByClientId(w3_id); |
| 866 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
| 867 ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id)); |
| 868 ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true)); |
| 869 |
| 870 // Set |w2| modal to |w1|. |
| 871 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
| 872 ASSERT_TRUE(tree->SetModal(w2_id)); |
| 873 |
| 874 // Set capture to |w3|. |
| 875 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
| 876 ASSERT_TRUE(tree->SetCapture(w3_id)); |
| 877 EXPECT_EQ(w3, GetCaptureWindow(display)); |
| 878 AckPreviousEvent(); |
| 879 |
| 880 // Make |w3| child of |w1|. This should release capture as |w3| is now blocked |
| 881 // by a modal window. |
| 882 ASSERT_TRUE(tree->AddWindow(w1_id, w3_id)); |
| 883 EXPECT_EQ(nullptr, GetCaptureWindow(display)); |
| 884 } |
| 885 |
668 } // namespace test | 886 } // namespace test |
669 } // namespace ws | 887 } // namespace ws |
670 } // namespace mus | 888 } // namespace mus |
OLD | NEW |