| 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/pepper_session.h" | 5 #include "remoting/protocol/pepper_session.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 219 |
| 220 client_session_ = client_server_->Connect( | 220 client_session_ = client_server_->Connect( |
| 221 kHostJid, authenticator.Pass(), | 221 kHostJid, authenticator.Pass(), |
| 222 CandidateSessionConfig::CreateDefault(), | 222 CandidateSessionConfig::CreateDefault(), |
| 223 base::Bind(&MockSessionCallback::OnStateChange, | 223 base::Bind(&MockSessionCallback::OnStateChange, |
| 224 base::Unretained(&client_connection_callback_))); | 224 base::Unretained(&client_connection_callback_))); |
| 225 | 225 |
| 226 message_loop_.RunAllPending(); | 226 message_loop_.RunAllPending(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void CreateChannel() { | 229 void CreateChannel(bool expect_fail) { |
| 230 client_session_->CreateStreamChannel(kChannelName, base::Bind( | 230 client_session_->CreateStreamChannel(kChannelName, base::Bind( |
| 231 &PepperSessionTest::OnClientChannelCreated, base::Unretained(this))); | 231 &PepperSessionTest::OnClientChannelCreated, base::Unretained(this))); |
| 232 host_session_->CreateStreamChannel(kChannelName, base::Bind( | 232 host_session_->CreateStreamChannel(kChannelName, base::Bind( |
| 233 &PepperSessionTest::OnHostChannelCreated, base::Unretained(this))); | 233 &PepperSessionTest::OnHostChannelCreated, base::Unretained(this))); |
| 234 | 234 |
| 235 int counter = 2; | 235 int counter = 2; |
| 236 EXPECT_CALL(client_channel_callback_, OnDone(_)) | 236 EXPECT_CALL(client_channel_callback_, OnDone(_)) |
| 237 .WillOnce(QuitThreadOnCounter(&counter)); | 237 .WillOnce(QuitThreadOnCounter(&counter)); |
| 238 EXPECT_CALL(host_channel_callback_, OnDone(_)) | 238 EXPECT_CALL(host_channel_callback_, OnDone(_)) |
| 239 .WillOnce(QuitThreadOnCounter(&counter)); | 239 .WillOnce(QuitThreadOnCounter(&counter)); |
| 240 message_loop_.Run(); | 240 message_loop_.Run(); |
| 241 |
| 242 if (expect_fail) { |
| 243 // At least one socket should fail to connect. |
| 244 EXPECT_TRUE((!client_socket_.get()) || (!host_socket_.get())); |
| 245 } else { |
| 246 EXPECT_TRUE(client_socket_.get()); |
| 247 EXPECT_TRUE(host_socket_.get()); |
| 248 } |
| 241 } | 249 } |
| 242 | 250 |
| 243 JingleThreadMessageLoop message_loop_; | 251 JingleThreadMessageLoop message_loop_; |
| 244 | 252 |
| 245 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; | 253 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; |
| 246 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; | 254 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; |
| 247 | 255 |
| 248 scoped_ptr<PepperSessionManager> host_server_; | 256 scoped_ptr<PepperSessionManager> host_server_; |
| 249 MockSessionManagerListener host_server_listener_; | 257 MockSessionManagerListener host_server_listener_; |
| 250 scoped_ptr<PepperSessionManager> client_server_; | 258 scoped_ptr<PepperSessionManager> client_server_; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 CreateSessionManagers(1, FakeAuthenticator::REJECT); | 324 CreateSessionManagers(1, FakeAuthenticator::REJECT); |
| 317 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); | 325 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); |
| 318 } | 326 } |
| 319 | 327 |
| 320 // Verify that connection is terminated when multi-step auth fails. | 328 // Verify that connection is terminated when multi-step auth fails. |
| 321 TEST_F(PepperSessionTest, ConnectWithBadMultistepAuth) { | 329 TEST_F(PepperSessionTest, ConnectWithBadMultistepAuth) { |
| 322 CreateSessionManagers(3, FakeAuthenticator::REJECT); | 330 CreateSessionManagers(3, FakeAuthenticator::REJECT); |
| 323 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); | 331 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); |
| 324 } | 332 } |
| 325 | 333 |
| 326 // Verify that data can sent over stream channel. | 334 // Verify that data can be sent over stream channel. |
| 327 TEST_F(PepperSessionTest, TestStreamChannel) { | 335 TEST_F(PepperSessionTest, TestStreamChannel) { |
| 328 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 336 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
| 329 ASSERT_NO_FATAL_FAILURE( | 337 ASSERT_NO_FATAL_FAILURE( |
| 330 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | 338 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); |
| 331 | 339 |
| 332 ASSERT_NO_FATAL_FAILURE(CreateChannel()); | 340 ASSERT_NO_FATAL_FAILURE(CreateChannel(false)); |
| 333 | 341 |
| 334 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 342 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
| 335 kMessageSize, kMessages); | 343 kMessageSize, kMessages); |
| 336 tester.Start(); | 344 tester.Start(); |
| 337 message_loop_.Run(); | 345 message_loop_.Run(); |
| 338 tester.CheckResults(); | 346 tester.CheckResults(); |
| 339 } | 347 } |
| 340 | 348 |
| 341 // Verify that we can connect channels with multistep auth. | 349 // Verify that we can connect channels with multistep auth. |
| 342 TEST_F(PepperSessionTest, TestMultistepAuthStreamChannel) { | 350 TEST_F(PepperSessionTest, TestMultistepAuthStreamChannel) { |
| 343 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 351 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
| 344 ASSERT_NO_FATAL_FAILURE( | 352 ASSERT_NO_FATAL_FAILURE( |
| 345 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); | 353 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); |
| 346 | 354 |
| 347 ASSERT_NO_FATAL_FAILURE(CreateChannel()); | 355 ASSERT_NO_FATAL_FAILURE(CreateChannel(false)); |
| 348 | 356 |
| 349 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 357 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
| 350 kMessageSize, kMessages); | 358 kMessageSize, kMessages); |
| 351 tester.Start(); | 359 tester.Start(); |
| 352 message_loop_.Run(); | 360 message_loop_.Run(); |
| 353 tester.CheckResults(); | 361 tester.CheckResults(); |
| 354 } | 362 } |
| 355 | 363 |
| 364 // Verify that we shutdown properly when channel authentication fails. |
| 365 TEST_F(PepperSessionTest, TestFailedChannelAuth) { |
| 366 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
| 367 ASSERT_NO_FATAL_FAILURE( |
| 368 InitiateConnection(1, FakeAuthenticator::REJECT_CHANNEL, false)); |
| 369 |
| 370 ASSERT_NO_FATAL_FAILURE(CreateChannel(true)); |
| 371 } |
| 372 |
| 356 } // namespace protocol | 373 } // namespace protocol |
| 357 } // namespace remoting | 374 } // namespace remoting |
| OLD | NEW |