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 <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 ASSERT_TRUE(channel.Connect()); | 237 ASSERT_TRUE(channel.Connect()); |
238 ASSERT_TRUE(channel.AcceptsConnections()); | 238 ASSERT_TRUE(channel.AcceptsConnections()); |
239 ASSERT_FALSE(channel.HasAcceptedConnection()); | 239 ASSERT_FALSE(channel.HasAcceptedConnection()); |
240 | 240 |
241 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", | 241 base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc", |
242 false); | 242 false); |
243 ASSERT_TRUE(handle); | 243 ASSERT_TRUE(handle); |
244 SpinRunLoop(TestTimeouts::action_max_timeout()); | 244 SpinRunLoop(TestTimeouts::action_max_timeout()); |
245 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 245 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
246 ASSERT_TRUE(channel.HasAcceptedConnection()); | 246 ASSERT_TRUE(channel.HasAcceptedConnection()); |
247 IPC::Message* message = new IPC::Message(0, // routing_id | 247 IPC::Message* message = new IPC::Message(0, /* routing_id */ |
248 kQuitMessage, // message type | 248 kQuitMessage /* message type */); |
249 IPC::Message::PRIORITY_NORMAL); | |
250 channel.Send(message); | 249 channel.Send(message); |
251 SpinRunLoop(TestTimeouts::action_timeout()); | 250 SpinRunLoop(TestTimeouts::action_timeout()); |
252 int exit_code = 0; | 251 int exit_code = 0; |
253 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); | 252 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); |
254 EXPECT_EQ(0, exit_code); | 253 EXPECT_EQ(0, exit_code); |
255 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 254 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
256 ASSERT_FALSE(channel.HasAcceptedConnection()); | 255 ASSERT_FALSE(channel.HasAcceptedConnection()); |
257 } | 256 } |
258 | 257 |
259 TEST_F(IPCChannelPosixTest, ResetState) { | 258 TEST_F(IPCChannelPosixTest, ResetState) { |
(...skipping 16 matching lines...) Expand all Loading... |
276 ASSERT_TRUE(channel.HasAcceptedConnection()); | 275 ASSERT_TRUE(channel.HasAcceptedConnection()); |
277 channel.ResetToAcceptingConnectionState(); | 276 channel.ResetToAcceptingConnectionState(); |
278 ASSERT_FALSE(channel.HasAcceptedConnection()); | 277 ASSERT_FALSE(channel.HasAcceptedConnection()); |
279 | 278 |
280 base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixTestConnectionProc", | 279 base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixTestConnectionProc", |
281 false); | 280 false); |
282 ASSERT_TRUE(handle2); | 281 ASSERT_TRUE(handle2); |
283 SpinRunLoop(TestTimeouts::action_max_timeout()); | 282 SpinRunLoop(TestTimeouts::action_max_timeout()); |
284 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); | 283 ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); |
285 ASSERT_TRUE(channel.HasAcceptedConnection()); | 284 ASSERT_TRUE(channel.HasAcceptedConnection()); |
286 IPC::Message* message = new IPC::Message(0, // routing_id | 285 IPC::Message* message = new IPC::Message(0, /* routing_id */ |
287 kQuitMessage, // message type | 286 kQuitMessage /* message type */); |
288 IPC::Message::PRIORITY_NORMAL); | |
289 channel.Send(message); | 287 channel.Send(message); |
290 SpinRunLoop(TestTimeouts::action_timeout()); | 288 SpinRunLoop(TestTimeouts::action_timeout()); |
291 EXPECT_TRUE(base::KillProcess(handle, 0, false)); | 289 EXPECT_TRUE(base::KillProcess(handle, 0, false)); |
292 int exit_code = 0; | 290 int exit_code = 0; |
293 EXPECT_TRUE(base::WaitForExitCode(handle2, &exit_code)); | 291 EXPECT_TRUE(base::WaitForExitCode(handle2, &exit_code)); |
294 EXPECT_EQ(0, exit_code); | 292 EXPECT_EQ(0, exit_code); |
295 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 293 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
296 ASSERT_FALSE(channel.HasAcceptedConnection()); | 294 ASSERT_FALSE(channel.HasAcceptedConnection()); |
297 } | 295 } |
298 | 296 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 ASSERT_TRUE(channel.HasAcceptedConnection()); | 333 ASSERT_TRUE(channel.HasAcceptedConnection()); |
336 base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixFailConnectionProc", | 334 base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixFailConnectionProc", |
337 false); | 335 false); |
338 ASSERT_TRUE(handle2); | 336 ASSERT_TRUE(handle2); |
339 SpinRunLoop(TestTimeouts::action_max_timeout()); | 337 SpinRunLoop(TestTimeouts::action_max_timeout()); |
340 int exit_code = 0; | 338 int exit_code = 0; |
341 EXPECT_TRUE(base::WaitForExitCode(handle2, &exit_code)); | 339 EXPECT_TRUE(base::WaitForExitCode(handle2, &exit_code)); |
342 EXPECT_EQ(exit_code, 0); | 340 EXPECT_EQ(exit_code, 0); |
343 ASSERT_EQ(IPCChannelPosixTestListener::DENIED, listener.status()); | 341 ASSERT_EQ(IPCChannelPosixTestListener::DENIED, listener.status()); |
344 ASSERT_TRUE(channel.HasAcceptedConnection()); | 342 ASSERT_TRUE(channel.HasAcceptedConnection()); |
345 IPC::Message* message = new IPC::Message(0, // routing_id | 343 IPC::Message* message = new IPC::Message(0, /* routing_id */ |
346 kQuitMessage, // message type | 344 kQuitMessage /* message type */); |
347 IPC::Message::PRIORITY_NORMAL); | |
348 channel.Send(message); | 345 channel.Send(message); |
349 SpinRunLoop(TestTimeouts::action_timeout()); | 346 SpinRunLoop(TestTimeouts::action_timeout()); |
350 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); | 347 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); |
351 EXPECT_EQ(exit_code, 0); | 348 EXPECT_EQ(exit_code, 0); |
352 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 349 ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
353 ASSERT_FALSE(channel.HasAcceptedConnection()); | 350 ASSERT_FALSE(channel.HasAcceptedConnection()); |
354 } | 351 } |
355 | 352 |
356 TEST_F(IPCChannelPosixTest, DoubleServer) { | 353 TEST_F(IPCChannelPosixTest, DoubleServer) { |
357 // Test setting up two servers with the same name. | 354 // Test setting up two servers with the same name. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 if (connected) { | 414 if (connected) { |
418 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); | 415 IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); |
419 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); | 416 EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); |
420 } else { | 417 } else { |
421 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); | 418 EXPECT_EQ(IPCChannelPosixTestListener::DISCONNECTED, listener.status()); |
422 } | 419 } |
423 return 0; | 420 return 0; |
424 } | 421 } |
425 | 422 |
426 } // namespace | 423 } // namespace |
OLD | NEW |