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/fake_session.h" | 5 #include "remoting/protocol/fake_session.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace remoting { | 15 namespace remoting { |
16 namespace protocol { | 16 namespace protocol { |
17 | 17 |
18 const char kTestJid[] = "host1@gmail.com/chromoting123"; | 18 const char kTestJid[] = "host1@gmail.com/chromoting123"; |
19 | 19 |
20 FakeSocket::FakeSocket() | 20 FakeSocket::FakeSocket() |
21 : read_pending_(false), | 21 : next_read_error_(net::OK), |
| 22 read_pending_(false), |
22 read_buffer_size_(0), | 23 read_buffer_size_(0), |
23 input_pos_(0), | 24 input_pos_(0), |
24 message_loop_(MessageLoop::current()), | 25 message_loop_(MessageLoop::current()), |
25 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 26 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
26 } | 27 } |
27 | 28 |
28 FakeSocket::~FakeSocket() { | 29 FakeSocket::~FakeSocket() { |
29 EXPECT_EQ(message_loop_, MessageLoop::current()); | 30 EXPECT_EQ(message_loop_, MessageLoop::current()); |
30 } | 31 } |
31 | 32 |
(...skipping 16 matching lines...) Expand all Loading... |
48 | 49 |
49 void FakeSocket::PairWith(FakeSocket* peer_socket) { | 50 void FakeSocket::PairWith(FakeSocket* peer_socket) { |
50 EXPECT_EQ(message_loop_, MessageLoop::current()); | 51 EXPECT_EQ(message_loop_, MessageLoop::current()); |
51 peer_socket_ = peer_socket->weak_factory_.GetWeakPtr(); | 52 peer_socket_ = peer_socket->weak_factory_.GetWeakPtr(); |
52 peer_socket->peer_socket_ = weak_factory_.GetWeakPtr(); | 53 peer_socket->peer_socket_ = weak_factory_.GetWeakPtr(); |
53 } | 54 } |
54 | 55 |
55 int FakeSocket::Read(net::IOBuffer* buf, int buf_len, | 56 int FakeSocket::Read(net::IOBuffer* buf, int buf_len, |
56 const net::CompletionCallback& callback) { | 57 const net::CompletionCallback& callback) { |
57 EXPECT_EQ(message_loop_, MessageLoop::current()); | 58 EXPECT_EQ(message_loop_, MessageLoop::current()); |
| 59 |
| 60 if (next_read_error_ != net::OK) { |
| 61 int r = next_read_error_; |
| 62 next_read_error_ = net::OK; |
| 63 return r; |
| 64 } |
| 65 |
58 if (input_pos_ < static_cast<int>(input_data_.size())) { | 66 if (input_pos_ < static_cast<int>(input_data_.size())) { |
59 int result = std::min(buf_len, | 67 int result = std::min(buf_len, |
60 static_cast<int>(input_data_.size()) - input_pos_); | 68 static_cast<int>(input_data_.size()) - input_pos_); |
61 memcpy(buf->data(), &(*input_data_.begin()) + input_pos_, result); | 69 memcpy(buf->data(), &(*input_data_.begin()) + input_pos_, result); |
62 input_pos_ += result; | 70 input_pos_ += result; |
63 return result; | 71 return result; |
64 } else { | 72 } else { |
65 read_pending_ = true; | 73 read_pending_ = true; |
66 read_buffer_ = buf; | 74 read_buffer_ = buf; |
67 read_buffer_size_ = buf_len; | 75 read_buffer_size_ = buf_len; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 void FakeSession::set_config(const SessionConfig& config) { | 291 void FakeSession::set_config(const SessionConfig& config) { |
284 config_ = config; | 292 config_ = config; |
285 } | 293 } |
286 | 294 |
287 void FakeSession::Close() { | 295 void FakeSession::Close() { |
288 closed_ = true; | 296 closed_ = true; |
289 } | 297 } |
290 | 298 |
291 } // namespace protocol | 299 } // namespace protocol |
292 } // namespace remoting | 300 } // namespace remoting |
OLD | NEW |