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

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

Issue 1420273002: 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"
22 #include "remoting/protocol/jingle_session_manager.h" 23 #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 LibjingleTransportFactory( 150 scoped_ptr<TransportFactory> host_transport(new IceTransportFactory(
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 LibjingleTransportFactory( 164 scoped_ptr<TransportFactory> client_transport(new IceTransportFactory(
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_->GetTransportChannelFactory()->CreateChannel( 258 client_session_->GetTransportSession()
259 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, 259 ->GetStreamChannelFactory()
260 base::Unretained(this))); 260 ->CreateChannel(kChannelName,
261 host_session_->GetTransportChannelFactory()->CreateChannel( 261 base::Bind(&JingleSessionTest::OnClientChannelCreated,
262 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, 262 base::Unretained(this)));
263 base::Unretained(this))); 263 host_session_->GetTransportSession()
264 ->GetStreamChannelFactory()
265 ->CreateChannel(kChannelName,
266 base::Bind(&JingleSessionTest::OnHostChannelCreated,
267 base::Unretained(this)));
264 268
265 int counter = 2; 269 int counter = 2;
266 ExpectRouteChange(kChannelName); 270 ExpectRouteChange(kChannelName);
267 EXPECT_CALL(client_channel_callback_, OnDone(_)) 271 EXPECT_CALL(client_channel_callback_, OnDone(_))
268 .WillOnce(QuitThreadOnCounter(&counter)); 272 .WillOnce(QuitThreadOnCounter(&counter));
269 EXPECT_CALL(host_channel_callback_, OnDone(_)) 273 EXPECT_CALL(host_channel_callback_, OnDone(_))
270 .WillOnce(QuitThreadOnCounter(&counter)); 274 .WillOnce(QuitThreadOnCounter(&counter));
271 message_loop_->Run(); 275 message_loop_->Run();
272 276
273 EXPECT_TRUE(client_socket_.get()); 277 EXPECT_TRUE(client_socket_.get());
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); 493 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass());
490 base::RunLoop().RunUntilIdle(); 494 base::RunLoop().RunUntilIdle();
491 } 495 }
492 496
493 // Verify that data can be sent over a multiplexed channel. 497 // Verify that data can be sent over a multiplexed channel.
494 TEST_F(JingleSessionTest, TestMuxStreamChannel) { 498 TEST_F(JingleSessionTest, TestMuxStreamChannel) {
495 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 499 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
496 ASSERT_NO_FATAL_FAILURE( 500 ASSERT_NO_FATAL_FAILURE(
497 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); 501 InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
498 502
499 client_session_->GetMultiplexedChannelFactory()->CreateChannel( 503 client_session_->GetTransportSession()
500 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, 504 ->GetMultiplexedChannelFactory()
501 base::Unretained(this))); 505 ->CreateChannel(kChannelName,
502 host_session_->GetMultiplexedChannelFactory()->CreateChannel( 506 base::Bind(&JingleSessionTest::OnClientChannelCreated,
503 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, 507 base::Unretained(this)));
504 base::Unretained(this))); 508 host_session_->GetTransportSession()
509 ->GetMultiplexedChannelFactory()
510 ->CreateChannel(kChannelName,
511 base::Bind(&JingleSessionTest::OnHostChannelCreated,
512 base::Unretained(this)));
505 513
506 int counter = 2; 514 int counter = 2;
507 ExpectRouteChange("mux"); 515 ExpectRouteChange("mux");
508 EXPECT_CALL(client_channel_callback_, OnDone(_)) 516 EXPECT_CALL(client_channel_callback_, OnDone(_))
509 .WillOnce(QuitThreadOnCounter(&counter)); 517 .WillOnce(QuitThreadOnCounter(&counter));
510 EXPECT_CALL(host_channel_callback_, OnDone(_)) 518 EXPECT_CALL(host_channel_callback_, OnDone(_))
511 .WillOnce(QuitThreadOnCounter(&counter)); 519 .WillOnce(QuitThreadOnCounter(&counter));
512 message_loop_->Run(); 520 message_loop_->Run();
513 521
514 EXPECT_TRUE(client_socket_.get()); 522 EXPECT_TRUE(client_socket_.get());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 message_loop_->Run(); 617 message_loop_->Run();
610 tester.CheckResults(); 618 tester.CheckResults();
611 } 619 }
612 620
613 // Verify that we shutdown properly when channel authentication fails. 621 // Verify that we shutdown properly when channel authentication fails.
614 TEST_F(JingleSessionTest, TestFailedChannelAuth) { 622 TEST_F(JingleSessionTest, TestFailedChannelAuth) {
615 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL); 623 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL);
616 ASSERT_NO_FATAL_FAILURE( 624 ASSERT_NO_FATAL_FAILURE(
617 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); 625 InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
618 626
619 client_session_->GetTransportChannelFactory()->CreateChannel( 627 client_session_->GetTransportSession()
620 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, 628 ->GetStreamChannelFactory()
621 base::Unretained(this))); 629 ->CreateChannel(kChannelName,
622 host_session_->GetTransportChannelFactory()->CreateChannel( 630 base::Bind(&JingleSessionTest::OnClientChannelCreated,
623 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, 631 base::Unretained(this)));
624 base::Unretained(this))); 632 host_session_->GetTransportSession()
633 ->GetStreamChannelFactory()
634 ->CreateChannel(kChannelName,
635 base::Bind(&JingleSessionTest::OnHostChannelCreated,
636 base::Unretained(this)));
625 637
626 // Terminate the message loop when we get rejection notification 638 // Terminate the message loop when we get rejection notification
627 // from the host. 639 // from the host.
628 EXPECT_CALL(host_channel_callback_, OnDone(nullptr)) 640 EXPECT_CALL(host_channel_callback_, OnDone(nullptr))
629 .WillOnce(QuitThread()); 641 .WillOnce(QuitThread());
630 ExpectRouteChange(kChannelName); 642 ExpectRouteChange(kChannelName);
631 643
632 message_loop_->Run(); 644 message_loop_->Run();
633 645
634 client_session_->GetTransportChannelFactory()->CancelChannelCreation( 646 client_session_->GetTransportSession()
635 kChannelName); 647 ->GetStreamChannelFactory()
648 ->CancelChannelCreation(kChannelName);
636 649
637 EXPECT_TRUE(!host_socket_.get()); 650 EXPECT_TRUE(!host_socket_.get());
638 } 651 }
639 652
640 TEST_F(JingleSessionTest, TestCancelChannelCreation) { 653 TEST_F(JingleSessionTest, TestCancelChannelCreation) {
641 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL); 654 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL);
642 ASSERT_NO_FATAL_FAILURE( 655 ASSERT_NO_FATAL_FAILURE(
643 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); 656 InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
644 657
645 client_session_->GetTransportChannelFactory()->CreateChannel( 658 client_session_->GetTransportSession()
646 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, 659 ->GetStreamChannelFactory()
647 base::Unretained(this))); 660 ->CreateChannel(kChannelName,
648 client_session_->GetTransportChannelFactory()->CancelChannelCreation( 661 base::Bind(&JingleSessionTest::OnClientChannelCreated,
649 kChannelName); 662 base::Unretained(this)));
663 client_session_->GetTransportSession()
664 ->GetStreamChannelFactory()
665 ->CancelChannelCreation(kChannelName);
650 666
651 EXPECT_TRUE(!client_socket_.get()); 667 EXPECT_TRUE(!client_socket_.get());
652 } 668 }
653 669
654 // Verify that we can still connect even when there is a delay in signaling 670 // Verify that we can still connect even when there is a delay in signaling
655 // messages delivery. 671 // messages delivery.
656 TEST_F(JingleSessionTest, TestDelayedSignaling) { 672 TEST_F(JingleSessionTest, TestDelayedSignaling) {
657 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 673 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
658 ASSERT_NO_FATAL_FAILURE( 674 ASSERT_NO_FATAL_FAILURE(
659 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); 675 InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
660 676
661 host_signal_strategy_->set_send_delay( 677 host_signal_strategy_->set_send_delay(
662 base::TimeDelta::FromMilliseconds(100)); 678 base::TimeDelta::FromMilliseconds(100));
663 679
664 ASSERT_NO_FATAL_FAILURE(CreateChannel()); 680 ASSERT_NO_FATAL_FAILURE(CreateChannel());
665 681
666 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), 682 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
667 kMessageSize, 1); 683 kMessageSize, 1);
668 tester.Start(); 684 tester.Start();
669 message_loop_->Run(); 685 message_loop_->Run();
670 tester.CheckResults(); 686 tester.CheckResults();
671 } 687 }
672 688
673 } // namespace protocol 689 } // namespace protocol
674 } // namespace remoting 690 } // 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