| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // These tests are POSIX only. | 5 // These tests are POSIX only. |
| 6 | 6 |
| 7 #include "ipc/ipc_channel_posix.h" | 7 #include "ipc/ipc_channel_posix.h" |
| 8 | 8 |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <stdint.h> |
| 10 #include <sys/socket.h> | 11 #include <sys/socket.h> |
| 11 #include <sys/un.h> | 12 #include <sys/un.h> |
| 12 #include <unistd.h> | 13 #include <unistd.h> |
| 13 | 14 |
| 14 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 17 #include "base/location.h" | 18 #include "base/location.h" |
| 18 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 20 #include "base/posix/eintr_wrapper.h" | 21 #include "base/posix/eintr_wrapper.h" |
| 21 #include "base/process/process.h" | 22 #include "base/process/process.h" |
| 22 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 23 #include "base/test/multiprocess_test.h" | 24 #include "base/test/multiprocess_test.h" |
| 24 #include "base/test/test_timeouts.h" | 25 #include "base/test/test_timeouts.h" |
| 25 #include "ipc/ipc_listener.h" | 26 #include "ipc/ipc_listener.h" |
| 26 #include "ipc/unix_domain_socket_util.h" | 27 #include "ipc/unix_domain_socket_util.h" |
| 27 #include "testing/multiprocess_func_list.h" | 28 #include "testing/multiprocess_func_list.h" |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 static const uint32 kQuitMessage = 47; | 32 static const uint32_t kQuitMessage = 47; |
| 32 | 33 |
| 33 class IPCChannelPosixTestListener : public IPC::Listener { | 34 class IPCChannelPosixTestListener : public IPC::Listener { |
| 34 public: | 35 public: |
| 35 enum STATUS { | 36 enum STATUS { |
| 36 DISCONNECTED, | 37 DISCONNECTED, |
| 37 MESSAGE_RECEIVED, | 38 MESSAGE_RECEIVED, |
| 38 CHANNEL_ERROR, | 39 CHANNEL_ERROR, |
| 39 CONNECTED, | 40 CONNECTED, |
| 40 DENIED, | 41 DENIED, |
| 41 LISTEN_ERROR | 42 LISTEN_ERROR |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 IPCChannelPosixTestListener(bool quit_only_on_message) | 45 IPCChannelPosixTestListener(bool quit_only_on_message) |
| 45 : status_(DISCONNECTED), | 46 : status_(DISCONNECTED), |
| 46 quit_only_on_message_(quit_only_on_message) { | 47 quit_only_on_message_(quit_only_on_message) { |
| 47 } | 48 } |
| 48 | 49 |
| 49 ~IPCChannelPosixTestListener() override {} | 50 ~IPCChannelPosixTestListener() override {} |
| 50 | 51 |
| 51 bool OnMessageReceived(const IPC::Message& message) override { | 52 bool OnMessageReceived(const IPC::Message& message) override { |
| 52 EXPECT_EQ(message.type(), kQuitMessage); | 53 EXPECT_EQ(message.type(), kQuitMessage); |
| 53 status_ = MESSAGE_RECEIVED; | 54 status_ = MESSAGE_RECEIVED; |
| 54 QuitRunLoop(); | 55 QuitRunLoop(); |
| 55 return true; | 56 return true; |
| 56 } | 57 } |
| 57 | 58 |
| 58 void OnChannelConnected(int32 peer_pid) override { | 59 void OnChannelConnected(int32_t peer_pid) override { |
| 59 status_ = CONNECTED; | 60 status_ = CONNECTED; |
| 60 if (!quit_only_on_message_) { | 61 if (!quit_only_on_message_) { |
| 61 QuitRunLoop(); | 62 QuitRunLoop(); |
| 62 } | 63 } |
| 63 } | 64 } |
| 64 | 65 |
| 65 void OnChannelError() override { | 66 void OnChannelError() override { |
| 66 status_ = CHANNEL_ERROR; | 67 status_ = CHANNEL_ERROR; |
| 67 QuitRunLoop(); | 68 QuitRunLoop(); |
| 68 } | 69 } |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 if (connected) { | 495 if (connected) { |
| 495 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 496 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
| 496 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 497 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
| 497 } else { | 498 } else { |
| 498 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 499 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
| 499 } | 500 } |
| 500 return 0; | 501 return 0; |
| 501 } | 502 } |
| 502 | 503 |
| 503 } // namespace | 504 } // namespace |
| OLD | NEW |