| 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 "ipc/ipc_channel_mojo.h" | 5 #include "ipc/ipc_channel_mojo.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "build/build_config.h" | 31 #include "build/build_config.h" |
| 32 #include "ipc/ipc_message.h" | 32 #include "ipc/ipc_message.h" |
| 33 #include "ipc/ipc_mojo_handle_attachment.h" | 33 #include "ipc/ipc_mojo_handle_attachment.h" |
| 34 #include "ipc/ipc_mojo_message_helper.h" | 34 #include "ipc/ipc_mojo_message_helper.h" |
| 35 #include "ipc/ipc_mojo_param_traits.h" | 35 #include "ipc/ipc_mojo_param_traits.h" |
| 36 #include "ipc/ipc_sync_channel.h" | 36 #include "ipc/ipc_sync_channel.h" |
| 37 #include "ipc/ipc_sync_message.h" | 37 #include "ipc/ipc_sync_message.h" |
| 38 #include "ipc/ipc_test.mojom.h" | 38 #include "ipc/ipc_test.mojom.h" |
| 39 #include "ipc/ipc_test_base.h" | 39 #include "ipc/ipc_test_base.h" |
| 40 #include "ipc/ipc_test_channel_listener.h" | 40 #include "ipc/ipc_test_channel_listener.h" |
| 41 #include "mojo/public/cpp/system/wait.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 43 |
| 43 #if defined(OS_POSIX) | 44 #if defined(OS_POSIX) |
| 44 #include "base/file_descriptor_posix.h" | 45 #include "base/file_descriptor_posix.h" |
| 45 #include "ipc/ipc_platform_file_attachment_posix.h" | 46 #include "ipc/ipc_platform_file_attachment_posix.h" |
| 46 #endif | 47 #endif |
| 47 | 48 |
| 48 namespace { | 49 namespace { |
| 49 | 50 |
| 50 void SendString(IPC::Sender* sender, const std::string& str) { | 51 void SendString(IPC::Sender* sender, const std::string& str) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 241 |
| 241 static void ReadReceivedPipe(const IPC::Message& message, | 242 static void ReadReceivedPipe(const IPC::Message& message, |
| 242 base::PickleIterator* iter) { | 243 base::PickleIterator* iter) { |
| 243 mojo::ScopedMessagePipeHandle pipe; | 244 mojo::ScopedMessagePipeHandle pipe; |
| 244 EXPECT_TRUE( | 245 EXPECT_TRUE( |
| 245 IPC::MojoMessageHelper::ReadMessagePipeFrom(&message, iter, &pipe)); | 246 IPC::MojoMessageHelper::ReadMessagePipeFrom(&message, iter, &pipe)); |
| 246 std::string content(GetSendingFileContent().size(), ' '); | 247 std::string content(GetSendingFileContent().size(), ' '); |
| 247 | 248 |
| 248 uint32_t num_bytes = static_cast<uint32_t>(content.size()); | 249 uint32_t num_bytes = static_cast<uint32_t>(content.size()); |
| 249 ASSERT_EQ(MOJO_RESULT_OK, | 250 ASSERT_EQ(MOJO_RESULT_OK, |
| 250 mojo::Wait(pipe.get(), MOJO_HANDLE_SIGNAL_READABLE, | 251 mojo::Wait(pipe.get(), MOJO_HANDLE_SIGNAL_READABLE)); |
| 251 MOJO_DEADLINE_INDEFINITE, nullptr)); | |
| 252 EXPECT_EQ(MOJO_RESULT_OK, | 252 EXPECT_EQ(MOJO_RESULT_OK, |
| 253 mojo::ReadMessageRaw(pipe.get(), &content[0], &num_bytes, nullptr, | 253 mojo::ReadMessageRaw(pipe.get(), &content[0], &num_bytes, nullptr, |
| 254 nullptr, 0)); | 254 nullptr, 0)); |
| 255 EXPECT_EQ(content, GetSendingFileContent()); | 255 EXPECT_EQ(content, GetSendingFileContent()); |
| 256 } | 256 } |
| 257 | 257 |
| 258 #if defined(OS_POSIX) | 258 #if defined(OS_POSIX) |
| 259 static base::FilePath GetSendingFilePath(const base::FilePath& dir_path) { | 259 static base::FilePath GetSendingFilePath(const base::FilePath& dir_path) { |
| 260 return dir_path.Append("ListenerThatExpectsFile.txt"); | 260 return dir_path.Append("ListenerThatExpectsFile.txt"); |
| 261 } | 261 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 listener.set_sender(channel()); | 349 listener.set_sender(channel()); |
| 350 | 350 |
| 351 base::RunLoop().Run(); | 351 base::RunLoop().Run(); |
| 352 | 352 |
| 353 Close(); | 353 Close(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void ReadOK(mojo::MessagePipeHandle pipe) { | 356 void ReadOK(mojo::MessagePipeHandle pipe) { |
| 357 std::string should_be_ok("xx"); | 357 std::string should_be_ok("xx"); |
| 358 uint32_t num_bytes = static_cast<uint32_t>(should_be_ok.size()); | 358 uint32_t num_bytes = static_cast<uint32_t>(should_be_ok.size()); |
| 359 CHECK_EQ(MOJO_RESULT_OK, mojo::Wait(pipe, MOJO_HANDLE_SIGNAL_READABLE, | 359 CHECK_EQ(MOJO_RESULT_OK, mojo::Wait(pipe, MOJO_HANDLE_SIGNAL_READABLE)); |
| 360 MOJO_DEADLINE_INDEFINITE, nullptr)); | |
| 361 CHECK_EQ(MOJO_RESULT_OK, | 360 CHECK_EQ(MOJO_RESULT_OK, |
| 362 mojo::ReadMessageRaw(pipe, &should_be_ok[0], &num_bytes, nullptr, | 361 mojo::ReadMessageRaw(pipe, &should_be_ok[0], &num_bytes, nullptr, |
| 363 nullptr, 0)); | 362 nullptr, 0)); |
| 364 EXPECT_EQ(should_be_ok, std::string("OK")); | 363 EXPECT_EQ(should_be_ok, std::string("OK")); |
| 365 } | 364 } |
| 366 | 365 |
| 367 void WriteOK(mojo::MessagePipeHandle pipe) { | 366 void WriteOK(mojo::MessagePipeHandle pipe) { |
| 368 std::string ok("OK"); | 367 std::string ok("OK"); |
| 369 CHECK_EQ(MOJO_RESULT_OK, | 368 CHECK_EQ(MOJO_RESULT_OK, |
| 370 mojo::WriteMessageRaw(pipe, &ok[0], static_cast<uint32_t>(ok.size()), | 369 mojo::WriteMessageRaw(pipe, &ok[0], static_cast<uint32_t>(ok.size()), |
| (...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 Connect(&listener); | 1463 Connect(&listener); |
| 1465 | 1464 |
| 1466 base::RunLoop().Run(); | 1465 base::RunLoop().Run(); |
| 1467 | 1466 |
| 1468 Close(); | 1467 Close(); |
| 1469 } | 1468 } |
| 1470 | 1469 |
| 1471 #endif // OS_LINUX | 1470 #endif // OS_LINUX |
| 1472 | 1471 |
| 1473 } // namespace | 1472 } // namespace |
| OLD | NEW |