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" |
| 6 |
5 #include <stdint.h> | 7 #include <stdint.h> |
6 | 8 |
| 9 #include <utility> |
| 10 |
7 #include "base/bind.h" | 11 #include "base/bind.h" |
8 #include "base/macros.h" | 12 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
11 #include "base/win/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" |
12 #include "base/win/scoped_process_information.h" | 16 #include "base/win/scoped_process_information.h" |
13 #include "ipc/ipc_channel.h" | 17 #include "ipc/ipc_channel.h" |
14 #include "ipc/ipc_channel_proxy.h" | 18 #include "ipc/ipc_channel_proxy.h" |
15 #include "ipc/ipc_listener.h" | 19 #include "ipc/ipc_listener.h" |
16 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
17 #include "remoting/base/auto_thread_task_runner.h" | 21 #include "remoting/base/auto_thread_task_runner.h" |
18 #include "remoting/host/chromoting_messages.h" | 22 #include "remoting/host/chromoting_messages.h" |
19 #include "remoting/host/host_exit_codes.h" | 23 #include "remoting/host/host_exit_codes.h" |
20 #include "remoting/host/ipc_util.h" | 24 #include "remoting/host/ipc_util.h" |
21 #include "remoting/host/win/launch_process_with_token.h" | 25 #include "remoting/host/win/launch_process_with_token.h" |
22 #include "remoting/host/win/worker_process_launcher.h" | |
23 #include "remoting/host/worker_process_ipc_delegate.h" | 26 #include "remoting/host/worker_process_ipc_delegate.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gmock_mutant.h" | 28 #include "testing/gmock_mutant.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
27 | 30 |
28 using base::win::ScopedHandle; | 31 using base::win::ScopedHandle; |
29 using testing::_; | 32 using testing::_; |
30 using testing::AnyNumber; | 33 using testing::AnyNumber; |
31 using testing::CreateFunctor; | 34 using testing::CreateFunctor; |
32 using testing::DoAll; | 35 using testing::DoAll; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 channel_client_->Send( | 312 channel_client_->Send( |
310 new ChromotingDesktopNetworkMsg_DisconnectSession(protocol::OK)); | 313 new ChromotingDesktopNetworkMsg_DisconnectSession(protocol::OK)); |
311 } | 314 } |
312 } | 315 } |
313 | 316 |
314 void WorkerProcessLauncherTest::CrashWorker() { | 317 void WorkerProcessLauncherTest::CrashWorker() { |
315 launcher_->Crash(FROM_HERE); | 318 launcher_->Crash(FROM_HERE); |
316 } | 319 } |
317 | 320 |
318 void WorkerProcessLauncherTest::StartWorker() { | 321 void WorkerProcessLauncherTest::StartWorker() { |
319 launcher_.reset(new WorkerProcessLauncher( | 322 launcher_.reset(new WorkerProcessLauncher(std::move(launcher_delegate_), |
320 launcher_delegate_.Pass(), | 323 &server_listener_)); |
321 &server_listener_)); | |
322 | 324 |
323 launcher_->SetKillProcessTimeoutForTest(base::TimeDelta::FromMilliseconds(0)); | 325 launcher_->SetKillProcessTimeoutForTest(base::TimeDelta::FromMilliseconds(0)); |
324 } | 326 } |
325 | 327 |
326 void WorkerProcessLauncherTest::StopWorker() { | 328 void WorkerProcessLauncherTest::StopWorker() { |
327 launcher_.reset(); | 329 launcher_.reset(); |
328 DisconnectClient(); | 330 DisconnectClient(); |
329 channel_name_.clear(); | 331 channel_name_.clear(); |
330 channel_server_.reset(); | 332 channel_server_.reset(); |
331 task_runner_ = nullptr; | 333 task_runner_ = nullptr; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 channel_name_ = IPC::Channel::GenerateUniqueRandomChannelID(); | 366 channel_name_ = IPC::Channel::GenerateUniqueRandomChannelID(); |
365 ScopedHandle pipe; | 367 ScopedHandle pipe; |
366 ASSERT_TRUE(CreateIpcChannel(channel_name_, kIpcSecurityDescriptor, &pipe)); | 368 ASSERT_TRUE(CreateIpcChannel(channel_name_, kIpcSecurityDescriptor, &pipe)); |
367 | 369 |
368 // Wrap the pipe into an IPC channel. | 370 // Wrap the pipe into an IPC channel. |
369 channel_server_ = IPC::ChannelProxy::Create( | 371 channel_server_ = IPC::ChannelProxy::Create( |
370 IPC::ChannelHandle(pipe.Get()), IPC::Channel::MODE_SERVER, this, | 372 IPC::ChannelHandle(pipe.Get()), IPC::Channel::MODE_SERVER, this, |
371 task_runner_); | 373 task_runner_); |
372 | 374 |
373 HANDLE temp_handle; | 375 HANDLE temp_handle; |
374 ASSERT_TRUE(DuplicateHandle(GetCurrentProcess(), | 376 ASSERT_TRUE(DuplicateHandle(GetCurrentProcess(), worker_process_.Get(), |
375 worker_process_.Get(), | 377 GetCurrentProcess(), &temp_handle, 0, FALSE, |
376 GetCurrentProcess(), | |
377 &temp_handle, | |
378 0, | |
379 FALSE, | |
380 DUPLICATE_SAME_ACCESS)); | 378 DUPLICATE_SAME_ACCESS)); |
381 ScopedHandle copy(temp_handle); | 379 event_handler_->OnProcessLaunched(ScopedHandle(temp_handle)); |
382 | |
383 event_handler_->OnProcessLaunched(copy.Pass()); | |
384 } | 380 } |
385 | 381 |
386 TEST_F(WorkerProcessLauncherTest, Start) { | 382 TEST_F(WorkerProcessLauncherTest, Start) { |
387 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) | 383 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) |
388 .Times(1) | 384 .Times(1) |
389 .WillRepeatedly(Invoke(this, &WorkerProcessLauncherTest::LaunchProcess)); | 385 .WillRepeatedly(Invoke(this, &WorkerProcessLauncherTest::LaunchProcess)); |
390 | 386 |
391 EXPECT_CALL(server_listener_, OnChannelConnected(_)) | 387 EXPECT_CALL(server_listener_, OnChannelConnected(_)) |
392 .Times(0); | 388 .Times(0); |
393 EXPECT_CALL(server_listener_, OnPermanentError(_)) | 389 EXPECT_CALL(server_listener_, OnPermanentError(_)) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) | 524 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) |
529 .Times(1) | 525 .Times(1) |
530 .WillOnce(InvokeWithoutArgs( | 526 .WillOnce(InvokeWithoutArgs( |
531 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher)); | 527 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher)); |
532 | 528 |
533 StartWorker(); | 529 StartWorker(); |
534 message_loop_.Run(); | 530 message_loop_.Run(); |
535 } | 531 } |
536 | 532 |
537 } // namespace remoting | 533 } // namespace remoting |
OLD | NEW |