OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "net/socket/socket_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 net::CompletionCallback* callback) { | 277 net::CompletionCallback* callback) { |
278 return transport_->Read(buf, buf_len, callback); | 278 return transport_->Read(buf, buf_len, callback); |
279 } | 279 } |
280 | 280 |
281 int MockSSLClientSocket::Write(net::IOBuffer* buf, int buf_len, | 281 int MockSSLClientSocket::Write(net::IOBuffer* buf, int buf_len, |
282 net::CompletionCallback* callback) { | 282 net::CompletionCallback* callback) { |
283 return transport_->Write(buf, buf_len, callback); | 283 return transport_->Write(buf, buf_len, callback); |
284 } | 284 } |
285 | 285 |
286 MockRead StaticSocketDataProvider::GetNextRead() { | 286 MockRead StaticSocketDataProvider::GetNextRead() { |
287 MockRead rv = reads_[read_index_]; | 287 DCHECK(!at_read_eof()); |
288 if (reads_[read_index_].result != OK || | 288 return reads_[read_index_++]; |
289 reads_[read_index_].data_len != 0) | |
290 read_index_++; // Don't advance past an EOF. | |
291 return rv; | |
292 } | 289 } |
293 | 290 |
294 MockWriteResult StaticSocketDataProvider::OnWrite(const std::string& data) { | 291 MockWriteResult StaticSocketDataProvider::OnWrite(const std::string& data) { |
295 if (!writes_) { | 292 if (!writes_) { |
296 // Not using mock writes; succeed synchronously. | 293 // Not using mock writes; succeed synchronously. |
297 return MockWriteResult(false, data.length()); | 294 return MockWriteResult(false, data.length()); |
298 } | 295 } |
299 | 296 |
| 297 DCHECK(!at_write_eof()); |
| 298 |
300 // Check that what we are writing matches the expectation. | 299 // Check that what we are writing matches the expectation. |
301 // Then give the mocked return value. | 300 // Then give the mocked return value. |
302 net::MockWrite* w = &writes_[write_index_++]; | 301 net::MockWrite* w = &writes_[write_index_++]; |
303 int result = w->result; | 302 int result = w->result; |
304 if (w->data) { | 303 if (w->data) { |
305 // Note - we can simulate a partial write here. If the expected data | 304 // Note - we can simulate a partial write here. If the expected data |
306 // is a match, but shorter than the write actually written, that is legal. | 305 // is a match, but shorter than the write actually written, that is legal. |
307 // Example: | 306 // Example: |
308 // Application writes "foobarbaz" (9 bytes) | 307 // Application writes "foobarbaz" (9 bytes) |
309 // Expected write was "foo" (3 bytes) | 308 // Expected write was "foo" (3 bytes) |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 } | 462 } |
464 | 463 |
465 void ClientSocketPoolTest::ReleaseAllConnections(KeepAlive keep_alive) { | 464 void ClientSocketPoolTest::ReleaseAllConnections(KeepAlive keep_alive) { |
466 bool released_one; | 465 bool released_one; |
467 do { | 466 do { |
468 released_one = ReleaseOneConnection(keep_alive); | 467 released_one = ReleaseOneConnection(keep_alive); |
469 } while (released_one); | 468 } while (released_one); |
470 } | 469 } |
471 | 470 |
472 } // namespace net | 471 } // namespace net |
OLD | NEW |