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

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

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

Powered by Google App Engine
This is Rietveld 408576698