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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 TEST_F(BindingSetTest, AssociatedBindingSetContext) { | 177 TEST_F(BindingSetTest, AssociatedBindingSetContext) { |
178 AssociatedPingProviderPtr provider; | 178 AssociatedPingProviderPtr provider; |
179 PingProviderImpl impl; | 179 PingProviderImpl impl; |
180 Binding<AssociatedPingProvider> binding(&impl, MakeRequest(&provider)); | 180 Binding<AssociatedPingProvider> binding(&impl, MakeRequest(&provider)); |
181 | 181 |
182 PingServiceAssociatedPtr ping_a; | 182 PingServiceAssociatedPtr ping_a; |
183 { | 183 { |
184 base::RunLoop loop; | 184 base::RunLoop loop; |
185 impl.set_new_ping_context(1); | 185 impl.set_new_ping_context(1); |
186 impl.set_new_ping_handler(loop.QuitClosure()); | 186 impl.set_new_ping_handler(loop.QuitClosure()); |
187 provider->GetPing(MakeRequest(&ping_a, provider.associated_group())); | 187 provider->GetPing(MakeRequest(&ping_a)); |
188 loop.Run(); | 188 loop.Run(); |
189 } | 189 } |
190 | 190 |
191 PingServiceAssociatedPtr ping_b; | 191 PingServiceAssociatedPtr ping_b; |
192 { | 192 { |
193 base::RunLoop loop; | 193 base::RunLoop loop; |
194 impl.set_new_ping_context(2); | 194 impl.set_new_ping_context(2); |
195 impl.set_new_ping_handler(loop.QuitClosure()); | 195 impl.set_new_ping_handler(loop.QuitClosure()); |
196 provider->GetPing(MakeRequest(&ping_b, provider.associated_group())); | 196 provider->GetPing(MakeRequest(&ping_b)); |
197 loop.Run(); | 197 loop.Run(); |
198 } | 198 } |
199 | 199 |
200 { | 200 { |
201 impl.set_ping_handler(ExpectContext(&impl.ping_bindings(), 1)); | 201 impl.set_ping_handler(ExpectContext(&impl.ping_bindings(), 1)); |
202 base::RunLoop loop; | 202 base::RunLoop loop; |
203 ping_a->Ping(loop.QuitClosure()); | 203 ping_a->Ping(loop.QuitClosure()); |
204 loop.Run(); | 204 loop.Run(); |
205 } | 205 } |
206 | 206 |
(...skipping 29 matching lines...) Expand all Loading... |
236 BindingSet<AssociatedPingProvider, int> bindings; | 236 BindingSet<AssociatedPingProvider, int> bindings; |
237 | 237 |
238 bindings.AddBinding(&impl, MakeRequest(&provider_a), 1); | 238 bindings.AddBinding(&impl, MakeRequest(&provider_a), 1); |
239 bindings.AddBinding(&impl, MakeRequest(&provider_b), 2); | 239 bindings.AddBinding(&impl, MakeRequest(&provider_b), 2); |
240 | 240 |
241 { | 241 { |
242 PingServiceAssociatedPtr ping; | 242 PingServiceAssociatedPtr ping; |
243 base::RunLoop loop; | 243 base::RunLoop loop; |
244 impl.set_new_ping_handler( | 244 impl.set_new_ping_handler( |
245 Sequence(ExpectContext(&bindings, 1), loop.QuitClosure())); | 245 Sequence(ExpectContext(&bindings, 1), loop.QuitClosure())); |
246 provider_a->GetPing(MakeRequest(&ping, provider_a.associated_group())); | 246 provider_a->GetPing(MakeRequest(&ping)); |
247 loop.Run(); | 247 loop.Run(); |
248 } | 248 } |
249 | 249 |
250 { | 250 { |
251 PingServiceAssociatedPtr ping; | 251 PingServiceAssociatedPtr ping; |
252 base::RunLoop loop; | 252 base::RunLoop loop; |
253 impl.set_new_ping_handler( | 253 impl.set_new_ping_handler( |
254 Sequence(ExpectContext(&bindings, 2), loop.QuitClosure())); | 254 Sequence(ExpectContext(&bindings, 2), loop.QuitClosure())); |
255 provider_b->GetPing(MakeRequest(&ping, provider_b.associated_group())); | 255 provider_b->GetPing(MakeRequest(&ping)); |
256 loop.Run(); | 256 loop.Run(); |
257 } | 257 } |
258 | 258 |
259 { | 259 { |
260 base::RunLoop loop; | 260 base::RunLoop loop; |
261 bindings.set_connection_error_handler( | 261 bindings.set_connection_error_handler( |
262 Sequence(ExpectContext(&bindings, 1), loop.QuitClosure())); | 262 Sequence(ExpectContext(&bindings, 1), loop.QuitClosure())); |
263 provider_a.reset(); | 263 provider_a.reset(); |
264 loop.Run(); | 264 loop.Run(); |
265 } | 265 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 base::Bind( | 336 base::Bind( |
337 [](const base::Closure& quit_closure, uint32_t custom_reason, | 337 [](const base::Closure& quit_closure, uint32_t custom_reason, |
338 const std::string& description) { | 338 const std::string& description) { |
339 EXPECT_EQ(2048u, custom_reason); | 339 EXPECT_EQ(2048u, custom_reason); |
340 EXPECT_EQ("bye", description); | 340 EXPECT_EQ("bye", description); |
341 quit_closure.Run(); | 341 quit_closure.Run(); |
342 }, | 342 }, |
343 run_loop.QuitClosure())); | 343 run_loop.QuitClosure())); |
344 | 344 |
345 PingServiceAssociatedPtr ptr; | 345 PingServiceAssociatedPtr ptr; |
346 master_ptr->GetPing(MakeRequest(&ptr, master_ptr.associated_group())); | 346 master_ptr->GetPing(MakeRequest(&ptr)); |
347 | 347 |
348 ptr.ResetWithReason(2048u, "bye"); | 348 ptr.ResetWithReason(2048u, "bye"); |
349 | 349 |
350 run_loop.Run(); | 350 run_loop.Run(); |
351 } | 351 } |
352 | 352 |
353 class PingInstanceCounter : public PingService { | 353 class PingInstanceCounter : public PingService { |
354 public: | 354 public: |
355 PingInstanceCounter() { ++instance_count; } | 355 PingInstanceCounter() { ++instance_count; } |
356 ~PingInstanceCounter() override { --instance_count; } | 356 ~PingInstanceCounter() override { --instance_count; } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 EXPECT_TRUE(bindings.RemoveBinding(binding_id_a)); | 407 EXPECT_TRUE(bindings.RemoveBinding(binding_id_a)); |
408 EXPECT_EQ(1, PingInstanceCounter::instance_count); | 408 EXPECT_EQ(1, PingInstanceCounter::instance_count); |
409 | 409 |
410 EXPECT_TRUE(bindings.RemoveBinding(binding_id_b)); | 410 EXPECT_TRUE(bindings.RemoveBinding(binding_id_b)); |
411 EXPECT_EQ(0, PingInstanceCounter::instance_count); | 411 EXPECT_EQ(0, PingInstanceCounter::instance_count); |
412 } | 412 } |
413 | 413 |
414 } // namespace | 414 } // namespace |
415 } // namespace test | 415 } // namespace test |
416 } // namespace mojo | 416 } // namespace mojo |
OLD | NEW |