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 "services/ui/ws/window_tree.h" | 5 #include "services/ui/ws/window_tree.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 ASSERT_TRUE(tree->SetWindowVisibility(w11_id, true)); | 795 ASSERT_TRUE(tree->SetWindowVisibility(w11_id, true)); |
796 | 796 |
797 // Create |w2| as a child of |root_window| and modal to |w1| and leave it | 797 // Create |w2| as a child of |root_window| and modal to |w1| and leave it |
798 // hidden. | 798 // hidden. |
799 ClientWindowId w2_id = BuildClientWindowId(tree, 2); | 799 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
800 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); | 800 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
801 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); | 801 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
802 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); | 802 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
803 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); | 803 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
804 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); | 804 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
805 ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_WINDOW)); | 805 ASSERT_TRUE(tree->SetModalType(w2, MODAL_TYPE_WINDOW)); |
806 | 806 |
807 // Set capture to |w11|. | 807 // Set capture to |w11|. |
808 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); | 808 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
809 ASSERT_TRUE(tree->SetCapture(w11_id)); | 809 ASSERT_TRUE(tree->SetCapture(w11_id)); |
810 EXPECT_EQ(w11, GetCaptureWindow(display)); | 810 EXPECT_EQ(w11, GetCaptureWindow(display)); |
811 AckPreviousEvent(); | 811 AckPreviousEvent(); |
812 | 812 |
813 // Make |w2| visible. This should release capture as capture is set to a | 813 // Make |w2| visible. This should release capture as capture is set to a |
814 // descendant of the modal parent. | 814 // descendant of the modal parent. |
815 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); | 815 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 | 848 |
849 // Set capture to |w11|. | 849 // Set capture to |w11|. |
850 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); | 850 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
851 ASSERT_TRUE(tree->SetCapture(w11_id)); | 851 ASSERT_TRUE(tree->SetCapture(w11_id)); |
852 EXPECT_EQ(w11, GetCaptureWindow(display)); | 852 EXPECT_EQ(w11, GetCaptureWindow(display)); |
853 AckPreviousEvent(); | 853 AckPreviousEvent(); |
854 | 854 |
855 // Set |w2| modal to |w1|. This should release the capture as the capture is | 855 // Set |w2| modal to |w1|. This should release the capture as the capture is |
856 // set to a descendant of the modal parent. | 856 // set to a descendant of the modal parent. |
857 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); | 857 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
858 ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_WINDOW)); | 858 ASSERT_TRUE(tree->SetModalType(w2, MODAL_TYPE_WINDOW)); |
859 EXPECT_EQ(nullptr, GetCaptureWindow(display)); | 859 EXPECT_EQ(nullptr, GetCaptureWindow(display)); |
860 } | 860 } |
861 | 861 |
862 // Tests that showing a modal window does not change capture if the capture is | 862 // Tests that showing a modal window does not change capture if the capture is |
863 // not on a descendant of the modal parent. | 863 // not on a descendant of the modal parent. |
864 TEST_F(WindowTreeTest, ShowModalWindowWithNonDescendantCapture) { | 864 TEST_F(WindowTreeTest, ShowModalWindowWithNonDescendantCapture) { |
865 TestWindowTreeClient* embed_client = nullptr; | 865 TestWindowTreeClient* embed_client = nullptr; |
866 WindowTree* tree = nullptr; | 866 WindowTree* tree = nullptr; |
867 ServerWindow* w1 = nullptr; | 867 ServerWindow* w1 = nullptr; |
868 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1)); | 868 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1)); |
869 | 869 |
870 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 870 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
871 const ServerWindow* root_window = *tree->roots().begin(); | 871 const ServerWindow* root_window = *tree->roots().begin(); |
872 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); | 872 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); |
873 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); | 873 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); |
874 Display* display = tree->GetDisplay(w1); | 874 Display* display = tree->GetDisplay(w1); |
875 | 875 |
876 // Create |w2| as a child of |root_window| and modal to |w1| and leave it | 876 // Create |w2| as a child of |root_window| and modal to |w1| and leave it |
877 // hidden. | 877 // hidden. |
878 ClientWindowId w2_id = BuildClientWindowId(tree, 2); | 878 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
879 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); | 879 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
880 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); | 880 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
881 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); | 881 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
882 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); | 882 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
883 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); | 883 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
884 ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_WINDOW)); | 884 ASSERT_TRUE(tree->SetModalType(w2, MODAL_TYPE_WINDOW)); |
885 | 885 |
886 // Create |w3| as a child of |root_window| and make it visible. | 886 // Create |w3| as a child of |root_window| and make it visible. |
887 ClientWindowId w3_id = BuildClientWindowId(tree, 3); | 887 ClientWindowId w3_id = BuildClientWindowId(tree, 3); |
888 ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties())); | 888 ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties())); |
889 ServerWindow* w3 = tree->GetWindowByClientId(w3_id); | 889 ServerWindow* w3 = tree->GetWindowByClientId(w3_id); |
890 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); | 890 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
891 ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id)); | 891 ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id)); |
892 ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true)); | 892 ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true)); |
893 | 893 |
894 // Set capture to |w3|. | 894 // Set capture to |w3|. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 | 934 |
935 // Set capture to |w3|. | 935 // Set capture to |w3|. |
936 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); | 936 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
937 ASSERT_TRUE(tree->SetCapture(w3_id)); | 937 ASSERT_TRUE(tree->SetCapture(w3_id)); |
938 EXPECT_EQ(w3, GetCaptureWindow(display)); | 938 EXPECT_EQ(w3, GetCaptureWindow(display)); |
939 AckPreviousEvent(); | 939 AckPreviousEvent(); |
940 | 940 |
941 // Set |w2| modal to |w1|. This should not release the capture as the capture | 941 // Set |w2| modal to |w1|. This should not release the capture as the capture |
942 // is not set to a descendant of the modal parent. | 942 // is not set to a descendant of the modal parent. |
943 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); | 943 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
944 ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_WINDOW)); | 944 ASSERT_TRUE(tree->SetModalType(w2, MODAL_TYPE_WINDOW)); |
945 EXPECT_EQ(w3, GetCaptureWindow(display)); | 945 EXPECT_EQ(w3, GetCaptureWindow(display)); |
946 } | 946 } |
947 | 947 |
948 // Tests that showing a system modal window releases the capture. | 948 // Tests that showing a system modal window releases the capture. |
949 TEST_F(WindowTreeTest, ShowSystemModalWindowWithCapture) { | 949 TEST_F(WindowTreeTest, ShowSystemModalWindowWithCapture) { |
950 TestWindowTreeClient* embed_client = nullptr; | 950 TestWindowTreeClient* embed_client = nullptr; |
951 WindowTree* tree = nullptr; | 951 WindowTree* tree = nullptr; |
952 ServerWindow* w1 = nullptr; | 952 ServerWindow* w1 = nullptr; |
953 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1)); | 953 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1)); |
954 | 954 |
955 w1->SetBounds(gfx::Rect(10, 10, 10, 10)); | 955 w1->SetBounds(gfx::Rect(10, 10, 10, 10)); |
956 const ServerWindow* root_window = *tree->roots().begin(); | 956 const ServerWindow* root_window = *tree->roots().begin(); |
957 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); | 957 ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window); |
958 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); | 958 ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1); |
959 Display* display = tree->GetDisplay(w1); | 959 Display* display = tree->GetDisplay(w1); |
960 | 960 |
961 // Create a system modal window |w2| as a child of |root_window| and leave it | 961 // Create a system modal window |w2| as a child of |root_window| and leave it |
962 // hidden. | 962 // hidden. |
963 ClientWindowId w2_id = BuildClientWindowId(tree, 2); | 963 ClientWindowId w2_id = BuildClientWindowId(tree, 2); |
964 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); | 964 ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties())); |
965 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); | 965 ServerWindow* w2 = tree->GetWindowByClientId(w2_id); |
966 w2->SetBounds(gfx::Rect(30, 10, 10, 10)); | 966 w2->SetBounds(gfx::Rect(30, 10, 10, 10)); |
967 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); | 967 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
968 ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_SYSTEM)); | 968 ASSERT_TRUE(tree->SetModalType(w2, MODAL_TYPE_SYSTEM)); |
969 | 969 |
970 // Set capture to |w1|. | 970 // Set capture to |w1|. |
971 DispatchEventWithoutAck(CreatePointerDownEvent(15, 15)); | 971 DispatchEventWithoutAck(CreatePointerDownEvent(15, 15)); |
972 ASSERT_TRUE(tree->SetCapture(w1_id)); | 972 ASSERT_TRUE(tree->SetCapture(w1_id)); |
973 EXPECT_EQ(w1, GetCaptureWindow(display)); | 973 EXPECT_EQ(w1, GetCaptureWindow(display)); |
974 AckPreviousEvent(); | 974 AckPreviousEvent(); |
975 | 975 |
976 // Make |w2| visible. This should release capture as it is system modal | 976 // Make |w2| visible. This should release capture as it is system modal |
977 // window. | 977 // window. |
978 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); | 978 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
(...skipping 21 matching lines...) Expand all Loading... |
1000 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); | 1000 ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id)); |
1001 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); | 1001 ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true)); |
1002 | 1002 |
1003 // Set capture to |w1|. | 1003 // Set capture to |w1|. |
1004 DispatchEventWithoutAck(CreatePointerDownEvent(15, 15)); | 1004 DispatchEventWithoutAck(CreatePointerDownEvent(15, 15)); |
1005 ASSERT_TRUE(tree->SetCapture(w1_id)); | 1005 ASSERT_TRUE(tree->SetCapture(w1_id)); |
1006 EXPECT_EQ(w1, GetCaptureWindow(display)); | 1006 EXPECT_EQ(w1, GetCaptureWindow(display)); |
1007 AckPreviousEvent(); | 1007 AckPreviousEvent(); |
1008 | 1008 |
1009 // Make |w2| modal to system. This should release capture. | 1009 // Make |w2| modal to system. This should release capture. |
1010 ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_SYSTEM)); | 1010 ASSERT_TRUE(tree->SetModalType(w2, MODAL_TYPE_SYSTEM)); |
1011 EXPECT_EQ(nullptr, GetCaptureWindow(display)); | 1011 EXPECT_EQ(nullptr, GetCaptureWindow(display)); |
1012 } | 1012 } |
1013 | 1013 |
1014 // Tests that moving the capture window to a modal parent releases the capture | 1014 // Tests that moving the capture window to a modal parent releases the capture |
1015 // as capture cannot be blocked by a modal window. | 1015 // as capture cannot be blocked by a modal window. |
1016 TEST_F(WindowTreeTest, MoveCaptureWindowToModalParent) { | 1016 TEST_F(WindowTreeTest, MoveCaptureWindowToModalParent) { |
1017 TestWindowTreeClient* embed_client = nullptr; | 1017 TestWindowTreeClient* embed_client = nullptr; |
1018 WindowTree* tree = nullptr; | 1018 WindowTree* tree = nullptr; |
1019 ServerWindow* w1 = nullptr; | 1019 ServerWindow* w1 = nullptr; |
1020 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1)); | 1020 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1)); |
(...skipping 14 matching lines...) Expand all Loading... |
1035 | 1035 |
1036 ClientWindowId w3_id = BuildClientWindowId(tree, 3); | 1036 ClientWindowId w3_id = BuildClientWindowId(tree, 3); |
1037 ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties())); | 1037 ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties())); |
1038 ServerWindow* w3 = tree->GetWindowByClientId(w3_id); | 1038 ServerWindow* w3 = tree->GetWindowByClientId(w3_id); |
1039 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); | 1039 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
1040 ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id)); | 1040 ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id)); |
1041 ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true)); | 1041 ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true)); |
1042 | 1042 |
1043 // Set |w2| modal to |w1|. | 1043 // Set |w2| modal to |w1|. |
1044 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); | 1044 ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id)); |
1045 ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_WINDOW)); | 1045 ASSERT_TRUE(tree->SetModalType(w2, MODAL_TYPE_WINDOW)); |
1046 | 1046 |
1047 // Set capture to |w3|. | 1047 // Set capture to |w3|. |
1048 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); | 1048 DispatchEventWithoutAck(CreatePointerDownEvent(25, 25)); |
1049 ASSERT_TRUE(tree->SetCapture(w3_id)); | 1049 ASSERT_TRUE(tree->SetCapture(w3_id)); |
1050 EXPECT_EQ(w3, GetCaptureWindow(display)); | 1050 EXPECT_EQ(w3, GetCaptureWindow(display)); |
1051 AckPreviousEvent(); | 1051 AckPreviousEvent(); |
1052 | 1052 |
1053 // Make |w3| child of |w1|. This should release capture as |w3| is now blocked | 1053 // Make |w3| child of |w1|. This should release capture as |w3| is now blocked |
1054 // by a modal window. | 1054 // by a modal window. |
1055 ASSERT_TRUE(tree->AddWindow(w1_id, w3_id)); | 1055 ASSERT_TRUE(tree->AddWindow(w1_id, w3_id)); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1421 client->tracker()->changes()->clear(); | 1421 client->tracker()->changes()->clear(); |
1422 } | 1422 } |
1423 | 1423 |
1424 // Client should not have got any messages after shutdown. | 1424 // Client should not have got any messages after shutdown. |
1425 EXPECT_TRUE(client->tracker()->changes()->empty()); | 1425 EXPECT_TRUE(client->tracker()->changes()->empty()); |
1426 } | 1426 } |
1427 | 1427 |
1428 } // namespace test | 1428 } // namespace test |
1429 } // namespace ws | 1429 } // namespace ws |
1430 } // namespace ui | 1430 } // namespace ui |
OLD | NEW |