| OLD | NEW |
| 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 #include "mojo/edk/system/ipc_support.h" | 5 #include "mojo/edk/system/ipc_support.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // Note: Before destruction, |ShutdownIPCSupport()| must be called. | 224 // Note: Before destruction, |ShutdownIPCSupport()| must be called. |
| 225 TestSlave(embedder::PlatformSupport* platform_support, | 225 TestSlave(embedder::PlatformSupport* platform_support, |
| 226 test::TestIOThread* test_io_thread, | 226 test::TestIOThread* test_io_thread, |
| 227 ScopedPlatformHandle platform_handle) | 227 ScopedPlatformHandle platform_handle) |
| 228 : test_io_thread_(test_io_thread), | 228 : test_io_thread_(test_io_thread), |
| 229 slave_ipc_support_(platform_support, | 229 slave_ipc_support_(platform_support, |
| 230 embedder::ProcessType::SLAVE, | 230 embedder::ProcessType::SLAVE, |
| 231 test_io_thread->task_runner().Clone(), | 231 test_io_thread->task_runner().Clone(), |
| 232 &slave_process_delegate_, | 232 &slave_process_delegate_, |
| 233 test_io_thread->task_runner().Clone(), | 233 test_io_thread->task_runner().Clone(), |
| 234 test_io_thread->platform_handle_watcher(), |
| 234 platform_handle.Pass()) {} | 235 platform_handle.Pass()) {} |
| 235 ~TestSlave() {} | 236 ~TestSlave() {} |
| 236 | 237 |
| 237 // After this is called, |ShutdownChannelToMaster()| must be called (possibly | 238 // After this is called, |ShutdownChannelToMaster()| must be called (possibly |
| 238 // after |WaitForChannelToMaster()|) before destruction. | 239 // after |WaitForChannelToMaster()|) before destruction. |
| 239 RefPtr<MessagePipeDispatcher> ConnectToMaster( | 240 RefPtr<MessagePipeDispatcher> ConnectToMaster( |
| 240 const ConnectionIdentifier& connection_id) { | 241 const ConnectionIdentifier& connection_id) { |
| 241 ProcessIdentifier master_id = kInvalidProcessIdentifier; | 242 ProcessIdentifier master_id = kInvalidProcessIdentifier; |
| 242 RefPtr<MessagePipeDispatcher> mp = slave_ipc_support_.ConnectToMaster( | 243 RefPtr<MessagePipeDispatcher> mp = slave_ipc_support_.ConnectToMaster( |
| 243 connection_id, [this]() { event_.Signal(); }, nullptr, &master_id); | 244 connection_id, [this]() { event_.Signal(); }, nullptr, &master_id); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 class IPCSupportTest : public testing::Test { | 362 class IPCSupportTest : public testing::Test { |
| 362 public: | 363 public: |
| 363 // Note: Run master process delegate methods on the I/O thread. | 364 // Note: Run master process delegate methods on the I/O thread. |
| 364 IPCSupportTest() | 365 IPCSupportTest() |
| 365 : test_io_thread_(test::TestIOThread::StartMode::AUTO), | 366 : test_io_thread_(test::TestIOThread::StartMode::AUTO), |
| 366 master_ipc_support_(&platform_support_, | 367 master_ipc_support_(&platform_support_, |
| 367 embedder::ProcessType::MASTER, | 368 embedder::ProcessType::MASTER, |
| 368 test_io_thread_.task_runner().Clone(), | 369 test_io_thread_.task_runner().Clone(), |
| 369 &master_process_delegate_, | 370 &master_process_delegate_, |
| 370 test_io_thread_.task_runner().Clone(), | 371 test_io_thread_.task_runner().Clone(), |
| 372 test_io_thread_.platform_handle_watcher(), |
| 371 ScopedPlatformHandle()) {} | 373 ScopedPlatformHandle()) {} |
| 372 ~IPCSupportTest() override {} | 374 ~IPCSupportTest() override {} |
| 373 | 375 |
| 374 std::unique_ptr<TestSlaveSetup> SetupSlave() { | 376 std::unique_ptr<TestSlaveSetup> SetupSlave() { |
| 375 std::unique_ptr<TestSlaveSetup> s( | 377 std::unique_ptr<TestSlaveSetup> s( |
| 376 new TestSlaveSetup(&platform_support_, &test_io_thread_, | 378 new TestSlaveSetup(&platform_support_, &test_io_thread_, |
| 377 &master_process_delegate_, &master_ipc_support_)); | 379 &master_process_delegate_, &master_ipc_support_)); |
| 378 s->Init(); | 380 s->Init(); |
| 379 return s; | 381 return s; |
| 380 } | 382 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 connection_id, nullptr, channel_pair.PassServerHandle(), &slave_id); | 582 connection_id, nullptr, channel_pair.PassServerHandle(), &slave_id); |
| 581 ASSERT_TRUE(master_second_platform_handle.is_valid()); | 583 ASSERT_TRUE(master_second_platform_handle.is_valid()); |
| 582 EXPECT_NE(slave_id, kInvalidProcessIdentifier); | 584 EXPECT_NE(slave_id, kInvalidProcessIdentifier); |
| 583 EXPECT_NE(slave_id, kMasterProcessIdentifier); | 585 EXPECT_NE(slave_id, kMasterProcessIdentifier); |
| 584 | 586 |
| 585 TestSlaveProcessDelegate slave_process_delegate; | 587 TestSlaveProcessDelegate slave_process_delegate; |
| 586 // Note: Run process delegate methods on the I/O thread. | 588 // Note: Run process delegate methods on the I/O thread. |
| 587 IPCSupport slave_ipc_support( | 589 IPCSupport slave_ipc_support( |
| 588 &platform_support(), embedder::ProcessType::SLAVE, | 590 &platform_support(), embedder::ProcessType::SLAVE, |
| 589 test_io_thread().task_runner().Clone(), &slave_process_delegate, | 591 test_io_thread().task_runner().Clone(), &slave_process_delegate, |
| 590 test_io_thread().task_runner().Clone(), channel_pair.PassClientHandle()); | 592 test_io_thread().task_runner().Clone(), |
| 593 test_io_thread().platform_handle_watcher(), |
| 594 channel_pair.PassClientHandle()); |
| 591 | 595 |
| 592 ScopedPlatformHandle slave_second_platform_handle = | 596 ScopedPlatformHandle slave_second_platform_handle = |
| 593 slave_ipc_support.ConnectToMasterInternal(connection_id); | 597 slave_ipc_support.ConnectToMasterInternal(connection_id); |
| 594 ASSERT_TRUE(slave_second_platform_handle.is_valid()); | 598 ASSERT_TRUE(slave_second_platform_handle.is_valid()); |
| 595 | 599 |
| 596 // Write an 'x' through the master's end. | 600 // Write an 'x' through the master's end. |
| 597 size_t n = 0; | 601 size_t n = 0; |
| 598 EXPECT_TRUE(mojo::test::BlockingWrite(master_second_platform_handle.get(), | 602 EXPECT_TRUE(mojo::test::BlockingWrite(master_second_platform_handle.get(), |
| 599 "x", 1, &n)); | 603 "x", 1, &n)); |
| 600 EXPECT_EQ(1u, n); | 604 EXPECT_EQ(1u, n); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 671 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 668 ASSERT_TRUE(client_platform_handle.is_valid()); | 672 ASSERT_TRUE(client_platform_handle.is_valid()); |
| 669 | 673 |
| 670 embedder::SimplePlatformSupport platform_support; | 674 embedder::SimplePlatformSupport platform_support; |
| 671 test::TestIOThread test_io_thread(test::TestIOThread::StartMode::AUTO); | 675 test::TestIOThread test_io_thread(test::TestIOThread::StartMode::AUTO); |
| 672 TestSlaveProcessDelegate slave_process_delegate; | 676 TestSlaveProcessDelegate slave_process_delegate; |
| 673 // Note: Run process delegate methods on the I/O thread. | 677 // Note: Run process delegate methods on the I/O thread. |
| 674 IPCSupport ipc_support( | 678 IPCSupport ipc_support( |
| 675 &platform_support, embedder::ProcessType::SLAVE, | 679 &platform_support, embedder::ProcessType::SLAVE, |
| 676 test_io_thread.task_runner().Clone(), &slave_process_delegate, | 680 test_io_thread.task_runner().Clone(), &slave_process_delegate, |
| 677 test_io_thread.task_runner().Clone(), client_platform_handle.Pass()); | 681 test_io_thread.task_runner().Clone(), |
| 682 test_io_thread.platform_handle_watcher(), client_platform_handle.Pass()); |
| 678 | 683 |
| 679 std::string connection_id_string; | 684 std::string connection_id_string; |
| 680 ASSERT_TRUE(test::GetTestCommandLine()->GetOptionValue( | 685 ASSERT_TRUE(test::GetTestCommandLine()->GetOptionValue( |
| 681 kConnectionIdFlag, &connection_id_string)); | 686 kConnectionIdFlag, &connection_id_string)); |
| 682 bool ok = false; | 687 bool ok = false; |
| 683 ConnectionIdentifier connection_id = | 688 ConnectionIdentifier connection_id = |
| 684 ConnectionIdentifier::FromString(connection_id_string, &ok); | 689 ConnectionIdentifier::FromString(connection_id_string, &ok); |
| 685 ASSERT_TRUE(ok); | 690 ASSERT_TRUE(ok); |
| 686 | 691 |
| 687 ScopedPlatformHandle second_platform_handle = | 692 ScopedPlatformHandle second_platform_handle = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 703 | 708 |
| 704 test_io_thread.PostTaskAndWait( | 709 test_io_thread.PostTaskAndWait( |
| 705 [&ipc_support]() { ipc_support.ShutdownOnIOThread(); }); | 710 [&ipc_support]() { ipc_support.ShutdownOnIOThread(); }); |
| 706 } | 711 } |
| 707 | 712 |
| 708 // TODO(vtl): Also test the case of the master "dying" before the slave. (The | 713 // TODO(vtl): Also test the case of the master "dying" before the slave. (The |
| 709 // slave should get OnMasterDisconnect(), which we currently don't test.) | 714 // slave should get OnMasterDisconnect(), which we currently don't test.) |
| 710 | 715 |
| 711 } // namespace system | 716 } // namespace system |
| 712 } // namespace mojo | 717 } // namespace mojo |
| OLD | NEW |