OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 212 |
213 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 213 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
214 .WillOnce(DoAll( | 214 .WillOnce(DoAll( |
215 WithArg<0>(Invoke( | 215 WithArg<0>(Invoke( |
216 this, &JingleSessionTest::SetHostSession)), | 216 this, &JingleSessionTest::SetHostSession)), |
217 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); | 217 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); |
218 | 218 |
219 { | 219 { |
220 InSequence dummy; | 220 InSequence dummy; |
221 | 221 |
222 if (shared_secret == kTestSharedSecret) { | 222 EXPECT_CALL(host_connection_callback_, |
223 EXPECT_CALL(host_connection_callback_, | 223 OnStateChange(Session::CONNECTED)) |
224 OnStateChange(Session::CONNECTED)) | 224 .Times(1) |
225 .Times(1); | 225 .WillOnce(QuitThreadOnCounter(¬_connected_peers)); |
226 EXPECT_CALL(host_connection_callback_, | 226 // Expect that the connection will be closed eventually. |
227 OnStateChange(Session::CONNECTED_CHANNELS)) | 227 EXPECT_CALL(host_connection_callback_, |
228 .Times(1) | 228 OnStateChange(Session::CLOSED)) |
229 .WillOnce(QuitThreadOnCounter(¬_connected_peers)); | 229 .Times(AtMost(1)); |
230 // Expect that the connection will be closed eventually. | |
231 EXPECT_CALL(host_connection_callback_, | |
232 OnStateChange(Session::CLOSED)) | |
233 .Times(AtMost(1)); | |
234 } else { | |
235 // Might pass through the CONNECTED state. | |
236 EXPECT_CALL(host_connection_callback_, | |
237 OnStateChange(Session::CONNECTED)) | |
238 .Times(AtMost(1)); | |
239 EXPECT_CALL(host_connection_callback_, | |
240 OnStateChange(Session::CONNECTED_CHANNELS)) | |
241 .Times(AtMost(1)); | |
242 // Expect that the connection will fail. | |
243 EXPECT_CALL(host_connection_callback_, | |
244 OnStateChange(Session::FAILED)) | |
245 .Times(1) | |
246 .WillOnce(InvokeWithoutArgs(&QuitCurrentThread)); | |
247 } | |
248 } | 230 } |
249 | 231 |
250 { | 232 { |
251 InSequence dummy; | 233 InSequence dummy; |
252 | 234 |
253 EXPECT_CALL(client_connection_callback_, | 235 EXPECT_CALL(client_connection_callback_, |
254 OnStateChange(Session::CONNECTING)) | 236 OnStateChange(Session::CONNECTING)) |
255 .Times(1); | 237 .Times(1); |
256 if (shared_secret == kTestSharedSecret) { | 238 EXPECT_CALL(client_connection_callback_, |
257 EXPECT_CALL(client_connection_callback_, | 239 OnStateChange(Session::CONNECTED)) |
258 OnStateChange(Session::CONNECTED)) | 240 .Times(1) |
259 .Times(1); | 241 .WillOnce(QuitThreadOnCounter(¬_connected_peers)); |
260 EXPECT_CALL(client_connection_callback_, | |
261 OnStateChange(Session::CONNECTED_CHANNELS)) | |
262 .Times(1) | |
263 .WillOnce(QuitThreadOnCounter(¬_connected_peers)); | |
264 } else { | |
265 EXPECT_CALL(client_connection_callback_, | |
266 OnStateChange(Session::CONNECTED)) | |
267 .Times(AtMost(1)); | |
268 EXPECT_CALL(client_connection_callback_, | |
269 OnStateChange(Session::CONNECTED_CHANNELS)) | |
270 .Times(AtMost(1)); | |
271 } | |
272 // Expect that the connection will be closed eventually. | 242 // Expect that the connection will be closed eventually. |
273 EXPECT_CALL(client_connection_callback_, | 243 EXPECT_CALL(client_connection_callback_, |
274 OnStateChange(Session::CLOSED)) | 244 OnStateChange(Session::CLOSED)) |
275 .Times(AtMost(1)); | 245 .Times(AtMost(1)); |
276 } | 246 } |
277 | 247 |
278 client_session_.reset(client_server_->Connect( | 248 client_session_.reset(client_server_->Connect( |
279 kHostJid, kTestHostPublicKey, kTestToken, | 249 kHostJid, kTestHostPublicKey, kTestToken, |
280 CandidateSessionConfig::CreateDefault(), | 250 CandidateSessionConfig::CreateDefault(), |
281 base::Bind(&MockSessionCallback::OnStateChange, | 251 base::Bind(&MockSessionCallback::OnStateChange, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 read_cb_(this, &TCPChannelTester::OnRead)), | 331 read_cb_(this, &TCPChannelTester::OnRead)), |
362 write_errors_(0), | 332 write_errors_(0), |
363 read_errors_(0), | 333 read_errors_(0), |
364 message_size_(message_size), | 334 message_size_(message_size), |
365 message_count_(message_count), | 335 message_count_(message_count), |
366 test_data_size_(message_size * message_count) { | 336 test_data_size_(message_size * message_count) { |
367 } | 337 } |
368 | 338 |
369 virtual ~TCPChannelTester() { } | 339 virtual ~TCPChannelTester() { } |
370 | 340 |
| 341 virtual bool did_initialization_fail() { |
| 342 return !sockets_[0].get() || !sockets_[1].get(); |
| 343 } |
| 344 |
371 virtual void CheckResults() { | 345 virtual void CheckResults() { |
| 346 ASSERT_FALSE(did_initialization_fail()); |
| 347 |
372 EXPECT_EQ(0, write_errors_); | 348 EXPECT_EQ(0, write_errors_); |
373 EXPECT_EQ(0, read_errors_); | 349 EXPECT_EQ(0, read_errors_); |
374 | 350 |
375 ASSERT_EQ(test_data_size_, input_buffer_->offset()); | 351 ASSERT_EQ(test_data_size_, input_buffer_->offset()); |
376 | 352 |
377 output_buffer_->SetOffset(0); | 353 output_buffer_->SetOffset(0); |
378 ASSERT_EQ(test_data_size_, output_buffer_->size()); | 354 ASSERT_EQ(test_data_size_, output_buffer_->size()); |
379 | 355 |
380 EXPECT_EQ(0, memcmp(output_buffer_->data(), | 356 EXPECT_EQ(0, memcmp(output_buffer_->data(), |
381 input_buffer_->StartOfBuffer(), test_data_size_)); | 357 input_buffer_->StartOfBuffer(), test_data_size_)); |
382 } | 358 } |
383 | 359 |
384 protected: | 360 protected: |
385 virtual void InitChannels() OVERRIDE { | 361 virtual void InitChannels() OVERRIDE { |
386 host_session_->CreateStreamChannel( | 362 host_session_->CreateStreamChannel( |
387 kChannelName, | 363 kChannelName, |
388 base::Bind(&TCPChannelTester::OnChannelReady, | 364 base::Bind(&TCPChannelTester::OnChannelReady, |
389 base::Unretained(this), 0)); | 365 base::Unretained(this), 0)); |
390 client_session_->CreateStreamChannel( | 366 client_session_->CreateStreamChannel( |
391 kChannelName, | 367 kChannelName, |
392 base::Bind(&TCPChannelTester::OnChannelReady, | 368 base::Bind(&TCPChannelTester::OnChannelReady, |
393 base::Unretained(this), 1)); | 369 base::Unretained(this), 1)); |
394 } | 370 } |
395 | 371 |
396 void OnChannelReady(int id, net::StreamSocket* socket) { | 372 void OnChannelReady(int id, net::StreamSocket* socket) { |
397 ASSERT_TRUE(socket); | |
398 if (!socket) { | 373 if (!socket) { |
399 Done(); | 374 Done(); |
400 return; | 375 return; |
401 } | 376 } |
402 | 377 |
403 DCHECK(id >= 0 && id < 2); | 378 DCHECK(id >= 0 && id < 2); |
404 sockets_[id].reset(socket); | 379 sockets_[id].reset(socket); |
405 | 380 |
406 if (sockets_[0].get() && sockets_[1].get()) { | 381 if (sockets_[0].get() && sockets_[1].get()) { |
407 InitBuffers(); | 382 InitBuffers(); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 // Verify that we can connect two endpoints. | 682 // Verify that we can connect two endpoints. |
708 TEST_F(JingleSessionTest, Connect) { | 683 TEST_F(JingleSessionTest, Connect) { |
709 CreateServerPair(); | 684 CreateServerPair(); |
710 ASSERT_TRUE(InitiateConnection(kTestSharedSecret)); | 685 ASSERT_TRUE(InitiateConnection(kTestSharedSecret)); |
711 } | 686 } |
712 | 687 |
713 // Verify that we can't connect two endpoints with mismatched secrets. | 688 // Verify that we can't connect two endpoints with mismatched secrets. |
714 TEST_F(JingleSessionTest, ConnectBadChannelAuth) { | 689 TEST_F(JingleSessionTest, ConnectBadChannelAuth) { |
715 CreateServerPair(); | 690 CreateServerPair(); |
716 ASSERT_TRUE(InitiateConnection(kTestSharedSecretBad)); | 691 ASSERT_TRUE(InitiateConnection(kTestSharedSecretBad)); |
| 692 scoped_refptr<TCPChannelTester> tester( |
| 693 new TCPChannelTester(host_session_.get(), client_session_.get(), |
| 694 kMessageSize, kMessages)); |
| 695 tester->Start(); |
| 696 ASSERT_TRUE(tester->WaitFinished()); |
| 697 EXPECT_TRUE(tester->did_initialization_fail()); |
| 698 |
| 699 CloseSessions(); |
717 } | 700 } |
718 | 701 |
719 // Verify that data can be transmitted over the event channel. | 702 // Verify that data can be transmitted over the event channel. |
720 TEST_F(JingleSessionTest, TestTcpChannel) { | 703 TEST_F(JingleSessionTest, TestTcpChannel) { |
721 CreateServerPair(); | 704 CreateServerPair(); |
722 ASSERT_TRUE(InitiateConnection(kTestSharedSecret)); | 705 ASSERT_TRUE(InitiateConnection(kTestSharedSecret)); |
723 scoped_refptr<TCPChannelTester> tester( | 706 scoped_refptr<TCPChannelTester> tester( |
724 new TCPChannelTester(host_session_.get(), client_session_.get(), | 707 new TCPChannelTester(host_session_.get(), client_session_.get(), |
725 kMessageSize, kMessages)); | 708 kMessageSize, kMessages)); |
726 tester->Start(); | 709 tester->Start(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 ASSERT_TRUE(tester->WaitFinished()); | 771 ASSERT_TRUE(tester->WaitFinished()); |
789 LOG(INFO) << "Time for 500k bytes " | 772 LOG(INFO) << "Time for 500k bytes " |
790 << tester->GetElapsedTime().InMilliseconds() << " ms."; | 773 << tester->GetElapsedTime().InMilliseconds() << " ms."; |
791 | 774 |
792 // Connections must be closed while |tester| still exists. | 775 // Connections must be closed while |tester| still exists. |
793 CloseSessions(); | 776 CloseSessions(); |
794 } | 777 } |
795 | 778 |
796 } // namespace protocol | 779 } // namespace protocol |
797 } // namespace remoting | 780 } // namespace remoting |
OLD | NEW |