| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop_proxy.h" | 6 #include "base/message_loop_proxy.h" |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "net/socket/socket.h" | 8 #include "net/socket/socket.h" |
| 9 #include "net/socket/stream_socket.h" | 9 #include "net/socket/stream_socket.h" |
| 10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 bool expect_fail) { | 164 bool expect_fail) { |
| 165 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 165 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
| 166 .WillOnce(DoAll( | 166 .WillOnce(DoAll( |
| 167 WithArg<0>(Invoke( | 167 WithArg<0>(Invoke( |
| 168 this, &JingleSessionTest::SetHostSession)), | 168 this, &JingleSessionTest::SetHostSession)), |
| 169 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); | 169 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); |
| 170 | 170 |
| 171 { | 171 { |
| 172 InSequence dummy; | 172 InSequence dummy; |
| 173 | 173 |
| 174 EXPECT_CALL(host_connection_callback_, |
| 175 OnStateChange(Session::CONNECTED)) |
| 176 .Times(AtMost(1)); |
| 174 if (expect_fail) { | 177 if (expect_fail) { |
| 175 EXPECT_CALL(host_connection_callback_, | 178 EXPECT_CALL(host_connection_callback_, |
| 176 OnStateChange(Session::FAILED)) | 179 OnStateChange(Session::FAILED)) |
| 177 .Times(1); | 180 .Times(1); |
| 178 } else { | 181 } else { |
| 179 EXPECT_CALL(host_connection_callback_, | 182 EXPECT_CALL(host_connection_callback_, |
| 180 OnStateChange(Session::CONNECTED)) | |
| 181 .Times(1); | |
| 182 EXPECT_CALL(host_connection_callback_, | |
| 183 OnStateChange(Session::AUTHENTICATED)) | 183 OnStateChange(Session::AUTHENTICATED)) |
| 184 .Times(1); | 184 .Times(1); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 { | 188 { |
| 189 InSequence dummy; | 189 InSequence dummy; |
| 190 | 190 |
| 191 EXPECT_CALL(client_connection_callback_, | 191 EXPECT_CALL(client_connection_callback_, |
| 192 OnStateChange(Session::CONNECTING)) | 192 OnStateChange(Session::CONNECTING)) |
| 193 .Times(1); | 193 .Times(1); |
| 194 EXPECT_CALL(client_connection_callback_, |
| 195 OnStateChange(Session::CONNECTED)) |
| 196 .Times(AtMost(1)); |
| 194 if (expect_fail) { | 197 if (expect_fail) { |
| 195 EXPECT_CALL(client_connection_callback_, | 198 EXPECT_CALL(client_connection_callback_, |
| 196 OnStateChange(Session::FAILED)) | 199 OnStateChange(Session::FAILED)) |
| 197 .Times(1); | 200 .Times(1); |
| 198 } else { | 201 } else { |
| 199 EXPECT_CALL(client_connection_callback_, | 202 EXPECT_CALL(client_connection_callback_, |
| 200 OnStateChange(Session::CONNECTED)) | |
| 201 .Times(1); | |
| 202 EXPECT_CALL(client_connection_callback_, | |
| 203 OnStateChange(Session::AUTHENTICATED)) | 203 OnStateChange(Session::AUTHENTICATED)) |
| 204 .Times(1); | 204 .Times(1); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 Authenticator* authenticator = new FakeAuthenticator( | 208 Authenticator* authenticator = new FakeAuthenticator( |
| 209 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true); | 209 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true); |
| 210 | 210 |
| 211 client_session_.reset(client_server_->Connect( | 211 client_session_.reset(client_server_->Connect( |
| 212 kHostJid, authenticator, | 212 kHostJid, authenticator, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 319 |
| 320 message_loop_.RunAllPending(); | 320 message_loop_.RunAllPending(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 // Verify that we can connect two endpoints. | 323 // Verify that we can connect two endpoints. |
| 324 TEST_F(JingleSessionTest, Connect) { | 324 TEST_F(JingleSessionTest, Connect) { |
| 325 CreateServerPair(1, FakeAuthenticator::ACCEPT); | 325 CreateServerPair(1, FakeAuthenticator::ACCEPT); |
| 326 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | 326 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // Verify that we can't connect two endpoints with mismatched secrets. | 329 // Verify that we can connect two endpoints with multi-step authentication. |
| 330 TEST_F(JingleSessionTest, ConnectMultistep) { |
| 331 CreateServerPair(3, FakeAuthenticator::ACCEPT); |
| 332 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); |
| 333 } |
| 334 |
| 335 // Verify that connection is terminated when auth fails. |
| 330 TEST_F(JingleSessionTest, ConnectBadAuth) { | 336 TEST_F(JingleSessionTest, ConnectBadAuth) { |
| 331 CreateServerPair(1, FakeAuthenticator::REJECT); | 337 CreateServerPair(1, FakeAuthenticator::REJECT); |
| 332 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); | 338 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); |
| 333 } | 339 } |
| 334 | 340 |
| 341 // Verify that connection is terminted when multi-step auth fails. |
| 342 TEST_F(JingleSessionTest, ConnectBadMultistepAuth) { |
| 343 CreateServerPair(3, FakeAuthenticator::REJECT); |
| 344 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); |
| 345 } |
| 346 |
| 335 TEST_F(JingleSessionTest, ConnectBadChannelAuth) { | 347 TEST_F(JingleSessionTest, ConnectBadChannelAuth) { |
| 336 CreateServerPair(1, FakeAuthenticator::REJECT_CHANNEL); | 348 CreateServerPair(1, FakeAuthenticator::REJECT_CHANNEL); |
| 337 ASSERT_NO_FATAL_FAILURE( | 349 ASSERT_NO_FATAL_FAILURE( |
| 338 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | 350 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); |
| 339 | 351 |
| 340 MockStreamChannelCallback client_callback; | 352 MockStreamChannelCallback client_callback; |
| 341 MockStreamChannelCallback host_callback; | 353 MockStreamChannelCallback host_callback; |
| 342 | 354 |
| 343 client_session_->CreateStreamChannel(kChannelName, base::Bind( | 355 client_session_->CreateStreamChannel(kChannelName, base::Bind( |
| 344 &MockStreamChannelCallback::OnDone, | 356 &MockStreamChannelCallback::OnDone, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 367 | 379 |
| 368 ASSERT_NO_FATAL_FAILURE(CreateChannel()); | 380 ASSERT_NO_FATAL_FAILURE(CreateChannel()); |
| 369 | 381 |
| 370 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 382 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
| 371 kMessageSize, kMessages); | 383 kMessageSize, kMessages); |
| 372 tester.Start(); | 384 tester.Start(); |
| 373 message_loop_.Run(); | 385 message_loop_.Run(); |
| 374 tester.CheckResults(); | 386 tester.CheckResults(); |
| 375 } | 387 } |
| 376 | 388 |
| 389 // Verify that we can connect channels with multistep auth. |
| 390 TEST_F(JingleSessionTest, TestMultistepAuthTcpChannel) { |
| 391 CreateServerPair(3, FakeAuthenticator::ACCEPT); |
| 392 ASSERT_NO_FATAL_FAILURE( |
| 393 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); |
| 394 |
| 395 ASSERT_NO_FATAL_FAILURE(CreateChannel()); |
| 396 |
| 397 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
| 398 kMessageSize, kMessages); |
| 399 tester.Start(); |
| 400 message_loop_.Run(); |
| 401 tester.CheckResults(); |
| 402 } |
| 403 |
| 377 // Verify that data can be transmitted over the video RTP channel. | 404 // Verify that data can be transmitted over the video RTP channel. |
| 378 TEST_F(JingleSessionTest, TestUdpChannel) { | 405 TEST_F(JingleSessionTest, TestUdpChannel) { |
| 379 CreateServerPair(1, FakeAuthenticator::ACCEPT); | 406 CreateServerPair(1, FakeAuthenticator::ACCEPT); |
| 380 ASSERT_NO_FATAL_FAILURE( | 407 ASSERT_NO_FATAL_FAILURE( |
| 381 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | 408 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); |
| 382 | 409 |
| 383 MockDatagramChannelCallback client_callback; | 410 MockDatagramChannelCallback client_callback; |
| 384 MockDatagramChannelCallback host_callback; | 411 MockDatagramChannelCallback host_callback; |
| 385 | 412 |
| 386 int counter = 2; | 413 int counter = 2; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 410 | 437 |
| 411 DatagramConnectionTester tester( | 438 DatagramConnectionTester tester( |
| 412 client_socket, host_socket, kMessageSize, kMessages, kUdpWriteDelayMs); | 439 client_socket, host_socket, kMessageSize, kMessages, kUdpWriteDelayMs); |
| 413 tester.Start(); | 440 tester.Start(); |
| 414 message_loop_.Run(); | 441 message_loop_.Run(); |
| 415 tester.CheckResults(); | 442 tester.CheckResults(); |
| 416 } | 443 } |
| 417 | 444 |
| 418 } // namespace protocol | 445 } // namespace protocol |
| 419 } // namespace remoting | 446 } // namespace remoting |
| OLD | NEW |