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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 message_loop_.reset(new base::MessageLoopForIO()); | 98 message_loop_.reset(new base::MessageLoopForIO()); |
99 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 99 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
100 } | 100 } |
101 | 101 |
102 // Helper method that handles OnIncomingSession(). | 102 // Helper method that handles OnIncomingSession(). |
103 void SetHostSession(Session* session) { | 103 void SetHostSession(Session* session) { |
104 DCHECK(session); | 104 DCHECK(session); |
105 host_session_.reset(session); | 105 host_session_.reset(session); |
106 host_session_->SetEventHandler(&host_session_event_handler_); | 106 host_session_->SetEventHandler(&host_session_event_handler_); |
107 | 107 |
108 session->set_config(standard_ice_ ? SessionConfig::ForTest() | 108 session->set_config(SessionConfig::ForTest()); |
109 : SessionConfig::WithLegacyIceForTest()); | |
110 } | 109 } |
111 | 110 |
112 void DeleteSession() { | 111 void DeleteSession() { |
113 host_session_.reset(); | 112 host_session_.reset(); |
114 } | 113 } |
115 | 114 |
116 void OnClientChannelCreated(scoped_ptr<net::StreamSocket> socket) { | 115 void OnClientChannelCreated(scoped_ptr<net::StreamSocket> socket) { |
117 client_channel_callback_.OnDone(socket.get()); | 116 client_channel_callback_.OnDone(socket.get()); |
118 client_socket_ = socket.Pass(); | 117 client_socket_ = socket.Pass(); |
119 } | 118 } |
(...skipping 27 matching lines...) Expand all Loading... |
147 client_signal_strategy_.get()); | 146 client_signal_strategy_.get()); |
148 | 147 |
149 EXPECT_CALL(host_server_listener_, OnSessionManagerReady()) | 148 EXPECT_CALL(host_server_listener_, OnSessionManagerReady()) |
150 .Times(1); | 149 .Times(1); |
151 | 150 |
152 NetworkSettings network_settings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); | 151 NetworkSettings network_settings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); |
153 | 152 |
154 scoped_ptr<TransportFactory> host_transport(new LibjingleTransportFactory( | 153 scoped_ptr<TransportFactory> host_transport(new LibjingleTransportFactory( |
155 nullptr, | 154 nullptr, |
156 ChromiumPortAllocator::Create(nullptr, network_settings).Pass(), | 155 ChromiumPortAllocator::Create(nullptr, network_settings).Pass(), |
157 network_settings, TransportRole::SERVER)); | 156 network_settings)); |
158 host_server_.reset(new JingleSessionManager(host_transport.Pass())); | 157 host_server_.reset(new JingleSessionManager(host_transport.Pass())); |
159 host_server_->Init(host_signal_strategy_.get(), &host_server_listener_); | 158 host_server_->Init(host_signal_strategy_.get(), &host_server_listener_); |
160 | 159 |
161 scoped_ptr<AuthenticatorFactory> factory( | 160 scoped_ptr<AuthenticatorFactory> factory( |
162 new FakeHostAuthenticatorFactory(auth_round_trips, | 161 new FakeHostAuthenticatorFactory(auth_round_trips, |
163 messages_till_start, auth_action, true)); | 162 messages_till_start, auth_action, true)); |
164 host_server_->set_authenticator_factory(factory.Pass()); | 163 host_server_->set_authenticator_factory(factory.Pass()); |
165 | 164 |
166 EXPECT_CALL(client_server_listener_, OnSessionManagerReady()) | 165 EXPECT_CALL(client_server_listener_, OnSessionManagerReady()) |
167 .Times(1); | 166 .Times(1); |
168 scoped_ptr<TransportFactory> client_transport(new LibjingleTransportFactory( | 167 scoped_ptr<TransportFactory> client_transport(new LibjingleTransportFactory( |
169 nullptr, | 168 nullptr, |
170 ChromiumPortAllocator::Create(nullptr, network_settings).Pass(), | 169 ChromiumPortAllocator::Create(nullptr, network_settings).Pass(), |
171 network_settings, TransportRole::CLIENT)); | 170 network_settings)); |
172 client_server_.reset( | 171 client_server_.reset( |
173 new JingleSessionManager(client_transport.Pass())); | 172 new JingleSessionManager(client_transport.Pass())); |
174 client_server_->Init(client_signal_strategy_.get(), | 173 client_server_->Init(client_signal_strategy_.get(), |
175 &client_server_listener_); | 174 &client_server_listener_); |
176 } | 175 } |
177 | 176 |
178 void CreateSessionManagers(int auth_round_trips, | 177 void CreateSessionManagers(int auth_round_trips, |
179 FakeAuthenticator::Action auth_action) { | 178 FakeAuthenticator::Action auth_action) { |
180 CreateSessionManagers(auth_round_trips, 0, auth_action); | 179 CreateSessionManagers(auth_round_trips, 0, auth_action); |
181 } | 180 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 EXPECT_CALL(host_session_event_handler_, | 283 EXPECT_CALL(host_session_event_handler_, |
285 OnSessionRouteChange(channel_name, _)) | 284 OnSessionRouteChange(channel_name, _)) |
286 .Times(AtLeast(1)); | 285 .Times(AtLeast(1)); |
287 EXPECT_CALL(client_session_event_handler_, | 286 EXPECT_CALL(client_session_event_handler_, |
288 OnSessionRouteChange(channel_name, _)) | 287 OnSessionRouteChange(channel_name, _)) |
289 .Times(AtLeast(1)); | 288 .Times(AtLeast(1)); |
290 } | 289 } |
291 | 290 |
292 scoped_ptr<base::MessageLoopForIO> message_loop_; | 291 scoped_ptr<base::MessageLoopForIO> message_loop_; |
293 | 292 |
294 bool standard_ice_ = true; | |
295 | |
296 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; | 293 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; |
297 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; | 294 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; |
298 | 295 |
299 scoped_ptr<JingleSessionManager> host_server_; | 296 scoped_ptr<JingleSessionManager> host_server_; |
300 MockSessionManagerListener host_server_listener_; | 297 MockSessionManagerListener host_server_listener_; |
301 scoped_ptr<JingleSessionManager> client_server_; | 298 scoped_ptr<JingleSessionManager> client_server_; |
302 MockSessionManagerListener client_server_listener_; | 299 MockSessionManagerListener client_server_listener_; |
303 | 300 |
304 scoped_ptr<Session> host_session_; | 301 scoped_ptr<Session> host_session_; |
305 MockSessionEventHandler host_session_event_handler_; | 302 MockSessionEventHandler host_session_event_handler_; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 // Verify that we can connect two endpoints with single-step authentication. | 345 // Verify that we can connect two endpoints with single-step authentication. |
349 TEST_F(JingleSessionTest, Connect) { | 346 TEST_F(JingleSessionTest, Connect) { |
350 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 347 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
351 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | 348 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); |
352 | 349 |
353 // Verify that the client specified correct initiator value. | 350 // Verify that the client specified correct initiator value. |
354 ASSERT_GT(host_signal_strategy_->received_messages().size(), 0U); | 351 ASSERT_GT(host_signal_strategy_->received_messages().size(), 0U); |
355 const buzz::XmlElement* initiate_xml = | 352 const buzz::XmlElement* initiate_xml = |
356 host_signal_strategy_->received_messages().front(); | 353 host_signal_strategy_->received_messages().front(); |
357 const buzz::XmlElement* jingle_element = | 354 const buzz::XmlElement* jingle_element = |
358 initiate_xml->FirstNamed(buzz::QName("urn:xmpp:jingle:1", "jingle")); | 355 initiate_xml->FirstNamed(buzz::QName(kJingleNamespace, "jingle")); |
359 ASSERT_TRUE(jingle_element); | 356 ASSERT_TRUE(jingle_element); |
360 ASSERT_EQ(kClientJid, | 357 ASSERT_EQ(kClientJid, |
361 jingle_element->Attr(buzz::QName(std::string(), "initiator"))); | 358 jingle_element->Attr(buzz::QName(std::string(), "initiator"))); |
362 } | 359 } |
363 | 360 |
364 // Verify that we can connect two endpoints with multi-step authentication. | 361 // Verify that we can connect two endpoints with multi-step authentication. |
365 TEST_F(JingleSessionTest, ConnectWithMultistep) { | 362 TEST_F(JingleSessionTest, ConnectWithMultistep) { |
366 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 363 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
367 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); | 364 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); |
368 } | 365 } |
369 | 366 |
370 // Verify that connection is terminated when single-step auth fails. | 367 // Verify that connection is terminated when single-step auth fails. |
371 TEST_F(JingleSessionTest, ConnectWithBadAuth) { | 368 TEST_F(JingleSessionTest, ConnectWithBadAuth) { |
372 CreateSessionManagers(1, FakeAuthenticator::REJECT); | 369 CreateSessionManagers(1, FakeAuthenticator::REJECT); |
373 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); | 370 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); |
374 } | 371 } |
375 | 372 |
376 // Verify that connection is terminated when multi-step auth fails. | 373 // Verify that connection is terminated when multi-step auth fails. |
377 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { | 374 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { |
378 CreateSessionManagers(3, FakeAuthenticator::REJECT); | 375 CreateSessionManagers(3, FakeAuthenticator::REJECT); |
379 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); | 376 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); |
380 } | 377 } |
381 | 378 |
382 // Verify that data can be sent over stream channel. | 379 // Verify that data can be sent over stream channel. |
383 TEST_F(JingleSessionTest, TestStreamChannel) { | 380 TEST_F(JingleSessionTest, TestStreamChannel) { |
384 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 381 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
385 ASSERT_NO_FATAL_FAILURE( | 382 ASSERT_NO_FATAL_FAILURE( |
386 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | 383 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); |
387 | |
388 ASSERT_NO_FATAL_FAILURE(CreateChannel()); | |
389 | |
390 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | |
391 kMessageSize, kMessages); | |
392 tester.Start(); | |
393 message_loop_->Run(); | |
394 tester.CheckResults(); | |
395 } | |
396 | |
397 // Verify that we can still connect using legacy GICE transport. | |
398 TEST_F(JingleSessionTest, TestLegacyIceConnection) { | |
399 standard_ice_ = false; | |
400 | |
401 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | |
402 ASSERT_NO_FATAL_FAILURE( | |
403 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | |
404 | 384 |
405 ASSERT_NO_FATAL_FAILURE(CreateChannel()); | 385 ASSERT_NO_FATAL_FAILURE(CreateChannel()); |
406 | 386 |
407 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 387 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
408 kMessageSize, kMessages); | 388 kMessageSize, kMessages); |
409 tester.Start(); | 389 tester.Start(); |
410 message_loop_->Run(); | 390 message_loop_->Run(); |
411 tester.CheckResults(); | 391 tester.CheckResults(); |
412 } | 392 } |
413 | 393 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 546 |
567 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 547 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
568 kMessageSize, 1); | 548 kMessageSize, 1); |
569 tester.Start(); | 549 tester.Start(); |
570 message_loop_->Run(); | 550 message_loop_->Run(); |
571 tester.CheckResults(); | 551 tester.CheckResults(); |
572 } | 552 } |
573 | 553 |
574 } // namespace protocol | 554 } // namespace protocol |
575 } // namespace remoting | 555 } // namespace remoting |
OLD | NEW |