OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_test_util.h" | 5 #include "net/http/http_transaction_test_util.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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // Let the MockTransactionHandler worry about this: the only way for this | 270 // Let the MockTransactionHandler worry about this: the only way for this |
271 // test to succeed is by using an explicit handler for the transaction so | 271 // test to succeed is by using an explicit handler for the transaction so |
272 // that server behavior can be simulated. | 272 // that server behavior can be simulated. |
273 return StartInternal(&auth_request_info, callback, net::BoundNetLog()); | 273 return StartInternal(&auth_request_info, callback, net::BoundNetLog()); |
274 } | 274 } |
275 | 275 |
276 bool MockNetworkTransaction::IsReadyToRestartForAuth() { | 276 bool MockNetworkTransaction::IsReadyToRestartForAuth() { |
277 if (!request_) | 277 if (!request_) |
278 return false; | 278 return false; |
279 | 279 |
280 // Only mock auth when the test asks for it. | 280 if (!request_->extra_headers.HasHeader("X-Require-Mock-Auth")) |
281 return request_->extra_headers.HasHeader("X-Require-Mock-Auth"); | 281 return false; |
| 282 |
| 283 // Allow the mock server to decide whether authentication is required or not. |
| 284 std::string status_line = response_.headers->GetStatusLine(); |
| 285 return status_line.find(" 401 ") != std::string::npos || |
| 286 status_line.find(" 407 ") != std::string::npos; |
282 } | 287 } |
283 | 288 |
284 int MockNetworkTransaction::Read(net::IOBuffer* buf, int buf_len, | 289 int MockNetworkTransaction::Read(net::IOBuffer* buf, int buf_len, |
285 const net::CompletionCallback& callback) { | 290 const net::CompletionCallback& callback) { |
286 int data_len = static_cast<int>(data_.size()); | 291 int data_len = static_cast<int>(data_.size()); |
287 int num = std::min(buf_len, data_len - data_cursor_); | 292 int num = std::min(buf_len, data_len - data_cursor_); |
288 if (test_mode_ & TEST_MODE_SLOW_READ) | 293 if (test_mode_ & TEST_MODE_SLOW_READ) |
289 num = std::min(num, 1); | 294 num = std::min(num, 1); |
290 if (num) { | 295 if (num) { |
291 memcpy(buf->data(), data_.data() + data_cursor_, num); | 296 memcpy(buf->data(), data_.data() + data_cursor_, num); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 503 |
499 if (rv > 0) | 504 if (rv > 0) |
500 content.append(buf->data(), rv); | 505 content.append(buf->data(), rv); |
501 else if (rv < 0) | 506 else if (rv < 0) |
502 return rv; | 507 return rv; |
503 } while (rv > 0); | 508 } while (rv > 0); |
504 | 509 |
505 result->swap(content); | 510 result->swap(content); |
506 return net::OK; | 511 return net::OK; |
507 } | 512 } |
OLD | NEW |