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

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

Issue 1832193002: Mojo C++ bindings: refactor SyncHandleWatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/bindings/lib/sync_handle_watcher.cc ('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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
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 "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 base::RunLoop run_loop1; 359 base::RunLoop run_loop1;
360 impl.set_async_echo_handler( 360 impl.set_async_echo_handler(
361 [&async_echo_request_value, &async_echo_request_callback, &run_loop1]( 361 [&async_echo_request_value, &async_echo_request_callback, &run_loop1](
362 int32_t value, const TestSync::AsyncEchoCallback& callback) { 362 int32_t value, const TestSync::AsyncEchoCallback& callback) {
363 async_echo_request_value = value; 363 async_echo_request_value = value;
364 async_echo_request_callback = callback; 364 async_echo_request_callback = callback;
365 run_loop1.Quit(); 365 run_loop1.Quit();
366 }); 366 });
367 367
368 bool async_echo_response_dispatched = false; 368 bool async_echo_response_dispatched = false;
369 bool connection_error_dispatched = false;
369 base::RunLoop run_loop2; 370 base::RunLoop run_loop2;
370 ptr->AsyncEcho(123, 371 ptr->AsyncEcho(
371 [&async_echo_response_dispatched, &run_loop2](int32_t result) { 372 123, [&async_echo_response_dispatched, &connection_error_dispatched, &ptr,
372 async_echo_response_dispatched = true; 373 &run_loop2](int32_t result) {
373 EXPECT_EQ(123, result); 374 async_echo_response_dispatched = true;
374 run_loop2.Quit(); 375 // At this point, error notification should not be dispatched
375 }); 376 // yet.
377 EXPECT_FALSE(connection_error_dispatched);
378 EXPECT_FALSE(ptr.encountered_error());
379 EXPECT_EQ(123, result);
380 run_loop2.Quit();
381 });
376 // Run until the AsyncEcho request reaches the service side. 382 // Run until the AsyncEcho request reaches the service side.
377 run_loop1.Run(); 383 run_loop1.Run();
378 384
379 impl.set_echo_handler( 385 impl.set_echo_handler(
380 [&impl, &async_echo_request_value, &async_echo_request_callback]( 386 [&impl, &async_echo_request_value, &async_echo_request_callback](
381 int32_t value, const TestSync::EchoCallback& callback) { 387 int32_t value, const TestSync::EchoCallback& callback) {
382 // Send back the async response first. 388 // Send back the async response first.
383 EXPECT_FALSE(async_echo_request_callback.is_null()); 389 EXPECT_FALSE(async_echo_request_callback.is_null());
384 async_echo_request_callback.Run(async_echo_request_value); 390 async_echo_request_callback.Run(async_echo_request_value);
385 391
386 impl.binding()->Close(); 392 impl.binding()->Close();
387 }); 393 });
388 394
389 bool connection_error_dispatched = false;
390 base::RunLoop run_loop3; 395 base::RunLoop run_loop3;
391 ptr.set_connection_error_handler( 396 ptr.set_connection_error_handler(
392 [&connection_error_dispatched, &run_loop3]() { 397 [&connection_error_dispatched, &run_loop3]() {
393 connection_error_dispatched = true; 398 connection_error_dispatched = true;
394 run_loop3.Quit(); 399 run_loop3.Quit();
395 }); 400 });
396 401
397 int32_t result_value = -1; 402 int32_t result_value = -1;
398 ASSERT_FALSE(ptr->Echo(456, &result_value)); 403 ASSERT_FALSE(ptr->Echo(456, &result_value));
399 EXPECT_EQ(-1, result_value); 404 EXPECT_EQ(-1, result_value);
400 ASSERT_FALSE(connection_error_dispatched); 405 ASSERT_FALSE(connection_error_dispatched);
401 EXPECT_FALSE(ptr.encountered_error()); 406 EXPECT_FALSE(ptr.encountered_error());
402 407
403 // Although the AsyncEcho response arrives before the Echo response, it should 408 // Although the AsyncEcho response arrives before the Echo response, it should
404 // be queued and not yet dispatched. 409 // be queued and not yet dispatched.
405 EXPECT_FALSE(async_echo_response_dispatched); 410 EXPECT_FALSE(async_echo_response_dispatched);
406 411
407 // Run until the AsyncEcho response is dispatched. 412 // Run until the AsyncEcho response is dispatched.
408 run_loop2.Run(); 413 run_loop2.Run();
409 414
410 EXPECT_TRUE(async_echo_response_dispatched); 415 EXPECT_TRUE(async_echo_response_dispatched);
411 ASSERT_FALSE(connection_error_dispatched);
412 EXPECT_FALSE(ptr.encountered_error());
413 416
414 // Run until the error notification is dispatched. 417 // Run until the error notification is dispatched.
415 run_loop3.Run(); 418 run_loop3.Run();
416 419
417 ASSERT_TRUE(connection_error_dispatched); 420 ASSERT_TRUE(connection_error_dispatched);
418 EXPECT_TRUE(ptr.encountered_error()); 421 EXPECT_TRUE(ptr.encountered_error());
419 } 422 }
420 423
421 TEST_F(SyncMethodTest, InvalidMessageDuringSyncCall) { 424 TEST_F(SyncMethodTest, InvalidMessageDuringSyncCall) {
422 // Test that while an interface pointer is waiting for the response to a sync 425 // Test that while an interface pointer is waiting for the response to a sync
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 EXPECT_EQ(-1, result_value); 458 EXPECT_EQ(-1, result_value);
456 ASSERT_FALSE(connection_error_dispatched); 459 ASSERT_FALSE(connection_error_dispatched);
457 460
458 run_loop.Run(); 461 run_loop.Run();
459 ASSERT_TRUE(connection_error_dispatched); 462 ASSERT_TRUE(connection_error_dispatched);
460 } 463 }
461 464
462 } // namespace 465 } // namespace
463 } // namespace test 466 } // namespace test
464 } // namespace mojo 467 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/sync_handle_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698