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

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

Issue 2424353002: Use ChannelMojo between the remoting daemon and network processes. (Closed)
Patch Set: Created 4 years, 2 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
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" 15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/win/scoped_handle.h" 17 #include "base/win/scoped_handle.h"
18 #include "base/win/scoped_process_information.h" 18 #include "base/win/scoped_process_information.h"
19 #include "ipc/ipc_channel.h" 19 #include "ipc/ipc_channel.h"
20 #include "ipc/ipc_channel_proxy.h" 20 #include "ipc/ipc_channel_proxy.h"
21 #include "ipc/ipc_listener.h" 21 #include "ipc/ipc_listener.h"
22 #include "ipc/ipc_message.h" 22 #include "ipc/ipc_message.h"
23 #include "remoting/base/auto_thread_task_runner.h" 23 #include "remoting/base/auto_thread_task_runner.h"
24 #include "remoting/host/chromoting_messages.h" 24 #include "remoting/host/chromoting_messages.h"
25 #include "remoting/host/host_exit_codes.h" 25 #include "remoting/host/host_exit_codes.h"
26 #include "remoting/host/ipc_util.h"
27 #include "remoting/host/win/launch_process_with_token.h" 26 #include "remoting/host/win/launch_process_with_token.h"
28 #include "remoting/host/worker_process_ipc_delegate.h" 27 #include "remoting/host/worker_process_ipc_delegate.h"
29 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gmock_mutant.h" 29 #include "testing/gmock_mutant.h"
31 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
32 31
33 using base::win::ScopedHandle; 32 using base::win::ScopedHandle;
34 using testing::_; 33 using testing::_;
35 using testing::AnyNumber; 34 using testing::AnyNumber;
36 using testing::CreateFunctor; 35 using testing::CreateFunctor;
37 using testing::DoAll; 36 using testing::DoAll;
38 using testing::Expectation; 37 using testing::Expectation;
39 using testing::Invoke; 38 using testing::Invoke;
40 using testing::InvokeWithoutArgs; 39 using testing::InvokeWithoutArgs;
41 using testing::Return; 40 using testing::Return;
42 41
43 namespace remoting { 42 namespace remoting {
44 43
45 namespace { 44 namespace {
46 45
47 const char kIpcSecurityDescriptor[] = "D:(A;;GA;;;AU)";
joedow 2016/10/20 17:40:04 How is the Mojo pipe secured? Is there a default
Sam McNally 2016/10/20 22:40:22 For pipes to be passed through handle inheritance
48
49 class MockProcessLauncherDelegate : public WorkerProcessLauncher::Delegate { 46 class MockProcessLauncherDelegate : public WorkerProcessLauncher::Delegate {
50 public: 47 public:
51 MockProcessLauncherDelegate() {} 48 MockProcessLauncherDelegate() {}
52 ~MockProcessLauncherDelegate() override {} 49 ~MockProcessLauncherDelegate() override {}
53 50
54 // WorkerProcessLauncher::Delegate interface. 51 // WorkerProcessLauncher::Delegate interface.
55 MOCK_METHOD1(LaunchProcess, void(WorkerProcessLauncher*)); 52 MOCK_METHOD1(LaunchProcess, void(WorkerProcessLauncher*));
56 MOCK_METHOD1(Send, void(IPC::Message*)); 53 MOCK_METHOD1(Send, void(IPC::Message*));
57 MOCK_METHOD0(CloseChannel, void()); 54 MOCK_METHOD0(CloseChannel, void());
58 MOCK_METHOD0(KillProcess, void()); 55 MOCK_METHOD0(KillProcess, void());
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 161
165 // Receives messages sent to the worker process. 162 // Receives messages sent to the worker process.
166 MockWorkerListener client_listener_; 163 MockWorkerListener client_listener_;
167 164
168 // Receives messages sent from the worker process. 165 // Receives messages sent from the worker process.
169 MockIpcDelegate server_listener_; 166 MockIpcDelegate server_listener_;
170 167
171 // Implements WorkerProcessLauncher::Delegate. 168 // Implements WorkerProcessLauncher::Delegate.
172 std::unique_ptr<MockProcessLauncherDelegate> launcher_delegate_; 169 std::unique_ptr<MockProcessLauncherDelegate> launcher_delegate_;
173 170
174 // The name of the IPC channel. 171 // The client handle to the channel.
175 std::string channel_name_; 172 mojo::ScopedMessagePipeHandle client_channel_handle_;
176 173
177 // Client and server ends of the IPC channel. 174 // Client and server ends of the IPC channel.
178 std::unique_ptr<IPC::ChannelProxy> channel_client_; 175 std::unique_ptr<IPC::ChannelProxy> channel_client_;
179 std::unique_ptr<IPC::ChannelProxy> channel_server_; 176 std::unique_ptr<IPC::ChannelProxy> channel_server_;
180 177
181 WorkerProcessLauncher* event_handler_; 178 WorkerProcessLauncher* event_handler_;
182 179
183 // The worker process launcher. 180 // The worker process launcher.
184 std::unique_ptr<WorkerProcessLauncher> launcher_; 181 std::unique_ptr<WorkerProcessLauncher> launcher_;
185 182
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 worker_process_.Close(); 271 worker_process_.Close();
275 } 272 }
276 } 273 }
277 274
278 void WorkerProcessLauncherTest::TerminateWorker(DWORD exit_code) { 275 void WorkerProcessLauncherTest::TerminateWorker(DWORD exit_code) {
279 if (worker_process_.IsValid()) 276 if (worker_process_.IsValid())
280 TerminateProcess(worker_process_.Get(), exit_code); 277 TerminateProcess(worker_process_.Get(), exit_code);
281 } 278 }
282 279
283 void WorkerProcessLauncherTest::ConnectClient() { 280 void WorkerProcessLauncherTest::ConnectClient() {
284 channel_client_ = IPC::ChannelProxy::Create(IPC::ChannelHandle(channel_name_), 281 channel_client_ = IPC::ChannelProxy::Create(client_channel_handle_.release(),
285 IPC::Channel::MODE_CLIENT, 282 IPC::Channel::MODE_CLIENT,
286 &client_listener_, 283 &client_listener_, task_runner_);
287 task_runner_);
288 284
289 // Pretend that |kLaunchSuccessTimeoutSeconds| passed since launching 285 // Pretend that |kLaunchSuccessTimeoutSeconds| passed since launching
290 // the worker process. This will make the backoff algorithm think that this 286 // the worker process. This will make the backoff algorithm think that this
291 // launch attempt was successful and it will not delay the next launch. 287 // launch attempt was successful and it will not delay the next launch.
292 launcher_->RecordSuccessfulLaunchForTest(); 288 launcher_->RecordSuccessfulLaunchForTest();
293 } 289 }
294 290
295 void WorkerProcessLauncherTest::DisconnectClient() { 291 void WorkerProcessLauncherTest::DisconnectClient() {
296 channel_client_.reset(); 292 channel_client_.reset();
297 } 293 }
(...skipping 25 matching lines...) Expand all
323 void WorkerProcessLauncherTest::StartWorker() { 319 void WorkerProcessLauncherTest::StartWorker() {
324 launcher_.reset(new WorkerProcessLauncher(std::move(launcher_delegate_), 320 launcher_.reset(new WorkerProcessLauncher(std::move(launcher_delegate_),
325 &server_listener_)); 321 &server_listener_));
326 322
327 launcher_->SetKillProcessTimeoutForTest(base::TimeDelta::FromMilliseconds(0)); 323 launcher_->SetKillProcessTimeoutForTest(base::TimeDelta::FromMilliseconds(0));
328 } 324 }
329 325
330 void WorkerProcessLauncherTest::StopWorker() { 326 void WorkerProcessLauncherTest::StopWorker() {
331 launcher_.reset(); 327 launcher_.reset();
332 DisconnectClient(); 328 DisconnectClient();
333 channel_name_.clear(); 329 client_channel_handle_.reset();
334 channel_server_.reset(); 330 channel_server_.reset();
335 task_runner_ = nullptr; 331 task_runner_ = nullptr;
336 } 332 }
337 333
338 void WorkerProcessLauncherTest::QuitMainMessageLoop() { 334 void WorkerProcessLauncherTest::QuitMainMessageLoop() {
339 message_loop_.task_runner()->PostTask( 335 message_loop_.task_runner()->PostTask(
340 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 336 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
341 } 337 }
342 338
343 void WorkerProcessLauncherTest::DoLaunchProcess() { 339 void WorkerProcessLauncherTest::DoLaunchProcess() {
(...skipping 15 matching lines...) Expand all
359 FALSE, // do not inherit handles 355 FALSE, // do not inherit handles
360 CREATE_SUSPENDED, 356 CREATE_SUSPENDED,
361 nullptr, // no environment 357 nullptr, // no environment
362 nullptr, // default current directory 358 nullptr, // default current directory
363 &startup_info, 359 &startup_info,
364 &temp_process_info)); 360 &temp_process_info));
365 base::win::ScopedProcessInformation process_information(temp_process_info); 361 base::win::ScopedProcessInformation process_information(temp_process_info);
366 worker_process_.Set(process_information.TakeProcessHandle()); 362 worker_process_.Set(process_information.TakeProcessHandle());
367 ASSERT_TRUE(worker_process_.IsValid()); 363 ASSERT_TRUE(worker_process_.IsValid());
368 364
369 channel_name_ = IPC::Channel::GenerateUniqueRandomChannelID(); 365 mojo::MessagePipe pipe;
370 ScopedHandle pipe; 366 client_channel_handle_ = std::move(pipe.handle0);
371 ASSERT_TRUE(CreateIpcChannel(channel_name_, kIpcSecurityDescriptor, &pipe));
372 367
373 // Wrap the pipe into an IPC channel. 368 // Wrap the pipe into an IPC channel.
374 channel_server_ = IPC::ChannelProxy::Create( 369 channel_server_ = IPC::ChannelProxy::Create(
375 IPC::ChannelHandle(pipe.Get()), IPC::Channel::MODE_SERVER, this, 370 pipe.handle1.release(), IPC::Channel::MODE_SERVER, this, task_runner_);
376 task_runner_);
377 371
378 HANDLE temp_handle; 372 HANDLE temp_handle;
379 ASSERT_TRUE(DuplicateHandle(GetCurrentProcess(), worker_process_.Get(), 373 ASSERT_TRUE(DuplicateHandle(GetCurrentProcess(), worker_process_.Get(),
380 GetCurrentProcess(), &temp_handle, 0, FALSE, 374 GetCurrentProcess(), &temp_handle, 0, FALSE,
381 DUPLICATE_SAME_ACCESS)); 375 DUPLICATE_SAME_ACCESS));
382 event_handler_->OnProcessLaunched(ScopedHandle(temp_handle)); 376 event_handler_->OnProcessLaunched(ScopedHandle(temp_handle));
383 } 377 }
384 378
385 TEST_F(WorkerProcessLauncherTest, Start) { 379 TEST_F(WorkerProcessLauncherTest, Start) {
386 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_)) 380 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_))
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) 524 EXPECT_CALL(client_listener_, OnCrash(_, _, _))
531 .Times(1) 525 .Times(1)
532 .WillOnce(InvokeWithoutArgs( 526 .WillOnce(InvokeWithoutArgs(
533 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher)); 527 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher));
534 528
535 StartWorker(); 529 StartWorker();
536 base::RunLoop().Run(); 530 base::RunLoop().Run();
537 } 531 }
538 532
539 } // namespace remoting 533 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698