| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 private: | 258 private: |
| 259 MessageLoop message_loop_; | 259 MessageLoop message_loop_; |
| 260 }; | 260 }; |
| 261 | 261 |
| 262 //----------------------------------------------------------------------------- | 262 //----------------------------------------------------------------------------- |
| 263 | 263 |
| 264 namespace { | 264 namespace { |
| 265 | 265 |
| 266 class SimpleServer : public Worker { | 266 class SimpleServer : public Worker { |
| 267 public: | 267 public: |
| 268 SimpleServer(bool pump_during_send) | 268 explicit SimpleServer(bool pump_during_send) |
| 269 : Worker(Channel::MODE_SERVER, "simpler_server"), | 269 : Worker(Channel::MODE_SERVER, "simpler_server"), |
| 270 pump_during_send_(pump_during_send) { } | 270 pump_during_send_(pump_during_send) { } |
| 271 void Run() { | 271 void Run() { |
| 272 SendAnswerToLife(pump_during_send_, base::kNoTimeout, true); | 272 SendAnswerToLife(pump_during_send_, base::kNoTimeout, true); |
| 273 Done(); | 273 Done(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 bool pump_during_send_; | 276 bool pump_during_send_; |
| 277 }; | 277 }; |
| 278 | 278 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 if (delete_during_send_) | 419 if (delete_during_send_) |
| 420 ResetChannel(); | 420 ResetChannel(); |
| 421 } | 421 } |
| 422 | 422 |
| 423 bool pump_during_send_; | 423 bool pump_during_send_; |
| 424 bool delete_during_send_; | 424 bool delete_during_send_; |
| 425 }; | 425 }; |
| 426 | 426 |
| 427 class UnblockClient : public Worker { | 427 class UnblockClient : public Worker { |
| 428 public: | 428 public: |
| 429 UnblockClient(bool pump_during_send) | 429 explicit UnblockClient(bool pump_during_send) |
| 430 : Worker(Channel::MODE_CLIENT, "unblock_client"), | 430 : Worker(Channel::MODE_CLIENT, "unblock_client"), |
| 431 pump_during_send_(pump_during_send) { } | 431 pump_during_send_(pump_during_send) { } |
| 432 | 432 |
| 433 void OnAnswer(int* answer) { | 433 void OnAnswer(int* answer) { |
| 434 SendDouble(pump_during_send_, true); | 434 SendDouble(pump_during_send_, true); |
| 435 *answer = 42; | 435 *answer = 42; |
| 436 Done(); | 436 Done(); |
| 437 } | 437 } |
| 438 | 438 |
| 439 bool pump_during_send_; | 439 bool pump_during_send_; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 RecursiveNoHang(true, true, false); | 570 RecursiveNoHang(true, true, false); |
| 571 RecursiveNoHang(true, true, true); | 571 RecursiveNoHang(true, true, true); |
| 572 } | 572 } |
| 573 | 573 |
| 574 //----------------------------------------------------------------------------- | 574 //----------------------------------------------------------------------------- |
| 575 | 575 |
| 576 namespace { | 576 namespace { |
| 577 | 577 |
| 578 class MultipleServer1 : public Worker { | 578 class MultipleServer1 : public Worker { |
| 579 public: | 579 public: |
| 580 MultipleServer1(bool pump_during_send) | 580 explicit MultipleServer1(bool pump_during_send) |
| 581 : Worker("test_channel1", Channel::MODE_SERVER), | 581 : Worker("test_channel1", Channel::MODE_SERVER), |
| 582 pump_during_send_(pump_during_send) { } | 582 pump_during_send_(pump_during_send) { } |
| 583 | 583 |
| 584 void Run() { | 584 void Run() { |
| 585 SendDouble(pump_during_send_, true); | 585 SendDouble(pump_during_send_, true); |
| 586 Done(); | 586 Done(); |
| 587 } | 587 } |
| 588 | 588 |
| 589 bool pump_during_send_; | 589 bool pump_during_send_; |
| 590 }; | 590 }; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 | 687 |
| 688 //----------------------------------------------------------------------------- | 688 //----------------------------------------------------------------------------- |
| 689 | 689 |
| 690 namespace { | 690 namespace { |
| 691 | 691 |
| 692 // This class provides server side functionality to test the case where | 692 // This class provides server side functionality to test the case where |
| 693 // multiple sync channels are in use on the same thread on the client and | 693 // multiple sync channels are in use on the same thread on the client and |
| 694 // nested calls are issued. | 694 // nested calls are issued. |
| 695 class QueuedReplyServer : public Worker { | 695 class QueuedReplyServer : public Worker { |
| 696 public: | 696 public: |
| 697 QueuedReplyServer(base::Thread* listener_thread, | 697 QueuedReplyServer(base::Thread* listener_thread, |
| 698 const std::string& channel_name, | 698 const std::string& channel_name, |
| 699 const std::string& reply_text) | 699 const std::string& reply_text) |
| 700 : Worker(channel_name, Channel::MODE_SERVER), | 700 : Worker(channel_name, Channel::MODE_SERVER), |
| 701 reply_text_(reply_text) { | 701 reply_text_(reply_text) { |
| 702 Worker::OverrideThread(listener_thread); | 702 Worker::OverrideThread(listener_thread); |
| 703 } | 703 } |
| 704 | 704 |
| 705 virtual void OnNestedTestMsg(Message* reply_msg) { | 705 virtual void OnNestedTestMsg(Message* reply_msg) { |
| 706 LOG(INFO) << __FUNCTION__ << " Sending reply: " | 706 LOG(INFO) << __FUNCTION__ << " Sending reply: " |
| 707 << reply_text_.c_str(); | 707 << reply_text_.c_str(); |
| 708 SyncChannelNestedTestMsg_String::WriteReplyParams( | 708 SyncChannelNestedTestMsg_String::WriteReplyParams( |
| 709 reply_msg, reply_text_); | 709 reply_msg, reply_text_); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 QueuedReply(false); | 801 QueuedReply(false); |
| 802 QueuedReply(true); | 802 QueuedReply(true); |
| 803 } | 803 } |
| 804 | 804 |
| 805 //----------------------------------------------------------------------------- | 805 //----------------------------------------------------------------------------- |
| 806 | 806 |
| 807 namespace { | 807 namespace { |
| 808 | 808 |
| 809 class BadServer : public Worker { | 809 class BadServer : public Worker { |
| 810 public: | 810 public: |
| 811 BadServer(bool pump_during_send) | 811 explicit BadServer(bool pump_during_send) |
| 812 : Worker(Channel::MODE_SERVER, "simpler_server"), | 812 : Worker(Channel::MODE_SERVER, "simpler_server"), |
| 813 pump_during_send_(pump_during_send) { } | 813 pump_during_send_(pump_during_send) { } |
| 814 void Run() { | 814 void Run() { |
| 815 int answer = 0; | 815 int answer = 0; |
| 816 | 816 |
| 817 SyncMessage* msg = new SyncMessage( | 817 SyncMessage* msg = new SyncMessage( |
| 818 MSG_ROUTING_CONTROL, SyncChannelTestMsg_Double::ID, | 818 MSG_ROUTING_CONTROL, SyncChannelTestMsg_Double::ID, |
| 819 Message::PRIORITY_NORMAL, NULL); | 819 Message::PRIORITY_NORMAL, NULL); |
| 820 if (pump_during_send_) | 820 if (pump_during_send_) |
| 821 msg->EnableMessagePumping(); | 821 msg->EnableMessagePumping(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 ChattyServer(false); | 892 ChattyServer(false); |
| 893 ChattyServer(true); | 893 ChattyServer(true); |
| 894 } | 894 } |
| 895 | 895 |
| 896 //------------------------------------------------------------------------------ | 896 //------------------------------------------------------------------------------ |
| 897 | 897 |
| 898 namespace { | 898 namespace { |
| 899 | 899 |
| 900 class TimeoutServer : public Worker { | 900 class TimeoutServer : public Worker { |
| 901 public: | 901 public: |
| 902 TimeoutServer(int timeout_ms, | 902 TimeoutServer(int timeout_ms, |
| 903 std::vector<bool> timeout_seq, | 903 std::vector<bool> timeout_seq, |
| 904 bool pump_during_send) | 904 bool pump_during_send) |
| 905 : Worker(Channel::MODE_SERVER, "timeout_server"), | 905 : Worker(Channel::MODE_SERVER, "timeout_server"), |
| 906 timeout_ms_(timeout_ms), | 906 timeout_ms_(timeout_ms), |
| 907 timeout_seq_(timeout_seq), | 907 timeout_seq_(timeout_seq), |
| 908 pump_during_send_(pump_during_send) { | 908 pump_during_send_(pump_during_send) { |
| 909 } | 909 } |
| 910 | 910 |
| 911 void Run() { | 911 void Run() { |
| 912 for (std::vector<bool>::const_iterator iter = timeout_seq_.begin(); | 912 for (std::vector<bool>::const_iterator iter = timeout_seq_.begin(); |
| 913 iter != timeout_seq_.end(); ++iter) { | 913 iter != timeout_seq_.end(); ++iter) { |
| 914 SendAnswerToLife(pump_during_send_, timeout_ms_, !*iter); | 914 SendAnswerToLife(pump_during_send_, timeout_ms_, !*iter); |
| 915 } | 915 } |
| 916 Done(); | 916 Done(); |
| 917 } | 917 } |
| 918 | 918 |
| 919 private: | 919 private: |
| 920 int timeout_ms_; | 920 int timeout_ms_; |
| 921 std::vector<bool> timeout_seq_; | 921 std::vector<bool> timeout_seq_; |
| 922 bool pump_during_send_; | 922 bool pump_during_send_; |
| 923 }; | 923 }; |
| 924 | 924 |
| 925 class UnresponsiveClient : public Worker { | 925 class UnresponsiveClient : public Worker { |
| 926 public: | 926 public: |
| 927 UnresponsiveClient(std::vector<bool> timeout_seq) | 927 explicit UnresponsiveClient(std::vector<bool> timeout_seq) |
| 928 : Worker(Channel::MODE_CLIENT, "unresponsive_client"), | 928 : Worker(Channel::MODE_CLIENT, "unresponsive_client"), |
| 929 timeout_seq_(timeout_seq) { | 929 timeout_seq_(timeout_seq) { |
| 930 } | 930 } |
| 931 | 931 |
| 932 void OnAnswerDelay(Message* reply_msg) { | 932 void OnAnswerDelay(Message* reply_msg) { |
| 933 DCHECK(!timeout_seq_.empty()); | 933 DCHECK(!timeout_seq_.empty()); |
| 934 if (!timeout_seq_[0]) { | 934 if (!timeout_seq_[0]) { |
| 935 SyncChannelTestMsg_AnswerToLife::WriteReplyParams(reply_msg, 42); | 935 SyncChannelTestMsg_AnswerToLife::WriteReplyParams(reply_msg, 42); |
| 936 Send(reply_msg); | 936 Send(reply_msg); |
| 937 } else { | 937 } else { |
| 938 // Don't reply. | 938 // Don't reply. |
| 939 delete reply_msg; | 939 delete reply_msg; |
| 940 } | 940 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 SendWithTimeoutMixedOKAndTimeout(false); | 1003 SendWithTimeoutMixedOKAndTimeout(false); |
| 1004 SendWithTimeoutMixedOKAndTimeout(true); | 1004 SendWithTimeoutMixedOKAndTimeout(true); |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 //------------------------------------------------------------------------------ | 1007 //------------------------------------------------------------------------------ |
| 1008 | 1008 |
| 1009 namespace { | 1009 namespace { |
| 1010 | 1010 |
| 1011 class NestedTask : public Task { | 1011 class NestedTask : public Task { |
| 1012 public: | 1012 public: |
| 1013 NestedTask(Worker* server) : server_(server) { } | 1013 explicit NestedTask(Worker* server) : server_(server) { } |
| 1014 void Run() { | 1014 void Run() { |
| 1015 // Sleep a bit so that we wake up after the reply has been received. | 1015 // Sleep a bit so that we wake up after the reply has been received. |
| 1016 PlatformThread::Sleep(250); | 1016 PlatformThread::Sleep(250); |
| 1017 server_->SendAnswerToLife(true, base::kNoTimeout, true); | 1017 server_->SendAnswerToLife(true, base::kNoTimeout, true); |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 Worker* server_; | 1020 Worker* server_; |
| 1021 }; | 1021 }; |
| 1022 | 1022 |
| 1023 static bool timeout_occured = false; | 1023 static bool timeout_occured = false; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 | 1109 |
| 1110 } // namespace | 1110 } // namespace |
| 1111 | 1111 |
| 1112 // Tests basic synchronous call | 1112 // Tests basic synchronous call |
| 1113 TEST_F(IPCSyncChannelTest, SyncMessageFilter) { | 1113 TEST_F(IPCSyncChannelTest, SyncMessageFilter) { |
| 1114 std::vector<Worker*> workers; | 1114 std::vector<Worker*> workers; |
| 1115 workers.push_back(new SyncMessageFilterServer()); | 1115 workers.push_back(new SyncMessageFilterServer()); |
| 1116 workers.push_back(new SimpleClient()); | 1116 workers.push_back(new SimpleClient()); |
| 1117 RunTest(workers); | 1117 RunTest(workers); |
| 1118 } | 1118 } |
| OLD | NEW |