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

Side by Side Diff: mojo/public/cpp/bindings/tests/binding_set_unittest.cc

Issue 2318793002: Mojo C++ bindings: support disconnect with a reason. (Closed)
Patch Set: . 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
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 <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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 base::RunLoop loop; 108 base::RunLoop loop;
109 bindings_.set_connection_error_handler( 109 bindings_.set_connection_error_handler(
110 Sequence(ExpectContext(&bindings_, context_b), loop.QuitClosure())); 110 Sequence(ExpectContext(&bindings_, context_b), loop.QuitClosure()));
111 ping_b.reset(); 111 ping_b.reset();
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) {
119 PingImpl impl;
120 PingServicePtr ptr;
121 BindingSet<PingService> bindings;
122 bindings.AddBinding(&impl, GetProxy(&ptr));
123
124 base::RunLoop run_loop;
125 bindings.set_connection_error_with_reason_handler(base::Bind(
126 [](const base::Closure& quit_closure, uint32_t custom_reason,
127 const std::string& description) {
128 EXPECT_EQ(1024u, custom_reason);
129 EXPECT_EQ("bye", description);
130 quit_closure.Run();
131 },
132 run_loop.QuitClosure()));
133
134 ptr.ResetWithReason(1024u, "bye");
135 }
136
118 class PingProviderImpl : public AssociatedPingProvider, public PingService { 137 class PingProviderImpl : public AssociatedPingProvider, public PingService {
119 public: 138 public:
120 PingProviderImpl() : ping_bindings_(BindingSetDispatchMode::WITH_CONTEXT) {} 139 PingProviderImpl() : ping_bindings_(BindingSetDispatchMode::WITH_CONTEXT) {}
121 ~PingProviderImpl() override {} 140 ~PingProviderImpl() override {}
122 141
123 void set_new_ping_context(void* context) { new_ping_context_ = context; } 142 void set_new_ping_context(void* context) { new_ping_context_ = context; }
124 143
125 void set_new_ping_handler(const base::Closure& handler) { 144 void set_new_ping_handler(const base::Closure& handler) {
126 new_ping_handler_ = handler; 145 new_ping_handler_ = handler;
127 } 146 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 base::RunLoop loop; 275 base::RunLoop loop;
257 bindings.set_connection_error_handler( 276 bindings.set_connection_error_handler(
258 Sequence(ExpectContext(&bindings, context_b), loop.QuitClosure())); 277 Sequence(ExpectContext(&bindings, context_b), loop.QuitClosure()));
259 provider_b.reset(); 278 provider_b.reset();
260 loop.Run(); 279 loop.Run();
261 } 280 }
262 281
263 EXPECT_TRUE(bindings.empty()); 282 EXPECT_TRUE(bindings.empty());
264 } 283 }
265 284
285 TEST_F(BindingSetTest, AssociatedBindingSetConnectionErrorWithReason) {
286 AssociatedPingProviderPtr master_ptr;
287 PingProviderImpl master_impl;
288 Binding<AssociatedPingProvider> master_binding(&master_impl, &master_ptr);
289
290 base::RunLoop run_loop;
291 master_impl.ping_bindings().set_connection_error_with_reason_handler(
292 base::Bind(
293 [](const base::Closure& quit_closure, uint32_t custom_reason,
294 const std::string& description) {
295 EXPECT_EQ(2048u, custom_reason);
296 EXPECT_EQ("bye", description);
297 quit_closure.Run();
298 },
299 run_loop.QuitClosure()));
300
301 PingServiceAssociatedPtr ptr;
302 master_ptr->GetPing(GetProxy(&ptr, master_ptr.associated_group()));
303
304 ptr.ResetWithReason(2048u, "bye");
305
306 run_loop.Run();
307 }
308
266 } // namespace 309 } // namespace
267 } // namespace test 310 } // namespace test
268 } // namespace mojo 311 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/associated_interface_unittest.cc ('k') | mojo/public/cpp/bindings/tests/binding_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698