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 "net/http/http_transaction_unittest.h" | 5 #include "net/http/http_transaction_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 return false; | 278 return false; |
279 | 279 |
280 // Only mock auth when the test asks for it. | 280 // Only mock auth when the test asks for it. |
281 return request_->extra_headers.HasHeader("X-Require-Mock-Auth"); | 281 return request_->extra_headers.HasHeader("X-Require-Mock-Auth"); |
282 } | 282 } |
283 | 283 |
284 int MockNetworkTransaction::Read(net::IOBuffer* buf, int buf_len, | 284 int MockNetworkTransaction::Read(net::IOBuffer* buf, int buf_len, |
285 const net::CompletionCallback& callback) { | 285 const net::CompletionCallback& callback) { |
286 int data_len = static_cast<int>(data_.size()); | 286 int data_len = static_cast<int>(data_.size()); |
287 int num = std::min(buf_len, data_len - data_cursor_); | 287 int num = std::min(buf_len, data_len - data_cursor_); |
| 288 if (test_mode_ & TEST_MODE_SLOW_READ) |
| 289 num = std::min(num, 1); |
288 if (num) { | 290 if (num) { |
289 memcpy(buf->data(), data_.data() + data_cursor_, num); | 291 memcpy(buf->data(), data_.data() + data_cursor_, num); |
290 data_cursor_ += num; | 292 data_cursor_ += num; |
291 } | 293 } |
292 if (test_mode_ & TEST_MODE_SYNC_NET_READ) | 294 if (test_mode_ & TEST_MODE_SYNC_NET_READ) |
293 return num; | 295 return num; |
294 | 296 |
295 CallbackLater(callback, num); | 297 CallbackLater(callback, num); |
296 return net::ERR_IO_PENDING; | 298 return net::ERR_IO_PENDING; |
297 } | 299 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 494 |
493 if (rv > 0) | 495 if (rv > 0) |
494 content.append(buf->data(), rv); | 496 content.append(buf->data(), rv); |
495 else if (rv < 0) | 497 else if (rv < 0) |
496 return rv; | 498 return rv; |
497 } while (rv > 0); | 499 } while (rv > 0); |
498 | 500 |
499 result->swap(content); | 501 result->swap(content); |
500 return net::OK; | 502 return net::OK; |
501 } | 503 } |
OLD | NEW |