OLD | NEW |
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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" |
15 #include "base/win/scoped_handle.h" | 17 #include "base/win/scoped_handle.h" |
16 #include "base/win/scoped_process_information.h" | 18 #include "base/win/scoped_process_information.h" |
17 #include "ipc/ipc_channel.h" | 19 #include "ipc/ipc_channel.h" |
18 #include "ipc/ipc_channel_proxy.h" | 20 #include "ipc/ipc_channel_proxy.h" |
19 #include "ipc/ipc_listener.h" | 21 #include "ipc/ipc_listener.h" |
20 #include "ipc/ipc_message.h" | 22 #include "ipc/ipc_message.h" |
21 #include "remoting/base/auto_thread_task_runner.h" | 23 #include "remoting/base/auto_thread_task_runner.h" |
22 #include "remoting/host/chromoting_messages.h" | 24 #include "remoting/host/chromoting_messages.h" |
23 #include "remoting/host/host_exit_codes.h" | 25 #include "remoting/host/host_exit_codes.h" |
24 #include "remoting/host/ipc_util.h" | 26 #include "remoting/host/ipc_util.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 329 |
328 void WorkerProcessLauncherTest::StopWorker() { | 330 void WorkerProcessLauncherTest::StopWorker() { |
329 launcher_.reset(); | 331 launcher_.reset(); |
330 DisconnectClient(); | 332 DisconnectClient(); |
331 channel_name_.clear(); | 333 channel_name_.clear(); |
332 channel_server_.reset(); | 334 channel_server_.reset(); |
333 task_runner_ = nullptr; | 335 task_runner_ = nullptr; |
334 } | 336 } |
335 | 337 |
336 void WorkerProcessLauncherTest::QuitMainMessageLoop() { | 338 void WorkerProcessLauncherTest::QuitMainMessageLoop() { |
337 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 339 message_loop_.task_runner()->PostTask( |
| 340 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
338 } | 341 } |
339 | 342 |
340 void WorkerProcessLauncherTest::DoLaunchProcess() { | 343 void WorkerProcessLauncherTest::DoLaunchProcess() { |
341 EXPECT_TRUE(event_handler_); | 344 EXPECT_TRUE(event_handler_); |
342 EXPECT_FALSE(worker_process_.IsValid()); | 345 EXPECT_FALSE(worker_process_.IsValid()); |
343 | 346 |
344 WCHAR notepad[MAX_PATH + 1]; | 347 WCHAR notepad[MAX_PATH + 1]; |
345 ASSERT_GT(ExpandEnvironmentStrings( | 348 ASSERT_GT(ExpandEnvironmentStrings( |
346 L"\045SystemRoot\045\\system32\\notepad.exe", notepad, MAX_PATH), 0u); | 349 L"\045SystemRoot\045\\system32\\notepad.exe", notepad, MAX_PATH), 0u); |
347 | 350 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 .Times(1) | 387 .Times(1) |
385 .WillRepeatedly(Invoke(this, &WorkerProcessLauncherTest::LaunchProcess)); | 388 .WillRepeatedly(Invoke(this, &WorkerProcessLauncherTest::LaunchProcess)); |
386 | 389 |
387 EXPECT_CALL(server_listener_, OnChannelConnected(_)) | 390 EXPECT_CALL(server_listener_, OnChannelConnected(_)) |
388 .Times(0); | 391 .Times(0); |
389 EXPECT_CALL(server_listener_, OnPermanentError(_)) | 392 EXPECT_CALL(server_listener_, OnPermanentError(_)) |
390 .Times(0); | 393 .Times(0); |
391 | 394 |
392 StartWorker(); | 395 StartWorker(); |
393 StopWorker(); | 396 StopWorker(); |
394 message_loop_.Run(); | 397 base::RunLoop().Run(); |
395 } | 398 } |
396 | 399 |
397 // Starts and connects to the worker process. Expect OnChannelConnected to be | 400 // Starts and connects to the worker process. Expect OnChannelConnected to be |
398 // called. | 401 // called. |
399 TEST_F(WorkerProcessLauncherTest, StartAndConnect) { | 402 TEST_F(WorkerProcessLauncherTest, StartAndConnect) { |
400 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) | 403 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) |
401 .Times(1) | 404 .Times(1) |
402 .WillRepeatedly(Invoke( | 405 .WillRepeatedly(Invoke( |
403 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); | 406 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); |
404 | 407 |
405 EXPECT_CALL(server_listener_, OnChannelConnected(_)) | 408 EXPECT_CALL(server_listener_, OnChannelConnected(_)) |
406 .Times(1) | 409 .Times(1) |
407 .WillOnce(InvokeWithoutArgs(this, | 410 .WillOnce(InvokeWithoutArgs(this, |
408 &WorkerProcessLauncherTest::StopWorker)); | 411 &WorkerProcessLauncherTest::StopWorker)); |
409 EXPECT_CALL(server_listener_, OnPermanentError(_)) | 412 EXPECT_CALL(server_listener_, OnPermanentError(_)) |
410 .Times(0); | 413 .Times(0); |
411 | 414 |
412 StartWorker(); | 415 StartWorker(); |
413 message_loop_.Run(); | 416 base::RunLoop().Run(); |
414 } | 417 } |
415 | 418 |
416 // Kills the worker process after the 1st connect and expects it to be | 419 // Kills the worker process after the 1st connect and expects it to be |
417 // restarted. | 420 // restarted. |
418 TEST_F(WorkerProcessLauncherTest, Restart) { | 421 TEST_F(WorkerProcessLauncherTest, Restart) { |
419 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) | 422 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) |
420 .Times(2) | 423 .Times(2) |
421 .WillRepeatedly(Invoke( | 424 .WillRepeatedly(Invoke( |
422 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); | 425 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); |
423 Expectation first_connect = | 426 Expectation first_connect = |
424 EXPECT_CALL(server_listener_, OnChannelConnected(_)) | 427 EXPECT_CALL(server_listener_, OnChannelConnected(_)) |
425 .Times(2) | 428 .Times(2) |
426 .WillOnce(InvokeWithoutArgs(CreateFunctor( | 429 .WillOnce(InvokeWithoutArgs(CreateFunctor( |
427 &WorkerProcessLauncherTest::TerminateWorker, | 430 &WorkerProcessLauncherTest::TerminateWorker, |
428 base::Unretained(this), | 431 base::Unretained(this), |
429 CONTROL_C_EXIT))) | 432 CONTROL_C_EXIT))) |
430 .WillOnce(InvokeWithoutArgs(this, | 433 .WillOnce(InvokeWithoutArgs(this, |
431 &WorkerProcessLauncherTest::StopWorker)); | 434 &WorkerProcessLauncherTest::StopWorker)); |
432 | 435 |
433 EXPECT_CALL(server_listener_, OnPermanentError(_)) | 436 EXPECT_CALL(server_listener_, OnPermanentError(_)) |
434 .Times(0); | 437 .Times(0); |
435 | 438 |
436 StartWorker(); | 439 StartWorker(); |
437 message_loop_.Run(); | 440 base::RunLoop().Run(); |
438 } | 441 } |
439 | 442 |
440 // Drops the IPC channel to the worker process after the 1st connect and expects | 443 // Drops the IPC channel to the worker process after the 1st connect and expects |
441 // the worker process to be restarted. | 444 // the worker process to be restarted. |
442 TEST_F(WorkerProcessLauncherTest, DropIpcChannel) { | 445 TEST_F(WorkerProcessLauncherTest, DropIpcChannel) { |
443 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) | 446 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) |
444 .Times(2) | 447 .Times(2) |
445 .WillRepeatedly(Invoke( | 448 .WillRepeatedly(Invoke( |
446 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); | 449 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); |
447 | 450 |
448 Expectation first_connect = | 451 Expectation first_connect = |
449 EXPECT_CALL(server_listener_, OnChannelConnected(_)) | 452 EXPECT_CALL(server_listener_, OnChannelConnected(_)) |
450 .Times(2) | 453 .Times(2) |
451 .WillOnce(InvokeWithoutArgs( | 454 .WillOnce(InvokeWithoutArgs( |
452 this, &WorkerProcessLauncherTest::DisconnectClient)) | 455 this, &WorkerProcessLauncherTest::DisconnectClient)) |
453 .WillOnce(InvokeWithoutArgs( | 456 .WillOnce(InvokeWithoutArgs( |
454 this, &WorkerProcessLauncherTest::StopWorker)); | 457 this, &WorkerProcessLauncherTest::StopWorker)); |
455 | 458 |
456 EXPECT_CALL(server_listener_, OnPermanentError(_)) | 459 EXPECT_CALL(server_listener_, OnPermanentError(_)) |
457 .Times(0); | 460 .Times(0); |
458 | 461 |
459 StartWorker(); | 462 StartWorker(); |
460 message_loop_.Run(); | 463 base::RunLoop().Run(); |
461 } | 464 } |
462 | 465 |
463 // Returns a permanent error exit code and expects OnPermanentError() to be | 466 // Returns a permanent error exit code and expects OnPermanentError() to be |
464 // invoked. | 467 // invoked. |
465 TEST_F(WorkerProcessLauncherTest, PermanentError) { | 468 TEST_F(WorkerProcessLauncherTest, PermanentError) { |
466 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) | 469 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) |
467 .Times(1) | 470 .Times(1) |
468 .WillRepeatedly(Invoke( | 471 .WillRepeatedly(Invoke( |
469 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); | 472 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); |
470 | 473 |
471 EXPECT_CALL(server_listener_, OnChannelConnected(_)) | 474 EXPECT_CALL(server_listener_, OnChannelConnected(_)) |
472 .Times(1) | 475 .Times(1) |
473 .WillOnce(InvokeWithoutArgs(CreateFunctor( | 476 .WillOnce(InvokeWithoutArgs(CreateFunctor( |
474 &WorkerProcessLauncherTest::TerminateWorker, | 477 &WorkerProcessLauncherTest::TerminateWorker, |
475 base::Unretained(this), | 478 base::Unretained(this), |
476 kMinPermanentErrorExitCode))); | 479 kMinPermanentErrorExitCode))); |
477 EXPECT_CALL(server_listener_, OnPermanentError(_)) | 480 EXPECT_CALL(server_listener_, OnPermanentError(_)) |
478 .Times(1) | 481 .Times(1) |
479 .WillOnce(InvokeWithoutArgs(this, | 482 .WillOnce(InvokeWithoutArgs(this, |
480 &WorkerProcessLauncherTest::StopWorker)); | 483 &WorkerProcessLauncherTest::StopWorker)); |
481 | 484 |
482 StartWorker(); | 485 StartWorker(); |
483 message_loop_.Run(); | 486 base::RunLoop().Run(); |
484 } | 487 } |
485 | 488 |
486 // Requests the worker to crash and expects it to honor the request. | 489 // Requests the worker to crash and expects it to honor the request. |
487 TEST_F(WorkerProcessLauncherTest, Crash) { | 490 TEST_F(WorkerProcessLauncherTest, Crash) { |
488 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) | 491 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) |
489 .Times(2) | 492 .Times(2) |
490 .WillRepeatedly(Invoke( | 493 .WillRepeatedly(Invoke( |
491 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); | 494 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); |
492 | 495 |
493 EXPECT_CALL(server_listener_, OnChannelConnected(_)) | 496 EXPECT_CALL(server_listener_, OnChannelConnected(_)) |
494 .Times(2) | 497 .Times(2) |
495 .WillOnce(InvokeWithoutArgs(this, | 498 .WillOnce(InvokeWithoutArgs(this, |
496 &WorkerProcessLauncherTest::CrashWorker)) | 499 &WorkerProcessLauncherTest::CrashWorker)) |
497 .WillOnce(InvokeWithoutArgs(this, | 500 .WillOnce(InvokeWithoutArgs(this, |
498 &WorkerProcessLauncherTest::StopWorker)); | 501 &WorkerProcessLauncherTest::StopWorker)); |
499 | 502 |
500 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) | 503 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) |
501 .Times(1) | 504 .Times(1) |
502 .WillOnce(InvokeWithoutArgs(CreateFunctor( | 505 .WillOnce(InvokeWithoutArgs(CreateFunctor( |
503 &WorkerProcessLauncherTest::TerminateWorker, | 506 &WorkerProcessLauncherTest::TerminateWorker, |
504 base::Unretained(this), | 507 base::Unretained(this), |
505 EXCEPTION_BREAKPOINT))); | 508 EXCEPTION_BREAKPOINT))); |
506 | 509 |
507 StartWorker(); | 510 StartWorker(); |
508 message_loop_.Run(); | 511 base::RunLoop().Run(); |
509 } | 512 } |
510 | 513 |
511 // Requests the worker to crash and terminates the worker even if it does not | 514 // Requests the worker to crash and terminates the worker even if it does not |
512 // comply. | 515 // comply. |
513 TEST_F(WorkerProcessLauncherTest, CrashAnyway) { | 516 TEST_F(WorkerProcessLauncherTest, CrashAnyway) { |
514 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) | 517 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) |
515 .Times(2) | 518 .Times(2) |
516 .WillRepeatedly(Invoke( | 519 .WillRepeatedly(Invoke( |
517 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); | 520 this, &WorkerProcessLauncherTest::LaunchProcessAndConnect)); |
518 | 521 |
519 EXPECT_CALL(server_listener_, OnChannelConnected(_)) | 522 EXPECT_CALL(server_listener_, OnChannelConnected(_)) |
520 .Times(2) | 523 .Times(2) |
521 .WillOnce(InvokeWithoutArgs(this, | 524 .WillOnce(InvokeWithoutArgs(this, |
522 &WorkerProcessLauncherTest::CrashWorker)) | 525 &WorkerProcessLauncherTest::CrashWorker)) |
523 .WillOnce(InvokeWithoutArgs(this, | 526 .WillOnce(InvokeWithoutArgs(this, |
524 &WorkerProcessLauncherTest::StopWorker)); | 527 &WorkerProcessLauncherTest::StopWorker)); |
525 | 528 |
526 // Ignore the crash request and try send another message to the launcher. | 529 // Ignore the crash request and try send another message to the launcher. |
527 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) | 530 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) |
528 .Times(1) | 531 .Times(1) |
529 .WillOnce(InvokeWithoutArgs( | 532 .WillOnce(InvokeWithoutArgs( |
530 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher)); | 533 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher)); |
531 | 534 |
532 StartWorker(); | 535 StartWorker(); |
533 message_loop_.Run(); | 536 base::RunLoop().Run(); |
534 } | 537 } |
535 | 538 |
536 } // namespace remoting | 539 } // namespace remoting |
OLD | NEW |