OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
17 #include "base/files/scoped_file.h" | 17 #include "base/files/scoped_file.h" |
18 #include "base/files/scoped_temp_dir.h" | 18 #include "base/files/scoped_temp_dir.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "mojo/edk/embedder/platform_channel_pair.h" |
22 #include "mojo/edk/embedder/scoped_platform_handle.h" | 23 #include "mojo/edk/embedder/scoped_platform_handle.h" |
23 #include "mojo/edk/system/handle_signals_state.h" | 24 #include "mojo/edk/system/handle_signals_state.h" |
24 #include "mojo/edk/system/test_utils.h" | 25 #include "mojo/edk/system/test_utils.h" |
25 #include "mojo/edk/test/mojo_test_base.h" | 26 #include "mojo/edk/test/mojo_test_base.h" |
26 #include "mojo/edk/test/test_utils.h" | 27 #include "mojo/edk/test/test_utils.h" |
27 #include "mojo/public/c/system/buffer.h" | 28 #include "mojo/public/c/system/buffer.h" |
28 #include "mojo/public/c/system/functions.h" | 29 #include "mojo/public/c/system/functions.h" |
29 #include "mojo/public/c/system/types.h" | 30 #include "mojo/public/c/system/types.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 | 32 |
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 EXPECT_EQ("qux", ReadMessage(p)); | 1265 EXPECT_EQ("qux", ReadMessage(p)); |
1265 | 1266 |
1266 // Expect to have peer closure signaled. | 1267 // Expect to have peer closure signaled. |
1267 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(p, MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 1268 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(p, MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
1268 MOJO_DEADLINE_INDEFINITE, nullptr)); | 1269 MOJO_DEADLINE_INDEFINITE, nullptr)); |
1269 | 1270 |
1270 WriteMessage(h, "quit"); | 1271 WriteMessage(h, "quit"); |
1271 END_CHILD() | 1272 END_CHILD() |
1272 } | 1273 } |
1273 | 1274 |
| 1275 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(BootstrapMessagePipeAsyncClient, |
| 1276 MultiprocessMessagePipeTest, parent) { |
| 1277 // Receive one end of a platform channel from the parent. |
| 1278 MojoHandle channel_handle; |
| 1279 EXPECT_EQ("hi", ReadMessageWithHandles(parent, &channel_handle, 1)); |
| 1280 ScopedPlatformHandle channel; |
| 1281 EXPECT_EQ(MOJO_RESULT_OK, |
| 1282 edk::PassWrappedPlatformHandle(channel_handle, &channel)); |
| 1283 ASSERT_TRUE(channel.is_valid()); |
| 1284 |
| 1285 // Create a new pipe using our end of the channel. |
| 1286 ScopedMessagePipeHandle pipe = edk::CreateMessagePipe(std::move(channel)); |
| 1287 |
| 1288 // Ensure that we can read and write on the new pipe. |
| 1289 VerifyEcho(pipe.get().value(), "goodbye"); |
| 1290 } |
| 1291 |
| 1292 TEST_F(MultiprocessMessagePipeTest, BootstrapMessagePipeAsync) { |
| 1293 // Tests that new cross-process message pipes can be created synchronously |
| 1294 // using asynchronous negotiation over an arbitrary platform channel. |
| 1295 RUN_CHILD_ON_PIPE(BootstrapMessagePipeAsyncClient, child) |
| 1296 // Pass one end of a platform channel to the child. |
| 1297 PlatformChannelPair platform_channel; |
| 1298 MojoHandle client_channel_handle; |
| 1299 EXPECT_EQ(MOJO_RESULT_OK, |
| 1300 CreatePlatformHandleWrapper(platform_channel.PassClientHandle(), |
| 1301 &client_channel_handle)); |
| 1302 WriteMessageWithHandles(child, "hi", &client_channel_handle, 1); |
| 1303 |
| 1304 // Create a new pipe using our end of the channel. |
| 1305 ScopedMessagePipeHandle pipe = |
| 1306 edk::CreateMessagePipe(platform_channel.PassServerHandle()); |
| 1307 |
| 1308 // Ensure that we can read and write on the new pipe. |
| 1309 VerifyEcho(pipe.get().value(), "goodbye"); |
| 1310 END_CHILD() |
| 1311 } |
| 1312 |
1274 } // namespace | 1313 } // namespace |
1275 } // namespace edk | 1314 } // namespace edk |
1276 } // namespace mojo | 1315 } // namespace mojo |
OLD | NEW |