Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: remoting/protocol/connection_tester.cc

Issue 2757723002: Update ICE protocol to handle closed channel (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/connection_tester.h ('k') | remoting/protocol/fake_session.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 bad_packets_received_++; 253 bad_packets_received_++;
254 } else { 254 } else {
255 if (memcmp(read_buffer_->data(), sent_packets_[packet_id]->data(), 255 if (memcmp(read_buffer_->data(), sent_packets_[packet_id]->data(),
256 message_size_) != 0) 256 message_size_) != 0)
257 bad_packets_received_++; 257 bad_packets_received_++;
258 } 258 }
259 } 259 }
260 } 260 }
261 } 261 }
262 262
263 class MessagePipeConnectionTester::MessageSender
264 : public MessagePipe::EventHandler {
265 public:
266 MessageSender(MessagePipe* pipe, int message_size, int message_count)
267 : pipe_(pipe),
268 message_size_(message_size),
269 message_count_(message_count) {}
270
271 void Start() { pipe_->Start(this); }
272
273 const std::vector<std::unique_ptr<VideoPacket>>& sent_messages() {
274 return sent_messages_;
275 }
276
277 // MessagePipe::EventHandler interface.
278 void OnMessagePipeOpen() override {
279 for (int i = 0; i < message_count_; ++i) {
280 std::unique_ptr<VideoPacket> message(new VideoPacket());
281 message->mutable_data()->resize(message_size_);
282 for (int p = 0; p < message_size_; ++p) {
283 message->mutable_data()[0] = static_cast<char>(i + p);
284 }
285 pipe_->Send(message.get(), base::Closure());
286 sent_messages_.push_back(std::move(message));
287 }
288 }
289 void OnMessageReceived(std::unique_ptr<CompoundBuffer> message) override {
290 NOTREACHED();
291 }
292 void OnMessagePipeClosed() override { NOTREACHED(); }
293
294 private:
295 MessagePipe* pipe_;
296 int message_size_;
297 int message_count_;
298
299 std::vector<std::unique_ptr<VideoPacket>> sent_messages_;
300 };
301
263 MessagePipeConnectionTester::MessagePipeConnectionTester( 302 MessagePipeConnectionTester::MessagePipeConnectionTester(
303 MessagePipe* host_pipe,
264 MessagePipe* client_pipe, 304 MessagePipe* client_pipe,
265 MessagePipe* host_pipe,
266 int message_size, 305 int message_size,
267 int message_count) 306 int message_count)
268 : host_pipe_(host_pipe), 307 : client_pipe_(client_pipe),
269 client_pipe_(client_pipe), 308 sender_(new MessageSender(host_pipe, message_size, message_count)) {}
270 message_size_(message_size), 309
271 message_count_(message_count) {}
272 MessagePipeConnectionTester::~MessagePipeConnectionTester() {} 310 MessagePipeConnectionTester::~MessagePipeConnectionTester() {}
273 311
274 void MessagePipeConnectionTester::RunAndCheckResults() { 312 void MessagePipeConnectionTester::RunAndCheckResults() {
275 host_pipe_->Start(this); 313 sender_->Start();
276 } 314 client_pipe_->Start(this);
277
278 void MessagePipeConnectionTester::OnMessagePipeOpen() {
279 for (int i = 0; i < message_count_; ++i) {
280 std::unique_ptr<VideoPacket> message(new VideoPacket());
281 message->mutable_data()->resize(message_size_);
282 for (int p = 0; p < message_size_; ++p) {
283 message->mutable_data()[0] = static_cast<char>(i + p);
284 }
285 client_pipe_->Send(message.get(), base::Closure());
286 sent_messages_.push_back(std::move(message));
287 }
288 315
289 run_loop_.Run(); 316 run_loop_.Run();
290 317
291 ASSERT_EQ(sent_messages_.size(), received_messages_.size()); 318 ASSERT_EQ(sender_->sent_messages().size(), received_messages_.size());
292 for (size_t i = 0; i < sent_messages_.size(); ++i) { 319 for (size_t i = 0; i < sender_->sent_messages().size(); ++i) {
293 EXPECT_TRUE(sent_messages_[i]->data() == received_messages_[i]->data()); 320 EXPECT_TRUE(sender_->sent_messages()[i]->data() ==
321 received_messages_[i]->data());
294 } 322 }
295 } 323 }
296 324
325 void MessagePipeConnectionTester::OnMessagePipeOpen() {}
326
297 void MessagePipeConnectionTester::OnMessageReceived( 327 void MessagePipeConnectionTester::OnMessageReceived(
298 std::unique_ptr<CompoundBuffer> message) { 328 std::unique_ptr<CompoundBuffer> message) {
299 received_messages_.push_back(ParseMessage<VideoPacket>(message.get())); 329 received_messages_.push_back(ParseMessage<VideoPacket>(message.get()));
300 if (received_messages_.size() >= sent_messages_.size()) { 330 if (received_messages_.size() >= sender_->sent_messages().size()) {
301 run_loop_.Quit(); 331 run_loop_.Quit();
302 } 332 }
303 } 333 }
304 334
305 void MessagePipeConnectionTester::OnMessagePipeClosed() { 335 void MessagePipeConnectionTester::OnMessagePipeClosed() {
306 run_loop_.Quit(); 336 run_loop_.Quit();
307 FAIL(); 337 FAIL();
308 } 338 }
309 339
310 } // namespace protocol 340 } // namespace protocol
311 } // namespace remoting 341 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/connection_tester.h ('k') | remoting/protocol/fake_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698