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 #include "base/sync_socket.h" | 5 #include "base/sync_socket.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <memory> | 9 #include <memory> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // which causes the message loop to exit. | 102 // which causes the message loop to exit. |
103 void OnMsgClassShutdown() { base::MessageLoop::current()->QuitWhenIdle(); } | 103 void OnMsgClassShutdown() { base::MessageLoop::current()->QuitWhenIdle(); } |
104 | 104 |
105 IPC::Channel* chan_; | 105 IPC::Channel* chan_; |
106 | 106 |
107 DISALLOW_COPY_AND_ASSIGN(SyncSocketServerListener); | 107 DISALLOW_COPY_AND_ASSIGN(SyncSocketServerListener); |
108 }; | 108 }; |
109 | 109 |
110 // Runs the fuzzing server child mode. Returns when the preset number of | 110 // Runs the fuzzing server child mode. Returns when the preset number of |
111 // messages have been received. | 111 // messages have been received. |
112 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(SyncSocketServerClient) { | 112 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SyncSocketServerClient) { |
| 113 base::MessageLoopForIO main_message_loop; |
113 SyncSocketServerListener listener; | 114 SyncSocketServerListener listener; |
114 Connect(&listener); | 115 std::unique_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( |
115 listener.Init(channel()); | 116 IPCTestBase::GetChannelName("SyncSocketServerClient"), &listener, |
| 117 main_message_loop.task_runner())); |
| 118 EXPECT_TRUE(channel->Connect()); |
| 119 listener.Init(channel.get()); |
116 base::RunLoop().Run(); | 120 base::RunLoop().Run(); |
117 Close(); | 121 return 0; |
118 } | 122 } |
119 | 123 |
120 // The SyncSocket client listener only processes one sort of message, | 124 // The SyncSocket client listener only processes one sort of message, |
121 // a response from the server. | 125 // a response from the server. |
122 class SyncSocketClientListener : public IPC::Listener { | 126 class SyncSocketClientListener : public IPC::Listener { |
123 public: | 127 public: |
124 SyncSocketClientListener() { | 128 SyncSocketClientListener() { |
125 } | 129 } |
126 | 130 |
127 void Init(base::SyncSocket* socket, IPC::Channel* chan) { | 131 void Init(base::SyncSocket* socket, IPC::Channel* chan) { |
(...skipping 27 matching lines...) Expand all Loading... |
155 EXPECT_TRUE(chan_->Send(msg)); | 159 EXPECT_TRUE(chan_->Send(msg)); |
156 base::MessageLoop::current()->QuitWhenIdle(); | 160 base::MessageLoop::current()->QuitWhenIdle(); |
157 } | 161 } |
158 | 162 |
159 base::SyncSocket* socket_; | 163 base::SyncSocket* socket_; |
160 IPC::Channel* chan_; | 164 IPC::Channel* chan_; |
161 | 165 |
162 DISALLOW_COPY_AND_ASSIGN(SyncSocketClientListener); | 166 DISALLOW_COPY_AND_ASSIGN(SyncSocketClientListener); |
163 }; | 167 }; |
164 | 168 |
165 using SyncSocketTest = IPCChannelMojoTestBase; | 169 class SyncSocketTest : public IPCTestBase { |
| 170 }; |
166 | 171 |
167 TEST_F(SyncSocketTest, SanityTest) { | 172 TEST_F(SyncSocketTest, SanityTest) { |
168 Init("SyncSocketServerClient"); | 173 Init("SyncSocketServerClient"); |
169 | 174 |
170 SyncSocketClientListener listener; | 175 SyncSocketClientListener listener; |
171 CreateChannel(&listener); | 176 CreateChannel(&listener); |
| 177 ASSERT_TRUE(StartClient()); |
172 // Create a pair of SyncSockets. | 178 // Create a pair of SyncSockets. |
173 base::SyncSocket pair[2]; | 179 base::SyncSocket pair[2]; |
174 base::SyncSocket::CreatePair(&pair[0], &pair[1]); | 180 base::SyncSocket::CreatePair(&pair[0], &pair[1]); |
175 // Immediately after creation there should be no pending bytes. | 181 // Immediately after creation there should be no pending bytes. |
176 EXPECT_EQ(0U, pair[0].Peek()); | 182 EXPECT_EQ(0U, pair[0].Peek()); |
177 EXPECT_EQ(0U, pair[1].Peek()); | 183 EXPECT_EQ(0U, pair[1].Peek()); |
178 base::SyncSocket::Handle target_handle; | 184 base::SyncSocket::Handle target_handle; |
179 // Connect the channel and listener. | 185 // Connect the channel and listener. |
180 ASSERT_TRUE(ConnectChannel()); | 186 ASSERT_TRUE(ConnectChannel()); |
181 listener.Init(&pair[0], channel()); | 187 listener.Init(&pair[0], channel()); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 304 |
299 // Read from another socket to free some space for a new write. | 305 // Read from another socket to free some space for a new write. |
300 char hello[kHelloStringLength] = {0}; | 306 char hello[kHelloStringLength] = {0}; |
301 pair[1].Receive(&hello[0], sizeof(hello)); | 307 pair[1].Receive(&hello[0], sizeof(hello)); |
302 | 308 |
303 // Should be able to write more data to the buffer now. | 309 // Should be able to write more data to the buffer now. |
304 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); | 310 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); |
305 } | 311 } |
306 | 312 |
307 } // namespace | 313 } // namespace |
OLD | NEW |