| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
| 22 #include "base/debug/debug_on_start_win.h" | 22 #include "base/debug/debug_on_start_win.h" |
| 23 #include "base/perftimer.h" | 23 #include "base/perftimer.h" |
| 24 #include "base/test/perf_test_suite.h" | 24 #include "base/test/perf_test_suite.h" |
| 25 #include "base/test/test_suite.h" | 25 #include "base/test/test_suite.h" |
| 26 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
| 27 #include "ipc/ipc_descriptors.h" | 27 #include "ipc/ipc_descriptors.h" |
| 28 #include "ipc/ipc_channel.h" | 28 #include "ipc/ipc_channel.h" |
| 29 #include "ipc/ipc_channel_proxy.h" | 29 #include "ipc/ipc_channel_proxy.h" |
| 30 #include "ipc/ipc_message_utils.h" | 30 #include "ipc/ipc_message_utils.h" |
| 31 #include "ipc/ipc_sender.h" |
| 31 #include "ipc/ipc_switches.h" | 32 #include "ipc/ipc_switches.h" |
| 32 #include "testing/multiprocess_func_list.h" | 33 #include "testing/multiprocess_func_list.h" |
| 33 | 34 |
| 34 // Define to enable IPC performance testing instead of the regular unit tests | 35 // Define to enable IPC performance testing instead of the regular unit tests |
| 35 // #define PERFORMANCE_TEST | 36 // #define PERFORMANCE_TEST |
| 36 | 37 |
| 37 const char kTestClientChannel[] = "T1"; | 38 const char kTestClientChannel[] = "T1"; |
| 38 const char kReflectorChannel[] = "T2"; | 39 const char kReflectorChannel[] = "T2"; |
| 39 const char kFuzzerChannel[] = "F3"; | 40 const char kFuzzerChannel[] = "F3"; |
| 40 const char kSyncSocketChannel[] = "S4"; | 41 const char kSyncSocketChannel[] = "S4"; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 155 |
| 155 EXPECT_TRUE(m.ReadWString(&iter, &vw)); | 156 EXPECT_TRUE(m.ReadWString(&iter, &vw)); |
| 156 EXPECT_EQ(v3, vw); | 157 EXPECT_EQ(v3, vw); |
| 157 | 158 |
| 158 // should fail | 159 // should fail |
| 159 EXPECT_FALSE(m.ReadInt(&iter, &vi)); | 160 EXPECT_FALSE(m.ReadInt(&iter, &vi)); |
| 160 EXPECT_FALSE(m.ReadString(&iter, &vs)); | 161 EXPECT_FALSE(m.ReadString(&iter, &vs)); |
| 161 EXPECT_FALSE(m.ReadWString(&iter, &vw)); | 162 EXPECT_FALSE(m.ReadWString(&iter, &vw)); |
| 162 } | 163 } |
| 163 | 164 |
| 164 static void Send(IPC::Message::Sender* sender, const char* text) { | 165 static void Send(IPC::Sender* sender, const char* text) { |
| 165 static int message_index = 0; | 166 static int message_index = 0; |
| 166 | 167 |
| 167 IPC::Message* message = new IPC::Message(0, | 168 IPC::Message* message = new IPC::Message(0, |
| 168 2, | 169 2, |
| 169 IPC::Message::PRIORITY_NORMAL); | 170 IPC::Message::PRIORITY_NORMAL); |
| 170 message->WriteInt(message_index++); | 171 message->WriteInt(message_index++); |
| 171 message->WriteString(std::string(text)); | 172 message->WriteString(std::string(text)); |
| 172 | 173 |
| 173 // Make sure we can handle large messages. | 174 // Make sure we can handle large messages. |
| 174 char junk[kLongMessageStringNumBytes]; | 175 char junk[kLongMessageStringNumBytes]; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 198 } | 199 } |
| 199 return true; | 200 return true; |
| 200 } | 201 } |
| 201 | 202 |
| 202 virtual void OnChannelError() { | 203 virtual void OnChannelError() { |
| 203 // There is a race when closing the channel so the last message may be lost. | 204 // There is a race when closing the channel so the last message may be lost. |
| 204 EXPECT_LE(messages_left_, 1); | 205 EXPECT_LE(messages_left_, 1); |
| 205 MessageLoop::current()->Quit(); | 206 MessageLoop::current()->Quit(); |
| 206 } | 207 } |
| 207 | 208 |
| 208 void Init(IPC::Message::Sender* s) { | 209 void Init(IPC::Sender* s) { |
| 209 sender_ = s; | 210 sender_ = s; |
| 210 messages_left_ = 50; | 211 messages_left_ = 50; |
| 211 } | 212 } |
| 212 | 213 |
| 213 private: | 214 private: |
| 214 IPC::Message::Sender* sender_; | 215 IPC::Sender* sender_; |
| 215 int messages_left_; | 216 int messages_left_; |
| 216 }; | 217 }; |
| 217 | 218 |
| 218 TEST_F(IPCChannelTest, ChannelTest) { | 219 TEST_F(IPCChannelTest, ChannelTest) { |
| 219 MyChannelListener channel_listener; | 220 MyChannelListener channel_listener; |
| 220 // Setup IPC channel. | 221 // Setup IPC channel. |
| 221 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER, | 222 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER, |
| 222 &channel_listener); | 223 &channel_listener); |
| 223 ASSERT_TRUE(chan.Connect()); | 224 ASSERT_TRUE(chan.Connect()); |
| 224 | 225 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 SendNextMessage(); | 344 SendNextMessage(); |
| 344 return true; | 345 return true; |
| 345 } | 346 } |
| 346 | 347 |
| 347 virtual void OnChannelError() OVERRIDE { | 348 virtual void OnChannelError() OVERRIDE { |
| 348 // There is a race when closing the channel so the last message may be lost. | 349 // There is a race when closing the channel so the last message may be lost. |
| 349 EXPECT_LE(messages_left_, 1); | 350 EXPECT_LE(messages_left_, 1); |
| 350 MessageLoop::current()->Quit(); | 351 MessageLoop::current()->Quit(); |
| 351 } | 352 } |
| 352 | 353 |
| 353 void Init(IPC::Message::Sender* s) { | 354 void Init(IPC::Sender* s) { |
| 354 sender_ = s; | 355 sender_ = s; |
| 355 messages_left_ = 50; | 356 messages_left_ = 50; |
| 356 } | 357 } |
| 357 | 358 |
| 358 private: | 359 private: |
| 359 void SendNextMessage() { | 360 void SendNextMessage() { |
| 360 if (--messages_left_ == 0) { | 361 if (--messages_left_ == 0) { |
| 361 MessageLoop::current()->Quit(); | 362 MessageLoop::current()->Quit(); |
| 362 } else { | 363 } else { |
| 363 Send(sender_, "Foo"); | 364 Send(sender_, "Foo"); |
| 364 } | 365 } |
| 365 } | 366 } |
| 366 | 367 |
| 367 IPC::Message::Sender* sender_; | 368 IPC::Sender* sender_; |
| 368 int messages_left_; | 369 int messages_left_; |
| 369 }; | 370 }; |
| 370 | 371 |
| 371 #if defined(OS_WIN) | 372 #if defined(OS_WIN) |
| 372 // Acting flakey in Windows. http://crbug.com/129595 | 373 // Acting flakey in Windows. http://crbug.com/129595 |
| 373 #define MAYBE_SendMessageInChannelConnected DISABLED_SendMessageInChannelConnect
ed | 374 #define MAYBE_SendMessageInChannelConnected DISABLED_SendMessageInChannelConnect
ed |
| 374 #else | 375 #else |
| 375 #define MAYBE_SendMessageInChannelConnected SendMessageInChannelConnected | 376 #define MAYBE_SendMessageInChannelConnected SendMessageInChannelConnected |
| 376 #endif | 377 #endif |
| 377 TEST_F(IPCChannelTest, MAYBE_SendMessageInChannelConnected) { | 378 TEST_F(IPCChannelTest, MAYBE_SendMessageInChannelConnected) { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 #endif // PERFORMANCE_TEST | 586 #endif // PERFORMANCE_TEST |
| 586 | 587 |
| 587 int main(int argc, char** argv) { | 588 int main(int argc, char** argv) { |
| 588 #ifdef PERFORMANCE_TEST | 589 #ifdef PERFORMANCE_TEST |
| 589 int retval = base::PerfTestSuite(argc, argv).Run(); | 590 int retval = base::PerfTestSuite(argc, argv).Run(); |
| 590 #else | 591 #else |
| 591 int retval = base::TestSuite(argc, argv).Run(); | 592 int retval = base::TestSuite(argc, argv).Run(); |
| 592 #endif | 593 #endif |
| 593 return retval; | 594 return retval; |
| 594 } | 595 } |
| OLD | NEW |