OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <string> | 6 #include <string> |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/platform_thread.h" | 10 #include "base/platform_thread.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 FUZZER_ROUTING_ID = 5 | 151 FUZZER_ROUTING_ID = 5 |
152 }; | 152 }; |
153 | 153 |
154 // The fuzzer server class. It runs in a child process and expects | 154 // The fuzzer server class. It runs in a child process and expects |
155 // only two IPC calls; after that it exits the message loop which | 155 // only two IPC calls; after that it exits the message loop which |
156 // terminates the child process. | 156 // terminates the child process. |
157 class FuzzerServerListener : public SimpleListener { | 157 class FuzzerServerListener : public SimpleListener { |
158 public: | 158 public: |
159 FuzzerServerListener() : message_count_(2), pending_messages_(0) { | 159 FuzzerServerListener() : message_count_(2), pending_messages_(0) { |
160 } | 160 } |
161 virtual void OnMessageReceived(const IPC::Message& msg) { | 161 virtual bool OnMessageReceived(const IPC::Message& msg) { |
162 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 162 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
163 ++pending_messages_; | 163 ++pending_messages_; |
164 IPC_BEGIN_MESSAGE_MAP(FuzzerServerListener, msg) | 164 IPC_BEGIN_MESSAGE_MAP(FuzzerServerListener, msg) |
165 IPC_MESSAGE_HANDLER(MsgClassIS, OnMsgClassISMessage) | 165 IPC_MESSAGE_HANDLER(MsgClassIS, OnMsgClassISMessage) |
166 IPC_MESSAGE_HANDLER(MsgClassSI, OnMsgClassSIMessage) | 166 IPC_MESSAGE_HANDLER(MsgClassSI, OnMsgClassSIMessage) |
167 IPC_END_MESSAGE_MAP() | 167 IPC_END_MESSAGE_MAP() |
168 if (pending_messages_) { | 168 if (pending_messages_) { |
169 // Probably a problem de-serializing the message. | 169 // Probably a problem de-serializing the message. |
170 ReplyMsgNotHandled(msg.type()); | 170 ReplyMsgNotHandled(msg.type()); |
171 } | 171 } |
172 } | 172 } |
| 173 return true; |
173 } | 174 } |
174 | 175 |
175 private: | 176 private: |
176 void OnMsgClassISMessage(int value, const std::wstring& text) { | 177 void OnMsgClassISMessage(int value, const std::wstring& text) { |
177 UseData(MsgClassIS::ID, value, text); | 178 UseData(MsgClassIS::ID, value, text); |
178 RoundtripAckReply(FUZZER_ROUTING_ID, MsgClassIS::ID, value); | 179 RoundtripAckReply(FUZZER_ROUTING_ID, MsgClassIS::ID, value); |
179 Cleanup(); | 180 Cleanup(); |
180 } | 181 } |
181 | 182 |
182 void OnMsgClassSIMessage(const std::wstring& text, int value) { | 183 void OnMsgClassSIMessage(const std::wstring& text, int value) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 215 |
215 int message_count_; | 216 int message_count_; |
216 int pending_messages_; | 217 int pending_messages_; |
217 }; | 218 }; |
218 | 219 |
219 class FuzzerClientListener : public SimpleListener { | 220 class FuzzerClientListener : public SimpleListener { |
220 public: | 221 public: |
221 FuzzerClientListener() : last_msg_(NULL) { | 222 FuzzerClientListener() : last_msg_(NULL) { |
222 } | 223 } |
223 | 224 |
224 virtual void OnMessageReceived(const IPC::Message& msg) { | 225 virtual bool OnMessageReceived(const IPC::Message& msg) { |
225 last_msg_ = new IPC::Message(msg); | 226 last_msg_ = new IPC::Message(msg); |
226 MessageLoop::current()->Quit(); | 227 MessageLoop::current()->Quit(); |
| 228 return true; |
227 } | 229 } |
228 | 230 |
229 bool ExpectMessage(int value, uint32 type_id) { | 231 bool ExpectMessage(int value, uint32 type_id) { |
230 if (!MsgHandlerInternal(type_id)) | 232 if (!MsgHandlerInternal(type_id)) |
231 return false; | 233 return false; |
232 int msg_value1 = 0; | 234 int msg_value1 = 0; |
233 int msg_value2 = 0; | 235 int msg_value2 = 0; |
234 void* iter = NULL; | 236 void* iter = NULL; |
235 if (!last_msg_->ReadInt(&iter, &msg_value1)) | 237 if (!last_msg_->ReadInt(&iter, &msg_value1)) |
236 return false; | 238 return false; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, | 424 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, |
423 IPC::Message::PRIORITY_NORMAL); | 425 IPC::Message::PRIORITY_NORMAL); |
424 msg->WriteInt(0x64); | 426 msg->WriteInt(0x64); |
425 msg->WriteInt(0x32); | 427 msg->WriteInt(0x32); |
426 EXPECT_FALSE(server.OnMessageReceived(*msg)); | 428 EXPECT_FALSE(server.OnMessageReceived(*msg)); |
427 delete msg; | 429 delete msg; |
428 | 430 |
429 EXPECT_EQ(0, server.unhandled_msgs()); | 431 EXPECT_EQ(0, server.unhandled_msgs()); |
430 #endif | 432 #endif |
431 } | 433 } |
OLD | NEW |