| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 SessionManager::IncomingSessionResponse*)); | 77 SessionManager::IncomingSessionResponse*)); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 class MockSessionEventHandler : public Session::EventHandler { | 80 class MockSessionEventHandler : public Session::EventHandler { |
| 81 public: | 81 public: |
| 82 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); | 82 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); |
| 83 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, | 83 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, |
| 84 const TransportRoute& route)); | 84 const TransportRoute& route)); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 class MockStreamChannelCallback { | 87 class MockChannelCreatedCallback { |
| 88 public: | 88 public: |
| 89 MOCK_METHOD1(OnDone, void(net::StreamSocket* socket)); | 89 MOCK_METHOD1(OnDone, void(net::StreamSocket* socket)); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 class JingleSessionTest : public testing::Test { | 94 class JingleSessionTest : public testing::Test { |
| 95 public: | 95 public: |
| 96 JingleSessionTest() { | 96 JingleSessionTest() { |
| 97 message_loop_.reset(new base::MessageLoopForIO()); | 97 message_loop_.reset(new base::MessageLoopForIO()); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 255 |
| 256 client_session_ = client_server_->Connect( | 256 client_session_ = client_server_->Connect( |
| 257 kHostJid, authenticator.Pass(), | 257 kHostJid, authenticator.Pass(), |
| 258 CandidateSessionConfig::CreateDefault()); | 258 CandidateSessionConfig::CreateDefault()); |
| 259 client_session_->SetEventHandler(&client_session_event_handler_); | 259 client_session_->SetEventHandler(&client_session_event_handler_); |
| 260 | 260 |
| 261 base::RunLoop().RunUntilIdle(); | 261 base::RunLoop().RunUntilIdle(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 void CreateChannel() { | 264 void CreateChannel() { |
| 265 client_session_->GetTransportChannelFactory()->CreateStreamChannel( | 265 client_session_->GetTransportChannelFactory()->CreateChannel( |
| 266 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, | 266 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, |
| 267 base::Unretained(this))); | 267 base::Unretained(this))); |
| 268 host_session_->GetTransportChannelFactory()->CreateStreamChannel( | 268 host_session_->GetTransportChannelFactory()->CreateChannel( |
| 269 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, | 269 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, |
| 270 base::Unretained(this))); | 270 base::Unretained(this))); |
| 271 | 271 |
| 272 int counter = 2; | 272 int counter = 2; |
| 273 ExpectRouteChange(kChannelName); | 273 ExpectRouteChange(kChannelName); |
| 274 EXPECT_CALL(client_channel_callback_, OnDone(_)) | 274 EXPECT_CALL(client_channel_callback_, OnDone(_)) |
| 275 .WillOnce(QuitThreadOnCounter(&counter)); | 275 .WillOnce(QuitThreadOnCounter(&counter)); |
| 276 EXPECT_CALL(host_channel_callback_, OnDone(_)) | 276 EXPECT_CALL(host_channel_callback_, OnDone(_)) |
| 277 .WillOnce(QuitThreadOnCounter(&counter)); | 277 .WillOnce(QuitThreadOnCounter(&counter)); |
| 278 message_loop_->Run(); | 278 message_loop_->Run(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 298 scoped_ptr<JingleSessionManager> host_server_; | 298 scoped_ptr<JingleSessionManager> host_server_; |
| 299 MockSessionManagerListener host_server_listener_; | 299 MockSessionManagerListener host_server_listener_; |
| 300 scoped_ptr<JingleSessionManager> client_server_; | 300 scoped_ptr<JingleSessionManager> client_server_; |
| 301 MockSessionManagerListener client_server_listener_; | 301 MockSessionManagerListener client_server_listener_; |
| 302 | 302 |
| 303 scoped_ptr<Session> host_session_; | 303 scoped_ptr<Session> host_session_; |
| 304 MockSessionEventHandler host_session_event_handler_; | 304 MockSessionEventHandler host_session_event_handler_; |
| 305 scoped_ptr<Session> client_session_; | 305 scoped_ptr<Session> client_session_; |
| 306 MockSessionEventHandler client_session_event_handler_; | 306 MockSessionEventHandler client_session_event_handler_; |
| 307 | 307 |
| 308 MockStreamChannelCallback client_channel_callback_; | 308 MockChannelCreatedCallback client_channel_callback_; |
| 309 MockStreamChannelCallback host_channel_callback_; | 309 MockChannelCreatedCallback host_channel_callback_; |
| 310 | 310 |
| 311 scoped_ptr<net::StreamSocket> client_socket_; | 311 scoped_ptr<net::StreamSocket> client_socket_; |
| 312 scoped_ptr<net::StreamSocket> host_socket_; | 312 scoped_ptr<net::StreamSocket> host_socket_; |
| 313 }; | 313 }; |
| 314 | 314 |
| 315 | 315 |
| 316 // Verify that we can create and destroy session managers without a | 316 // Verify that we can create and destroy session managers without a |
| 317 // connection. | 317 // connection. |
| 318 TEST_F(JingleSessionTest, CreateAndDestoy) { | 318 TEST_F(JingleSessionTest, CreateAndDestoy) { |
| 319 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 319 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 CandidateSessionConfig::CreateDefault()); | 446 CandidateSessionConfig::CreateDefault()); |
| 447 base::RunLoop().RunUntilIdle(); | 447 base::RunLoop().RunUntilIdle(); |
| 448 } | 448 } |
| 449 | 449 |
| 450 // Verify that data can be sent over a multiplexed channel. | 450 // Verify that data can be sent over a multiplexed channel. |
| 451 TEST_F(JingleSessionTest, TestMuxStreamChannel) { | 451 TEST_F(JingleSessionTest, TestMuxStreamChannel) { |
| 452 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 452 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
| 453 ASSERT_NO_FATAL_FAILURE( | 453 ASSERT_NO_FATAL_FAILURE( |
| 454 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | 454 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); |
| 455 | 455 |
| 456 client_session_->GetMultiplexedChannelFactory()->CreateStreamChannel( | 456 client_session_->GetMultiplexedChannelFactory()->CreateChannel( |
| 457 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, | 457 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, |
| 458 base::Unretained(this))); | 458 base::Unretained(this))); |
| 459 host_session_->GetMultiplexedChannelFactory()->CreateStreamChannel( | 459 host_session_->GetMultiplexedChannelFactory()->CreateChannel( |
| 460 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, | 460 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, |
| 461 base::Unretained(this))); | 461 base::Unretained(this))); |
| 462 | 462 |
| 463 int counter = 2; | 463 int counter = 2; |
| 464 ExpectRouteChange("mux"); | 464 ExpectRouteChange("mux"); |
| 465 EXPECT_CALL(client_channel_callback_, OnDone(_)) | 465 EXPECT_CALL(client_channel_callback_, OnDone(_)) |
| 466 .WillOnce(QuitThreadOnCounter(&counter)); | 466 .WillOnce(QuitThreadOnCounter(&counter)); |
| 467 EXPECT_CALL(host_channel_callback_, OnDone(_)) | 467 EXPECT_CALL(host_channel_callback_, OnDone(_)) |
| 468 .WillOnce(QuitThreadOnCounter(&counter)); | 468 .WillOnce(QuitThreadOnCounter(&counter)); |
| 469 message_loop_->Run(); | 469 message_loop_->Run(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 492 message_loop_->Run(); | 492 message_loop_->Run(); |
| 493 tester.CheckResults(); | 493 tester.CheckResults(); |
| 494 } | 494 } |
| 495 | 495 |
| 496 // Verify that we shutdown properly when channel authentication fails. | 496 // Verify that we shutdown properly when channel authentication fails. |
| 497 TEST_F(JingleSessionTest, TestFailedChannelAuth) { | 497 TEST_F(JingleSessionTest, TestFailedChannelAuth) { |
| 498 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL); | 498 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL); |
| 499 ASSERT_NO_FATAL_FAILURE( | 499 ASSERT_NO_FATAL_FAILURE( |
| 500 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | 500 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); |
| 501 | 501 |
| 502 client_session_->GetTransportChannelFactory()->CreateStreamChannel( | 502 client_session_->GetTransportChannelFactory()->CreateChannel( |
| 503 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, | 503 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, |
| 504 base::Unretained(this))); | 504 base::Unretained(this))); |
| 505 host_session_->GetTransportChannelFactory()->CreateStreamChannel( | 505 host_session_->GetTransportChannelFactory()->CreateChannel( |
| 506 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, | 506 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, |
| 507 base::Unretained(this))); | 507 base::Unretained(this))); |
| 508 | 508 |
| 509 // Terminate the message loop when we get rejection notification | 509 // Terminate the message loop when we get rejection notification |
| 510 // from the host. | 510 // from the host. |
| 511 EXPECT_CALL(host_channel_callback_, OnDone(NULL)) | 511 EXPECT_CALL(host_channel_callback_, OnDone(NULL)) |
| 512 .WillOnce(QuitThread()); | 512 .WillOnce(QuitThread()); |
| 513 EXPECT_CALL(client_channel_callback_, OnDone(_)) | 513 EXPECT_CALL(client_channel_callback_, OnDone(_)) |
| 514 .Times(AtMost(1)); | 514 .Times(AtMost(1)); |
| 515 ExpectRouteChange(kChannelName); | 515 ExpectRouteChange(kChannelName); |
| 516 | 516 |
| 517 message_loop_->Run(); | 517 message_loop_->Run(); |
| 518 | 518 |
| 519 EXPECT_TRUE(!host_socket_.get()); | 519 EXPECT_TRUE(!host_socket_.get()); |
| 520 } | 520 } |
| 521 | 521 |
| 522 } // namespace protocol | 522 } // namespace protocol |
| 523 } // namespace remoting | 523 } // namespace remoting |
| OLD | NEW |