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

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

Issue 10915206: [Chromoting] Refactoring DesktopEnvironment and moving screen/audio recorders to ClientSession. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 3 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/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 #include "remoting/base/auto_thread_task_runner.h"
8 #include "remoting/jingle_glue/mock_objects.h" 9 #include "remoting/jingle_glue/mock_objects.h"
9 #include "remoting/host/audio_capturer.h" 10 #include "remoting/host/audio_capturer.h"
10 #include "remoting/host/chromoting_host_context.h" 11 #include "remoting/host/chromoting_host_context.h"
11 #include "remoting/host/chromoting_host.h" 12 #include "remoting/host/chromoting_host.h"
13 #include "remoting/host/desktop_environment.h"
14 #include "remoting/host/desktop_environment_factory.h"
15 #include "remoting/host/event_executor_fake.h"
12 #include "remoting/host/host_mock_objects.h" 16 #include "remoting/host/host_mock_objects.h"
13 #include "remoting/host/it2me_host_user_interface.h" 17 #include "remoting/host/it2me_host_user_interface.h"
14 #include "remoting/host/video_frame_capturer_fake.h" 18 #include "remoting/host/video_frame_capturer_fake.h"
15 #include "remoting/proto/video.pb.h" 19 #include "remoting/proto/video.pb.h"
16 #include "remoting/protocol/errors.h" 20 #include "remoting/protocol/errors.h"
17 #include "remoting/protocol/protocol_mock_objects.h" 21 #include "remoting/protocol/protocol_mock_objects.h"
18 #include "remoting/protocol/session_config.h" 22 #include "remoting/protocol/session_config.h"
19 #include "testing/gmock_mutant.h" 23 #include "testing/gmock_mutant.h"
20 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // done callbacks. 59 // done callbacks.
56 ACTION(RunDoneTask) { 60 ACTION(RunDoneTask) {
57 arg1.Run(); 61 arg1.Run();
58 } 62 }
59 63
60 void DoNothing() { 64 void DoNothing() {
61 } 65 }
62 66
63 } // namespace 67 } // namespace
64 68
69 class MockDesktopEnvironmentFactory : public DesktopEnvironmentFactory {
70 public:
71 MockDesktopEnvironmentFactory();
72 virtual ~MockDesktopEnvironmentFactory();
73
74 virtual scoped_ptr<DesktopEnvironment> Create(
75 ChromotingHostContext* context) OVERRIDE;
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(MockDesktopEnvironmentFactory);
79 };
80
81 MockDesktopEnvironmentFactory::MockDesktopEnvironmentFactory() {
82 }
83
84 MockDesktopEnvironmentFactory::~MockDesktopEnvironmentFactory() {
85 }
86
87 scoped_ptr<DesktopEnvironment> MockDesktopEnvironmentFactory::Create(
88 ChromotingHostContext* context) {
89 scoped_ptr<EventExecutor> event_executor(new EventExecutorFake());
90 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake());
91 return scoped_ptr<DesktopEnvironment>(new DesktopEnvironment(
92 scoped_ptr<AudioCapturer>(NULL),
93 event_executor.Pass(),
94 video_capturer.Pass()));
95 }
96
65 class ChromotingHostTest : public testing::Test { 97 class ChromotingHostTest : public testing::Test {
66 public: 98 public:
67 ChromotingHostTest() { 99 ChromotingHostTest() {
68 } 100 }
69 101
70 virtual void SetUp() OVERRIDE { 102 virtual void SetUp() OVERRIDE {
71 message_loop_proxy_ = base::MessageLoopProxy::current(); 103 ui_task_runner_ = new AutoThreadTaskRunner(
104 message_loop_.message_loop_proxy(),
105 base::Bind(&ChromotingHostTest::QuitMainMessageLoop,
106 base::Unretained(this)));
72 107
73 EXPECT_CALL(context_, ui_task_runner()) 108 EXPECT_CALL(context_, ui_task_runner())
74 .Times(AnyNumber()) 109 .Times(AnyNumber())
75 .WillRepeatedly(Return(message_loop_proxy_.get())); 110 .WillRepeatedly(Return(ui_task_runner_.get()));
76 EXPECT_CALL(context_, capture_task_runner()) 111 EXPECT_CALL(context_, capture_task_runner())
77 .Times(AnyNumber()) 112 .Times(AnyNumber())
78 .WillRepeatedly(Return(message_loop_proxy_.get())); 113 .WillRepeatedly(Return(ui_task_runner_.get()));
79 EXPECT_CALL(context_, encode_task_runner()) 114 EXPECT_CALL(context_, encode_task_runner())
80 .Times(AnyNumber()) 115 .Times(AnyNumber())
81 .WillRepeatedly(Return(message_loop_proxy_.get())); 116 .WillRepeatedly(Return(ui_task_runner_.get()));
82 EXPECT_CALL(context_, network_task_runner()) 117 EXPECT_CALL(context_, network_task_runner())
83 .Times(AnyNumber()) 118 .Times(AnyNumber())
84 .WillRepeatedly(Return(message_loop_proxy_.get())); 119 .WillRepeatedly(Return(ui_task_runner_.get()));
85 120
86 scoped_ptr<VideoFrameCapturer> capturer(new VideoFrameCapturerFake()); 121 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
87 scoped_ptr<AudioCapturer> audio_capturer(NULL);
88 event_executor_ = new MockEventExecutor();
89 desktop_environment_ = DesktopEnvironment::CreateFake(
90 &context_,
91 capturer.Pass(),
92 scoped_ptr<EventExecutor>(event_executor_),
93 audio_capturer.Pass());
94 session_manager_ = new protocol::MockSessionManager(); 122 session_manager_ = new protocol::MockSessionManager();
95 123
96 host_ = new ChromotingHost( 124 host_ = new ChromotingHost(
97 &context_, &signal_strategy_, desktop_environment_.get(), 125 &context_, &signal_strategy_, desktop_environment_factory_.get(),
98 scoped_ptr<protocol::SessionManager>(session_manager_)); 126 scoped_ptr<protocol::SessionManager>(session_manager_));
99 host_->AddStatusObserver(&host_status_observer_); 127 host_->AddStatusObserver(&host_status_observer_);
100 128
101 disconnect_window_ = new MockDisconnectWindow(); 129 disconnect_window_ = new MockDisconnectWindow();
102 continue_window_ = new MockContinueWindow(); 130 continue_window_ = new MockContinueWindow();
103 local_input_monitor_ = new MockLocalInputMonitor(); 131 local_input_monitor_ = new MockLocalInputMonitor();
104 it2me_host_user_interface_.reset(new It2MeHostUserInterface(&context_)); 132 it2me_host_user_interface_.reset(new It2MeHostUserInterface(&context_));
105 it2me_host_user_interface_->StartForTest( 133 it2me_host_user_interface_->StartForTest(
106 host_, 134 host_,
107 base::Bind(&ChromotingHost::Shutdown, host_, base::Closure()), 135 base::Bind(&ChromotingHost::Shutdown, host_, base::Closure()),
(...skipping 30 matching lines...) Expand all
138 EXPECT_CALL(*session_unowned1_, SetEventHandler(_)) 166 EXPECT_CALL(*session_unowned1_, SetEventHandler(_))
139 .Times(AnyNumber()) 167 .Times(AnyNumber())
140 .WillRepeatedly(Invoke(this, &ChromotingHostTest::SetEventHandler)); 168 .WillRepeatedly(Invoke(this, &ChromotingHostTest::SetEventHandler));
141 EXPECT_CALL(*session_unowned2_, SetEventHandler(_)) 169 EXPECT_CALL(*session_unowned2_, SetEventHandler(_))
142 .Times(AnyNumber()); 170 .Times(AnyNumber());
143 EXPECT_CALL(*session1_, config()) 171 EXPECT_CALL(*session1_, config())
144 .WillRepeatedly(ReturnRef(session_config1_)); 172 .WillRepeatedly(ReturnRef(session_config1_));
145 EXPECT_CALL(*session2_, config()) 173 EXPECT_CALL(*session2_, config())
146 .WillRepeatedly(ReturnRef(session_config2_)); 174 .WillRepeatedly(ReturnRef(session_config2_));
147 175
148 owned_connection1_.reset(new MockConnectionToClient( 176 owned_connection1_.reset(new MockConnectionToClient(session1_,
149 session1_, &host_stub1_, desktop_environment_->event_executor())); 177 &host_stub1_));
150 connection1_ = owned_connection1_.get(); 178 connection1_ = owned_connection1_.get();
151 owned_connection2_.reset(new MockConnectionToClient( 179 owned_connection2_.reset(new MockConnectionToClient(session2_,
152 session2_, &host_stub2_, desktop_environment_->event_executor())); 180 &host_stub2_));
153 connection2_ = owned_connection2_.get(); 181 connection2_ = owned_connection2_.get();
154 182
155 ON_CALL(video_stub1_, ProcessVideoPacketPtr(_, _)) 183 ON_CALL(video_stub1_, ProcessVideoPacketPtr(_, _))
156 .WillByDefault(DeleteArg<0>()); 184 .WillByDefault(DeleteArg<0>());
157 ON_CALL(video_stub2_, ProcessVideoPacketPtr(_, _)) 185 ON_CALL(video_stub2_, ProcessVideoPacketPtr(_, _))
158 .WillByDefault(DeleteArg<0>()); 186 .WillByDefault(DeleteArg<0>());
159 ON_CALL(*connection1_, video_stub()) 187 ON_CALL(*connection1_, video_stub())
160 .WillByDefault(Return(&video_stub1_)); 188 .WillByDefault(Return(&video_stub1_));
161 ON_CALL(*connection1_, client_stub()) 189 ON_CALL(*connection1_, client_stub())
162 .WillByDefault(Return(&client_stub1_)); 190 .WillByDefault(Return(&client_stub1_));
(...skipping 24 matching lines...) Expand all
187 protocol::CandidateSessionConfig::CreateDefault(); 215 protocol::CandidateSessionConfig::CreateDefault();
188 } 216 }
189 217
190 // Helper method to pretend a client is connected to ChromotingHost. 218 // Helper method to pretend a client is connected to ChromotingHost.
191 void SimulateClientConnection(int connection_index, bool authenticate, 219 void SimulateClientConnection(int connection_index, bool authenticate,
192 bool reject) { 220 bool reject) {
193 scoped_ptr<protocol::ConnectionToClient> connection = 221 scoped_ptr<protocol::ConnectionToClient> connection =
194 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). 222 ((connection_index == 0) ? owned_connection1_ : owned_connection2_).
195 PassAs<protocol::ConnectionToClient>(); 223 PassAs<protocol::ConnectionToClient>();
196 protocol::ConnectionToClient* connection_ptr = connection.get(); 224 protocol::ConnectionToClient* connection_ptr = connection.get();
225 scoped_ptr<DesktopEnvironment> desktop_environment =
226 host_->desktop_environment_factory_->Create(&context_);
227 connection_ptr->set_input_stub(desktop_environment->event_executor());
228
197 ClientSession* client = new ClientSession( 229 ClientSession* client = new ClientSession(
198 host_.get(), 230 host_.get(),
231 context_.capture_task_runner(),
232 context_.encode_task_runner(),
233 context_.network_task_runner(),
199 connection.Pass(), 234 connection.Pass(),
200 desktop_environment_->event_executor(), 235 host_->desktop_environment_factory_->Create(&context_),
201 desktop_environment_->event_executor(),
202 desktop_environment_->capturer(),
203 base::TimeDelta()); 236 base::TimeDelta());
204 connection_ptr->set_host_stub(client); 237 connection_ptr->set_host_stub(client);
205 238
206 context_.network_task_runner()->PostTask( 239 context_.network_task_runner()->PostTask(
207 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, 240 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost,
208 host_, client)); 241 host_, client));
209 242
210 if (authenticate) { 243 if (authenticate) {
211 context_.network_task_runner()->PostTask( 244 context_.network_task_runner()->PostTask(
212 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, 245 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 291
259 void NotifyConnectionClosed() { 292 void NotifyConnectionClosed() {
260 if (session_event_handler_) { 293 if (session_event_handler_) {
261 session_event_handler_->OnSessionStateChange(protocol::Session::CLOSED); 294 session_event_handler_->OnSessionStateChange(protocol::Session::CLOSED);
262 } 295 }
263 } 296 }
264 297
265 static void AddClientToHost(scoped_refptr<ChromotingHost> host, 298 static void AddClientToHost(scoped_refptr<ChromotingHost> host,
266 ClientSession* session) { 299 ClientSession* session) {
267 host->clients_.push_back(session); 300 host->clients_.push_back(session);
301 host->clients_count_++;
268 } 302 }
269 303
270 void ShutdownHost() { 304 void ShutdownHost() {
271 message_loop_.PostTask( 305 ui_task_runner_->PostTask(
272 FROM_HERE, base::Bind(&ChromotingHost::Shutdown, host_, 306 FROM_HERE,
273 base::Bind(&PostQuitTask, &message_loop_))); 307 base::Bind(&ChromotingHost::Shutdown, host_,
308 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner,
309 base::Unretained(this))));
310 }
311
312 void ReleaseUiTaskRunner() {
313 it2me_host_user_interface_.reset();
314 ui_task_runner_ = NULL;
274 } 315 }
275 316
276 void QuitMainMessageLoop() { 317 void QuitMainMessageLoop() {
277 PostQuitTask(&message_loop_); 318 PostQuitTask(&message_loop_);
278 } 319 }
279 320
280 // Expect the host to start. 321 // Expect the host to start.
281 void ExpectHostStart() { 322 void ExpectHostStart() {
282 EXPECT_CALL(*disconnect_window_, Hide()); 323 EXPECT_CALL(*disconnect_window_, Hide());
283 EXPECT_CALL(*continue_window_, Hide()); 324 EXPECT_CALL(*continue_window_, Hide());
(...skipping 13 matching lines...) Expand all
297 // Do |action| when that happens. 338 // Do |action| when that happens.
298 template <class A> 339 template <class A>
299 Expectation ExpectClientConnected(int connection_index, A action) { 340 Expectation ExpectClientConnected(int connection_index, A action) {
300 const std::string& session_jid = get_session_jid(connection_index); 341 const std::string& session_jid = get_session_jid(connection_index);
301 MockVideoStub& video_stub = get_video_stub(connection_index); 342 MockVideoStub& video_stub = get_video_stub(connection_index);
302 343
303 Expectation client_authenticated = 344 Expectation client_authenticated =
304 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid)); 345 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid));
305 EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid)) 346 EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid))
306 .After(client_authenticated); 347 .After(client_authenticated);
307 Expectation session_started =
308 EXPECT_CALL(*event_executor_, OnSessionStartedPtr(_))
309 .After(client_authenticated);
310 Expectation video_packet_sent = 348 Expectation video_packet_sent =
311 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) 349 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _))
312 .After(session_started) 350 .After(client_authenticated)
313 .WillOnce(DoAll( 351 .WillOnce(DoAll(
314 action, 352 action,
315 RunDoneTask())) 353 RunDoneTask()))
316 .RetiresOnSaturation(); 354 .RetiresOnSaturation();
317 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) 355 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _))
318 .Times(AnyNumber()) 356 .Times(AnyNumber())
319 .After(video_packet_sent) 357 .After(video_packet_sent)
320 .WillRepeatedly(RunDoneTask()); 358 .WillRepeatedly(RunDoneTask());
321 return video_packet_sent; 359 return video_packet_sent;
322 } 360 }
(...skipping 25 matching lines...) Expand all
348 // Expect the side-effects of a client disconnection, after a given 386 // Expect the side-effects of a client disconnection, after a given
349 // expectation. The given action will be done after the event executor is 387 // expectation. The given action will be done after the event executor is
350 // notifed that the session has finished. 388 // notifed that the session has finished.
351 template <class A> 389 template <class A>
352 void ExpectClientDisconnectEffects(int connection_index, 390 void ExpectClientDisconnectEffects(int connection_index,
353 bool expect_host_status_change, 391 bool expect_host_status_change,
354 Expectation after, 392 Expectation after,
355 A action) { 393 A action) {
356 const std::string& session_jid = get_session_jid(connection_index); 394 const std::string& session_jid = get_session_jid(connection_index);
357 395
358 EXPECT_CALL(*event_executor_, OnSessionFinished())
359 .After(after)
360 .WillOnce(action);
361 if (expect_host_status_change) { 396 if (expect_host_status_change) {
362 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid)) 397 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid))
363 .After(after) 398 .After(after)
399 .WillOnce(action)
364 .RetiresOnSaturation(); 400 .RetiresOnSaturation();
365 } 401 }
366 } 402 }
367 403
368 protected: 404 protected:
369 MessageLoop message_loop_; 405 MessageLoop message_loop_;
370 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 406 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
371 MockChromotingHostContext context_; 407 MockChromotingHostContext context_;
372 MockConnectionToClientEventHandler handler_; 408 MockConnectionToClientEventHandler handler_;
373 MockSignalStrategy signal_strategy_; 409 MockSignalStrategy signal_strategy_;
374 MockEventExecutor* event_executor_; 410 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
375 scoped_ptr<DesktopEnvironment> desktop_environment_;
376 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; 411 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_;
377 scoped_refptr<ChromotingHost> host_; 412 scoped_refptr<ChromotingHost> host_;
378 MockHostStatusObserver host_status_observer_; 413 MockHostStatusObserver host_status_observer_;
379 protocol::MockSessionManager* session_manager_; 414 protocol::MockSessionManager* session_manager_;
380 std::string xmpp_login_; 415 std::string xmpp_login_;
381 MockConnectionToClient* connection1_; 416 MockConnectionToClient* connection1_;
382 scoped_ptr<MockConnectionToClient> owned_connection1_; 417 scoped_ptr<MockConnectionToClient> owned_connection1_;
383 ClientSession* client1_; 418 ClientSession* client1_;
384 std::string session_jid1_; 419 std::string session_jid1_;
385 MockSession* session1_; // Owned by |connection_|. 420 MockSession* session1_; // Owned by |connection_|.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 MockVideoStub& get_video_stub(int connection_index) { 461 MockVideoStub& get_video_stub(int connection_index) {
427 return (connection_index == 0) ? video_stub1_ : video_stub2_; 462 return (connection_index == 0) ? video_stub1_ : video_stub2_;
428 } 463 }
429 }; 464 };
430 465
431 TEST_F(ChromotingHostTest, StartAndShutdown) { 466 TEST_F(ChromotingHostTest, StartAndShutdown) {
432 Expectation start = ExpectHostAndSessionManagerStart(); 467 Expectation start = ExpectHostAndSessionManagerStart();
433 EXPECT_CALL(host_status_observer_, OnShutdown()).After(start); 468 EXPECT_CALL(host_status_observer_, OnShutdown()).After(start);
434 469
435 host_->Start(xmpp_login_); 470 host_->Start(xmpp_login_);
436 message_loop_.PostTask( 471 ShutdownHost();
437 FROM_HERE, base::Bind(
438 &ChromotingHost::Shutdown, host_.get(),
439 base::Bind(&PostQuitTask, &message_loop_)));
440 message_loop_.Run(); 472 message_loop_.Run();
441 } 473 }
442 474
443 TEST_F(ChromotingHostTest, Connect) { 475 TEST_F(ChromotingHostTest, Connect) {
444 ExpectHostAndSessionManagerStart(); 476 ExpectHostAndSessionManagerStart();
445 477
446 // Shut down the host when the first video packet is received. 478 // Shut down the host when the first video packet is received.
447 Expectation video_packet_sent = ExpectClientConnected( 479 Expectation video_packet_sent = ExpectClientConnected(
448 0, InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 480 0, InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
449 Expectation client_disconnected = ExpectClientDisconnected( 481 Expectation client_disconnected = ExpectClientDisconnected(
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 ExpectClientDisconnected(0, true, video_packet_sent, 664 ExpectClientDisconnected(0, true, video_packet_sent,
633 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 665 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
634 EXPECT_CALL(host_status_observer_, OnShutdown()); 666 EXPECT_CALL(host_status_observer_, OnShutdown());
635 667
636 host_->Start(xmpp_login_); 668 host_->Start(xmpp_login_);
637 SimulateClientConnection(0, true, false); 669 SimulateClientConnection(0, true, false);
638 message_loop_.Run(); 670 message_loop_.Run();
639 } 671 }
640 672
641 } // namespace remoting 673 } // 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