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