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

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

Issue 2950993003: [Chromoting] Use ProcessStatsSender in DaemonProcess (daemon process) (Closed)
Patch Set: Resolve review comments Created 3 years, 5 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
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 "remoting/host/win/worker_process_launcher.h" 5 #include "remoting/host/win/worker_process_launcher.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 class MockIpcDelegate : public WorkerProcessIpcDelegate { 62 class MockIpcDelegate : public WorkerProcessIpcDelegate {
63 public: 63 public:
64 MockIpcDelegate() {} 64 MockIpcDelegate() {}
65 ~MockIpcDelegate() override {} 65 ~MockIpcDelegate() override {}
66 66
67 // WorkerProcessIpcDelegate interface. 67 // WorkerProcessIpcDelegate interface.
68 MOCK_METHOD1(OnChannelConnected, void(int32_t)); 68 MOCK_METHOD1(OnChannelConnected, void(int32_t));
69 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message&)); 69 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message&));
70 MOCK_METHOD1(OnPermanentError, void(int)); 70 MOCK_METHOD1(OnPermanentError, void(int));
71 MOCK_METHOD0(OnWorkerProcessStopped, void());
71 72
72 private: 73 private:
73 DISALLOW_COPY_AND_ASSIGN(MockIpcDelegate); 74 DISALLOW_COPY_AND_ASSIGN(MockIpcDelegate);
74 }; 75 };
75 76
76 class MockWorkerListener : public IPC::Listener { 77 class MockWorkerListener : public IPC::Listener {
77 public: 78 public:
78 MockWorkerListener() {} 79 MockWorkerListener() {}
79 ~MockWorkerListener() override {} 80 ~MockWorkerListener() override {}
80 81
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 388
388 TEST_F(WorkerProcessLauncherTest, Start) { 389 TEST_F(WorkerProcessLauncherTest, Start) {
389 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 390 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
390 .Times(1) 391 .Times(1)
391 .WillRepeatedly(Invoke(this, &WorkerProcessLauncherTest::LaunchProcess)); 392 .WillRepeatedly(Invoke(this, &WorkerProcessLauncherTest::LaunchProcess));
392 393
393 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 394 EXPECT_CALL(server_listener_, OnChannelConnected(_))
394 .Times(0); 395 .Times(0);
395 EXPECT_CALL(server_listener_, OnPermanentError(_)) 396 EXPECT_CALL(server_listener_, OnPermanentError(_))
396 .Times(0); 397 .Times(0);
398 EXPECT_CALL(server_listener_, OnWorkerProcessStopped())
399 .Times(0);
397 400
398 StartWorker(); 401 StartWorker();
399 StopWorker(); 402 StopWorker();
400 base::RunLoop().Run(); 403 base::RunLoop().Run();
401 } 404 }
402 405
403 // Starts and connects to the worker process. Expect OnChannelConnected to be 406 // Starts and connects to the worker process. Expect OnChannelConnected to be
404 // called. 407 // called.
405 TEST_F(WorkerProcessLauncherTest, StartAndConnect) { 408 TEST_F(WorkerProcessLauncherTest, StartAndConnect) {
406 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 409 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
407 .Times(1) 410 .Times(1)
408 .WillRepeatedly(Invoke( 411 .WillRepeatedly(Invoke(
409 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); 412 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect));
410 413
411 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 414 EXPECT_CALL(server_listener_, OnChannelConnected(_))
412 .Times(1) 415 .Times(1)
413 .WillOnce(InvokeWithoutArgs(this, 416 .WillOnce(InvokeWithoutArgs(this,
414 &WorkerProcessLauncherTest::StopWorker)); 417 &WorkerProcessLauncherTest::StopWorker));
415 EXPECT_CALL(server_listener_, OnPermanentError(_)) 418 EXPECT_CALL(server_listener_, OnPermanentError(_))
416 .Times(0); 419 .Times(0);
420 EXPECT_CALL(server_listener_, OnWorkerProcessStopped())
421 .Times(0);
417 422
418 StartWorker(); 423 StartWorker();
419 base::RunLoop().Run(); 424 base::RunLoop().Run();
420 } 425 }
421 426
422 // Kills the worker process after the 1st connect and expects it to be 427 // Kills the worker process after the 1st connect and expects it to be
423 // restarted. 428 // restarted.
424 TEST_F(WorkerProcessLauncherTest, Restart) { 429 TEST_F(WorkerProcessLauncherTest, Restart) {
425 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 430 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
426 .Times(2) 431 .Times(2)
427 .WillRepeatedly(Invoke( 432 .WillRepeatedly(Invoke(
428 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); 433 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect));
429 Expectation first_connect = 434 Expectation first_connect =
430 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 435 EXPECT_CALL(server_listener_, OnChannelConnected(_))
431 .Times(2) 436 .Times(2)
432 .WillOnce(InvokeWithoutArgs(CreateFunctor( 437 .WillOnce(InvokeWithoutArgs(CreateFunctor(
433 &WorkerProcessLauncherTest::TerminateWorker, 438 &WorkerProcessLauncherTest::TerminateWorker,
434 base::Unretained(this), 439 base::Unretained(this),
435 CONTROL_C_EXIT))) 440 CONTROL_C_EXIT)))
436 .WillOnce(InvokeWithoutArgs(this, 441 .WillOnce(InvokeWithoutArgs(this,
437 &WorkerProcessLauncherTest::StopWorker)); 442 &WorkerProcessLauncherTest::StopWorker));
438 443
439 EXPECT_CALL(server_listener_, OnPermanentError(_)) 444 EXPECT_CALL(server_listener_, OnPermanentError(_))
440 .Times(0); 445 .Times(0);
446 EXPECT_CALL(server_listener_, OnWorkerProcessStopped())
447 .Times(1);
441 448
442 StartWorker(); 449 StartWorker();
443 base::RunLoop().Run(); 450 base::RunLoop().Run();
444 } 451 }
445 452
446 // Drops the IPC channel to the worker process after the 1st connect and expects 453 // Drops the IPC channel to the worker process after the 1st connect and expects
447 // the worker process to be restarted. 454 // the worker process to be restarted.
448 TEST_F(WorkerProcessLauncherTest, DropIpcChannel) { 455 TEST_F(WorkerProcessLauncherTest, DropIpcChannel) {
449 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 456 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
450 .Times(2) 457 .Times(2)
451 .WillRepeatedly(Invoke( 458 .WillRepeatedly(Invoke(
452 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); 459 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect));
453 460
454 Expectation first_connect = 461 Expectation first_connect =
455 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 462 EXPECT_CALL(server_listener_, OnChannelConnected(_))
456 .Times(2) 463 .Times(2)
457 .WillOnce(InvokeWithoutArgs( 464 .WillOnce(InvokeWithoutArgs(
458 this, &WorkerProcessLauncherTest::DisconnectClient)) 465 this, &WorkerProcessLauncherTest::DisconnectClient))
459 .WillOnce(InvokeWithoutArgs( 466 .WillOnce(InvokeWithoutArgs(
460 this, &WorkerProcessLauncherTest::StopWorker)); 467 this, &WorkerProcessLauncherTest::StopWorker));
461 468
462 EXPECT_CALL(server_listener_, OnPermanentError(_)) 469 EXPECT_CALL(server_listener_, OnPermanentError(_))
463 .Times(0); 470 .Times(0);
471 EXPECT_CALL(server_listener_, OnWorkerProcessStopped())
472 .Times(1);
464 473
465 StartWorker(); 474 StartWorker();
466 base::RunLoop().Run(); 475 base::RunLoop().Run();
467 } 476 }
468 477
469 // Returns a permanent error exit code and expects OnPermanentError() to be 478 // Returns a permanent error exit code and expects OnPermanentError() to be
470 // invoked. 479 // invoked.
471 TEST_F(WorkerProcessLauncherTest, PermanentError) { 480 TEST_F(WorkerProcessLauncherTest, PermanentError) {
472 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 481 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
473 .Times(1) 482 .Times(1)
474 .WillRepeatedly(Invoke( 483 .WillRepeatedly(Invoke(
475 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); 484 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect));
476 485
477 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 486 EXPECT_CALL(server_listener_, OnChannelConnected(_))
478 .Times(1) 487 .Times(1)
479 .WillOnce(InvokeWithoutArgs(CreateFunctor( 488 .WillOnce(InvokeWithoutArgs(CreateFunctor(
480 &WorkerProcessLauncherTest::TerminateWorker, 489 &WorkerProcessLauncherTest::TerminateWorker,
481 base::Unretained(this), 490 base::Unretained(this),
482 kMinPermanentErrorExitCode))); 491 kMinPermanentErrorExitCode)));
483 EXPECT_CALL(server_listener_, OnPermanentError(_)) 492 EXPECT_CALL(server_listener_, OnPermanentError(_))
484 .Times(1) 493 .Times(1)
485 .WillOnce(InvokeWithoutArgs(this, 494 .WillOnce(InvokeWithoutArgs(this,
486 &WorkerProcessLauncherTest::StopWorker)); 495 &WorkerProcessLauncherTest::StopWorker));
496 EXPECT_CALL(server_listener_, OnWorkerProcessStopped())
497 .Times(1);
487 498
488 StartWorker(); 499 StartWorker();
489 base::RunLoop().Run(); 500 base::RunLoop().Run();
490 } 501 }
491 502
492 // Requests the worker to crash and expects it to honor the request. 503 // Requests the worker to crash and expects it to honor the request.
493 TEST_F(WorkerProcessLauncherTest, Crash) { 504 TEST_F(WorkerProcessLauncherTest, Crash) {
494 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 505 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
495 .Times(2) 506 .Times(2)
496 .WillRepeatedly(Invoke( 507 .WillRepeatedly(Invoke(
497 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); 508 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect));
498 509
499 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 510 EXPECT_CALL(server_listener_, OnChannelConnected(_))
500 .Times(2) 511 .Times(2)
501 .WillOnce(InvokeWithoutArgs(this, 512 .WillOnce(InvokeWithoutArgs(this,
502 &WorkerProcessLauncherTest::CrashWorker)) 513 &WorkerProcessLauncherTest::CrashWorker))
503 .WillOnce(InvokeWithoutArgs(this, 514 .WillOnce(InvokeWithoutArgs(this,
504 &WorkerProcessLauncherTest::StopWorker)); 515 &WorkerProcessLauncherTest::StopWorker));
505 516
506 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) 517 EXPECT_CALL(client_listener_, OnCrash(_, _, _))
507 .Times(1) 518 .Times(1)
508 .WillOnce(InvokeWithoutArgs(CreateFunctor( 519 .WillOnce(InvokeWithoutArgs(CreateFunctor(
509 &WorkerProcessLauncherTest::TerminateWorker, 520 &WorkerProcessLauncherTest::TerminateWorker,
510 base::Unretained(this), 521 base::Unretained(this),
511 EXCEPTION_BREAKPOINT))); 522 EXCEPTION_BREAKPOINT)));
523 EXPECT_CALL(server_listener_, OnWorkerProcessStopped())
524 .Times(1);
512 525
513 StartWorker(); 526 StartWorker();
514 base::RunLoop().Run(); 527 base::RunLoop().Run();
515 } 528 }
516 529
517 // Requests the worker to crash and terminates the worker even if it does not 530 // Requests the worker to crash and terminates the worker even if it does not
518 // comply. 531 // comply.
519 TEST_F(WorkerProcessLauncherTest, CrashAnyway) { 532 TEST_F(WorkerProcessLauncherTest, CrashAnyway) {
520 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 533 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
521 .Times(2) 534 .Times(2)
522 .WillRepeatedly(Invoke( 535 .WillRepeatedly(Invoke(
523 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); 536 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect));
524 537
525 EXPECT_CALL(server_listener_, OnChannelConnected(_)) 538 EXPECT_CALL(server_listener_, OnChannelConnected(_))
526 .Times(2) 539 .Times(2)
527 .WillOnce(InvokeWithoutArgs(this, 540 .WillOnce(InvokeWithoutArgs(this,
528 &WorkerProcessLauncherTest::CrashWorker)) 541 &WorkerProcessLauncherTest::CrashWorker))
529 .WillOnce(InvokeWithoutArgs(this, 542 .WillOnce(InvokeWithoutArgs(this,
530 &WorkerProcessLauncherTest::StopWorker)); 543 &WorkerProcessLauncherTest::StopWorker));
531 544
532 // Ignore the crash request and try send another message to the launcher. 545 // Ignore the crash request and try send another message to the launcher.
533 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) 546 EXPECT_CALL(client_listener_, OnCrash(_, _, _))
534 .Times(1) 547 .Times(1)
535 .WillOnce(InvokeWithoutArgs( 548 .WillOnce(InvokeWithoutArgs(
536 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher)); 549 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher));
550 EXPECT_CALL(server_listener_, OnWorkerProcessStopped())
551 .Times(1);
537 552
538 StartWorker(); 553 StartWorker();
539 base::RunLoop().Run(); 554 base::RunLoop().Run();
540 } 555 }
541 556
542 } // namespace remoting 557 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/win/worker_process_launcher.cc ('k') | remoting/host/worker_process_ipc_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698