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 "content/renderer/p2p/p2p_transport_impl.h" | 5 #include "content/renderer/p2p/p2p_transport_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 // Verify that we've received at least one packet. | 78 // Verify that we've received at least one packet. |
79 EXPECT_GT(packets_received_, 0); | 79 EXPECT_GT(packets_received_, 0); |
80 LOG(INFO) << "Received " << packets_received_ << " packets out of " | 80 LOG(INFO) << "Received " << packets_received_ << " packets out of " |
81 << kMessages; | 81 << kMessages; |
82 } | 82 } |
83 | 83 |
84 protected: | 84 protected: |
85 void Done() { | 85 void Done() { |
86 done_ = true; | 86 done_ = true; |
87 message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 87 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
88 } | 88 } |
89 | 89 |
90 void DoStart() { | 90 void DoStart() { |
91 DoRead(); | 91 DoRead(); |
92 DoWrite(); | 92 DoWrite(); |
93 } | 93 } |
94 | 94 |
95 void DoWrite() { | 95 void DoWrite() { |
96 if (packets_sent_ >= kMessages) { | 96 if (packets_sent_ >= kMessages) { |
97 Done(); | 97 Done(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 | 234 |
235 send_buffer_->SetOffset(0); | 235 send_buffer_->SetOffset(0); |
236 EXPECT_EQ(kTcpDataSize, static_cast<int>(received_data_.size())); | 236 EXPECT_EQ(kTcpDataSize, static_cast<int>(received_data_.size())); |
237 EXPECT_EQ(0, memcmp(send_buffer_->data(), | 237 EXPECT_EQ(0, memcmp(send_buffer_->data(), |
238 &received_data_[0], received_data_.size())); | 238 &received_data_[0], received_data_.size())); |
239 } | 239 } |
240 | 240 |
241 protected: | 241 protected: |
242 void Done() { | 242 void Done() { |
243 done_ = true; | 243 done_ = true; |
244 message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 244 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
245 } | 245 } |
246 | 246 |
247 void DoWrite() { | 247 void DoWrite() { |
248 if (send_buffer_->BytesRemaining() == 0) { | 248 if (send_buffer_->BytesRemaining() == 0) { |
249 return; | 249 return; |
250 } | 250 } |
251 | 251 |
252 int result = write_socket_->Write( | 252 int result = write_socket_->Write( |
253 send_buffer_, send_buffer_->BytesRemaining(), &write_cb_); | 253 send_buffer_, send_buffer_->BytesRemaining(), &write_cb_); |
254 HandleWriteResult(result); | 254 HandleWriteResult(result); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 EXPECT_CALL(event_handler2_, OnStateChange(P2PTransport::STATE_WRITABLE)) | 427 EXPECT_CALL(event_handler2_, OnStateChange(P2PTransport::STATE_WRITABLE)) |
428 .Times(AtMost(1)); | 428 .Times(AtMost(1)); |
429 EXPECT_CALL(event_handler2_, OnStateChange( | 429 EXPECT_CALL(event_handler2_, OnStateChange( |
430 static_cast<P2PTransport::State>(P2PTransport::STATE_READABLE | | 430 static_cast<P2PTransport::State>(P2PTransport::STATE_READABLE | |
431 P2PTransport::STATE_WRITABLE))) | 431 P2PTransport::STATE_WRITABLE))) |
432 .Times(Exactly(1)); | 432 .Times(Exactly(1)); |
433 | 433 |
434 scoped_refptr<UdpChannelTester> channel_tester = new UdpChannelTester( | 434 scoped_refptr<UdpChannelTester> channel_tester = new UdpChannelTester( |
435 &message_loop_, transport1_->GetChannel(), transport2_->GetChannel()); | 435 &message_loop_, transport1_->GetChannel(), transport2_->GetChannel()); |
436 | 436 |
437 message_loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask(), | 437 message_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
438 TestTimeouts::action_max_timeout_ms()); | 438 TestTimeouts::action_max_timeout_ms()); |
439 | 439 |
440 channel_tester->Start(); | 440 channel_tester->Start(); |
441 message_loop_.Run(); | 441 message_loop_.Run(); |
442 channel_tester->CheckResults(); | 442 channel_tester->CheckResults(); |
443 } | 443 } |
444 | 444 |
445 TEST_F(P2PTransportImplTest, SendDataTcp) { | 445 TEST_F(P2PTransportImplTest, SendDataTcp) { |
446 Init(P2PTransport::PROTOCOL_TCP); | 446 Init(P2PTransport::PROTOCOL_TCP); |
447 | 447 |
(...skipping 24 matching lines...) Expand all Loading... |
472 EXPECT_CALL(event_handler2_, OnStateChange(P2PTransport::STATE_WRITABLE)) | 472 EXPECT_CALL(event_handler2_, OnStateChange(P2PTransport::STATE_WRITABLE)) |
473 .Times(AtMost(1)); | 473 .Times(AtMost(1)); |
474 EXPECT_CALL(event_handler2_, OnStateChange( | 474 EXPECT_CALL(event_handler2_, OnStateChange( |
475 static_cast<P2PTransport::State>(P2PTransport::STATE_READABLE | | 475 static_cast<P2PTransport::State>(P2PTransport::STATE_READABLE | |
476 P2PTransport::STATE_WRITABLE))) | 476 P2PTransport::STATE_WRITABLE))) |
477 .Times(Exactly(1)) | 477 .Times(Exactly(1)) |
478 .WillOnce(InvokeWithoutArgs(channel_tester.get(), | 478 .WillOnce(InvokeWithoutArgs(channel_tester.get(), |
479 &TcpChannelTester::StartRead)) | 479 &TcpChannelTester::StartRead)) |
480 .RetiresOnSaturation(); | 480 .RetiresOnSaturation(); |
481 | 481 |
482 message_loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask(), | 482 message_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
483 TestTimeouts::action_max_timeout_ms()); | 483 TestTimeouts::action_max_timeout_ms()); |
484 | 484 |
485 channel_tester->Init(); | 485 channel_tester->Init(); |
486 message_loop_.Run(); | 486 message_loop_.Run(); |
487 channel_tester->CheckResults(); | 487 channel_tester->CheckResults(); |
488 } | 488 } |
489 | 489 |
490 } // namespace content | 490 } // namespace content |
OLD | NEW |