Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: net/http/http_transaction_test_util.cc

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_transaction_test_util.h ('k') | net/http/transport_security_state_static.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/time/clock.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "net/base/load_flags.h" 14 #include "net/base/load_flags.h"
14 #include "net/base/load_timing_info.h" 15 #include "net/base/load_timing_info.h"
15 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
16 #include "net/disk_cache/disk_cache.h" 17 #include "net/disk_cache/disk_cache.h"
17 #include "net/http/http_cache.h" 18 #include "net/http/http_cache.h"
18 #include "net/http/http_request_info.h" 19 #include "net/http/http_request_info.h"
19 #include "net/http/http_response_info.h" 20 #include "net/http/http_response_info.h"
20 #include "net/http/http_transaction.h" 21 #include "net/http/http_transaction.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 std::string resp_headers = t->response_headers; 393 std::string resp_headers = t->response_headers;
393 std::string resp_data = t->data; 394 std::string resp_data = t->data;
394 received_bytes_ = resp_status.size() + resp_headers.size() + resp_data.size(); 395 received_bytes_ = resp_status.size() + resp_headers.size() + resp_data.size();
395 if (t->handler) 396 if (t->handler)
396 (t->handler)(request, &resp_status, &resp_headers, &resp_data); 397 (t->handler)(request, &resp_status, &resp_headers, &resp_data);
397 398
398 std::string header_data = base::StringPrintf( 399 std::string header_data = base::StringPrintf(
399 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); 400 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str());
400 std::replace(header_data.begin(), header_data.end(), '\n', '\0'); 401 std::replace(header_data.begin(), header_data.end(), '\n', '\0');
401 402
402 response_.request_time = base::Time::Now(); 403 response_.request_time = transaction_factory_->Now();
403 if (!t->request_time.is_null()) 404 if (!t->request_time.is_null())
404 response_.request_time = t->request_time; 405 response_.request_time = t->request_time;
405 406
406 response_.was_cached = false; 407 response_.was_cached = false;
407 response_.network_accessed = true; 408 response_.network_accessed = true;
408 409
409 response_.response_time = base::Time::Now(); 410 response_.response_time = transaction_factory_->Now();
410 if (!t->response_time.is_null()) 411 if (!t->response_time.is_null())
411 response_.response_time = t->response_time; 412 response_.response_time = t->response_time;
412 413
413 response_.headers = new net::HttpResponseHeaders(header_data); 414 response_.headers = new net::HttpResponseHeaders(header_data);
414 response_.vary_data.Init(*request, *response_.headers.get()); 415 response_.vary_data.Init(*request, *response_.headers.get());
415 response_.ssl_info.cert_status = t->cert_status; 416 response_.ssl_info.cert_status = t->cert_status;
416 data_ = resp_data; 417 data_ = resp_data;
417 418
418 if (net_log.net_log()) 419 if (net_log.net_log())
419 socket_log_id_ = net_log.net_log()->NextID(); 420 socket_log_id_ = net_log.net_log()->NextID();
420 421
422 if (request_->load_flags & net::LOAD_PREFETCH)
423 response_.unused_since_prefetch = true;
424
421 if (test_mode_ & TEST_MODE_SYNC_NET_START) 425 if (test_mode_ & TEST_MODE_SYNC_NET_START)
422 return net::OK; 426 return net::OK;
423 427
424 CallbackLater(callback, net::OK); 428 CallbackLater(callback, net::OK);
425 return net::ERR_IO_PENDING; 429 return net::ERR_IO_PENDING;
426 } 430 }
427 431
428 void MockNetworkTransaction::SetBeforeNetworkStartCallback( 432 void MockNetworkTransaction::SetBeforeNetworkStartCallback(
429 const BeforeNetworkStartCallback& callback) { 433 const BeforeNetworkStartCallback& callback) {
430 } 434 }
(...skipping 16 matching lines...) Expand all
447 451
448 void MockNetworkTransaction::RunCallback( 452 void MockNetworkTransaction::RunCallback(
449 const net::CompletionCallback& callback, int result) { 453 const net::CompletionCallback& callback, int result) {
450 callback.Run(result); 454 callback.Run(result);
451 } 455 }
452 456
453 MockNetworkLayer::MockNetworkLayer() 457 MockNetworkLayer::MockNetworkLayer()
454 : transaction_count_(0), 458 : transaction_count_(0),
455 done_reading_called_(false), 459 done_reading_called_(false),
456 stop_caching_called_(false), 460 stop_caching_called_(false),
457 last_create_transaction_priority_(net::DEFAULT_PRIORITY) {} 461 last_create_transaction_priority_(net::DEFAULT_PRIORITY),
462 clock_(nullptr) {
463 }
458 464
459 MockNetworkLayer::~MockNetworkLayer() {} 465 MockNetworkLayer::~MockNetworkLayer() {}
460 466
461 void MockNetworkLayer::TransactionDoneReading() { 467 void MockNetworkLayer::TransactionDoneReading() {
462 done_reading_called_ = true; 468 done_reading_called_ = true;
463 } 469 }
464 470
465 void MockNetworkLayer::TransactionStopCaching() { 471 void MockNetworkLayer::TransactionStopCaching() {
466 stop_caching_called_ = true; 472 stop_caching_called_ = true;
467 } 473 }
(...skipping 11 matching lines...) Expand all
479 } 485 }
480 486
481 net::HttpCache* MockNetworkLayer::GetCache() { 487 net::HttpCache* MockNetworkLayer::GetCache() {
482 return NULL; 488 return NULL;
483 } 489 }
484 490
485 net::HttpNetworkSession* MockNetworkLayer::GetSession() { 491 net::HttpNetworkSession* MockNetworkLayer::GetSession() {
486 return NULL; 492 return NULL;
487 } 493 }
488 494
495 void MockNetworkLayer::SetClock(base::Clock* clock) {
496 DCHECK(!clock_);
497 clock_ = clock;
498 }
499
500 base::Time MockNetworkLayer::Now() {
501 if (clock_)
502 return clock_->Now();
503 return base::Time::Now();
504 }
505
489 //----------------------------------------------------------------------------- 506 //-----------------------------------------------------------------------------
490 // helpers 507 // helpers
491 508
492 int ReadTransaction(net::HttpTransaction* trans, std::string* result) { 509 int ReadTransaction(net::HttpTransaction* trans, std::string* result) {
493 int rv; 510 int rv;
494 511
495 net::TestCompletionCallback callback; 512 net::TestCompletionCallback callback;
496 513
497 std::string content; 514 std::string content;
498 do { 515 do {
499 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 516 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
500 rv = trans->Read(buf.get(), 256, callback.callback()); 517 rv = trans->Read(buf.get(), 256, callback.callback());
501 if (rv == net::ERR_IO_PENDING) 518 if (rv == net::ERR_IO_PENDING)
502 rv = callback.WaitForResult(); 519 rv = callback.WaitForResult();
503 520
504 if (rv > 0) 521 if (rv > 0)
505 content.append(buf->data(), rv); 522 content.append(buf->data(), rv);
506 else if (rv < 0) 523 else if (rv < 0)
507 return rv; 524 return rv;
508 } while (rv > 0); 525 } while (rv > 0);
509 526
510 result->swap(content); 527 result->swap(content);
511 return net::OK; 528 return net::OK;
512 } 529 }
OLDNEW
« no previous file with comments | « net/http/http_transaction_test_util.h ('k') | net/http/transport_security_state_static.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698