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/ice_transport_factory.h" | 22 #include "remoting/protocol/ice_transport_factory.h" |
23 #include "remoting/protocol/jingle_session_manager.h" | 23 #include "remoting/protocol/jingle_session_manager.h" |
24 #include "remoting/protocol/network_settings.h" | 24 #include "remoting/protocol/network_settings.h" |
25 #include "remoting/protocol/p2p_stream_socket.h" | |
26 #include "remoting/protocol/stream_channel_factory.h" | |
27 #include "remoting/signaling/fake_signal_strategy.h" | 25 #include "remoting/signaling/fake_signal_strategy.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
30 | 28 |
31 using testing::_; | 29 using testing::_; |
32 using testing::AtLeast; | 30 using testing::AtLeast; |
33 using testing::AtMost; | 31 using testing::AtMost; |
34 using testing::DeleteArg; | 32 using testing::DeleteArg; |
35 using testing::DoAll; | 33 using testing::DoAll; |
36 using testing::InSequence; | 34 using testing::InSequence; |
37 using testing::Invoke; | 35 using testing::Invoke; |
38 using testing::InvokeWithoutArgs; | 36 using testing::InvokeWithoutArgs; |
39 using testing::Return; | 37 using testing::Return; |
40 using testing::SaveArg; | 38 using testing::SaveArg; |
41 using testing::SetArgumentPointee; | 39 using testing::SetArgumentPointee; |
42 using testing::WithArg; | 40 using testing::WithArg; |
43 | 41 |
44 namespace remoting { | 42 namespace remoting { |
45 namespace protocol { | 43 namespace protocol { |
46 | 44 |
47 namespace { | 45 namespace { |
48 | 46 |
49 const char kHostJid[] = "host1@gmail.com/123"; | 47 const char kHostJid[] = "host1@gmail.com/123"; |
50 const char kClientJid[] = "host2@gmail.com/321"; | 48 const char kClientJid[] = "host2@gmail.com/321"; |
51 | 49 |
52 // Send 100 messages 1024 bytes each. UDP messages are sent with 10ms delay | |
53 // between messages (about 1 second for 100 messages). | |
54 const int kMessageSize = 1024; | |
55 const int kMessages = 100; | |
56 const char kChannelName[] = "test_channel"; | |
57 | |
58 void QuitCurrentThread() { | |
59 base::MessageLoop::current()->PostTask( | |
60 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
61 } | |
62 | |
63 ACTION(QuitThread) { | |
64 QuitCurrentThread(); | |
65 } | |
66 | |
67 ACTION_P(QuitThreadOnCounter, counter) { | |
68 --(*counter); | |
69 EXPECT_GE(*counter, 0); | |
70 if (*counter == 0) | |
71 QuitCurrentThread(); | |
72 } | |
73 | |
74 class MockSessionManagerListener : public SessionManager::Listener { | 50 class MockSessionManagerListener : public SessionManager::Listener { |
75 public: | 51 public: |
76 MOCK_METHOD0(OnSessionManagerReady, void()); | 52 MOCK_METHOD0(OnSessionManagerReady, void()); |
77 MOCK_METHOD2(OnIncomingSession, | 53 MOCK_METHOD2(OnIncomingSession, |
78 void(Session*, | 54 void(Session*, |
79 SessionManager::IncomingSessionResponse*)); | 55 SessionManager::IncomingSessionResponse*)); |
80 }; | 56 }; |
81 | 57 |
82 class MockSessionEventHandler : public Session::EventHandler { | 58 class MockSessionEventHandler : public Session::EventHandler { |
83 public: | 59 public: |
84 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); | 60 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); |
85 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, | 61 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, |
86 const TransportRoute& route)); | 62 const TransportRoute& route)); |
87 }; | 63 }; |
88 | 64 |
89 class MockChannelCreatedCallback { | |
90 public: | |
91 MOCK_METHOD1(OnDone, void(P2PStreamSocket* socket)); | |
92 }; | |
93 | |
94 } // namespace | 65 } // namespace |
95 | 66 |
96 class JingleSessionTest : public testing::Test { | 67 class JingleSessionTest : public testing::Test { |
97 public: | 68 public: |
98 JingleSessionTest() { | 69 JingleSessionTest() { |
99 message_loop_.reset(new base::MessageLoopForIO()); | 70 message_loop_.reset(new base::MessageLoopForIO()); |
100 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 71 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
101 network_settings_ = | 72 network_settings_ = |
102 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); | 73 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); |
103 } | 74 } |
104 | 75 |
105 // Helper method that handles OnIncomingSession(). | 76 // Helper method that handles OnIncomingSession(). |
106 void SetHostSession(Session* session) { | 77 void SetHostSession(Session* session) { |
107 DCHECK(session); | 78 DCHECK(session); |
108 host_session_.reset(session); | 79 host_session_.reset(session); |
109 host_session_->SetEventHandler(&host_session_event_handler_); | 80 host_session_->SetEventHandler(&host_session_event_handler_); |
110 } | 81 } |
111 | 82 |
112 void DeleteSession() { | 83 void DeleteSession() { |
113 host_session_.reset(); | 84 host_session_.reset(); |
114 } | 85 } |
115 | 86 |
116 void OnClientChannelCreated(scoped_ptr<P2PStreamSocket> socket) { | |
117 client_channel_callback_.OnDone(socket.get()); | |
118 client_socket_ = socket.Pass(); | |
119 } | |
120 | |
121 void OnHostChannelCreated(scoped_ptr<P2PStreamSocket> socket) { | |
122 host_channel_callback_.OnDone(socket.get()); | |
123 host_socket_ = socket.Pass(); | |
124 } | |
125 | |
126 protected: | 87 protected: |
127 void TearDown() override { | 88 void TearDown() override { |
128 CloseSessions(); | 89 CloseSessions(); |
129 CloseSessionManager(); | 90 CloseSessionManager(); |
130 base::RunLoop().RunUntilIdle(); | 91 base::RunLoop().RunUntilIdle(); |
131 } | 92 } |
132 | 93 |
133 void CloseSessions() { | 94 void CloseSessions() { |
134 host_socket_.reset(); | |
135 host_session_.reset(); | 95 host_session_.reset(); |
136 client_socket_.reset(); | |
137 client_session_.reset(); | 96 client_session_.reset(); |
138 } | 97 } |
139 | 98 |
140 void CreateSessionManagers(int auth_round_trips, int messages_till_start, | 99 void CreateSessionManagers(int auth_round_trips, int messages_till_start, |
141 FakeAuthenticator::Action auth_action) { | 100 FakeAuthenticator::Action auth_action) { |
142 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid)); | 101 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid)); |
143 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid)); | 102 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid)); |
144 FakeSignalStrategy::Connect(host_signal_strategy_.get(), | 103 FakeSignalStrategy::Connect(host_signal_strategy_.get(), |
145 client_signal_strategy_.get()); | 104 client_signal_strategy_.get()); |
146 | 105 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 206 |
248 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( | 207 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( |
249 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); | 208 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); |
250 | 209 |
251 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); | 210 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); |
252 client_session_->SetEventHandler(&client_session_event_handler_); | 211 client_session_->SetEventHandler(&client_session_event_handler_); |
253 | 212 |
254 base::RunLoop().RunUntilIdle(); | 213 base::RunLoop().RunUntilIdle(); |
255 } | 214 } |
256 | 215 |
257 void CreateChannel() { | |
258 client_session_->GetTransport()->GetStreamChannelFactory()->CreateChannel( | |
259 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, | |
260 base::Unretained(this))); | |
261 host_session_->GetTransport()->GetStreamChannelFactory()->CreateChannel( | |
262 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, | |
263 base::Unretained(this))); | |
264 | |
265 int counter = 2; | |
266 ExpectRouteChange(kChannelName); | |
267 EXPECT_CALL(client_channel_callback_, OnDone(_)) | |
268 .WillOnce(QuitThreadOnCounter(&counter)); | |
269 EXPECT_CALL(host_channel_callback_, OnDone(_)) | |
270 .WillOnce(QuitThreadOnCounter(&counter)); | |
271 message_loop_->Run(); | |
272 | |
273 EXPECT_TRUE(client_socket_.get()); | |
274 EXPECT_TRUE(host_socket_.get()); | |
275 } | |
276 | |
277 void ExpectRouteChange(const std::string& channel_name) { | 216 void ExpectRouteChange(const std::string& channel_name) { |
278 EXPECT_CALL(host_session_event_handler_, | 217 EXPECT_CALL(host_session_event_handler_, |
279 OnSessionRouteChange(channel_name, _)) | 218 OnSessionRouteChange(channel_name, _)) |
280 .Times(AtLeast(1)); | 219 .Times(AtLeast(1)); |
281 EXPECT_CALL(client_session_event_handler_, | 220 EXPECT_CALL(client_session_event_handler_, |
282 OnSessionRouteChange(channel_name, _)) | 221 OnSessionRouteChange(channel_name, _)) |
283 .Times(AtLeast(1)); | 222 .Times(AtLeast(1)); |
284 } | 223 } |
285 | 224 |
286 scoped_ptr<base::MessageLoopForIO> message_loop_; | 225 scoped_ptr<base::MessageLoopForIO> message_loop_; |
287 | 226 |
288 NetworkSettings network_settings_; | 227 NetworkSettings network_settings_; |
289 | 228 |
290 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; | 229 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; |
291 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; | 230 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; |
292 | 231 |
293 scoped_ptr<JingleSessionManager> host_server_; | 232 scoped_ptr<JingleSessionManager> host_server_; |
294 MockSessionManagerListener host_server_listener_; | 233 MockSessionManagerListener host_server_listener_; |
295 scoped_ptr<JingleSessionManager> client_server_; | 234 scoped_ptr<JingleSessionManager> client_server_; |
296 MockSessionManagerListener client_server_listener_; | 235 MockSessionManagerListener client_server_listener_; |
297 | 236 |
298 scoped_ptr<Session> host_session_; | 237 scoped_ptr<Session> host_session_; |
299 MockSessionEventHandler host_session_event_handler_; | 238 MockSessionEventHandler host_session_event_handler_; |
300 scoped_ptr<Session> client_session_; | 239 scoped_ptr<Session> client_session_; |
301 MockSessionEventHandler client_session_event_handler_; | 240 MockSessionEventHandler client_session_event_handler_; |
302 | |
303 MockChannelCreatedCallback client_channel_callback_; | |
304 MockChannelCreatedCallback host_channel_callback_; | |
305 | |
306 scoped_ptr<P2PStreamSocket> client_socket_; | |
307 scoped_ptr<P2PStreamSocket> host_socket_; | |
308 }; | 241 }; |
309 | 242 |
310 | 243 |
311 // Verify that we can create and destroy session managers without a | 244 // Verify that we can create and destroy session managers without a |
312 // connection. | 245 // connection. |
313 TEST_F(JingleSessionTest, CreateAndDestoy) { | 246 TEST_F(JingleSessionTest, CreateAndDestoy) { |
314 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 247 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
315 } | 248 } |
316 | 249 |
317 // Verify that an incoming session can be rejected, and that the | 250 // Verify that an incoming session can be rejected, and that the |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 CreateSessionManagers(1, FakeAuthenticator::REJECT); | 298 CreateSessionManagers(1, FakeAuthenticator::REJECT); |
366 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); | 299 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); |
367 } | 300 } |
368 | 301 |
369 // Verify that connection is terminated when multi-step auth fails. | 302 // Verify that connection is terminated when multi-step auth fails. |
370 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { | 303 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { |
371 CreateSessionManagers(3, FakeAuthenticator::REJECT); | 304 CreateSessionManagers(3, FakeAuthenticator::REJECT); |
372 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); | 305 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); |
373 } | 306 } |
374 | 307 |
375 // Verify that data can be sent over stream channel. | |
376 TEST_F(JingleSessionTest, TestStreamChannel) { | |
377 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | |
378 ASSERT_NO_FATAL_FAILURE( | |
379 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | |
380 | |
381 ASSERT_NO_FATAL_FAILURE(CreateChannel()); | |
382 | |
383 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | |
384 kMessageSize, kMessages); | |
385 tester.Start(); | |
386 message_loop_->Run(); | |
387 tester.CheckResults(); | |
388 } | |
389 | |
390 // Verify that incompatible protocol configuration is handled properly. | 308 // Verify that incompatible protocol configuration is handled properly. |
391 TEST_F(JingleSessionTest, TestIncompatibleProtocol) { | 309 TEST_F(JingleSessionTest, TestIncompatibleProtocol) { |
392 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 310 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
393 | 311 |
394 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0); | 312 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0); |
395 | 313 |
396 EXPECT_CALL(client_session_event_handler_, | 314 EXPECT_CALL(client_session_event_handler_, |
397 OnSessionStateChange(Session::FAILED)) | 315 OnSessionStateChange(Session::FAILED)) |
398 .Times(1); | 316 .Times(1); |
399 | 317 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 OnSessionStateChange(Session::AUTHENTICATING)) | 401 OnSessionStateChange(Session::AUTHENTICATING)) |
484 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession)); | 402 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteSession)); |
485 | 403 |
486 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( | 404 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( |
487 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); | 405 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); |
488 | 406 |
489 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); | 407 client_session_ = client_server_->Connect(kHostJid, authenticator.Pass()); |
490 base::RunLoop().RunUntilIdle(); | 408 base::RunLoop().RunUntilIdle(); |
491 } | 409 } |
492 | 410 |
493 // Verify that data can be sent over a multiplexed channel. | 411 // Verify that we can connect with multistep authentication. |
494 TEST_F(JingleSessionTest, TestMuxStreamChannel) { | 412 TEST_F(JingleSessionTest, TestMultistepAuth) { |
495 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | |
496 ASSERT_NO_FATAL_FAILURE( | |
497 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | |
498 | |
499 client_session_->GetTransport() | |
500 ->GetMultiplexedChannelFactory() | |
501 ->CreateChannel(kChannelName, | |
502 base::Bind(&JingleSessionTest::OnClientChannelCreated, | |
503 base::Unretained(this))); | |
504 host_session_->GetTransport() | |
505 ->GetMultiplexedChannelFactory() | |
506 ->CreateChannel(kChannelName, | |
507 base::Bind(&JingleSessionTest::OnHostChannelCreated, | |
508 base::Unretained(this))); | |
509 | |
510 int counter = 2; | |
511 ExpectRouteChange("mux"); | |
512 EXPECT_CALL(client_channel_callback_, OnDone(_)) | |
513 .WillOnce(QuitThreadOnCounter(&counter)); | |
514 EXPECT_CALL(host_channel_callback_, OnDone(_)) | |
515 .WillOnce(QuitThreadOnCounter(&counter)); | |
516 message_loop_->Run(); | |
517 | |
518 EXPECT_TRUE(client_socket_.get()); | |
519 EXPECT_TRUE(host_socket_.get()); | |
520 | |
521 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | |
522 kMessageSize, kMessages); | |
523 tester.Start(); | |
524 message_loop_->Run(); | |
525 tester.CheckResults(); | |
526 } | |
527 | |
528 // Verify that channels are never marked connected if transport is broken. | |
529 TEST_F(JingleSessionTest, TestBrokenTransport) { | |
530 // Allow only incoming connections on both ends, which effectively renders P2P | |
531 // transport unusable. | |
532 network_settings_ = NetworkSettings(NetworkSettings::NAT_TRAVERSAL_DISABLED); | |
533 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | |
534 | |
535 scoped_ptr<CandidateSessionConfig> config = | |
536 CandidateSessionConfig::CreateDefault(); | |
537 config->PreferTransport(ChannelConfig::TRANSPORT_MUX_STREAM); | |
538 client_server_->set_protocol_config(config.Pass()); | |
539 | |
540 ASSERT_NO_FATAL_FAILURE( | |
541 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | |
542 | |
543 EXPECT_CALL(client_channel_callback_, OnDone(_)).Times(0); | |
544 EXPECT_CALL(host_channel_callback_, OnDone(_)).Times(0); | |
545 | |
546 client_session_->GetTransport() | |
547 ->GetMultiplexedChannelFactory() | |
548 ->CreateChannel(kChannelName, | |
549 base::Bind(&JingleSessionTest::OnClientChannelCreated, | |
550 base::Unretained(this))); | |
551 host_session_->GetTransport()->GetMultiplexedChannelFactory()->CreateChannel( | |
552 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, | |
553 base::Unretained(this))); | |
554 | |
555 message_loop_->RunUntilIdle(); | |
556 | |
557 // Verify that neither of the two ends of the channel is connected. | |
558 EXPECT_FALSE(client_socket_); | |
559 EXPECT_FALSE(host_socket_); | |
560 | |
561 client_session_->GetTransport() | |
562 ->GetMultiplexedChannelFactory() | |
563 ->CancelChannelCreation(kChannelName); | |
564 host_session_->GetTransport() | |
565 ->GetMultiplexedChannelFactory() | |
566 ->CancelChannelCreation(kChannelName); | |
567 } | |
568 | |
569 // Verify that we can connect channels with multistep auth. | |
570 TEST_F(JingleSessionTest, TestMultistepAuthStreamChannel) { | |
571 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 413 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
572 ASSERT_NO_FATAL_FAILURE( | 414 ASSERT_NO_FATAL_FAILURE( |
573 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); | 415 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); |
574 | |
575 ASSERT_NO_FATAL_FAILURE(CreateChannel()); | |
576 | |
577 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | |
578 kMessageSize, kMessages); | |
579 tester.Start(); | |
580 message_loop_->Run(); | |
581 tester.CheckResults(); | |
582 } | |
583 | |
584 // Verify that we shutdown properly when channel authentication fails. | |
585 TEST_F(JingleSessionTest, TestFailedChannelAuth) { | |
586 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL); | |
587 ASSERT_NO_FATAL_FAILURE( | |
588 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | |
589 | |
590 client_session_->GetTransport()->GetStreamChannelFactory()->CreateChannel( | |
591 kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated, | |
592 base::Unretained(this))); | |
593 host_session_->GetTransport()->GetStreamChannelFactory()->CreateChannel( | |
594 kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated, | |
595 base::Unretained(this))); | |
596 | |
597 // Terminate the message loop when we get rejection notification | |
598 // from the host. | |
599 EXPECT_CALL(host_channel_callback_, OnDone(nullptr)) | |
600 .WillOnce(QuitThread()); | |
601 ExpectRouteChange(kChannelName); | |
602 | |
603 message_loop_->Run(); | |
604 | |
605 client_session_->GetTransport() | |
606 ->GetStreamChannelFactory() | |
607 ->CancelChannelCreation(kChannelName); | |
608 | |
609 EXPECT_TRUE(!host_socket_.get()); | |
610 } | |
611 | |
612 TEST_F(JingleSessionTest, TestCancelChannelCreation) { | |
613 CreateSessionManagers(1, FakeAuthenticator::REJECT_CHANNEL); | |
614 ASSERT_NO_FATAL_FAILURE( | |
615 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | |
616 | |
617 client_session_->GetTransport() | |
618 ->GetStreamChannelFactory() | |
619 ->CreateChannel(kChannelName, | |
620 base::Bind(&JingleSessionTest::OnClientChannelCreated, | |
621 base::Unretained(this))); | |
622 client_session_->GetTransport() | |
623 ->GetStreamChannelFactory() | |
624 ->CancelChannelCreation(kChannelName); | |
625 | |
626 EXPECT_TRUE(!client_socket_.get()); | |
627 } | |
628 | |
629 // Verify that we can still connect even when there is a delay in signaling | |
630 // messages delivery. | |
631 TEST_F(JingleSessionTest, TestDelayedSignaling) { | |
632 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | |
633 ASSERT_NO_FATAL_FAILURE( | |
634 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); | |
635 | |
636 host_signal_strategy_->set_send_delay( | |
637 base::TimeDelta::FromMilliseconds(100)); | |
638 | |
639 ASSERT_NO_FATAL_FAILURE(CreateChannel()); | |
640 | |
641 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | |
642 kMessageSize, 1); | |
643 tester.Start(); | |
644 message_loop_->Run(); | |
645 tester.CheckResults(); | |
646 } | 416 } |
647 | 417 |
648 } // namespace protocol | 418 } // namespace protocol |
649 } // namespace remoting | 419 } // namespace remoting |
OLD | NEW |