| 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 #include <unordered_map> | 8 #include <unordered_map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/time/clock.h" | 17 #include "base/time/clock.h" |
| 18 #include "base/time/time.h" |
| 18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 19 #include "net/base/load_timing_info.h" | 20 #include "net/base/load_timing_info.h" |
| 20 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 21 #include "net/cert/x509_certificate.h" | 22 #include "net/cert/x509_certificate.h" |
| 22 #include "net/disk_cache/disk_cache.h" | 23 #include "net/disk_cache/disk_cache.h" |
| 23 #include "net/http/http_cache.h" | 24 #include "net/http/http_cache.h" |
| 24 #include "net/http/http_request_info.h" | 25 #include "net/http/http_request_info.h" |
| 25 #include "net/http/http_response_info.h" | 26 #include "net/http/http_response_info.h" |
| 26 #include "net/http/http_transaction.h" | 27 #include "net/http/http_transaction.h" |
| 27 #include "net/log/net_log.h" | 28 #include "net/log/net_log.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 weak_factory_(this) {} | 239 weak_factory_(this) {} |
| 239 | 240 |
| 240 MockNetworkTransaction::~MockNetworkTransaction() {} | 241 MockNetworkTransaction::~MockNetworkTransaction() {} |
| 241 | 242 |
| 242 int MockNetworkTransaction::Start(const HttpRequestInfo* request, | 243 int MockNetworkTransaction::Start(const HttpRequestInfo* request, |
| 243 const CompletionCallback& callback, | 244 const CompletionCallback& callback, |
| 244 const NetLogWithSource& net_log) { | 245 const NetLogWithSource& net_log) { |
| 245 if (request_) | 246 if (request_) |
| 246 return ERR_FAILED; | 247 return ERR_FAILED; |
| 247 | 248 |
| 248 start_time_ = base::TimeTicks::Now(); | |
| 249 request_ = request; | 249 request_ = request; |
| 250 return StartInternal(request, callback, net_log); | 250 return StartInternal(request, callback, net_log); |
| 251 } | 251 } |
| 252 | 252 |
| 253 int MockNetworkTransaction::RestartIgnoringLastError( | 253 int MockNetworkTransaction::RestartIgnoringLastError( |
| 254 const CompletionCallback& callback) { | 254 const CompletionCallback& callback) { |
| 255 return ERR_FAILED; | 255 return ERR_FAILED; |
| 256 } | 256 } |
| 257 | 257 |
| 258 int MockNetworkTransaction::RestartWithCertificate( | 258 int MockNetworkTransaction::RestartWithCertificate( |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 QuicServerInfo* quic_server_info) { | 359 QuicServerInfo* quic_server_info) { |
| 360 } | 360 } |
| 361 | 361 |
| 362 bool MockNetworkTransaction::GetLoadTimingInfo( | 362 bool MockNetworkTransaction::GetLoadTimingInfo( |
| 363 LoadTimingInfo* load_timing_info) const { | 363 LoadTimingInfo* load_timing_info) const { |
| 364 if (socket_log_id_ != NetLogSource::kInvalidId) { | 364 if (socket_log_id_ != NetLogSource::kInvalidId) { |
| 365 // The minimal set of times for a request that gets a response, assuming it | 365 // The minimal set of times for a request that gets a response, assuming it |
| 366 // gets a new socket. | 366 // gets a new socket. |
| 367 load_timing_info->socket_reused = false; | 367 load_timing_info->socket_reused = false; |
| 368 load_timing_info->socket_log_id = socket_log_id_; | 368 load_timing_info->socket_log_id = socket_log_id_; |
| 369 load_timing_info->connect_timing.connect_start = start_time_; | 369 load_timing_info->connect_timing.connect_start = base::TimeTicks::Now(); |
| 370 load_timing_info->connect_timing.connect_end = start_time_; | 370 load_timing_info->connect_timing.connect_end = base::TimeTicks::Now(); |
| 371 load_timing_info->send_start = start_time_; | 371 load_timing_info->send_start = base::TimeTicks::Now(); |
| 372 load_timing_info->send_end = start_time_; | 372 load_timing_info->send_end = base::TimeTicks::Now(); |
| 373 } else { | 373 } else { |
| 374 // If there's no valid socket ID, just use the generic socket reused values. | 374 // If there's no valid socket ID, just use the generic socket reused values. |
| 375 // No tests currently depend on this, just should not match the values set | 375 // No tests currently depend on this, just should not match the values set |
| 376 // by a cache hit. | 376 // by a cache hit. |
| 377 load_timing_info->socket_reused = true; | 377 load_timing_info->socket_reused = true; |
| 378 load_timing_info->send_start = start_time_; | 378 load_timing_info->send_start = base::TimeTicks::Now(); |
| 379 load_timing_info->send_end = start_time_; | 379 load_timing_info->send_end = base::TimeTicks::Now(); |
| 380 } | 380 } |
| 381 return true; | 381 return true; |
| 382 } | 382 } |
| 383 | 383 |
| 384 bool MockNetworkTransaction::GetRemoteEndpoint(IPEndPoint* endpoint) const { | 384 bool MockNetworkTransaction::GetRemoteEndpoint(IPEndPoint* endpoint) const { |
| 385 *endpoint = IPEndPoint(IPAddress(127, 0, 0, 1), 80); | 385 *endpoint = IPEndPoint(IPAddress(127, 0, 0, 1), 80); |
| 386 return true; | 386 return true; |
| 387 } | 387 } |
| 388 | 388 |
| 389 void MockNetworkTransaction::SetPriority(RequestPriority priority) { | 389 void MockNetworkTransaction::SetPriority(RequestPriority priority) { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 content.append(buf->data(), rv); | 575 content.append(buf->data(), rv); |
| 576 else if (rv < 0) | 576 else if (rv < 0) |
| 577 return rv; | 577 return rv; |
| 578 } while (rv > 0); | 578 } while (rv > 0); |
| 579 | 579 |
| 580 result->swap(content); | 580 result->swap(content); |
| 581 return OK; | 581 return OK; |
| 582 } | 582 } |
| 583 | 583 |
| 584 } // namespace net | 584 } // namespace net |
| OLD | NEW |