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

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

Issue 2104363004: Remove remaining calls to deprecated MessageLoop methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR gab Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // Note: This file tests both binding.h (mojo::Binding) and strong_binding.h 5 // Note: This file tests both binding.h (mojo::Binding) and strong_binding.h
6 // (mojo::StrongBinding). 6 // (mojo::StrongBinding).
7 7
8 #include "mojo/public/cpp/bindings/binding.h" 8 #include "mojo/public/cpp/bindings/binding.h"
9 9
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // Now that the Binding is out of scope we should detect an error on the other 116 // Now that the Binding is out of scope we should detect an error on the other
117 // end of the pipe. 117 // end of the pipe.
118 run_loop.Run(); 118 run_loop.Run();
119 EXPECT_TRUE(encountered_error); 119 EXPECT_TRUE(encountered_error);
120 120
121 // And calls should fail. 121 // And calls should fail.
122 called = false; 122 called = false;
123 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, 123 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr,
124 SetFlagAndRunClosure<int32_t>(&called, 124 SetFlagAndRunClosure<int32_t>(&called,
125 run_loop2.QuitClosure())); 125 run_loop2.QuitClosure()));
126 loop().RunUntilIdle(); 126 base::RunLoop().RunUntilIdle();
127 EXPECT_FALSE(called); 127 EXPECT_FALSE(called);
128 } 128 }
129 129
130 // Tests that the binding's connection error handler gets called when the other 130 // Tests that the binding's connection error handler gets called when the other
131 // end is closed. 131 // end is closed.
132 TEST_F(BindingTest, ConnectionError) { 132 TEST_F(BindingTest, ConnectionError) {
133 bool called = false; 133 bool called = false;
134 { 134 {
135 ServiceImpl impl; 135 ServiceImpl impl;
136 sample::ServicePtr ptr; 136 sample::ServicePtr ptr;
(...skipping 13 matching lines...) Expand all
150 150
151 // Tests that calling Close doesn't result in the connection error handler being 151 // Tests that calling Close doesn't result in the connection error handler being
152 // called. 152 // called.
153 TEST_F(BindingTest, CloseDoesntCallConnectionErrorHandler) { 153 TEST_F(BindingTest, CloseDoesntCallConnectionErrorHandler) {
154 ServiceImpl impl; 154 ServiceImpl impl;
155 sample::ServicePtr ptr; 155 sample::ServicePtr ptr;
156 Binding<sample::Service> binding(&impl, GetProxy(&ptr)); 156 Binding<sample::Service> binding(&impl, GetProxy(&ptr));
157 bool called = false; 157 bool called = false;
158 binding.set_connection_error_handler(SetFlagAndRunClosure(&called)); 158 binding.set_connection_error_handler(SetFlagAndRunClosure(&called));
159 binding.Close(); 159 binding.Close();
160 loop().RunUntilIdle(); 160 base::RunLoop().RunUntilIdle();
161 EXPECT_FALSE(called); 161 EXPECT_FALSE(called);
162 162
163 // We can also close the other end, and the error handler still won't be 163 // We can also close the other end, and the error handler still won't be
164 // called. 164 // called.
165 ptr.reset(); 165 ptr.reset();
166 loop().RunUntilIdle(); 166 base::RunLoop().RunUntilIdle();
167 EXPECT_FALSE(called); 167 EXPECT_FALSE(called);
168 } 168 }
169 169
170 class ServiceImplWithBinding : public ServiceImpl { 170 class ServiceImplWithBinding : public ServiceImpl {
171 public: 171 public:
172 ServiceImplWithBinding(bool* was_deleted, 172 ServiceImplWithBinding(bool* was_deleted,
173 const base::Closure& closure, 173 const base::Closure& closure,
174 InterfaceRequest<sample::Service> request) 174 InterfaceRequest<sample::Service> request)
175 : ServiceImpl(was_deleted), 175 : ServiceImpl(was_deleted),
176 binding_(this, std::move(request)), 176 binding_(this, std::move(request)),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 run_loop.Run(); 221 run_loop.Run();
222 EXPECT_TRUE(called); 222 EXPECT_TRUE(called);
223 223
224 called = false; 224 called = false;
225 auto request = binding.Unbind(); 225 auto request = binding.Unbind();
226 EXPECT_FALSE(binding.is_bound()); 226 EXPECT_FALSE(binding.is_bound());
227 // All calls should fail when not bound... 227 // All calls should fail when not bound...
228 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, 228 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr,
229 SetFlagAndRunClosure<int32_t>(&called, 229 SetFlagAndRunClosure<int32_t>(&called,
230 run_loop.QuitClosure())); 230 run_loop.QuitClosure()));
231 loop().RunUntilIdle(); 231 base::RunLoop().RunUntilIdle();
232 EXPECT_FALSE(called); 232 EXPECT_FALSE(called);
233 233
234 called = false; 234 called = false;
235 binding.Bind(std::move(request)); 235 binding.Bind(std::move(request));
236 EXPECT_TRUE(binding.is_bound()); 236 EXPECT_TRUE(binding.is_bound());
237 // ...and should succeed again when the rebound. 237 // ...and should succeed again when the rebound.
238 base::RunLoop run_loop2; 238 base::RunLoop run_loop2;
239 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, 239 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr,
240 SetFlagAndRunClosure<int32_t>(&called, 240 SetFlagAndRunClosure<int32_t>(&called,
241 run_loop2.QuitClosure())); 241 run_loop2.QuitClosure()));
(...skipping 28 matching lines...) Expand all
270 base::RunLoop run_loop; 270 base::RunLoop run_loop;
271 sample::ServicePtr ptr; 271 sample::ServicePtr ptr;
272 auto request = GetProxy(&ptr); 272 auto request = GetProxy(&ptr);
273 ServiceImpl impl; 273 ServiceImpl impl;
274 Binding<sample::Service> binding(&impl, std::move(request)); 274 Binding<sample::Service> binding(&impl, std::move(request));
275 binding.PauseIncomingMethodCallProcessing(); 275 binding.PauseIncomingMethodCallProcessing();
276 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, 276 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr,
277 SetFlagAndRunClosure<int32_t>(&called, 277 SetFlagAndRunClosure<int32_t>(&called,
278 run_loop.QuitClosure())); 278 run_loop.QuitClosure()));
279 EXPECT_FALSE(called); 279 EXPECT_FALSE(called);
280 loop().RunUntilIdle(); 280 base::RunLoop().RunUntilIdle();
281 // Frobinate() should not be called as the binding is paused. 281 // Frobinate() should not be called as the binding is paused.
282 EXPECT_FALSE(called); 282 EXPECT_FALSE(called);
283 283
284 // Resume the binding, which should trigger processing. 284 // Resume the binding, which should trigger processing.
285 binding.ResumeIncomingMethodCallProcessing(); 285 binding.ResumeIncomingMethodCallProcessing();
286 run_loop.Run(); 286 run_loop.Run();
287 EXPECT_TRUE(called); 287 EXPECT_TRUE(called);
288 } 288 }
289 289
290 // Verifies the connection error handler is not run while a binding is paused. 290 // Verifies the connection error handler is not run while a binding is paused.
291 TEST_F(BindingTest, ErrorHandleNotRunWhilePaused) { 291 TEST_F(BindingTest, ErrorHandleNotRunWhilePaused) {
292 bool called = false; 292 bool called = false;
293 base::RunLoop run_loop; 293 base::RunLoop run_loop;
294 sample::ServicePtr ptr; 294 sample::ServicePtr ptr;
295 auto request = GetProxy(&ptr); 295 auto request = GetProxy(&ptr);
296 ServiceImpl impl; 296 ServiceImpl impl;
297 Binding<sample::Service> binding(&impl, std::move(request)); 297 Binding<sample::Service> binding(&impl, std::move(request));
298 binding.set_connection_error_handler( 298 binding.set_connection_error_handler(
299 SetFlagAndRunClosure(&called, run_loop.QuitClosure())); 299 SetFlagAndRunClosure(&called, run_loop.QuitClosure()));
300 binding.PauseIncomingMethodCallProcessing(); 300 binding.PauseIncomingMethodCallProcessing();
301 301
302 ptr.reset(); 302 ptr.reset();
303 loop().RunUntilIdle(); 303 base::RunLoop().RunUntilIdle();
304 // The connection error handle should not be called as the binding is paused. 304 // The connection error handle should not be called as the binding is paused.
305 EXPECT_FALSE(called); 305 EXPECT_FALSE(called);
306 306
307 // Resume the binding, which should trigger the error handler. 307 // Resume the binding, which should trigger the error handler.
308 binding.ResumeIncomingMethodCallProcessing(); 308 binding.ResumeIncomingMethodCallProcessing();
309 run_loop.Run(); 309 run_loop.Run();
310 EXPECT_TRUE(called); 310 EXPECT_TRUE(called);
311 } 311 }
312 312
313 // StrongBindingTest ----------------------------------------------------------- 313 // StrongBindingTest -----------------------------------------------------------
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // Tests the typical case, where the implementation object owns the 361 // Tests the typical case, where the implementation object owns the
362 // StrongBinding (and should be destroyed on connection error). 362 // StrongBinding (and should be destroyed on connection error).
363 TEST_F(StrongBindingTest, ConnectionErrorDestroysImpl) { 363 TEST_F(StrongBindingTest, ConnectionErrorDestroysImpl) {
364 sample::ServicePtr ptr; 364 sample::ServicePtr ptr;
365 bool was_deleted = false; 365 bool was_deleted = false;
366 // Will delete itself. 366 // Will delete itself.
367 base::RunLoop run_loop; 367 base::RunLoop run_loop;
368 new ServiceImplWithBinding(&was_deleted, run_loop.QuitClosure(), 368 new ServiceImplWithBinding(&was_deleted, run_loop.QuitClosure(),
369 GetProxy(&ptr)); 369 GetProxy(&ptr));
370 370
371 loop().RunUntilIdle(); 371 base::RunLoop().RunUntilIdle();
372 EXPECT_FALSE(was_deleted); 372 EXPECT_FALSE(was_deleted);
373 373
374 ptr.reset(); 374 ptr.reset();
375 EXPECT_FALSE(was_deleted); 375 EXPECT_FALSE(was_deleted);
376 run_loop.Run(); 376 run_loop.Run();
377 EXPECT_TRUE(was_deleted); 377 EXPECT_TRUE(was_deleted);
378 } 378 }
379 379
380 // Tests that even when the implementation object owns the StrongBinding, that 380 // Tests that even when the implementation object owns the StrongBinding, that
381 // the implementation can still be deleted (which should result in the message 381 // the implementation can still be deleted (which should result in the message
382 // pipe being closed). Also checks that the connection error handler doesn't get 382 // pipe being closed). Also checks that the connection error handler doesn't get
383 // called. 383 // called.
384 TEST_F(StrongBindingTest, ExplicitDeleteImpl) { 384 TEST_F(StrongBindingTest, ExplicitDeleteImpl) {
385 bool ptr_error_handler_called = false; 385 bool ptr_error_handler_called = false;
386 sample::ServicePtr ptr; 386 sample::ServicePtr ptr;
387 auto request = GetProxy(&ptr); 387 auto request = GetProxy(&ptr);
388 base::RunLoop run_loop; 388 base::RunLoop run_loop;
389 ptr.set_connection_error_handler( 389 ptr.set_connection_error_handler(
390 SetFlagAndRunClosure(&ptr_error_handler_called, run_loop.QuitClosure())); 390 SetFlagAndRunClosure(&ptr_error_handler_called, run_loop.QuitClosure()));
391 bool was_deleted = false; 391 bool was_deleted = false;
392 ServiceImplWithStrongBinding* impl = 392 ServiceImplWithStrongBinding* impl =
393 new ServiceImplWithStrongBinding(&was_deleted, std::move(request)); 393 new ServiceImplWithStrongBinding(&was_deleted, std::move(request));
394 bool binding_error_handler_called = false; 394 bool binding_error_handler_called = false;
395 impl->binding().set_connection_error_handler( 395 impl->binding().set_connection_error_handler(
396 SetFlagAndRunClosure(&binding_error_handler_called)); 396 SetFlagAndRunClosure(&binding_error_handler_called));
397 397
398 loop().RunUntilIdle(); 398 base::RunLoop().RunUntilIdle();
399 EXPECT_FALSE(ptr_error_handler_called); 399 EXPECT_FALSE(ptr_error_handler_called);
400 EXPECT_FALSE(was_deleted); 400 EXPECT_FALSE(was_deleted);
401 401
402 delete impl; 402 delete impl;
403 EXPECT_FALSE(ptr_error_handler_called); 403 EXPECT_FALSE(ptr_error_handler_called);
404 EXPECT_TRUE(was_deleted); 404 EXPECT_TRUE(was_deleted);
405 was_deleted = false; // It shouldn't be double-deleted! 405 was_deleted = false; // It shouldn't be double-deleted!
406 run_loop.Run(); 406 run_loop.Run();
407 EXPECT_TRUE(ptr_error_handler_called); 407 EXPECT_TRUE(ptr_error_handler_called);
408 EXPECT_FALSE(was_deleted); 408 EXPECT_FALSE(was_deleted);
409 409
410 EXPECT_FALSE(binding_error_handler_called); 410 EXPECT_FALSE(binding_error_handler_called);
411 } 411 }
412 412
413 } // namespace 413 } // namespace
414 } // mojo 414 } // mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/binding_callback_unittest.cc ('k') | mojo/public/cpp/bindings/tests/handle_passing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698