| 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" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "jingle/glue/thread_wrapper.h" | 12 #include "jingle/glue/thread_wrapper.h" |
| 13 #include "net/socket/socket.h" | 13 #include "net/socket/socket.h" |
| 14 #include "net/socket/stream_socket.h" | 14 #include "net/socket/stream_socket.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 15 #include "net/url_request/url_request_context_getter.h" |
| 16 #include "remoting/base/constants.h" | 16 #include "remoting/base/constants.h" |
| 17 #include "remoting/protocol/authenticator.h" | 17 #include "remoting/protocol/authenticator.h" |
| 18 #include "remoting/protocol/channel_authenticator.h" | 18 #include "remoting/protocol/channel_authenticator.h" |
| 19 #include "remoting/protocol/chromium_port_allocator.h" | 19 #include "remoting/protocol/chromium_port_allocator.h" |
| 20 #include "remoting/protocol/connection_tester.h" | 20 #include "remoting/protocol/connection_tester.h" |
| 21 #include "remoting/protocol/fake_authenticator.h" | 21 #include "remoting/protocol/fake_authenticator.h" |
| 22 #include "remoting/protocol/jingle_session_manager.h" | 22 #include "remoting/protocol/jingle_session_manager.h" |
| 23 #include "remoting/protocol/libjingle_transport_factory.h" | 23 #include "remoting/protocol/libjingle_transport_factory.h" |
| 24 #include "remoting/protocol/network_settings.h" | 24 #include "remoting/protocol/network_settings.h" |
| 25 #include "remoting/protocol/p2p_stream_socket.h" |
| 25 #include "remoting/protocol/stream_channel_factory.h" | 26 #include "remoting/protocol/stream_channel_factory.h" |
| 26 #include "remoting/signaling/fake_signal_strategy.h" | 27 #include "remoting/signaling/fake_signal_strategy.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 30 |
| 30 using testing::_; | 31 using testing::_; |
| 31 using testing::AtLeast; | 32 using testing::AtLeast; |
| 32 using testing::AtMost; | 33 using testing::AtMost; |
| 33 using testing::DeleteArg; | 34 using testing::DeleteArg; |
| 34 using testing::DoAll; | 35 using testing::DoAll; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 81 |
| 81 class MockSessionEventHandler : public Session::EventHandler { | 82 class MockSessionEventHandler : public Session::EventHandler { |
| 82 public: | 83 public: |
| 83 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); | 84 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); |
| 84 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, | 85 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, |
| 85 const TransportRoute& route)); | 86 const TransportRoute& route)); |
| 86 }; | 87 }; |
| 87 | 88 |
| 88 class MockChannelCreatedCallback { | 89 class MockChannelCreatedCallback { |
| 89 public: | 90 public: |
| 90 MOCK_METHOD1(OnDone, void(net::StreamSocket* socket)); | 91 MOCK_METHOD1(OnDone, void(P2PStreamSocket* socket)); |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 } // namespace | 94 } // namespace |
| 94 | 95 |
| 95 class JingleSessionTest : public testing::Test { | 96 class JingleSessionTest : public testing::Test { |
| 96 public: | 97 public: |
| 97 JingleSessionTest() { | 98 JingleSessionTest() { |
| 98 message_loop_.reset(new base::MessageLoopForIO()); | 99 message_loop_.reset(new base::MessageLoopForIO()); |
| 99 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 100 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 100 } | 101 } |
| 101 | 102 |
| 102 // Helper method that handles OnIncomingSession(). | 103 // Helper method that handles OnIncomingSession(). |
| 103 void SetHostSession(Session* session) { | 104 void SetHostSession(Session* session) { |
| 104 DCHECK(session); | 105 DCHECK(session); |
| 105 host_session_.reset(session); | 106 host_session_.reset(session); |
| 106 host_session_->SetEventHandler(&host_session_event_handler_); | 107 host_session_->SetEventHandler(&host_session_event_handler_); |
| 107 | 108 |
| 108 session->set_config(standard_ice_ ? SessionConfig::ForTest() | 109 session->set_config(standard_ice_ ? SessionConfig::ForTest() |
| 109 : SessionConfig::WithLegacyIceForTest()); | 110 : SessionConfig::WithLegacyIceForTest()); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void DeleteSession() { | 113 void DeleteSession() { |
| 113 host_session_.reset(); | 114 host_session_.reset(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void OnClientChannelCreated(scoped_ptr<net::StreamSocket> socket) { | 117 void OnClientChannelCreated(scoped_ptr<P2PStreamSocket> socket) { |
| 117 client_channel_callback_.OnDone(socket.get()); | 118 client_channel_callback_.OnDone(socket.get()); |
| 118 client_socket_ = socket.Pass(); | 119 client_socket_ = socket.Pass(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void OnHostChannelCreated(scoped_ptr<net::StreamSocket> socket) { | 122 void OnHostChannelCreated(scoped_ptr<P2PStreamSocket> socket) { |
| 122 host_channel_callback_.OnDone(socket.get()); | 123 host_channel_callback_.OnDone(socket.get()); |
| 123 host_socket_ = socket.Pass(); | 124 host_socket_ = socket.Pass(); |
| 124 } | 125 } |
| 125 | 126 |
| 126 protected: | 127 protected: |
| 127 void SetUp() override {} | 128 void SetUp() override {} |
| 128 | 129 |
| 129 void TearDown() override { | 130 void TearDown() override { |
| 130 CloseSessions(); | 131 CloseSessions(); |
| 131 CloseSessionManager(); | 132 CloseSessionManager(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 MockSessionManagerListener client_server_listener_; | 303 MockSessionManagerListener client_server_listener_; |
| 303 | 304 |
| 304 scoped_ptr<Session> host_session_; | 305 scoped_ptr<Session> host_session_; |
| 305 MockSessionEventHandler host_session_event_handler_; | 306 MockSessionEventHandler host_session_event_handler_; |
| 306 scoped_ptr<Session> client_session_; | 307 scoped_ptr<Session> client_session_; |
| 307 MockSessionEventHandler client_session_event_handler_; | 308 MockSessionEventHandler client_session_event_handler_; |
| 308 | 309 |
| 309 MockChannelCreatedCallback client_channel_callback_; | 310 MockChannelCreatedCallback client_channel_callback_; |
| 310 MockChannelCreatedCallback host_channel_callback_; | 311 MockChannelCreatedCallback host_channel_callback_; |
| 311 | 312 |
| 312 scoped_ptr<net::StreamSocket> client_socket_; | 313 scoped_ptr<P2PStreamSocket> client_socket_; |
| 313 scoped_ptr<net::StreamSocket> host_socket_; | 314 scoped_ptr<P2PStreamSocket> host_socket_; |
| 314 }; | 315 }; |
| 315 | 316 |
| 316 | 317 |
| 317 // Verify that we can create and destroy session managers without a | 318 // Verify that we can create and destroy session managers without a |
| 318 // connection. | 319 // connection. |
| 319 TEST_F(JingleSessionTest, CreateAndDestoy) { | 320 TEST_F(JingleSessionTest, CreateAndDestoy) { |
| 320 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 321 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
| 321 } | 322 } |
| 322 | 323 |
| 323 // Verify that an incoming session can be rejected, and that the | 324 // Verify that an incoming session can be rejected, and that the |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 567 |
| 567 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 568 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
| 568 kMessageSize, 1); | 569 kMessageSize, 1); |
| 569 tester.Start(); | 570 tester.Start(); |
| 570 message_loop_->Run(); | 571 message_loop_->Run(); |
| 571 tester.CheckResults(); | 572 tester.CheckResults(); |
| 572 } | 573 } |
| 573 | 574 |
| 574 } // namespace protocol | 575 } // namespace protocol |
| 575 } // namespace remoting | 576 } // namespace remoting |
| OLD | NEW |