Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: remoting/protocol/jingle_session_unittest.cc

Issue 1413813006: Revert of Add TransportSession interface to prepare for WebRTC-based transport. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/jingle_session.cc ('k') | remoting/protocol/libjingle_transport_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ice_transport_factory.h"
23 #include "remoting/protocol/jingle_session_manager.h" 22 #include "remoting/protocol/jingle_session_manager.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/p2p_stream_socket.h"
26 #include "remoting/protocol/stream_channel_factory.h" 26 #include "remoting/protocol/stream_channel_factory.h"
27 #include "remoting/signaling/fake_signal_strategy.h" 27 #include "remoting/signaling/fake_signal_strategy.h"
28 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 30
31 using testing::_; 31 using testing::_;
32 using testing::AtLeast; 32 using testing::AtLeast;
33 using testing::AtMost; 33 using testing::AtMost;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 void CreateSessionManagers(int auth_round_trips, int messages_till_start, 140 void CreateSessionManagers(int auth_round_trips, int messages_till_start,
141 FakeAuthenticator::Action auth_action) { 141 FakeAuthenticator::Action auth_action) {
142 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid)); 142 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid));
143 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid)); 143 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid));
144 FakeSignalStrategy::Connect(host_signal_strategy_.get(), 144 FakeSignalStrategy::Connect(host_signal_strategy_.get(),
145 client_signal_strategy_.get()); 145 client_signal_strategy_.get());
146 146
147 EXPECT_CALL(host_server_listener_, OnSessionManagerReady()) 147 EXPECT_CALL(host_server_listener_, OnSessionManagerReady())
148 .Times(1); 148 .Times(1);
149 149
150 scoped_ptr<TransportFactory> host_transport(new IceTransportFactory( 150 scoped_ptr<TransportFactory> host_transport(new LibjingleTransportFactory(
151 nullptr, 151 nullptr,
152 ChromiumPortAllocator::Create(nullptr, network_settings_).Pass(), 152 ChromiumPortAllocator::Create(nullptr, network_settings_).Pass(),
153 network_settings_, TransportRole::SERVER)); 153 network_settings_, TransportRole::SERVER));
154 host_server_.reset(new JingleSessionManager(host_transport.Pass())); 154 host_server_.reset(new JingleSessionManager(host_transport.Pass()));
155 host_server_->Init(host_signal_strategy_.get(), &host_server_listener_); 155 host_server_->Init(host_signal_strategy_.get(), &host_server_listener_);
156 156
157 scoped_ptr<AuthenticatorFactory> factory( 157 scoped_ptr<AuthenticatorFactory> factory(
158 new FakeHostAuthenticatorFactory(auth_round_trips, 158 new FakeHostAuthenticatorFactory(auth_round_trips,
159 messages_till_start, auth_action, true)); 159 messages_till_start, auth_action, true));
160 host_server_->set_authenticator_factory(factory.Pass()); 160 host_server_->set_authenticator_factory(factory.Pass());
161 161
162 EXPECT_CALL(client_server_listener_, OnSessionManagerReady()) 162 EXPECT_CALL(client_server_listener_, OnSessionManagerReady())
163 .Times(1); 163 .Times(1);
164 scoped_ptr<TransportFactory> client_transport(new IceTransportFactory( 164 scoped_ptr<TransportFactory> client_transport(new LibjingleTransportFactory(
165 nullptr, 165 nullptr,
166 ChromiumPortAllocator::Create(nullptr, network_settings_).Pass(), 166 ChromiumPortAllocator::Create(nullptr, network_settings_).Pass(),
167 network_settings_, TransportRole::CLIENT)); 167 network_settings_, TransportRole::CLIENT));
168 client_server_.reset( 168 client_server_.reset(
169 new JingleSessionManager(client_transport.Pass())); 169 new JingleSessionManager(client_transport.Pass()));
170 client_server_->Init(client_signal_strategy_.get(), 170 client_server_->Init(client_signal_strategy_.get(),
171 &client_server_listener_); 171 &client_server_listener_);
172 } 172 }
173 173
174 void CreateSessionManagers(int auth_round_trips, 174 void CreateSessionManagers(int auth_round_trips,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( 248 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator(
249 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); 249 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true));
250 250
251 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); 251 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass());
252 client_session_->SetEventHandler(&client_session_event_handler_); 252 client_session_->SetEventHandler(&client_session_event_handler_);
253 253
254 base::RunLoop().RunUntilIdle(); 254 base::RunLoop().RunUntilIdle();
255 } 255 }
256 256
257 void CreateChannel() { 257 void CreateChannel() {
258 client_session_->GetTransportSession() 258 client_session_->GetTransportChannelFactory()->CreateChannel(
259 ->GetStreamChannelFactory() 259 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated,
260 ->CreateChannel(kChannelName, 260 base::Unretained(this)));
261 base::Bind(&JingleSessionTest::OnClientChannelCreated, 261 host_session_->GetTransportChannelFactory()->CreateChannel(
262 base::Unretained(this))); 262 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated,
263 host_session_->GetTransportSession() 263 base::Unretained(this)));
264 ->GetStreamChannelFactory()
265 ->CreateChannel(kChannelName,
266 base::Bind(&JingleSessionTest::OnHostChannelCreated,
267 base::Unretained(this)));
268 264
269 int counter = 2; 265 int counter = 2;
270 ExpectRouteChange(kChannelName); 266 ExpectRouteChange(kChannelName);
271 EXPECT_CALL(client_channel_callback_, OnDone(_)) 267 EXPECT_CALL(client_channel_callback_, OnDone(_))
272 .WillOnce(QuitThreadOnCounter(&counter)); 268 .WillOnce(QuitThreadOnCounter(&counter));
273 EXPECT_CALL(host_channel_callback_, OnDone(_)) 269 EXPECT_CALL(host_channel_callback_, OnDone(_))
274 .WillOnce(QuitThreadOnCounter(&counter)); 270 .WillOnce(QuitThreadOnCounter(&counter));
275 message_loop_->Run(); 271 message_loop_->Run();
276 272
277 EXPECT_TRUE(client_socket_.get()); 273 EXPECT_TRUE(client_socket_.get());
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); 489 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass());
494 base::RunLoop().RunUntilIdle(); 490 base::RunLoop().RunUntilIdle();
495 } 491 }
496 492
497 // Verify that data can be sent over a multiplexed channel. 493 // Verify that data can be sent over a multiplexed channel.
498 TEST_F(JingleSessionTest, TestMuxStreamChannel) { 494 TEST_F(JingleSessionTest, TestMuxStreamChannel) {
499 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 495 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
500 ASSERT_NO_FATAL_FAILURE( 496 ASSERT_NO_FATAL_FAILURE(
501 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); 497 InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
502 498
503 client_session_->GetTransportSession() 499 client_session_->GetMultiplexedChannelFactory()->CreateChannel(
504 ->GetMultiplexedChannelFactory() 500 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated,
505 ->CreateChannel(kChannelName, 501 base::Unretained(this)));
506 base::Bind(&JingleSessionTest::OnClientChannelCreated, 502 host_session_->GetMultiplexedChannelFactory()->CreateChannel(
507 base::Unretained(this))); 503 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated,
508 host_session_->GetTransportSession() 504 base::Unretained(this)));
509 ->GetMultiplexedChannelFactory()
510 ->CreateChannel(kChannelName,
511 base::Bind(&JingleSessionTest::OnHostChannelCreated,
512 base::Unretained(this)));
513 505
514 int counter = 2; 506 int counter = 2;
515 ExpectRouteChange("mux"); 507 ExpectRouteChange("mux");
516 EXPECT_CALL(client_channel_callback_, OnDone(_)) 508 EXPECT_CALL(client_channel_callback_, OnDone(_))
517 .WillOnce(QuitThreadOnCounter(&counter)); 509 .WillOnce(QuitThreadOnCounter(&counter));
518 EXPECT_CALL(host_channel_callback_, OnDone(_)) 510 EXPECT_CALL(host_channel_callback_, OnDone(_))
519 .WillOnce(QuitThreadOnCounter(&counter)); 511 .WillOnce(QuitThreadOnCounter(&counter));
520 message_loop_->Run(); 512 message_loop_->Run();
521 513
522 EXPECT_TRUE(client_socket_.get()); 514 EXPECT_TRUE(client_socket_.get());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 message_loop_->Run(); 609 message_loop_->Run();
618 tester.CheckResults(); 610 tester.CheckResults();
619 } 611 }
620 612
621 // Verify that we shutdown properly when channel authentication fails. 613 // Verify that we shutdown properly when channel authentication fails.
622 TEST_F(JingleSessionTest, TestFailedChannelAuth) { 614 TEST_F(JingleSessionTest, TestFailedChannelAuth) {
623 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL); 615 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL);
624 ASSERT_NO_FATAL_FAILURE( 616 ASSERT_NO_FATAL_FAILURE(
625 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); 617 InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
626 618
627 client_session_->GetTransportSession() 619 client_session_->GetTransportChannelFactory()->CreateChannel(
628 ->GetStreamChannelFactory() 620 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated,
629 ->CreateChannel(kChannelName, 621 base::Unretained(this)));
630 base::Bind(&JingleSessionTest::OnClientChannelCreated, 622 host_session_->GetTransportChannelFactory()->CreateChannel(
631 base::Unretained(this))); 623 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated,
632 host_session_->GetTransportSession() 624 base::Unretained(this)));
633 ->GetStreamChannelFactory()
634 ->CreateChannel(kChannelName,
635 base::Bind(&JingleSessionTest::OnHostChannelCreated,
636 base::Unretained(this)));
637 625
638 // Terminate the message loop when we get rejection notification 626 // Terminate the message loop when we get rejection notification
639 // from the host. 627 // from the host.
640 EXPECT_CALL(host_channel_callback_, OnDone(nullptr)) 628 EXPECT_CALL(host_channel_callback_, OnDone(nullptr))
641 .WillOnce(QuitThread()); 629 .WillOnce(QuitThread());
642 ExpectRouteChange(kChannelName); 630 ExpectRouteChange(kChannelName);
643 631
644 message_loop_->Run(); 632 message_loop_->Run();
645 633
646 client_session_->GetTransportSession() 634 client_session_->GetTransportChannelFactory()->CancelChannelCreation(
647 ->GetStreamChannelFactory() 635 kChannelName);
648 ->CancelChannelCreation(kChannelName);
649 636
650 EXPECT_TRUE(!host_socket_.get()); 637 EXPECT_TRUE(!host_socket_.get());
651 } 638 }
652 639
653 TEST_F(JingleSessionTest, TestCancelChannelCreation) { 640 TEST_F(JingleSessionTest, TestCancelChannelCreation) {
654 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL); 641 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL);
655 ASSERT_NO_FATAL_FAILURE( 642 ASSERT_NO_FATAL_FAILURE(
656 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); 643 InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
657 644
658 client_session_->GetTransportSession() 645 client_session_->GetTransportChannelFactory()->CreateChannel(
659 ->GetStreamChannelFactory() 646 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated,
660 ->CreateChannel(kChannelName, 647 base::Unretained(this)));
661 base::Bind(&JingleSessionTest::OnClientChannelCreated, 648 client_session_->GetTransportChannelFactory()->CancelChannelCreation(
662 base::Unretained(this))); 649 kChannelName);
663 client_session_->GetTransportSession()
664 ->GetStreamChannelFactory()
665 ->CancelChannelCreation(kChannelName);
666 650
667 EXPECT_TRUE(!client_socket_.get()); 651 EXPECT_TRUE(!client_socket_.get());
668 } 652 }
669 653
670 // Verify that we can still connect even when there is a delay in signaling 654 // Verify that we can still connect even when there is a delay in signaling
671 // messages delivery. 655 // messages delivery.
672 TEST_F(JingleSessionTest, TestDelayedSignaling) { 656 TEST_F(JingleSessionTest, TestDelayedSignaling) {
673 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 657 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
674 ASSERT_NO_FATAL_FAILURE( 658 ASSERT_NO_FATAL_FAILURE(
675 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); 659 InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
676 660
677 host_signal_strategy_->set_send_delay( 661 host_signal_strategy_->set_send_delay(
678 base::TimeDelta::FromMilliseconds(100)); 662 base::TimeDelta::FromMilliseconds(100));
679 663
680 ASSERT_NO_FATAL_FAILURE(CreateChannel()); 664 ASSERT_NO_FATAL_FAILURE(CreateChannel());
681 665
682 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), 666 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
683 kMessageSize, 1); 667 kMessageSize, 1);
684 tester.Start(); 668 tester.Start();
685 message_loop_->Run(); 669 message_loop_->Run();
686 tester.CheckResults(); 670 tester.CheckResults();
687 } 671 }
688 672
689 } // namespace protocol 673 } // namespace protocol
690 } // namespace remoting 674 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/jingle_session.cc ('k') | remoting/protocol/libjingle_transport_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698