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

Side by Side Diff: mojo/public/cpp/application/tests/service_provider_impl_unittest.cc

Issue 1976063002: More work on ServiceProviderImpl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: sigh Created 4 years, 7 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 | « mojo/public/cpp/application/service_provider_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "mojo/public/cpp/application/service_provider_impl.h" 5 #include "mojo/public/cpp/application/service_provider_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "mojo/public/cpp/application/connect.h" 9 #include "mojo/public/cpp/application/connect.h"
10 #include "mojo/public/cpp/bindings/strong_binding.h" 10 #include "mojo/public/cpp/bindings/strong_binding.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const char kConnectionUrl[] = "https://example.com/me.mojo"; 58 const char kConnectionUrl[] = "https://example.com/me.mojo";
59 59
60 const char kPing1[] = "Ping1"; 60 const char kPing1[] = "Ping1";
61 const char kPing2[] = "Ping2"; 61 const char kPing2[] = "Ping2";
62 const char kPing3[] = "Ping3"; 62 const char kPing3[] = "Ping3";
63 63
64 ServiceProviderPtr sp; 64 ServiceProviderPtr sp;
65 ServiceProviderImpl impl(ConnectionContext(ConnectionContext::Type::INCOMING, 65 ServiceProviderImpl impl(ConnectionContext(ConnectionContext::Type::INCOMING,
66 kRemoteUrl, kConnectionUrl), 66 kRemoteUrl, kConnectionUrl),
67 GetProxy(&sp)); 67 GetProxy(&sp));
68 EXPECT_EQ(ConnectionContext::Type::INCOMING, impl.connection_context().type);
69 EXPECT_EQ(kRemoteUrl, impl.connection_context().remote_url);
70 EXPECT_EQ(kConnectionUrl, impl.connection_context().connection_url);
68 71
69 impl.AddServiceNew<test::PingService>( 72 impl.AddService<test::PingService>(
70 [&kRemoteUrl, &kConnectionUrl]( 73 [&kRemoteUrl, &kConnectionUrl](
71 const ConnectionContext& connection_context, 74 const ConnectionContext& connection_context,
72 InterfaceRequest<test::PingService> ping_service_request) { 75 InterfaceRequest<test::PingService> ping_service_request) {
73 EXPECT_EQ(ConnectionContext::Type::INCOMING, connection_context.type); 76 EXPECT_EQ(ConnectionContext::Type::INCOMING, connection_context.type);
74 EXPECT_EQ(kRemoteUrl, connection_context.remote_url); 77 EXPECT_EQ(kRemoteUrl, connection_context.remote_url);
75 EXPECT_EQ(kConnectionUrl, connection_context.connection_url); 78 EXPECT_EQ(kConnectionUrl, connection_context.connection_url);
76 new PingServiceImpl(std::move(ping_service_request)); 79 new PingServiceImpl(std::move(ping_service_request));
77 }, 80 },
78 kPing1); 81 kPing1);
79 82
80 impl.AddServiceNew<test::PingService>( 83 impl.AddService<test::PingService>(
81 [&kRemoteUrl, &kConnectionUrl]( 84 [&kRemoteUrl, &kConnectionUrl](
82 const ConnectionContext& connection_context, 85 const ConnectionContext& connection_context,
83 InterfaceRequest<test::PingService> ping_service_request) { 86 InterfaceRequest<test::PingService> ping_service_request) {
84 EXPECT_EQ(ConnectionContext::Type::INCOMING, connection_context.type); 87 EXPECT_EQ(ConnectionContext::Type::INCOMING, connection_context.type);
85 EXPECT_EQ(kRemoteUrl, connection_context.remote_url); 88 EXPECT_EQ(kRemoteUrl, connection_context.remote_url);
86 EXPECT_EQ(kConnectionUrl, connection_context.connection_url); 89 EXPECT_EQ(kConnectionUrl, connection_context.connection_url);
87 new PingServiceImpl(std::move(ping_service_request)); 90 new PingServiceImpl(std::move(ping_service_request));
88 }, 91 },
89 kPing2); 92 kPing2);
90 93
(...skipping 18 matching lines...) Expand all
109 // "Ping3" isn't actually registered! 112 // "Ping3" isn't actually registered!
110 { 113 {
111 test::PingServicePtr ping3; 114 test::PingServicePtr ping3;
112 ConnectToService(sp.get(), GetProxy(&ping3), kPing3); 115 ConnectToService(sp.get(), GetProxy(&ping3), kPing3);
113 ping3.set_connection_error_handler([this] { QuitLoop(true); }); 116 ping3.set_connection_error_handler([this] { QuitLoop(true); });
114 ping3->Ping([this] { QuitLoop(false); }); 117 ping3->Ping([this] { QuitLoop(false); });
115 loop().Run(); 118 loop().Run();
116 } 119 }
117 loop().RunUntilIdle(); // Run stuff caused by destructors. 120 loop().RunUntilIdle(); // Run stuff caused by destructors.
118 121
122 impl.RemoveService<test::PingService>(kPing2);
123
124 // "Ping2" should no longer work.
125 {
126 test::PingServicePtr ping2;
127 ConnectToService(sp.get(), GetProxy(&ping2), kPing2);
128 ping2.set_connection_error_handler([this] { QuitLoop(true); });
129 ping2->Ping([this] { QuitLoop(false); });
130 loop().Run();
131 }
132 loop().RunUntilIdle(); // Run stuff caused by destructors.
133
134 // But "Ping1" should still work.
135 {
136 test::PingServicePtr ping1;
137 ConnectToService(sp.get(), GetProxy(&ping1), kPing1);
138 ping1.set_connection_error_handler([this] { QuitLoop(false); });
139 ping1->Ping([this] { QuitLoop(true); });
140 loop().Run();
141 }
142 loop().RunUntilIdle(); // Run stuff caused by destructors.
143
144 impl.RemoveServiceForName(kPing1);
145
146 // "Ping1" should no longer work.
147 {
148 test::PingServicePtr ping1;
149 ConnectToService(sp.get(), GetProxy(&ping1), kPing1);
150 ping1.set_connection_error_handler([this] { QuitLoop(true); });
151 ping1->Ping([this] { QuitLoop(false); });
152 loop().Run();
153 }
154 loop().RunUntilIdle(); // Run stuff caused by destructors.
155
119 sp.reset(); 156 sp.reset();
120 loop().RunUntilIdle(); 157 loop().RunUntilIdle();
121 } 158 }
122 159
123 TEST_F(ServiceProviderImplTest, CloseAndRebind) { 160 TEST_F(ServiceProviderImplTest, CloseAndRebind) {
124 const char kRemoteUrl1[] = "https://example.com/remote1.mojo"; 161 const char kRemoteUrl1[] = "https://example.com/remote1.mojo";
125 const char kRemoteUrl2[] = "https://example.com/remote2.mojo"; 162 const char kRemoteUrl2[] = "https://example.com/remote2.mojo";
126 const char kConnectionUrl[] = "https://example.com/me.mojo"; 163 const char kConnectionUrl[] = "https://example.com/me.mojo";
127 const char kPing[] = "Ping"; 164 const char kPing[] = "Ping";
128 165
129 ServiceProviderPtr sp1; 166 ServiceProviderPtr sp1;
130 ServiceProviderImpl impl(ConnectionContext(ConnectionContext::Type::INCOMING, 167 ServiceProviderImpl impl(ConnectionContext(ConnectionContext::Type::INCOMING,
131 kRemoteUrl1, kConnectionUrl), 168 kRemoteUrl1, kConnectionUrl),
132 GetProxy(&sp1)); 169 GetProxy(&sp1));
170 EXPECT_EQ(ConnectionContext::Type::INCOMING, impl.connection_context().type);
171 EXPECT_EQ(kRemoteUrl1, impl.connection_context().remote_url);
172 EXPECT_EQ(kConnectionUrl, impl.connection_context().connection_url);
133 173
134 impl.AddServiceNew<test::PingService>( 174 impl.AddService<test::PingService>(
135 [&kRemoteUrl1, &kRemoteUrl2, &kConnectionUrl]( 175 [&kRemoteUrl1, &kRemoteUrl2, &kConnectionUrl](
136 const ConnectionContext& connection_context, 176 const ConnectionContext& connection_context,
137 InterfaceRequest<test::PingService> ping_service_request) { 177 InterfaceRequest<test::PingService> ping_service_request) {
138 EXPECT_EQ(ConnectionContext::Type::INCOMING, connection_context.type); 178 EXPECT_EQ(ConnectionContext::Type::INCOMING, connection_context.type);
139 EXPECT_TRUE(connection_context.remote_url == kRemoteUrl1 || 179 EXPECT_TRUE(connection_context.remote_url == kRemoteUrl1 ||
140 connection_context.remote_url == kRemoteUrl2); 180 connection_context.remote_url == kRemoteUrl2);
141 EXPECT_EQ(kConnectionUrl, connection_context.connection_url); 181 EXPECT_EQ(kConnectionUrl, connection_context.connection_url);
142 new PingServiceImpl(std::move(ping_service_request)); 182 new PingServiceImpl(std::move(ping_service_request));
143 }, 183 },
144 kPing); 184 kPing);
145 185
146 { 186 {
147 test::PingServicePtr ping; 187 test::PingServicePtr ping;
148 ConnectToService(sp1.get(), GetProxy(&ping), kPing); 188 ConnectToService(sp1.get(), GetProxy(&ping), kPing);
149 ping.set_connection_error_handler([this] { QuitLoop(false); }); 189 ping.set_connection_error_handler([this] { QuitLoop(false); });
150 ping->Ping([this] { QuitLoop(true); }); 190 ping->Ping([this] { QuitLoop(true); });
151 loop().Run(); 191 loop().Run();
152 } 192 }
153 loop().RunUntilIdle(); // Run stuff caused by destructors. 193 loop().RunUntilIdle(); // Run stuff caused by destructors.
154 194
155 impl.Close(); 195 impl.Close();
196 EXPECT_EQ(ConnectionContext::Type::UNKNOWN, impl.connection_context().type);
197 EXPECT_EQ(std::string(), impl.connection_context().remote_url);
198 EXPECT_EQ(std::string(), impl.connection_context().connection_url);
156 sp1.reset(); 199 sp1.reset();
157 loop().RunUntilIdle(); 200 loop().RunUntilIdle();
158 201
159 ServiceProviderPtr sp2; 202 ServiceProviderPtr sp2;
160 impl.Bind(ConnectionContext(ConnectionContext::Type::INCOMING, kRemoteUrl2, 203 impl.Bind(ConnectionContext(ConnectionContext::Type::INCOMING, kRemoteUrl2,
161 kConnectionUrl), 204 kConnectionUrl),
162 GetProxy(&sp2)); 205 GetProxy(&sp2));
206 EXPECT_EQ(ConnectionContext::Type::INCOMING, impl.connection_context().type);
207 EXPECT_EQ(kRemoteUrl2, impl.connection_context().remote_url);
208 EXPECT_EQ(kConnectionUrl, impl.connection_context().connection_url);
163 209
164 { 210 {
165 test::PingServicePtr ping; 211 test::PingServicePtr ping;
166 ConnectToService(sp2.get(), GetProxy(&ping), kPing); 212 ConnectToService(sp2.get(), GetProxy(&ping), kPing);
167 ping.set_connection_error_handler([this] { QuitLoop(false); }); 213 ping.set_connection_error_handler([this] { QuitLoop(false); });
168 ping->Ping([this] { QuitLoop(true); }); 214 ping->Ping([this] { QuitLoop(true); });
169 loop().Run(); 215 loop().Run();
170 } 216 }
171 loop().RunUntilIdle(); // Run stuff caused by destructors. 217 loop().RunUntilIdle(); // Run stuff caused by destructors.
172 218
173 // Can close multiple times. 219 // Can close multiple times.
174 impl.Close(); 220 impl.Close();
175 impl.Close(); 221 impl.Close();
176 sp2.reset(); 222 sp2.reset();
177 loop().RunUntilIdle(); 223 loop().RunUntilIdle();
178 } 224 }
179 225
180 TEST_F(ServiceProviderImplTest, Bind) { 226 TEST_F(ServiceProviderImplTest, Bind) {
181 const char kRemoteUrl[] = "https://example.com/remote.mojo"; 227 const char kRemoteUrl[] = "https://example.com/remote.mojo";
182 const char kConnectionUrl[] = "https://example.com/me.mojo"; 228 const char kConnectionUrl[] = "https://example.com/me.mojo";
183 const char kPing[] = "Ping"; 229 const char kPing[] = "Ping";
184 230
185 ServiceProviderPtr sp; 231 ServiceProviderPtr sp;
186 ServiceProviderImpl impl; 232 ServiceProviderImpl impl;
233 EXPECT_EQ(ConnectionContext::Type::UNKNOWN, impl.connection_context().type);
234 EXPECT_EQ(std::string(), impl.connection_context().remote_url);
235 EXPECT_EQ(std::string(), impl.connection_context().connection_url);
187 236
188 impl.Bind(ConnectionContext(ConnectionContext::Type::INCOMING, kRemoteUrl, 237 impl.Bind(ConnectionContext(ConnectionContext::Type::INCOMING, kRemoteUrl,
189 kConnectionUrl), 238 kConnectionUrl),
190 GetProxy(&sp)); 239 GetProxy(&sp));
191 240
192 impl.AddServiceNew<test::PingService>( 241 impl.AddService<test::PingService>(
193 [&kRemoteUrl, &kConnectionUrl]( 242 [&kRemoteUrl, &kConnectionUrl](
194 const ConnectionContext& connection_context, 243 const ConnectionContext& connection_context,
195 InterfaceRequest<test::PingService> request) { 244 InterfaceRequest<test::PingService> request) {
196 EXPECT_EQ(ConnectionContext::Type::INCOMING, connection_context.type); 245 EXPECT_EQ(ConnectionContext::Type::INCOMING, connection_context.type);
197 EXPECT_EQ(kRemoteUrl, connection_context.remote_url); 246 EXPECT_EQ(kRemoteUrl, connection_context.remote_url);
198 EXPECT_EQ(kConnectionUrl, connection_context.connection_url); 247 EXPECT_EQ(kConnectionUrl, connection_context.connection_url);
199 new PingServiceImpl(std::move(request)); 248 new PingServiceImpl(std::move(request));
200 }, 249 },
201 kPing); 250 kPing);
202 251
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 loop().Run(); 331 loop().Run();
283 } 332 }
284 loop().RunUntilIdle(); // Run stuff caused by destructors. 333 loop().RunUntilIdle(); // Run stuff caused by destructors.
285 334
286 sp.reset(); 335 sp.reset();
287 loop().RunUntilIdle(); 336 loop().RunUntilIdle();
288 337
289 EXPECT_FALSE(was_run); 338 EXPECT_FALSE(was_run);
290 } 339 }
291 340
341 // TODO(vtl): Explicitly test |AddServiceForName()|?
342
292 } // namespace 343 } // namespace
293 } // namespace mojo 344 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/service_provider_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698