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

Side by Side Diff: remoting/host/chromoting_host_unittest.cc

Issue 11778049: Making DesktopEnvironment a factory class used by ClientSession to create audio/video capturers and… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/client_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "remoting/base/auto_thread_task_runner.h" 9 #include "remoting/base/auto_thread_task_runner.h"
10 #include "remoting/capturer/video_frame_capturer_fake.h" 10 #include "remoting/capturer/video_frame_capturer_fake.h"
11 #include "remoting/host/audio_capturer.h" 11 #include "remoting/host/audio_capturer.h"
12 #include "remoting/host/chromoting_host.h" 12 #include "remoting/host/chromoting_host.h"
13 #include "remoting/host/chromoting_host_context.h" 13 #include "remoting/host/chromoting_host_context.h"
14 #include "remoting/host/desktop_environment.h" 14 #include "remoting/host/desktop_environment.h"
15 #include "remoting/host/desktop_environment_factory.h"
16 #include "remoting/host/event_executor_fake.h"
17 #include "remoting/host/host_mock_objects.h" 15 #include "remoting/host/host_mock_objects.h"
18 #include "remoting/host/it2me_host_user_interface.h" 16 #include "remoting/host/it2me_host_user_interface.h"
19 #include "remoting/jingle_glue/mock_objects.h" 17 #include "remoting/jingle_glue/mock_objects.h"
20 #include "remoting/proto/video.pb.h" 18 #include "remoting/proto/video.pb.h"
21 #include "remoting/protocol/errors.h" 19 #include "remoting/protocol/errors.h"
22 #include "remoting/protocol/protocol_mock_objects.h" 20 #include "remoting/protocol/protocol_mock_objects.h"
23 #include "remoting/protocol/session_config.h" 21 #include "remoting/protocol/session_config.h"
24 #include "testing/gmock_mutant.h" 22 #include "testing/gmock_mutant.h"
25 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 ui_task_runner_ = new AutoThreadTaskRunner( 114 ui_task_runner_ = new AutoThreadTaskRunner(
117 message_loop_.message_loop_proxy(), 115 message_loop_.message_loop_proxy(),
118 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, 116 base::Bind(&ChromotingHostTest::QuitMainMessageLoop,
119 base::Unretained(this))); 117 base::Unretained(this)));
120 118
121 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); 119 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
122 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) 120 EXPECT_CALL(*desktop_environment_factory_, CreatePtr())
123 .Times(AnyNumber()) 121 .Times(AnyNumber())
124 .WillRepeatedly(Invoke(this, 122 .WillRepeatedly(Invoke(this,
125 &ChromotingHostTest::CreateDesktopEnvironment)); 123 &ChromotingHostTest::CreateDesktopEnvironment));
124 EXPECT_CALL(*desktop_environment_factory_, SupportsAudioCapture())
125 .Times(AnyNumber())
126 .WillRepeatedly(Return(false));
126 127
127 session_manager_ = new protocol::MockSessionManager(); 128 session_manager_ = new protocol::MockSessionManager();
128 129
129 host_ = new ChromotingHost( 130 host_ = new ChromotingHost(
130 &signal_strategy_, 131 &signal_strategy_,
131 desktop_environment_factory_.get(), 132 desktop_environment_factory_.get(),
132 scoped_ptr<protocol::SessionManager>(session_manager_), 133 scoped_ptr<protocol::SessionManager>(session_manager_),
133 ui_task_runner_, // Audio 134 ui_task_runner_, // Audio
135 ui_task_runner_, // Input
134 ui_task_runner_, // Video capture 136 ui_task_runner_, // Video capture
135 ui_task_runner_, // Video encode 137 ui_task_runner_, // Video encode
136 ui_task_runner_); // Network 138 ui_task_runner_, // Network
139 ui_task_runner_); // UI
137 host_->AddStatusObserver(&host_status_observer_); 140 host_->AddStatusObserver(&host_status_observer_);
138 141
139 disconnect_window_ = new MockDisconnectWindow(); 142 disconnect_window_ = new MockDisconnectWindow();
140 continue_window_ = new MockContinueWindow(); 143 continue_window_ = new MockContinueWindow();
141 local_input_monitor_ = new MockLocalInputMonitor(); 144 local_input_monitor_ = new MockLocalInputMonitor();
142 it2me_host_user_interface_.reset( 145 it2me_host_user_interface_.reset(
143 new MockIt2MeHostUserInterface(ui_task_runner_, ui_task_runner_)); 146 new MockIt2MeHostUserInterface(ui_task_runner_, ui_task_runner_));
144 it2me_host_user_interface_->InitFrom( 147 it2me_host_user_interface_->InitFrom(
145 scoped_ptr<DisconnectWindow>(disconnect_window_), 148 scoped_ptr<DisconnectWindow>(disconnect_window_),
146 scoped_ptr<ContinueWindow>(continue_window_), 149 scoped_ptr<ContinueWindow>(continue_window_),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // Helper method to pretend a client is connected to ChromotingHost. 233 // Helper method to pretend a client is connected to ChromotingHost.
231 void SimulateClientConnection(int connection_index, bool authenticate, 234 void SimulateClientConnection(int connection_index, bool authenticate,
232 bool reject) { 235 bool reject) {
233 scoped_ptr<protocol::ConnectionToClient> connection = 236 scoped_ptr<protocol::ConnectionToClient> connection =
234 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). 237 ((connection_index == 0) ? owned_connection1_ : owned_connection2_).
235 PassAs<protocol::ConnectionToClient>(); 238 PassAs<protocol::ConnectionToClient>();
236 protocol::ConnectionToClient* connection_ptr = connection.get(); 239 protocol::ConnectionToClient* connection_ptr = connection.get();
237 scoped_refptr<ClientSession> client = new ClientSession( 240 scoped_refptr<ClientSession> client = new ClientSession(
238 host_.get(), 241 host_.get(),
239 ui_task_runner_, // Audio 242 ui_task_runner_, // Audio
243 ui_task_runner_, // Input
240 ui_task_runner_, // Video capture 244 ui_task_runner_, // Video capture
241 ui_task_runner_, // Video encode 245 ui_task_runner_, // Video encode
242 ui_task_runner_, // Network 246 ui_task_runner_, // Network
247 ui_task_runner_, // UI
243 connection.Pass(), 248 connection.Pass(),
244 desktop_environment_factory_.get(), 249 desktop_environment_factory_.get(),
245 base::TimeDelta()); 250 base::TimeDelta());
246 connection_ptr->set_host_stub(client); 251 connection_ptr->set_host_stub(client);
247 252
248 ui_task_runner_->PostTask( 253 ui_task_runner_->PostTask(
249 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, 254 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost,
250 host_, client)); 255 host_, client));
251 256
252 if (authenticate) { 257 if (authenticate) {
(...skipping 20 matching lines...) Expand all
273 // Make sure that the host has been properly deleted. 278 // Make sure that the host has been properly deleted.
274 DCHECK(host_.get() == NULL); 279 DCHECK(host_.get() == NULL);
275 } 280 }
276 281
277 // Change the session route for |client1_|. 282 // Change the session route for |client1_|.
278 void ChangeSessionRoute(const std::string& channel_name, 283 void ChangeSessionRoute(const std::string& channel_name,
279 const protocol::TransportRoute& route) { 284 const protocol::TransportRoute& route) {
280 host_->OnSessionRouteChange(get_client(0), channel_name, route); 285 host_->OnSessionRouteChange(get_client(0), channel_name, route);
281 } 286 }
282 287
288 // Creates a DesktopEnvironment with a fake VideoFrameCapturer, to mock
289 // DesktopEnvironmentFactory::Create().
283 DesktopEnvironment* CreateDesktopEnvironment() { 290 DesktopEnvironment* CreateDesktopEnvironment() {
284 scoped_ptr<EventExecutor> event_executor(new EventExecutorFake()); 291 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment();
285 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake()); 292 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr(_))
286 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL), 293 .Times(0);
287 event_executor.Pass(), 294 EXPECT_CALL(*desktop_environment, CreateEventExecutorPtr(_, _))
288 video_capturer.Pass()); 295 .Times(AnyNumber())
296 .WillRepeatedly(Invoke(this, &ChromotingHostTest::CreateEventExecutor));
297 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _))
298 .Times(AnyNumber())
299 .WillRepeatedly(Invoke(this, &ChromotingHostTest::CreateVideoCapturer));
300
301 return desktop_environment;
302 }
303
304 // Creates a dummy EventExecutor, to mock
305 // DesktopEnvironment::CreateEventExecutor().
306 EventExecutor* CreateEventExecutor(
307 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
308 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
309 MockEventExecutor* event_executor = new MockEventExecutor();
310 EXPECT_CALL(*event_executor, StartPtr(_));
311 return event_executor;
312 }
313
314 // Creates a fake VideoFrameCapturer, to mock
315 // DesktopEnvironment::CreateVideoCapturer().
316 VideoFrameCapturer* CreateVideoCapturer(
317 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
318 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) {
319 return new VideoFrameCapturerFake();
289 } 320 }
290 321
291 void DisconnectAllClients() { 322 void DisconnectAllClients() {
292 host_->DisconnectAllClients(); 323 host_->DisconnectAllClients();
293 } 324 }
294 325
295 // Helper method to disconnect client 1 from the host. 326 // Helper method to disconnect client 1 from the host.
296 void DisconnectClient1() { 327 void DisconnectClient1() {
297 NotifyClientSessionClosed(0); 328 NotifyClientSessionClosed(0);
298 } 329 }
(...skipping 15 matching lines...) Expand all
314 345
315 void NotifyConnectionClosed() { 346 void NotifyConnectionClosed() {
316 if (session_event_handler_) { 347 if (session_event_handler_) {
317 session_event_handler_->OnSessionStateChange(protocol::Session::CLOSED); 348 session_event_handler_->OnSessionStateChange(protocol::Session::CLOSED);
318 } 349 }
319 } 350 }
320 351
321 static void AddClientToHost(scoped_refptr<ChromotingHost> host, 352 static void AddClientToHost(scoped_refptr<ChromotingHost> host,
322 ClientSession* session) { 353 ClientSession* session) {
323 host->clients_.push_back(session); 354 host->clients_.push_back(session);
324 host->clients_count_++;
325 } 355 }
326 356
327 void ShutdownHost() { 357 void ShutdownHost() {
328 ui_task_runner_->PostTask( 358 ui_task_runner_->PostTask(
329 FROM_HERE, 359 FROM_HERE,
330 base::Bind(&ChromotingHost::Shutdown, host_, 360 base::Bind(&ChromotingHost::Shutdown, host_,
331 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner, 361 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner,
332 base::Unretained(this)))); 362 base::Unretained(this))));
333 } 363 }
334 364
335 void ReleaseUiTaskRunner() { 365 void ReleaseUiTaskRunner() {
336 it2me_host_user_interface_.reset(); 366 it2me_host_user_interface_.reset();
337 ui_task_runner_ = NULL; 367 ui_task_runner_ = NULL;
338 host_ = NULL; 368 host_ = NULL;
369 desktop_environment_factory_.reset();
339 } 370 }
340 371
341 void QuitMainMessageLoop() { 372 void QuitMainMessageLoop() {
342 PostQuitTask(&message_loop_); 373 PostQuitTask(&message_loop_);
343 } 374 }
344 375
345 // Expect the host to start. 376 // Expect the host to start.
346 void ExpectHostStart() { 377 void ExpectHostStart() {
347 EXPECT_CALL(*disconnect_window_, Hide()); 378 EXPECT_CALL(*disconnect_window_, Hide());
348 EXPECT_CALL(*continue_window_, Hide()); 379 EXPECT_CALL(*continue_window_, Hide());
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 ExpectClientDisconnected(0, true, video_packet_sent, 719 ExpectClientDisconnected(0, true, video_packet_sent,
689 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 720 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
690 EXPECT_CALL(host_status_observer_, OnShutdown()); 721 EXPECT_CALL(host_status_observer_, OnShutdown());
691 722
692 host_->Start(xmpp_login_); 723 host_->Start(xmpp_login_);
693 SimulateClientConnection(0, true, false); 724 SimulateClientConnection(0, true, false);
694 message_loop_.Run(); 725 message_loop_.Run();
695 } 726 }
696 727
697 } // namespace remoting 728 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/client_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698