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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "jingle/glue/thread_wrapper.h" | |
15 #include "net/socket/socket.h" | 14 #include "net/socket/socket.h" |
16 #include "net/socket/stream_socket.h" | 15 #include "net/socket/stream_socket.h" |
17 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
18 #include "remoting/base/constants.h" | 17 #include "remoting/base/constants.h" |
19 #include "remoting/protocol/authenticator.h" | 18 #include "remoting/protocol/authenticator.h" |
20 #include "remoting/protocol/channel_authenticator.h" | 19 #include "remoting/protocol/channel_authenticator.h" |
21 #include "remoting/protocol/chromium_port_allocator.h" | 20 #include "remoting/protocol/chromium_port_allocator.h" |
22 #include "remoting/protocol/connection_tester.h" | 21 #include "remoting/protocol/connection_tester.h" |
23 #include "remoting/protocol/fake_authenticator.h" | 22 #include "remoting/protocol/fake_authenticator.h" |
24 #include "remoting/protocol/ice_transport.h" | |
25 #include "remoting/protocol/jingle_session_manager.h" | 23 #include "remoting/protocol/jingle_session_manager.h" |
26 #include "remoting/protocol/network_settings.h" | 24 #include "remoting/protocol/network_settings.h" |
| 25 #include "remoting/protocol/transport.h" |
27 #include "remoting/protocol/transport_context.h" | 26 #include "remoting/protocol/transport_context.h" |
28 #include "remoting/signaling/fake_signal_strategy.h" | 27 #include "remoting/signaling/fake_signal_strategy.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
31 | 30 |
32 using testing::_; | 31 using testing::_; |
33 using testing::AtLeast; | 32 using testing::AtLeast; |
34 using testing::AtMost; | 33 using testing::AtMost; |
35 using testing::DeleteArg; | 34 using testing::DeleteArg; |
36 using testing::DoAll; | 35 using testing::DoAll; |
(...skipping 20 matching lines...) Expand all Loading... |
57 SessionManager::IncomingSessionResponse*)); | 56 SessionManager::IncomingSessionResponse*)); |
58 }; | 57 }; |
59 | 58 |
60 class MockSessionEventHandler : public Session::EventHandler { | 59 class MockSessionEventHandler : public Session::EventHandler { |
61 public: | 60 public: |
62 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); | 61 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); |
63 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, | 62 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, |
64 const TransportRoute& route)); | 63 const TransportRoute& route)); |
65 }; | 64 }; |
66 | 65 |
| 66 class MockTransport : public Transport { |
| 67 public: |
| 68 MOCK_METHOD2(Start, |
| 69 void(Authenticator* authenticator, |
| 70 SendTransportInfoCallback send_transport_info_callback)); |
| 71 MOCK_METHOD1(ProcessTransportInfo, bool(buzz::XmlElement* transport_info)); |
| 72 }; |
| 73 |
67 } // namespace | 74 } // namespace |
68 | 75 |
69 class JingleSessionTest : public testing::Test { | 76 class JingleSessionTest : public testing::Test { |
70 public: | 77 public: |
71 JingleSessionTest() { | 78 JingleSessionTest() { |
72 message_loop_.reset(new base::MessageLoopForIO()); | 79 message_loop_.reset(new base::MessageLoopForIO()); |
73 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | |
74 network_settings_ = | 80 network_settings_ = |
75 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); | 81 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); |
76 } | 82 } |
77 | 83 |
78 // Helper method that handles OnIncomingSession(). | 84 // Helper method that handles OnIncomingSession(). |
79 void SetHostSession(Session* session) { | 85 void SetHostSession(Session* session) { |
80 DCHECK(session); | 86 DCHECK(session); |
81 host_session_.reset(session); | 87 host_session_.reset(session); |
82 host_session_->SetEventHandler(&host_session_event_handler_); | 88 host_session_->SetEventHandler(&host_session_event_handler_); |
| 89 host_session_->SetTransport(&host_transport_); |
83 } | 90 } |
84 | 91 |
85 void DeleteSession() { | 92 void DeleteSession() { |
86 host_session_.reset(); | 93 host_session_.reset(); |
87 } | 94 } |
88 | 95 |
89 protected: | 96 protected: |
90 void TearDown() override { | 97 void TearDown() override { |
91 CloseSessions(); | 98 CloseSessions(); |
92 CloseSessionManager(); | 99 CloseSessionManager(); |
93 base::RunLoop().RunUntilIdle(); | 100 base::RunLoop().RunUntilIdle(); |
94 } | 101 } |
95 | 102 |
96 void CloseSessions() { | 103 void CloseSessions() { |
97 host_session_.reset(); | 104 host_session_.reset(); |
98 client_session_.reset(); | 105 client_session_.reset(); |
99 } | 106 } |
100 | 107 |
101 void CreateSessionManagers(int auth_round_trips, int messages_till_start, | 108 void CreateSessionManagers(int auth_round_trips, int messages_till_start, |
102 FakeAuthenticator::Action auth_action) { | 109 FakeAuthenticator::Action auth_action) { |
103 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid)); | 110 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid)); |
104 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid)); | 111 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid)); |
105 FakeSignalStrategy::Connect(host_signal_strategy_.get(), | 112 FakeSignalStrategy::Connect(host_signal_strategy_.get(), |
106 client_signal_strategy_.get()); | 113 client_signal_strategy_.get()); |
107 | 114 |
108 host_server_.reset(new JingleSessionManager( | 115 host_server_.reset(new JingleSessionManager(host_signal_strategy_.get())); |
109 make_scoped_ptr(new IceTransportFactory(new TransportContext( | |
110 nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), | |
111 network_settings_, TransportRole::SERVER))), | |
112 host_signal_strategy_.get())); | |
113 host_server_->AcceptIncoming( | 116 host_server_->AcceptIncoming( |
114 base::Bind(&MockSessionManagerListener::OnIncomingSession, | 117 base::Bind(&MockSessionManagerListener::OnIncomingSession, |
115 base::Unretained(&host_server_listener_))); | 118 base::Unretained(&host_server_listener_))); |
116 | 119 |
117 scoped_ptr<AuthenticatorFactory> factory( | 120 scoped_ptr<AuthenticatorFactory> factory( |
118 new FakeHostAuthenticatorFactory(auth_round_trips, | 121 new FakeHostAuthenticatorFactory(auth_round_trips, |
119 messages_till_start, auth_action, true)); | 122 messages_till_start, auth_action, true)); |
120 host_server_->set_authenticator_factory(std::move(factory)); | 123 host_server_->set_authenticator_factory(std::move(factory)); |
121 | 124 |
122 client_server_.reset(new JingleSessionManager( | 125 client_server_.reset( |
123 make_scoped_ptr(new IceTransportFactory(new TransportContext( | 126 new JingleSessionManager(client_signal_strategy_.get())); |
124 nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), | |
125 network_settings_, TransportRole::CLIENT))), | |
126 client_signal_strategy_.get())); | |
127 } | 127 } |
128 | 128 |
129 void CreateSessionManagers(int auth_round_trips, | 129 void CreateSessionManagers(int auth_round_trips, |
130 FakeAuthenticator::Action auth_action) { | 130 FakeAuthenticator::Action auth_action) { |
131 CreateSessionManagers(auth_round_trips, 0, auth_action); | 131 CreateSessionManagers(auth_round_trips, 0, auth_action); |
132 } | 132 } |
133 | 133 |
134 void CloseSessionManager() { | 134 void CloseSessionManager() { |
135 host_server_.reset(); | 135 host_server_.reset(); |
136 client_server_.reset(); | 136 client_server_.reset(); |
(...skipping 16 matching lines...) Expand all Loading... |
153 OnSessionStateChange(Session::ACCEPTED)) | 153 OnSessionStateChange(Session::ACCEPTED)) |
154 .Times(AtMost(1)); | 154 .Times(AtMost(1)); |
155 EXPECT_CALL(host_session_event_handler_, | 155 EXPECT_CALL(host_session_event_handler_, |
156 OnSessionStateChange(Session::AUTHENTICATING)) | 156 OnSessionStateChange(Session::AUTHENTICATING)) |
157 .Times(AtMost(1)); | 157 .Times(AtMost(1)); |
158 if (expect_fail) { | 158 if (expect_fail) { |
159 EXPECT_CALL(host_session_event_handler_, | 159 EXPECT_CALL(host_session_event_handler_, |
160 OnSessionStateChange(Session::FAILED)) | 160 OnSessionStateChange(Session::FAILED)) |
161 .Times(1); | 161 .Times(1); |
162 } else { | 162 } else { |
| 163 EXPECT_CALL(host_transport_, Start(_, _)).Times(1); |
163 EXPECT_CALL(host_session_event_handler_, | 164 EXPECT_CALL(host_session_event_handler_, |
164 OnSessionStateChange(Session::AUTHENTICATED)) | 165 OnSessionStateChange(Session::AUTHENTICATED)) |
165 .Times(1); | 166 .Times(1); |
| 167 |
166 // Expect that the connection will be closed eventually. | 168 // Expect that the connection will be closed eventually. |
167 EXPECT_CALL(host_session_event_handler_, | 169 EXPECT_CALL(host_session_event_handler_, |
168 OnSessionStateChange(Session::CLOSED)) | 170 OnSessionStateChange(Session::CLOSED)) |
169 .Times(AtMost(1)); | 171 .Times(AtMost(1)); |
170 } | 172 } |
171 } | 173 } |
172 | 174 |
173 { | 175 { |
174 InSequence dummy; | 176 InSequence dummy; |
175 | 177 |
176 EXPECT_CALL(client_session_event_handler_, | 178 EXPECT_CALL(client_session_event_handler_, |
177 OnSessionStateChange(Session::ACCEPTED)) | 179 OnSessionStateChange(Session::ACCEPTED)) |
178 .Times(AtMost(1)); | 180 .Times(AtMost(1)); |
179 EXPECT_CALL(client_session_event_handler_, | 181 EXPECT_CALL(client_session_event_handler_, |
180 OnSessionStateChange(Session::AUTHENTICATING)) | 182 OnSessionStateChange(Session::AUTHENTICATING)) |
181 .Times(AtMost(1)); | 183 .Times(AtMost(1)); |
182 if (expect_fail) { | 184 if (expect_fail) { |
183 EXPECT_CALL(client_session_event_handler_, | 185 EXPECT_CALL(client_session_event_handler_, |
184 OnSessionStateChange(Session::FAILED)) | 186 OnSessionStateChange(Session::FAILED)) |
185 .Times(1); | 187 .Times(1); |
186 } else { | 188 } else { |
| 189 EXPECT_CALL(client_transport_, Start(_, _)).Times(1); |
187 EXPECT_CALL(client_session_event_handler_, | 190 EXPECT_CALL(client_session_event_handler_, |
188 OnSessionStateChange(Session::AUTHENTICATED)) | 191 OnSessionStateChange(Session::AUTHENTICATED)) |
189 .Times(1); | 192 .Times(1); |
| 193 |
190 // Expect that the connection will be closed eventually. | 194 // Expect that the connection will be closed eventually. |
191 EXPECT_CALL(client_session_event_handler_, | 195 EXPECT_CALL(client_session_event_handler_, |
192 OnSessionStateChange(Session::CLOSED)) | 196 OnSessionStateChange(Session::CLOSED)) |
193 .Times(AtMost(1)); | 197 .Times(AtMost(1)); |
194 } | 198 } |
195 } | 199 } |
196 | 200 |
197 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( | 201 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( |
198 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); | 202 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); |
199 | 203 |
200 client_session_ = | 204 client_session_ = |
201 client_server_->Connect(kHostJid, std::move(authenticator)); | 205 client_server_->Connect(kHostJid, std::move(authenticator)); |
202 client_session_->SetEventHandler(&client_session_event_handler_); | 206 client_session_->SetEventHandler(&client_session_event_handler_); |
| 207 client_session_->SetTransport(&client_transport_); |
203 | 208 |
204 base::RunLoop().RunUntilIdle(); | 209 base::RunLoop().RunUntilIdle(); |
205 } | 210 } |
206 | 211 |
207 void ExpectRouteChange(const std::string& channel_name) { | 212 void ExpectRouteChange(const std::string& channel_name) { |
208 EXPECT_CALL(host_session_event_handler_, | 213 EXPECT_CALL(host_session_event_handler_, |
209 OnSessionRouteChange(channel_name, _)) | 214 OnSessionRouteChange(channel_name, _)) |
210 .Times(AtLeast(1)); | 215 .Times(AtLeast(1)); |
211 EXPECT_CALL(client_session_event_handler_, | 216 EXPECT_CALL(client_session_event_handler_, |
212 OnSessionRouteChange(channel_name, _)) | 217 OnSessionRouteChange(channel_name, _)) |
213 .Times(AtLeast(1)); | 218 .Times(AtLeast(1)); |
214 } | 219 } |
215 | 220 |
216 scoped_ptr<base::MessageLoopForIO> message_loop_; | 221 scoped_ptr<base::MessageLoopForIO> message_loop_; |
217 | 222 |
218 NetworkSettings network_settings_; | 223 NetworkSettings network_settings_; |
219 | 224 |
220 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; | 225 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; |
221 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; | 226 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; |
222 | 227 |
223 scoped_ptr<JingleSessionManager> host_server_; | 228 scoped_ptr<JingleSessionManager> host_server_; |
224 MockSessionManagerListener host_server_listener_; | 229 MockSessionManagerListener host_server_listener_; |
225 scoped_ptr<JingleSessionManager> client_server_; | 230 scoped_ptr<JingleSessionManager> client_server_; |
226 | 231 |
227 scoped_ptr<Session> host_session_; | 232 scoped_ptr<Session> host_session_; |
228 MockSessionEventHandler host_session_event_handler_; | 233 MockSessionEventHandler host_session_event_handler_; |
| 234 MockTransport host_transport_; |
229 scoped_ptr<Session> client_session_; | 235 scoped_ptr<Session> client_session_; |
230 MockSessionEventHandler client_session_event_handler_; | 236 MockSessionEventHandler client_session_event_handler_; |
| 237 MockTransport client_transport_; |
231 }; | 238 }; |
232 | 239 |
233 | 240 |
234 // Verify that we can create and destroy session managers without a | 241 // Verify that we can create and destroy session managers without a |
235 // connection. | 242 // connection. |
236 TEST_F(JingleSessionTest, CreateAndDestoy) { | 243 TEST_F(JingleSessionTest, CreateAndDestoy) { |
237 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 244 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
238 } | 245 } |
239 | 246 |
240 // Verify that an incoming session can be rejected, and that the | 247 // Verify that an incoming session can be rejected, and that the |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 407 |
401 // Verify that we can connect with multistep authentication. | 408 // Verify that we can connect with multistep authentication. |
402 TEST_F(JingleSessionTest, TestMultistepAuth) { | 409 TEST_F(JingleSessionTest, TestMultistepAuth) { |
403 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 410 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
404 ASSERT_NO_FATAL_FAILURE( | 411 ASSERT_NO_FATAL_FAILURE( |
405 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); | 412 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); |
406 } | 413 } |
407 | 414 |
408 } // namespace protocol | 415 } // namespace protocol |
409 } // namespace remoting | 416 } // namespace remoting |
OLD | NEW |