| 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 "base/time/time.h" |
| 19 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 20 #include "net/base/load_timing_info.h" | 20 #include "net/base/load_timing_info.h" |
| 21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 #include "net/cert/x509_certificate.h" | 22 #include "net/cert/x509_certificate.h" |
| 23 #include "net/disk_cache/disk_cache.h" | 23 #include "net/disk_cache/disk_cache.h" |
| 24 #include "net/http/http_cache.h" | 24 #include "net/http/http_cache.h" |
| 25 #include "net/http/http_request_info.h" | 25 #include "net/http/http_request_info.h" |
| 26 #include "net/http/http_response_info.h" | 26 #include "net/http/http_response_info.h" |
| 27 #include "net/http/http_transaction.h" | 27 #include "net/http/http_transaction.h" |
| 28 #include "net/log/net_log.h" |
| 29 #include "net/log/net_log_source.h" |
| 30 #include "net/log/net_log_with_source.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 32 |
| 30 namespace net { | 33 namespace net { |
| 31 | 34 |
| 32 namespace { | 35 namespace { |
| 33 using MockTransactionMap = | 36 using MockTransactionMap = |
| 34 std::unordered_map<std::string, const MockTransaction*>; | 37 std::unordered_map<std::string, const MockTransaction*>; |
| 35 static MockTransactionMap mock_transactions; | 38 static MockTransactionMap mock_transactions; |
| 36 } // namespace | 39 } // namespace |
| 37 | 40 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 MockNetworkLayer* factory) | 227 MockNetworkLayer* factory) |
| 225 : request_(nullptr), | 228 : request_(nullptr), |
| 226 data_cursor_(0), | 229 data_cursor_(0), |
| 227 content_length_(0), | 230 content_length_(0), |
| 228 priority_(priority), | 231 priority_(priority), |
| 229 read_handler_(nullptr), | 232 read_handler_(nullptr), |
| 230 websocket_handshake_stream_create_helper_(nullptr), | 233 websocket_handshake_stream_create_helper_(nullptr), |
| 231 transaction_factory_(factory->AsWeakPtr()), | 234 transaction_factory_(factory->AsWeakPtr()), |
| 232 received_bytes_(0), | 235 received_bytes_(0), |
| 233 sent_bytes_(0), | 236 sent_bytes_(0), |
| 234 socket_log_id_(NetLog::Source::kInvalidId), | 237 socket_log_id_(NetLogSource::kInvalidId), |
| 235 done_reading_called_(false), | 238 done_reading_called_(false), |
| 236 weak_factory_(this) {} | 239 weak_factory_(this) {} |
| 237 | 240 |
| 238 MockNetworkTransaction::~MockNetworkTransaction() {} | 241 MockNetworkTransaction::~MockNetworkTransaction() {} |
| 239 | 242 |
| 240 int MockNetworkTransaction::Start(const HttpRequestInfo* request, | 243 int MockNetworkTransaction::Start(const HttpRequestInfo* request, |
| 241 const CompletionCallback& callback, | 244 const CompletionCallback& callback, |
| 242 const NetLogWithSource& net_log) { | 245 const NetLogWithSource& net_log) { |
| 243 if (request_) | 246 if (request_) |
| 244 return ERR_FAILED; | 247 return ERR_FAILED; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 return LOAD_STATE_READING_RESPONSE; | 354 return LOAD_STATE_READING_RESPONSE; |
| 352 return LOAD_STATE_IDLE; | 355 return LOAD_STATE_IDLE; |
| 353 } | 356 } |
| 354 | 357 |
| 355 void MockNetworkTransaction::SetQuicServerInfo( | 358 void MockNetworkTransaction::SetQuicServerInfo( |
| 356 QuicServerInfo* quic_server_info) { | 359 QuicServerInfo* quic_server_info) { |
| 357 } | 360 } |
| 358 | 361 |
| 359 bool MockNetworkTransaction::GetLoadTimingInfo( | 362 bool MockNetworkTransaction::GetLoadTimingInfo( |
| 360 LoadTimingInfo* load_timing_info) const { | 363 LoadTimingInfo* load_timing_info) const { |
| 361 if (socket_log_id_ != NetLog::Source::kInvalidId) { | 364 if (socket_log_id_ != NetLogSource::kInvalidId) { |
| 362 // 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 |
| 363 // gets a new socket. | 366 // gets a new socket. |
| 364 load_timing_info->socket_reused = false; | 367 load_timing_info->socket_reused = false; |
| 365 load_timing_info->socket_log_id = socket_log_id_; | 368 load_timing_info->socket_log_id = socket_log_id_; |
| 366 load_timing_info->connect_timing.connect_start = base::TimeTicks::Now(); | 369 load_timing_info->connect_timing.connect_start = base::TimeTicks::Now(); |
| 367 load_timing_info->connect_timing.connect_end = base::TimeTicks::Now(); | 370 load_timing_info->connect_timing.connect_end = base::TimeTicks::Now(); |
| 368 load_timing_info->send_start = base::TimeTicks::Now(); | 371 load_timing_info->send_start = base::TimeTicks::Now(); |
| 369 load_timing_info->send_end = base::TimeTicks::Now(); | 372 load_timing_info->send_end = base::TimeTicks::Now(); |
| 370 } else { | 373 } else { |
| 371 // 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. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 content.append(buf->data(), rv); | 575 content.append(buf->data(), rv); |
| 573 else if (rv < 0) | 576 else if (rv < 0) |
| 574 return rv; | 577 return rv; |
| 575 } while (rv > 0); | 578 } while (rv > 0); |
| 576 | 579 |
| 577 result->swap(content); | 580 result->swap(content); |
| 578 return OK; | 581 return OK; |
| 579 } | 582 } |
| 580 | 583 |
| 581 } // namespace net | 584 } // namespace net |
| OLD | NEW |