| 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 // Unit test for SyncChannel. | 5 // Unit test for SyncChannel. |
| 6 | 6 |
| 7 #include "ipc/ipc_sync_channel.h" | 7 #include "ipc/ipc_sync_channel.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 this, ipc_thread().message_loop_proxy(), shutdown_event()); | 337 this, ipc_thread().message_loop_proxy(), shutdown_event()); |
| 338 channel->Init(channel_name(), mode(), create_pipe_now_); | 338 channel->Init(channel_name(), mode(), create_pipe_now_); |
| 339 return channel; | 339 return channel; |
| 340 } | 340 } |
| 341 | 341 |
| 342 bool create_pipe_now_; | 342 bool create_pipe_now_; |
| 343 }; | 343 }; |
| 344 | 344 |
| 345 class TwoStepClient : public Worker { | 345 class TwoStepClient : public Worker { |
| 346 public: | 346 public: |
| 347 TwoStepClient(bool create_pipe_now) | 347 explicit TwoStepClient(bool create_pipe_now) |
| 348 : Worker(Channel::MODE_CLIENT, "simple_client"), | 348 : Worker(Channel::MODE_CLIENT, "simple_client"), |
| 349 create_pipe_now_(create_pipe_now) { } | 349 create_pipe_now_(create_pipe_now) { } |
| 350 | 350 |
| 351 void OnAnswer(int* answer) { | 351 void OnAnswer(int* answer) { |
| 352 *answer = 42; | 352 *answer = 42; |
| 353 Done(); | 353 Done(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 virtual SyncChannel* CreateChannel() { | 356 virtual SyncChannel* CreateChannel() { |
| 357 SyncChannel* channel = new SyncChannel( | 357 SyncChannel* channel = new SyncChannel( |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 sent_ping_event_->Signal(); | 1240 sent_ping_event_->Signal(); |
| 1241 } | 1241 } |
| 1242 | 1242 |
| 1243 void OnNoArgs() { } | 1243 void OnNoArgs() { } |
| 1244 WaitableEvent* sent_ping_event_; | 1244 WaitableEvent* sent_ping_event_; |
| 1245 WaitableEvent* wait_event_; | 1245 WaitableEvent* wait_event_; |
| 1246 }; | 1246 }; |
| 1247 | 1247 |
| 1248 class NonRestrictedDispatchServer : public Worker { | 1248 class NonRestrictedDispatchServer : public Worker { |
| 1249 public: | 1249 public: |
| 1250 NonRestrictedDispatchServer(WaitableEvent* signal_event) | 1250 explicit NonRestrictedDispatchServer(WaitableEvent* signal_event) |
| 1251 : Worker("non_restricted_channel", Channel::MODE_SERVER), | 1251 : Worker("non_restricted_channel", Channel::MODE_SERVER), |
| 1252 signal_event_(signal_event) {} | 1252 signal_event_(signal_event) {} |
| 1253 | 1253 |
| 1254 base::Thread* ListenerThread() { return Worker::ListenerThread(); } | 1254 base::Thread* ListenerThread() { return Worker::ListenerThread(); } |
| 1255 | 1255 |
| 1256 void OnDoPingTTL(int ping) { | 1256 void OnDoPingTTL(int ping) { |
| 1257 int value = 0; | 1257 int value = 0; |
| 1258 Send(new SyncChannelTestMsg_PingTTL(ping, &value)); | 1258 Send(new SyncChannelTestMsg_PingTTL(ping, &value)); |
| 1259 signal_event_->Signal(); | 1259 signal_event_->Signal(); |
| 1260 } | 1260 } |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1763 // behaves as a reply, not a regular message. | 1763 // behaves as a reply, not a regular message. |
| 1764 // We have 3 workers. Server1 will send a message to Server2 (which will block), | 1764 // We have 3 workers. Server1 will send a message to Server2 (which will block), |
| 1765 // during which it will dispatch a message comming from Client, at which point | 1765 // during which it will dispatch a message comming from Client, at which point |
| 1766 // it will send another message to Server2. While sending that second message it | 1766 // it will send another message to Server2. While sending that second message it |
| 1767 // will receive a reply from Server1 with the unblock flag. | 1767 // will receive a reply from Server1 with the unblock flag. |
| 1768 | 1768 |
| 1769 namespace { | 1769 namespace { |
| 1770 | 1770 |
| 1771 class ReentrantReplyServer1 : public Worker { | 1771 class ReentrantReplyServer1 : public Worker { |
| 1772 public: | 1772 public: |
| 1773 ReentrantReplyServer1(WaitableEvent* server_ready) | 1773 explicit ReentrantReplyServer1(WaitableEvent* server_ready) |
| 1774 : Worker("reentrant_reply1", Channel::MODE_SERVER), | 1774 : Worker("reentrant_reply1", Channel::MODE_SERVER), |
| 1775 server_ready_(server_ready) { } | 1775 server_ready_(server_ready) { } |
| 1776 | 1776 |
| 1777 void Run() { | 1777 void Run() { |
| 1778 server2_channel_.reset(new SyncChannel( | 1778 server2_channel_.reset(new SyncChannel( |
| 1779 "reentrant_reply2", Channel::MODE_CLIENT, this, | 1779 "reentrant_reply2", Channel::MODE_CLIENT, this, |
| 1780 ipc_thread().message_loop_proxy(), true, shutdown_event())); | 1780 ipc_thread().message_loop_proxy(), true, shutdown_event())); |
| 1781 server_ready_->Signal(); | 1781 server_ready_->Signal(); |
| 1782 Message* msg = new SyncChannelTestMsg_Reentrant1(); | 1782 Message* msg = new SyncChannelTestMsg_Reentrant1(); |
| 1783 server2_channel_->Send(msg); | 1783 server2_channel_->Send(msg); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 reply->set_unblock(true); | 1837 reply->set_unblock(true); |
| 1838 Send(reply); | 1838 Send(reply); |
| 1839 Done(); | 1839 Done(); |
| 1840 } | 1840 } |
| 1841 | 1841 |
| 1842 Message* reply_; | 1842 Message* reply_; |
| 1843 }; | 1843 }; |
| 1844 | 1844 |
| 1845 class ReentrantReplyClient : public Worker { | 1845 class ReentrantReplyClient : public Worker { |
| 1846 public: | 1846 public: |
| 1847 ReentrantReplyClient(WaitableEvent* server_ready) | 1847 explicit ReentrantReplyClient(WaitableEvent* server_ready) |
| 1848 : Worker("reentrant_reply1", Channel::MODE_CLIENT), | 1848 : Worker("reentrant_reply1", Channel::MODE_CLIENT), |
| 1849 server_ready_(server_ready) { } | 1849 server_ready_(server_ready) { } |
| 1850 | 1850 |
| 1851 void Run() { | 1851 void Run() { |
| 1852 server_ready_->Wait(); | 1852 server_ready_->Wait(); |
| 1853 Send(new SyncChannelTestMsg_Reentrant2()); | 1853 Send(new SyncChannelTestMsg_Reentrant2()); |
| 1854 Done(); | 1854 Done(); |
| 1855 } | 1855 } |
| 1856 | 1856 |
| 1857 private: | 1857 private: |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1956 | 1956 |
| 1957 } // namespace | 1957 } // namespace |
| 1958 | 1958 |
| 1959 // Windows needs to send an out-of-band secret to verify the client end of the | 1959 // Windows needs to send an out-of-band secret to verify the client end of the |
| 1960 // channel. Test that we still connect correctly in that case. | 1960 // channel. Test that we still connect correctly in that case. |
| 1961 TEST_F(IPCSyncChannelTest, Verified) { | 1961 TEST_F(IPCSyncChannelTest, Verified) { |
| 1962 Verified(); | 1962 Verified(); |
| 1963 } | 1963 } |
| 1964 | 1964 |
| 1965 } // namespace IPC | 1965 } // namespace IPC |
| OLD | NEW |