OLD | NEW |
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 "remoting/protocol/jingle_session.h" | 5 #include "remoting/protocol/jingle_session.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), | 108 nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), |
109 network_settings_, TransportRole::SERVER))), | 109 network_settings_, TransportRole::SERVER))), |
110 host_signal_strategy_.get())); | 110 host_signal_strategy_.get())); |
111 host_server_->AcceptIncoming( | 111 host_server_->AcceptIncoming( |
112 base::Bind(&MockSessionManagerListener::OnIncomingSession, | 112 base::Bind(&MockSessionManagerListener::OnIncomingSession, |
113 base::Unretained(&host_server_listener_))); | 113 base::Unretained(&host_server_listener_))); |
114 | 114 |
115 scoped_ptr<AuthenticatorFactory> factory( | 115 scoped_ptr<AuthenticatorFactory> factory( |
116 new FakeHostAuthenticatorFactory(auth_round_trips, | 116 new FakeHostAuthenticatorFactory(auth_round_trips, |
117 messages_till_start, auth_action, true)); | 117 messages_till_start, auth_action, true)); |
118 host_server_->set_authenticator_factory(factory.Pass()); | 118 host_server_->set_authenticator_factory(std::move(factory)); |
119 | 119 |
120 client_server_.reset(new JingleSessionManager( | 120 client_server_.reset(new JingleSessionManager( |
121 make_scoped_ptr(new IceTransportFactory(new TransportContext( | 121 make_scoped_ptr(new IceTransportFactory(new TransportContext( |
122 nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), | 122 nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), |
123 network_settings_, TransportRole::CLIENT))), | 123 network_settings_, TransportRole::CLIENT))), |
124 client_signal_strategy_.get())); | 124 client_signal_strategy_.get())); |
125 } | 125 } |
126 | 126 |
127 void CreateSessionManagers(int auth_round_trips, | 127 void CreateSessionManagers(int auth_round_trips, |
128 FakeAuthenticator::Action auth_action) { | 128 FakeAuthenticator::Action auth_action) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // Expect that the connection will be closed eventually. | 188 // Expect that the connection will be closed eventually. |
189 EXPECT_CALL(client_session_event_handler_, | 189 EXPECT_CALL(client_session_event_handler_, |
190 OnSessionStateChange(Session::CLOSED)) | 190 OnSessionStateChange(Session::CLOSED)) |
191 .Times(AtMost(1)); | 191 .Times(AtMost(1)); |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( | 195 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( |
196 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); | 196 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); |
197 | 197 |
198 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); | 198 client_session_ = |
| 199 client_server_->Connect(kHostJid, std::move(authenticator)); |
199 client_session_->SetEventHandler(&client_session_event_handler_); | 200 client_session_->SetEventHandler(&client_session_event_handler_); |
200 | 201 |
201 base::RunLoop().RunUntilIdle(); | 202 base::RunLoop().RunUntilIdle(); |
202 } | 203 } |
203 | 204 |
204 void ExpectRouteChange(const std::string& channel_name) { | 205 void ExpectRouteChange(const std::string& channel_name) { |
205 EXPECT_CALL(host_session_event_handler_, | 206 EXPECT_CALL(host_session_event_handler_, |
206 OnSessionRouteChange(channel_name, _)) | 207 OnSessionRouteChange(channel_name, _)) |
207 .Times(AtLeast(1)); | 208 .Times(AtLeast(1)); |
208 EXPECT_CALL(client_session_event_handler_, | 209 EXPECT_CALL(client_session_event_handler_, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 246 |
246 { | 247 { |
247 InSequence dummy; | 248 InSequence dummy; |
248 EXPECT_CALL(client_session_event_handler_, | 249 EXPECT_CALL(client_session_event_handler_, |
249 OnSessionStateChange(Session::FAILED)) | 250 OnSessionStateChange(Session::FAILED)) |
250 .Times(1); | 251 .Times(1); |
251 } | 252 } |
252 | 253 |
253 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( | 254 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( |
254 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); | 255 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); |
255 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); | 256 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); |
256 client_session_->SetEventHandler(&client_session_event_handler_); | 257 client_session_->SetEventHandler(&client_session_event_handler_); |
257 | 258 |
258 base::RunLoop().RunUntilIdle(); | 259 base::RunLoop().RunUntilIdle(); |
259 } | 260 } |
260 | 261 |
261 // Verify that we can connect two endpoints with single-step authentication. | 262 // Verify that we can connect two endpoints with single-step authentication. |
262 TEST_F(JingleSessionTest, Connect) { | 263 TEST_F(JingleSessionTest, Connect) { |
263 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 264 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
264 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | 265 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); |
265 | 266 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 OnSessionStateChange(Session::FAILED)) | 303 OnSessionStateChange(Session::FAILED)) |
303 .Times(1); | 304 .Times(1); |
304 | 305 |
305 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( | 306 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( |
306 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); | 307 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); |
307 | 308 |
308 scoped_ptr<CandidateSessionConfig> config = | 309 scoped_ptr<CandidateSessionConfig> config = |
309 CandidateSessionConfig::CreateDefault(); | 310 CandidateSessionConfig::CreateDefault(); |
310 // Disable all video codecs so the host will reject connection. | 311 // Disable all video codecs so the host will reject connection. |
311 config->mutable_video_configs()->clear(); | 312 config->mutable_video_configs()->clear(); |
312 client_server_->set_protocol_config(config.Pass()); | 313 client_server_->set_protocol_config(std::move(config)); |
313 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); | 314 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); |
314 client_session_->SetEventHandler(&client_session_event_handler_); | 315 client_session_->SetEventHandler(&client_session_event_handler_); |
315 | 316 |
316 base::RunLoop().RunUntilIdle(); | 317 base::RunLoop().RunUntilIdle(); |
317 | 318 |
318 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error()); | 319 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error()); |
319 EXPECT_FALSE(host_session_); | 320 EXPECT_FALSE(host_session_); |
320 } | 321 } |
321 | 322 |
322 // Verify that GICE-only client is rejected with an appropriate error code. | 323 // Verify that GICE-only client is rejected with an appropriate error code. |
323 TEST_F(JingleSessionTest, TestLegacyIceConnection) { | 324 TEST_F(JingleSessionTest, TestLegacyIceConnection) { |
324 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 325 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
325 | 326 |
326 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0); | 327 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0); |
327 | 328 |
328 EXPECT_CALL(client_session_event_handler_, | 329 EXPECT_CALL(client_session_event_handler_, |
329 OnSessionStateChange(Session::FAILED)) | 330 OnSessionStateChange(Session::FAILED)) |
330 .Times(1); | 331 .Times(1); |
331 | 332 |
332 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( | 333 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( |
333 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); | 334 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); |
334 | 335 |
335 scoped_ptr<CandidateSessionConfig> config = | 336 scoped_ptr<CandidateSessionConfig> config = |
336 CandidateSessionConfig::CreateDefault(); | 337 CandidateSessionConfig::CreateDefault(); |
337 config->set_ice_supported(false); | 338 config->set_ice_supported(false); |
338 client_server_->set_protocol_config(config.Pass()); | 339 client_server_->set_protocol_config(std::move(config)); |
339 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); | 340 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); |
340 client_session_->SetEventHandler(&client_session_event_handler_); | 341 client_session_->SetEventHandler(&client_session_event_handler_); |
341 | 342 |
342 base::RunLoop().RunUntilIdle(); | 343 base::RunLoop().RunUntilIdle(); |
343 | 344 |
344 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error()); | 345 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error()); |
345 EXPECT_FALSE(host_session_); | 346 EXPECT_FALSE(host_session_); |
346 } | 347 } |
347 | 348 |
348 TEST_F(JingleSessionTest, DeleteSessionOnIncomingConnection) { | 349 TEST_F(JingleSessionTest, DeleteSessionOnIncomingConnection) { |
349 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 350 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
350 | 351 |
351 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 352 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
352 .WillOnce(DoAll( | 353 .WillOnce(DoAll( |
353 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), | 354 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), |
354 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); | 355 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); |
355 | 356 |
356 EXPECT_CALL(host_session_event_handler_, | 357 EXPECT_CALL(host_session_event_handler_, |
357 OnSessionStateChange(Session::ACCEPTED)) | 358 OnSessionStateChange(Session::ACCEPTED)) |
358 .Times(AtMost(1)); | 359 .Times(AtMost(1)); |
359 | 360 |
360 EXPECT_CALL(host_session_event_handler_, | 361 EXPECT_CALL(host_session_event_handler_, |
361 OnSessionStateChange(Session::AUTHENTICATING)) | 362 OnSessionStateChange(Session::AUTHENTICATING)) |
362 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession)); | 363 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession)); |
363 | 364 |
364 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( | 365 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( |
365 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); | 366 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); |
366 | 367 |
367 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); | 368 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); |
368 | 369 |
369 base::RunLoop().RunUntilIdle(); | 370 base::RunLoop().RunUntilIdle(); |
370 } | 371 } |
371 | 372 |
372 TEST_F(JingleSessionTest, DeleteSessionOnAuth) { | 373 TEST_F(JingleSessionTest, DeleteSessionOnAuth) { |
373 // Same as the previous test, but set messages_till_started to 2 in | 374 // Same as the previous test, but set messages_till_started to 2 in |
374 // CreateSessionManagers so that the session will goes into the | 375 // CreateSessionManagers so that the session will goes into the |
375 // AUTHENTICATING state after two message exchanges. | 376 // AUTHENTICATING state after two message exchanges. |
376 CreateSessionManagers(3, 2, FakeAuthenticator::ACCEPT); | 377 CreateSessionManagers(3, 2, FakeAuthenticator::ACCEPT); |
377 | 378 |
378 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 379 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
379 .WillOnce(DoAll( | 380 .WillOnce(DoAll( |
380 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), | 381 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), |
381 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); | 382 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); |
382 | 383 |
383 EXPECT_CALL(host_session_event_handler_, | 384 EXPECT_CALL(host_session_event_handler_, |
384 OnSessionStateChange(Session::ACCEPTED)) | 385 OnSessionStateChange(Session::ACCEPTED)) |
385 .Times(AtMost(1)); | 386 .Times(AtMost(1)); |
386 | 387 |
387 EXPECT_CALL(host_session_event_handler_, | 388 EXPECT_CALL(host_session_event_handler_, |
388 OnSessionStateChange(Session::AUTHENTICATING)) | 389 OnSessionStateChange(Session::AUTHENTICATING)) |
389 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession)); | 390 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession)); |
390 | 391 |
391 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( | 392 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( |
392 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); | 393 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); |
393 | 394 |
394 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); | 395 client_session_ = client_server_->Connect(kHostJid, std::move(authenticator)); |
395 base::RunLoop().RunUntilIdle(); | 396 base::RunLoop().RunUntilIdle(); |
396 } | 397 } |
397 | 398 |
398 // Verify that we can connect with multistep authentication. | 399 // Verify that we can connect with multistep authentication. |
399 TEST_F(JingleSessionTest, TestMultistepAuth) { | 400 TEST_F(JingleSessionTest, TestMultistepAuth) { |
400 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 401 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
401 ASSERT_NO_FATAL_FAILURE( | 402 ASSERT_NO_FATAL_FAILURE( |
402 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); | 403 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); |
403 } | 404 } |
404 | 405 |
405 } // namespace protocol | 406 } // namespace protocol |
406 } // namespace remoting | 407 } // namespace remoting |
OLD | NEW |