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

Side by Side Diff: remoting/host/win/worker_process_launcher_unittest.cc

Issue 17261013: Change the daemon start type to 'manual' if the host ID has been deleted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/win/scoped_handle.h" 9 #include "base/win/scoped_handle.h"
10 #include "base/win/scoped_process_information.h" 10 #include "base/win/scoped_process_information.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 }; 55 };
56 56
57 class MockIpcDelegate : public WorkerProcessIpcDelegate { 57 class MockIpcDelegate : public WorkerProcessIpcDelegate {
58 public: 58 public:
59 MockIpcDelegate() {} 59 MockIpcDelegate() {}
60 virtual ~MockIpcDelegate() {} 60 virtual ~MockIpcDelegate() {}
61 61
62 // WorkerProcessIpcDelegate interface. 62 // WorkerProcessIpcDelegate interface.
63 MOCK_METHOD1(OnChannelConnected, void(int32)); 63 MOCK_METHOD1(OnChannelConnected, void(int32));
64 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message&)); 64 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message&));
65 MOCK_METHOD0(OnPermanentError, void()); 65 MOCK_METHOD1(OnPermanentError, void(int));
66 66
67 private: 67 private:
68 DISALLOW_COPY_AND_ASSIGN(MockIpcDelegate); 68 DISALLOW_COPY_AND_ASSIGN(MockIpcDelegate);
69 }; 69 };
70 70
71 class MockWorkerListener : public IPC::Listener { 71 class MockWorkerListener : public IPC::Listener {
72 public: 72 public:
73 MockWorkerListener() {} 73 MockWorkerListener() {}
74 virtual ~MockWorkerListener() {} 74 virtual ~MockWorkerListener() {}
75 75
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 event_handler_->OnProcessLaunched(copy.Pass()); 380 event_handler_->OnProcessLaunched(copy.Pass());
381 } 381 }
382 382
383 TEST_F(WorkerProcessLauncherTest, Start) { 383 TEST_F(WorkerProcessLauncherTest, Start) {
384 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 384 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
385 .Times(1) 385 .Times(1)
386 .WillRepeatedly(Invoke(this, &WorkerProcessLauncherTest::LaunchProcess)); 386 .WillRepeatedly(Invoke(this, &WorkerProcessLauncherTest::LaunchProcess));
387 387
388 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 388 EXPECT_CALL(server_listener_, OnChannelConnected(_))
389 .Times(0); 389 .Times(0);
390 EXPECT_CALL(server_listener_, OnPermanentError()) 390 EXPECT_CALL(server_listener_, OnPermanentError(_))
391 .Times(0); 391 .Times(0);
392 392
393 StartWorker(); 393 StartWorker();
394 StopWorker(); 394 StopWorker();
395 message_loop_.Run(); 395 message_loop_.Run();
396 } 396 }
397 397
398 // Starts and connects to the worker process. Expect OnChannelConnected to be 398 // Starts and connects to the worker process. Expect OnChannelConnected to be
399 // called. 399 // called.
400 TEST_F(WorkerProcessLauncherTest, StartAndConnect) { 400 TEST_F(WorkerProcessLauncherTest, StartAndConnect) {
401 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 401 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
402 .Times(1) 402 .Times(1)
403 .WillRepeatedly(Invoke( 403 .WillRepeatedly(Invoke(
404 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); 404 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect));
405 405
406 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 406 EXPECT_CALL(server_listener_, OnChannelConnected(_))
407 .Times(1) 407 .Times(1)
408 .WillOnce(InvokeWithoutArgs(this, 408 .WillOnce(InvokeWithoutArgs(this,
409 &WorkerProcessLauncherTest::StopWorker)); 409 &WorkerProcessLauncherTest::StopWorker));
410 EXPECT_CALL(server_listener_, OnPermanentError()) 410 EXPECT_CALL(server_listener_, OnPermanentError(_))
411 .Times(0); 411 .Times(0);
412 412
413 StartWorker(); 413 StartWorker();
414 message_loop_.Run(); 414 message_loop_.Run();
415 } 415 }
416 416
417 // Kills the worker process after the 1st connect and expects it to be 417 // Kills the worker process after the 1st connect and expects it to be
418 // restarted. 418 // restarted.
419 TEST_F(WorkerProcessLauncherTest, Restart) { 419 TEST_F(WorkerProcessLauncherTest, Restart) {
420 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 420 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
421 .Times(2) 421 .Times(2)
422 .WillRepeatedly(Invoke( 422 .WillRepeatedly(Invoke(
423 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); 423 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect));
424 Expectation first_connect = 424 Expectation first_connect =
425 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 425 EXPECT_CALL(server_listener_, OnChannelConnected(_))
426 .Times(2) 426 .Times(2)
427 .WillOnce(InvokeWithoutArgs(CreateFunctor( 427 .WillOnce(InvokeWithoutArgs(CreateFunctor(
428 this, &WorkerProcessLauncherTest::TerminateWorker, 428 this, &WorkerProcessLauncherTest::TerminateWorker,
429 CONTROL_C_EXIT))) 429 CONTROL_C_EXIT)))
430 .WillOnce(InvokeWithoutArgs(this, 430 .WillOnce(InvokeWithoutArgs(this,
431 &WorkerProcessLauncherTest::StopWorker)); 431 &WorkerProcessLauncherTest::StopWorker));
432 432
433 EXPECT_CALL(server_listener_, OnPermanentError()) 433 EXPECT_CALL(server_listener_, OnPermanentError(_))
434 .Times(0); 434 .Times(0);
435 435
436 StartWorker(); 436 StartWorker();
437 message_loop_.Run(); 437 message_loop_.Run();
438 } 438 }
439 439
440 // Drops the IPC channel to the worker process after the 1st connect and expects 440 // Drops the IPC channel to the worker process after the 1st connect and expects
441 // the worker process to be restarted. 441 // the worker process to be restarted.
442 TEST_F(WorkerProcessLauncherTest, DropIpcChannel) { 442 TEST_F(WorkerProcessLauncherTest, DropIpcChannel) {
443 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 443 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
444 .Times(2) 444 .Times(2)
445 .WillRepeatedly(Invoke( 445 .WillRepeatedly(Invoke(
446 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); 446 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect));
447 447
448 Expectation first_connect = 448 Expectation first_connect =
449 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 449 EXPECT_CALL(server_listener_, OnChannelConnected(_))
450 .Times(2) 450 .Times(2)
451 .WillOnce(InvokeWithoutArgs( 451 .WillOnce(InvokeWithoutArgs(
452 this, &WorkerProcessLauncherTest::DisconnectClient)) 452 this, &WorkerProcessLauncherTest::DisconnectClient))
453 .WillOnce(InvokeWithoutArgs( 453 .WillOnce(InvokeWithoutArgs(
454 this, &WorkerProcessLauncherTest::StopWorker)); 454 this, &WorkerProcessLauncherTest::StopWorker));
455 455
456 EXPECT_CALL(server_listener_, OnPermanentError()) 456 EXPECT_CALL(server_listener_, OnPermanentError(_))
457 .Times(0); 457 .Times(0);
458 458
459 StartWorker(); 459 StartWorker();
460 message_loop_.Run(); 460 message_loop_.Run();
461 } 461 }
462 462
463 // Returns a permanent error exit code and expects OnPermanentError() to be 463 // Returns a permanent error exit code and expects OnPermanentError() to be
464 // invoked. 464 // invoked.
465 TEST_F(WorkerProcessLauncherTest, PermanentError) { 465 TEST_F(WorkerProcessLauncherTest, PermanentError) {
466 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 466 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
467 .Times(1) 467 .Times(1)
468 .WillRepeatedly(Invoke( 468 .WillRepeatedly(Invoke(
469 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); 469 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect));
470 470
471 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 471 EXPECT_CALL(server_listener_, OnChannelConnected(_))
472 .Times(1) 472 .Times(1)
473 .WillOnce(InvokeWithoutArgs(CreateFunctor( 473 .WillOnce(InvokeWithoutArgs(CreateFunctor(
474 this, &WorkerProcessLauncherTest::TerminateWorker, 474 this, &WorkerProcessLauncherTest::TerminateWorker,
475 kMinPermanentErrorExitCode))); 475 kMinPermanentErrorExitCode)));
476 EXPECT_CALL(server_listener_, OnPermanentError()) 476 EXPECT_CALL(server_listener_, OnPermanentError(_))
477 .Times(1) 477 .Times(1)
478 .WillOnce(InvokeWithoutArgs(this, 478 .WillOnce(InvokeWithoutArgs(this,
479 &WorkerProcessLauncherTest::StopWorker)); 479 &WorkerProcessLauncherTest::StopWorker));
480 480
481 StartWorker(); 481 StartWorker();
482 message_loop_.Run(); 482 message_loop_.Run();
483 } 483 }
484 484
485 // Requests the worker to crash and expects it to honor the request. 485 // Requests the worker to crash and expects it to honor the request.
486 TEST_F(WorkerProcessLauncherTest, Crash) { 486 TEST_F(WorkerProcessLauncherTest, Crash) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) 525 EXPECT_CALL(client_listener_, OnCrash(_, _, _))
526 .Times(1) 526 .Times(1)
527 .WillOnce(InvokeWithoutArgs( 527 .WillOnce(InvokeWithoutArgs(
528 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher)); 528 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher));
529 529
530 StartWorker(); 530 StartWorker();
531 message_loop_.Run(); 531 message_loop_.Run();
532 } 532 }
533 533
534 } // namespace remoting 534 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698