| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 333   DelayReply(false); | 333   DelayReply(false); | 
| 334   DelayReply(true); | 334   DelayReply(true); | 
| 335 } | 335 } | 
| 336 | 336 | 
| 337 //----------------------------------------------------------------------------- | 337 //----------------------------------------------------------------------------- | 
| 338 | 338 | 
| 339 namespace { | 339 namespace { | 
| 340 | 340 | 
| 341 class NoHangServer : public Worker { | 341 class NoHangServer : public Worker { | 
| 342  public: | 342  public: | 
| 343   explicit NoHangServer(WaitableEvent* got_first_reply, bool pump_during_send) | 343   NoHangServer(WaitableEvent* got_first_reply, bool pump_during_send) | 
| 344       : Worker(Channel::MODE_SERVER, "no_hang_server"), | 344       : Worker(Channel::MODE_SERVER, "no_hang_server"), | 
| 345         got_first_reply_(got_first_reply), | 345         got_first_reply_(got_first_reply), | 
| 346         pump_during_send_(pump_during_send) { } | 346         pump_during_send_(pump_during_send) { } | 
| 347   void Run() { | 347   void Run() { | 
| 348     SendAnswerToLife(pump_during_send_, base::kNoTimeout, true); | 348     SendAnswerToLife(pump_during_send_, base::kNoTimeout, true); | 
| 349     got_first_reply_->Signal(); | 349     got_first_reply_->Signal(); | 
| 350 | 350 | 
| 351     SendAnswerToLife(pump_during_send_, base::kNoTimeout, false); | 351     SendAnswerToLife(pump_during_send_, base::kNoTimeout, false); | 
| 352     Done(); | 352     Done(); | 
| 353   } | 353   } | 
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 468   Unblock(true, false, true); | 468   Unblock(true, false, true); | 
| 469   Unblock(true, true, true); | 469   Unblock(true, true, true); | 
| 470 } | 470 } | 
| 471 | 471 | 
| 472 //----------------------------------------------------------------------------- | 472 //----------------------------------------------------------------------------- | 
| 473 | 473 | 
| 474 namespace { | 474 namespace { | 
| 475 | 475 | 
| 476 class RecursiveServer : public Worker { | 476 class RecursiveServer : public Worker { | 
| 477  public: | 477  public: | 
| 478   explicit RecursiveServer( | 478   RecursiveServer(bool expected_send_result, bool pump_first, bool pump_second) | 
| 479     bool expected_send_result, bool pump_first, bool pump_second) | 479       : Worker(Channel::MODE_SERVER, "recursive_server"), | 
| 480     : Worker(Channel::MODE_SERVER, "recursive_server"), | 480         expected_send_result_(expected_send_result), | 
| 481       expected_send_result_(expected_send_result), | 481         pump_first_(pump_first), pump_second_(pump_second) {} | 
| 482       pump_first_(pump_first), pump_second_(pump_second)  { } |  | 
| 483   void Run() { | 482   void Run() { | 
| 484     SendDouble(pump_first_, expected_send_result_); | 483     SendDouble(pump_first_, expected_send_result_); | 
| 485     Done(); | 484     Done(); | 
| 486   } | 485   } | 
| 487 | 486 | 
| 488   void OnDouble(int in, int* out) { | 487   void OnDouble(int in, int* out) { | 
| 489     *out = in * 2; | 488     *out = in * 2; | 
| 490     SendAnswerToLife(pump_second_, base::kNoTimeout, expected_send_result_); | 489     SendAnswerToLife(pump_second_, base::kNoTimeout, expected_send_result_); | 
| 491   } | 490   } | 
| 492 | 491 | 
| 493   bool expected_send_result_, pump_first_, pump_second_; | 492   bool expected_send_result_, pump_first_, pump_second_; | 
| 494 }; | 493 }; | 
| 495 | 494 | 
| 496 class RecursiveClient : public Worker { | 495 class RecursiveClient : public Worker { | 
| 497  public: | 496  public: | 
| 498   explicit RecursiveClient(bool pump_during_send, bool close_channel) | 497   RecursiveClient(bool pump_during_send, bool close_channel) | 
| 499     : Worker(Channel::MODE_CLIENT, "recursive_client"), | 498       : Worker(Channel::MODE_CLIENT, "recursive_client"), | 
| 500       pump_during_send_(pump_during_send), close_channel_(close_channel) { } | 499         pump_during_send_(pump_during_send), close_channel_(close_channel) {} | 
| 501 | 500 | 
| 502   void OnDoubleDelay(int in, Message* reply_msg) { | 501   void OnDoubleDelay(int in, Message* reply_msg) { | 
| 503     SendDouble(pump_during_send_, !close_channel_); | 502     SendDouble(pump_during_send_, !close_channel_); | 
| 504     if (close_channel_) { | 503     if (close_channel_) { | 
| 505       delete reply_msg; | 504       delete reply_msg; | 
| 506     } else { | 505     } else { | 
| 507       SyncChannelTestMsg_Double::WriteReplyParams(reply_msg, in * 2); | 506       SyncChannelTestMsg_Double::WriteReplyParams(reply_msg, in * 2); | 
| 508       Send(reply_msg); | 507       Send(reply_msg); | 
| 509     } | 508     } | 
| 510     Done(); | 509     Done(); | 
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 952   SendWithTimeoutMixedOKAndTimeout(false); | 951   SendWithTimeoutMixedOKAndTimeout(false); | 
| 953   SendWithTimeoutMixedOKAndTimeout(true); | 952   SendWithTimeoutMixedOKAndTimeout(true); | 
| 954 } | 953 } | 
| 955 | 954 | 
| 956 //------------------------------------------------------------------------------ | 955 //------------------------------------------------------------------------------ | 
| 957 | 956 | 
| 958 namespace { | 957 namespace { | 
| 959 | 958 | 
| 960 class NestedTask : public Task { | 959 class NestedTask : public Task { | 
| 961  public: | 960  public: | 
| 962   explicit NestedTask(Worker* server) : server_(server) { } | 961   explicit NestedTask(Worker* server) : server_(server) {} | 
| 963   void Run() { | 962   void Run() { | 
| 964     // Sleep a bit so that we wake up after the reply has been received. | 963     // Sleep a bit so that we wake up after the reply has been received. | 
| 965     base::PlatformThread::Sleep(250); | 964     base::PlatformThread::Sleep(250); | 
| 966     server_->SendAnswerToLife(true, base::kNoTimeout, true); | 965     server_->SendAnswerToLife(true, base::kNoTimeout, true); | 
| 967   } | 966   } | 
| 968 | 967 | 
| 969   Worker* server_; | 968   Worker* server_; | 
| 970 }; | 969 }; | 
| 971 | 970 | 
| 972 static bool timeout_occured = false; | 971 static bool timeout_occured = false; | 
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1258   std::vector<Worker*> workers; | 1257   std::vector<Worker*> workers; | 
| 1259   workers.push_back(new NonRestrictedDispatchServer); | 1258   workers.push_back(new NonRestrictedDispatchServer); | 
| 1260   workers.push_back(server); | 1259   workers.push_back(server); | 
| 1261   workers.push_back( | 1260   workers.push_back( | 
| 1262       new RestrictedDispatchClient(&sent_ping_event, server, &success)); | 1261       new RestrictedDispatchClient(&sent_ping_event, server, &success)); | 
| 1263   RunTest(workers); | 1262   RunTest(workers); | 
| 1264   EXPECT_EQ(3, success); | 1263   EXPECT_EQ(3, success); | 
| 1265 } | 1264 } | 
| 1266 | 1265 | 
| 1267 }  // namespace IPC | 1266 }  // namespace IPC | 
| OLD | NEW | 
|---|