Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: services/ui/ws/window_manager_client_unittest.cc

Issue 2301353003: Changes ownership of WindowTreeClient (Closed)
Patch Set: fix navigation Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/test_wm/test_wm.cc ('k') | ui/views/mus/window_manager_connection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 WaitForWindowToHaveFocus(focused[index]); 924 WaitForWindowToHaveFocus(focused[index]);
925 EXPECT_TRUE(focused[index]->HasFocus()); 925 EXPECT_TRUE(focused[index]->HasFocus());
926 EXPECT_EQ(parent->children().back(), expecteds[index]); 926 EXPECT_EQ(parent->children().back(), expecteds[index]);
927 } 927 }
928 } 928 }
929 929
930 namespace { 930 namespace {
931 931
932 class DestroyedChangedObserver : public WindowObserver { 932 class DestroyedChangedObserver : public WindowObserver {
933 public: 933 public:
934 DestroyedChangedObserver(WindowServerTestBase* test, 934 DestroyedChangedObserver(Window* window, bool* got_destroy)
935 Window* window, 935 : window_(window), got_destroy_(got_destroy) {
936 bool* got_destroy)
937 : test_(test), window_(window), got_destroy_(got_destroy) {
938 window_->AddObserver(this); 936 window_->AddObserver(this);
939 } 937 }
940 ~DestroyedChangedObserver() override { 938 ~DestroyedChangedObserver() override {
941 if (window_) 939 if (window_)
942 window_->RemoveObserver(this); 940 window_->RemoveObserver(this);
943 } 941 }
944 942
945 private: 943 private:
946 // Overridden from WindowObserver: 944 // Overridden from WindowObserver:
947 void OnWindowDestroyed(Window* window) override { 945 void OnWindowDestroyed(Window* window) override {
948 EXPECT_EQ(window, window_); 946 EXPECT_EQ(window, window_);
949 window_->RemoveObserver(this); 947 window_->RemoveObserver(this);
950 *got_destroy_ = true; 948 *got_destroy_ = true;
951 window_ = nullptr; 949 window_ = nullptr;
952
953 // We should always get OnWindowDestroyed() before
954 // OnDidDestroyClient().
955 EXPECT_FALSE(test_->window_tree_client_destroyed());
956 } 950 }
957 951
958 WindowServerTestBase* test_;
959 Window* window_; 952 Window* window_;
960 bool* got_destroy_; 953 bool* got_destroy_;
961 954
962 DISALLOW_COPY_AND_ASSIGN(DestroyedChangedObserver); 955 DISALLOW_COPY_AND_ASSIGN(DestroyedChangedObserver);
963 }; 956 };
964 957
965 } // namespace 958 } // namespace
966 959
967 // Verifies deleting a WindowServer sends the right notifications. 960 // Verifies deleting a WindowServer sends the right notifications.
968 TEST_F(WindowServerTest, DeleteWindowServer) { 961 TEST_F(WindowServerTest, DeleteWindowServer) {
969 Window* window = window_manager()->NewWindow(); 962 Window* window = window_manager()->NewWindow();
970 ASSERT_NE(nullptr, window); 963 ASSERT_NE(nullptr, window);
971 window->SetVisible(true); 964 window->SetVisible(true);
972 GetFirstWMRoot()->AddChild(window); 965 GetFirstWMRoot()->AddChild(window);
973 WindowTreeClient* client = Embed(window).client; 966 WindowTreeClient* client = Embed(window).client;
974 ASSERT_TRUE(client); 967 ASSERT_TRUE(client);
975 bool got_destroy = false; 968 bool got_destroy = false;
976 DestroyedChangedObserver observer(this, GetFirstRoot(client), 969 DestroyedChangedObserver observer(GetFirstRoot(client), &got_destroy);
977 &got_destroy); 970 DeleteWindowTreeClient(client);
978 delete client;
979 EXPECT_TRUE(window_tree_client_destroyed());
980 EXPECT_TRUE(got_destroy); 971 EXPECT_TRUE(got_destroy);
981 } 972 }
982 973
983 // Verifies two Embed()s in the same window trigger deletion of the first
984 // WindowServer.
985 TEST_F(WindowServerTest, DisconnectTriggersDelete) {
986 Window* window = window_manager()->NewWindow();
987 ASSERT_NE(nullptr, window);
988 window->SetVisible(true);
989 GetFirstWMRoot()->AddChild(window);
990 WindowTreeClient* client = Embed(window).client;
991 EXPECT_NE(client, window_manager());
992 Window* embedded_window = client->NewWindow();
993 // Embed again, this should trigger disconnect and deletion of client.
994 bool got_destroy;
995 DestroyedChangedObserver observer(this, embedded_window, &got_destroy);
996 EXPECT_FALSE(window_tree_client_destroyed());
997 Embed(window);
998 EXPECT_TRUE(window_tree_client_destroyed());
999 }
1000
1001 class WindowRemovedFromParentObserver : public WindowObserver { 974 class WindowRemovedFromParentObserver : public WindowObserver {
1002 public: 975 public:
1003 explicit WindowRemovedFromParentObserver(Window* window) 976 explicit WindowRemovedFromParentObserver(Window* window)
1004 : window_(window), was_removed_(false) { 977 : window_(window), was_removed_(false) {
1005 window_->AddObserver(this); 978 window_->AddObserver(this);
1006 } 979 }
1007 ~WindowRemovedFromParentObserver() override { window_->RemoveObserver(this); } 980 ~WindowRemovedFromParentObserver() override { window_->RemoveObserver(this); }
1008 981
1009 bool was_removed() const { return was_removed_; } 982 bool was_removed() const { return was_removed_; }
1010 983
(...skipping 25 matching lines...) Expand all
1036 // Run the message loop so the Embed() call above completes. Without this 1009 // Run the message loop so the Embed() call above completes. Without this
1037 // we may end up reconnecting to the test and rerunning the test, which is 1010 // we may end up reconnecting to the test and rerunning the test, which is
1038 // problematic since the other services don't shut down. 1011 // problematic since the other services don't shut down.
1039 ASSERT_TRUE(DoRunLoopWithTimeout()); 1012 ASSERT_TRUE(DoRunLoopWithTimeout());
1040 } 1013 }
1041 1014
1042 namespace { 1015 namespace {
1043 1016
1044 class DestroyObserver : public WindowObserver { 1017 class DestroyObserver : public WindowObserver {
1045 public: 1018 public:
1046 DestroyObserver(WindowServerTestBase* test, 1019 DestroyObserver(WindowTreeClient* client, bool* got_destroy)
1047 WindowTreeClient* client, 1020 : got_destroy_(got_destroy) {
1048 bool* got_destroy)
1049 : test_(test), got_destroy_(got_destroy) {
1050 GetFirstRoot(client)->AddObserver(this); 1021 GetFirstRoot(client)->AddObserver(this);
1051 } 1022 }
1052 ~DestroyObserver() override {} 1023 ~DestroyObserver() override {}
1053 1024
1054 private: 1025 private:
1055 // Overridden from WindowObserver: 1026 // Overridden from WindowObserver:
1056 void OnWindowDestroyed(Window* window) override { 1027 void OnWindowDestroyed(Window* window) override {
1057 *got_destroy_ = true; 1028 *got_destroy_ = true;
1058 window->RemoveObserver(this); 1029 window->RemoveObserver(this);
1059 1030
1060 // We should always get OnWindowDestroyed() before
1061 // OnWindowManagerDestroyed().
1062 EXPECT_FALSE(test_->window_tree_client_destroyed());
1063
1064 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); 1031 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
1065 } 1032 }
1066 1033
1067 WindowServerTestBase* test_;
1068 bool* got_destroy_; 1034 bool* got_destroy_;
1069 1035
1070 DISALLOW_COPY_AND_ASSIGN(DestroyObserver); 1036 DISALLOW_COPY_AND_ASSIGN(DestroyObserver);
1071 }; 1037 };
1072 1038
1073 } // namespace 1039 } // namespace
1074 1040
1075 // Verifies deleting a Window that is the root of another client notifies 1041 // Verifies deleting a Window that is the root of another client notifies
1076 // observers in the right order (OnWindowDestroyed() before 1042 // observers in the right order (OnWindowDestroyed() before
1077 // OnWindowManagerDestroyed()). 1043 // OnWindowManagerDestroyed()).
1078 TEST_F(WindowServerTest, WindowServerDestroyedAfterRootObserver) { 1044 TEST_F(WindowServerTest, WindowServerDestroyedAfterRootObserver) {
1079 Window* embed_window = window_manager()->NewWindow(); 1045 Window* embed_window = window_manager()->NewWindow();
1080 GetFirstWMRoot()->AddChild(embed_window); 1046 GetFirstWMRoot()->AddChild(embed_window);
1081 1047
1082 WindowTreeClient* embedded_client = Embed(embed_window).client; 1048 WindowTreeClient* embedded_client = Embed(embed_window).client;
1083 1049
1084 bool got_destroy = false; 1050 bool got_destroy = false;
1085 DestroyObserver observer(this, embedded_client, &got_destroy); 1051 DestroyObserver observer(embedded_client, &got_destroy);
1086 // Delete the window |embedded_client| is embedded in. This is async, 1052 // Delete the window |embedded_client| is embedded in. This is async,
1087 // but will eventually trigger deleting |embedded_client|. 1053 // but will eventually trigger deleting |embedded_client|.
1088 embed_window->Destroy(); 1054 embed_window->Destroy();
1089 EXPECT_TRUE(DoRunLoopWithTimeout()); 1055 EXPECT_TRUE(DoRunLoopWithTimeout());
1090 EXPECT_TRUE(got_destroy); 1056 EXPECT_TRUE(got_destroy);
1091 } 1057 }
1092 1058
1093 TEST_F(WindowServerTest, ClientAreaChanged) { 1059 TEST_F(WindowServerTest, ClientAreaChanged) {
1094 Window* embed_window = window_manager()->NewWindow(); 1060 Window* embed_window = window_manager()->NewWindow();
1095 GetFirstWMRoot()->AddChild(embed_window); 1061 GetFirstWMRoot()->AddChild(embed_window);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 WindowTreeClient* client_; 1110 WindowTreeClient* client_;
1145 std::unique_ptr<base::RunLoop> run_loop_; 1111 std::unique_ptr<base::RunLoop> run_loop_;
1146 Window* created_window_; 1112 Window* created_window_;
1147 1113
1148 DISALLOW_COPY_AND_ASSIGN(EstablishConnectionViaFactoryDelegate); 1114 DISALLOW_COPY_AND_ASSIGN(EstablishConnectionViaFactoryDelegate);
1149 }; 1115 };
1150 1116
1151 TEST_F(WindowServerTest, EstablishConnectionViaFactory) { 1117 TEST_F(WindowServerTest, EstablishConnectionViaFactory) {
1152 EstablishConnectionViaFactoryDelegate delegate(window_manager()); 1118 EstablishConnectionViaFactoryDelegate delegate(window_manager());
1153 set_window_manager_delegate(&delegate); 1119 set_window_manager_delegate(&delegate);
1154 std::unique_ptr<WindowTreeClient> second_client( 1120 WindowTreeClient second_client(this, nullptr, nullptr);
1155 new WindowTreeClient(this, nullptr, nullptr)); 1121 second_client.ConnectViaWindowTreeFactory(connector());
1156 second_client->ConnectViaWindowTreeFactory(connector()); 1122 Window* window_in_second_client = second_client.NewTopLevelWindow(nullptr);
1157 Window* window_in_second_client =
1158 second_client->NewTopLevelWindow(nullptr);
1159 ASSERT_TRUE(window_in_second_client); 1123 ASSERT_TRUE(window_in_second_client);
1160 ASSERT_TRUE(second_client->GetRoots().count(window_in_second_client) > 1124 ASSERT_TRUE(second_client.GetRoots().count(window_in_second_client) > 0);
1161 0);
1162 // Wait for the window to appear in the wm. 1125 // Wait for the window to appear in the wm.
1163 ASSERT_TRUE(delegate.QuitOnCreate()); 1126 ASSERT_TRUE(delegate.QuitOnCreate());
1164 1127
1165 Window* window_in_wm = delegate.created_window(); 1128 Window* window_in_wm = delegate.created_window();
1166 ASSERT_TRUE(window_in_wm); 1129 ASSERT_TRUE(window_in_wm);
1167 1130
1168 // Change the bounds in the wm, and make sure the child sees it. 1131 // Change the bounds in the wm, and make sure the child sees it.
1169 window_in_wm->SetBounds(gfx::Rect(1, 11, 12, 101)); 1132 window_in_wm->SetBounds(gfx::Rect(1, 11, 12, 101));
1170 ASSERT_TRUE(WaitForBoundsToChange(window_in_second_client)); 1133 ASSERT_TRUE(WaitForBoundsToChange(window_in_second_client));
1171 EXPECT_EQ(gfx::Rect(1, 11, 12, 101), window_in_second_client->bounds()); 1134 EXPECT_EQ(gfx::Rect(1, 11, 12, 101), window_in_second_client->bounds());
1172 } 1135 }
1173 1136
1174 } // namespace ws 1137 } // namespace ws
1175 } // namespace ui 1138 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/test_wm/test_wm.cc ('k') | ui/views/mus/window_manager_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698