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/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 MessagePipe* host_pipe, | 265 MessagePipe* host_pipe, |
266 int message_size, | 266 int message_size, |
267 int message_count) | 267 int message_count) |
268 : host_pipe_(host_pipe), | 268 : host_pipe_(host_pipe), |
269 client_pipe_(client_pipe), | 269 client_pipe_(client_pipe), |
270 message_size_(message_size), | 270 message_size_(message_size), |
271 message_count_(message_count) {} | 271 message_count_(message_count) {} |
272 MessagePipeConnectionTester::~MessagePipeConnectionTester() {} | 272 MessagePipeConnectionTester::~MessagePipeConnectionTester() {} |
273 | 273 |
274 void MessagePipeConnectionTester::RunAndCheckResults() { | 274 void MessagePipeConnectionTester::RunAndCheckResults() { |
275 host_pipe_->StartReceiving(base::Bind( | 275 host_pipe_->Start(this); |
276 &MessagePipeConnectionTester::OnMessageReceived, base::Unretained(this))); | |
277 | 276 |
278 for (int i = 0; i < message_count_; ++i) { | 277 for (int i = 0; i < message_count_; ++i) { |
279 std::unique_ptr<VideoPacket> message(new VideoPacket()); | 278 std::unique_ptr<VideoPacket> message(new VideoPacket()); |
280 message->mutable_data()->resize(message_size_); | 279 message->mutable_data()->resize(message_size_); |
281 for (int p = 0; p < message_size_; ++p) { | 280 for (int p = 0; p < message_size_; ++p) { |
282 message->mutable_data()[0] = static_cast<char>(i + p); | 281 message->mutable_data()[0] = static_cast<char>(i + p); |
283 } | 282 } |
284 client_pipe_->Send(message.get(), base::Closure()); | 283 client_pipe_->Send(message.get(), base::Closure()); |
285 sent_messages_.push_back(std::move(message)); | 284 sent_messages_.push_back(std::move(message)); |
286 } | 285 } |
287 | 286 |
288 run_loop_.Run(); | 287 run_loop_.Run(); |
289 | 288 |
290 ASSERT_EQ(sent_messages_.size(), received_messages_.size()); | 289 ASSERT_EQ(sent_messages_.size(), received_messages_.size()); |
291 for (size_t i = 0; i < sent_messages_.size(); ++i) { | 290 for (size_t i = 0; i < sent_messages_.size(); ++i) { |
292 EXPECT_TRUE(sent_messages_[i]->data() == received_messages_[i]->data()); | 291 EXPECT_TRUE(sent_messages_[i]->data() == received_messages_[i]->data()); |
293 } | 292 } |
294 } | 293 } |
295 | 294 |
296 void MessagePipeConnectionTester::OnMessageReceived( | 295 void MessagePipeConnectionTester::OnMessageReceived( |
297 std::unique_ptr<CompoundBuffer> message) { | 296 std::unique_ptr<CompoundBuffer> message) { |
298 received_messages_.push_back(ParseMessage<VideoPacket>(message.get())); | 297 received_messages_.push_back(ParseMessage<VideoPacket>(message.get())); |
299 if (received_messages_.size() >= sent_messages_.size()) { | 298 if (received_messages_.size() >= sent_messages_.size()) { |
300 run_loop_.Quit(); | 299 run_loop_.Quit(); |
301 } | 300 } |
302 } | 301 } |
303 | 302 |
| 303 void MessagePipeConnectionTester::OnMessagePipeClosed() { |
| 304 run_loop_.Quit(); |
| 305 FAIL(); |
| 306 } |
| 307 |
304 } // namespace protocol | 308 } // namespace protocol |
305 } // namespace remoting | 309 } // namespace remoting |
OLD | NEW |