| OLD | NEW |
| 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/embedder/embedder.h" | 5 #include "mojo/edk/embedder/embedder.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/files/file.h" | 15 #include "base/files/file.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/shared_memory.h" | 18 #include "base/memory/shared_memory.h" |
| 19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/process/process_handle.h" |
| 20 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
| 21 #include "base/test/test_timeouts.h" | 22 #include "base/test/test_timeouts.h" |
| 22 #include "mojo/edk/embedder/platform_channel_pair.h" | 23 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 23 #include "mojo/edk/embedder/test_embedder.h" | 24 #include "mojo/edk/embedder/test_embedder.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/public/c/system/core.h" | 27 #include "mojo/public/c/system/core.h" |
| 27 #include "mojo/public/cpp/system/handle.h" | 28 #include "mojo/public/cpp/system/handle.h" |
| 28 #include "mojo/public/cpp/system/message_pipe.h" | 29 #include "mojo/public/cpp/system/message_pipe.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 175 |
| 175 // Wait for |h0| to become readable and read a message from it. | 176 // Wait for |h0| to become readable and read a message from it. |
| 176 EXPECT_EQ(kBarBaz, ReadMessage(h0)); | 177 EXPECT_EQ(kBarBaz, ReadMessage(h0)); |
| 177 | 178 |
| 178 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); | 179 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); |
| 179 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); | 180 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); |
| 180 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(h0)); | 181 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(h0)); |
| 181 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(h1)); | 182 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(h1)); |
| 182 } | 183 } |
| 183 | 184 |
| 185 TEST_F(EmbedderTest, PipeSetup) { |
| 186 std::string child_token = GenerateRandomToken(); |
| 187 std::string pipe_token = GenerateRandomToken(); |
| 188 |
| 189 ScopedMessagePipeHandle parent_mp = |
| 190 CreateParentMessagePipe(pipe_token, child_token); |
| 191 ScopedMessagePipeHandle child_mp = |
| 192 CreateChildMessagePipe(pipe_token); |
| 193 |
| 194 const std::string kHello = "hello"; |
| 195 WriteMessage(parent_mp.get().value(), kHello); |
| 196 |
| 197 EXPECT_EQ(kHello, ReadMessage(child_mp.get().value())); |
| 198 } |
| 199 |
| 200 TEST_F(EmbedderTest, PipeSetup_LaunchDeath) { |
| 201 PlatformChannelPair pair; |
| 202 |
| 203 std::string child_token = GenerateRandomToken(); |
| 204 std::string pipe_token = GenerateRandomToken(); |
| 205 |
| 206 ScopedMessagePipeHandle parent_mp = |
| 207 CreateParentMessagePipe(pipe_token, child_token); |
| 208 ChildProcessLaunched(base::GetCurrentProcessHandle(), pair.PassServerHandle(), |
| 209 child_token); |
| 210 |
| 211 // Close the remote end, simulating child death before the child connects to |
| 212 // the reserved port. |
| 213 ignore_result(pair.PassClientHandle()); |
| 214 |
| 215 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(parent_mp.get().value(), |
| 216 MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 217 MOJO_DEADLINE_INDEFINITE, |
| 218 nullptr)); |
| 219 } |
| 220 |
| 221 TEST_F(EmbedderTest, PipeSetup_LaunchFailure) { |
| 222 PlatformChannelPair pair; |
| 223 |
| 224 std::string child_token = GenerateRandomToken(); |
| 225 std::string pipe_token = GenerateRandomToken(); |
| 226 |
| 227 ScopedMessagePipeHandle parent_mp = |
| 228 CreateParentMessagePipe(pipe_token, child_token); |
| 229 |
| 230 ChildProcessLaunchFailed(child_token); |
| 231 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(parent_mp.get().value(), |
| 232 MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 233 MOJO_DEADLINE_INDEFINITE, |
| 234 nullptr)); |
| 235 } |
| 236 |
| 184 // The sequence of messages sent is: | 237 // The sequence of messages sent is: |
| 185 // server_mp client_mp mp0 mp1 mp2 mp3 | 238 // server_mp client_mp mp0 mp1 mp2 mp3 |
| 186 // 1. "hello" | 239 // 1. "hello" |
| 187 // 2. "world!" | 240 // 2. "world!" |
| 188 // 3. "FOO" | 241 // 3. "FOO" |
| 189 // 4. "Bar"+mp1 | 242 // 4. "Bar"+mp1 |
| 190 // 5. (close) | 243 // 5. (close) |
| 191 // 6. (close) | 244 // 6. (close) |
| 192 // 7. "baz" | 245 // 7. "baz" |
| 193 // 8. (closed) | 246 // 8. (closed) |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 553 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 501 | 554 |
| 502 // TODO(vtl): Test immediate write & close. | 555 // TODO(vtl): Test immediate write & close. |
| 503 // TODO(vtl): Test broken-connection cases. | 556 // TODO(vtl): Test broken-connection cases. |
| 504 | 557 |
| 505 #endif // !defined(OS_IOS) | 558 #endif // !defined(OS_IOS) |
| 506 | 559 |
| 507 } // namespace | 560 } // namespace |
| 508 } // namespace edk | 561 } // namespace edk |
| 509 } // namespace mojo | 562 } // namespace mojo |
| OLD | NEW |