Chromium Code Reviews| 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/connection_tester.h" | 5 #include "remoting/protocol/connection_tester.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/single_thread_task_runner.h" | |
| 9 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 #include "remoting/proto/video.pb.h" | 12 #include "remoting/proto/video.pb.h" |
| 12 #include "remoting/protocol/message_pipe.h" | 13 #include "remoting/protocol/message_pipe.h" |
| 13 #include "remoting/protocol/message_serialization.h" | 14 #include "remoting/protocol/message_serialization.h" |
| 14 #include "remoting/protocol/p2p_datagram_socket.h" | 15 #include "remoting/protocol/p2p_datagram_socket.h" |
| 15 #include "remoting/protocol/p2p_stream_socket.h" | 16 #include "remoting/protocol/p2p_stream_socket.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 namespace remoting { | 19 namespace remoting { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 49 | 50 |
| 50 output_buffer_->SetOffset(0); | 51 output_buffer_->SetOffset(0); |
| 51 ASSERT_EQ(test_data_size_, output_buffer_->size()); | 52 ASSERT_EQ(test_data_size_, output_buffer_->size()); |
| 52 | 53 |
| 53 EXPECT_EQ(0, memcmp(output_buffer_->data(), | 54 EXPECT_EQ(0, memcmp(output_buffer_->data(), |
| 54 input_buffer_->StartOfBuffer(), test_data_size_)); | 55 input_buffer_->StartOfBuffer(), test_data_size_)); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void StreamConnectionTester::Done() { | 58 void StreamConnectionTester::Done() { |
| 58 done_ = true; | 59 done_ = true; |
| 59 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 60 message_loop_->task_runner()->PostTask( |
| 61 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
| 60 } | 62 } |
| 61 | 63 |
| 62 void StreamConnectionTester::InitBuffers() { | 64 void StreamConnectionTester::InitBuffers() { |
| 63 output_buffer_ = new net::DrainableIOBuffer( | 65 output_buffer_ = new net::DrainableIOBuffer( |
| 64 new net::IOBuffer(test_data_size_), test_data_size_); | 66 new net::IOBuffer(test_data_size_), test_data_size_); |
| 65 for (int i = 0; i < test_data_size_; ++i) { | 67 for (int i = 0; i < test_data_size_; ++i) { |
| 66 output_buffer_->data()[i] = static_cast<char>(i); | 68 output_buffer_->data()[i] = static_cast<char>(i); |
| 67 } | 69 } |
| 68 | 70 |
| 69 input_buffer_ = new net::GrowableIOBuffer(); | 71 input_buffer_ = new net::GrowableIOBuffer(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 Done(); | 132 Done(); |
| 131 } | 133 } |
| 132 } | 134 } |
| 133 | 135 |
| 134 DatagramConnectionTester::DatagramConnectionTester( | 136 DatagramConnectionTester::DatagramConnectionTester( |
| 135 P2PDatagramSocket* client_socket, | 137 P2PDatagramSocket* client_socket, |
| 136 P2PDatagramSocket* host_socket, | 138 P2PDatagramSocket* host_socket, |
| 137 int message_size, | 139 int message_size, |
| 138 int message_count, | 140 int message_count, |
| 139 int delay_ms) | 141 int delay_ms) |
| 140 : message_loop_(base::MessageLoop::current()), | 142 : message_loop_(base::MessageLoop::current()), |
|
gab
2016/06/30 20:28:18
This could be TaskRunnerHandle and then no need fo
fdoray
2016/07/04 13:59:46
Done.
| |
| 141 host_socket_(host_socket), | 143 host_socket_(host_socket), |
| 142 client_socket_(client_socket), | 144 client_socket_(client_socket), |
| 143 message_size_(message_size), | 145 message_size_(message_size), |
| 144 message_count_(message_count), | 146 message_count_(message_count), |
| 145 delay_ms_(delay_ms), | 147 delay_ms_(delay_ms), |
| 146 done_(false), | 148 done_(false), |
| 147 write_errors_(0), | 149 write_errors_(0), |
| 148 read_errors_(0), | 150 read_errors_(0), |
| 149 packets_sent_(0), | 151 packets_sent_(0), |
| 150 packets_received_(0), | 152 packets_received_(0), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 167 EXPECT_EQ(0, bad_packets_received_); | 169 EXPECT_EQ(0, bad_packets_received_); |
| 168 | 170 |
| 169 // Verify that we've received at least one packet. | 171 // Verify that we've received at least one packet. |
| 170 EXPECT_GT(packets_received_, 0); | 172 EXPECT_GT(packets_received_, 0); |
| 171 VLOG(0) << "Received " << packets_received_ << " packets out of " | 173 VLOG(0) << "Received " << packets_received_ << " packets out of " |
| 172 << message_count_; | 174 << message_count_; |
| 173 } | 175 } |
| 174 | 176 |
| 175 void DatagramConnectionTester::Done() { | 177 void DatagramConnectionTester::Done() { |
| 176 done_ = true; | 178 done_ = true; |
| 177 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 179 message_loop_->task_runner()->PostTask( |
| 180 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
| 178 } | 181 } |
| 179 | 182 |
| 180 void DatagramConnectionTester::DoWrite() { | 183 void DatagramConnectionTester::DoWrite() { |
| 181 if (packets_sent_ >= message_count_) { | 184 if (packets_sent_ >= message_count_) { |
| 182 Done(); | 185 Done(); |
| 183 return; | 186 return; |
| 184 } | 187 } |
| 185 | 188 |
| 186 scoped_refptr<net::IOBuffer> packet(new net::IOBuffer(message_size_)); | 189 scoped_refptr<net::IOBuffer> packet(new net::IOBuffer(message_size_)); |
| 187 for (int i = 0; i < message_size_; ++i) { | 190 for (int i = 0; i < message_size_; ++i) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 202 } | 205 } |
| 203 | 206 |
| 204 void DatagramConnectionTester::HandleWriteResult(int result) { | 207 void DatagramConnectionTester::HandleWriteResult(int result) { |
| 205 if (result <= 0 && result != net::ERR_IO_PENDING) { | 208 if (result <= 0 && result != net::ERR_IO_PENDING) { |
| 206 LOG(ERROR) << "Received error " << result << " when trying to write"; | 209 LOG(ERROR) << "Received error " << result << " when trying to write"; |
| 207 write_errors_++; | 210 write_errors_++; |
| 208 Done(); | 211 Done(); |
| 209 } else if (result > 0) { | 212 } else if (result > 0) { |
| 210 EXPECT_EQ(message_size_, result); | 213 EXPECT_EQ(message_size_, result); |
| 211 packets_sent_++; | 214 packets_sent_++; |
| 212 message_loop_->PostDelayedTask( | 215 message_loop_->task_runner()->PostDelayedTask( |
| 213 FROM_HERE, | 216 FROM_HERE, |
| 214 base::Bind(&DatagramConnectionTester::DoWrite, base::Unretained(this)), | 217 base::Bind(&DatagramConnectionTester::DoWrite, base::Unretained(this)), |
| 215 base::TimeDelta::FromMilliseconds(delay_ms_)); | 218 base::TimeDelta::FromMilliseconds(delay_ms_)); |
| 216 } | 219 } |
| 217 } | 220 } |
| 218 | 221 |
| 219 void DatagramConnectionTester::DoRead() { | 222 void DatagramConnectionTester::DoRead() { |
| 220 int result = 1; | 223 int result = 1; |
| 221 while (result > 0) { | 224 while (result > 0) { |
| 222 int kReadSize = message_size_ * 2; | 225 int kReadSize = message_size_ * 2; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 void MessagePipeConnectionTester::OnMessageReceived( | 299 void MessagePipeConnectionTester::OnMessageReceived( |
| 297 std::unique_ptr<CompoundBuffer> message) { | 300 std::unique_ptr<CompoundBuffer> message) { |
| 298 received_messages_.push_back(ParseMessage<VideoPacket>(message.get())); | 301 received_messages_.push_back(ParseMessage<VideoPacket>(message.get())); |
| 299 if (received_messages_.size() >= sent_messages_.size()) { | 302 if (received_messages_.size() >= sent_messages_.size()) { |
| 300 run_loop_.Quit(); | 303 run_loop_.Quit(); |
| 301 } | 304 } |
| 302 } | 305 } |
| 303 | 306 |
| 304 } // namespace protocol | 307 } // namespace protocol |
| 305 } // namespace remoting | 308 } // namespace remoting |
| OLD | NEW |