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

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

Issue 1530523002: More cleanups in JingleSessionManager interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@transport_context
Patch Set: Created 5 years 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
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/it2me/it2me_host.cc » ('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 "remoting/base/auto_thread_task_runner.h" 8 #include "remoting/base/auto_thread_task_runner.h"
9 #include "remoting/host/audio_capturer.h" 9 #include "remoting/host/audio_capturer.h"
10 #include "remoting/host/chromoting_host.h" 10 #include "remoting/host/chromoting_host.h"
11 #include "remoting/host/chromoting_host_context.h" 11 #include "remoting/host/chromoting_host_context.h"
12 #include "remoting/host/fake_desktop_environment.h" 12 #include "remoting/host/fake_desktop_environment.h"
13 #include "remoting/host/fake_mouse_cursor_monitor.h" 13 #include "remoting/host/fake_mouse_cursor_monitor.h"
14 #include "remoting/host/host_mock_objects.h" 14 #include "remoting/host/host_mock_objects.h"
15 #include "remoting/proto/video.pb.h" 15 #include "remoting/proto/video.pb.h"
16 #include "remoting/protocol/errors.h" 16 #include "remoting/protocol/errors.h"
17 #include "remoting/protocol/fake_connection_to_client.h" 17 #include "remoting/protocol/fake_connection_to_client.h"
18 #include "remoting/protocol/fake_desktop_capturer.h" 18 #include "remoting/protocol/fake_desktop_capturer.h"
19 #include "remoting/protocol/protocol_mock_objects.h" 19 #include "remoting/protocol/protocol_mock_objects.h"
20 #include "remoting/protocol/session_config.h" 20 #include "remoting/protocol/session_config.h"
21 #include "remoting/signaling/mock_signal_strategy.h"
22 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gmock_mutant.h" 22 #include "testing/gmock_mutant.h"
24 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
25 24
26 using ::remoting::protocol::MockClientStub; 25 using ::remoting::protocol::MockClientStub;
27 using ::remoting::protocol::MockConnectionToClientEventHandler; 26 using ::remoting::protocol::MockConnectionToClientEventHandler;
28 using ::remoting::protocol::MockHostStub; 27 using ::remoting::protocol::MockHostStub;
29 using ::remoting::protocol::MockSession; 28 using ::remoting::protocol::MockSession;
30 using ::remoting::protocol::MockVideoStub; 29 using ::remoting::protocol::MockVideoStub;
31 using ::remoting::protocol::Session; 30 using ::remoting::protocol::Session;
(...skipping 22 matching lines...) Expand all
54 ChromotingHostTest() { 53 ChromotingHostTest() {
55 } 54 }
56 55
57 void SetUp() override { 56 void SetUp() override {
58 task_runner_ = new AutoThreadTaskRunner(message_loop_.task_runner(), 57 task_runner_ = new AutoThreadTaskRunner(message_loop_.task_runner(),
59 base::Bind(&base::DoNothing)); 58 base::Bind(&base::DoNothing));
60 59
61 desktop_environment_factory_.reset(new FakeDesktopEnvironmentFactory()); 60 desktop_environment_factory_.reset(new FakeDesktopEnvironmentFactory());
62 session_manager_ = new protocol::MockSessionManager(); 61 session_manager_ = new protocol::MockSessionManager();
63 62
64 host_.reset(new ChromotingHost( 63 host_.reset(new ChromotingHost(desktop_environment_factory_.get(),
65 &signal_strategy_, 64 make_scoped_ptr(session_manager_),
66 desktop_environment_factory_.get(), 65 task_runner_, // Audio
67 make_scoped_ptr(session_manager_), 66 task_runner_, // Input
68 task_runner_, // Audio 67 task_runner_, // Video capture
69 task_runner_, // Input 68 task_runner_, // Video encode
70 task_runner_, // Video capture 69 task_runner_, // Network
71 task_runner_, // Video encode 70 task_runner_)); // UI
72 task_runner_, // Network
73 task_runner_)); // UI
74 host_->AddStatusObserver(&host_status_observer_); 71 host_->AddStatusObserver(&host_status_observer_);
75 72
76 xmpp_login_ = "host@domain"; 73 xmpp_login_ = "host@domain";
77 session1_ = new MockSession(); 74 session1_ = new MockSession();
78 session2_ = new MockSession(); 75 session2_ = new MockSession();
79 session_unowned1_.reset(new MockSession()); 76 session_unowned1_.reset(new MockSession());
80 session_unowned2_.reset(new MockSession()); 77 session_unowned2_.reset(new MockSession());
81 session_config1_ = SessionConfig::ForTest(); 78 session_config1_ = SessionConfig::ForTest();
82 session_jid1_ = "user@domain/rest-of-jid"; 79 session_jid1_ = "user@domain/rest-of-jid";
83 session_config2_ = SessionConfig::ForTest(); 80 session_config2_ = SessionConfig::ForTest();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 session_unowned2_event_handler_->OnSessionStateChange(Session::CLOSED); 179 session_unowned2_event_handler_->OnSessionStateChange(Session::CLOSED);
183 } 180 }
184 } 181 }
185 182
186 void ShutdownHost() { 183 void ShutdownHost() {
187 EXPECT_CALL(host_status_observer_, OnShutdown()); 184 EXPECT_CALL(host_status_observer_, OnShutdown());
188 host_.reset(); 185 host_.reset();
189 desktop_environment_factory_.reset(); 186 desktop_environment_factory_.reset();
190 } 187 }
191 188
192 // Expect the host and session manager to start, and return the expectation 189 // Starts the host.
193 // that the session manager has started. 190 void StartHost() {
194 Expectation ExpectHostAndSessionManagerStart() {
195 EXPECT_CALL(host_status_observer_, OnStart(xmpp_login_)); 191 EXPECT_CALL(host_status_observer_, OnStart(xmpp_login_));
196 return EXPECT_CALL(*session_manager_, Init(_, host_.get())); 192 EXPECT_CALL(*session_manager_, AcceptIncoming(_));
193 host_->Start(xmpp_login_);
197 } 194 }
198 195
199 // Expect a client to connect. 196 // Expect a client to connect.
200 // Return an expectation that a session has started. 197 // Return an expectation that a session has started.
201 Expectation ExpectClientConnected(int connection_index) { 198 Expectation ExpectClientConnected(int connection_index) {
202 const std::string& session_jid = get_session_jid(connection_index); 199 const std::string& session_jid = get_session_jid(connection_index);
203 200
204 Expectation client_authenticated = 201 Expectation client_authenticated =
205 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid)); 202 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid));
206 return EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid)) 203 return EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid))
207 .After(client_authenticated); 204 .After(client_authenticated);
208 } 205 }
209 206
210 // Expect that a client is disconnected. The given action will be done after 207 // Expect that a client is disconnected. The given action will be done after
211 // the status observer is notified that the session has finished. 208 // the status observer is notified that the session has finished.
212 Expectation ExpectClientDisconnected(int connection_index) { 209 Expectation ExpectClientDisconnected(int connection_index) {
213 return EXPECT_CALL(host_status_observer_, 210 return EXPECT_CALL(host_status_observer_,
214 OnClientDisconnected(get_session_jid(connection_index))) 211 OnClientDisconnected(get_session_jid(connection_index)))
215 .RetiresOnSaturation(); 212 .RetiresOnSaturation();
216 } 213 }
217 214
218 protected: 215 protected:
219 base::MessageLoop message_loop_; 216 base::MessageLoop message_loop_;
220 scoped_refptr<AutoThreadTaskRunner> task_runner_; 217 scoped_refptr<AutoThreadTaskRunner> task_runner_;
221 MockConnectionToClientEventHandler handler_; 218 MockConnectionToClientEventHandler handler_;
222 MockSignalStrategy signal_strategy_;
223 scoped_ptr<FakeDesktopEnvironmentFactory> desktop_environment_factory_; 219 scoped_ptr<FakeDesktopEnvironmentFactory> desktop_environment_factory_;
224 MockHostStatusObserver host_status_observer_; 220 MockHostStatusObserver host_status_observer_;
225 scoped_ptr<ChromotingHost> host_; 221 scoped_ptr<ChromotingHost> host_;
226 protocol::MockSessionManager* session_manager_; 222 protocol::MockSessionManager* session_manager_;
227 std::string xmpp_login_; 223 std::string xmpp_login_;
228 protocol::FakeConnectionToClient* connection1_; 224 protocol::FakeConnectionToClient* connection1_;
229 scoped_ptr<protocol::FakeConnectionToClient> owned_connection1_; 225 scoped_ptr<protocol::FakeConnectionToClient> owned_connection1_;
230 ClientSession* client1_; 226 ClientSession* client1_;
231 std::string session_jid1_; 227 std::string session_jid1_;
232 MockSession* session1_; // Owned by |connection_|. 228 MockSession* session1_; // Owned by |connection_|.
(...skipping 28 matching lines...) Expand all
261 std::list<ClientSession*>& get_clients_from_host() { 257 std::list<ClientSession*>& get_clients_from_host() {
262 return host_->clients_; 258 return host_->clients_;
263 } 259 }
264 260
265 const std::string& get_session_jid(int connection_index) { 261 const std::string& get_session_jid(int connection_index) {
266 return (connection_index == 0) ? session_jid1_ : session_jid2_; 262 return (connection_index == 0) ? session_jid1_ : session_jid2_;
267 } 263 }
268 }; 264 };
269 265
270 TEST_F(ChromotingHostTest, StartAndShutdown) { 266 TEST_F(ChromotingHostTest, StartAndShutdown) {
271 ExpectHostAndSessionManagerStart(); 267 StartHost();
272 host_->Start(xmpp_login_);
273 } 268 }
274 269
275 TEST_F(ChromotingHostTest, Connect) { 270 TEST_F(ChromotingHostTest, Connect) {
276 ExpectHostAndSessionManagerStart(); 271 StartHost();
277 host_->Start(xmpp_login_);
278 272
279 // Shut down the host when the first video packet is received. 273 // Shut down the host when the first video packet is received.
280 ExpectClientConnected(0); 274 ExpectClientConnected(0);
281 SimulateClientConnection(0, true, false); 275 SimulateClientConnection(0, true, false);
282 } 276 }
283 277
284 TEST_F(ChromotingHostTest, AuthenticationFailed) { 278 TEST_F(ChromotingHostTest, AuthenticationFailed) {
285 ExpectHostAndSessionManagerStart(); 279 StartHost();
286 host_->Start(xmpp_login_);
287 280
288 EXPECT_CALL(host_status_observer_, OnAccessDenied(session_jid1_)); 281 EXPECT_CALL(host_status_observer_, OnAccessDenied(session_jid1_));
289 SimulateClientConnection(0, false, false); 282 SimulateClientConnection(0, false, false);
290 } 283 }
291 284
292 TEST_F(ChromotingHostTest, Reconnect) { 285 TEST_F(ChromotingHostTest, Reconnect) {
293 ExpectHostAndSessionManagerStart(); 286 StartHost();
294 host_->Start(xmpp_login_);
295 287
296 // Connect first client. 288 // Connect first client.
297 ExpectClientConnected(0); 289 ExpectClientConnected(0);
298 SimulateClientConnection(0, true, false); 290 SimulateClientConnection(0, true, false);
299 291
300 // Disconnect first client. 292 // Disconnect first client.
301 ExpectClientDisconnected(0); 293 ExpectClientDisconnected(0);
302 client1_->OnConnectionClosed(connection1_, protocol::OK); 294 client1_->OnConnectionClosed(connection1_, protocol::OK);
303 295
304 // Connect second client. 296 // Connect second client.
305 ExpectClientConnected(1); 297 ExpectClientConnected(1);
306 SimulateClientConnection(1, true, false); 298 SimulateClientConnection(1, true, false);
307 299
308 // Disconnect second client. 300 // Disconnect second client.
309 ExpectClientDisconnected(1); 301 ExpectClientDisconnected(1);
310 client2_->OnConnectionClosed(connection2_, protocol::OK); 302 client2_->OnConnectionClosed(connection2_, protocol::OK);
311 } 303 }
312 304
313 TEST_F(ChromotingHostTest, ConnectWhenAnotherClientIsConnected) { 305 TEST_F(ChromotingHostTest, ConnectWhenAnotherClientIsConnected) {
314 ExpectHostAndSessionManagerStart(); 306 StartHost();
315 host_->Start(xmpp_login_);
316 307
317 // Connect first client. 308 // Connect first client.
318 ExpectClientConnected(0); 309 ExpectClientConnected(0);
319 SimulateClientConnection(0, true, false); 310 SimulateClientConnection(0, true, false);
320 311
321 // Connect second client. First client should be disconnected automatically. 312 // Connect second client. First client should be disconnected automatically.
322 { 313 {
323 InSequence s; 314 InSequence s;
324 ExpectClientDisconnected(0); 315 ExpectClientDisconnected(0);
325 ExpectClientConnected(1); 316 ExpectClientConnected(1);
326 } 317 }
327 SimulateClientConnection(1, true, false); 318 SimulateClientConnection(1, true, false);
328 319
329 // Disconnect second client. 320 // Disconnect second client.
330 ExpectClientDisconnected(1); 321 ExpectClientDisconnected(1);
331 client2_->OnConnectionClosed(connection2_, protocol::OK); 322 client2_->OnConnectionClosed(connection2_, protocol::OK);
332 } 323 }
333 324
334 TEST_F(ChromotingHostTest, IncomingSessionAccepted) { 325 TEST_F(ChromotingHostTest, IncomingSessionAccepted) {
335 ExpectHostAndSessionManagerStart(); 326 StartHost();
336 host_->Start(xmpp_login_);
337 327
338 MockSession* session = session_unowned1_.get(); 328 MockSession* session = session_unowned1_.get();
339 protocol::SessionManager::IncomingSessionResponse response = 329 protocol::SessionManager::IncomingSessionResponse response =
340 protocol::SessionManager::DECLINE; 330 protocol::SessionManager::DECLINE;
341 host_->OnIncomingSession(session_unowned1_.release(), &response); 331 host_->OnIncomingSession(session_unowned1_.release(), &response);
342 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 332 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
343 333
344 EXPECT_CALL(*session, Close(_)).WillOnce(InvokeWithoutArgs( 334 EXPECT_CALL(*session, Close(_)).WillOnce(InvokeWithoutArgs(
345 this, &ChromotingHostTest::NotifyConnectionClosed1)); 335 this, &ChromotingHostTest::NotifyConnectionClosed1));
346 ShutdownHost(); 336 ShutdownHost();
347 } 337 }
348 338
349 TEST_F(ChromotingHostTest, LoginBackOffUponConnection) { 339 TEST_F(ChromotingHostTest, LoginBackOffUponConnection) {
350 ExpectHostAndSessionManagerStart(); 340 StartHost();
351 host_->Start(xmpp_login_);
352 341
353 protocol::SessionManager::IncomingSessionResponse response = 342 protocol::SessionManager::IncomingSessionResponse response =
354 protocol::SessionManager::DECLINE; 343 protocol::SessionManager::DECLINE;
355 344
356 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce( 345 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce(
357 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1)); 346 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1));
358 host_->OnIncomingSession(session_unowned1_.release(), &response); 347 host_->OnIncomingSession(session_unowned1_.release(), &response);
359 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 348 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
360 349
361 host_->OnSessionAuthenticating(get_clients_from_host().front()); 350 host_->OnSessionAuthenticating(get_clients_from_host().front());
362 host_->OnIncomingSession(session_unowned2_.get(), &response); 351 host_->OnIncomingSession(session_unowned2_.get(), &response);
363 EXPECT_EQ(protocol::SessionManager::OVERLOAD, response); 352 EXPECT_EQ(protocol::SessionManager::OVERLOAD, response);
364 } 353 }
365 354
366 TEST_F(ChromotingHostTest, LoginBackOffUponAuthenticating) { 355 TEST_F(ChromotingHostTest, LoginBackOffUponAuthenticating) {
367 ExpectHostAndSessionManagerStart(); 356 StartHost();
368 357
369 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce( 358 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce(
370 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1)); 359 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1));
371 360
372 EXPECT_CALL(*session_unowned2_, Close(_)).WillOnce( 361 EXPECT_CALL(*session_unowned2_, Close(_)).WillOnce(
373 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed2)); 362 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed2));
374 363
375 host_->Start(xmpp_login_);
376
377 protocol::SessionManager::IncomingSessionResponse response = 364 protocol::SessionManager::IncomingSessionResponse response =
378 protocol::SessionManager::DECLINE; 365 protocol::SessionManager::DECLINE;
379 366
380 host_->OnIncomingSession(session_unowned1_.release(), &response); 367 host_->OnIncomingSession(session_unowned1_.release(), &response);
381 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 368 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
382 369
383 host_->OnIncomingSession(session_unowned2_.release(), &response); 370 host_->OnIncomingSession(session_unowned2_.release(), &response);
384 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 371 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
385 372
386 // This will set the backoff. 373 // This will set the backoff.
387 host_->OnSessionAuthenticating(get_clients_from_host().front()); 374 host_->OnSessionAuthenticating(get_clients_from_host().front());
388 375
389 // This should disconnect client2. 376 // This should disconnect client2.
390 host_->OnSessionAuthenticating(get_clients_from_host().back()); 377 host_->OnSessionAuthenticating(get_clients_from_host().back());
391 378
392 // Verify that the host only has 1 client at this point. 379 // Verify that the host only has 1 client at this point.
393 EXPECT_EQ(get_clients_from_host().size(), 1U); 380 EXPECT_EQ(get_clients_from_host().size(), 1U);
394 } 381 }
395 382
396 TEST_F(ChromotingHostTest, OnSessionRouteChange) { 383 TEST_F(ChromotingHostTest, OnSessionRouteChange) {
397 ExpectHostAndSessionManagerStart(); 384 StartHost();
398 host_->Start(xmpp_login_);
399 385
400 386
401 ExpectClientConnected(0); 387 ExpectClientConnected(0);
402 SimulateClientConnection(0, true, false); 388 SimulateClientConnection(0, true, false);
403 389
404 std::string channel_name("ChannelName"); 390 std::string channel_name("ChannelName");
405 protocol::TransportRoute route; 391 protocol::TransportRoute route;
406 EXPECT_CALL(host_status_observer_, 392 EXPECT_CALL(host_status_observer_,
407 OnClientRouteChange(session_jid1_, channel_name, _)); 393 OnClientRouteChange(session_jid1_, channel_name, _));
408 host_->OnSessionRouteChange(get_client(0), channel_name, route); 394 host_->OnSessionRouteChange(get_client(0), channel_name, route);
409 } 395 }
410 396
411 TEST_F(ChromotingHostTest, DisconnectAllClients) { 397 TEST_F(ChromotingHostTest, DisconnectAllClients) {
412 ExpectHostAndSessionManagerStart(); 398 StartHost();
413 host_->Start(xmpp_login_);
414 399
415 ExpectClientConnected(0); 400 ExpectClientConnected(0);
416 SimulateClientConnection(0, true, false); 401 SimulateClientConnection(0, true, false);
417 402
418 ExpectClientDisconnected(0); 403 ExpectClientDisconnected(0);
419 DisconnectAllClients(); 404 DisconnectAllClients();
420 testing::Mock::VerifyAndClearExpectations(&host_status_observer_); 405 testing::Mock::VerifyAndClearExpectations(&host_status_observer_);
421 } 406 }
422 407
423 } // namespace remoting 408 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/it2me/it2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698