| 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 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 // pumps messages while waiting for a response. | 799 // pumps messages while waiting for a response. |
| 800 TEST_F(IPCSyncChannelTest, QueuedReply) { | 800 TEST_F(IPCSyncChannelTest, QueuedReply) { |
| 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 void DropAssert(const std::string&) {} | |
| 810 | |
| 811 class BadServer : public Worker { | |
| 812 public: | |
| 813 explicit BadServer(bool pump_during_send) | |
| 814 : Worker(Channel::MODE_SERVER, "simpler_server"), | |
| 815 pump_during_send_(pump_during_send) { } | |
| 816 void Run() { | |
| 817 int answer = 0; | |
| 818 | |
| 819 SyncMessage* msg = new SyncMessage( | |
| 820 MSG_ROUTING_CONTROL, SyncChannelTestMsg_Double::ID, | |
| 821 Message::PRIORITY_NORMAL, NULL); | |
| 822 if (pump_during_send_) | |
| 823 msg->EnableMessagePumping(); | |
| 824 | |
| 825 // Temporarily ignore asserts so that the assertion in | |
| 826 // ipc_message_utils doesn't cause termination. | |
| 827 logging::SetLogAssertHandler(&DropAssert); | |
| 828 bool result = Send(msg); | |
| 829 logging::SetLogAssertHandler(NULL); | |
| 830 DCHECK(!result); | |
| 831 | |
| 832 // Need to send another message to get the client to call Done(). | |
| 833 result = Send(new SyncChannelTestMsg_AnswerToLife(&answer)); | |
| 834 DCHECK(result); | |
| 835 DCHECK_EQ(answer, 42); | |
| 836 | |
| 837 Done(); | |
| 838 } | |
| 839 | |
| 840 bool pump_during_send_; | |
| 841 }; | |
| 842 | |
| 843 void BadMessage(bool pump_during_send) { | |
| 844 std::vector<Worker*> workers; | |
| 845 workers.push_back(new BadServer(pump_during_send)); | |
| 846 workers.push_back(new SimpleClient()); | |
| 847 RunTest(workers); | |
| 848 } | |
| 849 | |
| 850 } // namespace | |
| 851 | |
| 852 #if defined(OS_WIN) | |
| 853 // Crashy on windows. See crbug.com/62511. | |
| 854 #define MAYBE_BadMessage DISABLED_BadMessage | |
| 855 #else | |
| 856 #define MAYBE_BadMessage BadMessage | |
| 857 #endif | |
| 858 | |
| 859 // Tests that if a message is not serialized correctly, the Send() will fail. | |
| 860 TEST_F(IPCSyncChannelTest, MAYBE_BadMessage) { | |
| 861 BadMessage(false); | |
| 862 BadMessage(true); | |
| 863 } | |
| 864 | |
| 865 //----------------------------------------------------------------------------- | |
| 866 | |
| 867 namespace { | |
| 868 | |
| 869 class ChattyClient : public Worker { | 809 class ChattyClient : public Worker { |
| 870 public: | 810 public: |
| 871 ChattyClient() : | 811 ChattyClient() : |
| 872 Worker(Channel::MODE_CLIENT, "chatty_client") { } | 812 Worker(Channel::MODE_CLIENT, "chatty_client") { } |
| 873 | 813 |
| 874 void OnAnswer(int* answer) { | 814 void OnAnswer(int* answer) { |
| 875 // The PostMessage limit is 10k. Send 20% more than that. | 815 // The PostMessage limit is 10k. Send 20% more than that. |
| 876 const int kMessageLimit = 10000; | 816 const int kMessageLimit = 10000; |
| 877 const int kMessagesToSend = kMessageLimit * 120 / 100; | 817 const int kMessagesToSend = kMessageLimit * 120 / 100; |
| 878 for (int i = 0; i < kMessagesToSend; ++i) { | 818 for (int i = 0; i < kMessagesToSend; ++i) { |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 std::vector<Worker*> workers; | 1258 std::vector<Worker*> workers; |
| 1319 workers.push_back(new NonRestrictedDispatchServer); | 1259 workers.push_back(new NonRestrictedDispatchServer); |
| 1320 workers.push_back(server); | 1260 workers.push_back(server); |
| 1321 workers.push_back( | 1261 workers.push_back( |
| 1322 new RestrictedDispatchClient(&sent_ping_event, server, &success)); | 1262 new RestrictedDispatchClient(&sent_ping_event, server, &success)); |
| 1323 RunTest(workers); | 1263 RunTest(workers); |
| 1324 EXPECT_EQ(3, success); | 1264 EXPECT_EQ(3, success); |
| 1325 } | 1265 } |
| 1326 | 1266 |
| 1327 } // namespace IPC | 1267 } // namespace IPC |
| OLD | NEW |