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

Side by Side Diff: mojo/edk/system/raw_channel_unittest.cc

Issue 1526063003: EDK: Add TaskRunner and PlatformHandleWatcher to RawChannel. (Closed) Base URL: https://github.com/domokit/mojo.git@channel_watcher
Patch Set: Created 5 years 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/edk/system/raw_channel.cc ('k') | mojo/edk/system/slave_connection_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/edk/system/raw_channel.h" 5 #include "mojo/edk/system/raw_channel.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 std::vector<unsigned char> bytes_; 188 std::vector<unsigned char> bytes_;
189 189
190 MOJO_DISALLOW_COPY_AND_ASSIGN(TestMessageReaderAndChecker); 190 MOJO_DISALLOW_COPY_AND_ASSIGN(TestMessageReaderAndChecker);
191 }; 191 };
192 192
193 // Tests writing (and verifies reading using our own custom reader). 193 // Tests writing (and verifies reading using our own custom reader).
194 TEST_F(RawChannelTest, WriteMessage) { 194 TEST_F(RawChannelTest, WriteMessage) {
195 WriteOnlyRawChannelDelegate delegate; 195 WriteOnlyRawChannelDelegate delegate;
196 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); 196 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
197 TestMessageReaderAndChecker checker(handles[1].get()); 197 TestMessageReaderAndChecker checker(handles[1].get());
198 io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); }); 198 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
199 rc->Init(io_thread()->task_runner().Clone(),
200 io_thread()->platform_handle_watcher(), &delegate);
201 });
199 202
200 // Write and read, for a variety of sizes. 203 // Write and read, for a variety of sizes.
201 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) { 204 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) {
202 EXPECT_TRUE(rc->WriteMessage(MakeTestMessage(size))); 205 EXPECT_TRUE(rc->WriteMessage(MakeTestMessage(size)));
203 EXPECT_TRUE(checker.ReadAndCheckNextMessage(size)) << size; 206 EXPECT_TRUE(checker.ReadAndCheckNextMessage(size)) << size;
204 } 207 }
205 208
206 // Write/queue and read afterwards, for a variety of sizes. 209 // Write/queue and read afterwards, for a variety of sizes.
207 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) 210 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1)
208 EXPECT_TRUE(rc->WriteMessage(MakeTestMessage(size))); 211 EXPECT_TRUE(rc->WriteMessage(MakeTestMessage(size)));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 std::vector<uint32_t> expected_sizes_ MOJO_GUARDED_BY(mutex_); 273 std::vector<uint32_t> expected_sizes_ MOJO_GUARDED_BY(mutex_);
271 size_t position_ MOJO_GUARDED_BY(mutex_); 274 size_t position_ MOJO_GUARDED_BY(mutex_);
272 275
273 MOJO_DISALLOW_COPY_AND_ASSIGN(ReadCheckerRawChannelDelegate); 276 MOJO_DISALLOW_COPY_AND_ASSIGN(ReadCheckerRawChannelDelegate);
274 }; 277 };
275 278
276 // Tests reading (writing using our own custom writer). 279 // Tests reading (writing using our own custom writer).
277 TEST_F(RawChannelTest, OnReadMessage) { 280 TEST_F(RawChannelTest, OnReadMessage) {
278 ReadCheckerRawChannelDelegate delegate; 281 ReadCheckerRawChannelDelegate delegate;
279 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); 282 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
280 io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); }); 283 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
284 rc->Init(io_thread()->task_runner().Clone(),
285 io_thread()->platform_handle_watcher(), &delegate);
286 });
281 287
282 // Write and read, for a variety of sizes. 288 // Write and read, for a variety of sizes.
283 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) { 289 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) {
284 delegate.SetExpectedSizes(std::vector<uint32_t>(1, size)); 290 delegate.SetExpectedSizes(std::vector<uint32_t>(1, size));
285 291
286 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size)); 292 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size));
287 293
288 delegate.Wait(); 294 delegate.Wait();
289 } 295 }
290 296
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 368
363 MOJO_DISALLOW_COPY_AND_ASSIGN(ReadCountdownRawChannelDelegate); 369 MOJO_DISALLOW_COPY_AND_ASSIGN(ReadCountdownRawChannelDelegate);
364 }; 370 };
365 371
366 TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) { 372 TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) {
367 static const size_t kNumWriterThreads = 10; 373 static const size_t kNumWriterThreads = 10;
368 static const size_t kNumWriteMessagesPerThread = 4000; 374 static const size_t kNumWriteMessagesPerThread = 4000;
369 375
370 WriteOnlyRawChannelDelegate writer_delegate; 376 WriteOnlyRawChannelDelegate writer_delegate;
371 std::unique_ptr<RawChannel> writer_rc(RawChannel::Create(handles[0].Pass())); 377 std::unique_ptr<RawChannel> writer_rc(RawChannel::Create(handles[0].Pass()));
372 io_thread()->PostTaskAndWait( 378 io_thread()->PostTaskAndWait([this, &writer_rc, &writer_delegate]() {
373 [&writer_rc, &writer_delegate]() { writer_rc->Init(&writer_delegate); }); 379 writer_rc->Init(io_thread()->task_runner().Clone(),
380 io_thread()->platform_handle_watcher(), &writer_delegate);
381 });
374 382
375 ReadCountdownRawChannelDelegate reader_delegate(kNumWriterThreads * 383 ReadCountdownRawChannelDelegate reader_delegate(kNumWriterThreads *
376 kNumWriteMessagesPerThread); 384 kNumWriteMessagesPerThread);
377 std::unique_ptr<RawChannel> reader_rc(RawChannel::Create(handles[1].Pass())); 385 std::unique_ptr<RawChannel> reader_rc(RawChannel::Create(handles[1].Pass()));
378 io_thread()->PostTaskAndWait( 386 io_thread()->PostTaskAndWait([this, &reader_rc, &reader_delegate]() {
379 [&reader_rc, &reader_delegate]() { reader_rc->Init(&reader_delegate); }); 387 reader_rc->Init(io_thread()->task_runner().Clone(),
388 io_thread()->platform_handle_watcher(), &reader_delegate);
389 });
380 390
381 { 391 {
382 std::vector<std::unique_ptr<RawChannelWriterThread>> writer_threads; 392 std::vector<std::unique_ptr<RawChannelWriterThread>> writer_threads;
383 for (size_t i = 0; i < kNumWriterThreads; i++) { 393 for (size_t i = 0; i < kNumWriterThreads; i++) {
384 writer_threads.push_back(MakeUnique<RawChannelWriterThread>( 394 writer_threads.push_back(MakeUnique<RawChannelWriterThread>(
385 writer_rc.get(), kNumWriteMessagesPerThread)); 395 writer_rc.get(), kNumWriteMessagesPerThread));
386 } 396 }
387 for (size_t i = 0; i < writer_threads.size(); i++) 397 for (size_t i = 0; i < writer_threads.size(); i++)
388 writer_threads[i]->Start(); 398 writer_threads[i]->Start();
389 } // Joins all the writer threads. 399 } // Joins all the writer threads.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 bool expecting_read_error_; 461 bool expecting_read_error_;
452 bool expecting_write_error_; 462 bool expecting_write_error_;
453 463
454 MOJO_DISALLOW_COPY_AND_ASSIGN(ErrorRecordingRawChannelDelegate); 464 MOJO_DISALLOW_COPY_AND_ASSIGN(ErrorRecordingRawChannelDelegate);
455 }; 465 };
456 466
457 // Tests (fatal) errors. 467 // Tests (fatal) errors.
458 TEST_F(RawChannelTest, OnError) { 468 TEST_F(RawChannelTest, OnError) {
459 ErrorRecordingRawChannelDelegate delegate(0, true, true); 469 ErrorRecordingRawChannelDelegate delegate(0, true, true);
460 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); 470 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
461 io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); }); 471 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
472 rc->Init(io_thread()->task_runner().Clone(),
473 io_thread()->platform_handle_watcher(), &delegate);
474 });
462 475
463 // Close the handle of the other end, which should make writing fail. 476 // Close the handle of the other end, which should make writing fail.
464 handles[1].reset(); 477 handles[1].reset();
465 478
466 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); 479 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
467 480
468 // We should get a write error. 481 // We should get a write error.
469 delegate.WaitForWriteError(); 482 delegate.WaitForWriteError();
470 483
471 // We should also get a read error. 484 // We should also get a read error.
(...skipping 19 matching lines...) Expand all
491 i++, message_size += message_size / 2 + 1) 504 i++, message_size += message_size / 2 + 1)
492 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), message_size)); 505 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), message_size));
493 506
494 // Close the other end, which should make writing fail. 507 // Close the other end, which should make writing fail.
495 handles[1].reset(); 508 handles[1].reset();
496 509
497 // Only start up reading here. The system buffer should still contain the 510 // Only start up reading here. The system buffer should still contain the
498 // messages that were written. 511 // messages that were written.
499 ErrorRecordingRawChannelDelegate delegate(kMessageCount, true, true); 512 ErrorRecordingRawChannelDelegate delegate(kMessageCount, true, true);
500 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); 513 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
501 io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); }); 514 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
515 rc->Init(io_thread()->task_runner().Clone(),
516 io_thread()->platform_handle_watcher(), &delegate);
517 });
502 518
503 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); 519 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
504 520
505 // We should definitely get a write error. 521 // We should definitely get a write error.
506 delegate.WaitForWriteError(); 522 delegate.WaitForWriteError();
507 523
508 // Wait for reading to finish. A writing failure shouldn't affect reading. 524 // Wait for reading to finish. A writing failure shouldn't affect reading.
509 delegate.Wait(); 525 delegate.Wait();
510 526
511 // And then we should get a read error. 527 // And then we should get a read error.
512 delegate.WaitForReadError(); 528 delegate.WaitForReadError();
513 529
514 io_thread()->PostTaskAndWait([&rc]() { rc->Shutdown(); }); 530 io_thread()->PostTaskAndWait([&rc]() { rc->Shutdown(); });
515 } 531 }
516 532
517 // RawChannelTest.WriteMessageAfterShutdown ------------------------------------ 533 // RawChannelTest.WriteMessageAfterShutdown ------------------------------------
518 534
519 // Makes sure that calling |WriteMessage()| after |Shutdown()| behaves 535 // Makes sure that calling |WriteMessage()| after |Shutdown()| behaves
520 // correctly. 536 // correctly.
521 TEST_F(RawChannelTest, WriteMessageAfterShutdown) { 537 TEST_F(RawChannelTest, WriteMessageAfterShutdown) {
522 WriteOnlyRawChannelDelegate delegate; 538 WriteOnlyRawChannelDelegate delegate;
523 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); 539 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
524 io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); }); 540 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
541 rc->Init(io_thread()->task_runner().Clone(),
542 io_thread()->platform_handle_watcher(), &delegate);
543 });
525 io_thread()->PostTaskAndWait([&rc]() { rc->Shutdown(); }); 544 io_thread()->PostTaskAndWait([&rc]() { rc->Shutdown(); });
526 545
527 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); 546 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
528 } 547 }
529 548
530 // RawChannelTest.{Shutdown, ShutdownAndDestroy}OnReadMessage ------------------ 549 // RawChannelTest.{Shutdown, ShutdownAndDestroy}OnReadMessage ------------------
531 550
532 class ShutdownOnReadMessageRawChannelDelegate : public RawChannel::Delegate { 551 class ShutdownOnReadMessageRawChannelDelegate : public RawChannel::Delegate {
533 public: 552 public:
534 explicit ShutdownOnReadMessageRawChannelDelegate(RawChannel* raw_channel, 553 explicit ShutdownOnReadMessageRawChannelDelegate(RawChannel* raw_channel,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 MOJO_DISALLOW_COPY_AND_ASSIGN(ShutdownOnReadMessageRawChannelDelegate); 590 MOJO_DISALLOW_COPY_AND_ASSIGN(ShutdownOnReadMessageRawChannelDelegate);
572 }; 591 };
573 592
574 TEST_F(RawChannelTest, ShutdownOnReadMessage) { 593 TEST_F(RawChannelTest, ShutdownOnReadMessage) {
575 // Write a few messages into the other end. 594 // Write a few messages into the other end.
576 for (size_t count = 0; count < 5; count++) 595 for (size_t count = 0; count < 5; count++)
577 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), 10)); 596 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), 10));
578 597
579 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); 598 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
580 ShutdownOnReadMessageRawChannelDelegate delegate(rc.get(), false); 599 ShutdownOnReadMessageRawChannelDelegate delegate(rc.get(), false);
581 io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); }); 600 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
601 rc->Init(io_thread()->task_runner().Clone(),
602 io_thread()->platform_handle_watcher(), &delegate);
603 });
582 604
583 // Wait for the delegate, which will shut the |RawChannel| down. 605 // Wait for the delegate, which will shut the |RawChannel| down.
584 delegate.Wait(); 606 delegate.Wait();
585 } 607 }
586 608
587 TEST_F(RawChannelTest, ShutdownAndDestroyOnReadMessage) { 609 TEST_F(RawChannelTest, ShutdownAndDestroyOnReadMessage) {
588 // Write a message into the other end. 610 // Write a message into the other end.
589 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), 10)); 611 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), 10));
590 612
591 // The delegate will destroy |rc|. 613 // The delegate will destroy |rc|.
592 RawChannel* rc = RawChannel::Create(handles[0].Pass()).release(); 614 RawChannel* rc = RawChannel::Create(handles[0].Pass()).release();
593 ShutdownOnReadMessageRawChannelDelegate delegate(rc, true); 615 ShutdownOnReadMessageRawChannelDelegate delegate(rc, true);
594 io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); }); 616 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
617 rc->Init(io_thread()->task_runner().Clone(),
618 io_thread()->platform_handle_watcher(), &delegate);
619 });
595 620
596 // Wait for the delegate, which will shut the |RawChannel| down. 621 // Wait for the delegate, which will shut the |RawChannel| down.
597 delegate.Wait(); 622 delegate.Wait();
598 } 623 }
599 624
600 // RawChannelTest.{Shutdown, ShutdownAndDestroy}OnError{Read, Write} ----------- 625 // RawChannelTest.{Shutdown, ShutdownAndDestroy}OnError{Read, Write} -----------
601 626
602 class ShutdownOnErrorRawChannelDelegate : public RawChannel::Delegate { 627 class ShutdownOnErrorRawChannelDelegate : public RawChannel::Delegate {
603 public: 628 public:
604 ShutdownOnErrorRawChannelDelegate(RawChannel* raw_channel, 629 ShutdownOnErrorRawChannelDelegate(RawChannel* raw_channel,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 AutoResetWaitableEvent done_event_; 666 AutoResetWaitableEvent done_event_;
642 bool did_shutdown_; 667 bool did_shutdown_;
643 668
644 MOJO_DISALLOW_COPY_AND_ASSIGN(ShutdownOnErrorRawChannelDelegate); 669 MOJO_DISALLOW_COPY_AND_ASSIGN(ShutdownOnErrorRawChannelDelegate);
645 }; 670 };
646 671
647 TEST_F(RawChannelTest, ShutdownOnErrorRead) { 672 TEST_F(RawChannelTest, ShutdownOnErrorRead) {
648 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); 673 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
649 ShutdownOnErrorRawChannelDelegate delegate( 674 ShutdownOnErrorRawChannelDelegate delegate(
650 rc.get(), false, RawChannel::Delegate::ERROR_READ_SHUTDOWN); 675 rc.get(), false, RawChannel::Delegate::ERROR_READ_SHUTDOWN);
651 io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); }); 676 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
677 rc->Init(io_thread()->task_runner().Clone(),
678 io_thread()->platform_handle_watcher(), &delegate);
679 });
652 680
653 // Close the handle of the other end, which should stuff fail. 681 // Close the handle of the other end, which should stuff fail.
654 handles[1].reset(); 682 handles[1].reset();
655 683
656 // Wait for the delegate, which will shut the |RawChannel| down. 684 // Wait for the delegate, which will shut the |RawChannel| down.
657 delegate.Wait(); 685 delegate.Wait();
658 } 686 }
659 687
660 TEST_F(RawChannelTest, ShutdownAndDestroyOnErrorRead) { 688 TEST_F(RawChannelTest, ShutdownAndDestroyOnErrorRead) {
661 RawChannel* rc = RawChannel::Create(handles[0].Pass()).release(); 689 RawChannel* rc = RawChannel::Create(handles[0].Pass()).release();
662 ShutdownOnErrorRawChannelDelegate delegate( 690 ShutdownOnErrorRawChannelDelegate delegate(
663 rc, true, RawChannel::Delegate::ERROR_READ_SHUTDOWN); 691 rc, true, RawChannel::Delegate::ERROR_READ_SHUTDOWN);
664 io_thread()->PostTaskAndWait([rc, &delegate]() { rc->Init(&delegate); }); 692 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
693 rc->Init(io_thread()->task_runner().Clone(),
694 io_thread()->platform_handle_watcher(), &delegate);
695 });
665 696
666 // Close the handle of the other end, which should stuff fail. 697 // Close the handle of the other end, which should stuff fail.
667 handles[1].reset(); 698 handles[1].reset();
668 699
669 // Wait for the delegate, which will shut the |RawChannel| down. 700 // Wait for the delegate, which will shut the |RawChannel| down.
670 delegate.Wait(); 701 delegate.Wait();
671 } 702 }
672 703
673 TEST_F(RawChannelTest, ShutdownOnErrorWrite) { 704 TEST_F(RawChannelTest, ShutdownOnErrorWrite) {
674 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); 705 std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
675 ShutdownOnErrorRawChannelDelegate delegate(rc.get(), false, 706 ShutdownOnErrorRawChannelDelegate delegate(rc.get(), false,
676 RawChannel::Delegate::ERROR_WRITE); 707 RawChannel::Delegate::ERROR_WRITE);
677 io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); }); 708 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
709 rc->Init(io_thread()->task_runner().Clone(),
710 io_thread()->platform_handle_watcher(), &delegate);
711 });
678 712
679 // Close the handle of the other end, which should stuff fail. 713 // Close the handle of the other end, which should stuff fail.
680 handles[1].reset(); 714 handles[1].reset();
681 715
682 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); 716 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
683 717
684 // Wait for the delegate, which will shut the |RawChannel| down. 718 // Wait for the delegate, which will shut the |RawChannel| down.
685 delegate.Wait(); 719 delegate.Wait();
686 } 720 }
687 721
688 TEST_F(RawChannelTest, ShutdownAndDestroyOnErrorWrite) { 722 TEST_F(RawChannelTest, ShutdownAndDestroyOnErrorWrite) {
689 RawChannel* rc = RawChannel::Create(handles[0].Pass()).release(); 723 RawChannel* rc = RawChannel::Create(handles[0].Pass()).release();
690 ShutdownOnErrorRawChannelDelegate delegate(rc, true, 724 ShutdownOnErrorRawChannelDelegate delegate(rc, true,
691 RawChannel::Delegate::ERROR_WRITE); 725 RawChannel::Delegate::ERROR_WRITE);
692 io_thread()->PostTaskAndWait([rc, &delegate]() { rc->Init(&delegate); }); 726 io_thread()->PostTaskAndWait([this, &rc, &delegate]() {
727 rc->Init(io_thread()->task_runner().Clone(),
728 io_thread()->platform_handle_watcher(), &delegate);
729 });
693 730
694 // Close the handle of the other end, which should stuff fail. 731 // Close the handle of the other end, which should stuff fail.
695 handles[1].reset(); 732 handles[1].reset();
696 733
697 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); 734 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
698 735
699 // Wait for the delegate, which will shut the |RawChannel| down. 736 // Wait for the delegate, which will shut the |RawChannel| down.
700 delegate.Wait(); 737 delegate.Wait();
701 } 738 }
702 739
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 AutoResetWaitableEvent done_event_; 794 AutoResetWaitableEvent done_event_;
758 795
759 MOJO_DISALLOW_COPY_AND_ASSIGN(ReadPlatformHandlesCheckerRawChannelDelegate); 796 MOJO_DISALLOW_COPY_AND_ASSIGN(ReadPlatformHandlesCheckerRawChannelDelegate);
760 }; 797 };
761 798
762 TEST_F(RawChannelTest, ReadWritePlatformHandles) { 799 TEST_F(RawChannelTest, ReadWritePlatformHandles) {
763 test::ScopedTestDir test_dir; 800 test::ScopedTestDir test_dir;
764 801
765 WriteOnlyRawChannelDelegate write_delegate; 802 WriteOnlyRawChannelDelegate write_delegate;
766 std::unique_ptr<RawChannel> rc_write(RawChannel::Create(handles[0].Pass())); 803 std::unique_ptr<RawChannel> rc_write(RawChannel::Create(handles[0].Pass()));
767 io_thread()->PostTaskAndWait( 804 io_thread()->PostTaskAndWait([this, &rc_write, &write_delegate]() {
768 [&rc_write, &write_delegate]() { rc_write->Init(&write_delegate); }); 805 rc_write->Init(io_thread()->task_runner().Clone(),
806 io_thread()->platform_handle_watcher(), &write_delegate);
807 });
769 808
770 ReadPlatformHandlesCheckerRawChannelDelegate read_delegate; 809 ReadPlatformHandlesCheckerRawChannelDelegate read_delegate;
771 std::unique_ptr<RawChannel> rc_read(RawChannel::Create(handles[1].Pass())); 810 std::unique_ptr<RawChannel> rc_read(RawChannel::Create(handles[1].Pass()));
772 io_thread()->PostTaskAndWait( 811 io_thread()->PostTaskAndWait([this, &rc_read, &read_delegate]() {
773 [&rc_read, &read_delegate]() { rc_read->Init(&read_delegate); }); 812 rc_read->Init(io_thread()->task_runner().Clone(),
813 io_thread()->platform_handle_watcher(), &read_delegate);
814 });
774 815
775 util::ScopedFILE fp1(test_dir.CreateFile()); 816 util::ScopedFILE fp1(test_dir.CreateFile());
776 EXPECT_EQ(1u, fwrite("1", 1, 1, fp1.get())); 817 EXPECT_EQ(1u, fwrite("1", 1, 1, fp1.get()));
777 util::ScopedFILE fp2(test_dir.CreateFile()); 818 util::ScopedFILE fp2(test_dir.CreateFile());
778 EXPECT_EQ(1u, fwrite("2", 1, 1, fp2.get())); 819 EXPECT_EQ(1u, fwrite("2", 1, 1, fp2.get()));
779 820
780 { 821 {
781 const char kHello[] = "hello"; 822 const char kHello[] = "hello";
782 auto platform_handles = MakeUnique<std::vector<ScopedPlatformHandle>>(); 823 auto platform_handles = MakeUnique<std::vector<ScopedPlatformHandle>>();
783 platform_handles->push_back( 824 platform_handles->push_back(
(...skipping 13 matching lines...) Expand all
797 838
798 read_delegate.Wait(); 839 read_delegate.Wait();
799 840
800 io_thread()->PostTaskAndWait([&rc_read]() { rc_read->Shutdown(); }); 841 io_thread()->PostTaskAndWait([&rc_read]() { rc_read->Shutdown(); });
801 io_thread()->PostTaskAndWait([&rc_write]() { rc_write->Shutdown(); }); 842 io_thread()->PostTaskAndWait([&rc_write]() { rc_write->Shutdown(); });
802 } 843 }
803 844
804 } // namespace 845 } // namespace
805 } // namespace system 846 } // namespace system
806 } // namespace mojo 847 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/raw_channel.cc ('k') | mojo/edk/system/slave_connection_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698