OLD | NEW |
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 <memory> | 5 #include <memory> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "mojo/public/cpp/bindings/associated_binding_set.h" | 10 #include "mojo/public/cpp/bindings/associated_binding_set.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 }; | 72 }; |
73 | 73 |
74 TEST_F(BindingSetTest, BindingSetContext) { | 74 TEST_F(BindingSetTest, BindingSetContext) { |
75 PingImpl impl; | 75 PingImpl impl; |
76 | 76 |
77 void* context_a = reinterpret_cast<void*>(1); | 77 void* context_a = reinterpret_cast<void*>(1); |
78 void* context_b = reinterpret_cast<void*>(2); | 78 void* context_b = reinterpret_cast<void*>(2); |
79 | 79 |
80 BindingSet<PingService> bindings_(BindingSetDispatchMode::WITH_CONTEXT); | 80 BindingSet<PingService> bindings_(BindingSetDispatchMode::WITH_CONTEXT); |
81 PingServicePtr ping_a, ping_b; | 81 PingServicePtr ping_a, ping_b; |
82 bindings_.AddBinding(&impl, GetProxy(&ping_a), context_a); | 82 bindings_.AddBinding(&impl, MakeRequest(&ping_a), context_a); |
83 bindings_.AddBinding(&impl, GetProxy(&ping_b), context_b); | 83 bindings_.AddBinding(&impl, MakeRequest(&ping_b), context_b); |
84 | 84 |
85 { | 85 { |
86 impl.set_ping_handler(ExpectContext(&bindings_, context_a)); | 86 impl.set_ping_handler(ExpectContext(&bindings_, context_a)); |
87 base::RunLoop loop; | 87 base::RunLoop loop; |
88 ping_a->Ping(loop.QuitClosure()); | 88 ping_a->Ping(loop.QuitClosure()); |
89 loop.Run(); | 89 loop.Run(); |
90 } | 90 } |
91 | 91 |
92 { | 92 { |
93 impl.set_ping_handler(ExpectContext(&bindings_, context_b)); | 93 impl.set_ping_handler(ExpectContext(&bindings_, context_b)); |
(...skipping 18 matching lines...) Expand all Loading... |
112 loop.Run(); | 112 loop.Run(); |
113 } | 113 } |
114 | 114 |
115 EXPECT_TRUE(bindings_.empty()); | 115 EXPECT_TRUE(bindings_.empty()); |
116 } | 116 } |
117 | 117 |
118 TEST_F(BindingSetTest, BindingSetConnectionErrorWithReason) { | 118 TEST_F(BindingSetTest, BindingSetConnectionErrorWithReason) { |
119 PingImpl impl; | 119 PingImpl impl; |
120 PingServicePtr ptr; | 120 PingServicePtr ptr; |
121 BindingSet<PingService> bindings; | 121 BindingSet<PingService> bindings; |
122 bindings.AddBinding(&impl, GetProxy(&ptr)); | 122 bindings.AddBinding(&impl, MakeRequest(&ptr)); |
123 | 123 |
124 base::RunLoop run_loop; | 124 base::RunLoop run_loop; |
125 bindings.set_connection_error_with_reason_handler(base::Bind( | 125 bindings.set_connection_error_with_reason_handler(base::Bind( |
126 [](const base::Closure& quit_closure, uint32_t custom_reason, | 126 [](const base::Closure& quit_closure, uint32_t custom_reason, |
127 const std::string& description) { | 127 const std::string& description) { |
128 EXPECT_EQ(1024u, custom_reason); | 128 EXPECT_EQ(1024u, custom_reason); |
129 EXPECT_EQ("bye", description); | 129 EXPECT_EQ("bye", description); |
130 quit_closure.Run(); | 130 quit_closure.Run(); |
131 }, | 131 }, |
132 run_loop.QuitClosure())); | 132 run_loop.QuitClosure())); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 168 |
169 AssociatedBindingSet<PingService> ping_bindings_; | 169 AssociatedBindingSet<PingService> ping_bindings_; |
170 void* new_ping_context_ = nullptr; | 170 void* new_ping_context_ = nullptr; |
171 base::Closure ping_handler_; | 171 base::Closure ping_handler_; |
172 base::Closure new_ping_handler_; | 172 base::Closure new_ping_handler_; |
173 }; | 173 }; |
174 | 174 |
175 TEST_F(BindingSetTest, AssociatedBindingSetContext) { | 175 TEST_F(BindingSetTest, AssociatedBindingSetContext) { |
176 AssociatedPingProviderPtr provider; | 176 AssociatedPingProviderPtr provider; |
177 PingProviderImpl impl; | 177 PingProviderImpl impl; |
178 Binding<AssociatedPingProvider> binding(&impl, GetProxy(&provider)); | 178 Binding<AssociatedPingProvider> binding(&impl, MakeRequest(&provider)); |
179 | 179 |
180 void* context_a = reinterpret_cast<void*>(1); | 180 void* context_a = reinterpret_cast<void*>(1); |
181 void* context_b = reinterpret_cast<void*>(2); | 181 void* context_b = reinterpret_cast<void*>(2); |
182 | 182 |
183 PingServiceAssociatedPtr ping_a; | 183 PingServiceAssociatedPtr ping_a; |
184 { | 184 { |
185 base::RunLoop loop; | 185 base::RunLoop loop; |
186 impl.set_new_ping_context(context_a); | 186 impl.set_new_ping_context(context_a); |
187 impl.set_new_ping_handler(loop.QuitClosure()); | 187 impl.set_new_ping_handler(loop.QuitClosure()); |
188 provider->GetPing(GetProxy(&ping_a, provider.associated_group())); | 188 provider->GetPing(MakeRequest(&ping_a, provider.associated_group())); |
189 loop.Run(); | 189 loop.Run(); |
190 } | 190 } |
191 | 191 |
192 PingServiceAssociatedPtr ping_b; | 192 PingServiceAssociatedPtr ping_b; |
193 { | 193 { |
194 base::RunLoop loop; | 194 base::RunLoop loop; |
195 impl.set_new_ping_context(context_b); | 195 impl.set_new_ping_context(context_b); |
196 impl.set_new_ping_handler(loop.QuitClosure()); | 196 impl.set_new_ping_handler(loop.QuitClosure()); |
197 provider->GetPing(GetProxy(&ping_b, provider.associated_group())); | 197 provider->GetPing(MakeRequest(&ping_b, provider.associated_group())); |
198 loop.Run(); | 198 loop.Run(); |
199 } | 199 } |
200 | 200 |
201 { | 201 { |
202 impl.set_ping_handler(ExpectContext(&impl.ping_bindings(), context_a)); | 202 impl.set_ping_handler(ExpectContext(&impl.ping_bindings(), context_a)); |
203 base::RunLoop loop; | 203 base::RunLoop loop; |
204 ping_a->Ping(loop.QuitClosure()); | 204 ping_a->Ping(loop.QuitClosure()); |
205 loop.Run(); | 205 loop.Run(); |
206 } | 206 } |
207 | 207 |
(...skipping 27 matching lines...) Expand all Loading... |
235 | 235 |
236 TEST_F(BindingSetTest, MasterInterfaceBindingSetContext) { | 236 TEST_F(BindingSetTest, MasterInterfaceBindingSetContext) { |
237 AssociatedPingProviderPtr provider_a, provider_b; | 237 AssociatedPingProviderPtr provider_a, provider_b; |
238 PingProviderImpl impl; | 238 PingProviderImpl impl; |
239 BindingSet<AssociatedPingProvider> bindings( | 239 BindingSet<AssociatedPingProvider> bindings( |
240 BindingSetDispatchMode::WITH_CONTEXT); | 240 BindingSetDispatchMode::WITH_CONTEXT); |
241 | 241 |
242 void* context_a = reinterpret_cast<void*>(1); | 242 void* context_a = reinterpret_cast<void*>(1); |
243 void* context_b = reinterpret_cast<void*>(2); | 243 void* context_b = reinterpret_cast<void*>(2); |
244 | 244 |
245 bindings.AddBinding(&impl, GetProxy(&provider_a), context_a); | 245 bindings.AddBinding(&impl, MakeRequest(&provider_a), context_a); |
246 bindings.AddBinding(&impl, GetProxy(&provider_b), context_b); | 246 bindings.AddBinding(&impl, MakeRequest(&provider_b), context_b); |
247 | 247 |
248 { | 248 { |
249 PingServiceAssociatedPtr ping; | 249 PingServiceAssociatedPtr ping; |
250 base::RunLoop loop; | 250 base::RunLoop loop; |
251 impl.set_new_ping_handler( | 251 impl.set_new_ping_handler( |
252 Sequence(ExpectContext(&bindings, context_a), loop.QuitClosure())); | 252 Sequence(ExpectContext(&bindings, context_a), loop.QuitClosure())); |
253 provider_a->GetPing(GetProxy(&ping, provider_a.associated_group())); | 253 provider_a->GetPing(MakeRequest(&ping, provider_a.associated_group())); |
254 loop.Run(); | 254 loop.Run(); |
255 } | 255 } |
256 | 256 |
257 { | 257 { |
258 PingServiceAssociatedPtr ping; | 258 PingServiceAssociatedPtr ping; |
259 base::RunLoop loop; | 259 base::RunLoop loop; |
260 impl.set_new_ping_handler( | 260 impl.set_new_ping_handler( |
261 Sequence(ExpectContext(&bindings, context_b), loop.QuitClosure())); | 261 Sequence(ExpectContext(&bindings, context_b), loop.QuitClosure())); |
262 provider_b->GetPing(GetProxy(&ping, provider_b.associated_group())); | 262 provider_b->GetPing(MakeRequest(&ping, provider_b.associated_group())); |
263 loop.Run(); | 263 loop.Run(); |
264 } | 264 } |
265 | 265 |
266 { | 266 { |
267 base::RunLoop loop; | 267 base::RunLoop loop; |
268 bindings.set_connection_error_handler( | 268 bindings.set_connection_error_handler( |
269 Sequence(ExpectContext(&bindings, context_a), loop.QuitClosure())); | 269 Sequence(ExpectContext(&bindings, context_a), loop.QuitClosure())); |
270 provider_a.reset(); | 270 provider_a.reset(); |
271 loop.Run(); | 271 loop.Run(); |
272 } | 272 } |
(...skipping 19 matching lines...) Expand all Loading... |
292 base::Bind( | 292 base::Bind( |
293 [](const base::Closure& quit_closure, uint32_t custom_reason, | 293 [](const base::Closure& quit_closure, uint32_t custom_reason, |
294 const std::string& description) { | 294 const std::string& description) { |
295 EXPECT_EQ(2048u, custom_reason); | 295 EXPECT_EQ(2048u, custom_reason); |
296 EXPECT_EQ("bye", description); | 296 EXPECT_EQ("bye", description); |
297 quit_closure.Run(); | 297 quit_closure.Run(); |
298 }, | 298 }, |
299 run_loop.QuitClosure())); | 299 run_loop.QuitClosure())); |
300 | 300 |
301 PingServiceAssociatedPtr ptr; | 301 PingServiceAssociatedPtr ptr; |
302 master_ptr->GetPing(GetProxy(&ptr, master_ptr.associated_group())); | 302 master_ptr->GetPing(MakeRequest(&ptr, master_ptr.associated_group())); |
303 | 303 |
304 ptr.ResetWithReason(2048u, "bye"); | 304 ptr.ResetWithReason(2048u, "bye"); |
305 | 305 |
306 run_loop.Run(); | 306 run_loop.Run(); |
307 } | 307 } |
308 | 308 |
309 } // namespace | 309 } // namespace |
310 } // namespace test | 310 } // namespace test |
311 } // namespace mojo | 311 } // namespace mojo |
OLD | NEW |