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

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
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"
15 #include "remoting/host/desktop_environment_factory.h" 14 #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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 public: 109 public:
112 ChromotingHostTest() { 110 ChromotingHostTest() {
113 } 111 }
114 112
115 virtual void SetUp() OVERRIDE { 113 virtual void SetUp() OVERRIDE {
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(
120 new MockDesktopEnvironmentFactory(ui_task_runner_));
122 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) 121 EXPECT_CALL(*desktop_environment_factory_, CreatePtr())
123 .Times(AnyNumber()) 122 .Times(AnyNumber())
124 .WillRepeatedly(Invoke(this, 123 .WillRepeatedly(Invoke(this,
125 &ChromotingHostTest::CreateDesktopEnvironment)); 124 &ChromotingHostTest::CreateDesktopEnvironment));
126 125
127 session_manager_ = new protocol::MockSessionManager(); 126 session_manager_ = new protocol::MockSessionManager();
128 127
129 host_ = new ChromotingHost( 128 host_ = new ChromotingHost(
130 &signal_strategy_, 129 &signal_strategy_,
131 desktop_environment_factory_.get(), 130 desktop_environment_factory_.get(),
132 scoped_ptr<protocol::SessionManager>(session_manager_), 131 scoped_ptr<protocol::SessionManager>(session_manager_),
133 ui_task_runner_, // Audio 132 ui_task_runner_, // Audio
133 ui_task_runner_, // Input
134 ui_task_runner_, // Video capture 134 ui_task_runner_, // Video capture
135 ui_task_runner_, // Video encode 135 ui_task_runner_, // Video encode
136 ui_task_runner_); // Network 136 ui_task_runner_, // Network
137 ui_task_runner_); // UI
137 host_->AddStatusObserver(&host_status_observer_); 138 host_->AddStatusObserver(&host_status_observer_);
138 139
139 disconnect_window_ = new MockDisconnectWindow(); 140 disconnect_window_ = new MockDisconnectWindow();
140 continue_window_ = new MockContinueWindow(); 141 continue_window_ = new MockContinueWindow();
141 local_input_monitor_ = new MockLocalInputMonitor(); 142 local_input_monitor_ = new MockLocalInputMonitor();
142 it2me_host_user_interface_.reset( 143 it2me_host_user_interface_.reset(
143 new MockIt2MeHostUserInterface(ui_task_runner_, ui_task_runner_)); 144 new MockIt2MeHostUserInterface(ui_task_runner_, ui_task_runner_));
144 it2me_host_user_interface_->InitFrom( 145 it2me_host_user_interface_->InitFrom(
145 scoped_ptr<DisconnectWindow>(disconnect_window_), 146 scoped_ptr<DisconnectWindow>(disconnect_window_),
146 scoped_ptr<ContinueWindow>(continue_window_), 147 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. 231 // Helper method to pretend a client is connected to ChromotingHost.
231 void SimulateClientConnection(int connection_index, bool authenticate, 232 void SimulateClientConnection(int connection_index, bool authenticate,
232 bool reject) { 233 bool reject) {
233 scoped_ptr<protocol::ConnectionToClient> connection = 234 scoped_ptr<protocol::ConnectionToClient> connection =
234 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). 235 ((connection_index == 0) ? owned_connection1_ : owned_connection2_).
235 PassAs<protocol::ConnectionToClient>(); 236 PassAs<protocol::ConnectionToClient>();
236 protocol::ConnectionToClient* connection_ptr = connection.get(); 237 protocol::ConnectionToClient* connection_ptr = connection.get();
237 scoped_refptr<ClientSession> client = new ClientSession( 238 scoped_refptr<ClientSession> client = new ClientSession(
238 host_.get(), 239 host_.get(),
239 ui_task_runner_, // Audio 240 ui_task_runner_, // Audio
241 ui_task_runner_, // Input
240 ui_task_runner_, // Video capture 242 ui_task_runner_, // Video capture
241 ui_task_runner_, // Video encode 243 ui_task_runner_, // Video encode
242 ui_task_runner_, // Network 244 ui_task_runner_, // Network
245 ui_task_runner_, // UI
243 connection.Pass(), 246 connection.Pass(),
244 desktop_environment_factory_.get(), 247 desktop_environment_factory_.get(),
245 base::TimeDelta()); 248 base::TimeDelta());
246 connection_ptr->set_host_stub(client); 249 connection_ptr->set_host_stub(client);
247 250
248 ui_task_runner_->PostTask( 251 ui_task_runner_->PostTask(
249 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, 252 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost,
250 host_, client)); 253 host_, client));
251 254
252 if (authenticate) { 255 if (authenticate) {
(...skipping 20 matching lines...) Expand all
273 // Make sure that the host has been properly deleted. 276 // Make sure that the host has been properly deleted.
274 DCHECK(host_.get() == NULL); 277 DCHECK(host_.get() == NULL);
275 } 278 }
276 279
277 // Change the session route for |client1_|. 280 // Change the session route for |client1_|.
278 void ChangeSessionRoute(const std::string& channel_name, 281 void ChangeSessionRoute(const std::string& channel_name,
279 const protocol::TransportRoute& route) { 282 const protocol::TransportRoute& route) {
280 host_->OnSessionRouteChange(get_client(0), channel_name, route); 283 host_->OnSessionRouteChange(get_client(0), channel_name, route);
281 } 284 }
282 285
286 // Creates a DesktopEnvironment with a fake VideoFrameCapturer, to mock
287 // DesktopEnvironmentFactory::Create().
283 DesktopEnvironment* CreateDesktopEnvironment() { 288 DesktopEnvironment* CreateDesktopEnvironment() {
284 scoped_ptr<EventExecutor> event_executor(new EventExecutorFake()); 289 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment();
285 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake()); 290 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr(_))
286 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL), 291 .Times(0);
287 event_executor.Pass(), 292 EXPECT_CALL(*desktop_environment, CreateEventExecutorPtr(_, _))
288 video_capturer.Pass()); 293 .Times(AnyNumber())
294 .WillRepeatedly(Invoke(this, &ChromotingHostTest::CreateEventExecutor));
295 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _))
296 .Times(AnyNumber())
297 .WillRepeatedly(Invoke(this, &ChromotingHostTest::CreateVideoCapturer));
298
299 return desktop_environment;
300 }
301
302 // Creates a dummy EventExecutor, to mock
303 // DesktopEnvironment::CreateEventExecutor().
304 EventExecutor* CreateEventExecutor(
305 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
306 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
307 MockEventExecutor* event_executor = new MockEventExecutor();
308 EXPECT_CALL(*event_executor, StartPtr(_));
309 return event_executor;
310 }
311
312 // Creates a fake VideoFrameCapturer, to mock
313 // DesktopEnvironment::CreateVideoCapturer().
314 VideoFrameCapturer* CreateVideoCapturer(
315 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
316 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) {
317 return new VideoFrameCapturerFake();
289 } 318 }
290 319
291 void DisconnectAllClients() { 320 void DisconnectAllClients() {
292 host_->DisconnectAllClients(); 321 host_->DisconnectAllClients();
293 } 322 }
294 323
295 // Helper method to disconnect client 1 from the host. 324 // Helper method to disconnect client 1 from the host.
296 void DisconnectClient1() { 325 void DisconnectClient1() {
297 NotifyClientSessionClosed(0); 326 NotifyClientSessionClosed(0);
298 } 327 }
(...skipping 30 matching lines...) Expand all
329 FROM_HERE, 358 FROM_HERE,
330 base::Bind(&ChromotingHost::Shutdown, host_, 359 base::Bind(&ChromotingHost::Shutdown, host_,
331 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner, 360 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner,
332 base::Unretained(this)))); 361 base::Unretained(this))));
333 } 362 }
334 363
335 void ReleaseUiTaskRunner() { 364 void ReleaseUiTaskRunner() {
336 it2me_host_user_interface_.reset(); 365 it2me_host_user_interface_.reset();
337 ui_task_runner_ = NULL; 366 ui_task_runner_ = NULL;
338 host_ = NULL; 367 host_ = NULL;
368 desktop_environment_factory_.reset();
339 } 369 }
340 370
341 void QuitMainMessageLoop() { 371 void QuitMainMessageLoop() {
342 PostQuitTask(&message_loop_); 372 PostQuitTask(&message_loop_);
343 } 373 }
344 374
345 // Expect the host to start. 375 // Expect the host to start.
346 void ExpectHostStart() { 376 void ExpectHostStart() {
347 EXPECT_CALL(*disconnect_window_, Hide()); 377 EXPECT_CALL(*disconnect_window_, Hide());
348 EXPECT_CALL(*continue_window_, Hide()); 378 EXPECT_CALL(*continue_window_, Hide());
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 ExpectClientDisconnected(0, true, video_packet_sent, 718 ExpectClientDisconnected(0, true, video_packet_sent,
689 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 719 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
690 EXPECT_CALL(host_status_observer_, OnShutdown()); 720 EXPECT_CALL(host_status_observer_, OnShutdown());
691 721
692 host_->Start(xmpp_login_); 722 host_->Start(xmpp_login_);
693 SimulateClientConnection(0, true, false); 723 SimulateClientConnection(0, true, false);
694 message_loop_.Run(); 724 message_loop_.Run();
695 } 725 }
696 726
697 } // namespace remoting 727 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698