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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "mojo/edk/embedder/master_process_delegate.h" | 12 #include "mojo/edk/embedder/master_process_delegate.h" |
13 #include "mojo/edk/embedder/platform_channel_pair.h" | |
14 #include "mojo/edk/embedder/simple_platform_support.h" | 13 #include "mojo/edk/embedder/simple_platform_support.h" |
15 #include "mojo/edk/embedder/slave_process_delegate.h" | 14 #include "mojo/edk/embedder/slave_process_delegate.h" |
| 15 #include "mojo/edk/platform/platform_pipe.h" |
16 #include "mojo/edk/system/channel_manager.h" | 16 #include "mojo/edk/system/channel_manager.h" |
17 #include "mojo/edk/system/connection_identifier.h" | 17 #include "mojo/edk/system/connection_identifier.h" |
18 #include "mojo/edk/system/dispatcher.h" | 18 #include "mojo/edk/system/dispatcher.h" |
19 #include "mojo/edk/system/message_pipe.h" | 19 #include "mojo/edk/system/message_pipe.h" |
20 #include "mojo/edk/system/message_pipe_dispatcher.h" | 20 #include "mojo/edk/system/message_pipe_dispatcher.h" |
21 #include "mojo/edk/system/process_identifier.h" | 21 #include "mojo/edk/system/process_identifier.h" |
22 #include "mojo/edk/system/test/test_command_line.h" | 22 #include "mojo/edk/system/test/test_command_line.h" |
23 #include "mojo/edk/system/test/test_io_thread.h" | 23 #include "mojo/edk/system/test/test_io_thread.h" |
24 #include "mojo/edk/system/test/timeouts.h" | 24 #include "mojo/edk/system/test/timeouts.h" |
25 #include "mojo/edk/system/waiter.h" | 25 #include "mojo/edk/system/waiter.h" |
26 #include "mojo/edk/test/multiprocess_test_helper.h" | 26 #include "mojo/edk/test/multiprocess_test_helper.h" |
27 #include "mojo/edk/test/test_utils.h" | 27 #include "mojo/edk/test/test_utils.h" |
28 #include "mojo/edk/util/command_line.h" | 28 #include "mojo/edk/util/command_line.h" |
29 #include "mojo/edk/util/waitable_event.h" | 29 #include "mojo/edk/util/waitable_event.h" |
30 #include "mojo/public/cpp/system/macros.h" | 30 #include "mojo/public/cpp/system/macros.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
| 33 using mojo::platform::PlatformPipe; |
33 using mojo::platform::ScopedPlatformHandle; | 34 using mojo::platform::ScopedPlatformHandle; |
34 using mojo::util::AutoResetWaitableEvent; | 35 using mojo::util::AutoResetWaitableEvent; |
35 using mojo::util::ManualResetWaitableEvent; | 36 using mojo::util::ManualResetWaitableEvent; |
36 using mojo::util::RefPtr; | 37 using mojo::util::RefPtr; |
37 | 38 |
38 namespace mojo { | 39 namespace mojo { |
39 namespace system { | 40 namespace system { |
40 namespace { | 41 namespace { |
41 | 42 |
42 const char kConnectionIdFlag[] = "test-connection-id"; | 43 const char kConnectionIdFlag[] = "test-connection-id"; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 IPCSupport* master_ipc_support) | 166 IPCSupport* master_ipc_support) |
166 : test_io_thread_(test_io_thread), | 167 : test_io_thread_(test_io_thread), |
167 master_ipc_support_(master_ipc_support), | 168 master_ipc_support_(master_ipc_support), |
168 connection_id_(master_ipc_support_->GenerateConnectionIdentifier()), | 169 connection_id_(master_ipc_support_->GenerateConnectionIdentifier()), |
169 slave_id_(kInvalidProcessIdentifier) {} | 170 slave_id_(kInvalidProcessIdentifier) {} |
170 ~TestSlaveConnection() {} | 171 ~TestSlaveConnection() {} |
171 | 172 |
172 // After this is called, |ShutdownChannelToSlave()| must be called (possibly | 173 // After this is called, |ShutdownChannelToSlave()| must be called (possibly |
173 // after |WaitForChannelToSlave()|) before destruction. | 174 // after |WaitForChannelToSlave()|) before destruction. |
174 RefPtr<MessagePipeDispatcher> ConnectToSlave() { | 175 RefPtr<MessagePipeDispatcher> ConnectToSlave() { |
175 embedder::PlatformChannelPair channel_pair; | 176 PlatformPipe channel_pair; |
176 // Note: |ChannelId|s and |ProcessIdentifier|s are interchangeable. | 177 // Note: |ChannelId|s and |ProcessIdentifier|s are interchangeable. |
177 RefPtr<MessagePipeDispatcher> mp = master_ipc_support_->ConnectToSlave( | 178 RefPtr<MessagePipeDispatcher> mp = master_ipc_support_->ConnectToSlave( |
178 connection_id_, nullptr, channel_pair.handle0.Pass(), | 179 connection_id_, nullptr, channel_pair.handle0.Pass(), |
179 [this]() { event_.Signal(); }, nullptr, &slave_id_); | 180 [this]() { event_.Signal(); }, nullptr, &slave_id_); |
180 EXPECT_TRUE(mp); | 181 EXPECT_TRUE(mp); |
181 EXPECT_NE(slave_id_, kInvalidProcessIdentifier); | 182 EXPECT_NE(slave_id_, kInvalidProcessIdentifier); |
182 EXPECT_NE(slave_id_, kMasterProcessIdentifier); | 183 EXPECT_NE(slave_id_, kMasterProcessIdentifier); |
183 slave_platform_handle_ = channel_pair.handle1.Pass(); | 184 slave_platform_handle_ = channel_pair.handle1.Pass(); |
184 return mp; | 185 return mp; |
185 } | 186 } |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 } | 569 } |
569 | 570 |
570 } // namespace | 571 } // namespace |
571 | 572 |
572 // Note: This test isn't in an anonymous namespace, since it needs to be | 573 // Note: This test isn't in an anonymous namespace, since it needs to be |
573 // friended by |IPCSupport|. | 574 // friended by |IPCSupport|. |
574 TEST_F(IPCSupportTest, MasterSlaveInternal) { | 575 TEST_F(IPCSupportTest, MasterSlaveInternal) { |
575 ConnectionIdentifier connection_id = | 576 ConnectionIdentifier connection_id = |
576 master_ipc_support().GenerateConnectionIdentifier(); | 577 master_ipc_support().GenerateConnectionIdentifier(); |
577 | 578 |
578 embedder::PlatformChannelPair channel_pair; | 579 PlatformPipe channel_pair; |
579 ProcessIdentifier slave_id = kInvalidProcessIdentifier; | 580 ProcessIdentifier slave_id = kInvalidProcessIdentifier; |
580 ScopedPlatformHandle master_second_platform_handle = | 581 ScopedPlatformHandle master_second_platform_handle = |
581 master_ipc_support().ConnectToSlaveInternal( | 582 master_ipc_support().ConnectToSlaveInternal( |
582 connection_id, nullptr, channel_pair.handle0.Pass(), &slave_id); | 583 connection_id, nullptr, channel_pair.handle0.Pass(), &slave_id); |
583 ASSERT_TRUE(master_second_platform_handle.is_valid()); | 584 ASSERT_TRUE(master_second_platform_handle.is_valid()); |
584 EXPECT_NE(slave_id, kInvalidProcessIdentifier); | 585 EXPECT_NE(slave_id, kInvalidProcessIdentifier); |
585 EXPECT_NE(slave_id, kMasterProcessIdentifier); | 586 EXPECT_NE(slave_id, kMasterProcessIdentifier); |
586 | 587 |
587 TestSlaveProcessDelegate slave_process_delegate; | 588 TestSlaveProcessDelegate slave_process_delegate; |
588 // Note: Run process delegate methods on the I/O thread. | 589 // Note: Run process delegate methods on the I/O thread. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 708 |
708 test_io_thread.PostTaskAndWait( | 709 test_io_thread.PostTaskAndWait( |
709 [&ipc_support]() { ipc_support.ShutdownOnIOThread(); }); | 710 [&ipc_support]() { ipc_support.ShutdownOnIOThread(); }); |
710 } | 711 } |
711 | 712 |
712 // 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 |
713 // slave should get OnMasterDisconnect(), which we currently don't test.) | 714 // slave should get OnMasterDisconnect(), which we currently don't test.) |
714 | 715 |
715 } // namespace system | 716 } // namespace system |
716 } // namespace mojo | 717 } // namespace mojo |
OLD | NEW |