Chromium Code Reviews| Index: ipc/ipc_sync_channel_unittest.cc |
| diff --git a/ipc/ipc_sync_channel_unittest.cc b/ipc/ipc_sync_channel_unittest.cc |
| index bdd83eb1f24f20f8a23234c92bb578ea98aa26da..b9ef7647b8625ce26f8bbf6dbda38b92e11fa760 100644 |
| --- a/ipc/ipc_sync_channel_unittest.cc |
| +++ b/ipc/ipc_sync_channel_unittest.cc |
| @@ -119,6 +119,7 @@ class Worker : public Channel::Listener, public Message::Sender { |
| DCHECK_EQ(answer, (succeed ? 10 : 0)); |
| return result; |
| } |
| + const std::string& channel_name() { return channel_name_; } |
| Channel::Mode mode() { return mode_; } |
| WaitableEvent* done_event() { return done_.get(); } |
| WaitableEvent* shutdown_event() { return &shutdown_event_; } |
| @@ -155,6 +156,12 @@ class Worker : public Channel::Listener, public Message::Sender { |
| NOTREACHED(); |
| } |
| + virtual SyncChannel* CreateChannel() { |
| + return new SyncChannel( |
| + channel_name_, mode_, this, ipc_thread_.message_loop_proxy(), true, |
| + &shutdown_event_); |
| + } |
| + |
| base::Thread* ListenerThread() { |
| return overrided_thread_ ? overrided_thread_ : &listener_thread_; |
| } |
| @@ -166,9 +173,7 @@ class Worker : public Channel::Listener, public Message::Sender { |
| void OnStart() { |
| // Link ipc_thread_, listener_thread_ and channel_ altogether. |
| StartThread(&ipc_thread_, MessageLoop::TYPE_IO); |
| - channel_.reset(new SyncChannel( |
| - channel_name_, mode_, this, ipc_thread_.message_loop_proxy(), true, |
| - &shutdown_event_)); |
| + channel_.reset(CreateChannel()); |
| channel_created_->Signal(); |
| Run(); |
| } |
| @@ -308,6 +313,70 @@ TEST_F(IPCSyncChannelTest, Simple) { |
| namespace { |
|
dmac
2011/11/04 22:30:44
could you add a more detailed comment for this set
kkania
2011/11/07 20:25:16
Done.
|
| +class TwoStepServer : public Worker { |
| + public: |
| + explicit TwoStepServer(bool create_pipe_now) |
| + : Worker(Channel::MODE_SERVER, "simpler_server"), |
| + create_pipe_now_(create_pipe_now) { } |
| + |
| + void Run() { |
| + SendAnswerToLife(false, base::kNoTimeout, true); |
| + Done(); |
| + } |
| + |
| + virtual SyncChannel* CreateChannel() { |
| + SyncChannel* channel = new SyncChannel( |
| + this, ipc_thread().message_loop_proxy(), shutdown_event()); |
| + channel->Init(channel_name(), mode(), create_pipe_now_); |
| + return channel; |
| + } |
| + |
| + bool create_pipe_now_; |
| +}; |
| + |
| +class TwoStepClient : public Worker { |
| + public: |
| + TwoStepClient(bool create_pipe_now) |
| + : Worker(Channel::MODE_CLIENT, "simple_client"), |
| + create_pipe_now_(create_pipe_now) { } |
| + |
| + void OnAnswer(int* answer) { |
| + *answer = 42; |
| + Done(); |
| + } |
| + |
| + virtual SyncChannel* CreateChannel() { |
| + SyncChannel* channel = new SyncChannel( |
| + this, ipc_thread().message_loop_proxy(), shutdown_event()); |
| + channel->Init(channel_name(), mode(), create_pipe_now_); |
| + return channel; |
| + } |
| + |
| + bool create_pipe_now_; |
| +}; |
| + |
| +void TwoStep(bool create_server_pipe_now, bool create_client_pipe_now) { |
| + std::vector<Worker*> workers; |
| + workers.push_back(new TwoStepServer(create_server_pipe_now)); |
| + workers.push_back(new TwoStepClient(create_client_pipe_now)); |
| + RunTest(workers); |
| +} |
| + |
| +} // namespace |
| + |
| +// Tests basic two-step initialization, where you call constructor then Init. |
| +TEST_F(IPCSyncChannelTest, TwoStepInitialization) { |
| + TwoStep(false, false); |
| + TwoStep(false, true); |
| + TwoStep(true, false); |
| + TwoStep(true, true); |
| +} |
| + |
| + |
| +//----------------------------------------------------------------------------- |
| + |
| +namespace { |
| + |
| class DelayClient : public Worker { |
| public: |
| DelayClient() : Worker(Channel::MODE_CLIENT, "delay_client") { } |