| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/win/scoped_handle.h" | 9 #include "base/win/scoped_handle.h" |
| 10 #include "ipc/ipc_channel.h" | 10 #include "ipc/ipc_channel.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // Starts the worker. | 137 // Starts the worker. |
| 138 void StartWorker(); | 138 void StartWorker(); |
| 139 | 139 |
| 140 // Stops the worker. | 140 // Stops the worker. |
| 141 void StopWorker(); | 141 void StopWorker(); |
| 142 | 142 |
| 143 // Quits |message_loop_|. | 143 // Quits |message_loop_|. |
| 144 void QuitMainMessageLoop(); | 144 void QuitMainMessageLoop(); |
| 145 | 145 |
| 146 protected: | 146 protected: |
| 147 MessageLoop message_loop_; | 147 base::MessageLoop message_loop_; |
| 148 scoped_refptr<AutoThreadTaskRunner> task_runner_; | 148 scoped_refptr<AutoThreadTaskRunner> task_runner_; |
| 149 | 149 |
| 150 // Receives messages sent to the worker process. | 150 // Receives messages sent to the worker process. |
| 151 MockWorkerListener client_listener_; | 151 MockWorkerListener client_listener_; |
| 152 | 152 |
| 153 // Receives messages sent from the worker process. | 153 // Receives messages sent from the worker process. |
| 154 MockIpcDelegate server_listener_; | 154 MockIpcDelegate server_listener_; |
| 155 | 155 |
| 156 // Implements WorkerProcessLauncher::Delegate. | 156 // Implements WorkerProcessLauncher::Delegate. |
| 157 scoped_ptr<MockProcessLauncherDelegate> launcher_delegate_; | 157 scoped_ptr<MockProcessLauncherDelegate> launcher_delegate_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 169 // The worker process launcher. | 169 // The worker process launcher. |
| 170 scoped_ptr<WorkerProcessLauncher> launcher_; | 170 scoped_ptr<WorkerProcessLauncher> launcher_; |
| 171 | 171 |
| 172 // The event signalling termination of the worker process. | 172 // The event signalling termination of the worker process. |
| 173 ScopedHandle process_exit_event_; | 173 ScopedHandle process_exit_event_; |
| 174 | 174 |
| 175 // True if a permanent error condition should be emulated. | 175 // True if a permanent error condition should be emulated. |
| 176 bool permanent_error_; | 176 bool permanent_error_; |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 | |
| 180 WorkerProcessLauncherTest::WorkerProcessLauncherTest() | 179 WorkerProcessLauncherTest::WorkerProcessLauncherTest() |
| 181 : message_loop_(MessageLoop::TYPE_IO), | 180 : message_loop_(base::MessageLoop::TYPE_IO), |
| 182 client_pid_(GetCurrentProcessId()), | 181 client_pid_(GetCurrentProcessId()), |
| 183 permanent_error_(false) { | 182 permanent_error_(false) {} |
| 184 } | |
| 185 | 183 |
| 186 WorkerProcessLauncherTest::~WorkerProcessLauncherTest() { | 184 WorkerProcessLauncherTest::~WorkerProcessLauncherTest() { |
| 187 } | 185 } |
| 188 | 186 |
| 189 void WorkerProcessLauncherTest::SetUp() { | 187 void WorkerProcessLauncherTest::SetUp() { |
| 190 task_runner_ = new AutoThreadTaskRunner( | 188 task_runner_ = new AutoThreadTaskRunner( |
| 191 message_loop_.message_loop_proxy(), | 189 message_loop_.message_loop_proxy(), |
| 192 base::Bind(&WorkerProcessLauncherTest::QuitMainMessageLoop, | 190 base::Bind(&WorkerProcessLauncherTest::QuitMainMessageLoop, |
| 193 base::Unretained(this))); | 191 base::Unretained(this))); |
| 194 | 192 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 321 |
| 324 void WorkerProcessLauncherTest::StopWorker() { | 322 void WorkerProcessLauncherTest::StopWorker() { |
| 325 launcher_.reset(); | 323 launcher_.reset(); |
| 326 DisconnectClient(); | 324 DisconnectClient(); |
| 327 channel_name_.clear(); | 325 channel_name_.clear(); |
| 328 channel_server_.reset(); | 326 channel_server_.reset(); |
| 329 task_runner_ = NULL; | 327 task_runner_ = NULL; |
| 330 } | 328 } |
| 331 | 329 |
| 332 void WorkerProcessLauncherTest::QuitMainMessageLoop() { | 330 void WorkerProcessLauncherTest::QuitMainMessageLoop() { |
| 333 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 331 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
| 334 } | 332 } |
| 335 | 333 |
| 336 TEST_F(WorkerProcessLauncherTest, Start) { | 334 TEST_F(WorkerProcessLauncherTest, Start) { |
| 337 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_, _)) | 335 EXPECT_CALL(*launcher_delegate_, LaunchProcess(_, _)) |
| 338 .Times(1) | 336 .Times(1) |
| 339 .WillRepeatedly(Invoke(this, &WorkerProcessLauncherTest::LaunchProcess)); | 337 .WillRepeatedly(Invoke(this, &WorkerProcessLauncherTest::LaunchProcess)); |
| 340 | 338 |
| 341 EXPECT_CALL(server_listener_, OnChannelConnected(_)) | 339 EXPECT_CALL(server_listener_, OnChannelConnected(_)) |
| 342 .Times(0); | 340 .Times(0); |
| 343 EXPECT_CALL(server_listener_, OnPermanentError()) | 341 EXPECT_CALL(server_listener_, OnPermanentError()) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) | 494 EXPECT_CALL(client_listener_, OnCrash(_, _, _)) |
| 497 .Times(1) | 495 .Times(1) |
| 498 .WillOnce(InvokeWithoutArgs( | 496 .WillOnce(InvokeWithoutArgs( |
| 499 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher)); | 497 this, &WorkerProcessLauncherTest::SendFakeMessageToLauncher)); |
| 500 | 498 |
| 501 StartWorker(); | 499 StartWorker(); |
| 502 message_loop_.Run(); | 500 message_loop_.Run(); |
| 503 } | 501 } |
| 504 | 502 |
| 505 } // namespace remoting | 503 } // namespace remoting |
| OLD | NEW |