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

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

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