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 <iostream> | 6 #include <iostream> |
7 #include <string> | 7 #include <string> |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 RoundtripAckReply(FUZZER_ROUTING_ID, MsgClassIS::ID, value); | 179 RoundtripAckReply(FUZZER_ROUTING_ID, MsgClassIS::ID, value); |
180 Cleanup(); | 180 Cleanup(); |
181 } | 181 } |
182 | 182 |
183 void OnMsgClassSIMessage(const std::wstring& text, int value) { | 183 void OnMsgClassSIMessage(const std::wstring& text, int value) { |
184 UseData(MsgClassSI::ID, value, text); | 184 UseData(MsgClassSI::ID, value, text); |
185 RoundtripAckReply(FUZZER_ROUTING_ID, MsgClassSI::ID, value); | 185 RoundtripAckReply(FUZZER_ROUTING_ID, MsgClassSI::ID, value); |
186 Cleanup(); | 186 Cleanup(); |
187 } | 187 } |
188 | 188 |
189 bool RoundtripAckReply(int routing, uint32 type_id, int reply) { | 189 bool RoundtripAckReply(int routing, int type_id, int reply) { |
190 IPC::Message* message = new IPC::Message(routing, type_id, | 190 IPC::Message* message = new IPC::Message(routing, type_id, |
191 IPC::Message::PRIORITY_NORMAL); | 191 IPC::Message::PRIORITY_NORMAL); |
192 message->WriteInt(reply + 1); | 192 message->WriteInt(reply + 1); |
193 message->WriteInt(reply); | 193 message->WriteInt(reply); |
194 return other_->Send(message); | 194 return other_->Send(message); |
195 } | 195 } |
196 | 196 |
197 void Cleanup() { | 197 void Cleanup() { |
198 --message_count_; | 198 --message_count_; |
199 --pending_messages_; | 199 --pending_messages_; |
200 if (0 == message_count_) | 200 if (0 == message_count_) |
201 MessageLoop::current()->Quit(); | 201 MessageLoop::current()->Quit(); |
202 } | 202 } |
203 | 203 |
204 void ReplyMsgNotHandled(uint32 type_id) { | 204 void ReplyMsgNotHandled(int type_id) { |
205 RoundtripAckReply(FUZZER_ROUTING_ID, CLIENT_UNHANDLED_IPC, type_id); | 205 RoundtripAckReply(FUZZER_ROUTING_ID, CLIENT_UNHANDLED_IPC, type_id); |
206 Cleanup(); | 206 Cleanup(); |
207 } | 207 } |
208 | 208 |
209 void UseData(int caller, int value, const std::wstring& text) { | 209 void UseData(int caller, int value, const std::wstring& text) { |
210 std::wostringstream wos; | 210 std::wostringstream wos; |
211 wos << L"IPC fuzzer:" << caller << " [" << value << L" " << text << L"]\n"; | 211 wos << L"IPC fuzzer:" << caller << " [" << value << L" " << text << L"]\n"; |
212 std::wstring output = wos.str(); | 212 std::wstring output = wos.str(); |
213 LOG(WARNING) << output.c_str(); | 213 LOG(WARNING) << output.c_str(); |
214 }; | 214 }; |
215 | 215 |
216 int message_count_; | 216 int message_count_; |
217 int pending_messages_; | 217 int pending_messages_; |
218 }; | 218 }; |
219 | 219 |
220 class FuzzerClientListener : public SimpleListener { | 220 class FuzzerClientListener : public SimpleListener { |
221 public: | 221 public: |
222 FuzzerClientListener() : last_msg_(NULL) { | 222 FuzzerClientListener() : last_msg_(NULL) { |
223 } | 223 } |
224 | 224 |
225 virtual void OnMessageReceived(const IPC::Message& msg) { | 225 virtual void OnMessageReceived(const IPC::Message& msg) { |
226 last_msg_ = new IPC::Message(msg); | 226 last_msg_ = new IPC::Message(msg); |
227 MessageLoop::current()->Quit(); | 227 MessageLoop::current()->Quit(); |
228 } | 228 } |
229 | 229 |
230 bool ExpectMessage(int value, uint32 type_id) { | 230 bool ExpectMessage(int value, int type_id) { |
231 if (!MsgHandlerInternal(type_id)) | 231 if (!MsgHandlerInternal(type_id)) |
232 return false; | 232 return false; |
233 int msg_value1 = 0; | 233 int msg_value1 = 0; |
234 int msg_value2 = 0; | 234 int msg_value2 = 0; |
235 void* iter = NULL; | 235 void* iter = NULL; |
236 if (!last_msg_->ReadInt(&iter, &msg_value1)) | 236 if (!last_msg_->ReadInt(&iter, &msg_value1)) |
237 return false; | 237 return false; |
238 if (!last_msg_->ReadInt(&iter, &msg_value2)) | 238 if (!last_msg_->ReadInt(&iter, &msg_value2)) |
239 return false; | 239 return false; |
240 if ((msg_value2 + 1) != msg_value1) | 240 if ((msg_value2 + 1) != msg_value1) |
241 return false; | 241 return false; |
242 if (msg_value2 != value) | 242 if (msg_value2 != value) |
243 return false; | 243 return false; |
244 | 244 |
245 delete last_msg_; | 245 delete last_msg_; |
246 last_msg_ = NULL; | 246 last_msg_ = NULL; |
247 return true; | 247 return true; |
248 } | 248 } |
249 | 249 |
250 bool ExpectMsgNotHandled(uint32 type_id) { | 250 bool ExpectMsgNotHandled(int type_id) { |
251 return ExpectMessage(type_id, CLIENT_UNHANDLED_IPC); | 251 return ExpectMessage(type_id, CLIENT_UNHANDLED_IPC); |
252 } | 252 } |
253 | 253 |
254 private: | 254 private: |
255 bool MsgHandlerInternal(uint32 type_id) { | 255 bool MsgHandlerInternal(int type_id) { |
256 MessageLoop::current()->Run(); | 256 MessageLoop::current()->Run(); |
257 if (NULL == last_msg_) | 257 if (NULL == last_msg_) |
258 return false; | 258 return false; |
259 if (FUZZER_ROUTING_ID != last_msg_->routing_id()) | 259 if (FUZZER_ROUTING_ID != last_msg_->routing_id()) |
260 return false; | 260 return false; |
261 return (type_id == last_msg_->type()); | 261 return (type_id == last_msg_->type()); |
262 }; | 262 }; |
263 | 263 |
264 IPC::Message* last_msg_; | 264 IPC::Message* last_msg_; |
265 }; | 265 }; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, | 421 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, |
422 IPC::Message::PRIORITY_NORMAL); | 422 IPC::Message::PRIORITY_NORMAL); |
423 msg->WriteInt(0x64); | 423 msg->WriteInt(0x64); |
424 msg->WriteInt(0x32); | 424 msg->WriteInt(0x32); |
425 EXPECT_FALSE(server.OnMessageReceived(*msg)); | 425 EXPECT_FALSE(server.OnMessageReceived(*msg)); |
426 delete msg; | 426 delete msg; |
427 | 427 |
428 EXPECT_EQ(0, server.unhandled_msgs()); | 428 EXPECT_EQ(0, server.unhandled_msgs()); |
429 #endif | 429 #endif |
430 } | 430 } |
OLD | NEW |