Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: chrome/common/ipc_fuzzing_tests.cc

Issue 24004: Fix the windows implementation of KillProcess and WaitForSingleProcess to not... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/metrics/metrics_service_uitest.cc ('k') | chrome/common/ipc_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 int value = 43; 295 int value = 43;
296 msg = new MsgClassIS(value, L"expect 43"); 296 msg = new MsgClassIS(value, L"expect 43");
297 chan.Send(msg); 297 chan.Send(msg);
298 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassIS::ID)); 298 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassIS::ID));
299 299
300 msg = new MsgClassSI(L"expect 44", ++value); 300 msg = new MsgClassSI(L"expect 44", ++value);
301 chan.Send(msg); 301 chan.Send(msg);
302 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID)); 302 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID));
303 303
304 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); 304 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000));
305 base::CloseProcessHandle(server_process);
305 } 306 }
306 307
307 // This test uses a payload that is smaller than expected. 308 // This test uses a payload that is smaller than expected.
308 // This generates an error while unpacking the IPC buffer which in 309 // This generates an error while unpacking the IPC buffer which in
309 // In debug this triggers an assertion and in release it is ignored(!!). Right 310 // In debug this triggers an assertion and in release it is ignored(!!). Right
310 // after we generate another valid IPC to make sure framing is working 311 // after we generate another valid IPC to make sure framing is working
311 // properly. 312 // properly.
312 #ifdef NDEBUG 313 #ifdef NDEBUG
313 TEST_F(IPCFuzzingTest, MsgBadPayloadShort) { 314 TEST_F(IPCFuzzingTest, MsgBadPayloadShort) {
314 FuzzerClientListener listener; 315 FuzzerClientListener listener;
315 IPC::Channel chan(kFuzzerChannel, IPC::Channel::MODE_SERVER, 316 IPC::Channel chan(kFuzzerChannel, IPC::Channel::MODE_SERVER,
316 &listener); 317 &listener);
317 base::ProcessHandle server_process = SpawnChild(FUZZER_SERVER, &chan); 318 base::ProcessHandle server_process = SpawnChild(FUZZER_SERVER, &chan);
318 ASSERT_TRUE(server_process); 319 ASSERT_TRUE(server_process);
319 PlatformThread::Sleep(1000); 320 PlatformThread::Sleep(1000);
320 ASSERT_TRUE(chan.Connect()); 321 ASSERT_TRUE(chan.Connect());
321 listener.Init(&chan); 322 listener.Init(&chan);
322 323
323 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, 324 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID,
324 IPC::Message::PRIORITY_NORMAL); 325 IPC::Message::PRIORITY_NORMAL);
325 msg->WriteInt(666); 326 msg->WriteInt(666);
326 chan.Send(msg); 327 chan.Send(msg);
327 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID)); 328 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID));
328 329
329 msg = new MsgClassSI(L"expect one", 1); 330 msg = new MsgClassSI(L"expect one", 1);
330 chan.Send(msg); 331 chan.Send(msg);
331 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID)); 332 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID));
332 333
333 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); 334 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000));
335 base::CloseProcessHandle(server_process);
334 } 336 }
335 #endif // NDEBUG 337 #endif // NDEBUG
336 338
337 // This test uses a payload that has too many arguments, but so the payload 339 // This test uses a payload that has too many arguments, but so the payload
338 // size is big enough so the unpacking routine does not generate an error as 340 // size is big enough so the unpacking routine does not generate an error as
339 // in the case of MsgBadPayloadShort test. 341 // in the case of MsgBadPayloadShort test.
340 // This test does not pinpoint a flaw (per se) as by design we don't carry 342 // This test does not pinpoint a flaw (per se) as by design we don't carry
341 // type information on the IPC message. 343 // type information on the IPC message.
342 TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) { 344 TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) {
343 FuzzerClientListener listener; 345 FuzzerClientListener listener;
(...skipping 14 matching lines...) Expand all
358 chan.Send(msg); 360 chan.Send(msg);
359 EXPECT_TRUE(listener.ExpectMessage(0, MsgClassSI::ID)); 361 EXPECT_TRUE(listener.ExpectMessage(0, MsgClassSI::ID));
360 362
361 // Now send a well formed message to make sure the receiver wasn't 363 // Now send a well formed message to make sure the receiver wasn't
362 // thrown out of sync by the extra argument. 364 // thrown out of sync by the extra argument.
363 msg = new MsgClassIS(3, L"expect three"); 365 msg = new MsgClassIS(3, L"expect three");
364 chan.Send(msg); 366 chan.Send(msg);
365 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); 367 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID));
366 368
367 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); 369 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000));
370 base::CloseProcessHandle(server_process);
368 } 371 }
369 372
370 // This class is for testing the IPC_BEGIN_MESSAGE_MAP_EX macros. 373 // This class is for testing the IPC_BEGIN_MESSAGE_MAP_EX macros.
371 class ServerMacroExTest { 374 class ServerMacroExTest {
372 public: 375 public:
373 ServerMacroExTest() : unhandled_msgs_(0) { 376 ServerMacroExTest() : unhandled_msgs_(0) {
374 } 377 }
375 virtual bool OnMessageReceived(const IPC::Message& msg) { 378 virtual bool OnMessageReceived(const IPC::Message& msg) {
376 bool msg_is_ok = false; 379 bool msg_is_ok = false;
377 IPC_BEGIN_MESSAGE_MAP_EX(ServerMacroExTest, msg, msg_is_ok) 380 IPC_BEGIN_MESSAGE_MAP_EX(ServerMacroExTest, msg, msg_is_ok)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 IPC::Message::PRIORITY_NORMAL); 422 IPC::Message::PRIORITY_NORMAL);
420 msg->WriteInt(0x64); 423 msg->WriteInt(0x64);
421 msg->WriteInt(0x32); 424 msg->WriteInt(0x32);
422 EXPECT_FALSE(server.OnMessageReceived(*msg)); 425 EXPECT_FALSE(server.OnMessageReceived(*msg));
423 delete msg; 426 delete msg;
424 427
425 EXPECT_EQ(0, server.unhandled_msgs()); 428 EXPECT_EQ(0, server.unhandled_msgs());
426 #endif 429 #endif
427 } 430 }
428 431
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service_uitest.cc ('k') | chrome/common/ipc_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698